|
1 | 1 | import { describe, expect, it, vi } from 'vitest'; |
2 | 2 | import { SortDirectionNumber } from '../../enums/index.js'; |
3 | 3 | import type { Column } from '../../interfaces/index.js'; |
4 | | -import { SortComparers } from '../sortComparers.index.js'; |
| 4 | +import * as booleanModule from '../booleanSortComparer.js'; |
| 5 | +import * as numericModule from '../numericSortComparer.js'; |
| 6 | +import * as objectStringModule from '../objectStringSortComparer.js'; |
5 | 7 | import { sortByFieldType } from '../sortUtilities.js'; |
| 8 | +import * as stringModule from '../stringSortComparer.js'; |
6 | 9 |
|
7 | 10 | describe('sortUtilities', () => { |
8 | | - it('should call the SortComparers.boolean when FieldType is boolean', () => { |
9 | | - const spy = vi.spyOn(SortComparers, 'boolean'); |
| 11 | + it('should call the booleanSortComparer when FieldType is boolean', () => { |
| 12 | + const spy = vi.spyOn(booleanModule, 'booleanSortComparer'); |
10 | 13 | sortByFieldType('boolean', 0, 4, SortDirectionNumber.asc, { id: 'field1', field: 'field1' }); |
11 | 14 | expect(spy).toHaveBeenCalledWith(0, 4, SortDirectionNumber.asc, { id: 'field1', field: 'field1' }, undefined); |
12 | 15 | }); |
13 | 16 |
|
14 | | - it('should call the SortComparers.numeric when FieldType is number', () => { |
15 | | - const spy = vi.spyOn(SortComparers, 'numeric'); |
| 17 | + it('should call the numericSortComparer when FieldType is number', () => { |
| 18 | + const spy = vi.spyOn(numericModule, 'numericSortComparer'); |
16 | 19 | sortByFieldType('number', 0, 4, SortDirectionNumber.asc, { id: 'field1', field: 'field1' }); |
17 | 20 | expect(spy).toHaveBeenCalledWith(0, 4, SortDirectionNumber.asc, { id: 'field1', field: 'field1' }, undefined); |
18 | 21 | }); |
19 | 22 |
|
20 | | - it('should call the SortComparers.numeric when FieldType is integer', () => { |
21 | | - const spy = vi.spyOn(SortComparers, 'numeric'); |
| 23 | + it('should call the numericSortComparer when FieldType is integer', () => { |
| 24 | + const spy = vi.spyOn(numericModule, 'numericSortComparer'); |
22 | 25 | sortByFieldType('integer', 0, 4, SortDirectionNumber.asc, { id: 'field1', field: 'field1' }); |
23 | 26 | expect(spy).toHaveBeenCalledWith(0, 4, SortDirectionNumber.asc, { id: 'field1', field: 'field1' }, undefined); |
24 | 27 | }); |
25 | 28 |
|
26 | | - it('should call the SortComparers.numeric when FieldType is float', () => { |
27 | | - const spy = vi.spyOn(SortComparers, 'numeric'); |
| 29 | + it('should call the numericSortComparer when FieldType is float', () => { |
| 30 | + const spy = vi.spyOn(numericModule, 'numericSortComparer'); |
28 | 31 | sortByFieldType('float', 0, 4, SortDirectionNumber.asc, { id: 'field1', field: 'field1' }); |
29 | 32 | expect(spy).toHaveBeenCalledWith(0, 4, SortDirectionNumber.asc, { id: 'field1', field: 'field1' }, undefined); |
30 | 33 | }); |
31 | 34 |
|
32 | | - it('should call the SortComparers.string when FieldType is a string (which is also the default)', () => { |
| 35 | + it('should call the stringSortComparer when FieldType is a string (which is also the default)', () => { |
33 | 36 | const string1 = 'John'; |
34 | 37 | const string2 = 'Jane'; |
35 | | - const spy = vi.spyOn(SortComparers, 'string'); |
| 38 | + const spy = vi.spyOn(stringModule, 'stringSortComparer'); |
36 | 39 | sortByFieldType('string', string1, string2, SortDirectionNumber.asc, { id: 'field1', field: 'field1' }); |
37 | 40 | expect(spy).toHaveBeenCalledWith(string1, string2, SortDirectionNumber.asc, { id: 'field1', field: 'field1' }, undefined); |
38 | 41 | }); |
39 | 42 |
|
40 | | - it('should call the SortComparers.date when FieldType is any date types', () => { |
| 43 | + it('should call the date comparer when FieldType is any date types', () => { |
41 | 44 | const result1 = sortByFieldType('dateIso', '2020-01-01', '2020-02-01', SortDirectionNumber.asc, { id: 'field1', field: 'field1' }); |
42 | 45 | expect(result1).toBeLessThan(0); |
43 | 46 |
|
44 | 47 | const result2 = sortByFieldType('dateIso', '2020-02-01', '2020-01-01', SortDirectionNumber.asc, { id: 'field1', field: 'field1' }); |
45 | 48 | expect(result2).toBeGreaterThan(0); |
46 | 49 | }); |
47 | 50 |
|
48 | | - it('should call the SortComparers.objectString when FieldType is objectString', () => { |
| 51 | + it('should call the objectStringSortComparer when FieldType is objectString', () => { |
49 | 52 | const object1 = { firstName: 'John', lastName: 'Z' }; |
50 | 53 | const object2 = { firstName: 'Jane', lastName: 'Doe' }; |
51 | 54 | const mockColumn = { id: 'field1', field: 'field1', dataKey: 'firstName' } as Column; |
52 | | - const spy = vi.spyOn(SortComparers, 'objectString'); |
| 55 | + const spy = vi.spyOn(objectStringModule, 'objectStringSortComparer'); |
53 | 56 | sortByFieldType('object', object1, object2, SortDirectionNumber.asc, mockColumn); |
54 | 57 | expect(spy).toHaveBeenCalledWith(object1, object2, SortDirectionNumber.asc, mockColumn, undefined); |
55 | 58 | }); |
|
0 commit comments