github.com/hernad/nomad@v1.6.112/ui/tests/integration/components/breadcrumbs-test.js (about) 1 /** 2 * Copyright (c) HashiCorp, Inc. 3 * SPDX-License-Identifier: MPL-2.0 4 */ 5 6 /* eslint-disable ember-a11y-testing/a11y-audit-called */ 7 import { module, test } from 'qunit'; 8 import { setupRenderingTest } from 'ember-qunit'; 9 import { click, findAll, render } from '@ember/test-helpers'; 10 import { hbs } from 'ember-cli-htmlbars'; 11 12 module('Integration | Component | breadcrumbs', function (hooks) { 13 setupRenderingTest(hooks); 14 15 test('it declaratively renders a list of registered crumbs', async function (assert) { 16 this.set('isRegistered', false); 17 this.set('toggleCrumb', () => this.set('isRegistered', !this.isRegistered)); 18 await render(hbs` 19 <Breadcrumbs as |bb|> 20 <ul> 21 {{#each bb as |crumb|}} 22 <li data-test-crumb={{crumb.args.crumb}}>{{crumb.args.crumb}}</li> 23 {{/each}} 24 </ul> 25 </Breadcrumbs> 26 <button data-test-button type="button" {{on "click" toggleCrumb}}>Toggle</button> 27 <Breadcrumb @crumb={{'Zoey'}} /> 28 {{#if this.isRegistered}} 29 <Breadcrumb @crumb={{'Tomster'}} /> 30 {{/if}} 31 `); 32 33 assert 34 .dom('[data-test-crumb]') 35 .exists({ count: 1 }, 'We register one crumb'); 36 assert 37 .dom('[data-test-crumb]') 38 .hasText('Zoey', 'The first registered crumb is Zoey'); 39 40 await click('[data-test-button]'); 41 const crumbs = await findAll('[data-test-crumb]'); 42 43 assert 44 .dom('[data-test-crumb]') 45 .exists({ count: 2 }, 'The second crumb registered successfully'); 46 assert 47 .dom(crumbs[0]) 48 .hasText( 49 'Zoey', 50 'Breadcrumbs maintain the order in which they are declared' 51 ); 52 assert 53 .dom(crumbs[1]) 54 .hasText( 55 'Tomster', 56 'Breadcrumbs maintain the order in which they are declared' 57 ); 58 59 await click('[data-test-button]'); 60 assert 61 .dom('[data-test-crumb]') 62 .exists({ count: 1 }, 'We deregister one crumb'); 63 assert 64 .dom('[data-test-crumb]') 65 .hasText( 66 'Zoey', 67 'Zoey remains in the template after Tomster deregisters' 68 ); 69 }); 70 71 test('it can register complex crumb objects', async function (assert) { 72 await render(hbs` 73 <Breadcrumbs as |bb|> 74 <ul> 75 {{#each bb as |crumb|}} 76 <li data-test-crumb>{{crumb.args.crumb.name}}</li> 77 {{/each}} 78 </ul> 79 </Breadcrumbs> 80 <Breadcrumb @crumb={{hash name='Tomster'}} /> 81 `); 82 83 assert 84 .dom('[data-test-crumb]') 85 .hasText( 86 'Tomster', 87 'We can access the registered breadcrumbs in the template' 88 ); 89 }); 90 });