diff --git a/front/core/components/smart-table/index.spec.js b/front/core/components/smart-table/index.spec.js index 9b8cc1d09..94edd45bb 100644 --- a/front/core/components/smart-table/index.spec.js +++ b/front/core/components/smart-table/index.spec.js @@ -80,6 +80,45 @@ describe('Component smartTable', () => { }); }); + describe('defaultOrder', () => { + it('should insert a new object to the controller sortCriteria with a sortType value of "ASC"', () => { + const element = document.createElement('div'); + controller.model = {order: 'id'}; + controller.columns = [ + {field: 'id', element: element}, + {field: 'test1', element: element}, + {field: 'test2', element: element} + ]; + + controller.defaultOrder(); + + const firstSortCriteria = controller.sortCriteria[0]; + + expect(firstSortCriteria.field).toEqual('id'); + expect(firstSortCriteria.sortType).toEqual('ASC'); + }); + + it('should insert two new objects to the controller sortCriteria with a sortType values of "ASC" and "DESC"', () => { + const element = document.createElement('div'); + controller.model = {order: 'test1, id DESC'}; + controller.columns = [ + {field: 'id', element: element}, + {field: 'test1', element: element}, + {field: 'test2', element: element} + ]; + + controller.defaultOrder(); + + const firstSortCriteria = controller.sortCriteria[0]; + const secondSortCriteria = controller.sortCriteria[1]; + + expect(firstSortCriteria.field).toEqual('test1'); + expect(firstSortCriteria.sortType).toEqual('ASC'); + expect(secondSortCriteria.field).toEqual('id'); + expect(secondSortCriteria.sortType).toEqual('DESC'); + }); + }); + describe('addFilter()', () => { it('should call the model addFilter() with a basic where filter if exprBuilder() was not received', () => { controller.model = {addFilter: jest.fn()};