From 037086b521684aee9fce8a81b9c4e55a034b3b04 Mon Sep 17 00:00:00 2001 From: Randall Morey Date: Mon, 8 Jun 2020 18:56:28 -0400 Subject: [PATCH] =?UTF-8?q?chore:=20=F0=9F=A4=96=20add=20host=20catalog=20?= =?UTF-8?q?acceptance=20tests?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../tests/acceptance/host-catalogs-test.js | 209 ++++++++++++++++++ ui/core/tests/acceptance/projects-test.js | 1 + 2 files changed, 210 insertions(+) create mode 100644 ui/core/tests/acceptance/host-catalogs-test.js diff --git a/ui/core/tests/acceptance/host-catalogs-test.js b/ui/core/tests/acceptance/host-catalogs-test.js new file mode 100644 index 000000000..acdacafa7 --- /dev/null +++ b/ui/core/tests/acceptance/host-catalogs-test.js @@ -0,0 +1,209 @@ +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'; + +module('Acceptance | host catalogs', function(hooks) { + setupApplicationTest(hooks); + setupMirage(hooks); + + 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'); + await a11yAudit(); + assert.equal(currentURL(), '/orgs/1/projects/1/host-catalogs'); + }); + + 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 ul li:first-child a'); + await a11yAudit(); + assert.equal(currentURL(), '/orgs/1/projects/1/host-catalogs/1'); + }); + + 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'); + await click('.rose-button-warning'); + assert.equal(this.server.db.hostCatalogs.length, 0); + }); + + 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'); + await fillIn('[name="name"]', 'Test Name'); + await click('form [type="submit"]:not(:disabled)'); + assert.equal(this.server.db.hostCatalogs[0].name, 'Test Name'); + }); + + 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'); + 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'); + 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'); + }); + + 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'); + 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'); + }); + + 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', () => { + return new Response( + 490, + {}, + { + status: 490, + code: 'error', + message: 'Oops.', + } + ); + }); + await visit('/orgs/1/projects/1/host-catalogs/1'); + await fillIn('[name="name"]', 'random string'); + await click('form [type="submit"]'); + await a11yAudit(); + assert.ok( + find('[role="alert"]').textContent.trim(), + 'Oops.', + 'Displays primary error message.' + ); + }); + + 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', () => { + return new Response( + 490, + {}, + { + status: 490, + code: 'error', + message: 'Oops.', + } + ); + }); + await visit('/orgs/1/projects/1/host-catalogs/1'); + await click('.rose-button-warning'); + await a11yAudit(); + assert.ok( + find('[role="alert"]').textContent.trim(), + 'Oops.', + 'Displays primary error message.' + ); + }); + + 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', () => { + return new Response( + 400, + {}, + { + status: 400, + code: 'invalid_argument', + message: 'The request was invalid.', + details: { + fields: [ + { + name: 'name', + message: 'Name is required.', + }, + ], + }, + } + ); + }); + this.server.createList('project', 1); + await visit('/orgs/1/projects/1/host-catalogs/new'); + await fillIn('[name="name"]', 'random string'); + await click('form [type="submit"]'); + await a11yAudit(); + 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('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', () => { + return new Response( + 400, + {}, + { + status: 400, + code: 'invalid_argument', + message: 'The request was invalid.', + details: { + fields: [ + { + name: 'name', + message: 'Name is required.', + }, + ], + }, + } + ); + }); + await visit('/orgs/1/projects/1/host-catalogs/1'); + await fillIn('[name="name"]', 'random string'); + await click('form [type="submit"]'); + await a11yAudit(); + 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.' + ); + }); + +}); diff --git a/ui/core/tests/acceptance/projects-test.js b/ui/core/tests/acceptance/projects-test.js index a98601b19..612da5ffb 100644 --- a/ui/core/tests/acceptance/projects-test.js +++ b/ui/core/tests/acceptance/projects-test.js @@ -11,6 +11,7 @@ module('Acceptance | projects', function (hooks) { test('visiting projects', async function (assert) { assert.expect(1); + this.server.createList('project', 1); await visit('/orgs/1/projects'); await a11yAudit(); assert.equal(currentURL(), '/orgs/1/projects');