2021-12-17 16:49:22 +00:00
|
|
|
/* eslint-disable ember-a11y-testing/a11y-audit-called */
|
2021-12-14 18:49:42 +00:00
|
|
|
import { module, test } from 'qunit';
|
|
|
|
import { setupRenderingTest } from 'ember-qunit';
|
|
|
|
import { click, findAll, render } from '@ember/test-helpers';
|
|
|
|
import { hbs } from 'ember-cli-htmlbars';
|
|
|
|
|
2022-01-20 15:39:02 +00:00
|
|
|
module('Integration | Component | breadcrumbs', function (hooks) {
|
2021-12-14 18:49:42 +00:00
|
|
|
setupRenderingTest(hooks);
|
|
|
|
|
2022-01-20 15:39:02 +00:00
|
|
|
test('it declaratively renders a list of registered crumbs', async function (assert) {
|
2021-12-14 18:49:42 +00:00
|
|
|
this.set('isRegistered', false);
|
|
|
|
this.set('toggleCrumb', () => this.set('isRegistered', !this.isRegistered));
|
|
|
|
await render(hbs`
|
|
|
|
<Breadcrumbs as |bb|>
|
|
|
|
<ul>
|
|
|
|
{{#each bb as |crumb|}}
|
|
|
|
<li data-test-crumb={{crumb.args.crumb}}>{{crumb.args.crumb}}</li>
|
|
|
|
{{/each}}
|
|
|
|
</ul>
|
|
|
|
</Breadcrumbs>
|
|
|
|
<button data-test-button type="button" {{on "click" toggleCrumb}}>Toggle</button>
|
|
|
|
<Breadcrumb @crumb={{'Zoey'}} />
|
|
|
|
{{#if this.isRegistered}}
|
|
|
|
<Breadcrumb @crumb={{'Tomster'}} />
|
|
|
|
{{/if}}
|
|
|
|
`);
|
|
|
|
|
2022-01-20 15:39:02 +00:00
|
|
|
assert
|
|
|
|
.dom('[data-test-crumb]')
|
|
|
|
.exists({ count: 1 }, 'We register one crumb');
|
|
|
|
assert
|
|
|
|
.dom('[data-test-crumb]')
|
|
|
|
.hasText('Zoey', 'The first registered crumb is Zoey');
|
2021-12-14 18:49:42 +00:00
|
|
|
|
|
|
|
await click('[data-test-button]');
|
|
|
|
const crumbs = await findAll('[data-test-crumb]');
|
|
|
|
|
|
|
|
assert
|
|
|
|
.dom('[data-test-crumb]')
|
|
|
|
.exists({ count: 2 }, 'The second crumb registered successfully');
|
|
|
|
assert
|
|
|
|
.dom(crumbs[0])
|
2022-01-20 15:39:02 +00:00
|
|
|
.hasText(
|
|
|
|
'Zoey',
|
|
|
|
'Breadcrumbs maintain the order in which they are declared'
|
|
|
|
);
|
2021-12-14 18:49:42 +00:00
|
|
|
assert
|
|
|
|
.dom(crumbs[1])
|
2022-01-20 15:39:02 +00:00
|
|
|
.hasText(
|
|
|
|
'Tomster',
|
|
|
|
'Breadcrumbs maintain the order in which they are declared'
|
|
|
|
);
|
2021-12-14 18:49:42 +00:00
|
|
|
|
|
|
|
await click('[data-test-button]');
|
|
|
|
assert
|
|
|
|
.dom('[data-test-crumb]')
|
2022-01-20 15:39:02 +00:00
|
|
|
.exists({ count: 1 }, 'We deregister one crumb');
|
|
|
|
assert
|
|
|
|
.dom('[data-test-crumb]')
|
|
|
|
.hasText(
|
|
|
|
'Zoey',
|
|
|
|
'Zoey remains in the template after Tomster deregisters'
|
|
|
|
);
|
2021-12-14 18:49:42 +00:00
|
|
|
});
|
|
|
|
|
2022-01-20 15:39:02 +00:00
|
|
|
test('it can register complex crumb objects', async function (assert) {
|
2021-12-14 18:49:42 +00:00
|
|
|
await render(hbs`
|
|
|
|
<Breadcrumbs as |bb|>
|
|
|
|
<ul>
|
|
|
|
{{#each bb as |crumb|}}
|
|
|
|
<li data-test-crumb>{{crumb.args.crumb.name}}</li>
|
|
|
|
{{/each}}
|
|
|
|
</ul>
|
|
|
|
</Breadcrumbs>
|
|
|
|
<Breadcrumb @crumb={{hash name='Tomster'}} />
|
|
|
|
`);
|
|
|
|
|
|
|
|
assert
|
|
|
|
.dom('[data-test-crumb]')
|
2022-01-20 15:39:02 +00:00
|
|
|
.hasText(
|
|
|
|
'Tomster',
|
|
|
|
'We can access the registered breadcrumbs in the template'
|
|
|
|
);
|
2021-12-14 18:49:42 +00:00
|
|
|
});
|
|
|
|
});
|