From 8f9f0179957727c0519e9c312dbd00dde2460ded Mon Sep 17 00:00:00 2001 From: Susmitha Girumala Date: Mon, 15 Jun 2020 14:34:37 -0400 Subject: [PATCH] =?UTF-8?q?test:=20=F0=9F=92=8D=20Add=20acceptance=20test?= =?UTF-8?q?=20for=20breadcrumbs=20in=20ui/core?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ui/core/tests/acceptance/bread-crumbs-test.js | 81 +++++++++++++++++++ .../components/bread-crumbs-test.js | 9 ++- 2 files changed, 88 insertions(+), 2 deletions(-) create mode 100644 ui/core/tests/acceptance/bread-crumbs-test.js diff --git a/ui/core/tests/acceptance/bread-crumbs-test.js b/ui/core/tests/acceptance/bread-crumbs-test.js new file mode 100644 index 000000000..6e302588d --- /dev/null +++ b/ui/core/tests/acceptance/bread-crumbs-test.js @@ -0,0 +1,81 @@ +import { module, test } from 'qunit'; +import { visit, currentURL, click, findAll } from '@ember/test-helpers'; +import { setupApplicationTest } from 'ember-qunit'; +import setupMirage from 'ember-cli-mirage/test-support/setup-mirage'; + +module('Acceptance | breadcrumbs', function (hooks) { + setupApplicationTest(hooks); + setupMirage(hooks); + + test('visiting projects', 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}`; + 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); + }); + + test('visiting project creation', 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); + }); + + test('visiting 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); + }); + + test('visiting 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); + }); + + test('visiting host catalog creation', 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); + }); +}); diff --git a/ui/core/tests/integration/components/bread-crumbs-test.js b/ui/core/tests/integration/components/bread-crumbs-test.js index 7ecb5ac86..a6f3579c8 100644 --- a/ui/core/tests/integration/components/bread-crumbs-test.js +++ b/ui/core/tests/integration/components/bread-crumbs-test.js @@ -10,15 +10,20 @@ module('Integration | Component | bread-crumbs', function(hooks) { this.set('breadCrumbs', [{label: 'Level 1'}]); await render(hbs``); + // Default index route + assert.ok(find('.rose-nav-breadcrumbs a').href.match(/#$/)); assert.equal(find('.rose-nav-breadcrumbs').textContent.trim(), 'Level 1'); }); test('it renders with model', async function(assert) { + let store = this.owner.lookup('service:store'); + let project = store.createRecord('project', {id: '1234'}); + this.set('breadCrumbs', [{ label: 'Level 2', path: 'orgs.org.projects.project', - model: {project_id: 'project'}} - ]); + model: project + }]); await render(hbs``); assert.equal(find('.rose-nav-breadcrumbs').textContent.trim(), 'Level 2');