From f2f0144e5b7ccd07ad49841a272a41cb80aedc64 Mon Sep 17 00:00:00 2001 From: Randall Morey Date: Tue, 16 Jun 2020 09:40:03 -0400 Subject: [PATCH] =?UTF-8?q?test:=20=F0=9F=92=8D=20use=20breadcrumbs=20acce?= =?UTF-8?q?ptance=20tests=20for=20navigation?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ui/core/tests/acceptance/bread-crumbs-test.js | 98 ++++++++----------- 1 file changed, 41 insertions(+), 57 deletions(-) diff --git a/ui/core/tests/acceptance/bread-crumbs-test.js b/ui/core/tests/acceptance/bread-crumbs-test.js index 6e302588d..8515916d0 100644 --- a/ui/core/tests/acceptance/bread-crumbs-test.js +++ b/ui/core/tests/acceptance/bread-crumbs-test.js @@ -1,5 +1,5 @@ import { module, test } from 'qunit'; -import { visit, currentURL, click, findAll } from '@ember/test-helpers'; +import { visit, currentURL, click, find, findAll } from '@ember/test-helpers'; import { setupApplicationTest } from 'ember-qunit'; import setupMirage from 'ember-cli-mirage/test-support/setup-mirage'; @@ -7,75 +7,59 @@ module('Acceptance | breadcrumbs', function (hooks) { setupApplicationTest(hooks); setupMirage(hooks); - test('visiting projects', async function (assert) { + test('can navigate via breadcrumbs to projects from project', async function (assert) { assert.expect(2); - this.server.createList('project', 1); - await visit('/orgs/1/projects'); - assert.equal(findAll('.rose-nav-breadcrumbs a').length, 1); - await click('.rose-nav-breadcrumbs a'); - assert.equal(currentURL(), '/orgs/1/projects'); - }); - - test('visiting project', async function (assert) { - assert.expect(2); - this.server.createList('project', 1); - const projectURL = `/orgs/1/projects/${this.server.db.projects[0].id}`; + const project = this.server.create('project'); + const projectURL = `/orgs/1/projects/${project.id}`; await visit(projectURL); - assert.equal(findAll('.rose-nav-breadcrumbs a').length, 2); - - await visit(projectURL); - await click(findAll('.rose-nav-breadcrumbs a')[1]); - assert.equal(currentURL(), projectURL); + assert.equal(currentURL(), projectURL, 'We begin on th expected page.'); + await click(find('.rose-nav-breadcrumbs-link:first-child')); + assert.equal(currentURL(), '/orgs/1/projects', 'After navigating via breadcrumbs, we are one level up.'); }); - test('visiting project creation', async function (assert) { + test('can navigate via breadcrumbs to projects from new project', async function (assert) { assert.expect(2); - this.server.createList('project', 1); - const projectURL = '/orgs/1/projects/new'; - await visit(projectURL); - assert.equal(findAll('.rose-nav-breadcrumbs a').length, 2); - - await visit(projectURL); - await click(findAll('.rose-nav-breadcrumbs a')[1]); - assert.equal(currentURL(), projectURL); + const newProjectURL = `/orgs/1/projects/new`; + await visit(newProjectURL); + assert.equal(currentURL(), newProjectURL, 'We begin on th expected page.'); + await click(find('.rose-nav-breadcrumbs-link:first-child')); + assert.equal(currentURL(), '/orgs/1/projects', 'After navigating via breadcrumbs, we are one level up.'); }); - test('visiting host catalogs', async function (assert) { + test('can navigate via breadcrumbs to project from host catalogs', async function (assert) { assert.expect(2); - this.server.createList('project', 1); - this.server.createList('host-catalog', 1); - const hostcatalogsURL = `/orgs/1/projects/${this.server.db.projects[0].id}/host-catalogs`; - await visit(hostcatalogsURL); - assert.equal(findAll('.rose-nav-breadcrumbs a').length, 3); - - await visit(hostcatalogsURL); - await click(findAll('.rose-nav-breadcrumbs a')[2]); - assert.equal(currentURL(), hostcatalogsURL); + const project = this.server.create('project'); + const projectURL = `/orgs/1/projects/${project.id}`; + const hostCatalogsURL = `${projectURL}/host-catalogs`; + await visit(hostCatalogsURL); + assert.equal(currentURL(), hostCatalogsURL, 'We begin on th expected page.'); + await click(findAll('.rose-nav-breadcrumbs-link')[1]); + assert.equal(currentURL(), projectURL, 'After navigating via breadcrumbs, we are one level up.'); }); - test('visiting host catalog', async function (assert) { + test('can navigate via breadcrumbs to host catalogs from host catalog', async function (assert) { assert.expect(2); - this.server.createList('project', 1); - this.server.createList('host-catalog', 1); - const hostcatalogURL = `/orgs/1/projects/${this.server.db.projects[0].id}/host-catalogs/${this.server.db.hostCatalogs[0].id}`; - await visit(hostcatalogURL); - assert.equal(findAll('.rose-nav-breadcrumbs a').length, 4); - - await visit(hostcatalogURL); - await click(findAll('.rose-nav-breadcrumbs a')[3]); - assert.equal(currentURL(), hostcatalogURL); + const project = this.server.create('project'); + const hostCatalog = this.server.create('host-catalog'); + const projectURL = `/orgs/1/projects/${project.id}`; + const hostCatalogsURL = `${projectURL}/host-catalogs`; + const hostCatalogURL = `${hostCatalogsURL}/${hostCatalog.id}`; + await visit(hostCatalogURL); + assert.equal(currentURL(), hostCatalogURL, 'We begin on th expected page.'); + await click(findAll('.rose-nav-breadcrumbs-link')[2]); + assert.equal(currentURL(), hostCatalogsURL, 'After navigating via breadcrumbs, we are one level up.'); }); - test('visiting host catalog creation', async function (assert) { + test('can navigate via breadcrumbs to host catalogs from new host catalog', async function (assert) { assert.expect(2); - this.server.createList('project', 1); - this.server.createList('host-catalog', 1); - const hostcatalogURL = `/orgs/1/projects/${this.server.db.projects[0].id}/host-catalogs/new`; - await visit(hostcatalogURL); - assert.equal(findAll('.rose-nav-breadcrumbs a').length, 4); - - await visit(hostcatalogURL); - await click(findAll('.rose-nav-breadcrumbs a')[3]); - assert.equal(currentURL(), hostcatalogURL); + const project = this.server.create('project'); + const projectURL = `/orgs/1/projects/${project.id}`; + const hostCatalogsURL = `${projectURL}/host-catalogs`; + const newHostCatalogURL = `${hostCatalogsURL}/new`; + await visit(newHostCatalogURL); + assert.equal(currentURL(), newHostCatalogURL, 'We begin on th expected page.'); + await click(findAll('.rose-nav-breadcrumbs-link')[2]); + assert.equal(currentURL(), hostCatalogsURL, 'After navigating via breadcrumbs, we are one level up.'); }); + });