diff --git a/src/Configuration/Provisioning/data/tests/utils.test.js b/src/Configuration/Provisioning/data/tests/utils.test.js index 2f3e29d74..ac336557c 100644 --- a/src/Configuration/Provisioning/data/tests/utils.test.js +++ b/src/Configuration/Provisioning/data/tests/utils.test.js @@ -13,6 +13,9 @@ import { createPolicy, determineInvalidFields, transformPolicyData, + transformDatatableDate, + filterDatatableData, + sortDatatableData, } from '../utils'; import { sampleCatalogQueries, @@ -326,3 +329,98 @@ describe('transformPolicyData', () => { expect(output).toEqual([]); }); }); + +describe('transformDatatableDate', () => { + it('returns the correct date', () => { + const dateStrings = '2023-06-28T18:03:09.898Z'; + const output = '6-28-2023'; + expect(transformDatatableDate(dateStrings)).toEqual(output); + }); + it('returns null if no date is passed', () => { + const output = null; + expect(transformDatatableDate()).toEqual(output); + }); +}); + +describe('filterDatatableData', () => { + it('returns empty object if no data is passed', () => { + const output = {}; + expect(filterDatatableData({ filters: {} })).toEqual(output); + }); + it('returns empty object if no filters are passed', () => { + const output = { + enterpriseCustomerName: 'testName', + enterpriseCustomerUuid: 'testUUID', + }; + expect(filterDatatableData( + { + filters: [{ + id: 'enterpriseCustomerName', + value: 'testName', + }, + { + id: 'enterpriseCustomerUuid', + value: 'testUUID', + }, + ], + }, + )).toEqual(output); + }); +}); + +describe('sortDatatableData', () => { + it('returns null if no data is passed', () => { + const output = null; + expect(sortDatatableData({ sortBy: {} })).toEqual(output); + }); + it('returns a sort by expirationDateTime if isActive is passed as the id', () => { + const output = 'expirationDatetime'; + + // desc is true + expect(sortDatatableData( + { + sortBy: + [{ + id: 'isActive', + desc: true, + }], + }, + )).toEqual(`-${output}`); + + // desc is false + expect(sortDatatableData( + { + sortBy: + [{ + id: 'isActive', + desc: false, + }], + }, + )).toEqual(output); + }); + it('returns a sort by title if title is passed as the id', () => { + const output = 'title'; + + // desc is true + expect(sortDatatableData( + { + sortBy: + [{ + id: 'title', + desc: true, + }], + }, + )).toEqual(`-${output}`); + + // desc is false + expect(sortDatatableData( + { + sortBy: + [{ + id: 'title', + desc: false, + }], + }, + )).toEqual(output); + }); +}); diff --git a/src/Configuration/Provisioning/data/utils.js b/src/Configuration/Provisioning/data/utils.js index 0c69ce25d..00b12ce98 100644 --- a/src/Configuration/Provisioning/data/utils.js +++ b/src/Configuration/Provisioning/data/utils.js @@ -482,9 +482,9 @@ export function filterDatatableData({ filters }) { export function sortDatatableData({ sortBy }) { if (sortBy[0]?.id) { if (sortBy[0].id === 'isActive') { - return sortBy[0].desc ? 'expirationDatetime' : '-expirationDatetime'; + return sortBy[0].desc ? '-expirationDatetime' : 'expirationDatetime'; } - return sortBy[0].desc ? sortBy[0].id : `-${sortBy[0].id}`; + return sortBy[0].desc ? `-${sortBy[0].id}` : sortBy[0].id; } return null; }