@zeedhi/teknisa-components-common 1.117.1 → 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 +43 -0
- package/dist/teknisa-components-common.js +3802 -0
- package/dist/teknisa-components-common.min.js +3802 -0
- package/dist/types/components/index.d.ts +7 -0
- package/{types → dist/types}/components/tek-breadcrumb-header/breadcrumb-header.d.ts +12 -12
- package/{types → dist/types}/components/tek-breadcrumb-header/interfaces.d.ts +6 -6
- package/dist/types/components/tek-datasource/index.d.ts +3 -0
- package/{types → dist/types}/components/tek-datasource/interfaces.d.ts +16 -16
- package/{types/components/tek-datasource/memory-datasource.d.ts → dist/types/components/tek-datasource/tek-memory-datasource.d.ts} +93 -100
- package/{types/components/tek-datasource/rest-datasource.d.ts → dist/types/components/tek-datasource/tek-rest-datasource.d.ts} +95 -103
- 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/{types → dist/types}/components/tek-grid/filter-helper.d.ts +7 -7
- package/{types → dist/types}/components/tek-grid/grid-filter-button.d.ts +29 -31
- 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/{types → dist/types}/components/tek-grid/layout-options.d.ts +39 -31
- package/{types/components/tek-grid/grid-column.d.ts → dist/types/components/tek-grid/tek-grid-column.d.ts} +42 -45
- package/{types/components/tek-grid/grid-columns-button-controller.d.ts → dist/types/components/tek-grid/tek-grid-columns-button/tek-grid-columns-button-controller.d.ts} +8 -8
- package/{types/components/tek-grid/grid-columns-button.d.ts → dist/types/components/tek-grid/tek-grid-columns-button/tek-grid-columns-button.d.ts} +13 -12
- 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/{types/utils/grid-base → dist/types/components/tek-grid/tek-grid-toolbar-provider}/export-options/button-option.d.ts +17 -16
- package/{types/utils/grid-base → dist/types/components/tek-grid/tek-grid-toolbar-provider}/export-options/index.d.ts +3 -3
- package/dist/types/components/tek-grid/tek-grid-toolbar-provider/export-options/interfaces.d.ts +5 -0
- package/{types/utils/grid-base → dist/types/components/tek-grid/tek-grid-toolbar-provider}/export-options/multi-option.d.ts +12 -12
- 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/{types → dist/types}/components/tek-user-info/TekUserInfoController.d.ts +22 -21
- package/{types → dist/types}/components/tek-user-info/interfaces.d.ts +27 -28
- package/{types → dist/types}/components/tek-user-info/tek-user-info-list.d.ts +32 -31
- package/{types → dist/types}/components/tek-user-info/tek-user-info.d.ts +37 -38
- package/{types → dist/types}/error/delete-rows-error.d.ts +6 -6
- 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 +2 -0
- package/{types → dist/types}/utils/config/config.d.ts +7 -7
- 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/environments.json +14 -0
- package/package.json +26 -18
- package/src/components/index.ts +101 -0
- package/src/components/tek-breadcrumb-header/breadcrumb-header.ts +29 -0
- package/src/components/tek-breadcrumb-header/interfaces.ts +7 -0
- 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 +2 -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/__helpers__/component-event-helper.ts +1 -1
- package/tests/__helpers__/get-child-helper.ts +1 -1
- package/tests/__helpers__/mock-created-helper.ts +1 -1
- package/tests/unit/components/crud/crud-button.spec.ts +1 -1
- package/tests/unit/components/tek-datasource/memory-datasource.spec.ts +1 -11
- package/tests/unit/components/tek-datasource/rest-datasource.spec.ts +5 -7
- package/tests/unit/components/tek-drag-grid/tek-drag-grid.spec.ts +1 -1
- 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 +114 -239
- 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} +70 -30
- 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} +44 -2
- 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/tests/unit/components/tek-user-info/tek-user-info-list.spec.ts +1 -1
- package/tests/unit/components/tek-user-info/tek-user-info.spec.ts +10 -14
- package/tests/unit/components/tree-grid/tree-grid.spec.ts +4 -28
- package/tests/unit/utils/grid-base/export-options/multi-option.spec.ts +2 -2
- package/tests/unit/utils/grid-base/grid-controller.spec.ts +17 -152
- package/tsconfig.build.json +7 -0
- package/coverage/clover.xml +0 -2007
- package/coverage/coverage-final.json +0 -48
- package/coverage/lcov-report/base.css +0 -224
- package/coverage/lcov-report/block-navigation.js +0 -87
- package/coverage/lcov-report/favicon.png +0 -0
- package/coverage/lcov-report/index.html +0 -431
- package/coverage/lcov-report/prettify.css +0 -1
- package/coverage/lcov-report/prettify.js +0 -2
- package/coverage/lcov-report/sort-arrow-sprite.png +0 -0
- package/coverage/lcov-report/sorter.js +0 -210
- package/coverage/lcov-report/tests/__helpers__/component-event-helper.ts.html +0 -100
- package/coverage/lcov-report/tests/__helpers__/flush-promises-helper.ts.html +0 -94
- package/coverage/lcov-report/tests/__helpers__/get-child-helper.ts.html +0 -166
- package/coverage/lcov-report/tests/__helpers__/index.html +0 -176
- package/coverage/lcov-report/tests/__helpers__/index.ts.html +0 -94
- package/coverage/lcov-report/tests/__helpers__/mock-created-helper.ts.html +0 -121
- package/coverage/lcov.info +0 -3885
- package/dist/tek-components-common.esm.js +0 -4833
- package/dist/tek-components-common.umd.js +0 -4870
- package/tests/unit/components/tek-grid/grid.spec.ts +0 -3377
- package/tests/unit/utils/grid-base/delete-rows-error.spec.ts +0 -24
- package/types/components/crud/crud-add-button.d.ts +0 -38
- package/types/components/crud/crud-button.d.ts +0 -27
- package/types/components/crud/crud-cancel-button.d.ts +0 -28
- package/types/components/crud/crud-delete-button.d.ts +0 -42
- package/types/components/crud/crud-form.d.ts +0 -46
- package/types/components/crud/crud-save-button.d.ts +0 -24
- package/types/components/crud/interfaces.d.ts +0 -15
- package/types/components/index.d.ts +0 -41
- package/types/components/tek-card-title/card-title.d.ts +0 -14
- package/types/components/tek-card-title/interfaces.d.ts +0 -9
- package/types/components/tek-drag-grid/interfaces.d.ts +0 -7
- package/types/components/tek-drag-grid/tek-drag-grid.d.ts +0 -36
- package/types/components/tek-grid/grid.d.ts +0 -267
- package/types/components/tek-grid/interfaces.d.ts +0 -203
- package/types/components/tek-image/image.d.ts +0 -55
- package/types/components/tek-image/interfaces.d.ts +0 -12
- package/types/components/tek-iterable-carousel/interfaces.d.ts +0 -5
- package/types/components/tek-iterable-carousel/iterable-carousel.d.ts +0 -13
- package/types/components/tek-iterable-component-render/interfaces.d.ts +0 -3
- package/types/components/tek-iterable-component-render/iterable-component-render.d.ts +0 -10
- package/types/components/tek-loading/interfaces.d.ts +0 -6
- package/types/components/tek-loading/loading.d.ts +0 -24
- package/types/components/tek-notifications/interfaces.d.ts +0 -22
- package/types/components/tek-notifications/notifications.d.ts +0 -35
- package/types/components/tek-product-card/interfaces.d.ts +0 -19
- package/types/components/tek-product-card/product-card.d.ts +0 -66
- package/types/components/tek-tree-grid/interfaces.d.ts +0 -30
- package/types/components/tek-tree-grid/tree-grid.d.ts +0 -102
- package/types/error/incomplete-groups-error.d.ts +0 -8
- package/types/index.d.ts +0 -2
- package/types/utils/extract-properties.d.ts +0 -7
- package/types/utils/grid-base/export-options/interfaces.d.ts +0 -5
- package/types/utils/grid-base/grid-base.d.ts +0 -59
- package/types/utils/grid-base/grid-controller.d.ts +0 -27
- package/types/utils/index.d.ts +0 -6
- package/types/utils/report-filter/report-filter.d.ts +0 -12
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
import { Button } from '@zeedhi/common';
|
|
2
|
+
import { TekGrid, ButtonOption } from '../../../../src';
|
|
3
|
+
import { Loader, SimpleControllerBuilder } from '@zeedhi/core';
|
|
4
|
+
|
|
5
|
+
describe('ButtonOption', () => {
|
|
6
|
+
beforeAll(() => {
|
|
7
|
+
Loader.setBuilder(new SimpleControllerBuilder());
|
|
8
|
+
});
|
|
9
|
+
|
|
10
|
+
describe('buildComponent()', () => {
|
|
11
|
+
it('when called, should build a simple button component', () => {
|
|
12
|
+
const grid = new TekGrid({ name: 'Grid', component: 'TekGrid' });
|
|
13
|
+
const config = {
|
|
14
|
+
type: 'pdf',
|
|
15
|
+
label: 'Exportar PDF',
|
|
16
|
+
};
|
|
17
|
+
const option = new ButtonOption(config);
|
|
18
|
+
|
|
19
|
+
const component = option.buildComponent(grid);
|
|
20
|
+
|
|
21
|
+
expect(component).toEqual(expect.objectContaining({
|
|
22
|
+
label: config.label,
|
|
23
|
+
name: 'Grid_export_pdf_portrait',
|
|
24
|
+
component: 'ZdButton',
|
|
25
|
+
iconName: undefined,
|
|
26
|
+
flat: true,
|
|
27
|
+
}));
|
|
28
|
+
});
|
|
29
|
+
|
|
30
|
+
it('the generated button component should call grid.getReport on click', () => {
|
|
31
|
+
const grid = new TekGrid({ name: 'Grid', component: 'TekGrid' });
|
|
32
|
+
const spy = jest.fn();
|
|
33
|
+
grid.getReport = spy;
|
|
34
|
+
const config = {
|
|
35
|
+
type: 'pdf',
|
|
36
|
+
label: 'Exportar PDF',
|
|
37
|
+
portrait: false,
|
|
38
|
+
};
|
|
39
|
+
const option = new ButtonOption(config);
|
|
40
|
+
|
|
41
|
+
const component = option.buildComponent(grid);
|
|
42
|
+
|
|
43
|
+
const instance = new Button(component);
|
|
44
|
+
instance.click();
|
|
45
|
+
|
|
46
|
+
expect(spy).toHaveBeenCalledTimes(1);
|
|
47
|
+
});
|
|
48
|
+
});
|
|
49
|
+
});
|
|
@@ -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
|
+
});
|