@zeedhi/teknisa-components-common 3.0.4 → 3.1.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.
Files changed (79) hide show
  1. package/coverage/clover.xml +2 -2
  2. package/coverage/lcov-report/index.html +1 -1
  3. package/coverage/lcov-report/tests/__helpers__/component-event-helper.ts.html +100 -0
  4. package/coverage/lcov-report/tests/__helpers__/create-component.ts.html +109 -0
  5. package/coverage/lcov-report/tests/__helpers__/find-component.ts.html +139 -0
  6. package/coverage/lcov-report/tests/__helpers__/flush-promises-helper.ts.html +94 -0
  7. package/coverage/lcov-report/tests/__helpers__/get-child-helper.ts.html +166 -0
  8. package/coverage/lcov-report/tests/__helpers__/index.html +221 -0
  9. package/coverage/lcov-report/tests/__helpers__/index.ts.html +106 -0
  10. package/coverage/lcov-report/tests/__helpers__/mock-created-helper.ts.html +121 -0
  11. package/coverage/lcov-report/tests/__helpers__/spy-on-all-methods.ts.html +223 -0
  12. package/dist/teknisa-components-common.js +72 -66
  13. package/dist/teknisa-components-common.min.js +72 -66
  14. package/dist/types/components/index.d.ts +2 -0
  15. package/dist/types/components/tek-datasource/tek-memory-datasource.d.ts +16 -16
  16. package/dist/types/components/tek-datasource/tek-rest-datasource.d.ts +18 -20
  17. package/dist/types/components/tek-grid/grouped-data-navigator.d.ts +12 -0
  18. package/dist/types/components/tek-grid/index.d.ts +1 -1
  19. package/dist/types/components/tek-grid/tek-grid.d.ts +2 -1
  20. package/dist/types/components/tek-loading/interfaces.d.ts +6 -0
  21. package/dist/types/components/tek-loading/loading.d.ts +16 -0
  22. package/environments.json +12 -0
  23. package/jest.config.cjs +23 -0
  24. package/package.json +5 -3
  25. package/src/components/index.ts +2 -2
  26. package/src/components/tek-datasource/tek-memory-datasource.ts +2 -2
  27. package/src/components/tek-datasource/tek-rest-datasource.ts +2 -2
  28. package/src/components/tek-grid/grid-filter-button.ts +5 -3
  29. package/src/components/tek-grid/grouped-data-navigator.ts +66 -0
  30. package/src/components/tek-grid/index.ts +1 -1
  31. package/src/components/tek-grid/tek-grid.ts +19 -15
  32. package/src/components/tek-loading/interfaces.ts +7 -0
  33. package/src/components/tek-loading/loading.ts +27 -0
  34. package/tests/__helpers__/create-component.ts +8 -0
  35. package/tests/__helpers__/find-component.ts +18 -0
  36. package/tests/__helpers__/index.ts +4 -0
  37. package/tests/__helpers__/spy-on-all-methods.ts +46 -0
  38. package/tests/unit/components/tek-breadcrumb-header/tek-breadcrumb-header.spec.ts +2 -1
  39. package/tests/unit/components/tek-datasource/memory-datasource.spec.ts +4 -1
  40. package/tests/unit/components/tek-datasource/rest-datasource.spec.ts +1 -1
  41. package/tests/unit/components/tek-grid/filter-helper.spec.ts +8 -4
  42. package/tests/unit/components/tek-grid/grid-filter-button.spec.ts +1 -1
  43. package/tests/unit/components/tek-grid/grouped-data-manager.spec.ts +1 -1
  44. package/tests/unit/components/tek-grid/grouped-data-navigator.spec.ts +143 -0
  45. package/tests/unit/components/tek-grid/layout-options.spec.ts +1 -1
  46. package/tests/unit/components/tek-grid/tek-grid-column.spec.ts +23 -17
  47. package/tests/unit/components/tek-grid/tek-grid-columns-button.spec.ts +2 -1
  48. package/tests/unit/components/tek-grid/tek-grid.spec.ts +14 -12
  49. package/tests/unit/components/tek-grid/tek-memory-datasource.spec.ts +1 -1
  50. package/tests/unit/components/tek-grid/tek-rest-datasource.spec.ts +1 -1
  51. package/tests/unit/components/tek-loading/loading.spec.ts +29 -0
  52. package/tests/unit/components/tek-user-info/tek-user-info-list.spec.ts +12 -2
  53. package/tests/unit/components/tek-user-info/tek-user-info.spec.ts +18 -6
  54. package/tests/unit/utils/mock-console.ts +18 -0
  55. package/tests/unit/utils/setup.ts +5 -0
  56. package/dist/types/error/delete-rows-error.d.ts +0 -6
  57. package/jest.config.js +0 -1
  58. package/src/components/tek-grid/grouped-view-navigator.ts +0 -84
  59. package/tests/unit/components/crud/crud-add-button.spec.ts +0 -56
  60. package/tests/unit/components/crud/crud-button.spec.ts +0 -94
  61. package/tests/unit/components/crud/crud-cancel-button.spec.ts +0 -91
  62. package/tests/unit/components/crud/crud-delete-button.spec.ts +0 -122
  63. package/tests/unit/components/crud/crud-form.spec.ts +0 -165
  64. package/tests/unit/components/crud/crud-save-button.spec.ts +0 -118
  65. package/tests/unit/components/tek-card-title/CardTitle.spec.ts +0 -34
  66. package/tests/unit/components/tek-drag-grid/tek-drag-grid.spec.ts +0 -112
  67. package/tests/unit/components/tek-grid/grouped-view-navigator.spec.ts +0 -244
  68. package/tests/unit/components/tek-grid/multi-option.spec.ts +0 -139
  69. package/tests/unit/components/tek-image/Image.spec.ts +0 -67
  70. package/tests/unit/components/tek-iterable-carousel/iterable-carousel.spec.ts +0 -37
  71. package/tests/unit/components/tek-iterable-component-render/iterable-component-render.spec.ts +0 -200
  72. package/tests/unit/components/tek-loading/Loading.spec.ts +0 -30
  73. package/tests/unit/components/tek-notifications/notifications.spec.ts +0 -201
  74. package/tests/unit/components/tek-product-card/product-card.spec.ts +0 -61
  75. package/tests/unit/components/tree-grid/tree-grid.spec.ts +0 -776
  76. package/tests/unit/utils/grid-base/export-options/button-option.spec.ts +0 -44
  77. package/tests/unit/utils/grid-base/export-options/multi-option.spec.ts +0 -135
  78. package/tests/unit/utils/grid-base/grid-controller.spec.ts +0 -174
  79. package/tests/unit/utils/report-filter/report-filter.spec.ts +0 -66
