2020-09-15 18:11:24 +00:00
|
|
|
import { module, test } from 'qunit';
|
|
|
|
import Service from '@ember/service';
|
|
|
|
import { setupRenderingTest } from 'ember-qunit';
|
|
|
|
import { render } from '@ember/test-helpers';
|
|
|
|
import { run } from '@ember/runloop';
|
|
|
|
import hbs from 'htmlbars-inline-precompile';
|
|
|
|
|
|
|
|
const DISPLAY_ARRAY = ['role-1', 'role-2', 'role-3', 'role-4', 'role-5'];
|
|
|
|
|
|
|
|
const storeService = Service.extend({
|
|
|
|
query() {
|
2021-12-17 03:44:29 +00:00
|
|
|
return new Promise((resolve) => {
|
2020-09-15 18:11:24 +00:00
|
|
|
resolve([
|
|
|
|
{ id: 'role-1' },
|
|
|
|
{ id: 'role-2' },
|
|
|
|
{ id: 'role-3' },
|
|
|
|
{ id: 'role-4' },
|
|
|
|
{ id: 'role-5' },
|
|
|
|
{ id: 'role-6' },
|
|
|
|
]);
|
|
|
|
});
|
|
|
|
},
|
|
|
|
});
|
|
|
|
|
2021-12-17 03:44:29 +00:00
|
|
|
module('Integration | Component | InfoTableItemArray', function (hooks) {
|
2020-09-15 18:11:24 +00:00
|
|
|
setupRenderingTest(hooks);
|
|
|
|
|
2021-12-17 03:44:29 +00:00
|
|
|
hooks.beforeEach(function () {
|
2020-09-15 18:11:24 +00:00
|
|
|
this.set('displayArray', DISPLAY_ARRAY);
|
|
|
|
this.set('isLink', true);
|
|
|
|
this.set('modelType', 'transform/role');
|
|
|
|
this.set('queryParam', 'role');
|
|
|
|
this.set('backend', 'transform');
|
|
|
|
this.set('wildcardLabel', 'role');
|
|
|
|
this.set('viewAll', 'roles');
|
|
|
|
run(() => {
|
|
|
|
this.owner.unregister('service:store');
|
|
|
|
this.owner.register('service:store', storeService);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2021-12-17 03:44:29 +00:00
|
|
|
hooks.afterEach(function () {
|
2020-09-15 18:11:24 +00:00
|
|
|
this.owner.unregister('service:store');
|
|
|
|
});
|
|
|
|
|
2021-12-17 03:44:29 +00:00
|
|
|
test('it renders', async function (assert) {
|
2020-09-15 18:11:24 +00:00
|
|
|
await render(hbs`<InfoTableItemArray
|
2021-12-17 03:44:29 +00:00
|
|
|
@displayArray={{this.displayArray}}
|
2020-09-15 18:11:24 +00:00
|
|
|
/>`);
|
|
|
|
|
|
|
|
assert.dom('[data-test-info-table-item-array]').exists();
|
2021-12-17 03:44:29 +00:00
|
|
|
let noLinkString = document.querySelector('code').textContent.trim();
|
2020-09-15 18:11:24 +00:00
|
|
|
assert.equal(
|
|
|
|
noLinkString.length,
|
|
|
|
DISPLAY_ARRAY.toString().length,
|
|
|
|
'renders a string of the array if isLink is not provided'
|
|
|
|
);
|
|
|
|
});
|
|
|
|
|
2021-12-17 03:44:29 +00:00
|
|
|
test('it renders links if isLink is true', async function (assert) {
|
2020-09-15 18:11:24 +00:00
|
|
|
await render(hbs`<InfoTableItemArray
|
2021-12-17 03:44:29 +00:00
|
|
|
@displayArray={{this.displayArray}}
|
|
|
|
@isLink={{this.isLink}}
|
|
|
|
@modelType={{this.modelType}}
|
|
|
|
@queryParam={{this.queryParam}}
|
|
|
|
@backend={{this.backend}}
|
2020-09-15 18:11:24 +00:00
|
|
|
/>`);
|
|
|
|
assert.equal(
|
|
|
|
document.querySelectorAll('a > span').length,
|
|
|
|
DISPLAY_ARRAY.length,
|
|
|
|
'renders each item in array with link'
|
|
|
|
);
|
|
|
|
});
|
|
|
|
|
2021-12-17 03:44:29 +00:00
|
|
|
test('it renders a badge and view all if wildcard in display array && < 10', async function (assert) {
|
2020-09-15 18:11:24 +00:00
|
|
|
const displayArrayWithWildcard = ['role-1', 'role-2', 'role-3', 'r*'];
|
|
|
|
this.set('displayArrayWithWildcard', displayArrayWithWildcard);
|
|
|
|
await render(hbs`<InfoTableItemArray
|
2021-12-17 03:44:29 +00:00
|
|
|
@displayArray={{this.displayArrayWithWildcard}}
|
|
|
|
@isLink={{this.isLink}}
|
|
|
|
@modelType={{this.modelType}}
|
|
|
|
@queryParam={{this.queryParam}}
|
|
|
|
@backend={{this.backend}}
|
|
|
|
@viewAll={{this.viewAll}}
|
2020-09-15 18:11:24 +00:00
|
|
|
/>`);
|
|
|
|
|
|
|
|
assert.equal(
|
|
|
|
document.querySelectorAll('a > span').length,
|
|
|
|
DISPLAY_ARRAY.length - 1,
|
|
|
|
'renders each item in array with link'
|
|
|
|
);
|
|
|
|
// 6 here comes from the six roles setup in the store service.
|
|
|
|
assert.dom('[data-test-count="6"]').exists('correctly counts with wildcard filter and shows the count');
|
|
|
|
assert.dom('[data-test-view-all="roles"]').exists({ count: 1 }, 'renders 1 view all roles');
|
|
|
|
});
|
|
|
|
|
2021-12-17 03:44:29 +00:00
|
|
|
test('it renders a badge and view all if wildcard in display array && >= 10', async function (assert) {
|
2020-09-15 18:11:24 +00:00
|
|
|
const displayArrayWithWildcard = [
|
|
|
|
'role-1',
|
|
|
|
'role-2',
|
|
|
|
'role-3',
|
|
|
|
'r*',
|
|
|
|
'role-4',
|
|
|
|
'role-5',
|
|
|
|
'role-6',
|
|
|
|
'role-7',
|
|
|
|
'role-8',
|
|
|
|
'role-9',
|
|
|
|
'role-10',
|
|
|
|
];
|
|
|
|
this.set('displayArrayWithWildcard', displayArrayWithWildcard);
|
|
|
|
await render(hbs`<InfoTableItemArray
|
2021-12-17 03:44:29 +00:00
|
|
|
@displayArray={{this.displayArrayWithWildcard}}
|
|
|
|
@isLink={{this.isLink}}
|
|
|
|
@modelType={{this.modelType}}
|
|
|
|
@queryParam={{this.queryParam}}
|
|
|
|
@backend={{this.backend}}
|
|
|
|
@viewAll={{this.viewAll}}
|
2020-09-15 18:11:24 +00:00
|
|
|
/>`);
|
|
|
|
const numberCutOffTruncatedArray = displayArrayWithWildcard.length - 5;
|
|
|
|
assert.equal(document.querySelectorAll('a > span').length, 5, 'renders truncated array of five');
|
|
|
|
assert
|
|
|
|
.dom(`[data-test-and="${numberCutOffTruncatedArray}"]`)
|
|
|
|
.exists('correctly counts with wildcard filter and shows the count');
|
|
|
|
});
|
|
|
|
});
|