diff options
Diffstat (limited to 'spec/frontend/lib/utils/table_utility_spec.js')
-rw-r--r-- | spec/frontend/lib/utils/table_utility_spec.js | 31 |
1 files changed, 31 insertions, 0 deletions
diff --git a/spec/frontend/lib/utils/table_utility_spec.js b/spec/frontend/lib/utils/table_utility_spec.js index 75b9252aa40..0ceccbe4c74 100644 --- a/spec/frontend/lib/utils/table_utility_spec.js +++ b/spec/frontend/lib/utils/table_utility_spec.js @@ -8,4 +8,35 @@ describe('table_utility', () => { expect(tableUtils.thWidthClass(width)).toBe(`gl-w-${width}p ${DEFAULT_TH_CLASSES}`); }); }); + + describe('sortObjectToString', () => { + it('returns the expected sorting string ending in "DESC" when sortDesc is true', () => { + expect(tableUtils.sortObjectToString({ sortBy: 'mergedAt', sortDesc: true })).toBe( + 'MERGED_AT_DESC', + ); + }); + + it('returns the expected sorting string ending in "ASC" when sortDesc is false', () => { + expect(tableUtils.sortObjectToString({ sortBy: 'mergedAt', sortDesc: false })).toBe( + 'MERGED_AT_ASC', + ); + }); + }); + + describe('sortStringToObject', () => { + it.each` + sortBy | sortDesc | sortString + ${'mergedAt'} | ${true} | ${'MERGED_AT_DESC'} + ${'mergedAt'} | ${false} | ${'MERGED_AT_ASC'} + ${'severity'} | ${true} | ${'SEVERITY_DESC'} + ${'severity'} | ${false} | ${'SEVERITY_ASC'} + ${null} | ${null} | ${'SEVERITY'} + ${null} | ${null} | ${''} + `( + 'returns the expected sort object when the sort string is "$sortString"', + ({ sortBy, sortDesc, sortString }) => { + expect(tableUtils.sortStringToObject(sortString)).toStrictEqual({ sortBy, sortDesc }); + }, + ); + }); }); |