@zeedhi/teknisa-components-common 3.0.0 → 3.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.package.json +4 -1
- package/dist/teknisa-components-common.js +3722 -32
- package/dist/teknisa-components-common.min.js +3722 -32
- package/dist/types/components/index.d.ts +5 -0
- package/dist/types/components/tek-datasource/index.d.ts +3 -0
- package/dist/types/components/tek-datasource/interfaces.d.ts +16 -0
- package/dist/types/components/tek-datasource/tek-memory-datasource.d.ts +93 -0
- package/dist/types/components/tek-datasource/tek-rest-datasource.d.ts +95 -0
- package/dist/types/components/tek-grid/columns-searcher.d.ts +5 -0
- package/dist/types/components/tek-grid/dynamic-filter-datasource-factory.d.ts +6 -0
- package/dist/types/components/tek-grid/filter-helper.d.ts +7 -0
- package/dist/types/components/tek-grid/grid-filter-button.d.ts +29 -0
- package/dist/types/components/tek-grid/grouped-data-manager.d.ts +82 -0
- package/dist/types/components/tek-grid/grouped-data-selector.d.ts +7 -0
- package/dist/types/components/tek-grid/grouped-view-navigator.d.ts +14 -0
- package/dist/types/components/tek-grid/index.d.ts +18 -0
- package/dist/types/components/tek-grid/interfaces.d.ts +259 -0
- package/dist/types/components/tek-grid/keymap-grouped.d.ts +6 -0
- package/dist/types/components/tek-grid/layout-options.d.ts +39 -0
- package/dist/types/components/tek-grid/tek-grid-column.d.ts +42 -0
- package/dist/types/components/tek-grid/tek-grid-columns-button/tek-grid-columns-button-controller.d.ts +8 -0
- package/dist/types/components/tek-grid/tek-grid-columns-button/tek-grid-columns-button.d.ts +13 -0
- package/dist/types/components/tek-grid/tek-grid-controller.d.ts +31 -0
- package/dist/types/components/tek-grid/tek-grid-events.d.ts +31 -0
- package/dist/types/components/tek-grid/tek-grid-toolbar-provider/export-options/button-option.d.ts +17 -0
- package/dist/types/components/tek-grid/tek-grid-toolbar-provider/export-options/index.d.ts +3 -0
- package/dist/types/components/tek-grid/tek-grid-toolbar-provider/export-options/interfaces.d.ts +5 -0
- package/dist/types/components/tek-grid/tek-grid-toolbar-provider/export-options/multi-option.d.ts +12 -0
- package/dist/types/components/tek-grid/tek-grid-toolbar-provider/index.d.ts +2 -0
- package/dist/types/components/tek-grid/tek-grid-toolbar-provider/tek-grid-toolbar-provider.d.ts +22 -0
- package/dist/types/components/tek-grid/tek-grid.d.ts +216 -0
- package/dist/types/components/tek-user-info/TekUserInfoController.d.ts +22 -0
- package/dist/types/components/tek-user-info/interfaces.d.ts +27 -0
- package/dist/types/components/tek-user-info/tek-user-info-list.d.ts +32 -0
- package/dist/types/components/tek-user-info/tek-user-info.d.ts +37 -0
- package/dist/types/error/tek-grid-delete-rows-error.d.ts +7 -0
- package/dist/types/error/teknisa-common-error.d.ts +6 -0
- package/dist/types/index.d.ts +1 -0
- package/dist/types/utils/config/config.d.ts +7 -0
- package/dist/types/utils/index.d.ts +3 -0
- package/dist/types/utils/is-filled-object/is-filled-object.d.ts +2 -0
- package/dist/types/utils/is-nil.d.ts +1 -0
- package/package.json +2 -2
- package/src/components/index.ts +5 -12
- package/src/components/tek-datasource/index.ts +3 -0
- package/src/components/tek-datasource/interfaces.ts +36 -0
- package/src/components/tek-datasource/tek-memory-datasource.ts +314 -0
- package/src/components/tek-datasource/tek-rest-datasource.ts +224 -0
- package/src/components/tek-grid/columns-searcher.ts +22 -0
- package/src/components/tek-grid/dynamic-filter-datasource-factory.ts +20 -0
- package/src/components/tek-grid/filter-helper.ts +20 -0
- package/src/components/tek-grid/grid-filter-button.ts +419 -0
- package/src/components/tek-grid/grouped-data-manager.ts +448 -0
- package/src/components/tek-grid/grouped-data-selector.ts +40 -0
- package/src/components/tek-grid/grouped-view-navigator.ts +84 -0
- package/src/components/tek-grid/index.ts +18 -0
- package/src/components/tek-grid/interfaces.ts +329 -0
- package/src/components/tek-grid/keymap-grouped.ts +20 -0
- package/src/components/tek-grid/layout-options.ts +248 -0
- package/src/components/tek-grid/tek-grid-column.ts +193 -0
- package/src/components/tek-grid/tek-grid-columns-button/tek-grid-columns-button-controller.ts +28 -0
- package/src/components/tek-grid/tek-grid-columns-button/tek-grid-columns-button.ts +38 -0
- package/src/components/tek-grid/tek-grid-controller.ts +140 -0
- package/src/components/tek-grid/tek-grid-events.ts +105 -0
- package/src/components/tek-grid/tek-grid-toolbar-provider/export-options/button-option.ts +26 -0
- package/src/components/tek-grid/tek-grid-toolbar-provider/export-options/index.ts +3 -0
- package/src/components/tek-grid/tek-grid-toolbar-provider/export-options/interfaces.ts +6 -0
- package/src/components/tek-grid/tek-grid-toolbar-provider/export-options/multi-option.ts +85 -0
- package/src/components/tek-grid/tek-grid-toolbar-provider/index.ts +2 -0
- package/src/components/tek-grid/tek-grid-toolbar-provider/tek-grid-toolbar-provider.ts +365 -0
- package/src/components/tek-grid/tek-grid.ts +1118 -0
- package/src/components/tek-user-info/TekUserInfoController.ts +87 -0
- package/src/components/tek-user-info/interfaces.ts +21 -0
- package/src/components/tek-user-info/tek-user-info-list.ts +64 -0
- package/src/components/tek-user-info/tek-user-info.ts +337 -0
- package/src/error/tek-grid-delete-rows-error.ts +15 -0
- package/src/error/teknisa-common-error.ts +8 -0
- package/src/index.ts +1 -0
- package/src/utils/config/config.ts +8 -0
- package/src/utils/index.ts +3 -0
- package/src/utils/is-filled-object/is-filled-object.ts +5 -0
- package/src/utils/is-nil.ts +3 -0
- package/tests/unit/components/tek-grid/button-option.spec.ts +49 -0
- package/tests/unit/components/tek-grid/columns-searcher.spec.ts +112 -0
- package/tests/unit/components/tek-grid/dynamic-filter-datasource-factory.spec.ts +90 -0
- package/tests/unit/components/tek-grid/filter-helper.spec.ts +34 -130
- package/tests/unit/components/tek-grid/grid-filter-button.spec.ts +110 -241
- package/tests/unit/components/tek-grid/grouped-data-manager.spec.ts +593 -0
- package/tests/unit/components/tek-grid/grouped-data-selector.spec.ts +136 -0
- package/tests/unit/components/tek-grid/grouped-view-navigator.spec.ts +244 -0
- package/tests/unit/components/tek-grid/keymap-grouped.spec.ts +20 -0
- package/tests/unit/components/tek-grid/{layout_options.spec.ts → layout-options.spec.ts} +77 -35
- package/tests/unit/components/tek-grid/multi-option.spec.ts +139 -0
- package/tests/unit/components/tek-grid/{grid-column.spec.ts → tek-grid-column.spec.ts} +48 -6
- package/tests/unit/components/tek-grid/{grid-columns-button.spec.ts → tek-grid-columns-button.spec.ts} +42 -9
- package/tests/unit/components/tek-grid/tek-grid-controller.spec.ts +253 -0
- package/tests/unit/components/tek-grid/tek-grid-events.spec.ts +186 -0
- package/tests/unit/components/tek-grid/tek-grid-toolbar-provider.spec.ts +34 -0
- package/tests/unit/components/tek-grid/tek-grid.spec.ts +895 -0
- package/tests/unit/components/tek-grid/tek-memory-datasource.spec.ts +482 -0
- package/tests/unit/components/tek-grid/tek-rest-datasource.spec.ts +422 -0
- package/src/error/delete-rows-error.ts +0 -11
- package/tests/unit/components/tek-grid/grid.spec.ts +0 -2701
|
@@ -0,0 +1,112 @@
|
|
|
1
|
+
import { ColumnsSearcher, ITekGridColumn } from '../../../../src';
|
|
2
|
+
|
|
3
|
+
describe("ColumnsSearcher", () => {
|
|
4
|
+
let columnsSearcher: ColumnsSearcher;
|
|
5
|
+
|
|
6
|
+
beforeEach(() => {
|
|
7
|
+
columnsSearcher = new ColumnsSearcher();
|
|
8
|
+
});
|
|
9
|
+
|
|
10
|
+
describe("searchColumn", () => {
|
|
11
|
+
it("should return empty object when search string is empty", async () => {
|
|
12
|
+
const columns: ITekGridColumn[] = [
|
|
13
|
+
{
|
|
14
|
+
name: "testColumn",
|
|
15
|
+
componentProps: { name: 'testColumnName', datasource: { uniqueKey: "id" } },
|
|
16
|
+
memorySearch: jest.fn(),
|
|
17
|
+
},
|
|
18
|
+
];
|
|
19
|
+
const search = "";
|
|
20
|
+
|
|
21
|
+
const result = await columnsSearcher.searchColumn(columns, search);
|
|
22
|
+
|
|
23
|
+
expect(result).toEqual({});
|
|
24
|
+
expect(columns[0].memorySearch).not.toHaveBeenCalled();
|
|
25
|
+
});
|
|
26
|
+
|
|
27
|
+
it("should skip columns without datasource", async () => {
|
|
28
|
+
const columns: ITekGridColumn[] = [
|
|
29
|
+
{
|
|
30
|
+
name: "noDataSourceColumn",
|
|
31
|
+
componentProps: { name: 'noDataSourceColumnName' },
|
|
32
|
+
memorySearch: jest.fn(),
|
|
33
|
+
},
|
|
34
|
+
{
|
|
35
|
+
name: "validColumn",
|
|
36
|
+
componentProps: { name: 'validColumnName', datasource: { uniqueKey: "id" } },
|
|
37
|
+
memorySearch: jest.fn().mockResolvedValue([{ id: 1 }]),
|
|
38
|
+
},
|
|
39
|
+
];
|
|
40
|
+
const search = "test";
|
|
41
|
+
|
|
42
|
+
const result = await columnsSearcher.searchColumn(columns, search);
|
|
43
|
+
|
|
44
|
+
expect(result).toEqual({ validColumn: [1] });
|
|
45
|
+
expect(columns[0].memorySearch).not.toHaveBeenCalled();
|
|
46
|
+
expect(columns[1].memorySearch).toHaveBeenCalledWith("test");
|
|
47
|
+
});
|
|
48
|
+
|
|
49
|
+
it("should skip columns with skipLookupSearch=true", async () => {
|
|
50
|
+
const columns: ITekGridColumn[] = [
|
|
51
|
+
{
|
|
52
|
+
name: "skippedColumn",
|
|
53
|
+
componentProps: { name: 'skippedColumnName', datasource: { uniqueKey: "id" } },
|
|
54
|
+
skipLookupSearch: true,
|
|
55
|
+
memorySearch: jest.fn(),
|
|
56
|
+
},
|
|
57
|
+
{
|
|
58
|
+
name: "validColumn",
|
|
59
|
+
componentProps: { name: 'validColumnName', datasource: { uniqueKey: "id" } },
|
|
60
|
+
memorySearch: jest.fn().mockResolvedValue([{ id: 1 }]),
|
|
61
|
+
},
|
|
62
|
+
];
|
|
63
|
+
const search = "test";
|
|
64
|
+
|
|
65
|
+
const result = await columnsSearcher.searchColumn(columns, search);
|
|
66
|
+
|
|
67
|
+
expect(result).toEqual({ validColumn: [1] });
|
|
68
|
+
expect(columns[0].memorySearch).not.toHaveBeenCalled();
|
|
69
|
+
expect(columns[1].memorySearch).toHaveBeenCalledWith("test");
|
|
70
|
+
});
|
|
71
|
+
|
|
72
|
+
it("should process multiple columns in parallel", async () => {
|
|
73
|
+
const columns: ITekGridColumn[] = [
|
|
74
|
+
{
|
|
75
|
+
name: "column1",
|
|
76
|
+
componentProps: { name: 'column1Name', datasource: { uniqueKey: "id" } },
|
|
77
|
+
memorySearch: jest.fn().mockResolvedValue([{ id: 1 }, { id: 2 }]),
|
|
78
|
+
},
|
|
79
|
+
{
|
|
80
|
+
name: "column2",
|
|
81
|
+
componentProps: { name: 'column2Name', datasource: { uniqueKey: "code" } },
|
|
82
|
+
memorySearch: jest.fn().mockResolvedValue([{ code: "A" }, { code: "B" }]),
|
|
83
|
+
},
|
|
84
|
+
];
|
|
85
|
+
const search = "test";
|
|
86
|
+
|
|
87
|
+
const result = await columnsSearcher.searchColumn(columns, search);
|
|
88
|
+
|
|
89
|
+
expect(result).toEqual({
|
|
90
|
+
column1: [1, 2],
|
|
91
|
+
column2: ["A", "B"],
|
|
92
|
+
});
|
|
93
|
+
expect(columns[0].memorySearch).toHaveBeenCalledWith("test");
|
|
94
|
+
expect(columns[1].memorySearch).toHaveBeenCalledWith("test");
|
|
95
|
+
});
|
|
96
|
+
|
|
97
|
+
it("should handle empty search results", async () => {
|
|
98
|
+
const columns: ITekGridColumn[] = [
|
|
99
|
+
{
|
|
100
|
+
name: "emptyResultsColumn",
|
|
101
|
+
componentProps: { name: 'emptyResultsColumnName', datasource: { uniqueKey: "id" } },
|
|
102
|
+
memorySearch: jest.fn().mockResolvedValue([]),
|
|
103
|
+
},
|
|
104
|
+
];
|
|
105
|
+
const search = "test";
|
|
106
|
+
|
|
107
|
+
const result = await columnsSearcher.searchColumn(columns, search);
|
|
108
|
+
|
|
109
|
+
expect(result).toEqual({ emptyResultsColumn: [] });
|
|
110
|
+
});
|
|
111
|
+
});
|
|
112
|
+
});
|
|
@@ -0,0 +1,90 @@
|
|
|
1
|
+
import { Datasource, DatasourceFactory, IDictionary } from '@zeedhi/core';
|
|
2
|
+
import { DynamicFilterDatasourceFactory } from '../../../../src';
|
|
3
|
+
|
|
4
|
+
describe('DynamicFilterDatasourceFactory', () => {
|
|
5
|
+
let factory: DynamicFilterDatasourceFactory;
|
|
6
|
+
let mockDatasourceFactory: jest.Mocked<typeof DatasourceFactory>;
|
|
7
|
+
|
|
8
|
+
beforeEach(() => {
|
|
9
|
+
factory = new DynamicFilterDatasourceFactory();
|
|
10
|
+
|
|
11
|
+
// Create a mock for just the DatasourceFactory.factory method
|
|
12
|
+
mockDatasourceFactory = {
|
|
13
|
+
factory: jest.fn(),
|
|
14
|
+
} as unknown as jest.Mocked<typeof DatasourceFactory>;
|
|
15
|
+
|
|
16
|
+
// Replace the original implementation with our mock
|
|
17
|
+
jest.spyOn(DatasourceFactory, 'factory').mockImplementation(mockDatasourceFactory.factory);
|
|
18
|
+
});
|
|
19
|
+
|
|
20
|
+
afterEach(() => {
|
|
21
|
+
jest.restoreAllMocks();
|
|
22
|
+
});
|
|
23
|
+
|
|
24
|
+
describe('factory', () => {
|
|
25
|
+
it('should create a datasource with correct configuration', () => {
|
|
26
|
+
const mockOptions: IDictionary<boolean> = {
|
|
27
|
+
option1: true,
|
|
28
|
+
option2: false,
|
|
29
|
+
};
|
|
30
|
+
const expectedData = [
|
|
31
|
+
{ text: 'TEKGRID_option1', value: 'option1' },
|
|
32
|
+
{ text: 'TEKGRID_option2', value: 'option2' },
|
|
33
|
+
];
|
|
34
|
+
const mockDatasource = {} as Datasource;
|
|
35
|
+
|
|
36
|
+
mockDatasourceFactory.factory.mockReturnValue(mockDatasource);
|
|
37
|
+
|
|
38
|
+
const result = factory.factory(mockOptions);
|
|
39
|
+
|
|
40
|
+
expect(mockDatasourceFactory.factory).toHaveBeenCalledWith({
|
|
41
|
+
data: expectedData,
|
|
42
|
+
loadAll: true,
|
|
43
|
+
translate: ['text'],
|
|
44
|
+
});
|
|
45
|
+
expect(result).toBe(mockDatasource);
|
|
46
|
+
});
|
|
47
|
+
|
|
48
|
+
it('should handle empty options', () => {
|
|
49
|
+
const mockOptions: IDictionary<boolean> = {};
|
|
50
|
+
const mockDatasource = {} as Datasource;
|
|
51
|
+
|
|
52
|
+
mockDatasourceFactory.factory.mockReturnValue(mockDatasource);
|
|
53
|
+
|
|
54
|
+
const result = factory.factory(mockOptions);
|
|
55
|
+
|
|
56
|
+
expect(mockDatasourceFactory.factory).toHaveBeenCalledWith({
|
|
57
|
+
data: [],
|
|
58
|
+
loadAll: true,
|
|
59
|
+
translate: ['text'],
|
|
60
|
+
});
|
|
61
|
+
expect(result).toBe(mockDatasource);
|
|
62
|
+
});
|
|
63
|
+
});
|
|
64
|
+
|
|
65
|
+
describe('getFilterOptionsData', () => {
|
|
66
|
+
// Since this is a private method, we'll test it indirectly through the public factory method
|
|
67
|
+
// If you want to test it directly, you might need to make it public or use type assertions
|
|
68
|
+
|
|
69
|
+
it('should transform options correctly (tested through factory)', () => {
|
|
70
|
+
const mockOptions: IDictionary<boolean> = {
|
|
71
|
+
active: true,
|
|
72
|
+
inactive: false,
|
|
73
|
+
};
|
|
74
|
+
const mockDatasource = {} as Datasource;
|
|
75
|
+
|
|
76
|
+
mockDatasourceFactory.factory.mockReturnValue(mockDatasource);
|
|
77
|
+
|
|
78
|
+
factory.factory(mockOptions);
|
|
79
|
+
|
|
80
|
+
expect(mockDatasourceFactory.factory).toHaveBeenCalledWith({
|
|
81
|
+
data: [
|
|
82
|
+
{ text: 'TEKGRID_active', value: 'active' },
|
|
83
|
+
{ text: 'TEKGRID_inactive', value: 'inactive' },
|
|
84
|
+
],
|
|
85
|
+
loadAll: true,
|
|
86
|
+
translate: ['text'],
|
|
87
|
+
});
|
|
88
|
+
});
|
|
89
|
+
});
|
|
90
|
+
});
|
|
@@ -1,148 +1,52 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
1
|
+
import { DateHelper } from '@zeedhi/core';
|
|
2
|
+
import { TekGridColumn, TekFilterHelper } from '../../../../src';
|
|
3
|
+
|
|
4
|
+
// Mock the DateHelper module
|
|
5
|
+
jest.mock('@zeedhi/core');
|
|
3
6
|
|
|
4
7
|
describe('TekFilterHelper', () => {
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
+
afterEach(() => {
|
|
9
|
+
jest.clearAllMocks();
|
|
10
|
+
});
|
|
8
11
|
|
|
9
|
-
|
|
10
|
-
|
|
12
|
+
describe('getLabel', () => {
|
|
13
|
+
it('should call DateHelper.getLabel with the provided name', () => {
|
|
14
|
+
const testName = 'testFilter';
|
|
15
|
+
TekFilterHelper.getLabel(testName);
|
|
16
|
+
expect(DateHelper.getLabel).toHaveBeenCalledWith(testName);
|
|
11
17
|
});
|
|
12
18
|
});
|
|
13
19
|
|
|
14
20
|
describe('getValue', () => {
|
|
15
|
-
it('should
|
|
16
|
-
const
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
dateFormat: 'YYYY-MM-DD',
|
|
26
|
-
},
|
|
27
|
-
},
|
|
28
|
-
],
|
|
29
|
-
});
|
|
30
|
-
const today = dayjs().format('YYYY-MM-DD');
|
|
31
|
-
const tomorrow = dayjs().add(1, 'day').format('YYYY-MM-DD');
|
|
32
|
-
const yesterday = dayjs().subtract(1, 'day').format('YYYY-MM-DD');
|
|
33
|
-
const last7Days = [
|
|
34
|
-
dayjs().subtract(7, 'day').format('YYYY-MM-DD'),
|
|
35
|
-
dayjs().format('YYYY-MM-DD'),
|
|
36
|
-
];
|
|
37
|
-
const next7Days = [
|
|
38
|
-
dayjs().format('YYYY-MM-DD'),
|
|
39
|
-
dayjs().add(7, 'day').format('YYYY-MM-DD'),
|
|
40
|
-
];
|
|
41
|
-
const currentWeek = [
|
|
42
|
-
dayjs().startOf('week').format('YYYY-MM-DD'),
|
|
43
|
-
dayjs().endOf('week').format('YYYY-MM-DD'),
|
|
44
|
-
];
|
|
45
|
-
const currentMonth = [
|
|
46
|
-
dayjs().startOf('month').format('YYYY-MM-DD'),
|
|
47
|
-
dayjs().endOf('month').format('YYYY-MM-DD'),
|
|
48
|
-
];
|
|
49
|
-
const currentYear = [
|
|
50
|
-
dayjs().startOf('year').format('YYYY-MM-DD'),
|
|
51
|
-
dayjs().endOf('year').format('YYYY-MM-DD'),
|
|
52
|
-
];
|
|
53
|
-
expect(TekFilterHelper.getValue('TODAY', grid.columns[0])).toBe(today);
|
|
54
|
-
expect(TekFilterHelper.getValue('TOMORROW', grid.columns[0])).toBe(tomorrow);
|
|
55
|
-
expect(TekFilterHelper.getValue('YESTERDAY', grid.columns[0])).toBe(yesterday);
|
|
56
|
-
expect(TekFilterHelper.getValue('LAST_7_DAYS', grid.columns[0])).toEqual(last7Days);
|
|
57
|
-
expect(TekFilterHelper.getValue('NEXT_7_DAYS', grid.columns[0])).toEqual(next7Days);
|
|
58
|
-
expect(TekFilterHelper.getValue('CURRENT_WEEK', grid.columns[0])).toEqual(currentWeek);
|
|
59
|
-
expect(TekFilterHelper.getValue('CURRENT_MONTH', grid.columns[0])).toEqual(currentMonth);
|
|
60
|
-
expect(TekFilterHelper.getValue('CURRENT_YEAR', grid.columns[0])).toEqual(currentYear);
|
|
61
|
-
});
|
|
62
|
-
|
|
63
|
-
it('should use default date format if column does not have it', () => {
|
|
64
|
-
const grid = new TekGrid({
|
|
65
|
-
name: 'grid',
|
|
66
|
-
component: 'TekGrid',
|
|
67
|
-
columns: [
|
|
68
|
-
{
|
|
69
|
-
name: 'date',
|
|
70
|
-
},
|
|
71
|
-
],
|
|
72
|
-
});
|
|
73
|
-
const today = dayjs().format(Config.dateFormat);
|
|
74
|
-
expect(TekFilterHelper.getValue('TODAY', grid.columns[0])).toBe(today);
|
|
21
|
+
it('should call DateHelper.getValue with name and column dateFormat', () => {
|
|
22
|
+
const testName = 'testValue';
|
|
23
|
+
const mockColumn = {
|
|
24
|
+
componentProps: {
|
|
25
|
+
dateFormat: 'YYYY-MM-DD'
|
|
26
|
+
}
|
|
27
|
+
} as TekGridColumn;
|
|
28
|
+
|
|
29
|
+
TekFilterHelper.getValue(testName, mockColumn);
|
|
30
|
+
expect(DateHelper.getValue).toHaveBeenCalledWith(testName, mockColumn.componentProps.dateFormat);
|
|
75
31
|
});
|
|
76
32
|
});
|
|
77
33
|
|
|
78
34
|
describe('register', () => {
|
|
79
|
-
it('should register
|
|
80
|
-
const
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
columns: [
|
|
84
|
-
{
|
|
85
|
-
name: 'date',
|
|
86
|
-
componentProps: {
|
|
87
|
-
name: 'date-comp',
|
|
88
|
-
component: 'ZdDate',
|
|
89
|
-
dateFormat: 'YYYY-MM-DD',
|
|
90
|
-
},
|
|
91
|
-
},
|
|
92
|
-
],
|
|
93
|
-
});
|
|
35
|
+
it('should call DateHelper.register with provided parameters', () => {
|
|
36
|
+
const testName = 'testRegister';
|
|
37
|
+
const testLabel = 'Test Register';
|
|
38
|
+
const testFn = () => new Date();
|
|
94
39
|
|
|
95
|
-
TekFilterHelper.register(
|
|
96
|
-
|
|
97
|
-
if (today.date() <= 5) return today.date(5).toDate();
|
|
98
|
-
return today.add(1, 'month').date(5).toDate();
|
|
99
|
-
});
|
|
100
|
-
|
|
101
|
-
TekFilterHelper.register('NEXT_WEEK', 'Next Week', () => {
|
|
102
|
-
const startOfNextWeek = dayjs().startOf('week').add(1, 'week').toDate();
|
|
103
|
-
const endOfNextWeek = dayjs().endOf('week').add(1, 'week').toDate();
|
|
104
|
-
return [startOfNextWeek, endOfNextWeek];
|
|
105
|
-
});
|
|
106
|
-
|
|
107
|
-
const today = dayjs();
|
|
108
|
-
let nextFifth = '';
|
|
109
|
-
if (today.date() <= 5) {
|
|
110
|
-
nextFifth = today.date(5).format('YYYY-MM-DD');
|
|
111
|
-
} else {
|
|
112
|
-
nextFifth = today.add(1, 'month').date(5).format('YYYY-MM-DD');
|
|
113
|
-
}
|
|
114
|
-
|
|
115
|
-
const nextWeek = [
|
|
116
|
-
dayjs().startOf('week').add(1, 'week').format('YYYY-MM-DD'),
|
|
117
|
-
dayjs().endOf('week').add(1, 'week').format('YYYY-MM-DD'),
|
|
118
|
-
];
|
|
119
|
-
expect(TekFilterHelper.getValue('NEXT_FIFTH_OF_THE_MONTH', grid.columns[0])).toBe(nextFifth);
|
|
120
|
-
expect(TekFilterHelper.getValue('NEXT_WEEK', grid.columns[0])).toEqual(nextWeek);
|
|
40
|
+
TekFilterHelper.register(testName, testLabel, testFn);
|
|
41
|
+
expect(DateHelper.register).toHaveBeenCalledWith(testName, testLabel, testFn);
|
|
121
42
|
});
|
|
122
43
|
});
|
|
123
44
|
|
|
124
45
|
describe('unregister', () => {
|
|
125
|
-
it('should unregister
|
|
126
|
-
const
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
columns: [
|
|
130
|
-
{
|
|
131
|
-
name: 'date',
|
|
132
|
-
componentProps: {
|
|
133
|
-
name: 'date-comp',
|
|
134
|
-
component: 'ZdDate',
|
|
135
|
-
dateFormat: 'YYYY-MM-DD',
|
|
136
|
-
},
|
|
137
|
-
},
|
|
138
|
-
],
|
|
139
|
-
});
|
|
140
|
-
|
|
141
|
-
TekFilterHelper.unregister('NEXT_FIFTH_OF_THE_MONTH');
|
|
142
|
-
TekFilterHelper.unregister('NEXT_WEEK');
|
|
143
|
-
|
|
144
|
-
expect(TekFilterHelper.getValue('NEXT_FIFTH_OF_THE_MONTH', grid.columns[0])).toBe('');
|
|
145
|
-
expect(TekFilterHelper.getValue('NEXT_WEEK', grid.columns[0])).toEqual('');
|
|
46
|
+
it('should call DateHelper.unregister with the provided name', () => {
|
|
47
|
+
const testName = 'testUnregister';
|
|
48
|
+
TekFilterHelper.unregister(testName);
|
|
49
|
+
expect(DateHelper.unregister).toHaveBeenCalledWith(testName);
|
|
146
50
|
});
|
|
147
51
|
});
|
|
148
|
-
});
|
|
52
|
+
});
|