* refactor: 💡 add custom sort * test: 💍 fix tests * test: 💍 fix more tests * refactor: 💡 use reusable sort function for name * refactor: 💡 use sort util in all resources w/ optional name * Add missing copyright headers * test: 💍 fix broken tests & add tests for new util * refactor: 💡 add name custom sort to users * test: 💍 fix import in tests * refactor: 💡 add custom name sort to scopes * test: 💍 pr feedback on util test cases * refactor: 💡 move sort function into object (pr feedback)
68 lines
1.8 KiB
JavaScript
68 lines
1.8 KiB
JavaScript
/**
|
|
* Copyright (c) HashiCorp, Inc.
|
|
* SPDX-License-Identifier: BUSL-1.1
|
|
*/
|
|
|
|
import { sortNameWithIdFallback } from 'admin/utils/sort-name-with-id-fallback';
|
|
import { module, test } from 'qunit';
|
|
|
|
function createMockRecord(id, attributes = {}) {
|
|
return {
|
|
id,
|
|
attributes,
|
|
};
|
|
}
|
|
|
|
module('Unit | Utility | sort-name-with-id-fallback', function () {
|
|
test.each(
|
|
'sort on name with id fallback',
|
|
[
|
|
{
|
|
recordA: createMockRecord('id_01'),
|
|
recordB: createMockRecord('id_01'),
|
|
expectedResult: 0,
|
|
},
|
|
{
|
|
recordA: createMockRecord('id_02'),
|
|
recordB: createMockRecord('id_01'),
|
|
expectedResult: 1,
|
|
},
|
|
{
|
|
recordA: createMockRecord('id_01'),
|
|
recordB: createMockRecord('id_02'),
|
|
expectedResult: -1,
|
|
},
|
|
{
|
|
recordA: createMockRecord('id_01', { name: 'Alpha' }),
|
|
recordB: createMockRecord('id_02'),
|
|
expectedResult: -1,
|
|
},
|
|
{
|
|
recordA: createMockRecord('id_01'),
|
|
recordB: createMockRecord('id_02', { name: 'Alpha' }),
|
|
expectedResult: 1,
|
|
},
|
|
{
|
|
recordA: createMockRecord('id_01', { name: 'Alpha' }),
|
|
recordB: createMockRecord('id_02', { name: 'Beta' }),
|
|
expectedResult: -1,
|
|
},
|
|
{
|
|
recordA: createMockRecord('id_01', { name: 'Beta' }),
|
|
recordB: createMockRecord('id_02', { name: 'Alpha' }),
|
|
expectedResult: 1,
|
|
},
|
|
{
|
|
recordA: createMockRecord('id_01', { name: 'Alpha' }),
|
|
recordB: createMockRecord('id_02', { name: 'Alpha' }),
|
|
expectedResult: 0,
|
|
},
|
|
],
|
|
function (assert, input) {
|
|
const result = sortNameWithIdFallback(input.recordA, input.recordB);
|
|
|
|
assert.strictEqual(result, input.expectedResult);
|
|
},
|
|
);
|
|
});
|