-
-
Notifications
You must be signed in to change notification settings - Fork 117
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(sorters): consolidate & provide all date sorters
- Loading branch information
Ghislain Beaulac
authored and
Ghislain Beaulac
committed
Aug 19, 2019
1 parent
1e983e2
commit fdc1155
Showing
20 changed files
with
199 additions
and
207 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
24 changes: 12 additions & 12 deletions
24
src/app/modules/angular-slickgrid/sorters/__tests__/dateEuroShortSorter.spec.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,33 +1,33 @@ | ||
import { SortDirectionNumber } from '../../models/sortDirectionNumber.enum'; | ||
import { dateEuroShortSorter } from '../dateEuroShortSorter'; | ||
import { sortByFieldType } from '../sorterUtilities'; | ||
import { FieldType, SortDirectionNumber } from '../../models'; | ||
|
||
describe('the Date Euro Short Sorter', () => { | ||
it('should return an array of Euro dates sorted ascending when only valid dates are provided', () => { | ||
it('should return an array of dates sorted ascending when only valid dates are provided', () => { | ||
const direction = SortDirectionNumber.asc; | ||
const inputArray = ['8/8/98', '8/10/98', '8/8/98', '01/01/18', '14/12/98']; | ||
inputArray.sort((value1, value2) => dateEuroShortSorter(value1, value2, direction)); | ||
inputArray.sort((value1, value2) => sortByFieldType(FieldType.dateEuroShort, value1, value2, direction)); | ||
expect(inputArray).toEqual(['8/8/98', '8/8/98', '8/10/98', '14/12/98', '01/01/18']); | ||
}); | ||
|
||
it('should return an array of Euro dates sorted descending when only valid dates are provided', () => { | ||
it('should return an array of dates sorted descending when only valid dates are provided', () => { | ||
const direction = SortDirectionNumber.desc; | ||
const inputArray = ['8/8/98', '8/10/98', null, '8/8/98', '01/01/18', '14/12/98']; | ||
inputArray.sort((value1, value2) => dateEuroShortSorter(value1, value2, direction)); | ||
inputArray.sort((value1, value2) => sortByFieldType(FieldType.dateEuroShort, value1, value2, direction)); | ||
expect(inputArray).toEqual(['01/01/18', '14/12/98', '8/10/98', '8/8/98', '8/8/98', null]); | ||
}); | ||
|
||
it(`should return an array with unsorted characters showing at the beginning | ||
then comes numbers sorted ascending when digits and chars are provided`, () => { | ||
const direction = SortDirectionNumber.asc; | ||
const inputArray = ['8/10/98', 'y', '8/8/98', '01/01/18', '14/12/98']; | ||
inputArray.sort((value1, value2) => dateEuroShortSorter(value1, value2, direction)); | ||
expect(inputArray).toEqual(['y', '8/8/98', '8/10/98', '14/12/98', '01/01/18']); | ||
}); | ||
const direction = SortDirectionNumber.asc; | ||
const inputArray = ['8/10/98', 'y', '8/8/98', '01/01/18', '14/12/98']; | ||
inputArray.sort((value1, value2) => sortByFieldType(FieldType.dateEuroShort, value1, value2, direction)); | ||
expect(inputArray).toEqual(['y', '8/8/98', '8/10/98', '14/12/98', '01/01/18']); | ||
}); | ||
|
||
it(`should return an array with dates sorted descending showing at the beginning then characters`, () => { | ||
const direction = SortDirectionNumber.desc; | ||
const inputArray = ['8/10/98', null, '8/8/98', '01/01/18', '14/12/98']; | ||
inputArray.sort((value1, value2) => dateEuroShortSorter(value1, value2, direction)); | ||
inputArray.sort((value1, value2) => sortByFieldType(FieldType.dateEuroShort, value1, value2, direction)); | ||
expect(inputArray).toEqual(['01/01/18', '14/12/98', '8/10/98', '8/8/98', null]); | ||
}); | ||
}); |
24 changes: 12 additions & 12 deletions
24
src/app/modules/angular-slickgrid/sorters/__tests__/dateEuroSorter.spec.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,33 +1,33 @@ | ||
import { SortDirectionNumber } from '../../models/sortDirectionNumber.enum'; | ||
import { dateEuroSorter } from '../dateEuroSorter'; | ||
import { sortByFieldType } from '../sorterUtilities'; | ||
import { FieldType, SortDirectionNumber } from '../../models'; | ||
|
||
describe('the Date Euro Sorter', () => { | ||
it('should return an array of Euro dates sorted ascending when only valid dates are provided', () => { | ||
it('should return an array of dates sorted ascending when only valid dates are provided', () => { | ||
const direction = SortDirectionNumber.asc; | ||
const inputArray = ['08/08/1998', '08/10/1998', '08/08/1998', '01/01/2000', '14/12/1998']; | ||
inputArray.sort((value1, value2) => dateEuroSorter(value1, value2, direction)); | ||
inputArray.sort((value1, value2) => sortByFieldType(FieldType.dateEuro, value1, value2, direction)); | ||
expect(inputArray).toEqual(['08/08/1998', '08/08/1998', '08/10/1998', '14/12/1998', '01/01/2000']); | ||
}); | ||
|
||
it('should return an array of Euro dates sorted descending when only valid dates are provided', () => { | ||
it('should return an array of dates sorted descending when only valid dates are provided', () => { | ||
const direction = SortDirectionNumber.desc; | ||
const inputArray = ['08/08/1998', '08/10/1998', null, '08/08/1998', '01/01/2000', '14/12/1998']; | ||
inputArray.sort((value1, value2) => dateEuroSorter(value1, value2, direction)); | ||
inputArray.sort((value1, value2) => sortByFieldType(FieldType.dateEuro, value1, value2, direction)); | ||
expect(inputArray).toEqual(['01/01/2000', '14/12/1998', '08/10/1998', '08/08/1998', '08/08/1998', null]); | ||
}); | ||
|
||
it(`should return an array with unsorted characters showing at the beginning | ||
then comes numbers sorted ascending when digits and chars are provided`, () => { | ||
const direction = SortDirectionNumber.asc; | ||
const inputArray = ['08/10/1998', 'y', '08/08/1998', '01/01/2000', '14/12/1998']; | ||
inputArray.sort((value1, value2) => dateEuroSorter(value1, value2, direction)); | ||
expect(inputArray).toEqual(['y', '08/08/1998', '08/10/1998', '14/12/1998', '01/01/2000']); | ||
}); | ||
const direction = SortDirectionNumber.asc; | ||
const inputArray = ['08/10/1998', 'y', '08/08/1998', '01/01/2000', '14/12/1998']; | ||
inputArray.sort((value1, value2) => sortByFieldType(FieldType.dateEuro, value1, value2, direction)); | ||
expect(inputArray).toEqual(['y', '08/08/1998', '08/10/1998', '14/12/1998', '01/01/2000']); | ||
}); | ||
|
||
it(`should return an array with dates sorted descending showing at the beginning then characters`, () => { | ||
const direction = SortDirectionNumber.desc; | ||
const inputArray = ['08/10/1998', null, '08/08/1998', '01/01/2000', '14/12/1998']; | ||
inputArray.sort((value1, value2) => dateEuroSorter(value1, value2, direction)); | ||
inputArray.sort((value1, value2) => sortByFieldType(FieldType.dateEuro, value1, value2, direction)); | ||
expect(inputArray).toEqual(['01/01/2000', '14/12/1998', '08/10/1998', '08/08/1998', null]); | ||
}); | ||
}); |
20 changes: 10 additions & 10 deletions
20
src/app/modules/angular-slickgrid/sorters/__tests__/dateIsoSorter.spec.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,33 +1,33 @@ | ||
import { SortDirectionNumber } from '../../models/sortDirectionNumber.enum'; | ||
import { dateIsoSorter } from '../dateIsoSorter'; | ||
import { sortByFieldType } from '../sorterUtilities'; | ||
import { FieldType, SortDirectionNumber } from '../../models'; | ||
|
||
describe('the Date ISO (without time) Sorter', () => { | ||
it('should return an array of US dates sorted ascending when only valid dates are provided', () => { | ||
const direction = SortDirectionNumber.asc; | ||
const inputArray = ['1998-08-08', '1998-10-08', '1998-08-08', '2001-01-01', '1998-12-14']; | ||
inputArray.sort((value1, value2) => dateIsoSorter(value1, value2, direction)); | ||
inputArray.sort((value1, value2) => sortByFieldType(FieldType.dateIso, value1, value2, direction)); | ||
expect(inputArray).toEqual(['1998-08-08', '1998-08-08', '1998-10-08', '1998-12-14', '2001-01-01']); | ||
}); | ||
|
||
it('should return an array of US dates sorted descending when only valid dates are provided', () => { | ||
const direction = SortDirectionNumber.desc; | ||
const inputArray = ['1998-08-08', '1998-10-08', null, '1998-08-08', '2001-01-01', '1998-12-14']; | ||
inputArray.sort((value1, value2) => dateIsoSorter(value1, value2, direction)); | ||
inputArray.sort((value1, value2) => sortByFieldType(FieldType.dateIso, value1, value2, direction)); | ||
expect(inputArray).toEqual(['2001-01-01', '1998-12-14', '1998-10-08', '1998-08-08', '1998-08-08', null]); | ||
}); | ||
|
||
it(`should return an array with unsorted characters showing at the beginning | ||
then comes numbers sorted ascending when digits and chars are provided`, () => { | ||
const direction = SortDirectionNumber.asc; | ||
const inputArray = ['1998-10-08', 'y', '1998-08-08', '2001-01-01', '1998-12-14']; | ||
inputArray.sort((value1, value2) => dateIsoSorter(value1, value2, direction)); | ||
expect(inputArray).toEqual(['y', '1998-08-08', '1998-10-08', '1998-12-14', '2001-01-01']); | ||
}); | ||
const direction = SortDirectionNumber.asc; | ||
const inputArray = ['1998-10-08', 'y', '1998-08-08', '2001-01-01', '1998-12-14']; | ||
inputArray.sort((value1, value2) => sortByFieldType(FieldType.dateIso, value1, value2, direction)); | ||
expect(inputArray).toEqual(['y', '1998-08-08', '1998-10-08', '1998-12-14', '2001-01-01']); | ||
}); | ||
|
||
it(`should return an array with dates sorted descending showing at the beginning then characters`, () => { | ||
const direction = SortDirectionNumber.desc; | ||
const inputArray = ['1998-10-08', null, '1998-08-08', '2001-01-01', '1998-12-14']; | ||
inputArray.sort((value1, value2) => dateIsoSorter(value1, value2, direction)); | ||
inputArray.sort((value1, value2) => sortByFieldType(FieldType.dateIso, value1, value2, direction)); | ||
expect(inputArray).toEqual(['2001-01-01', '1998-12-14', '1998-10-08', '1998-08-08', null]); | ||
}); | ||
}); |
20 changes: 10 additions & 10 deletions
20
src/app/modules/angular-slickgrid/sorters/__tests__/dateSorter.spec.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,33 +1,33 @@ | ||
import { SortDirectionNumber } from '../../models/sortDirectionNumber.enum'; | ||
import { dateSorter } from '../dateSorter'; | ||
import { sortByFieldType } from '../sorterUtilities'; | ||
import { FieldType, SortDirectionNumber } from '../../models'; | ||
|
||
describe('the Date Sorter (ISO format with optional time included)', () => { | ||
it('should return an array of ISO dates sorted ascending when only valid dates are provided', () => { | ||
const direction = SortDirectionNumber.asc; | ||
const inputArray = ['1998-08-08', '1998-08-09 01:01:10', null, '1998-08-08', '2000-01-01 23:00:05', '1998-08-09 01:01:11']; | ||
inputArray.sort((value1, value2) => dateSorter(value1, value2, direction)); | ||
inputArray.sort((value1, value2) => sortByFieldType(FieldType.date, value1, value2, direction)); | ||
expect(inputArray).toEqual([null, '1998-08-08', '1998-08-08', '1998-08-09 01:01:10', '1998-08-09 01:01:11', '2000-01-01 23:00:05']); | ||
}); | ||
|
||
it('should return an array of ISO dates sorted descending when only valid dates are provided', () => { | ||
const direction = SortDirectionNumber.desc; | ||
const inputArray = ['1998-08-08', '1998-08-09 01:01:10', null, '1998-08-08', '2000-01-01 23:00:05', '1998-08-09 01:01:11']; | ||
inputArray.sort((value1, value2) => dateSorter(value1, value2, direction)); | ||
inputArray.sort((value1, value2) => sortByFieldType(FieldType.date, value1, value2, direction)); | ||
expect(inputArray).toEqual(['2000-01-01 23:00:05', '1998-08-09 01:01:11', '1998-08-09 01:01:10', '1998-08-08', '1998-08-08', null]); | ||
}); | ||
|
||
it(`should return an array with unsorted characters showing at the beginning | ||
then comes numbers sorted ascending when digits and chars are provided`, () => { | ||
const direction = SortDirectionNumber.asc; | ||
const inputArray = ['1998-08-09 01:01:10', 'y', '1998-08-08', '2000-01-01 23:00:05', '1998-08-09 01:01:11']; | ||
inputArray.sort((value1, value2) => dateSorter(value1, value2, direction)); | ||
expect(inputArray).toEqual(['y', '1998-08-08', '1998-08-09 01:01:10', '1998-08-09 01:01:11', '2000-01-01 23:00:05']); | ||
}); | ||
const direction = SortDirectionNumber.asc; | ||
const inputArray = ['1998-08-09 01:01:10', 'y', '1998-08-08', '2000-01-01 23:00:05', '1998-08-09 01:01:11']; | ||
inputArray.sort((value1, value2) => sortByFieldType(FieldType.date, value1, value2, direction)); | ||
expect(inputArray).toEqual(['y', '1998-08-08', '1998-08-09 01:01:10', '1998-08-09 01:01:11', '2000-01-01 23:00:05']); | ||
}); | ||
|
||
it(`should return an array with dates sorted descending showing at the beginning then characters`, () => { | ||
const direction = SortDirectionNumber.desc; | ||
const inputArray = ['1998-08-09 01:01:10', null, '1998-08-08', '2000-01-01 23:00:05', '1998-08-09 01:01:11']; | ||
inputArray.sort((value1, value2) => dateSorter(value1, value2, direction)); | ||
inputArray.sort((value1, value2) => sortByFieldType(FieldType.date, value1, value2, direction)); | ||
expect(inputArray).toEqual(['2000-01-01 23:00:05', '1998-08-09 01:01:11', '1998-08-09 01:01:10', '1998-08-08', null]); | ||
}); | ||
}); |
20 changes: 10 additions & 10 deletions
20
src/app/modules/angular-slickgrid/sorters/__tests__/dateUsShortSorter.spec.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,33 +1,33 @@ | ||
import { SortDirectionNumber } from '../../models/sortDirectionNumber.enum'; | ||
import { dateUsShortSorter } from '../dateUsShortSorter'; | ||
import { sortByFieldType } from '../sorterUtilities'; | ||
import { FieldType, SortDirectionNumber } from '../../models'; | ||
|
||
describe('the Date US Short Sorter', () => { | ||
it('should return an array of US dates sorted ascending when only valid dates are provided', () => { | ||
const direction = SortDirectionNumber.asc; | ||
const inputArray = ['8/8/98', '10/8/98', '8/8/98', '01/01/18', '12/14/98']; | ||
inputArray.sort((value1, value2) => dateUsShortSorter(value1, value2, direction)); | ||
inputArray.sort((value1, value2) => sortByFieldType(FieldType.dateUsShort, value1, value2, direction)); | ||
expect(inputArray).toEqual(['8/8/98', '8/8/98', '10/8/98', '12/14/98', '01/01/18']); | ||
}); | ||
|
||
it('should return an array of US dates sorted descending when only valid dates are provided', () => { | ||
const direction = SortDirectionNumber.desc; | ||
const inputArray = ['8/8/98', '10/8/98', null, '8/8/98', '01/01/18', '12/14/98']; | ||
inputArray.sort((value1, value2) => dateUsShortSorter(value1, value2, direction)); | ||
inputArray.sort((value1, value2) => sortByFieldType(FieldType.dateUsShort, value1, value2, direction)); | ||
expect(inputArray).toEqual(['01/01/18', '12/14/98', '10/8/98', '8/8/98', '8/8/98', null]); | ||
}); | ||
|
||
it(`should return an array with unsorted characters showing at the beginning | ||
then comes numbers sorted ascending when digits and chars are provided`, () => { | ||
const direction = SortDirectionNumber.asc; | ||
const inputArray = ['10/8/98', 'y', '8/8/98', '01/01/18', '12/14/98']; | ||
inputArray.sort((value1, value2) => dateUsShortSorter(value1, value2, direction)); | ||
expect(inputArray).toEqual(['y', '8/8/98', '10/8/98', '12/14/98', '01/01/18']); | ||
}); | ||
const direction = SortDirectionNumber.asc; | ||
const inputArray = ['10/8/98', 'y', '8/8/98', '01/01/18', '12/14/98']; | ||
inputArray.sort((value1, value2) => sortByFieldType(FieldType.dateUsShort, value1, value2, direction)); | ||
expect(inputArray).toEqual(['y', '8/8/98', '10/8/98', '12/14/98', '01/01/18']); | ||
}); | ||
|
||
it(`should return an array with dates sorted descending showing at the beginning then characters`, () => { | ||
const direction = SortDirectionNumber.desc; | ||
const inputArray = ['10/8/98', null, '8/8/98', '01/01/18', '12/14/98']; | ||
inputArray.sort((value1, value2) => dateUsShortSorter(value1, value2, direction)); | ||
inputArray.sort((value1, value2) => sortByFieldType(FieldType.dateUsShort, value1, value2, direction)); | ||
expect(inputArray).toEqual(['01/01/18', '12/14/98', '10/8/98', '8/8/98', null]); | ||
}); | ||
}); |
20 changes: 10 additions & 10 deletions
20
src/app/modules/angular-slickgrid/sorters/__tests__/dateUsSorter.spec.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,33 +1,33 @@ | ||
import { SortDirectionNumber } from '../../models/sortDirectionNumber.enum'; | ||
import { dateUsSorter } from '../dateUsSorter'; | ||
import { sortByFieldType } from '../sorterUtilities'; | ||
import { FieldType, SortDirectionNumber } from '../../models'; | ||
|
||
describe('the Date US Sorter', () => { | ||
it('should return an array of US dates sorted ascending when only valid dates are provided', () => { | ||
const direction = SortDirectionNumber.asc; | ||
const inputArray = ['08/08/1998', '10/08/1998', '08/08/1998', '01/01/2000', '12/14/1998']; | ||
inputArray.sort((value1, value2) => dateUsSorter(value1, value2, direction)); | ||
inputArray.sort((value1, value2) => sortByFieldType(FieldType.dateUs, value1, value2, direction)); | ||
expect(inputArray).toEqual(['08/08/1998', '08/08/1998', '10/08/1998', '12/14/1998', '01/01/2000']); | ||
}); | ||
|
||
it('should return an array of US dates sorted descending when only valid dates are provided', () => { | ||
const direction = SortDirectionNumber.desc; | ||
const inputArray = ['08/08/1998', '10/08/1998', null, '08/08/1998', '01/01/2000', '12/14/1998']; | ||
inputArray.sort((value1, value2) => dateUsSorter(value1, value2, direction)); | ||
inputArray.sort((value1, value2) => sortByFieldType(FieldType.dateUs, value1, value2, direction)); | ||
expect(inputArray).toEqual(['01/01/2000', '12/14/1998', '10/08/1998', '08/08/1998', '08/08/1998', null]); | ||
}); | ||
|
||
it(`should return an array with unsorted characters showing at the beginning | ||
then comes numbers sorted ascending when digits and chars are provided`, () => { | ||
const direction = SortDirectionNumber.asc; | ||
const inputArray = ['10/08/1998', 'y', '08/08/1998', '01/01/2000', '12/14/1998']; | ||
inputArray.sort((value1, value2) => dateUsSorter(value1, value2, direction)); | ||
expect(inputArray).toEqual(['y', '08/08/1998', '10/08/1998', '12/14/1998', '01/01/2000']); | ||
}); | ||
const direction = SortDirectionNumber.asc; | ||
const inputArray = ['10/08/1998', 'y', '08/08/1998', '01/01/2000', '12/14/1998']; | ||
inputArray.sort((value1, value2) => sortByFieldType(FieldType.dateUs, value1, value2, direction)); | ||
expect(inputArray).toEqual(['y', '08/08/1998', '10/08/1998', '12/14/1998', '01/01/2000']); | ||
}); | ||
|
||
it(`should return an array with dates sorted descending showing at the beginning then characters`, () => { | ||
const direction = SortDirectionNumber.desc; | ||
const inputArray = ['10/08/1998', null, '08/08/1998', '01/01/2000', '12/14/1998']; | ||
inputArray.sort((value1, value2) => dateUsSorter(value1, value2, direction)); | ||
inputArray.sort((value1, value2) => sortByFieldType(FieldType.dateUs, value1, value2, direction)); | ||
expect(inputArray).toEqual(['01/01/2000', '12/14/1998', '10/08/1998', '08/08/1998', null]); | ||
}); | ||
}); |
Oops, something went wrong.