From 74d161f6f59a7ae66d88509f1127a3d8095ad8ff Mon Sep 17 00:00:00 2001 From: Carlos Alcaide Corvo Date: Wed, 10 Nov 2021 16:49:41 -0800 Subject: [PATCH 1/5] =?UTF-8?q?test:=20=F0=9F=92=8D=20Add=20acceptance=20t?= =?UTF-8?q?ests=20to=20create=20managed=20groups?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Add acceptance test to create managed groups --- .../acceptance/managed-groups/create-test.js | 160 ++++++++++++++++++ 1 file changed, 160 insertions(+) create mode 100644 ui/admin/tests/acceptance/managed-groups/create-test.js diff --git a/ui/admin/tests/acceptance/managed-groups/create-test.js b/ui/admin/tests/acceptance/managed-groups/create-test.js new file mode 100644 index 000000000..eeae7cef7 --- /dev/null +++ b/ui/admin/tests/acceptance/managed-groups/create-test.js @@ -0,0 +1,160 @@ +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 { authenticateSession } from 'ember-simple-auth/test-support'; +import a11yAudit from 'ember-a11y-testing/test-support/audit'; + +module('Acceptance | managed-groups | create', function (hooks) { + setupApplicationTest(hooks); + setupMirage(hooks); + + const instances = { + scopes: { + global: null, + org: null, + }, + authMethod: null, + managedGroup: null, + }; + const urls = { + orgScope: null, + authMethods: null, + managedGroups: null, + newManagedGroup: null, + managedGroup: 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.authMethod = this.server.create('auth-method', { + scope: instances.scopes.org, + type: 'oidc', + }); + instances.managedGroup = this.server.create('managed-group', { + scope: instances.scopes.org, + authMethod: instances.authMethod, + }); + // Generate route URLs for resources + urls.orgScope = `/scopes/${instances.scopes.org.id}`; + urls.authMethods = `${urls.orgScope}/auth-methods`; + urls.authMethod = `${urls.authMethods}/${instances.authMethod.id}`; + urls.managedGroups = `${urls.authMethod}/managed-groups`; + urls.newManagedGroup = `${urls.managedGroups}/new`; + urls.managedGroup = `${urls.managedGroups}/${instances.authMethod.id}`; + }); + + hooks.afterEach(async function () { + const notification = find('.rose-notification'); + if (notification) { + await click('.rose-notification-dismiss'); + } + }); + + test('visiting managed groups', async function (assert) { + assert.expect(1); + await visit(urls.managedGroups); + await a11yAudit(); + assert.equal(currentURL(), urls.managedGroups); + }); + + test('can create a new managed group', async function (assert) { + assert.expect(1); + const managedGroupsCount = this.server.db.managedGroups.length; + await visit(urls.newManagedGroup); + await fillIn('[name="name"]', 'Managed group name'); + await fillIn('[name="description"]', 'description'); + await click('form [type="submit"]:not(:disabled)'); + assert.equal(this.server.db.managedGroups.length, managedGroupsCount + 1); + }); + + test('User can not create a new managed group without proper authorization', async function (assert) { + assert.expect(2); + instances.authMethod.authorized_collection_actions['managed-groups'] = []; + await visit(urls.authMethod); + assert.notOk( + instances.authMethod.authorized_collection_actions[ + 'managed-groups' + ].includes('create') + ); + assert.notOk( + find(`.rose-layout-page-actions [href="${urls.newManagedGroup}"]`) + ); + }); + + test('User can navigate to new managed group route with proper authorization', async function (assert) { + assert.expect(2); + await visit(urls.managedGroups); + assert.ok( + instances.authMethod.authorized_collection_actions[ + 'managed-groups' + ].includes('create') + ); + assert.ok(find(`[href="${urls.newManagedGroup}"]`)); + }); + + test('User cannot navigate to new managed group route without proper authorization', async function (assert) { + assert.expect(2); + instances.authMethod.authorized_collection_actions['managed-groups'] = []; + await visit(urls.managedGroups); + assert.notOk( + instances.authMethod.authorized_collection_actions[ + 'managed-groups' + ].includes('create') + ); + assert.notOk(find(`[href="${urls.newManagedGroup}"]`)); + }); + + test('User can cancel a new managed group creation', async function (assert) { + assert.expect(2); + const managedGroupsCount = this.server.db.managedGroups.length; + await visit(urls.newManagedGroup); + await fillIn('[name="name"]', 'Managed group name'); + await click('form button:not([type="submit"])'); + assert.equal(this.server.db.managedGroups.length, managedGroupsCount); + assert.equal(currentURL(), urls.managedGroups); + }); + + // Temporary skipping this test because we did not implement mandatory fields in manageg groups + test.skip('When user saving a new managed group with invalid fields displays error message', async function (assert) { + assert.expect(2); + this.server.post('/managed-groups', () => { + 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.newManagedGroup); + await fillIn('[name="name"]', 'new managed group'); + await click('form [type="submit"]'); + await a11yAudit(); + assert.equal( + find('.rose-notification-body').textContent.trim(), + 'The request was invalid.', + 'Displays primary error message.' + ); + assert.equal( + find('.rose-form-error-message').textContent.trim(), + 'Name is required.', + 'Displays field-level errors.' + ); + }); +}); From bf8392ff9f95ddb45d1f086b04a35417ea352545 Mon Sep 17 00:00:00 2001 From: Carlos Alcaide Corvo Date: Wed, 10 Nov 2021 17:19:04 -0800 Subject: [PATCH 2/5] =?UTF-8?q?test:=20=F0=9F=92=8D=20Add=20acceptance=20t?= =?UTF-8?q?est=20to=20delete=20managed=20groups?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Add acceptance test to delete managed groups --- .../acceptance/managed-groups/delete-test.js | 103 ++++++++++++++++++ 1 file changed, 103 insertions(+) create mode 100644 ui/admin/tests/acceptance/managed-groups/delete-test.js diff --git a/ui/admin/tests/acceptance/managed-groups/delete-test.js b/ui/admin/tests/acceptance/managed-groups/delete-test.js new file mode 100644 index 000000000..e0e324cf5 --- /dev/null +++ b/ui/admin/tests/acceptance/managed-groups/delete-test.js @@ -0,0 +1,103 @@ +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 { authenticateSession } from 'ember-simple-auth/test-support'; +import a11yAudit from 'ember-a11y-testing/test-support/audit'; +import { Response } from 'miragejs'; + +module('Acceptance | managed-groups | delete', function (hooks) { + setupApplicationTest(hooks); + setupMirage(hooks); + + const instances = { + scopes: { + global: null, + org: null, + }, + authMethod: null, + managedGroup: null, + }; + const urls = { + orgScope: null, + authMethods: null, + managedGroups: null, + newManagedGroup: null, + managedGroup: 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.authMethod = this.server.create('auth-method', { + scope: instances.scopes.org, + type: 'oidc', + }); + instances.managedGroup = this.server.create('managed-group', { + scope: instances.scopes.org, + authMethod: instances.authMethod, + }); + // Generate route URLs for resources + urls.orgScope = `/scopes/${instances.scopes.org.id}`; + urls.authMethods = `${urls.orgScope}/auth-methods`; + urls.authMethod = `${urls.authMethods}/${instances.authMethod.id}`; + urls.managedGroups = `${urls.authMethod}/managed-groups`; + urls.newManagedGroup = `${urls.managedGroups}/new`; + // TODO refactor in the rest of the test this url + urls.managedGroup = `${urls.managedGroups}/${instances.managedGroup.id}`; + }); + + hooks.afterEach(async function () { + const notification = find('.rose-notification'); + if (notification) { + await click('.rose-notification-dismiss'); + } + }); + + test('User can delete a managed group', async function (assert) { + assert.expect(1); + const managedGroupsCount = this.server.db.managedGroups.length; + await visit(urls.managedGroup); + await click('.rose-layout-page-actions .rose-dropdown-button-danger'); + assert.equal(this.server.db.managedGroups.length, managedGroupsCount - 1); + }); + + test('User cannot delete a managed-group without proper authorization', async function (assert) { + assert.expect(1); + instances.managedGroup.authorized_actions = + instances.managedGroup.authorized_actions.filter( + (item) => item !== 'delete' + ); + await visit(urls.managedGroup); + assert.notOk( + find('.rose-layout-page-actions .rose-dropdown-button-danger') + ); + }); + + test('Errors are displayed when delete on managed group fails', async function (assert) { + assert.expect(1); + this.server.del('/managed-groups/:id', () => { + return new Response( + 490, + {}, + { + status: 490, + code: 'error', + message: 'Oops.', + } + ); + }); + await visit(urls.managedGroup); + await click('.rose-layout-page-actions .rose-dropdown-button-danger'); + await a11yAudit(); + assert.equal( + find('.rose-notification-body').textContent.trim(), + 'Oops.', + 'Displays primary error message.' + ); + }); +}); From 19d8bc44c8a5a9300302a444761c045e3554c58e Mon Sep 17 00:00:00 2001 From: Carlos Alcaide Corvo Date: Wed, 10 Nov 2021 17:26:27 -0800 Subject: [PATCH 3/5] Fix lint error --- ui/admin/tests/acceptance/managed-groups/delete-test.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ui/admin/tests/acceptance/managed-groups/delete-test.js b/ui/admin/tests/acceptance/managed-groups/delete-test.js index e0e324cf5..7be2263ab 100644 --- a/ui/admin/tests/acceptance/managed-groups/delete-test.js +++ b/ui/admin/tests/acceptance/managed-groups/delete-test.js @@ -1,5 +1,5 @@ import { module, test } from 'qunit'; -import { visit, currentURL, click, find, fillIn } from '@ember/test-helpers'; +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'; From 50a9a980ed4d63b953d4cdfbfd96803a065890c4 Mon Sep 17 00:00:00 2001 From: Carlos Alcaide Corvo Date: Wed, 10 Nov 2021 17:34:31 -0800 Subject: [PATCH 4/5] =?UTF-8?q?test:=20=F0=9F=92=8D=20Add=20acceptance=20t?= =?UTF-8?q?est=20to=20read=20managed=20groups?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Add acceptance test to read managed groups --- .../acceptance/managed-groups/read-test.js | 77 +++++++++++++++++++ 1 file changed, 77 insertions(+) create mode 100644 ui/admin/tests/acceptance/managed-groups/read-test.js diff --git a/ui/admin/tests/acceptance/managed-groups/read-test.js b/ui/admin/tests/acceptance/managed-groups/read-test.js new file mode 100644 index 000000000..ef11179c8 --- /dev/null +++ b/ui/admin/tests/acceptance/managed-groups/read-test.js @@ -0,0 +1,77 @@ +import { module, test } from 'qunit'; +import { visit, click, find, currentURL } 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 a11yAudit from 'ember-a11y-testing/test-support/audit'; + +module('Acceptance | managed-groups | read', function (hooks) { + setupApplicationTest(hooks); + setupMirage(hooks); + + const instances = { + scopes: { + global: null, + org: null, + }, + authMethod: null, + managedGroup: null, + }; + const urls = { + orgScope: null, + authMethods: null, + managedGroups: null, + newManagedGroup: null, + managedGroup: 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.authMethod = this.server.create('auth-method', { + scope: instances.scopes.org, + type: 'oidc', + }); + instances.managedGroup = this.server.create('managed-group', { + scope: instances.scopes.org, + authMethod: instances.authMethod, + }); + // Generate route URLs for resources + urls.orgScope = `/scopes/${instances.scopes.org.id}`; + urls.authMethods = `${urls.orgScope}/auth-methods`; + urls.authMethod = `${urls.authMethods}/${instances.authMethod.id}`; + urls.managedGroups = `${urls.authMethod}/managed-groups`; + urls.newManagedGroup = `${urls.managedGroups}/new`; + // TODO refactor in the rest of the test this url + urls.managedGroup = `${urls.managedGroups}/${instances.managedGroup.id}`; + }); + + hooks.afterEach(async function () { + const notification = find('.rose-notification'); + if (notification) { + await click('.rose-notification-dismiss'); + } + }); + + test('User can navigate to a managed group form', async function (assert) { + assert.expect(1); + await visit(urls.managedGroups); + await click('main tbody .rose-table-header-cell:nth-child(1) a'); + await a11yAudit(); + assert.equal(currentURL(), urls.managedGroup); + }); + + test('User cannot navigate to a managed group form without proper authorization', async function (assert) { + assert.expect(1); + instances.managedGroup.authorized_actions = + instances.managedGroup.authorized_actions.filter( + (item) => item !== 'read' + ); + await visit(urls.managedGroups); + assert.notOk(find('main tbody .rose-table-header-cell:nth-child(1) a')); + }); +}); From cc151b001ba2dafe8954cb550e2d101e41920227 Mon Sep 17 00:00:00 2001 From: Susmitha Girumala Date: Fri, 12 Nov 2021 09:27:07 -0500 Subject: [PATCH 5/5] test: Removed skipped managed group error notification test --- ui/admin/tests/acceptance/managed-groups/create-test.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/ui/admin/tests/acceptance/managed-groups/create-test.js b/ui/admin/tests/acceptance/managed-groups/create-test.js index eeae7cef7..8d07893e4 100644 --- a/ui/admin/tests/acceptance/managed-groups/create-test.js +++ b/ui/admin/tests/acceptance/managed-groups/create-test.js @@ -4,6 +4,7 @@ import { setupApplicationTest } from 'ember-qunit'; import setupMirage from 'ember-cli-mirage/test-support/setup-mirage'; import { authenticateSession } from 'ember-simple-auth/test-support'; import a11yAudit from 'ember-a11y-testing/test-support/audit'; +import { Response } from 'miragejs'; module('Acceptance | managed-groups | create', function (hooks) { setupApplicationTest(hooks); @@ -120,8 +121,7 @@ module('Acceptance | managed-groups | create', function (hooks) { assert.equal(currentURL(), urls.managedGroups); }); - // Temporary skipping this test because we did not implement mandatory fields in manageg groups - test.skip('When user saving a new managed group with invalid fields displays error message', async function (assert) { + test('When user saving a new managed group with invalid fields displays error message', async function (assert) { assert.expect(2); this.server.post('/managed-groups', () => { return new Response(