@@ -1,244 +0,0 @@
1
- import { IEventParam } from '@zeedhi/core';
2
- import { GroupedViewNavigator, ViewNavigator } from '../../../../src';
3
- import { spyOnAllMethods } from '../../__helpers__';
4
-
5
- describe('GroupedViewNavigator', () => {
6
- let navigator: GroupedViewNavigator;
7
- let mockGrid: any;
8
-
9
- beforeEach(() => {
10
- mockGrid = {
11
- isGrouped: jest.fn(),
12
- cellSelection: false,
13
- getGroupedData: jest.fn(),
14
- datasource: { currentRow: {} } as any,
15
- getRowKey: jest.fn(),
16
- isItemVisible: jest.fn().mockReturnValue(true),
17
- setCurrentRow: jest.fn(),
18
- };
19
-
20
- navigator = new GroupedViewNavigator(mockGrid);
21
- });
22
-
23
- afterEach(() => {
24
- jest.restoreAllMocks();
25
- });
26
-
27
- describe('constructor', () => {
28
- it('should initialize with the provided grid', () => {
29
- expect(navigator).toBeInstanceOf(GroupedViewNavigator);
30
- // @ts-ignore - access protected property for testing
31
- expect(navigator.grid).toBe(mockGrid);
32
- });
33
- });
34
-
35
- describe('basic navigation methods', () => {
36
- it('should delegate to ViewNavigator', () => {
37
- const spyObj = spyOnAllMethods(ViewNavigator.prototype);
38
-
39
- const param = {} as IEventParam<any>;
40
- navigator.navigateLeft(param);
41
- expect(spyObj.navigateLeft).toHaveBeenCalledWith(param);
42
-
43
- navigator.navigateRight(param);
44
- expect(spyObj.navigateRight).toHaveBeenCalledWith(param);
45
-
46
- const fn = jest.fn();
47
- navigator.setViewNavigate(fn);
48
- expect(spyObj.setViewNavigate).toHaveBeenCalledWith(fn);
49
- });
50
- });
51
-
52
- describe('getRowIndex', () => {
53
- const groupedData = [
54
- { group: true, groupValue: 'Group1' },
55
- { id: 1, name: 'Item1' },
56
- { id: 2, name: 'Item2' },
57
- { group: true, groupValue: 'Group2' },
58
- { id: 3, name: 'Item3' },
59
- ];
60
-
61
- it('should return provided index if given', () => {
62
- // @ts-ignore - access private method for testing
63
- const result = navigator.getRowIndex(groupedData, 2);
64
- expect(result).toBe(2);
65
- });
66
-
67
- it('should find index by groupValue when currentRow is a group', () => {
68
- mockGrid.datasource.currentRow = { group: true, groupValue: 'Group2' };
69
- // @ts-ignore - access private method for testing
70
- const result = navigator.getRowIndex(groupedData);
71
- expect(result).toBe(3);
72
- });
73
-
74
- it('should find index by rowKey when currentRow is not a group', () => {
75
- mockGrid.datasource.currentRow = { id: 2, name: 'Item2' };
76
- mockGrid.getRowKey.mockImplementation((row: any) => row.id);
77
- // @ts-ignore - access private method for testing
78
- const result = navigator.getRowIndex(groupedData);
79
- expect(result).toBe(2);
80
- expect(mockGrid.getRowKey).toHaveBeenCalledWith({ id: 2, name: 'Item2' });
81
- });
82
-
83
- it('should return -1 when row not found', () => {
84
- mockGrid.datasource.currentRow = { id: 99, name: 'NotFound' };
85
- mockGrid.getRowKey.mockImplementation((row: any) => row.id);
86
- // @ts-ignore - access private method for testing
87
- const result = navigator.getRowIndex(groupedData);
88
- expect(result).toBe(-1);
89
- });
90
- });
91
-
92
- describe('navigateUp', () => {
93
- const groupedData = [
94
- { group: true, groupValue: 'Group1' },
95
- { id: 1, name: 'Item1' },
96
- { id: 2, name: 'Item2' },
97
- { group: true, groupValue: 'Group2' },
98
- { id: 3, name: 'Item3' },
99
- { groupFooter: true, groupValue: 'Group2' },
100
- ];
101
-
102
- beforeEach(() => {
103
- mockGrid.getGroupedData.mockReturnValue(groupedData);
104
- });
105
-
106
- it('should delegate to ViewNavigator when not grouped or cellSelection is true', () => {
107
- const spyObj = spyOnAllMethods(ViewNavigator.prototype);
108
-
109
- mockGrid.isGrouped.mockReturnValue(false);
110
- navigator.navigateUp();
111
- expect(spyObj.navigateUp).toHaveBeenCalled();
112
-
113
- mockGrid.isGrouped.mockReturnValue(true);
114
- mockGrid.cellSelection = true;
115
- navigator.navigateUp();
116
- expect(spyObj.navigateUp).toHaveBeenCalledTimes(2);
117
- });
118
-
119
- it('should do nothing when groupedData is empty', () => {
120
- mockGrid.isGrouped.mockReturnValue(true);
121
- mockGrid.getGroupedData.mockReturnValue([]);
122
- navigator.navigateUp();
123
- expect(mockGrid.setCurrentRow).not.toHaveBeenCalled();
124
- });
125
-
126
- it('should navigate to previous visible row', () => {
127
- mockGrid.isGrouped.mockReturnValue(true);
128
- mockGrid.datasource.currentRow = groupedData[2]; // Item2
129
- mockGrid.getRowKey.mockImplementation((row: any) => row.id);
130
-
131
- navigator.navigateUp();
132
- expect(mockGrid.setCurrentRow).toHaveBeenCalledWith(groupedData[1]); // Item1
133
- });
134
-
135
- it('should skip group footers and invisible items', () => {
136
- mockGrid.isGrouped.mockReturnValue(true);
137
- mockGrid.datasource.currentRow = groupedData[4]; // Item3
138
- mockGrid.getRowKey.mockImplementation((row: any) => row.id);
139
- mockGrid.isItemVisible.mockImplementation((row: any) => !row.groupFooter);
140
-
141
- navigator.navigateUp();
142
- // Should skip groupFooter and land on Group2
143
- expect(mockGrid.setCurrentRow).toHaveBeenCalledWith(groupedData[3]);
144
- });
145
-
146
- it('should recursively find previous visible item', () => {
147
- mockGrid.isGrouped.mockReturnValue(true);
148
- mockGrid.datasource.currentRow = groupedData[4]; // Item3
149
- mockGrid.getRowKey.mockImplementation((row: any) => row.id);
150
- // Make Group2 invisible
151
- mockGrid.isItemVisible.mockImplementation((row: any) => row !== groupedData[3]);
152
-
153
- navigator.navigateUp();
154
- // Should skip invisible Group2 and land on Item2
155
- expect(mockGrid.setCurrentRow).toHaveBeenCalledWith(groupedData[2]);
156
- });
157
-
158
- it('should stop at beginning of list', () => {
159
- mockGrid.isGrouped.mockReturnValue(true);
160
- mockGrid.datasource.currentRow = groupedData[0]; // Group1
161
- mockGrid.getRowKey.mockImplementation((row: any) => row.groupValue);
162
-
163
- navigator.navigateUp();
164
- expect(mockGrid.setCurrentRow).not.toHaveBeenCalled();
165
- });
166
-
167
- it('should navigate to last row when currentRow is not defined', () => {
168
- mockGrid.isGrouped.mockReturnValue(true);
169
- mockGrid.datasource.currentRow = {};
170
- mockGrid.getRowKey.mockImplementation((row: any) => row.id);
171
-
172
- navigator.navigateUp();
173
- expect(mockGrid.setCurrentRow).toHaveBeenCalledWith(groupedData[4]);
174
- });
175
- });
176
-
177
- describe('navigateDown', () => {
178
- const groupedData = [
179
- { group: true, groupValue: 'Group1' },
180
- { id: 1, name: 'Item1' },
181
- { id: 2, name: 'Item2' },
182
- { group: true, groupValue: 'Group2' },
183
- { id: 3, name: 'Item3' }
184
- ];
185
-
186
- beforeEach(() => {
187
- mockGrid.getGroupedData.mockReturnValue(groupedData);
188
- });
189
-
190
- it('should delegate to ViewNavigator when not grouped or cellSelection is true', () => {
191
- const spyObj = spyOnAllMethods(ViewNavigator.prototype);
192
-
193
- mockGrid.isGrouped.mockReturnValue(false);
194
- navigator.navigateDown();
195
- expect(spyObj.navigateDown).toHaveBeenCalled();
196
-
197
- mockGrid.isGrouped.mockReturnValue(true);
198
- mockGrid.cellSelection = true;
199
- navigator.navigateDown();
200
- expect(spyObj.navigateDown).toHaveBeenCalledTimes(2);
201
- });
202
-
203
- it('should navigate to next visible row', () => {
204
- mockGrid.isGrouped.mockReturnValue(true);
205
- mockGrid.datasource.currentRow = groupedData[1]; // Item1
206
- mockGrid.getRowKey.mockImplementation((row: any) => row.id);
207
-
208
- navigator.navigateDown();
209
- expect(mockGrid.setCurrentRow).toHaveBeenCalledWith(groupedData[2]); // Item2
210
- });
211
-
212
- it('should skip group footers and invisible items', () => {
213
- mockGrid.isGrouped.mockReturnValue(true);
214
- mockGrid.datasource.currentRow = groupedData[3]; // Group2
215
- mockGrid.getRowKey.mockImplementation((row: any) => row.groupValue);
216
- mockGrid.isItemVisible.mockImplementation((row: any) => !row.groupFooter);
217
-
218
- navigator.navigateDown();
219
- // Should skip groupFooter and land on Item3
220
- expect(mockGrid.setCurrentRow).toHaveBeenCalledWith(groupedData[4]);
221
- });
222
-
223
- it('should recursively find next visible item', () => {
224
- mockGrid.isGrouped.mockReturnValue(true);
225
- mockGrid.datasource.currentRow = groupedData[1]; // Item1
226
- mockGrid.getRowKey.mockImplementation((row: any) => row.id);
227
- // Make Item2 invisible
228
- mockGrid.isItemVisible.mockImplementation((row: any) => row !== groupedData[2]);
229
-
230
- navigator.navigateDown();
231
- // Should skip invisible Item2 and land on Group2
232
- expect(mockGrid.setCurrentRow).toHaveBeenCalledWith(groupedData[3]);
233
- });
234
-
235
- it('should do nothing when at end of list', () => {
236
- mockGrid.isGrouped.mockReturnValue(true);
237
- mockGrid.datasource.currentRow = groupedData[4];
238
- mockGrid.getRowKey.mockImplementation((row: any) => row.id);
239
-
240
- navigator.navigateDown();
241
- expect(mockGrid.setCurrentRow).not.toHaveBeenCalled();
242
- });
243
- });
244
- });
@@ -1,139 +0,0 @@
1
- import { Button, IText, Text } from '@zeedhi/common';
2
- import { ITekGridExportConfig, TekGrid, MultiOption } from '../../../../src';
3
- import { Loader, SimpleControllerBuilder } from '@zeedhi/core';
4
-
5
- describe('MultiOption', () => {
6
- beforeAll(() => {
7
- Loader.setBuilder(new SimpleControllerBuilder());
8
- });
9
-
10
- describe('buildComponent()', () => {
11
- it('when called, should build a row with multiple buttons', () => {
12
- const grid = new TekGrid({ name: 'Grid', component: 'TekGrid' });
13
- const config: ITekGridExportConfig = {
14
- type: 'pdf',
15
- label: 'Exportar PDF',
16
- multiOption: [
17
- { label: 'portrait', iconName: 'icon-portrait' },
18
- { label: 'landscape', iconName: 'icon-landscape' },
19
- ],
20
- };
21
- const option = new MultiOption(config);
22
-
23
- const component = option.buildComponent(grid);
24
-
25
- expect(component).toEqual({
26
- name: 'Grid_export_pdf_row',
27
- component: 'ZdRow',
28
- cssClass: 'zd-display-flex zd-ma-0 zd-py-0 zd-gap-x-1 tek-grid-export-multioption-row',
29
- children: [
30
- expect.objectContaining({
31
- name: 'Grid_export_pdf_text',
32
- component: 'ZdText',
33
- text: 'Exportar PDF',
34
- cssClass: 'zd-display-flex zd-align-center zd-flex-grow-1 tek-grid-export-multioption-text',
35
- }),
36
- {
37
- name: 'Grid_export_pdf_tooltip_portrait',
38
- component: 'ZdTooltip',
39
- bottom: true,
40
- label: 'portrait',
41
- children: [
42
- expect.objectContaining({
43
- name: 'Grid_export_pdf_button_portrait',
44
- component: 'ZdButton',
45
- icon: true,
46
- iconName: 'icon-portrait',
47
- }),
48
- ],
49
- },
50
- expect.objectContaining({
51
- name: 'Grid_export_pdf_divider_portrait',
52
- component: 'ZdDivider',
53
- cssClass: 'zd-my-1',
54
- vertical: true,
55
- }),
56
- {
57
- name: 'Grid_export_pdf_tooltip_landscape',
58
- component: 'ZdTooltip',
59
- bottom: true,
60
- label: 'landscape',
61
- children: [
62
- expect.objectContaining({
63
- name: 'Grid_export_pdf_button_landscape',
64
- component: 'ZdButton',
65
- icon: true,
66
- iconName: 'icon-landscape',
67
- }),
68
- ],
69
- },
70
- ],
71
- });
72
- });
73
-
74
- it('the generated text component should call stopPropagation on click', () => {
75
- const grid = new TekGrid({ name: 'Grid', component: 'TekGrid' });
76
- const config: ITekGridExportConfig = {
77
- type: 'pdf',
78
- label: 'Exportar PDF',
79
- multiOption: [
80
- { label: 'portrait', iconName: 'icon-portrait' },
81
- { label: 'landscape', iconName: 'icon-landscape' },
82
- ],
83
- };
84
- const option = new MultiOption(config);
85
-
86
- const component = option.buildComponent(grid);
87
-
88
- const instance = new Text(component.children![0] as IText);
89
- const spy = jest.fn();
90
- const event = { stopPropagation: spy } as unknown as Event;
91
- instance.click(event);
92
-
93
- expect(spy).toHaveBeenCalled();
94
- });
95
-
96
- it('the generated text component should not throw if event is undefined', () => {
97
- const grid = new TekGrid({ name: 'Grid', component: 'TekGrid' });
98
- const config: ITekGridExportConfig = {
99
- type: 'pdf',
100
- label: 'Exportar PDF',
101
- multiOption: [
102
- { label: 'portrait', iconName: 'icon-portrait' },
103
- { label: 'landscape', iconName: 'icon-landscape' },
104
- ],
105
- };
106
- const option = new MultiOption(config);
107
-
108
- const component = option.buildComponent(grid);
109
-
110
- const instance = new Text(component.children![0] as IText);
111
-
112
- expect(() => instance.callEvent('click', { event: undefined })).not.toThrow();
113
- });
114
-
115
- it('the generated button components should call grid.getReport on click', () => {
116
- const grid = new TekGrid({ name: 'Grid', component: 'TekGrid' });
117
- const spy = jest.fn();
118
- grid.getReport = spy;
119
- const config: ITekGridExportConfig = {
120
- type: 'pdf',
121
- multiOption: [
122
- { label: 'portrait', iconName: 'icon-portrait' },
123
- { label: 'landscape', iconName: 'icon-landscape' },
124
- ],
125
- };
126
- const option = new MultiOption(config);
127
-
128
- const component = option.buildComponent(grid);
129
-
130
- const instance = new Button(component.children![1].children![0]);
131
- instance.click();
132
-
133
- const instance2 = new Button(component.children![3].children![0]);
134
- instance2.click();
135
-
136
- expect(spy).toHaveBeenCalledTimes(2);
137
- });
138
- });
139
- });
@@ -1,67 +0,0 @@
1
- import { Image } from '../../../../src';
2
-
3
- describe('Image', () => {
4
- describe('constructor()', () => {
5
- it('should create new Image with default values', () => {
6
- const instance = new Image({
7
- name: 'image',
8
- component: 'Image',
9
- });
10
- expect(instance.src).toBe('');
11
- expect(instance.to).toBe('');
12
- expect(instance.height).toBe('auto');
13
- expect(instance.minHeight).toBe('auto');
14
- expect(instance.maxHeight).toBe('none');
15
- expect(instance.fillHeight).toBeFalsy();
16
- expect(instance.width).toBe('auto');
17
- expect(instance.minWidth).toBe('auto');
18
- expect(instance.maxWidth).toBe('none');
19
- });
20
-
21
- it('should create new image replacing default values', () => {
22
- const instance = new Image({
23
- name: 'image',
24
- component: 'Image',
25
- src: '/img/zeedhi.svg',
26
- to: 'google.com.br',
27
- height: '400px',
28
- maxHeight: '500px',
29
- minHeight: '500px',
30
- width: '400px',
31
- maxWidth: '500px',
32
- minWidth: '500px',
33
- fillHeight: true,
34
- });
35
- expect(instance.src).toBe('/img/zeedhi.svg');
36
- expect(instance.to).toBe('google.com.br');
37
- expect(instance.height).toBe('400px');
38
- expect(instance.maxHeight).toBe('500px');
39
- expect(instance.minHeight).toBe('500px');
40
- expect(instance.width).toBe('400px');
41
- expect(instance.maxWidth).toBe('500px');
42
- expect(instance.minWidth).toBe('500px');
43
- expect(instance.fillHeight).toBeTruthy();
44
- });
45
- });
46
-
47
- describe('load event', () => {
48
- it('should call load event', () => {
49
- const load = jest.fn();
50
- const instance = new Image({
51
- name: 'image',
52
- component: 'TekImage',
53
- events: {
54
- load,
55
- },
56
- });
57
-
58
- const event = {} as Event;
59
- const element = {} as HTMLElement;
60
- instance.load(event, element);
61
-
62
- expect(load).toHaveBeenCalledWith({
63
- event, element, component: instance,
64
- });
65
- });
66
- });
67
- });
@@ -1,37 +0,0 @@
1
- import { IterableComponentRender } from '@zeedhi/common';
2
- import { IterableCarousel } from '../../../../src';
3
-
4
- describe('IterableCarousel', () => {
5
- describe('constructor()', () => {
6
- it('should create new IterableCarousel with default values', () => {
7
- const instance = new IterableCarousel({
8
- name: 'iterable',
9
- component: 'TekIterableCarousel',
10
- });
11
- expect(instance.iterable).toBeInstanceOf(IterableComponentRender);
12
- });
13
-
14
- it('should create new IterableCarousel replace default values', () => {
15
- const instance = new IterableCarousel({
16
- name: 'iterable',
17
- component: 'TekIterableCarousel',
18
- iterable: {
19
- cssClass: 'test',
20
- },
21
- children: [],
22
- });
23
- expect(instance.iterable.cssClass).toBe('test');
24
- expect(instance.children).toEqual([]);
25
- });
26
-
27
- it('Throw error', () => {
28
- const instance = new IterableCarousel({
29
- name: 'iterable',
30
- component: 'TekIterableCarousel',
31
- });
32
- expect(() => {
33
- instance.children = [{ name: 'childrenItem', component: 'Text' }];
34
- }).toThrow('You should not change children when using IterableCarousel');
35
- });
36
- });
37
- });
@@ -1,200 +0,0 @@
1
- import { IterableComponentRender } from '@zeedhi/common';
2
-
3
- describe('IterableComponentRender', () => {
4
- describe('constructor()', () => {
5
- it('should create new IterableComponentRender with default values', () => {
6
- const instance = new IterableComponentRender({
7
- name: 'IterableComponent',
8
- component: 'TekIterableComponentRender',
9
- });
10
- expect(instance.rowPropName).toBe('row');
11
- expect(instance.componentMetadata).toEqual(undefined);
12
- expect(instance.footerSlot).toEqual([]);
13
- expect(instance.toolbarSlot).toEqual([]);
14
- expect(instance.errorSlot).toEqual([]);
15
- expect(instance.noDataSlot).toEqual([{
16
- name: 'IterableComponent_no-data',
17
- component: 'ZdText',
18
- cssClass: 'no-data',
19
- text: 'NO_DATA',
20
- }]);
21
- expect(instance.noResultSlot).toEqual([
22
- {
23
- name: 'IterableComponent_no-result',
24
- component: 'ZdText',
25
- cssClass: 'no-result',
26
- text: 'NO_RESULT',
27
- },
28
- ]);
29
- expect(instance.height).toBe('auto');
30
- expect(instance.maxHeight).toBe('none');
31
- expect(instance.minHeight).toBe('auto');
32
- });
33
-
34
- it('should create new IterableComponentRender replacing default values', () => {
35
- const instance = new IterableComponentRender({
36
- name: 'IterableComponent',
37
- component: 'TekIterableComponentRender',
38
- rowPropName: 'div',
39
- noDataSlot: [{
40
- name: 'noData',
41
- component: 'ZdText',
42
- cssClass: 'noData',
43
- text: 'Sem dados',
44
- }],
45
- noResultSlot: [{
46
- name: 'noResult',
47
- component: 'ZdText',
48
- cssClass: 'noResult',
49
- text: 'Sem resultado',
50
- }],
51
- errorSlot: [{
52
- name: 'error',
53
- component: 'ZdText',
54
- cssClass: 'error',
55
- text: 'Error',
56
- }],
57
- toolbarSlot: [{
58
- name: 'toolbar',
59
- component: 'ZdText',
60
- text: 'toolbar',
61
- }],
62
- footerSlot: [{
63
- name: 'footer',
64
- component: 'ZdText',
65
- text: 'footer',
66
- }],
67
- height: '400px',
68
- minHeight: '300px',
69
- maxHeight: '500px',
70
- });
71
-
72
- expect(instance.height).toBe('400px');
73
- expect(instance.minHeight).toBe('300px');
74
- expect(instance.maxHeight).toBe('500px');
75
- expect(instance.rowPropName).toBe('div');
76
- expect(instance.componentMetadata).toStrictEqual(undefined);
77
- expect(instance.footerSlot).toEqual([
78
- {
79
- name: 'footer',
80
- component: 'ZdText',
81
- text: 'footer',
82
- },
83
- ]);
84
- expect(instance.toolbarSlot).toEqual([
85
- {
86
- name: 'toolbar',
87
- component: 'ZdText',
88
- text: 'toolbar',
89
- },
90
- ]);
91
- expect(instance.errorSlot).toEqual([
92
- {
93
- name: 'error',
94
- component: 'ZdText',
95
- cssClass: 'error',
96
- text: 'Error',
97
- },
98
- ]);
99
- expect(instance.noDataSlot).toEqual([
100
- {
101
- name: 'noData',
102
- component: 'ZdText',
103
- cssClass: 'noData',
104
- text: 'Sem dados',
105
- },
106
- ]);
107
- expect(instance.noResultSlot).toEqual([
108
- {
109
- name: 'noResult',
110
- component: 'ZdText',
111
- cssClass: 'noResult',
112
- text: 'Sem resultado',
113
- },
114
- ]);
115
- });
116
- });
117
-
118
- describe('getComponentMetaData()', () => {
119
- it('call getComponentMetaData()', () => {
120
- const instance = new IterableComponentRender({
121
- name: 'IterableComponent',
122
- component: 'TekIterableComponentRender',
123
- datasource: {
124
- uniqueKey: 'id',
125
- data: [{ id: 'id1', name: 'Item 1' }],
126
- },
127
- componentMetadata: {
128
- name: 'name-<<row.id>>',
129
- component: 'Col',
130
- children: [
131
- {
132
- name: 'name-<<row.id>>-button',
133
- component: 'Button',
134
- label: '<<row.name>>-button',
135
- value: '<<row.value>>',
136
- },
137
- ],
138
- },
139
- });
140
- expect(instance.getComponentMetadata({ id: 'id1', name: 'Item 1', value: true })).toEqual({
141
- name: 'name-id1',
142
- component: 'Col',
143
- children: [
144
- {
145
- name: 'name-id1-button',
146
- component: 'Button',
147
- label: 'Item 1-button',
148
- value: true,
149
- },
150
- ],
151
- });
152
- });
153
- });
154
-
155
- describe('addSlashes()', () => {
156
- it('add regexp slashes', () => {
157
- const instance = new IterableComponentRender({
158
- name: 'IterableComponent',
159
- component: 'TekIterableComponentRender',
160
- componentMetadata: {
161
- name: 'name-<<row.id>>',
162
- component: 'Col',
163
- children: [
164
- {
165
- name: 'name-<<row.id>>-button',
166
- component: 'Button',
167
- label: '<<row.name>>',
168
- },
169
- ],
170
- },
171
- });
172
-
173
- const metadata1: any = instance.getComponentMetadata({ id: 'id1', name: 'It \t em \n 1' });
174
- expect(metadata1).toEqual({
175
- name: 'name-id1',
176
- component: 'Col',
177
- children: [
178
- {
179
- name: 'name-id1-button',
180
- component: 'Button',
181
- label: 'It \t em \n 1',
182
- },
183
- ],
184
- });
185
-
186
- const metadata2: any = instance.getComponentMetadata({ id: 'id2', name: 'It \r em \f \x22 2' });
187
- expect(metadata2).toEqual({
188
- name: 'name-id2',
189
- component: 'Col',
190
- children: [
191
- {
192
- name: 'name-id2-button',
193
- component: 'Button',
194
- label: 'It \r em \f \x22 2',
195
- },
196
- ],
197
- });
198
- });
199
- });
200
- });