From 50518e7c4fa25adbad943d92c279a51024b4940b Mon Sep 17 00:00:00 2001 From: Susmitha Girumala Date: Wed, 23 Sep 2020 17:24:42 -0400 Subject: [PATCH] test: Add hosts in host catalog test --- .../host-catalogs/host-sets-test.js | 7 +- .../acceptance/host-catalogs/hosts-test.js | 102 ++++++++++++++++++ 2 files changed, 108 insertions(+), 1 deletion(-) 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 ae4421eab..2c90b8ada 100644 --- a/ui/core/tests/acceptance/host-catalogs/host-sets-test.js +++ b/ui/core/tests/acceptance/host-catalogs/host-sets-test.js @@ -21,6 +21,7 @@ module('Acceptance | host catalogs | host sets', function (hooks) { project: null, }, hostCatalog: null, + hostSets: null, }; const urls = { orgScope: null, @@ -47,7 +48,11 @@ module('Acceptance | host catalogs | host sets', function (hooks) { }); instances.hostCatalog = this.server.create('host-catalog', { scope: instances.scopes.project, - }, 'withChildren'); + }); + instances.hostSets = this.server.createList('host-set', 3, { + scope: instances.scopes.project, + hostCatalog: instances.hostCatalog + }); hostSetsCount = instances.hostCatalog.hostSetIds.length; // Generate route URLs for resources urls.orgScope = `/scopes/${instances.scopes.org.id}`; diff --git a/ui/core/tests/acceptance/host-catalogs/hosts-test.js b/ui/core/tests/acceptance/host-catalogs/hosts-test.js index e69de29bb..5b4720a24 100644 --- a/ui/core/tests/acceptance/host-catalogs/hosts-test.js +++ b/ui/core/tests/acceptance/host-catalogs/hosts-test.js @@ -0,0 +1,102 @@ +import { module, test } from 'qunit'; +import { visit, currentURL, fillIn, click, 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 { + authenticateSession, + // These are left here intentionally for future reference. + //currentSession, + //invalidateSession, +} from 'ember-simple-auth/test-support'; + +module('Acceptance | host catalogs | hosts', function (hooks) { + setupApplicationTest(hooks); + setupMirage(hooks); + + const instances = { + scopes: { + global: null, + org: null, + project: null, + }, + hostCatalog: null, + hosts: null, + }; + const urls = { + orgScope: null, + projects: null, + project: null, + hostCatalogs: null, + hostCatalog: null, + hosts: null, + newHost: null + }; + let hostsCount; + + 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.hosts = this.server.createList('host', 3, { + scope: instances.scopes.project, + hostCatalog: instances.hostCatalog + }); + hostsCount = instances.hosts.length; + // 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.hosts = `${urls.hostCatalog}/hosts`; + urls.newHost = `${urls.hosts}/new`; + }); + + test('visiting hosts', async function (assert) { + assert.expect(3); + await visit(urls.hosts); + await a11yAudit(); + assert.equal(currentURL(), urls.hosts); + assert.ok(hostsCount); + assert.equal(findAll('tbody tr').length, hostsCount); + }); + + test('can navigate to a host form', async function (assert) { + assert.expect(1); + await visit(urls.hosts); + await click('main tbody .rose-table-header-cell:nth-child(1) a'); + await a11yAudit(); + assert.notEqual(currentURL(), urls.hosts); + }); + + test('can create host and save changes', async function (assert) { + assert.expect(1); + await visit(urls.newHost); + await fillIn('[name="name"]', 'Test Name'); + await fillIn('[name="description"]', 'description'); + await click('form [type="submit"]:not(:disabled)'); + await visit(urls.hosts); + assert.equal(findAll('tbody tr').length, hostsCount + 1); + }); + + test('can create host and cancel changes', async function (assert) { + assert.expect(2); + await visit(urls.newHost); + await fillIn('[name="name"]', 'Test Name'); + await click('form button:not([type="submit"])'); + assert.equal(currentURL(), urls.hosts); + assert.equal(findAll('tbody tr').length, hostsCount); + }); +});