refactor: 💡 add custom sort to resources (#2860)
* 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)
This commit is contained in:
1 parent
4c959ab297
commit
738fa1f15f
27 files changed
+331
-41
No files matched your search
@@ -0,0 +1,67 @@
|
||||
/**
|
||||
* 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);
|
||||
},
|
||||
);
|
||||
});
|
||||
Reference in new issue
Block a user