This repository has been archived on 2025-03-30. You can view files and clone it, but cannot push or open issues or pull requests.
hymenobacterdotinfo/tests/acceptance/users-test.js
2015-11-16 10:32:49 -07:00

77 lines
2.4 KiB
JavaScript

import Ember from 'ember';
import { module, test } from 'qunit';
import startApp from '../helpers/start-app';
import { invalidateSession, authenticateSession } from '../helpers/ember-simple-auth';
module('Acceptance | users', {
beforeEach: function() {
this.application = startApp();
server.create('users', { role: 'A', canEdit: true, sub: 1 });
authenticateSession(this.application, {
access_token: "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJiYWN0ZGIiLCJzdWIiOiIxIiwiZXhwIjoxNDQ2NTAyMjI2LCJpYXQiOjE0NDY0OTg2MjZ9.vIjKHAsp2TkCV505EbtCo2xQT-2oQkB-Nv5y0b6E7Mg"
});
},
afterEach: function() {
Ember.run(this.application, 'destroy');
}
});
test('visiting /users', function(assert) {
const users = server.createList('users', 19); // We already created one user in beforeEach
visit('/users');
andThen(function() {
assert.equal(currentURL(), '/users');
assert.equal(find(".flakes-table > tbody > tr").length, users.length + 1);
assert.equal(find("#total-users").text(), "Total users: 20");
});
});
test('visiting /users/:id', function(assert) {
const user = server.create('users');
visit(`/users/${user.id}`);
andThen(function() {
assert.equal(currentURL(), `/users/${user.id}`);
assert.equal(find(".flakes-information-box > legend").text().trim(), user.name);
});
});
test('editing /users/:id/edit', function(assert) {
const user = server.create('users', { 'canEdit': true });
visit(`/users/${user.id}/edit`);
andThen(function() {
assert.equal(currentURL(), `/users/${user.id}/edit`);
fillIn('.user-name', 'Revised User Name');
click('.save-user');
andThen(function() {
assert.equal(currentURL(), `/users/${user.id}`);
assert.equal(find(".flakes-information-box > legend").text().trim(), 'Revised User Name');
});
});
});
test('creating /users/new', function(assert) {
invalidateSession(this.application);
visit(`/users/new`);
andThen(function() {
assert.equal(currentURL(), `/users/new`);
fillIn('.user-name', 'New User Name');
fillIn('.email', 'example@example.com');
fillIn('.password', 'Password1');
fillIn('.password-verify', 'Password1');
click('.save-user');
andThen(function() {
assert.equal(currentURL(), `/login`);
assert.equal(find(".flakes-message").text().trim(), `✖ You have successfully signed up.
Please check your email for further instructions.`);
});
});
});