2021-12-17 16:49:22 +00:00
|
|
|
/* eslint-disable ember-a11y-testing/a11y-audit-called */
|
2021-12-15 16:56:26 +00:00
|
|
|
import { setComponentTemplate } from '@ember/component';
|
2022-01-20 15:39:02 +00:00
|
|
|
import templateOnlyComponent from '@ember/component/template-only';
|
2019-03-13 00:04:16 +00:00
|
|
|
import { module, test } from 'qunit';
|
|
|
|
import { setupRenderingTest } from 'ember-qunit';
|
2021-12-15 16:56:26 +00:00
|
|
|
import { findAll, render } from '@ember/test-helpers';
|
2018-06-28 18:58:38 +00:00
|
|
|
import hbs from 'htmlbars-inline-precompile';
|
|
|
|
|
2022-01-20 15:39:02 +00:00
|
|
|
module('Integration | Component | app breadcrumbs', function (hooks) {
|
2019-03-13 00:04:16 +00:00
|
|
|
setupRenderingTest(hooks);
|
|
|
|
|
2021-12-15 16:56:26 +00:00
|
|
|
const commonCrumbs = [
|
|
|
|
{ label: 'Jobs', args: ['jobs.index'] },
|
2022-01-20 15:39:02 +00:00
|
|
|
{ label: 'Job', args: ['jobs.job.index'] },
|
2021-12-15 16:56:26 +00:00
|
|
|
];
|
2018-06-28 18:58:38 +00:00
|
|
|
|
2022-01-20 15:39:02 +00:00
|
|
|
test('every breadcrumb is rendered correctly', async function (assert) {
|
|
|
|
assert.expect(3);
|
2021-12-15 16:56:26 +00:00
|
|
|
this.set('commonCrumbs', commonCrumbs);
|
|
|
|
await render(hbs`
|
|
|
|
<AppBreadcrumbs />
|
|
|
|
{{#each this.commonCrumbs as |crumb|}}
|
|
|
|
<Breadcrumb @crumb={{hash label=crumb.label args=crumb.args }} />
|
|
|
|
{{/each}}
|
|
|
|
`);
|
|
|
|
|
|
|
|
assert
|
|
|
|
.dom('[data-test-breadcrumb-default]')
|
2021-12-28 19:30:38 +00:00
|
|
|
.exists(
|
|
|
|
'We register the default breadcrumb component if no type is specified on the crumb'
|
|
|
|
);
|
2018-06-28 18:58:38 +00:00
|
|
|
|
2019-03-13 00:04:16 +00:00
|
|
|
const renderedCrumbs = findAll('[data-test-breadcrumb]');
|
2018-06-28 18:58:38 +00:00
|
|
|
|
2019-03-13 00:04:16 +00:00
|
|
|
renderedCrumbs.forEach((crumb, index) => {
|
|
|
|
assert.equal(
|
|
|
|
crumb.textContent.trim(),
|
|
|
|
commonCrumbs[index].label,
|
|
|
|
`Crumb ${index} is ${commonCrumbs[index].label}`
|
|
|
|
);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2022-01-20 15:39:02 +00:00
|
|
|
test('when we register a crumb with a type property, a dedicated breadcrumb/<type> component renders', async function (assert) {
|
2021-12-15 16:56:26 +00:00
|
|
|
const crumbs = [
|
|
|
|
{ label: 'Jobs', args: ['jobs.index'] },
|
2022-01-20 15:39:02 +00:00
|
|
|
{ type: 'special', label: 'Job', args: ['jobs.job.index'] },
|
2021-12-15 16:56:26 +00:00
|
|
|
];
|
|
|
|
this.set('crumbs', crumbs);
|
|
|
|
|
|
|
|
this.owner.register(
|
|
|
|
'component:breadcrumbs/special',
|
|
|
|
setComponentTemplate(
|
|
|
|
hbs`
|
|
|
|
<div data-test-breadcrumb-special>Test</div>
|
|
|
|
`,
|
2022-01-20 15:39:02 +00:00
|
|
|
templateOnlyComponent()
|
2021-12-15 16:56:26 +00:00
|
|
|
)
|
2018-06-28 18:58:38 +00:00
|
|
|
);
|
2019-03-13 00:04:16 +00:00
|
|
|
|
2021-12-15 16:56:26 +00:00
|
|
|
await render(hbs`
|
|
|
|
<AppBreadcrumbs />
|
|
|
|
{{#each this.crumbs as |crumb|}}
|
|
|
|
<Breadcrumb @crumb={{hash type=crumb.type label=crumb.label args=crumb.args }} />
|
|
|
|
{{/each}}
|
|
|
|
`);
|
|
|
|
|
|
|
|
assert
|
|
|
|
.dom('[data-test-breadcrumb-special]')
|
|
|
|
.exists(
|
|
|
|
'We can create a new type of breadcrumb component and AppBreadcrumbs will handle rendering by type'
|
2019-03-13 00:04:16 +00:00
|
|
|
);
|
2021-12-15 16:56:26 +00:00
|
|
|
|
|
|
|
assert
|
|
|
|
.dom('[data-test-breadcrumb-default]')
|
|
|
|
.exists('Default breadcrumb registers if no type is specified');
|
2018-06-28 18:58:38 +00:00
|
|
|
});
|
|
|
|
});
|