From 3fe86614f120e92a66795c98e39764d2ec513a51 Mon Sep 17 00:00:00 2001 From: Randall Morey Date: Wed, 29 Jul 2020 11:20:37 -0400 Subject: [PATCH] test: add host catalogs acceptance tests --- .../tests/acceptance/host-catalogs-test.js | 130 +++++++++++------- 1 file changed, 83 insertions(+), 47 deletions(-) diff --git a/ui/core/tests/acceptance/host-catalogs-test.js b/ui/core/tests/acceptance/host-catalogs-test.js index 4be43309f..682f9c163 100644 --- a/ui/core/tests/acceptance/host-catalogs-test.js +++ b/ui/core/tests/acceptance/host-catalogs-test.js @@ -1,52 +1,92 @@ import { module, test } from 'qunit'; -import { visit, currentURL, click, fillIn, find } 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 { Response } from 'miragejs'; +import { +// currentSession, + authenticateSession, +// invalidateSession, +} from 'ember-simple-auth/test-support'; module('Acceptance | host catalogs', function(hooks) { setupApplicationTest(hooks); setupMirage(hooks); + const instances = { + scopes: { + global: null, + org: null, + project: null + }, + hostCatalog: null + }; + const urls = { + orgScope: null, + projects: null, + project: null, + hostCatalogs: null, + newHostCatalog: null, + hostCatalog: null + }; + hooks.beforeEach(function () { - this.server.create('org'); + // Setup Mirage mock resources for this test + instances.scopes.global = this.server.create('scope', { id: 'global' }); + instances.scopes.org = this.server.create('scope', { type: 'org', + scope: { id: instances.scopes.global.id, type: instances.scopes.global.type } + }); + instances.scopes.project = this.server.create('scope', { type: 'project', + scope: { id: instances.scopes.org.id, type: instances.scopes.org.type } + }); + instances.hostCatalog = this.server.create('host-catalog', { + scope: { + id: instances.scopes.project.id, + type: instances.scopes.project.type + } + }); + + // 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.newHostCatalog = `${urls.hostCatalogs}/new`; + urls.hostCatalog = `${urls.hostCatalogs}/${instances.hostCatalog.id}`; }); test('visiting host catalogs', async function (assert) { assert.expect(1); - this.server.createList('project', 1); - this.server.createList('host-catalog', 1); - await visit('/orgs/1/projects/1/host-catalogs'); + authenticateSession(); + await visit(urls.hostCatalogs); await a11yAudit(); - assert.equal(currentURL(), '/orgs/1/projects/1/host-catalogs'); + assert.equal(currentURL(), urls.hostCatalogs); }); test('can navigate to host catalog form', async function(assert) { assert.expect(1); - this.server.createList('project', 1); - this.server.createList('host-catalog', 1); - await visit('/orgs/1/projects/1/host-catalogs'); - await click('main .rose-table-cell:first-child a'); + authenticateSession({}); + await visit(urls.hostCatalogs); + await click('main tbody .rose-table-cell:nth-child(2) a'); await a11yAudit(); - assert.equal(currentURL(), '/orgs/1/projects/1/host-catalogs/1'); + assert.equal(currentURL(), urls.hostCatalog); }); test('can delete host catalog', async function(assert) { assert.expect(2); - this.server.createList('project', 1); - this.server.createList('host-catalog', 1); - assert.equal(this.server.db.hostCatalogs.length, 1); - await visit('/orgs/1/projects/1/host-catalogs/1'); + const hostCatalogsCount = this.server.db.hostCatalogs.length; + authenticateSession({}); + await visit(urls.hostCatalog); + assert.equal(currentURL(), urls.hostCatalog); await click('.rose-button-warning'); - assert.equal(this.server.db.hostCatalogs.length, 0); + assert.equal(this.server.db.hostCatalogs.length, hostCatalogsCount - 1); }); test('can update host catalog and save changes', async function(assert) { assert.expect(1); - this.server.createList('project', 1); - this.server.createList('host-catalog', 1); - await visit('/orgs/1/projects/1/host-catalogs/1'); + authenticateSession({}); + await visit(urls.hostCatalog); await fillIn('[name="name"]', 'Test Name'); await click('form [type="submit"]:not(:disabled)'); assert.equal(this.server.db.hostCatalogs[0].name, 'Test Name'); @@ -54,39 +94,36 @@ module('Acceptance | host catalogs', function(hooks) { test('can update host catalog and cancel changes', async function(assert) { assert.expect(1); - this.server.createList('project', 1); - this.server.createList('host-catalog', 1); - await visit('/orgs/1/projects/1/host-catalogs/1'); + authenticateSession({}); + await visit(urls.hostCatalog); await fillIn('[name="name"]', 'Test Name'); await click('form button:not([type="submit"])'); assert.notEqual(this.server.db.hostCatalogs[0].name, 'Test Name'); }); test('can create host catalog and save changes', async function(assert) { - assert.expect(2); - this.server.createList('project', 1); - await visit('/orgs/1/projects/1/host-catalogs/new'); + assert.expect(1); + const hostCatalogsCount = this.server.db.hostCatalogs.length; + authenticateSession({}); + await visit(urls.newHostCatalog); await fillIn('[name="name"]', 'Test Name'); await click('form [type="submit"]:not(:disabled)'); - assert.equal(this.server.db.hostCatalogs.length, 1); - assert.equal(currentURL(), '/orgs/1/projects/1/host-catalogs/1'); + assert.equal(this.server.db.hostCatalogs.length, hostCatalogsCount + 1); }); test('can create host catalog and cancel changes', async function(assert) { - assert.expect(2); - this.server.createList('project', 1); - await visit('/orgs/1/projects/1/host-catalogs/new'); + assert.expect(1); + const hostCatalogsCount = this.server.db.hostCatalogs.length; + authenticateSession({}); + await visit(urls.newHostCatalog); await fillIn('[name="name"]', 'Test Name'); await click('form button:not([type="submit"])'); - assert.equal(this.server.db.hostCatalogs.length, 0); - assert.equal(currentURL(), '/orgs/1/projects/1/host-catalogs'); + assert.equal(this.server.db.hostCatalogs.length, hostCatalogsCount); }); test('errors are displayed when save host catalog fails', async function (assert) { assert.expect(1); - this.server.createList('project', 1); - this.server.createList('host-catalog', 1); - this.server.patch('/orgs/:org_id/projects/:project_id/host-catalogs/:id', () => { + this.server.patch('/scopes/:scope_id/host-catalogs/:id', () => { return new Response( 490, {}, @@ -97,7 +134,8 @@ module('Acceptance | host catalogs', function(hooks) { } ); }); - await visit('/orgs/1/projects/1/host-catalogs/1'); + authenticateSession({}); + await visit(urls.hostCatalog); await fillIn('[name="name"]', 'random string'); await click('form [type="submit"]'); await a11yAudit(); @@ -110,9 +148,7 @@ module('Acceptance | host catalogs', function(hooks) { test('errors are displayed when delete host catalog fails', async function (assert) { assert.expect(1); - this.server.createList('project', 1); - this.server.createList('host-catalog', 1); - this.server.del('/orgs/:org_id/projects/:project_id/host-catalogs/:id', () => { + this.server.del('/scopes/:scope_id/host-catalogs/:id', () => { return new Response( 490, {}, @@ -123,7 +159,8 @@ module('Acceptance | host catalogs', function(hooks) { } ); }); - await visit('/orgs/1/projects/1/host-catalogs/1'); + authenticateSession({}); + await visit(urls.hostCatalog); await click('.rose-button-warning'); await a11yAudit(); assert.ok( @@ -135,7 +172,7 @@ module('Acceptance | host catalogs', function(hooks) { test('saving a new host catalog with invalid fields displays error messages', async function (assert) { assert.expect(2); - this.server.post('/orgs/:org_id/projects/:project_id/host-catalogs', () => { + this.server.post('/scopes/:scope_id/host-catalogs', () => { return new Response( 400, {}, @@ -154,8 +191,8 @@ module('Acceptance | host catalogs', function(hooks) { } ); }); - this.server.createList('project', 1); - await visit('/orgs/1/projects/1/host-catalogs/new'); + authenticateSession({}); + await visit(urls.newHostCatalog); await fillIn('[name="name"]', 'random string'); await click('form [type="submit"]'); await a11yAudit(); @@ -173,9 +210,7 @@ module('Acceptance | host catalogs', function(hooks) { test('saving an existing host catalog with invalid fields displays error messages', async function (assert) { assert.expect(2); - this.server.createList('project', 1); - this.server.createList('host-catalog', 1); - this.server.patch('/orgs/:org_id/projects/:project_id/host-catalogs/:id', () => { + this.server.patch('/scopes/:scope_id/host-catalogs/:id', () => { return new Response( 400, {}, @@ -194,7 +229,8 @@ module('Acceptance | host catalogs', function(hooks) { } ); }); - await visit('/orgs/1/projects/1/host-catalogs/1'); + authenticateSession({}); + await visit(urls.hostCatalog); await fillIn('[name="name"]', 'random string'); await click('form [type="submit"]'); await a11yAudit();