refactor: 💡 update indexed-display-name helper (#322)

This commit is contained in:
Cameron Perera authored and GitHub committed 2023-06-05 16:27:54 -05:00
1 parent 35f5547bf4
commit 9bd969c1f6
2 files changed
+7 -5

No files matched your search

@@ -2,8 +2,10 @@ import Helper from '@ember/component/helper';
import { inject as service } from '@ember/service';
export function indexedDisplayName(intl, translation, array, item) {
let index = array.indexOf(item) + 1;
if (index === 0) index = null;
const length = array.length;
let index = length - array.indexOf(item);
if (index > length) index = null;
return intl.t(translation, { index });
}
@@ -8,7 +8,7 @@ module('Integration | Helper | indexed-display-name', function (hooks) {
setupRenderingTest(hooks);
setupIntl(hooks);
test('it renders the resource name with its position in parent array', async function (assert) {
test('it renders the resource name with its position in parent array reversed', async function (assert) {
this.set('array', ['Boundary', 'is', 'cool!']);
await render(hbs`{{indexed-display-name
@@ -17,7 +17,7 @@ module('Integration | Helper | indexed-display-name', function (hooks) {
'Boundary'
}}`);
assert.dom(this.element).hasText('Connection 1');
assert.dom(this.element).hasText('Connection 3');
await render(hbs`{{indexed-display-name
'resources.session-recording.connection.title_index'
@@ -33,7 +33,7 @@ module('Integration | Helper | indexed-display-name', function (hooks) {
'cool!'
}}`);
assert.dom(this.element).hasText('Connection 3');
assert.dom(this.element).hasText('Connection 1');
});
test('it does not render the position if the index cannot be found', async function (assert) {