Merge branch 'main' into roles-capabilities

This commit is contained in:
Dharini Jeeva authored and GitHub committed 2021-08-17 08:13:55 -07:00
commit 3cc5456bde
35 files changed
+1440 -599

No files matched your search

@@ -118,10 +118,13 @@
</form.textarea>
{{/if}}
<form.actions
@disabled={{if @model.cannotSave @model.cannotSave}}
@enableEditText={{t 'actions.edit-form'}}
@submitText={{t 'actions.save'}}
@cancelText={{t 'actions.cancel'}}
/>
{{#if (can 'save model' @model)}}
<form.actions
@disabled={{if @model.cannotSave @model.cannotSave}}
@enableEditText={{t 'actions.edit-form'}}
@submitText={{t 'actions.save'}}
@cancelText={{t 'actions.cancel'}}
/>
{{/if}}
</Rose::Form>
+8 -7
View File
@@ -46,11 +46,12 @@
{{/if}}
</form.textarea>
<form.actions
@disabled={{if @model.cannotSave @model.cannotSave}}
@enableEditText={{t 'actions.edit-form'}}
@submitText={{t 'actions.save'}}
@cancelText={{t 'actions.cancel'}}
/>
{{#if (can 'save model' @model)}}
<form.actions
@disabled={{if @model.cannotSave @model.cannotSave}}
@enableEditText={{t 'actions.edit-form'}}
@submitText={{t 'actions.save'}}
@cancelText={{t 'actions.cancel'}}
/>
{{/if}}
</Rose::Form>
@@ -111,12 +111,12 @@
</field.errors>
{{/if}}
</form.input>
<form.actions
@disabled={{if @model.cannotSave @model.cannotSave}}
@enableEditText={{t 'actions.edit-form'}}
@submitText={{t 'actions.save'}}
@cancelText={{t 'actions.cancel'}}
/>
{{#if (can 'save model' @model)}}
<form.actions
@disabled={{if @model.cannotSave @model.cannotSave}}
@enableEditText={{t 'actions.edit-form'}}
@submitText={{t 'actions.save'}}
@cancelText={{t 'actions.cancel'}}
/>
{{/if}}
</Rose::Form>
+8 -7
View File
@@ -46,11 +46,12 @@
{{/if}}
</form.textarea>
<form.actions
@disabled={{if @model.cannotSave @model.cannotSave}}
@enableEditText={{t 'actions.edit-form'}}
@submitText={{t 'actions.save'}}
@cancelText={{t 'actions.cancel'}}
/>
{{#if (can 'save model' @model)}}
<form.actions
@disabled={{if @model.cannotSave @model.cannotSave}}
@enableEditText={{t 'actions.edit-form'}}
@submitText={{t 'actions.save'}}
@cancelText={{t 'actions.cancel'}}
/>
{{/if}}
</Rose::Form>
@@ -1,13 +1,15 @@
<Rose::Dropdown
@text={{t 'actions.manage'}}
@dropdownRight={{true}}
as |dropdown|
>
<dropdown.button
@style='danger'
@disabled={{@model.canSave}}
{{on 'click' (route-action 'delete' @model)}}
{{#if (can 'delete model' @model)}}
<Rose::Dropdown
@text={{t 'actions.manage'}}
@dropdownRight={{true}}
as |dropdown|
>
{{t 'resources.credential-library.actions.delete'}}
</dropdown.button>
</Rose::Dropdown>
<dropdown.button
@style='danger'
@disabled={{@model.canSave}}
{{on 'click' (route-action 'delete' @model)}}
>
{{t 'resources.credential-library.actions.delete'}}
</dropdown.button>
</Rose::Dropdown>
{{/if}}
@@ -12,12 +12,16 @@
{{#each @model as |credentialLibrary|}}
<body.row as |row|>
<row.headerCell>
<LinkTo
@route='scopes.scope.credential-stores.credential-store.credential-libraries.credential-library'
@model={{credentialLibrary.id}}
>
{{#if (can 'read model' credentialLibrary)}}
<LinkTo
@route='scopes.scope.credential-stores.credential-store.credential-libraries.credential-library'
@model={{credentialLibrary.id}}
>
{{credentialLibrary.displayName}}
</LinkTo>
{{else}}
{{credentialLibrary.displayName}}
</LinkTo>
{{/if}}
<p>{{credentialLibrary.description}}</p>
</row.headerCell>
<row.cell>
@@ -6,12 +6,14 @@
<dropdown.link @route='scopes.scope.groups.group.add-members'>
{{t 'resources.group.actions.add-members'}}
</dropdown.link>
<dropdown.separator />
<dropdown.button
@style='danger'
@disabled={{@model.canSave}}
{{on 'click' (route-action 'delete' @model)}}
>
{{t 'resources.group.actions.delete'}}
</dropdown.button>
{{#if (can 'delete model' @model)}}
<dropdown.separator />
<dropdown.button
@style='danger'
@disabled={{@model.canSave}}
{{on 'click' (route-action 'delete' @model)}}
>
{{t 'resources.group.actions.delete'}}
</dropdown.button>
{{/if}}
</Rose::Dropdown>
@@ -35,9 +35,16 @@
{{#each @model as |group|}}
<body.row as |row|>
<row.headerCell>
<LinkTo @route='scopes.scope.groups.group' @model={{group.id}}>
{{#if (can 'read model' group)}}
<LinkTo
@route='scopes.scope.groups.group'
@model={{group.id}}
>
{{group.displayName}}
</LinkTo>
{{else}}
{{group.displayName}}
</LinkTo>
{{/if}}
<p>{{group.description}}</p>
</row.headerCell>
<row.cell>
@@ -38,12 +38,16 @@
{{#each @model as |target|}}
<body.row as |row|>
<row.headerCell>
<LinkTo
@route='scopes.scope.targets.target'
@model={{target.id}}
>
{{#if (can 'read model' target)}}
<LinkTo
@route='scopes.scope.targets.target'
@model={{target.id}}
>
{{target.displayName}}
</LinkTo>
{{else}}
{{target.displayName}}
</LinkTo>
{{/if}}
<p>{{target.description}}</p>
</row.headerCell>
<row.cell>
@@ -13,12 +13,14 @@
{{t 'resources.target.actions.add-credential-libraries'}}
</dropdown.link>
{{/if}}
<dropdown.separator />
<dropdown.button
@style='danger'
@disabled={{@model.canSave}}
{{on 'click' (route-action 'delete' @model)}}
>
{{t 'resources.target.actions.delete'}}
</dropdown.button>
{{#if (can 'delete model' @model)}}
<dropdown.separator />
<dropdown.button
@style='danger'
@disabled={{@model.canSave}}
{{on 'click' (route-action 'delete' @model)}}
>
{{t 'resources.target.actions.delete'}}
</dropdown.button>
{{/if}}
</Rose::Dropdown>
@@ -37,9 +37,13 @@
{{#each @model as |user|}}
<body.row as |row|>
<row.headerCell>
<LinkTo @route='scopes.scope.users.user' @model={{user.id}}>
{{#if (can 'read model' user)}}
<LinkTo @route='scopes.scope.users.user' @model={{user.id}}>
{{user.displayName}}
</LinkTo>
{{else}}
{{user.displayName}}
</LinkTo>
{{/if}}
<p>{{user.description}}</p>
</row.headerCell>
<row.cell>
@@ -1,17 +1,19 @@
<Rose::Dropdown
@text='{{t 'actions.manage'}}'
@dropdownRight={{true}}
as |dropdown|
>
<dropdown.link @route='scopes.scope.users.user.add-accounts'>
{{t 'resources.user.actions.add-accounts'}}
</dropdown.link>
<dropdown.separator />
<dropdown.button
@style='danger'
@disabled={{@model.canSave}}
{{on 'click' (route-action 'delete' @model)}}
{{#if (can 'delete model' @model)}}
<Rose::Dropdown
@text='{{t 'actions.manage'}}'
@dropdownRight={{true}}
as |dropdown|
>
{{t 'resources.user.actions.delete'}}
</dropdown.button>
</Rose::Dropdown>
<dropdown.link @route='scopes.scope.users.user.add-accounts'>
{{t 'resources.user.actions.add-accounts'}}
</dropdown.link>
<dropdown.separator />
<dropdown.button
@style='danger'
@disabled={{@model.canSave}}
{{on 'click' (route-action 'delete' @model)}}
>
{{t 'resources.user.actions.delete'}}
</dropdown.button>
</Rose::Dropdown>
{{/if}}
+1
View File
@@ -0,0 +1 @@
{"compilerOptions":{"target":"es6","experimentalDecorators":true},"exclude":["node_modules","bower_components","tmp","vendor",".git","dist"]}
@@ -59,7 +59,7 @@ module('Acceptance | accounts | update', function (hooks) {
}
});
test('can update an account and save changes', async function (assert) {
test('can update resource and save changes', async function (assert) {
assert.expect(1);
await visit(urls.account);
await click('form [type="button"]', 'Activate edit mode');
@@ -68,6 +68,14 @@ module('Acceptance | accounts | update', function (hooks) {
assert.equal(this.server.db.accounts[0].name, 'update name');
});
test('cannot update resource without proper authorization', async function (assert) {
assert.expect(1);
instances.account.authorized_actions =
instances.account.authorized_actions.filter((item) => item !== 'update');
await visit(urls.account);
assert.notOk(find('form [type="button"]'));
});
test('can update an account and cancel changes', async function (assert) {
assert.expect(1);
await visit(urls.account);
@@ -0,0 +1,138 @@
import { module, test } from 'qunit';
import { visit, click, fillIn, currentURL, find } from '@ember/test-helpers';
import { setupApplicationTest } from 'ember-qunit';
import setupMirage from 'ember-cli-mirage/test-support/setup-mirage';
import a11yAudit from 'ember-a11y-testing/test-support/audit';
import { authenticateSession } from 'ember-simple-auth/test-support';
import { Response } from 'miragejs';
module('Acceptance | credential-libraries', function (hooks) {
setupApplicationTest(hooks);
setupMirage(hooks);
let getCredentialLibraryCount;
const instances = {
scopes: {
global: null,
org: null,
project: null,
},
};
const urls = {
globalScope: null,
orgScope: null,
projectScope: null,
credentialStores: null,
credentialStore: null,
credentialLibrary: null,
credentialLibraries: null,
newCredentialLibrary: null,
unknownCredentialLibrary: null,
};
hooks.beforeEach(function () {
// Generate resources
instances.scopes.global = this.server.create('scope', { id: 'global' });
instances.scopes.org = this.server.create('scope', {
type: 'org',
scope: { id: 'global', type: 'global' },
});
instances.scopes.project = this.server.create('scope', {
type: 'project',
scope: { id: instances.scopes.org.id, type: 'org' },
});
instances.credentialStore = this.server.create('credential-store', {
scope: instances.scopes.project,
});
instances.credentialLibrary = this.server.create('credential-library', {
scope: instances.scopes.project,
credentialStore: instances.credentialStore,
});
// Generate route URLs for resources
urls.globalScope = `/scopes/global/scopes`;
urls.orgScope = `/scopes/${instances.scopes.org.id}/scopes`;
urls.projectScope = `/scopes/${instances.scopes.project.id}`;
urls.credentialStores = `${urls.projectScope}/credential-stores`;
urls.credentialStore = `${urls.credentialStores}/${instances.credentialStore.id}`;
urls.credentialLibraries = `${urls.credentialStore}/credential-libraries`;
urls.credentialLibrary = `${urls.credentialLibraries}/${instances.credentialLibrary.id}`;
urls.newCredentialLibrary = `${urls.credentialLibraries}/new`;
urls.unknownCredentialLibrary = `${urls.credentialLibraries}/foo`;
// Generate resource counter
getCredentialLibraryCount = () =>
this.server.schema.credentialLibraries.all().models.length;
authenticateSession({});
});
test('visiting credential libraries', async function (assert) {
assert.expect(2);
await visit(urls.credentialLibraries);
await a11yAudit();
assert.equal(currentURL(), urls.credentialLibraries);
await visit(urls.credentialLibrary);
await a11yAudit();
assert.equal(currentURL(), urls.credentialLibrary);
});
test('visiting an unknown credential library displays 404 message', async function (assert) {
assert.expect(1);
await visit(urls.unknownCredentialLibrary);
await a11yAudit();
console.debug(find('.rose-message-subtitle'));
assert.ok(find('.rose-message-subtitle').textContent.trim(), 'Error 404');
});
test('can create a credential library', async function (assert) {
assert.expect(1);
const count = getCredentialLibraryCount();
await visit(urls.newCredentialLibrary);
await fillIn('[name="name"]', 'random string');
await click('[type="submit"]');
assert.equal(getCredentialLibraryCount(), count + 1);
});
test('can cancel create a new credential library', async function (assert) {
assert.expect(2);
const count = getCredentialLibraryCount();
await visit(urls.newCredentialLibrary);
await fillIn('[name="name"]', 'random string');
await click('.rose-form-actions [type="button"]');
assert.equal(currentURL(), urls.credentialLibraries);
assert.equal(getCredentialLibraryCount(), count);
});
test('saving a new credential library with invalid fields displays error messasges', async function (assert) {
assert.expect(2);
this.server.post('/credential-libraries', () => {
return new Response(
400,
{},
{
status: 400,
code: 'invalid_argument',
message: 'The request was invalid',
details: {
request_fields: [
{
name: 'name',
description: 'Name is required.',
},
],
},
}
);
});
await visit(urls.newCredentialLibrary);
await click('[type="submit"]');
assert.ok(
find('[role="alert"]').textContent.trim(),
'The request was invalid.'
);
assert.ok(
find('.rose-form-error-message').textContent.trim(),
'Name is required.'
);
});
});
@@ -0,0 +1,131 @@
import { module, test } from 'qunit';
import { visit, click, find } from '@ember/test-helpers';
import { setupApplicationTest } from 'ember-qunit';
import setupMirage from 'ember-cli-mirage/test-support/setup-mirage';
import { authenticateSession } from 'ember-simple-auth/test-support';
import { Response } from 'miragejs';
import { resolve, reject } from 'rsvp';
import sinon from 'sinon';
module('Acceptance | credential-libraries | delete', function (hooks) {
setupApplicationTest(hooks);
setupMirage(hooks);
let getCredentialLibraryCount;
const instances = {
scopes: {
global: null,
org: null,
project: null,
},
};
const urls = {
globalScope: null,
orgScope: null,
projectScope: null,
credentialStores: null,
credentialStore: null,
credentialLibrary: null,
credentialLibraries: null,
newCredentialLibrary: null,
unknownCredentialLibrary: null,
};
hooks.beforeEach(function () {
// Generate resources
instances.scopes.global = this.server.create('scope', { id: 'global' });
instances.scopes.org = this.server.create('scope', {
type: 'org',
scope: { id: 'global', type: 'global' },
});
instances.scopes.project = this.server.create('scope', {
type: 'project',
scope: { id: instances.scopes.org.id, type: 'org' },
});
instances.credentialStore = this.server.create('credential-store', {
scope: instances.scopes.project,
});
instances.credentialLibrary = this.server.create('credential-library', {
scope: instances.scopes.project,
credentialStore: instances.credentialStore,
});
// Generate route URLs for resources
urls.globalScope = `/scopes/global/scopes`;
urls.orgScope = `/scopes/${instances.scopes.org.id}/scopes`;
urls.projectScope = `/scopes/${instances.scopes.project.id}`;
urls.credentialStores = `${urls.projectScope}/credential-stores`;
urls.credentialStore = `${urls.credentialStores}/${instances.credentialStore.id}`;
urls.credentialLibraries = `${urls.credentialStore}/credential-libraries`;
urls.credentialLibrary = `${urls.credentialLibraries}/${instances.credentialLibrary.id}`;
urls.newCredentialLibrary = `${urls.credentialLibraries}/new`;
urls.unknownCredentialLibrary = `${urls.credentialLibraries}/foo`;
// Generate resource counter
getCredentialLibraryCount = () =>
this.server.schema.credentialLibraries.all().models.length;
authenticateSession({});
});
test('can delete resource', async function (assert) {
assert.expect(1);
const count = getCredentialLibraryCount();
await visit(urls.credentialLibrary);
await click('.rose-layout-page-actions .rose-dropdown-button-danger');
assert.equal(getCredentialLibraryCount(), count - 1);
});
test('cannot delete resource without proper authorization', async function (assert) {
assert.expect(1);
instances.credentialLibrary.authorized_actions =
instances.credentialLibrary.authorized_actions.filter(
(item) => item !== 'delete'
);
await visit(urls.credentialLibrary);
assert.notOk(
find('.rose-layout-page-actions .rose-dropdown-button-danger')
);
});
test('can accept delete credential library via dialog', async function (assert) {
assert.expect(2);
const confirmService = this.owner.lookup('service:confirm');
confirmService.enabled = true;
confirmService.confirm = sinon.fake.returns(resolve());
const count = getCredentialLibraryCount();
await visit(urls.credentialLibrary);
await click('.rose-layout-page-actions .rose-dropdown-button-danger');
assert.equal(getCredentialLibraryCount(), count - 1);
assert.ok(confirmService.confirm.calledOnce);
});
test('cannot cancel delete credential library via dialog', async function (assert) {
assert.expect(2);
const confirmService = this.owner.lookup('service:confirm');
confirmService.enabled = true;
confirmService.confirm = sinon.fake.returns(reject());
const count = getCredentialLibraryCount();
await visit(urls.credentialLibrary);
await click('.rose-layout-page-actions .rose-dropdown-button-danger');
assert.equal(getCredentialLibraryCount(), count);
assert.ok(confirmService.confirm.calledOnce);
});
test('deleting a credential library which errors displays error messages', async function (assert) {
assert.expect(1);
this.server.del('/credential-libraries/:id', () => {
return new Response(
490,
{},
{
status: 490,
code: 'error',
message: 'Oops.',
}
);
});
await visit(urls.credentialLibrary);
await click('.rose-layout-page-actions .rose-dropdown-button-danger');
assert.ok(find('[role="alert"]').textContent.trim(), 'Oops.');
});
});
@@ -0,0 +1,80 @@
import { module, test } from 'qunit';
import { visit, click, currentURL, find } from '@ember/test-helpers';
import { setupApplicationTest } from 'ember-qunit';
import setupMirage from 'ember-cli-mirage/test-support/setup-mirage';
import a11yAudit from 'ember-a11y-testing/test-support/audit';
import { authenticateSession } from 'ember-simple-auth/test-support';
module('Acceptance | credential-libraries | read', function (hooks) {
setupApplicationTest(hooks);
setupMirage(hooks);
const instances = {
scopes: {
global: null,
org: null,
project: null,
},
};
const urls = {
globalScope: null,
orgScope: null,
projectScope: null,
credentialStores: null,
credentialStore: null,
credentialLibrary: null,
credentialLibraries: null,
newCredentialLibrary: null,
unknownCredentialLibrary: null,
};
hooks.beforeEach(function () {
// Generate resources
instances.scopes.global = this.server.create('scope', { id: 'global' });
instances.scopes.org = this.server.create('scope', {
type: 'org',
scope: { id: 'global', type: 'global' },
});
instances.scopes.project = this.server.create('scope', {
type: 'project',
scope: { id: instances.scopes.org.id, type: 'org' },
});
instances.credentialStore = this.server.create('credential-store', {
scope: instances.scopes.project,
});
instances.credentialLibrary = this.server.create('credential-library', {
scope: instances.scopes.project,
credentialStore: instances.credentialStore,
});
// Generate route URLs for resources
urls.globalScope = `/scopes/global/scopes`;
urls.orgScope = `/scopes/${instances.scopes.org.id}/scopes`;
urls.projectScope = `/scopes/${instances.scopes.project.id}`;
urls.credentialStores = `${urls.projectScope}/credential-stores`;
urls.credentialStore = `${urls.credentialStores}/${instances.credentialStore.id}`;
urls.credentialLibraries = `${urls.credentialStore}/credential-libraries`;
urls.credentialLibrary = `${urls.credentialLibraries}/${instances.credentialLibrary.id}`;
urls.newCredentialLibrary = `${urls.credentialLibraries}/new`;
urls.unknownCredentialLibrary = `${urls.credentialLibraries}/foo`;
authenticateSession({});
});
test('can navigate to resource', async function (assert) {
assert.expect(1);
await visit(urls.credentialLibraries);
await click('main tbody .rose-table-header-cell a');
await a11yAudit();
assert.equal(currentURL(), urls.credentialLibrary);
});
test('cannot navigate to resource without proper authorization', async function (assert) {
assert.expect(1);
instances.credentialLibrary.authorized_actions =
instances.credentialLibrary.authorized_actions.filter(
(item) => item !== 'read'
);
await visit(urls.credentialLibraries);
assert.notOk(find('main tbody .rose-table-header-cell a'));
});
});
@@ -2,18 +2,13 @@ import { module, test } from 'qunit';
import { visit, click, fillIn, currentURL, find } from '@ember/test-helpers';
import { setupApplicationTest } from 'ember-qunit';
import setupMirage from 'ember-cli-mirage/test-support/setup-mirage';
import a11yAudit from 'ember-a11y-testing/test-support/audit';
import { authenticateSession } from 'ember-simple-auth/test-support';
import { Response } from 'miragejs';
import { resolve, reject } from 'rsvp';
import sinon from 'sinon';
module('Acceptance | credential-library', function (hooks) {
module('Acceptance | credential-libraries | update', function (hooks) {
setupApplicationTest(hooks);
setupMirage(hooks);
let getCredentialLibraryCount;
const instances = {
scopes: {
global: null,
@@ -50,6 +45,7 @@ module('Acceptance | credential-library', function (hooks) {
});
instances.credentialLibrary = this.server.create('credential-library', {
scope: instances.scopes.project,
credentialStore: instances.credentialStore,
});
// Generate route URLs for resources
urls.globalScope = `/scopes/global/scopes`;
@@ -61,83 +57,10 @@ module('Acceptance | credential-library', function (hooks) {
urls.credentialLibrary = `${urls.credentialLibraries}/${instances.credentialLibrary.id}`;
urls.newCredentialLibrary = `${urls.credentialLibraries}/new`;
urls.unknownCredentialLibrary = `${urls.credentialLibraries}/foo`;
// Generate resource counter
getCredentialLibraryCount = () =>
this.server.schema.credentialLibraries.all().models.length;
authenticateSession({});
});
test('visiting credential libraries', async function (assert) {
assert.expect(2);
await visit(urls.credentialLibraries);
await a11yAudit();
assert.equal(currentURL(), urls.credentialLibraries);
await visit(urls.credentialLibrary);
await a11yAudit();
assert.equal(currentURL(), urls.credentialLibrary);
});
test('visiting an unknown credential library displays 404 message', async function (assert) {
assert.expect(1);
await visit(urls.unknownCredentialLibrary);
await a11yAudit();
console.debug(find('.rose-message-subtitle'));
assert.ok(find('.rose-message-subtitle').textContent.trim(), 'Error 404');
});
test('can create a credential library', async function (assert) {
assert.expect(1);
const count = getCredentialLibraryCount();
await visit(urls.newCredentialLibrary);
await fillIn('[name="name"]', 'random string');
await click('[type="submit"]');
assert.equal(getCredentialLibraryCount(), count + 1);
});
test('can cancel create a new credential library', async function (assert) {
assert.expect(2);
const count = getCredentialLibraryCount();
await visit(urls.newCredentialLibrary);
await fillIn('[name="name"]', 'random string');
await click('.rose-form-actions [type="button"]');
assert.equal(currentURL(), urls.credentialLibraries);
assert.equal(getCredentialLibraryCount(), count);
});
test('saving a new credential library with invalid fields displays error messasges', async function (assert) {
assert.expect(2);
this.server.post('/credential-libraries', () => {
return new Response(
400,
{},
{
status: 400,
code: 'invalid_argument',
message: 'The request was invalid',
details: {
request_fields: [
{
name: 'name',
description: 'Name is required.',
},
],
},
}
);
});
await visit(urls.newCredentialLibrary);
await click('[type="submit"]');
assert.ok(
find('[role="alert"]').textContent.trim(),
'The request was invalid.'
);
assert.ok(
find('.rose-form-error-message').textContent.trim(),
'Name is required.'
);
});
test('can save changes to existing credential library', async function (assert) {
test('can update resource and save changes', async function (assert) {
assert.expect(3);
assert.notEqual(instances.credentialLibrary.name, 'random string');
await visit(urls.credentialLibrary);
@@ -151,7 +74,17 @@ module('Acceptance | credential-library', function (hooks) {
);
});
test('can cancel changes to existing credential library', async function (assert) {
test('cannot update resource without proper authorization', async function (assert) {
assert.expect(1);
instances.credentialLibrary.authorized_actions =
instances.credentialLibrary.authorized_actions.filter(
(item) => item !== 'update'
);
await visit(urls.credentialLibrary);
assert.notOk(find('form [type="button"]'));
});
test('can update a credential library and cancel changes', async function (assert) {
assert.expect(2);
await visit(urls.credentialLibrary);
await click('form [type="button"]', 'Activate edit mode');
@@ -245,54 +178,4 @@ module('Acceptance | credential-library', function (hooks) {
);
}
});
test('can delete credential library', async function (assert) {
assert.expect(1);
const count = getCredentialLibraryCount();
await visit(urls.credentialLibrary);
await click('.rose-layout-page-actions .rose-dropdown-button-danger');
assert.equal(getCredentialLibraryCount(), count - 1);
});
test('can accept delete credential library via dialog', async function (assert) {
assert.expect(2);
const confirmService = this.owner.lookup('service:confirm');
confirmService.enabled = true;
confirmService.confirm = sinon.fake.returns(resolve());
const count = getCredentialLibraryCount();
await visit(urls.credentialLibrary);
await click('.rose-layout-page-actions .rose-dropdown-button-danger');
assert.equal(getCredentialLibraryCount(), count - 1);
assert.ok(confirmService.confirm.calledOnce);
});
test('cannot cancel delete credential library via dialog', async function (assert) {
assert.expect(2);
const confirmService = this.owner.lookup('service:confirm');
confirmService.enabled = true;
confirmService.confirm = sinon.fake.returns(reject());
const count = getCredentialLibraryCount();
await visit(urls.credentialLibrary);
await click('.rose-layout-page-actions .rose-dropdown-button-danger');
assert.equal(getCredentialLibraryCount(), count);
assert.ok(confirmService.confirm.calledOnce);
});
test('deleting a credential library which errors displays error messages', async function (assert) {
assert.expect(1);
this.server.del('/credential-libraries/:id', () => {
return new Response(
490,
{},
{
status: 490,
code: 'error',
message: 'Oops.',
}
);
});
await visit(urls.credentialLibrary);
await click('.rose-layout-page-actions .rose-dropdown-button-danger');
assert.ok(find('[role="alert"]').textContent.trim(), 'Oops.');
});
});
-101
View File
@@ -2,7 +2,6 @@ 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 a11yAudit from 'ember-a11y-testing/test-support/audit';
import { Response } from 'miragejs';
import {
authenticateSession,
@@ -44,20 +43,6 @@ module('Acceptance | groups', function (hooks) {
urls.newGroup = `${urls.groups}/new`;
});
test('visiting groups', async function (assert) {
assert.expect(1);
await visit(urls.groups);
await a11yAudit();
assert.equal(currentURL(), urls.groups);
});
test('visiting a group', async function (assert) {
assert.expect(1);
await visit(urls.newGroup);
await a11yAudit();
assert.equal(currentURL(), urls.newGroup);
});
test('can create new group', async function (assert) {
assert.expect(1);
const groupsCount = this.server.db.groups.length;
@@ -112,90 +97,4 @@ module('Acceptance | groups', function (hooks) {
'Displays field-level errors.'
);
});
test('can save changes to an existing group', async function (assert) {
assert.expect(2);
await visit(urls.group);
await click('form [type="button"]', 'Activate edit mode');
await fillIn('[name="name"]', 'Updated admin group');
await click('.rose-form-actions [type="submit"]');
assert.equal(currentURL(), urls.group);
assert.equal(this.server.db.groups[0].name, 'Updated admin group');
});
test('can cancel changes to an existing group', async function (assert) {
assert.expect(1);
await visit(urls.group);
await click('form [type="button"]', 'Activate edit mode');
await fillIn('[name="name"]', 'Updated admin group');
await click('.rose-form-actions [type="button"]');
assert.notEqual(find('[name="name"]').value, 'Updated admin group');
});
test('can delete a group', async function (assert) {
assert.expect(1);
const groupsCount = this.server.db.groups.length;
await visit(urls.group);
await click('.rose-layout-page-actions .rose-dropdown-button-danger');
assert.equal(this.server.db.groups.length, groupsCount - 1);
});
test('saving an existing group with invalid fields displays error messages', async function (assert) {
assert.expect(2);
this.server.patch('/groups/:id', () => {
return new Response(
400,
{},
{
status: 400,
code: 'invalid_argument',
message: 'The request was invalid.',
details: {
request_fields: [
{
name: 'name',
description: 'Name is required.',
},
],
},
}
);
});
await visit(urls.group);
await click('form [type="button"]', 'Activate edit mode');
await fillIn('[name="name"]', 'random string');
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.'
);
});
test('errors are displayed when delete project fails', async function (assert) {
assert.expect(1);
this.server.del('/groups/:id', () => {
return new Response(
490,
{},
{
status: 490,
code: 'error',
message: 'Oops.',
}
);
});
await visit(urls.group);
await click('.rose-layout-page-actions .rose-dropdown-button-danger');
assert.ok(
find('[role="alert"]').textContent.trim(),
'Oops.',
'Displays primary error message.'
);
});
});
@@ -0,0 +1,85 @@
import { module, test } from 'qunit';
import { visit, click, 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';
module('Acceptance | groups | delete', function (hooks) {
setupApplicationTest(hooks);
setupMirage(hooks);
const instances = {
scopes: {
global: null,
org: null,
},
group: null,
};
const urls = {
orgScope: null,
groups: null,
group: null,
newGroup: null,
};
hooks.beforeEach(function () {
authenticateSession({});
instances.scopes.global = this.server.create('scope', { id: 'global' });
instances.scopes.org = this.server.create('scope', {
type: 'org',
scope: { id: 'global', type: 'global' },
});
instances.group = this.server.create('group', {
scope: instances.scopes.org,
});
urls.groups = `/scopes/${instances.scopes.org.id}/groups`;
urls.group = `${urls.groups}/${instances.group.id}`;
urls.newGroup = `${urls.groups}/new`;
});
test('can delete a group', async function (assert) {
assert.expect(1);
const groupsCount = this.server.db.groups.length;
await visit(urls.group);
await click('.rose-layout-page-actions .rose-dropdown-button-danger');
assert.equal(this.server.db.groups.length, groupsCount - 1);
});
test('cannot delete a group without proper authorization', async function (assert) {
assert.expect(1);
instances.group.authorized_actions =
instances.group.authorized_actions.filter((item) => item !== 'delete');
await visit(urls.group);
assert.notOk(
find('.rose-layout-page-actions .rose-dropdown-button-danger')
);
});
test('errors are displayed when delete project fails', async function (assert) {
assert.expect(1);
this.server.del('/groups/:id', () => {
return new Response(
490,
{},
{
status: 490,
code: 'error',
message: 'Oops.',
}
);
});
await visit(urls.group);
await click('.rose-layout-page-actions .rose-dropdown-button-danger');
assert.ok(
find('[role="alert"]').textContent.trim(),
'Oops.',
'Displays primary error message.'
);
});
});
@@ -0,0 +1,60 @@
import { module, test } from 'qunit';
import { visit, currentURL, find } from '@ember/test-helpers';
import { setupApplicationTest } from 'ember-qunit';
import setupMirage from 'ember-cli-mirage/test-support/setup-mirage';
import a11yAudit from 'ember-a11y-testing/test-support/audit';
import {
authenticateSession,
// These are left here intentionally for future reference.
//currentSession,
//invalidateSession,
} from 'ember-simple-auth/test-support';
module('Acceptance | groups | read', function (hooks) {
setupApplicationTest(hooks);
setupMirage(hooks);
const instances = {
scopes: {
global: null,
org: null,
},
group: null,
};
const urls = {
orgScope: null,
groups: null,
group: null,
newGroup: null,
};
hooks.beforeEach(function () {
authenticateSession({});
instances.scopes.global = this.server.create('scope', { id: 'global' });
instances.scopes.org = this.server.create('scope', {
type: 'org',
scope: { id: 'global', type: 'global' },
});
instances.group = this.server.create('group', {
scope: instances.scopes.org,
});
urls.groups = `/scopes/${instances.scopes.org.id}/groups`;
urls.group = `${urls.groups}/${instances.group.id}`;
urls.newGroup = `${urls.groups}/new`;
});
test('visiting a group', async function (assert) {
assert.expect(1);
await visit(urls.newGroup);
await a11yAudit();
assert.equal(currentURL(), urls.newGroup);
});
test('cannot navigate to a group form without proper authorization', async function (assert) {
assert.expect(1);
instances.group.authorized_actions =
instances.group.authorized_actions.filter((item) => item !== 'read');
await visit(urls.group);
assert.notOk(find('main tbody .rose-table-header-cell:nth-child(1) a'));
});
});
@@ -0,0 +1,109 @@
import { module, test } from 'qunit';
import { visit, currentURL, click, find, fillIn } 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';
module('Acceptance | groups | update', function (hooks) {
setupApplicationTest(hooks);
setupMirage(hooks);
const instances = {
scopes: {
global: null,
org: null,
},
group: null,
};
const urls = {
orgScope: null,
groups: null,
group: null,
newGroup: null,
};
hooks.beforeEach(function () {
authenticateSession({});
instances.scopes.global = this.server.create('scope', { id: 'global' });
instances.scopes.org = this.server.create('scope', {
type: 'org',
scope: { id: 'global', type: 'global' },
});
instances.group = this.server.create('group', {
scope: instances.scopes.org,
});
urls.groups = `/scopes/${instances.scopes.org.id}/groups`;
urls.group = `${urls.groups}/${instances.group.id}`;
urls.newGroup = `${urls.groups}/new`;
});
test('can save changes to an existing group', async function (assert) {
assert.expect(2);
await visit(urls.group);
await click('form [type="button"]', 'Activate edit mode');
await fillIn('[name="name"]', 'Updated admin group');
await click('.rose-form-actions [type="submit"]');
assert.equal(currentURL(), urls.group);
assert.equal(this.server.db.groups[0].name, 'Updated admin group');
});
test('cannot make changes to an existing group without proper authorization', async function (assert) {
assert.expect(1);
instances.group.authorized_actions =
instances.group.authorized_actions.filter((item) => item !== 'update');
await visit(urls.group);
assert.notOk(find('.rose-layout-page-actions .rose-button-secondary'));
});
test('can cancel changes to an existing group', async function (assert) {
assert.expect(1);
await visit(urls.group);
await click('form [type="button"]', 'Activate edit mode');
await fillIn('[name="name"]', 'Updated admin group');
await click('.rose-form-actions [type="button"]');
assert.notEqual(find('[name="name"]').value, 'Updated admin group');
});
test('saving an existing group with invalid fields displays error messages', async function (assert) {
assert.expect(2);
this.server.patch('/groups/:id', () => {
return new Response(
400,
{},
{
status: 400,
code: 'invalid_argument',
message: 'The request was invalid.',
details: {
request_fields: [
{
name: 'name',
description: 'Name is required.',
},
],
},
}
);
});
await visit(urls.group);
await click('form [type="button"]', 'Activate edit mode');
await fillIn('[name="name"]', 'random string');
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.'
);
});
});
-173
View File
@@ -2,10 +2,7 @@ import { module, test } from 'qunit';
import { visit, currentURL, find, click, fillIn } from '@ember/test-helpers';
import { setupApplicationTest } from 'ember-qunit';
import setupMirage from 'ember-cli-mirage/test-support/setup-mirage';
import a11yAudit from 'ember-a11y-testing/test-support/audit';
import { Response } from 'miragejs';
import { resolve, reject } from 'rsvp';
import sinon from 'sinon';
import {
authenticateSession,
// These are left here intentionally for future reference.
@@ -62,23 +59,6 @@ module('Acceptance | targets', function (hooks) {
authenticateSession({});
});
test('visiting targets', async function (assert) {
assert.expect(2);
await visit(urls.targets);
await a11yAudit();
assert.equal(currentURL(), urls.targets);
await visit(urls.target);
await a11yAudit();
assert.equal(currentURL(), urls.target);
});
test('visiting an unknown target displays 404 message', async function (assert) {
assert.expect(1);
await visit(urls.unknownTarget);
await a11yAudit();
assert.ok(find('.rose-message-subtitle').textContent.trim(), 'Error 404');
});
test('can create new targets', async function (assert) {
assert.expect(1);
const count = getTargetCount();
@@ -130,157 +110,4 @@ module('Acceptance | targets', function (hooks) {
'Name is required.'
);
});
test('can save changes to existing target', async function (assert) {
assert.expect(3);
assert.notEqual(instances.target.name, 'random string');
await visit(urls.target);
await click('form [type="button"]', 'Activate edit mode');
await fillIn('[name="name"]', 'random string');
await click('.rose-form-actions [type="submit"]');
assert.equal(currentURL(), urls.target);
assert.equal(
this.server.schema.targets.all().models[0].name,
'random string'
);
});
test('can cancel changes to existing target', async function (assert) {
assert.expect(2);
await visit(urls.target);
await click('form [type="button"]', 'Activate edit mode');
await fillIn('[name="name"]', 'random string');
await click('.rose-form-actions [type="button"]');
assert.notEqual(instances.target.name, 'random string');
assert.equal(find('[name="name"]').value, instances.target.name);
});
test('saving an existing target with invalid fields displays error messages', async function (assert) {
assert.expect(2);
this.server.patch('/targets/:id', () => {
return new Response(
400,
{},
{
status: 400,
code: 'invalid_argument',
message: 'The request was invalid.',
details: {
request_fields: [
{
name: 'name',
description: 'Name is required.',
},
],
},
}
);
});
await visit(urls.target);
await click('form [type="button"]', 'Activate edit mode');
await fillIn('[name="name"]', 'random string');
await click('[type="submit"]');
assert.ok(
find('[role="alert"]').textContent.trim(),
'The request was invalid.'
);
assert.ok(
find('.rose-form-error-message').textContent.trim(),
'Name is required.'
);
});
test('can discard unsaved target changes via dialog', async function (assert) {
assert.expect(5);
const confirmService = this.owner.lookup('service:confirm');
confirmService.enabled = true;
assert.notEqual(instances.target.name, 'random string');
await visit(urls.target);
await click('form [type="button"]', 'Activate edit mode');
await fillIn('[name="name"]', 'random string');
assert.equal(currentURL(), urls.target);
try {
await visit(urls.targets);
} catch (e) {
assert.ok(find('.rose-dialog'));
await click('.rose-dialog-footer button:first-child');
assert.equal(currentURL(), urls.targets);
assert.notEqual(
this.server.schema.targets.all().models[0].name,
'random string'
);
}
});
test('can cancel discard unsaved target changes via dialog', async function (assert) {
assert.expect(5);
const confirmService = this.owner.lookup('service:confirm');
confirmService.enabled = true;
assert.notEqual(instances.target.name, 'random string');
await visit(urls.target);
await click('form [type="button"]', 'Activate edit mode');
await fillIn('[name="name"]', 'random string');
assert.equal(currentURL(), urls.target);
try {
await visit(urls.targets);
} catch (e) {
assert.ok(find('.rose-dialog'));
await click('.rose-dialog-footer button:last-child');
assert.equal(currentURL(), urls.target);
assert.notEqual(
this.server.schema.targets.all().models[0].name,
'random string'
);
}
});
test('can delete target', async function (assert) {
assert.expect(1);
const count = getTargetCount();
await visit(urls.target);
await click('.rose-layout-page-actions .rose-dropdown-button-danger');
assert.equal(getTargetCount(), count - 1);
});
test('can accept delete target via dialog', async function (assert) {
assert.expect(2);
const confirmService = this.owner.lookup('service:confirm');
confirmService.enabled = true;
confirmService.confirm = sinon.fake.returns(resolve());
const count = getTargetCount();
await visit(urls.target);
await click('.rose-layout-page-actions .rose-dropdown-button-danger');
assert.equal(getTargetCount(), count - 1);
assert.ok(confirmService.confirm.calledOnce);
});
test('cannot cancel delete target via dialog', async function (assert) {
assert.expect(2);
const confirmService = this.owner.lookup('service:confirm');
confirmService.enabled = true;
confirmService.confirm = sinon.fake.returns(reject());
const count = getTargetCount();
await visit(urls.target);
await click('.rose-layout-page-actions .rose-dropdown-button-danger');
assert.equal(getTargetCount(), count);
assert.ok(confirmService.confirm.calledOnce);
});
test('deleting a target which errors displays error messages', async function (assert) {
assert.expect(1);
this.server.del('/targets/:id', () => {
return new Response(
490,
{},
{
status: 490,
code: 'error',
message: 'Oops.',
}
);
});
await visit(urls.target);
await click('.rose-layout-page-actions .rose-dropdown-button-danger');
assert.ok(find('[role="alert"]').textContent.trim(), 'Oops.');
});
});
@@ -0,0 +1,123 @@
import { module, test } from 'qunit';
import { visit, find, click } from '@ember/test-helpers';
import { setupApplicationTest } from 'ember-qunit';
import setupMirage from 'ember-cli-mirage/test-support/setup-mirage';
import { Response } from 'miragejs';
import { resolve, reject } from 'rsvp';
import sinon from 'sinon';
import {
authenticateSession,
// These are left here intentionally for future reference.
//currentSession,
//invalidateSession,
} from 'ember-simple-auth/test-support';
module('Acceptance | targets | delete', function (hooks) {
setupApplicationTest(hooks);
setupMirage(hooks);
let getTargetCount;
const instances = {
scopes: {
global: null,
org: null,
project: null,
},
};
const urls = {
globalScope: null,
orgScope: null,
projectScope: null,
targets: null,
target: null,
newTarget: null,
};
hooks.beforeEach(function () {
// Generate resources
instances.scopes.global = this.server.create('scope', { id: 'global' });
instances.scopes.org = this.server.create('scope', {
type: 'org',
scope: { id: 'global', type: 'global' },
});
instances.scopes.project = this.server.create('scope', {
type: 'project',
scope: { id: instances.scopes.org.id, type: 'org' },
});
instances.target = this.server.create('target', {
scope: instances.scopes.project,
});
// Generate route URLs for resources
urls.globalScope = `/scopes/global/scopes`;
urls.orgScope = `/scopes/${instances.scopes.org.id}/scopes`;
urls.projectScope = `/scopes/${instances.scopes.project.id}`;
urls.targets = `${urls.projectScope}/targets`;
urls.target = `${urls.targets}/${instances.target.id}`;
urls.unknownTarget = `${urls.targets}/foo`;
urls.newTarget = `${urls.targets}/new`;
// Generate resource couner
getTargetCount = () => this.server.schema.targets.all().models.length;
authenticateSession({});
});
test('can delete target', async function (assert) {
assert.expect(1);
const count = getTargetCount();
await visit(urls.target);
await click('.rose-layout-page-actions .rose-dropdown-button-danger');
assert.equal(getTargetCount(), count - 1);
});
test('can accept delete target via dialog', async function (assert) {
assert.expect(2);
const confirmService = this.owner.lookup('service:confirm');
confirmService.enabled = true;
confirmService.confirm = sinon.fake.returns(resolve());
const count = getTargetCount();
await visit(urls.target);
await click('.rose-layout-page-actions .rose-dropdown-button-danger');
assert.equal(getTargetCount(), count - 1);
assert.ok(confirmService.confirm.calledOnce);
});
test('cannot cancel delete target via dialog', async function (assert) {
assert.expect(2);
const confirmService = this.owner.lookup('service:confirm');
confirmService.enabled = true;
confirmService.confirm = sinon.fake.returns(reject());
const count = getTargetCount();
await visit(urls.target);
await click('.rose-layout-page-actions .rose-dropdown-button-danger');
assert.equal(getTargetCount(), count);
assert.ok(confirmService.confirm.calledOnce);
});
test('cannot delete target without proper authorization', async function (assert) {
assert.expect(1);
instances.target.authorized_actions =
instances.target.authorized_actions.filter((item) => item !== 'delete');
await visit(urls.target);
assert.notOk(
find('.rose-layout-page-actions .rose-dropdown-button-danger')
);
});
test('deleting a target which errors displays error messages', async function (assert) {
assert.expect(1);
this.server.del('/targets/:id', () => {
return new Response(
490,
{},
{
status: 490,
code: 'error',
message: 'Oops.',
}
);
});
await visit(urls.target);
await click('.rose-layout-page-actions .rose-dropdown-button-danger');
assert.ok(find('[role="alert"]').textContent.trim(), 'Oops.');
});
});
@@ -0,0 +1,83 @@
import { module, test } from 'qunit';
import { visit, currentURL, find } from '@ember/test-helpers';
import { setupApplicationTest } from 'ember-qunit';
import setupMirage from 'ember-cli-mirage/test-support/setup-mirage';
import a11yAudit from 'ember-a11y-testing/test-support/audit';
import {
authenticateSession,
// These are left here intentionally for future reference.
//currentSession,
//invalidateSession,
} from 'ember-simple-auth/test-support';
module('Acceptance | targets | read', function (hooks) {
setupApplicationTest(hooks);
setupMirage(hooks);
const instances = {
scopes: {
global: null,
org: null,
project: null,
},
};
const urls = {
globalScope: null,
orgScope: null,
projectScope: null,
targets: null,
target: null,
newTarget: null,
};
hooks.beforeEach(function () {
// Generate resources
instances.scopes.global = this.server.create('scope', { id: 'global' });
instances.scopes.org = this.server.create('scope', {
type: 'org',
scope: { id: 'global', type: 'global' },
});
instances.scopes.project = this.server.create('scope', {
type: 'project',
scope: { id: instances.scopes.org.id, type: 'org' },
});
instances.target = this.server.create('target', {
scope: instances.scopes.project,
});
// Generate route URLs for resources
urls.globalScope = `/scopes/global/scopes`;
urls.orgScope = `/scopes/${instances.scopes.org.id}/scopes`;
urls.projectScope = `/scopes/${instances.scopes.project.id}`;
urls.targets = `${urls.projectScope}/targets`;
urls.target = `${urls.targets}/${instances.target.id}`;
urls.unknownTarget = `${urls.targets}/foo`;
urls.newTarget = `${urls.targets}/new`;
// Generate resource couner
authenticateSession({});
});
test('visiting targets', async function (assert) {
assert.expect(2);
await visit(urls.targets);
await a11yAudit();
assert.equal(currentURL(), urls.targets);
await visit(urls.target);
await a11yAudit();
assert.equal(currentURL(), urls.target);
});
test('cannot navigate to target form without proper authorization', async function (assert) {
assert.expect(1);
instances.target.authorized_actions =
instances.target.authorized_actions.filter((item) => item !== 'read');
await visit(urls.target);
assert.notOk(find('main tbody .rose-table-header-cell:nth-child(1) a'));
});
test('visiting an unknown target displays 404 message', async function (assert) {
assert.expect(1);
await visit(urls.unknownTarget);
await a11yAudit();
assert.ok(find('.rose-message-subtitle').textContent.trim(), 'Error 404');
});
});
@@ -0,0 +1,202 @@
import { module, test } from 'qunit';
import { visit, currentURL, find, click, fillIn } 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';
module('Acceptance | targets | update', function (hooks) {
setupApplicationTest(hooks);
setupMirage(hooks);
const instances = {
scopes: {
global: null,
org: null,
project: null,
},
};
const urls = {
globalScope: null,
orgScope: null,
projectScope: null,
targets: null,
target: null,
newTarget: null,
};
hooks.beforeEach(function () {
// Generate resources
instances.scopes.global = this.server.create('scope', { id: 'global' });
instances.scopes.org = this.server.create('scope', {
type: 'org',
scope: { id: 'global', type: 'global' },
});
instances.scopes.project = this.server.create('scope', {
type: 'project',
scope: { id: instances.scopes.org.id, type: 'org' },
});
instances.target = this.server.create('target', {
scope: instances.scopes.project,
});
// Generate route URLs for resources
urls.globalScope = `/scopes/global/scopes`;
urls.orgScope = `/scopes/${instances.scopes.org.id}/scopes`;
urls.projectScope = `/scopes/${instances.scopes.project.id}`;
urls.targets = `${urls.projectScope}/targets`;
urls.target = `${urls.targets}/${instances.target.id}`;
urls.unknownTarget = `${urls.targets}/foo`;
urls.newTarget = `${urls.targets}/new`;
// Generate resource couner
authenticateSession({});
});
test('saving a new target with invalid fields displays error messages', async function (assert) {
assert.expect(2);
this.server.post('/targets', () => {
return new Response(
400,
{},
{
status: 400,
code: 'invalid_argument',
message: 'The request was invalid.',
details: {
request_fields: [
{
name: 'name',
description: 'Name is required.',
},
],
},
}
);
});
await visit(urls.newTarget);
await click('[type="submit"]');
assert.ok(
find('[role="alert"]').textContent.trim(),
'The request was invalid.'
);
assert.ok(
find('.rose-form-error-message').textContent.trim(),
'Name is required.'
);
});
test('can save changes to existing target', async function (assert) {
assert.expect(3);
assert.notEqual(instances.target.name, 'random string');
await visit(urls.target);
await click('form [type="button"]', 'Activate edit mode');
await fillIn('[name="name"]', 'random string');
await click('.rose-form-actions [type="submit"]');
assert.equal(currentURL(), urls.target);
assert.equal(
this.server.schema.targets.all().models[0].name,
'random string'
);
});
test('can cancel changes to existing target', async function (assert) {
assert.expect(2);
await visit(urls.target);
await click('form [type="button"]', 'Activate edit mode');
await fillIn('[name="name"]', 'random string');
await click('.rose-form-actions [type="button"]');
assert.notEqual(instances.target.name, 'random string');
assert.equal(find('[name="name"]').value, instances.target.name);
});
test('saving an existing target with invalid fields displays error messages', async function (assert) {
assert.expect(2);
this.server.patch('/targets/:id', () => {
return new Response(
400,
{},
{
status: 400,
code: 'invalid_argument',
message: 'The request was invalid.',
details: {
request_fields: [
{
name: 'name',
description: 'Name is required.',
},
],
},
}
);
});
await visit(urls.target);
await click('form [type="button"]', 'Activate edit mode');
await fillIn('[name="name"]', 'random string');
await click('[type="submit"]');
assert.ok(
find('[role="alert"]').textContent.trim(),
'The request was invalid.'
);
assert.ok(
find('.rose-form-error-message').textContent.trim(),
'Name is required.'
);
});
test('can discard unsaved target changes via dialog', async function (assert) {
assert.expect(5);
const confirmService = this.owner.lookup('service:confirm');
confirmService.enabled = true;
assert.notEqual(instances.target.name, 'random string');
await visit(urls.target);
await click('form [type="button"]', 'Activate edit mode');
await fillIn('[name="name"]', 'random string');
assert.equal(currentURL(), urls.target);
try {
await visit(urls.targets);
} catch (e) {
assert.ok(find('.rose-dialog'));
await click('.rose-dialog-footer button:first-child');
assert.equal(currentURL(), urls.targets);
assert.notEqual(
this.server.schema.targets.all().models[0].name,
'random string'
);
}
});
test('can cancel discard unsaved target changes via dialog', async function (assert) {
assert.expect(5);
const confirmService = this.owner.lookup('service:confirm');
confirmService.enabled = true;
assert.notEqual(instances.target.name, 'random string');
await visit(urls.target);
await click('form [type="button"]', 'Activate edit mode');
await fillIn('[name="name"]', 'random string');
assert.equal(currentURL(), urls.target);
try {
await visit(urls.targets);
} catch (e) {
assert.ok(find('.rose-dialog'));
await click('.rose-dialog-footer button:last-child');
assert.equal(currentURL(), urls.target);
assert.notEqual(
this.server.schema.targets.all().models[0].name,
'random string'
);
}
});
test('cannot make changes to an existing target without proper authorization', async function (assert) {
assert.expect(1);
instances.target.authorized_actions =
instances.target.authorized_actions.filter((item) => item !== 'update');
await visit(urls.target);
assert.notOk(find('.rose-layout-page-actions .rose-button-secondary'));
});
});
-107
View File
@@ -2,7 +2,6 @@ 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 a11yAudit from 'ember-a11y-testing/test-support/audit';
import { Response } from 'miragejs';
import {
authenticateSession,
@@ -17,7 +16,6 @@ module('Acceptance | users', function (hooks) {
let orgScope;
let usersURL;
let userURL;
let newUserURL;
hooks.beforeEach(function () {
@@ -29,31 +27,12 @@ module('Acceptance | users', function (hooks) {
'withChildren'
);
const user = this.server.create('user', {
scope: orgScope,
});
usersURL = `/scopes/${orgScope.id}/users`;
userURL = `${usersURL}/${user.id}`;
newUserURL = `${usersURL}/new`;
authenticateSession({});
});
test('visiting users', async function (assert) {
assert.expect(1);
await visit(usersURL);
await a11yAudit();
assert.equal(currentURL(), usersURL);
});
test('visiting a user', async function (assert) {
assert.expect(1);
await visit(newUserURL);
await a11yAudit();
assert.equal(currentURL(), newUserURL);
});
test('can create new users', async function (assert) {
assert.expect(1);
const usersCount = this.server.db.users.length;
@@ -108,90 +87,4 @@ module('Acceptance | users', function (hooks) {
'Displays field-level errors.'
);
});
test('can save changes to an existing user', async function (assert) {
assert.expect(2);
await visit(userURL);
await click('form [type="button"]', 'Activate edit mode');
await fillIn('[name="name"]', 'Updated user name');
await click('.rose-form-actions [type="submit"]');
assert.equal(currentURL(), userURL);
assert.equal(this.server.db.users[0].name, 'Updated user name');
});
test('can cancel changes to an existing user', async function (assert) {
assert.expect(1);
await visit(userURL);
await click('form [type="button"]', 'Activate edit mode');
await fillIn('[name="name"]', 'Unsaved user name');
await click('.rose-form-actions [type="button"]');
assert.notEqual(find('[name="name"]').value, 'Unsaved user name');
});
test('can delete an user', async function (assert) {
assert.expect(1);
const usersCount = this.server.db.users.length;
await visit(userURL);
await click('.rose-layout-page-actions .rose-dropdown-button-danger');
assert.equal(this.server.db.users.length, usersCount - 1);
});
test('saving an existing user with invalid fields displays error messages', async function (assert) {
assert.expect(2);
this.server.patch('/users/:id', () => {
return new Response(
400,
{},
{
status: 400,
code: 'invalid_argument',
message: 'The request was invalid.',
details: {
request_fields: [
{
name: 'name',
description: 'Name is required.',
},
],
},
}
);
});
await visit(userURL);
await click('form [type="button"]', 'Activate edit mode');
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.'
);
});
test('errors are displayed when user deletion fails', async function (assert) {
assert.expect(1);
this.server.del('/users/:id', () => {
return new Response(
490,
{},
{
status: 490,
code: 'error',
message: 'Oops.',
}
);
});
await visit(userURL);
await click('.rose-layout-page-actions .rose-dropdown-button-danger');
assert.ok(
find('[role="alert"]').textContent.trim(),
'Oops.',
'Displays primary error message.'
);
});
});
@@ -0,0 +1,86 @@
import { module, test } from 'qunit';
import { visit, click, 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';
module('Acceptance | users | delete', function (hooks) {
setupApplicationTest(hooks);
setupMirage(hooks);
let orgScope;
let usersURL;
let userURL;
const instances = {
scopes: {
global: null,
org: null,
},
user: null,
};
hooks.beforeEach(function () {
orgScope = this.server.create(
'scope',
{
type: 'org',
},
'withChildren'
);
instances.user = this.server.create('user', {
scope: orgScope,
});
//instances.user = this.server.schema.users.all().models[0];
usersURL = `/scopes/${orgScope.id}/users`;
userURL = `${usersURL}/${instances.user.id}`;
authenticateSession({});
});
test('can delete an user', async function (assert) {
assert.expect(1);
const usersCount = this.server.db.users.length;
await visit(userURL);
await click('.rose-layout-page-actions .rose-dropdown-button-danger');
assert.equal(this.server.db.users.length, usersCount - 1);
});
test('cannot delete a user without proper authorization', async function (assert) {
assert.expect(1);
instances.user.authorized_actions =
instances.user.authorized_actions.filter((item) => item !== 'delete');
await visit(userURL);
assert.notOk(
find('.rose-layout-page-actions .rose-dropdown-button-danger')
);
});
test('errors are displayed when user deletion fails', async function (assert) {
assert.expect(1);
this.server.del('/users/:id', () => {
return new Response(
490,
{},
{
status: 490,
code: 'error',
message: 'Oops.',
}
);
});
await visit(userURL);
await click('.rose-layout-page-actions .rose-dropdown-button-danger');
assert.ok(
find('[role="alert"]').textContent.trim(),
'Oops.',
'Displays primary error message.'
);
});
});
@@ -0,0 +1,57 @@
import { module, test } from 'qunit';
import { visit, currentURL, find } from '@ember/test-helpers';
import { setupApplicationTest } from 'ember-qunit';
import setupMirage from 'ember-cli-mirage/test-support/setup-mirage';
import a11yAudit from 'ember-a11y-testing/test-support/audit';
import {
authenticateSession,
// These are left here intentionally for future reference.
//currentSession,
//invalidateSession,
} from 'ember-simple-auth/test-support';
module('Acceptance | users | read', function (hooks) {
setupApplicationTest(hooks);
setupMirage(hooks);
let orgScope;
let usersURL;
const instances = {
scopes: {
global: null,
org: null,
},
user: null,
};
hooks.beforeEach(function () {
orgScope = this.server.create(
'scope',
{
type: 'org',
},
'withChildren'
);
instances.user = this.server.create('user', {
scope: orgScope,
});
usersURL = `/scopes/${orgScope.id}/users`;
authenticateSession({});
});
test('visiting users', async function (assert) {
assert.expect(1);
await visit(usersURL);
await a11yAudit();
assert.equal(currentURL(), usersURL);
});
test('cannot navigate to an account form without proper authorization', async function (assert) {
assert.expect(1);
instances.user.authorized_actions =
instances.user.authorized_actions.filter((item) => item !== 'read');
await visit(usersURL);
assert.notOk(find('main tbody .rose-table-header-cell:nth-child(1) a'));
});
});
@@ -0,0 +1,110 @@
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';
module('Acceptance | users | update', function (hooks) {
setupApplicationTest(hooks);
setupMirage(hooks);
let orgScope;
let usersURL;
let userURL;
const instances = {
scopes: {
global: null,
org: null,
},
user: null,
};
hooks.beforeEach(function () {
orgScope = this.server.create(
'scope',
{
type: 'org',
},
'withChildren'
);
instances.user = this.server.create('user', {
scope: orgScope,
});
usersURL = `/scopes/${orgScope.id}/users`;
userURL = `${usersURL}/${instances.user.id}`;
authenticateSession({});
});
test('can save changes to an existing user', async function (assert) {
assert.expect(2);
await visit(userURL);
await click('form [type="button"]', 'Activate edit mode');
await fillIn('[name="name"]', 'Updated user name');
await click('.rose-form-actions [type="submit"]');
assert.equal(currentURL(), userURL);
assert.equal(this.server.db.users[0].name, 'Updated user name');
});
test('cannot make changes to an existing user without proper authorization', async function (assert) {
assert.expect(1);
instances.user.authorized_actions =
instances.user.authorized_actions.filter((item) => item !== 'update');
await visit(userURL);
assert.notOk(find('.rose-layout-page-actions .rose-button-secondary'));
});
test('can cancel changes to an existing user', async function (assert) {
assert.expect(1);
await visit(userURL);
await click('form [type="button"]', 'Activate edit mode');
await fillIn('[name="name"]', 'Unsaved user name');
await click('.rose-form-actions [type="button"]');
assert.notEqual(find('[name="name"]').value, 'Unsaved user name');
});
test('saving an existing user with invalid fields displays error messages', async function (assert) {
assert.expect(2);
this.server.patch('/users/:id', () => {
return new Response(
400,
{},
{
status: 400,
code: 'invalid_argument',
message: 'The request was invalid.',
details: {
request_fields: [
{
name: 'name',
description: 'Name is required.',
},
],
},
}
);
});
await visit(userURL);
await click('form [type="button"]', 'Activate edit mode');
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.'
);
});
});
+1
View File
@@ -0,0 +1 @@
{"compilerOptions":{"target":"es6","experimentalDecorators":true},"exclude":["node_modules","bower_components","tmp","vendor",".git","dist"]}