From 547446546379fe2f268dc0d4c0a68b03554a2e76 Mon Sep 17 00:00:00 2001 From: lisbet-alvarez <107949262+lisbet-alvarez@users.noreply.github.com> Date: Wed, 7 Dec 2022 10:32:08 -0800 Subject: [PATCH] =?UTF-8?q?refactor:=20=F0=9F=92=A1=20acceptance=20tests?= =?UTF-8?q?=20in=20scopes=20folder=20(#1509)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit ✅ Closes: ICU-7126 --- .../tests/acceptance/scopes/delete-test.js | 81 ++++++------ ui/admin/tests/acceptance/scopes/read-test.js | 27 ++-- .../tests/acceptance/scopes/update-test.js | 115 ++++++++---------- 3 files changed, 112 insertions(+), 111 deletions(-) diff --git a/ui/admin/tests/acceptance/scopes/delete-test.js b/ui/admin/tests/acceptance/scopes/delete-test.js index c0d5ef406..304f8ee66 100644 --- a/ui/admin/tests/acceptance/scopes/delete-test.js +++ b/ui/admin/tests/acceptance/scopes/delete-test.js @@ -1,10 +1,8 @@ import { module, test } from 'qunit'; -import { visit, find, click } from '@ember/test-helpers'; +import { visit, click, currentURL } 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. @@ -22,21 +20,15 @@ module('Acceptance | scopes | delete', function (hooks) { scopes: { global: null, org: null, - org2: null, project: null, - project2: null, }, }; const urls = { globalScope: null, orgScope: null, - org2Scope: null, orgScopeEdit: null, - org2ScopeEdit: null, projectScope: null, - project2Scope: null, projectScopeEdit: null, - project2ScopeEdit: null, }; hooks.beforeEach(function () { @@ -46,78 +38,81 @@ module('Acceptance | scopes | delete', function (hooks) { type: 'org', scope: { id: 'global', type: 'global' }, }); - instances.scopes.org2 = 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.scopes.project2 = this.server.create('scope', { - type: 'project', - scope: { id: instances.scopes.org.id, type: 'org' }, - }); // Generate route URLs for resources urls.globalScope = `/scopes/global/scopes`; - urls.newOrgScope = `/scopes/global/new`; urls.orgScope = `/scopes/${instances.scopes.org.id}/scopes`; - urls.org2Scope = `/scopes/${instances.scopes.org2.id}/scopes`; urls.orgScopeEdit = `/scopes/${instances.scopes.org.id}/edit`; - urls.org2ScopeEdit = `/scopes/${instances.scopes.org2.id}/edit`; - urls.newProjectScope = `/scopes/${instances.scopes.org.id}/new`; urls.projectScope = `/scopes/${instances.scopes.project.id}`; - urls.project2Scope = `/scopes/${instances.scopes.project2.id}`; - urls.projectScopeEdit = `/scopes/${instances.scopes.project.id}/edit`; - urls.project2ScopeEdit = `/scopes/${instances.scopes.project2.id}/edit`; - // Generate resource couner + // Generate resource counter getScopeCount = (type) => this.server.schema.scopes.where({ type }).length; - authenticateSession({}); + authenticateSession({ isGlobal: true }); }); test('can delete scope', async function (assert) { assert.expect(1); const orgScopeCount = getScopeCount('org'); - await visit(urls.orgScopeEdit); + await visit(urls.orgScope); + + await click(`[href="${urls.orgScopeEdit}"]`); await click('.rose-layout-page-actions .rose-dropdown-button-danger'); + assert.strictEqual(getScopeCount('org'), orgScopeCount - 1); }); test('cannot delete scope without proper authorization', async function (assert) { - assert.expect(1); - instances.scopes.org.update({ authorized_actions: [] }); - await visit(urls.orgScopeEdit); - assert.notOk( - find('.rose-layout-page-actions .rose-dropdown-button-danger') - ); + assert.expect(2); + instances.scopes.org.update({ + authorized_actions: instances.scopes.org.authorized_actions.filter( + (item) => item !== 'delete' + ), + }); + await visit(urls.orgScope); + + await click(`[href="${urls.orgScopeEdit}"]`); + + assert.false(instances.scopes.org.authorized_actions.includes('delete')); + assert + .dom('.rose-layout-page-actions .rose-dropdown-button-danger') + .doesNotExist(); }); test('can accept delete scope 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 orgScopeCount = getScopeCount('org'); - await visit(urls.orgScopeEdit); + await visit(urls.orgScope); + + await click(`[href="${urls.orgScopeEdit}"]`); await click('.rose-layout-page-actions .rose-dropdown-button-danger'); + await click('.rose-dialog .rose-button-primary'); + assert.strictEqual(getScopeCount('org'), orgScopeCount - 1); - assert.ok(confirmService.confirm.calledOnce); + assert.strictEqual(currentURL(), urls.globalScope); }); - test('cannot cancel delete scope via dialog', async function (assert) { + test('can cancel delete scope 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 orgScopeCount = getScopeCount('org'); - await visit(urls.orgScopeEdit); + await visit(urls.orgScope); + + await click(`[href="${urls.orgScopeEdit}"]`); await click('.rose-layout-page-actions .rose-dropdown-button-danger'); + await click('.rose-dialog .rose-button-secondary'); + assert.strictEqual(getScopeCount('org'), orgScopeCount); - assert.ok(confirmService.confirm.calledOnce); + assert.strictEqual(currentURL(), urls.orgScopeEdit); }); test('deleting a scope which errors displays error messages', async function (assert) { assert.expect(1); + await visit(urls.orgScope); this.server.del('/scopes/:id', () => { return new Response( 490, @@ -129,8 +124,10 @@ module('Acceptance | scopes | delete', function (hooks) { } ); }); - await visit(urls.orgScopeEdit); + + await click(`[href="${urls.orgScopeEdit}"]`); await click('.rose-layout-page-actions .rose-dropdown-button-danger'); - assert.ok(find('[role="alert"]').textContent.trim(), 'Oops.'); + + assert.dom('.rose-notification-body').hasText('Oops.'); }); }); diff --git a/ui/admin/tests/acceptance/scopes/read-test.js b/ui/admin/tests/acceptance/scopes/read-test.js index 846f689fb..485c96ca5 100644 --- a/ui/admin/tests/acceptance/scopes/read-test.js +++ b/ui/admin/tests/acceptance/scopes/read-test.js @@ -1,5 +1,5 @@ import { module, test } from 'qunit'; -import { visit, currentURL, find } from '@ember/test-helpers'; +import { visit, currentURL, click } 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'; @@ -21,6 +21,7 @@ module('Acceptance | scopes | read', function (hooks) { }, }; const urls = { + orgScope: null, orgScopeEdit: null, }; @@ -32,24 +33,34 @@ module('Acceptance | scopes | read', function (hooks) { scope: { id: 'global', type: 'global' }, }); // Generate route URLs for resources + urls.orgScope = `/scopes/${instances.scopes.org.id}/scopes`; urls.orgScopeEdit = `/scopes/${instances.scopes.org.id}/edit`; - // Generate resource couner - authenticateSession({}); + authenticateSession({ isGlobal: true }); }); test('visiting org scope edit', async function (assert) { assert.expect(2); - await visit(urls.orgScopeEdit); + await visit(urls.orgScope); await a11yAudit(); + + await click(`[href="${urls.orgScopeEdit}"]`); + await a11yAudit(); + assert.strictEqual(currentURL(), urls.orgScopeEdit); - assert.ok(find('main .rose-form')); + assert.dom('main .rose-form').exists(); }); test('visiting org scope edit without read permission results in no form displayed', async function (assert) { assert.expect(2); - instances.scopes.org.update({ authorized_actions: [] }); - await visit(urls.orgScopeEdit); + instances.scopes.org.update({ + authorized_actions: instances.scopes.org.authorized_actions.filter( + (item) => item !== 'read' + ), + }); + await visit(urls.orgScope); + + await click(`[href="${urls.orgScopeEdit}"]`); assert.strictEqual(currentURL(), urls.orgScopeEdit); - assert.notOk(find('main .rose-form')); + assert.dom('main .rose-form').doesNotExist(); }); }); diff --git a/ui/admin/tests/acceptance/scopes/update-test.js b/ui/admin/tests/acceptance/scopes/update-test.js index 6e2c88489..8141b8fff 100644 --- a/ui/admin/tests/acceptance/scopes/update-test.js +++ b/ui/admin/tests/acceptance/scopes/update-test.js @@ -1,5 +1,5 @@ import { module, test } from 'qunit'; -import { visit, currentURL, find, click, fillIn } from '@ember/test-helpers'; +import { visit, currentURL, 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'; @@ -18,21 +18,14 @@ module('Acceptance | scopes | update', function (hooks) { scopes: { global: null, org: null, - org2: null, project: null, - project2: null, }, }; const urls = { globalScope: null, orgScope: null, - org2Scope: null, orgScopeEdit: null, - org2ScopeEdit: null, projectScope: null, - project2Scope: null, - projectScopeEdit: null, - project2ScopeEdit: null, }; hooks.beforeEach(function () { @@ -50,32 +43,24 @@ module('Acceptance | scopes | update', function (hooks) { type: 'project', scope: { id: instances.scopes.org.id, type: 'org' }, }); - instances.scopes.project2 = this.server.create('scope', { - type: 'project', - scope: { id: instances.scopes.org.id, type: 'org' }, - }); // Generate route URLs for resources urls.globalScope = `/scopes/global/scopes`; - urls.newOrgScope = `/scopes/global/new`; urls.orgScope = `/scopes/${instances.scopes.org.id}/scopes`; - urls.org2Scope = `/scopes/${instances.scopes.org2.id}/scopes`; urls.orgScopeEdit = `/scopes/${instances.scopes.org.id}/edit`; - urls.org2ScopeEdit = `/scopes/${instances.scopes.org2.id}/edit`; - urls.newProjectScope = `/scopes/${instances.scopes.org.id}/new`; urls.projectScope = `/scopes/${instances.scopes.project.id}`; - urls.project2Scope = `/scopes/${instances.scopes.project2.id}`; - urls.projectScopeEdit = `/scopes/${instances.scopes.project.id}/edit`; - urls.project2ScopeEdit = `/scopes/${instances.scopes.project2.id}/edit`; - authenticateSession({}); + authenticateSession({ isGlobal: true }); }); test('can save changes to existing scope', async function (assert) { assert.expect(3); assert.notEqual(instances.scopes.org.name, 'random string'); - await visit(urls.orgScopeEdit); + await visit(urls.orgScope); + + await click(`[href="${urls.orgScopeEdit}"]`); await click('form [type="button"]', 'Activate edit mode'); await fillIn('[name="name"]', 'random string'); await click('.rose-form-actions [type="submit"]'); + assert.strictEqual(currentURL(), urls.orgScopeEdit); assert.strictEqual( this.server.schema.scopes.where({ type: 'org' }).models[0].name, @@ -84,24 +69,36 @@ module('Acceptance | scopes | update', function (hooks) { }); test('cannot save changes to without proper authorization', async function (assert) { - assert.expect(1); - instances.scopes.org.update({ authorized_actions: [] }); - await visit(urls.orgScopeEdit); - assert.notOk(find('form [type="button"]')); + assert.expect(2); + instances.scopes.org.update({ + authorized_actions: instances.scopes.org.authorized_actions.filter( + (item) => item !== 'update' + ), + }); + await visit(urls.orgScope); + + await click(`[href="${urls.orgScopeEdit}"]`); + + assert.false(instances.scopes.org.authorized_actions.includes('update')); + assert.dom('form [type="button"]').doesNotExist(); }); test('can cancel changes to existing scope', async function (assert) { assert.expect(2); - await visit(urls.orgScopeEdit); + await visit(urls.orgScope); + + await click(`[href="${urls.orgScopeEdit}"]`); await click('form [type="button"]', 'Activate edit mode'); await fillIn('[name="name"]', 'random string'); await click('.rose-form-actions [type="button"]'); + assert.notEqual(instances.scopes.org.name, 'random string'); - assert.strictEqual(find('[name="name"]').value, instances.scopes.org.name); + assert.dom('[name="name"]').hasValue(instances.scopes.org.name); }); test('saving an existing scope with invalid fields displays error messages', async function (assert) { assert.expect(2); + await visit(urls.orgScope); this.server.patch('/scopes/:id', () => { return new Response( 400, @@ -121,18 +118,14 @@ module('Acceptance | scopes | update', function (hooks) { } ); }); - await visit(urls.orgScopeEdit); + + await click(`[href="${urls.orgScopeEdit}"]`); 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('.hds-form-error__message').textContent.trim(), - 'Name is required.' - ); + + assert.dom('[role="alert"] div').hasText('The request was invalid.'); + assert.dom('.hds-form-error__message').hasText('Name is required.'); }); test('can discard unsaved scope changes via dialog', async function (assert) { @@ -140,42 +133,42 @@ module('Acceptance | scopes | update', function (hooks) { const confirmService = this.owner.lookup('service:confirm'); confirmService.enabled = true; assert.notEqual(instances.scopes.org.name, 'random string'); - await visit(urls.orgScopeEdit); + await visit(urls.orgScope); + + await click(`[href="${urls.orgScopeEdit}"]`); await click('form [type="button"]', 'Activate edit mode'); await fillIn('[name="name"]', 'random string'); assert.strictEqual(currentURL(), urls.orgScopeEdit); - try { - await visit(urls.globalScope); - } catch (e) { - assert.ok(find('.rose-dialog')); - await click('.rose-dialog-footer button:first-child'); - assert.strictEqual(currentURL(), urls.globalScope); - assert.notEqual( - this.server.schema.scopes.where({ type: 'org' }).models[0].name, - 'random string' - ); - } + await click(`[href="${urls.globalScope}"]`); + assert.dom('.rose-dialog').exists(); + await click('.rose-dialog-footer button:first-child', 'Click Discard'); + + assert.strictEqual(currentURL(), urls.globalScope); + assert.notEqual( + this.server.schema.scopes.where({ type: 'org' }).models[0].name, + 'random string' + ); }); - test('can cancel discard unsaved scope changes via dialog', async function (assert) { + test('can click cancel on discard dialog box for unsaved scope changes', async function (assert) { assert.expect(5); const confirmService = this.owner.lookup('service:confirm'); confirmService.enabled = true; assert.notEqual(instances.scopes.org.name, 'random string'); - await visit(urls.orgScopeEdit); + await visit(urls.orgScope); + + await click(`[href="${urls.orgScopeEdit}"]`); await click('form [type="button"]', 'Activate edit mode'); await fillIn('[name="name"]', 'random string'); assert.strictEqual(currentURL(), urls.orgScopeEdit); - try { - await visit(urls.globalScope); - } catch (e) { - assert.ok(find('.rose-dialog')); - await click('.rose-dialog-footer button:last-child'); - assert.strictEqual(currentURL(), urls.orgScopeEdit); - assert.notEqual( - this.server.schema.scopes.where({ type: 'org' }).models[0].name, - 'random string' - ); - } + await click(`[href="${urls.globalScope}"]`); + assert.dom('.rose-dialog').exists(); + await click('.rose-dialog-footer button:last-child', 'Click Cancel'); + + assert.strictEqual(currentURL(), urls.orgScopeEdit); + assert.notEqual( + this.server.schema.scopes.where({ type: 'org' }).models[0].name, + 'random string' + ); }); });