2018-06-28 18:58:38 +00:00
|
|
|
import Service from '@ember/service';
|
|
|
|
import RSVP from 'rsvp';
|
2019-03-13 00:04:16 +00:00
|
|
|
import { module, test } from 'qunit';
|
|
|
|
import { setupRenderingTest } from 'ember-qunit';
|
2019-07-23 19:40:32 +00:00
|
|
|
import { findAll, render, settled } from '@ember/test-helpers';
|
2018-06-28 18:58:38 +00:00
|
|
|
import hbs from 'htmlbars-inline-precompile';
|
|
|
|
import PromiseObject from 'nomad-ui/utils/classes/promise-object';
|
2020-08-25 15:56:02 +00:00
|
|
|
import { componentA11yAudit } from 'nomad-ui/tests/helpers/a11y-audit';
|
2018-06-28 18:58:38 +00:00
|
|
|
|
2019-03-13 00:04:16 +00:00
|
|
|
module('Integration | Component | app breadcrumbs', function(hooks) {
|
|
|
|
setupRenderingTest(hooks);
|
|
|
|
|
|
|
|
hooks.beforeEach(function() {
|
2018-06-28 18:58:38 +00:00
|
|
|
const mockBreadcrumbs = Service.extend({
|
2020-06-09 21:03:28 +00:00
|
|
|
init() {
|
|
|
|
this._super(...arguments);
|
|
|
|
this.breadcrumbs = [];
|
|
|
|
},
|
2018-06-28 18:58:38 +00:00
|
|
|
});
|
|
|
|
|
2019-03-13 00:04:16 +00:00
|
|
|
this.owner.register('service:breadcrumbs', mockBreadcrumbs);
|
|
|
|
this.breadcrumbs = this.owner.lookup('service:breadcrumbs');
|
|
|
|
});
|
2018-06-28 18:58:38 +00:00
|
|
|
|
2019-03-13 00:04:16 +00:00
|
|
|
const commonCrumbs = [{ label: 'One', args: ['one'] }, { label: 'Two', args: ['two'] }];
|
2018-06-28 18:58:38 +00:00
|
|
|
|
2019-03-13 00:04:16 +00:00
|
|
|
const template = hbs`
|
2020-08-25 15:56:02 +00:00
|
|
|
<ul><AppBreadcrumbs /></ul>
|
2019-03-13 00:04:16 +00:00
|
|
|
`;
|
2018-06-28 18:58:38 +00:00
|
|
|
|
2019-03-13 00:04:16 +00:00
|
|
|
test('breadcrumbs comes from the breadcrumbs service', async function(assert) {
|
|
|
|
this.breadcrumbs.set('breadcrumbs', commonCrumbs);
|
2018-06-28 18:58:38 +00:00
|
|
|
|
2019-03-13 00:04:16 +00:00
|
|
|
await render(template);
|
2018-06-28 18:58:38 +00:00
|
|
|
|
|
|
|
assert.equal(
|
2019-03-13 00:04:16 +00:00
|
|
|
findAll('[data-test-breadcrumb]').length,
|
|
|
|
commonCrumbs.length,
|
|
|
|
'The number of crumbs matches the crumbs from the service'
|
2018-06-28 18:58:38 +00:00
|
|
|
);
|
|
|
|
});
|
|
|
|
|
2019-03-13 00:04:16 +00:00
|
|
|
test('every breadcrumb is rendered correctly', async function(assert) {
|
|
|
|
this.breadcrumbs.set('breadcrumbs', commonCrumbs);
|
2018-06-28 18:58:38 +00:00
|
|
|
|
2019-03-13 00:04:16 +00:00
|
|
|
await render(template);
|
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}`
|
|
|
|
);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
test('when breadcrumbs are pending promises, an ellipsis is rendered', async function(assert) {
|
|
|
|
let resolvePromise;
|
|
|
|
const promise = new RSVP.Promise(resolve => {
|
|
|
|
resolvePromise = resolve;
|
|
|
|
});
|
2018-06-28 18:58:38 +00:00
|
|
|
|
2019-03-13 00:04:16 +00:00
|
|
|
this.breadcrumbs.set('breadcrumbs', [
|
|
|
|
{ label: 'One', args: ['one'] },
|
|
|
|
PromiseObject.create({ promise }),
|
|
|
|
{ label: 'Three', args: ['three'] },
|
|
|
|
]);
|
|
|
|
|
|
|
|
await render(template);
|
2018-06-28 18:58:38 +00:00
|
|
|
|
|
|
|
assert.equal(
|
|
|
|
findAll('[data-test-breadcrumb]')[1].textContent.trim(),
|
2019-03-13 00:04:16 +00:00
|
|
|
'…',
|
|
|
|
'Promise breadcrumb is in a loading state'
|
2018-06-28 18:58:38 +00:00
|
|
|
);
|
2019-03-13 00:04:16 +00:00
|
|
|
|
2020-08-25 15:56:02 +00:00
|
|
|
await componentA11yAudit(this.element, assert);
|
|
|
|
|
2019-03-13 00:04:16 +00:00
|
|
|
resolvePromise({ label: 'Two', args: ['two'] });
|
|
|
|
|
|
|
|
return settled().then(() => {
|
|
|
|
assert.equal(
|
|
|
|
findAll('[data-test-breadcrumb]')[1].textContent.trim(),
|
|
|
|
'Two',
|
|
|
|
'Promise breadcrumb has resolved and now renders Two'
|
|
|
|
);
|
|
|
|
});
|
2018-06-28 18:58:38 +00:00
|
|
|
});
|
|
|
|
});
|