From 32e26989d5c560725a2ddf1643ccdff7c6b85bd8 Mon Sep 17 00:00:00 2001 From: Susmitha Girumala Date: Wed, 23 Sep 2020 18:35:45 -0400 Subject: [PATCH] test: Add hostsets acceptance test --- .../host-catalogs/host-sets-test.js | 32 +++- ui/core/tests/acceptance/host-sets-test.js | 181 +++++++++++++----- ui/core/tests/acceptance/hosts-test.js | 1 - 3 files changed, 169 insertions(+), 45 deletions(-) diff --git a/ui/core/tests/acceptance/host-catalogs/host-sets-test.js b/ui/core/tests/acceptance/host-catalogs/host-sets-test.js index 2c90b8ada..d7cd8a32a 100644 --- a/ui/core/tests/acceptance/host-catalogs/host-sets-test.js +++ b/ui/core/tests/acceptance/host-catalogs/host-sets-test.js @@ -1,8 +1,9 @@ import { module, test } from 'qunit'; -import { visit, currentURL, fillIn, click, findAll } from '@ember/test-helpers'; +import { visit, currentURL, fillIn, click, find, findAll } 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, // These are left here intentionally for future reference. @@ -99,4 +100,33 @@ module('Acceptance | host catalogs | host sets', function (hooks) { assert.equal(currentURL(), urls.hostSets); assert.equal(findAll('tbody tr').length, hostSetsCount); }); + + test('saving a new host set with invalid fields displays error messages', async function (assert) { + assert.expect(2); + this.server.post('/host-sets', () => { + 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.newHostSet); + await fillIn('[name="name"]', 'new target'); + await click('form [type="submit"]'); + await a11yAudit(); + assert.ok(find('[role="alert"]')); + assert.ok(find('.rose-form-error-message')); + }); }); diff --git a/ui/core/tests/acceptance/host-sets-test.js b/ui/core/tests/acceptance/host-sets-test.js index 741283838..3c69e1b0e 100644 --- a/ui/core/tests/acceptance/host-sets-test.js +++ b/ui/core/tests/acceptance/host-sets-test.js @@ -1,73 +1,168 @@ import { module, test } from 'qunit'; -//import { visit, currentURL } from '@ember/test-helpers'; +import { visit, currentURL, fillIn, click, 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'; +import a11yAudit from 'ember-a11y-testing/test-support/audit'; +import { Response } from 'miragejs'; +import { + authenticateSession, + // These are left here intentionally for future reference. + //currentSession, + //invalidateSession, +} from 'ember-simple-auth/test-support'; module('Acceptance | host sets', function (hooks) { setupApplicationTest(hooks); setupMirage(hooks); + const instances = { + scopes: { + global: null, + org: null, + project: null, + }, + hostCatalog: null, + hostSet: null, + }; + const urls = { + orgScope: null, + projects: null, + project: null, + hostCatalogs: null, + hostCatalog: null, + hostSets: null, + hostSet: null, + }; + hooks.beforeEach(function () { // Setup Mirage mock resources for this test + 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.scopes.project = this.server.create('scope', { + type: 'project', + scope: { id: instances.scopes.org.id, type: 'org' }, + }); + instances.hostCatalog = this.server.create('host-catalog', { + scope: instances.scopes.project, + }); + instances.hostSet = this.server.create('host-set', { + scope: instances.scopes.project, + hostCatalog: instances.hostCatalog + }); // Generate route URLs for resources + urls.orgScope = `/scopes/${instances.scopes.org.id}`; + urls.projects = `${urls.orgScope}/projects`; + urls.project = `${urls.projects}/${instances.hostCatalog.scope.id}`; + urls.hostCatalogs = `${urls.project}/host-catalogs`; + urls.hostCatalog = `${urls.hostCatalogs}/${instances.hostCatalog.id}`; + urls.hostSets = `${urls.hostCatalog}/host-sets`; + urls.hostSet = `${urls.hostSets}/${instances.hostSet.id}`; }); - test('visiting host sets', async function (assert) { - assert.expect(0); - }); - - test('can navigate to a host set form', async function (assert) { - assert.expect(0); + test('visiting a host set', async function (assert) { + assert.expect(1); + await visit(urls.hostSet); + await a11yAudit(); + assert.equal(currentURL(), urls.hostSet); }); test('can update a host set and save changes', async function (assert) { - assert.expect(0); + assert.expect(3); + await visit(urls.hostSet); + await fillIn('[name="name"]', 'Updated name'); + await fillIn('[name="description"]', 'Updated description'); + await click('.rose-form-actions [type="submit"]'); + assert.equal(currentURL(), urls.hostSet); + assert.equal(this.server.db.hostSets[0].name, 'Updated name'); + assert.equal(this.server.db.hostSets[0].description, 'Updated description'); }); test('can update a host set and cancel changes', async function (assert) { - assert.expect(0); + assert.expect(1); + await visit(urls.hostSet); + await fillIn('[name="name"]', 'Updated name'); + await click('.rose-form-actions [type="button"]'); + assert.notEqual(find('[name="name"]').value, 'Updated name'); }); - test('can create new host set', async function (assert) { - assert.expect(0); - }); - - test('can cancel new host set creation', async function (assert) { - assert.expect(0); - }); - - test('saving a new host set with invalid fields displays error messages', async function (assert) { - assert.expect(0); - }); - - test('errors are displayed when save on host set fails', async function (assert) { - assert.expect(0); - }); - - test('errors are displayed when delete on a host set fails', async function (assert) { - assert.expect(0); + test('can delete host set', async function (assert) { + assert.expect(2); + const hostSetsCount = this.server.db.hostSets.length; + await visit(urls.hostSet); + await click('.rose-layout-page-actions .rose-dropdown-button-danger'); + assert.equal(currentURL(), urls.hostSets); + assert.equal(this.server.db.hostSets.length, hostSetsCount - 1); }); test('saving an existing host set with invalid fields displays error messages', async function (assert) { - assert.expect(0); + assert.expect(2); + this.server.patch('/host-sets/: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.hostSet); + await fillIn('[name="name"]', 'existing host'); + await click('[type="submit"]'); + await a11yAudit(); + assert.ok(find('[role="alert"]')); + assert.ok(find('.rose-form-error-message')); }); - test('can view hosts associated with a host set', async function (assert) { - assert.expect(0); + test('errors are displayed when save on host set fails', async function (assert) { + assert.expect(1); + this.server.patch('/host-sets/:id', () => { + return new Response( + 490, + {}, + { + status: 490, + code: 'error', + message: 'Oops.', + } + ); + }); + await visit(urls.hostSet); + await fillIn('[name="name"]', 'save host'); + await click('form [type="submit"]'); + await a11yAudit(); + assert.ok(find('[role="alert"]')); }); - test('can add/remove host associations to a host set and save', async function (assert) { - assert.expect(0); - }); - - test('can cancel add/remove host associations to a host set', async function (assert) { - assert.expect(0); + test('errors are displayed when delete on a host set fails', async function (assert) { + assert.expect(1); + this.server.del('/host-sets/:id', () => { + return new Response( + 490, + {}, + { + status: 490, + code: 'error', + message: 'Oops.', + } + ); + }); + await visit(urls.hostSet); + await click('.rose-layout-page-actions .rose-dropdown-button-danger'); + await a11yAudit(); + assert.ok(find('[role="alert"]')); }); }); diff --git a/ui/core/tests/acceptance/hosts-test.js b/ui/core/tests/acceptance/hosts-test.js index fd8f580f4..27881f02b 100644 --- a/ui/core/tests/acceptance/hosts-test.js +++ b/ui/core/tests/acceptance/hosts-test.js @@ -32,7 +32,6 @@ module('Acceptance | hosts', function (hooks) { hostCatalog: null, hosts: null, host: null, - newHost: null }; hooks.beforeEach(function () {