@zeedhi/teknisa-components-common 1.107.2 → 1.108.0
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/LICENSE +21 -21
- package/README.md +7 -7
- package/coverage/clover.xml +772 -692
- package/coverage/coverage-final.json +47 -47
- package/coverage/lcov-report/index.html +15 -15
- package/coverage/lcov-report/tests/__helpers__/component-event-helper.ts.html +2 -2
- package/coverage/lcov-report/tests/__helpers__/flush-promises-helper.ts.html +2 -2
- package/coverage/lcov-report/tests/__helpers__/get-child-helper.ts.html +7 -7
- package/coverage/lcov-report/tests/__helpers__/index.html +1 -1
- package/coverage/lcov-report/tests/__helpers__/index.ts.html +1 -1
- package/coverage/lcov-report/tests/__helpers__/mock-created-helper.ts.html +1 -1
- package/coverage/lcov.info +1459 -1275
- package/dist/tek-components-common.esm.js +375 -252
- package/dist/tek-components-common.umd.js +375 -252
- package/jest.config.js +1 -1
- package/package.json +2 -2
- package/tests/__helpers__/component-event-helper.ts +5 -5
- package/tests/__helpers__/flush-promises-helper.ts +3 -3
- package/tests/__helpers__/get-child-helper.ts +27 -27
- package/tests/__helpers__/index.ts +3 -3
- package/tests/__helpers__/mock-created-helper.ts +12 -12
- package/tests/__mocks__/@zeedhi/core/i18n.js +74 -74
- package/tests/__mocks__/@zeedhi/core.js +4 -4
- package/tests/unit/components/crud/crud-add-button.spec.ts +56 -56
- package/tests/unit/components/crud/crud-button.spec.ts +94 -94
- package/tests/unit/components/crud/crud-cancel-button.spec.ts +91 -91
- package/tests/unit/components/crud/crud-delete-button.spec.ts +122 -122
- package/tests/unit/components/crud/crud-form.spec.ts +165 -165
- package/tests/unit/components/crud/crud-save-button.spec.ts +118 -118
- package/tests/unit/components/tek-breadcrumb-header/tek-breadcrumb-header.spec.ts +42 -42
- package/tests/unit/components/tek-card-title/CardTitle.spec.ts +34 -34
- package/tests/unit/components/tek-datasource/memory-datasource.spec.ts +470 -470
- package/tests/unit/components/tek-datasource/rest-datasource.spec.ts +364 -364
- package/tests/unit/components/tek-drag-grid/tek-drag-grid.spec.ts +112 -112
- package/tests/unit/components/tek-grid/filter-helper.spec.ts +148 -148
- package/tests/unit/components/tek-grid/grid-column.spec.ts +270 -270
- package/tests/unit/components/tek-grid/grid-columns-button.spec.ts +195 -195
- package/tests/unit/components/tek-grid/grid-filter-button.spec.ts +967 -967
- package/tests/unit/components/tek-grid/grid.spec.ts +3340 -3116
- package/tests/unit/components/tek-grid/layout_options.spec.ts +980 -980
- package/tests/unit/components/tek-image/Image.spec.ts +67 -67
- package/tests/unit/components/tek-iterable-carousel/iterable-carousel.spec.ts +37 -37
- package/tests/unit/components/tek-iterable-component-render/iterable-component-render.spec.ts +200 -200
- package/tests/unit/components/tek-loading/Loading.spec.ts +30 -30
- package/tests/unit/components/tek-notifications/notifications.spec.ts +201 -201
- package/tests/unit/components/tek-product-card/product-card.spec.ts +61 -61
- package/tests/unit/components/tek-user-info/TekUserInfoContoller.spec.ts +220 -220
- package/tests/unit/components/tek-user-info/tek-user-info-list.spec.ts +86 -86
- package/tests/unit/components/tek-user-info/tek-user-info.spec.ts +430 -430
- package/tests/unit/components/tree-grid/tree-grid.spec.ts +776 -776
- package/tests/unit/utils/grid-base/delete-rows-error.spec.ts +24 -0
- package/tests/unit/utils/grid-base/export-options/button-option.spec.ts +44 -44
- package/tests/unit/utils/grid-base/export-options/multi-option.spec.ts +135 -135
- package/tests/unit/utils/grid-base/grid-controller.spec.ts +267 -174
- package/tests/unit/utils/report-filter/report-filter.spec.ts +66 -66
- package/tsconfig.eslint.json +8 -8
- package/types/components/tek-datasource/memory-datasource.d.ts +2 -4
- package/types/components/tek-datasource/rest-datasource.d.ts +6 -3
- package/types/components/tek-grid/grid.d.ts +50 -6
- package/types/components/tek-grid/interfaces.d.ts +5 -3
- package/types/components/tek-tree-grid/tree-grid.d.ts +5 -1
- package/types/utils/grid-base/grid-base.d.ts +12 -229
- package/types/utils/grid-base/grid-controller.d.ts +1 -3
- package/types/components/tek-ag-grid/default-icons.d.ts +0 -53
- package/types/components/tek-ag-grid/interfaces.d.ts +0 -9
- package/types/components/tek-ag-grid/tek-ag-grid.d.ts +0 -35
- package/types/components/tek-datasource/datasource.d.ts +0 -94
- package/types/components/tek-grid/default-icons.d.ts +0 -53
- package/types/components/tek-grid/filter-dynamic-values.d.ts +0 -9
- package/types/components/tek-grid/grid-controller.d.ts +0 -19
- package/types/components/tek-grid/grid_column.d.ts +0 -14
- package/types/components/tek-grid/grid_controller.d.ts +0 -15
- package/types/components/tek-grid/tek-grid.d.ts +0 -35
- package/types/components/tek-login/interfaces.d.ts +0 -3
- package/types/components/tek-login/login-children.d.ts +0 -3
- package/types/components/tek-login/login.d.ts +0 -58
- package/types/components/tek-login/login_children.d.ts +0 -3
|
@@ -1,112 +1,112 @@
|
|
|
1
|
-
import { IDictionary } from '@zeedhi/core';
|
|
2
|
-
import { TekDragGrid } from '../../../../src/components/tek-drag-grid/tek-drag-grid';
|
|
3
|
-
|
|
4
|
-
const dragFromXToY = (from: number, to: number, data: IDictionary[]) => {
|
|
5
|
-
const row = data[from];
|
|
6
|
-
data.splice(from, 1);
|
|
7
|
-
data.splice(to, 0, row);
|
|
8
|
-
const event = {
|
|
9
|
-
oldIndex: from,
|
|
10
|
-
newIndex: to,
|
|
11
|
-
} as any;
|
|
12
|
-
const element = {} as HTMLElement;
|
|
13
|
-
|
|
14
|
-
return { event, element, row };
|
|
15
|
-
};
|
|
16
|
-
|
|
17
|
-
describe('DragGrid', () => {
|
|
18
|
-
describe('constructor()', () => {
|
|
19
|
-
it('create instance', () => {
|
|
20
|
-
const instance = new TekDragGrid({
|
|
21
|
-
name: 'DragGrid',
|
|
22
|
-
component: 'DragGrid',
|
|
23
|
-
orderColumnName: 'order',
|
|
24
|
-
});
|
|
25
|
-
|
|
26
|
-
expect(instance.orderColumnName).toBe('order');
|
|
27
|
-
expect(instance.orderMode).toBe('asc');
|
|
28
|
-
|
|
29
|
-
instance.orderColumnName = 'newOrder';
|
|
30
|
-
instance.orderMode = 'desc';
|
|
31
|
-
|
|
32
|
-
expect(instance.orderColumnName).toBe('newOrder');
|
|
33
|
-
expect(instance.orderMode).toBe('desc');
|
|
34
|
-
});
|
|
35
|
-
});
|
|
36
|
-
|
|
37
|
-
describe('onDragMove', () => {
|
|
38
|
-
it('should call onDragMove event', () => {
|
|
39
|
-
const onDragMove = jest.fn();
|
|
40
|
-
|
|
41
|
-
const instance = new TekDragGrid({
|
|
42
|
-
name: 'DragGrid',
|
|
43
|
-
component: 'DragGrid',
|
|
44
|
-
orderColumnName: 'order',
|
|
45
|
-
events: {
|
|
46
|
-
onDragMove,
|
|
47
|
-
},
|
|
48
|
-
});
|
|
49
|
-
|
|
50
|
-
const event = {} as Event;
|
|
51
|
-
const row = {};
|
|
52
|
-
const element = {} as HTMLElement;
|
|
53
|
-
|
|
54
|
-
instance.onDragMove(event, row, element);
|
|
55
|
-
|
|
56
|
-
expect(onDragMove).toHaveBeenCalled();
|
|
57
|
-
});
|
|
58
|
-
});
|
|
59
|
-
|
|
60
|
-
describe('onDragStart', () => {
|
|
61
|
-
it('should call onDragStart event', () => {
|
|
62
|
-
const onDragStart = jest.fn();
|
|
63
|
-
|
|
64
|
-
const instance = new TekDragGrid({
|
|
65
|
-
name: 'DragGrid',
|
|
66
|
-
component: 'DragGrid',
|
|
67
|
-
orderColumnName: 'order',
|
|
68
|
-
events: {
|
|
69
|
-
onDragStart,
|
|
70
|
-
},
|
|
71
|
-
});
|
|
72
|
-
|
|
73
|
-
const event = {} as Event;
|
|
74
|
-
const row = {};
|
|
75
|
-
const element = {} as HTMLElement;
|
|
76
|
-
|
|
77
|
-
instance.onDragStart(event, row, element);
|
|
78
|
-
|
|
79
|
-
expect(onDragStart).toHaveBeenCalled();
|
|
80
|
-
});
|
|
81
|
-
});
|
|
82
|
-
|
|
83
|
-
describe('onDragEnd()', () => {
|
|
84
|
-
it('when called, should change order columns of the rows', () => {
|
|
85
|
-
const instance = new TekDragGrid({
|
|
86
|
-
name: 'DragGrid',
|
|
87
|
-
component: 'DragGrid',
|
|
88
|
-
orderColumnName: 'order',
|
|
89
|
-
datasource: {
|
|
90
|
-
uniqueKey: 'id',
|
|
91
|
-
data: [
|
|
92
|
-
{ id: 1, name: 'a', order: 0 },
|
|
93
|
-
{ id: 2, name: 'b', order: 1 },
|
|
94
|
-
{ id: 3, name: 'c', order: 2 },
|
|
95
|
-
{ id: 4, name: 'd', order: 3 },
|
|
96
|
-
],
|
|
97
|
-
},
|
|
98
|
-
});
|
|
99
|
-
|
|
100
|
-
const { event, row, element } = dragFromXToY(0, 1, instance.datasource.data);
|
|
101
|
-
instance.onDragEnd(event, row, element);
|
|
102
|
-
|
|
103
|
-
const editedrows = instance.getEditedRows();
|
|
104
|
-
expect(editedrows).toEqual(
|
|
105
|
-
expect.arrayContaining([
|
|
106
|
-
{ id: 1, name: 'a', order: 1 },
|
|
107
|
-
{ id: 2, name: 'b', order: 0 },
|
|
108
|
-
]),
|
|
109
|
-
);
|
|
110
|
-
});
|
|
111
|
-
});
|
|
112
|
-
});
|
|
1
|
+
import { IDictionary } from '@zeedhi/core';
|
|
2
|
+
import { TekDragGrid } from '../../../../src/components/tek-drag-grid/tek-drag-grid';
|
|
3
|
+
|
|
4
|
+
const dragFromXToY = (from: number, to: number, data: IDictionary[]) => {
|
|
5
|
+
const row = data[from];
|
|
6
|
+
data.splice(from, 1);
|
|
7
|
+
data.splice(to, 0, row);
|
|
8
|
+
const event = {
|
|
9
|
+
oldIndex: from,
|
|
10
|
+
newIndex: to,
|
|
11
|
+
} as any;
|
|
12
|
+
const element = {} as HTMLElement;
|
|
13
|
+
|
|
14
|
+
return { event, element, row };
|
|
15
|
+
};
|
|
16
|
+
|
|
17
|
+
describe('DragGrid', () => {
|
|
18
|
+
describe('constructor()', () => {
|
|
19
|
+
it('create instance', () => {
|
|
20
|
+
const instance = new TekDragGrid({
|
|
21
|
+
name: 'DragGrid',
|
|
22
|
+
component: 'DragGrid',
|
|
23
|
+
orderColumnName: 'order',
|
|
24
|
+
});
|
|
25
|
+
|
|
26
|
+
expect(instance.orderColumnName).toBe('order');
|
|
27
|
+
expect(instance.orderMode).toBe('asc');
|
|
28
|
+
|
|
29
|
+
instance.orderColumnName = 'newOrder';
|
|
30
|
+
instance.orderMode = 'desc';
|
|
31
|
+
|
|
32
|
+
expect(instance.orderColumnName).toBe('newOrder');
|
|
33
|
+
expect(instance.orderMode).toBe('desc');
|
|
34
|
+
});
|
|
35
|
+
});
|
|
36
|
+
|
|
37
|
+
describe('onDragMove', () => {
|
|
38
|
+
it('should call onDragMove event', () => {
|
|
39
|
+
const onDragMove = jest.fn();
|
|
40
|
+
|
|
41
|
+
const instance = new TekDragGrid({
|
|
42
|
+
name: 'DragGrid',
|
|
43
|
+
component: 'DragGrid',
|
|
44
|
+
orderColumnName: 'order',
|
|
45
|
+
events: {
|
|
46
|
+
onDragMove,
|
|
47
|
+
},
|
|
48
|
+
});
|
|
49
|
+
|
|
50
|
+
const event = {} as Event;
|
|
51
|
+
const row = {};
|
|
52
|
+
const element = {} as HTMLElement;
|
|
53
|
+
|
|
54
|
+
instance.onDragMove(event, row, element);
|
|
55
|
+
|
|
56
|
+
expect(onDragMove).toHaveBeenCalled();
|
|
57
|
+
});
|
|
58
|
+
});
|
|
59
|
+
|
|
60
|
+
describe('onDragStart', () => {
|
|
61
|
+
it('should call onDragStart event', () => {
|
|
62
|
+
const onDragStart = jest.fn();
|
|
63
|
+
|
|
64
|
+
const instance = new TekDragGrid({
|
|
65
|
+
name: 'DragGrid',
|
|
66
|
+
component: 'DragGrid',
|
|
67
|
+
orderColumnName: 'order',
|
|
68
|
+
events: {
|
|
69
|
+
onDragStart,
|
|
70
|
+
},
|
|
71
|
+
});
|
|
72
|
+
|
|
73
|
+
const event = {} as Event;
|
|
74
|
+
const row = {};
|
|
75
|
+
const element = {} as HTMLElement;
|
|
76
|
+
|
|
77
|
+
instance.onDragStart(event, row, element);
|
|
78
|
+
|
|
79
|
+
expect(onDragStart).toHaveBeenCalled();
|
|
80
|
+
});
|
|
81
|
+
});
|
|
82
|
+
|
|
83
|
+
describe('onDragEnd()', () => {
|
|
84
|
+
it('when called, should change order columns of the rows', () => {
|
|
85
|
+
const instance = new TekDragGrid({
|
|
86
|
+
name: 'DragGrid',
|
|
87
|
+
component: 'DragGrid',
|
|
88
|
+
orderColumnName: 'order',
|
|
89
|
+
datasource: {
|
|
90
|
+
uniqueKey: 'id',
|
|
91
|
+
data: [
|
|
92
|
+
{ id: 1, name: 'a', order: 0 },
|
|
93
|
+
{ id: 2, name: 'b', order: 1 },
|
|
94
|
+
{ id: 3, name: 'c', order: 2 },
|
|
95
|
+
{ id: 4, name: 'd', order: 3 },
|
|
96
|
+
],
|
|
97
|
+
},
|
|
98
|
+
});
|
|
99
|
+
|
|
100
|
+
const { event, row, element } = dragFromXToY(0, 1, instance.datasource.data);
|
|
101
|
+
instance.onDragEnd(event, row, element);
|
|
102
|
+
|
|
103
|
+
const editedrows = instance.getEditedRows();
|
|
104
|
+
expect(editedrows).toEqual(
|
|
105
|
+
expect.arrayContaining([
|
|
106
|
+
{ id: 1, name: 'a', order: 1 },
|
|
107
|
+
{ id: 2, name: 'b', order: 0 },
|
|
108
|
+
]),
|
|
109
|
+
);
|
|
110
|
+
});
|
|
111
|
+
});
|
|
112
|
+
});
|
|
@@ -1,148 +1,148 @@
|
|
|
1
|
-
import { Config, DateHelper, dayjs } from '@zeedhi/core';
|
|
2
|
-
import { TekFilterHelper, TekGrid } from '../../../../src';
|
|
3
|
-
|
|
4
|
-
describe('TekFilterHelper', () => {
|
|
5
|
-
describe('getLabel', () => {
|
|
6
|
-
it('should return helper label', () => {
|
|
7
|
-
const dateHelperSpy = jest.spyOn(DateHelper, 'getLabel').mockImplementation((name: string) => name);
|
|
8
|
-
|
|
9
|
-
expect(TekFilterHelper.getLabel('TODAY')).toBe('TODAY');
|
|
10
|
-
dateHelperSpy.mockClear();
|
|
11
|
-
});
|
|
12
|
-
});
|
|
13
|
-
|
|
14
|
-
describe('getValue', () => {
|
|
15
|
-
it('should return helper value', () => {
|
|
16
|
-
const grid = new TekGrid({
|
|
17
|
-
name: 'grid',
|
|
18
|
-
component: 'TekGrid',
|
|
19
|
-
columns: [
|
|
20
|
-
{
|
|
21
|
-
name: 'date',
|
|
22
|
-
componentProps: {
|
|
23
|
-
name: 'date-comp',
|
|
24
|
-
component: 'ZdDate',
|
|
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);
|
|
75
|
-
});
|
|
76
|
-
});
|
|
77
|
-
|
|
78
|
-
describe('register', () => {
|
|
79
|
-
it('should register new functions', () => {
|
|
80
|
-
const grid = new TekGrid({
|
|
81
|
-
name: 'grid',
|
|
82
|
-
component: 'TekGrid',
|
|
83
|
-
columns: [
|
|
84
|
-
{
|
|
85
|
-
name: 'date',
|
|
86
|
-
componentProps: {
|
|
87
|
-
name: 'date-comp',
|
|
88
|
-
component: 'ZdDate',
|
|
89
|
-
dateFormat: 'YYYY-MM-DD',
|
|
90
|
-
},
|
|
91
|
-
},
|
|
92
|
-
],
|
|
93
|
-
});
|
|
94
|
-
|
|
95
|
-
TekFilterHelper.register('NEXT_FIFTH_OF_THE_MONTH', 'Next fifth day of the month', () => {
|
|
96
|
-
const today = dayjs();
|
|
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);
|
|
121
|
-
});
|
|
122
|
-
});
|
|
123
|
-
|
|
124
|
-
describe('unregister', () => {
|
|
125
|
-
it('should unregister new functions', () => {
|
|
126
|
-
const grid = new TekGrid({
|
|
127
|
-
name: 'grid',
|
|
128
|
-
component: 'TekGrid',
|
|
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('');
|
|
146
|
-
});
|
|
147
|
-
});
|
|
148
|
-
});
|
|
1
|
+
import { Config, DateHelper, dayjs } from '@zeedhi/core';
|
|
2
|
+
import { TekFilterHelper, TekGrid } from '../../../../src';
|
|
3
|
+
|
|
4
|
+
describe('TekFilterHelper', () => {
|
|
5
|
+
describe('getLabel', () => {
|
|
6
|
+
it('should return helper label', () => {
|
|
7
|
+
const dateHelperSpy = jest.spyOn(DateHelper, 'getLabel').mockImplementation((name: string) => name);
|
|
8
|
+
|
|
9
|
+
expect(TekFilterHelper.getLabel('TODAY')).toBe('TODAY');
|
|
10
|
+
dateHelperSpy.mockClear();
|
|
11
|
+
});
|
|
12
|
+
});
|
|
13
|
+
|
|
14
|
+
describe('getValue', () => {
|
|
15
|
+
it('should return helper value', () => {
|
|
16
|
+
const grid = new TekGrid({
|
|
17
|
+
name: 'grid',
|
|
18
|
+
component: 'TekGrid',
|
|
19
|
+
columns: [
|
|
20
|
+
{
|
|
21
|
+
name: 'date',
|
|
22
|
+
componentProps: {
|
|
23
|
+
name: 'date-comp',
|
|
24
|
+
component: 'ZdDate',
|
|
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);
|
|
75
|
+
});
|
|
76
|
+
});
|
|
77
|
+
|
|
78
|
+
describe('register', () => {
|
|
79
|
+
it('should register new functions', () => {
|
|
80
|
+
const grid = new TekGrid({
|
|
81
|
+
name: 'grid',
|
|
82
|
+
component: 'TekGrid',
|
|
83
|
+
columns: [
|
|
84
|
+
{
|
|
85
|
+
name: 'date',
|
|
86
|
+
componentProps: {
|
|
87
|
+
name: 'date-comp',
|
|
88
|
+
component: 'ZdDate',
|
|
89
|
+
dateFormat: 'YYYY-MM-DD',
|
|
90
|
+
},
|
|
91
|
+
},
|
|
92
|
+
],
|
|
93
|
+
});
|
|
94
|
+
|
|
95
|
+
TekFilterHelper.register('NEXT_FIFTH_OF_THE_MONTH', 'Next fifth day of the month', () => {
|
|
96
|
+
const today = dayjs();
|
|
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);
|
|
121
|
+
});
|
|
122
|
+
});
|
|
123
|
+
|
|
124
|
+
describe('unregister', () => {
|
|
125
|
+
it('should unregister new functions', () => {
|
|
126
|
+
const grid = new TekGrid({
|
|
127
|
+
name: 'grid',
|
|
128
|
+
component: 'TekGrid',
|
|
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('');
|
|
146
|
+
});
|
|
147
|
+
});
|
|
148
|
+
});
|