Files
threshold-ui/ui/admin/tests/acceptance/users-test.js
T

90 lines
2.5 KiB
JavaScript
Raw Normal View History

2020-06-23 15:42:37 -04:00
import { module, test } from 'qunit';
import { visit, currentURL, click, fillIn, find } from '@ember/test-helpers';
import { setupApplicationTest } from 'ember-qunit';
import setupMirage from 'ember-cli-mirage/test-support/setup-mirage';
import { Response } from 'miragejs';
import {
authenticateSession,
// These are left here intentionally for future reference.
//currentSession,
//invalidateSession,
} from 'ember-simple-auth/test-support';
2020-06-23 15:42:37 -04:00
2020-07-27 14:12:19 -04:00
module('Acceptance | users', function (hooks) {
2020-06-23 15:42:37 -04:00
setupApplicationTest(hooks);
setupMirage(hooks);
let orgScope;
let usersURL;
let newUserURL;
2020-06-23 15:42:37 -04:00
hooks.beforeEach(function () {
orgScope = this.server.create(
'scope',
{
type: 'org',
},
'withChildren'
);
usersURL = `/scopes/${orgScope.id}/users`;
newUserURL = `${usersURL}/new`;
authenticateSession({});
2020-06-23 15:42:37 -04:00
});
test('can create new users', async function (assert) {
assert.expect(1);
const usersCount = this.server.db.users.length;
await visit(newUserURL);
2020-06-23 15:42:37 -04:00
await fillIn('[name="name"]', 'User name');
await click('[type="submit"]');
assert.equal(this.server.db.users.length, usersCount + 1);
2020-06-23 15:42:37 -04:00
});
test('can cancel creation of a new user', async function (assert) {
assert.expect(2);
const usersCount = this.server.db.users.length;
await visit(newUserURL);
2020-06-23 15:42:37 -04:00
await fillIn('[name="name"]', 'User name');
await click('.rose-form-actions [type="button"]');
assert.equal(currentURL(), usersURL);
assert.equal(this.server.db.users.length, usersCount);
2020-06-23 15:42:37 -04:00
});
test('saving a new user with invalid fields displays error messages', async function (assert) {
assert.expect(2);
2020-09-09 16:53:41 -04:00
this.server.post('/users', () => {
2020-06-23 15:42:37 -04:00
return new Response(
400,
{},
{
status: 400,
code: 'invalid_argument',
message: 'The request was invalid.',
details: {
2020-09-11 12:01:56 -04:00
request_fields: [
2020-06-23 15:42:37 -04:00
{
name: 'name',
2020-09-11 12:01:56 -04:00
description: 'Name is required.',
2020-06-23 15:42:37 -04:00
},
],
},
}
);
});
await visit(newUserURL);
2020-06-23 15:42:37 -04:00
await fillIn('[name="name"]', 'User name');
await click('[type="submit"]');
assert.ok(
find('[role="alert"]').textContent.trim(),
'The request was invalid.',
'Displays primary error message.'
);
assert.ok(
find('.rose-form-error-message').textContent.trim(),
'Name is required.',
'Displays field-level errors.'
);
});
});