@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,44 +0,0 @@
1
- import { Button } from '@zeedhi/common';
2
- import { TekGrid } from '../../../../../src/components';
3
- import { ButtonOption } from '../../../../../src/utils';
4
-
5
- describe('ButtonOption', () => {
6
- describe('buildComponent()', () => {
7
- it('when called, should build a simple button component', () => {
8
- const grid = new TekGrid({ name: 'Grid', component: 'TekGrid' });
9
- const config = {
10
- type: 'pdf',
11
- label: 'Exportar PDF',
12
- };
13
- const option = new ButtonOption(config);
14
-
15
- const component = option.buildComponent(grid);
16
-
17
- expect(component).toEqual(expect.objectContaining({
18
- label: config.label,
19
- name: 'Grid_export_pdf_portrait',
20
- component: 'ZdButton',
21
- iconName: undefined,
22
- flat: true,
23
- }));
24
- });
25
-
26
- it('the generated button component should call grid.getReport on click', () => {
27
- const grid = new TekGrid({ name: 'Grid', component: 'TekGrid' });
28
- const spy = jest.fn();
29
- grid.getReport = spy;
30
- const config = {
31
- type: 'pdf',
32
- label: 'Exportar PDF',
33
- };
34
- const option = new ButtonOption(config);
35
-
36
- const component = option.buildComponent(grid);
37
-
38
- const instance = new Button(component);
39
- instance.click();
40
-
41
- expect(spy).toHaveBeenCalledTimes(1);
42
- });
43
- });
44
- });
@@ -1,135 +0,0 @@
1
- import { Button, type IText, Text } from '@zeedhi/common';
2
- import { type ITekGridExportConfig, TekGrid } from '../../../../../src/components';
3
- import { MultiOption } from '../../../../../src/utils';
4
-
5
- describe('MultiOption', () => {
6
- describe('buildComponent()', () => {
7
- it('when called, should build a row with multiple buttons', () => {
8
- const grid = new TekGrid({ name: 'Grid', component: 'TekGrid' });
9
- const config: ITekGridExportConfig = {
10
- type: 'pdf',
11
- label: 'Exportar PDF',
12
- multiOption: [
13
- { label: 'portrait', iconName: 'icon-portrait' },
14
- { label: 'landscape', iconName: 'icon-landscape' },
15
- ],
16
- };
17
- const option = new MultiOption(config);
18
-
19
- const component = option.buildComponent(grid);
20
-
21
- expect(component).toEqual({
22
- name: 'Grid_export_pdf_row',
23
- component: 'ZdRow',
24
- cssClass: 'zd-display-flex zd-ma-0 zd-py-0 zd-gap-x-1 tek-grid-export-multioption-row',
25
- children: [
26
- expect.objectContaining({
27
- name: 'Grid_export_pdf_text',
28
- component: 'ZdText',
29
- text: 'Exportar PDF',
30
- cssClass: 'zd-display-flex zd-align-center zd-flex-grow-1 tek-grid-export-multioption-text',
31
- }),
32
- {
33
- name: 'Grid_export_pdf_tooltip_portrait',
34
- component: 'ZdTooltip',
35
- bottom: true,
36
- label: 'portrait',
37
- children: [
38
- expect.objectContaining({
39
- name: 'Grid_export_pdf_button_portrait',
40
- component: 'ZdButton',
41
- icon: true,
42
- iconName: 'icon-portrait',
43
- }),
44
- ],
45
- },
46
- expect.objectContaining({
47
- name: 'Grid_export_pdf_divider_portrait',
48
- component: 'ZdDivider',
49
- cssClass: 'zd-my-1',
50
- vertical: true,
51
- }),
52
- {
53
- name: 'Grid_export_pdf_tooltip_landscape',
54
- component: 'ZdTooltip',
55
- bottom: true,
56
- label: 'landscape',
57
- children: [
58
- expect.objectContaining({
59
- name: 'Grid_export_pdf_button_landscape',
60
- component: 'ZdButton',
61
- icon: true,
62
- iconName: 'icon-landscape',
63
- }),
64
- ],
65
- },
66
- ],
67
- });
68
- });
69
-
70
- it('the generated text component should call stopPropagation on click', () => {
71
- const grid = new TekGrid({ name: 'Grid', component: 'TekGrid' });
72
- const config: ITekGridExportConfig = {
73
- type: 'pdf',
74
- label: 'Exportar PDF',
75
- multiOption: [
76
- { label: 'portrait', iconName: 'icon-portrait' },
77
- { label: 'landscape', iconName: 'icon-landscape' },
78
- ],
79
- };
80
- const option = new MultiOption(config);
81
-
82
- const component = option.buildComponent(grid);
83
-
84
- const instance = new Text(component.children![0] as IText);
85
- const spy = jest.fn();
86
- const event = { stopPropagation: spy } as unknown as Event;
87
- instance.click(event);
88
-
89
- expect(spy).toHaveBeenCalled();
90
- });
91
-
92
- it('the generated text component should not throw if event is undefined', () => {
93
- const grid = new TekGrid({ name: 'Grid', component: 'TekGrid' });
94
- const config: ITekGridExportConfig = {
95
- type: 'pdf',
96
- label: 'Exportar PDF',
97
- multiOption: [
98
- { label: 'portrait', iconName: 'icon-portrait' },
99
- { label: 'landscape', iconName: 'icon-landscape' },
100
- ],
101
- };
102
- const option = new MultiOption(config);
103
-
104
- const component = option.buildComponent(grid);
105
-
106
- const instance = new Text(component.children![0] as IText);
107
-
108
- expect(() => instance.callEvent('click', { event: undefined })).not.toThrow();
109
- });
110
-
111
- it('the generated button components should call grid.getReport on click', () => {
112
- const grid = new TekGrid({ name: 'Grid', component: 'TekGrid' });
113
- const spy = jest.fn();
114
- grid.getReport = spy;
115
- const config: ITekGridExportConfig = {
116
- type: 'pdf',
117
- multiOption: [
118
- { label: 'portrait', iconName: 'icon-portrait' },
119
- { label: 'landscape', iconName: 'icon-landscape' },
120
- ],
121
- };
122
- const option = new MultiOption(config);
123
-
124
- const component = option.buildComponent(grid);
125
-
126
- const instance = new Button(component.children![1].children![0]);
127
- instance.click();
128
-
129
- const instance2 = new Button(component.children![3].children![0]);
130
- instance2.click();
131
-
132
- expect(spy).toHaveBeenCalledTimes(2);
133
- });
134
- });
135
- });
@@ -1,174 +0,0 @@
1
- import {
2
- TekGrid,
3
- } from '../../../../src';
4
- import { GridController } from '../../../../src/utils/grid-base/grid-controller';
5
-
6
- describe('GridController', () => {
7
- describe('constructor()', () => {
8
- it('should create controller and get info from grid', () => {
9
- const grid = new TekGrid({
10
- name: 'Grid',
11
- component: 'TekGrid',
12
- title: 'title',
13
- addButton: false,
14
- deleteButton: 'currentRow',
15
- filterButton: true,
16
- columnsButton: true,
17
- editing: true,
18
- showEditButtons: false,
19
- modalFilterProps: {
20
- name: 'name',
21
- height: 'auto',
22
- persistent: true,
23
- },
24
- showExport: true,
25
- showLayoutOptionsButton: true,
26
- showReloadButton: true,
27
- actions: [{ name: 'button', component: 'ZdButton' }],
28
- });
29
- grid.editing = true;
30
- const instance = new GridController(grid);
31
- expect(instance.gridTitle).toBe('title');
32
- expect(instance.showAddButton).toBeFalsy();
33
- expect(instance.showDeleteButton).toBeTruthy();
34
- expect(instance.showFilterButton).toBeTruthy();
35
- expect(instance.showActionsButton).toBeTruthy();
36
- expect(instance.showExportButton).toBeTruthy();
37
- expect(instance.showActionAndExportButton).toBeTruthy();
38
- expect(instance.showSearchInput).toBeTruthy();
39
- expect(instance.showToolbar).toBeTruthy();
40
- expect(instance.toolbarStyle).toBe('');
41
- expect(instance.tooltipName).toBe('TEKGRID_HIDE');
42
- expect(instance.showDivider2).toBeTruthy();
43
- expect(instance.showDivider3).toBeTruthy();
44
- expect(instance.showColumnsButton).toBeTruthy();
45
- expect(instance.columnsButtonIgnore).toEqual([]);
46
- expect(instance.showLayoutOptionsButton).toBeTruthy();
47
- expect(instance.showReloadButton).toBeTruthy();
48
- expect(instance.showDivider1).toBeTruthy();
49
- expect(instance.isEditing).toBeTruthy();
50
- expect(instance.isNotEditing).toBeFalsy();
51
- expect(instance.showEditButtons).toBeFalsy();
52
- expect(instance.disableDeleteButton).toBeTruthy();
53
- expect(instance.showModalFilterProps).toEqual(
54
- expect.objectContaining({
55
- height: 'auto',
56
- persistent: true,
57
- }),
58
- );
59
-
60
- grid.datasource.currentRow = { id: '1' };
61
- expect(instance.disableDeleteButton).toBeFalsy();
62
- grid.showExport = false;
63
- grid.showLayoutOptions = false;
64
- grid.showReload = false;
65
- grid.columnsButton = false;
66
- grid.actions = [];
67
- grid.deleteButton = 'selection';
68
- grid.selectedRows = [{ id: '1' }];
69
- expect(instance.disableDeleteButton).toBeFalsy();
70
- expect(instance.showExportButton).toBeFalsy();
71
- expect(instance.showActionAndExportButton).toBeFalsy();
72
- expect(instance.showLayoutOptionsButton).toBeFalsy();
73
-
74
- instance.showToolbar = false;
75
- expect(instance.toolbarStyle).toBe('is-rotated');
76
- expect(instance.tooltipName).toBe('TEKGRID_SHOW');
77
- expect(instance.showToolbar).toBeFalsy();
78
- });
79
-
80
- it('should verify if showDivider3 is visibility', () => {
81
- const grid = new TekGrid({
82
- name: 'Grid',
83
- component: 'TekGrid',
84
- addButton: false,
85
- deleteButton: 'none',
86
- filterButton: false,
87
- columnsButton: false,
88
- showReload: false,
89
- showLayoutOptions: false,
90
- showReloadButton: true,
91
- showSearch: false,
92
- showExport: false,
93
- actions: [],
94
- });
95
- const instance = new GridController(grid);
96
-
97
- expect(instance.showDivider3).toBeFalsy();
98
- expect(instance.showActionsButton).toBeFalsy();
99
- expect(instance.showExportButton).toBeFalsy();
100
- expect(instance.showSearchInput).toBeFalsy();
101
- });
102
-
103
- it('should verify if showActionAndExportButton is visibility', () => {
104
- const grid = new TekGrid({
105
- name: 'Grid',
106
- component: 'TekGrid',
107
- addButton: false,
108
- deleteButton: 'none',
109
- filterButton: false,
110
- columnsButton: true,
111
- showReload: false,
112
- showLayoutOptions: true,
113
- showReloadButton: true,
114
- showSearch: false,
115
- showExport: false,
116
- actions: [],
117
- });
118
- const instance = new GridController(grid);
119
-
120
- expect(instance.showActionAndExportButton).toBeFalsy();
121
- expect(instance.showActionsButton).toBeFalsy();
122
- expect(instance.showSearchInput).toBeFalsy();
123
- expect(instance.showExportButton).toBeFalsy();
124
- });
125
-
126
- it('should verify if showDivider2 is visibility', () => {
127
- const grid = new TekGrid({
128
- name: 'Grid',
129
- component: 'TekGrid',
130
- addButton: false,
131
- deleteButton: 'none',
132
- filterButton: false,
133
- columnsButton: false,
134
- showReload: true,
135
- showLayoutOptions: false,
136
- showSearch: false,
137
- showExport: false,
138
- actions: [],
139
- });
140
- const instance = new GridController(grid);
141
-
142
- expect(instance.showDivider2).toBeFalsy();
143
- expect(instance.showActionsButton).toBeFalsy();
144
- expect(instance.showSearchInput).toBeFalsy();
145
- expect(instance.showColumnsButton).toBeFalsy();
146
- expect(instance.showExportButton).toBeFalsy();
147
- expect(instance.showReloadButton).toBeTruthy();
148
- });
149
-
150
- it('should verify if showDivider1 is visibility', () => {
151
- const grid = new TekGrid({
152
- name: 'Grid',
153
- component: 'TekGrid',
154
- addButton: true,
155
- deleteButton: 'selection',
156
- filterButton: false,
157
- columnsButton: false,
158
- showReload: false,
159
- showLayoutOptions: false,
160
- showSearch: false,
161
- showExport: false,
162
- actions: [],
163
- });
164
- const instance = new GridController(grid);
165
-
166
- expect(instance.showDivider1).toBeFalsy();
167
- expect(instance.showActionsButton).toBeFalsy();
168
- expect(instance.showSearchInput).toBeFalsy();
169
- expect(instance.showColumnsButton).toBeFalsy();
170
- expect(instance.showExportButton).toBeFalsy();
171
- expect(instance.showReloadButton).toBeFalsy();
172
- });
173
- });
174
- });
@@ -1,66 +0,0 @@
1
- import { ReportFilter } from '../../../../src/utils';
2
-
3
- describe('ReportFilter', () => {
4
- describe('constructor()', () => {
5
- it('should create a ReportFilter with defined values', () => {
6
- const filter = {
7
- name: [
8
- {
9
- value: 'Luiz',
10
- relation: 'AND',
11
- operation: 'CONTAINS',
12
- },
13
- ],
14
- };
15
-
16
- const instance = new ReportFilter(filter);
17
-
18
- expect(instance.filter).toEqual(filter);
19
- });
20
- });
21
-
22
- describe('build', () => {
23
- it('should build the filter in ZhReports format', () => {
24
- const filter = {
25
- name: [
26
- {
27
- value: 'Luiz',
28
- relation: 'AND',
29
- operation: 'CONTAINS',
30
- },
31
- ],
32
- salary: [
33
- {
34
- value: '100',
35
- relation: 'AND',
36
- operation: 'GREATER_THAN',
37
- },
38
- {
39
- value: '200',
40
- relation: 'AND',
41
- operation: 'LESS_THAN',
42
- },
43
- {
44
- value: '500',
45
- relation: 'OR',
46
- operation: 'EQUALS',
47
- },
48
- ],
49
- };
50
- const instance = new ReportFilter(filter);
51
-
52
- const newFilter = instance.build();
53
-
54
- expect(newFilter).toEqual([
55
- {
56
- label: 'name',
57
- value: 'contains Luiz',
58
- },
59
- {
60
- label: 'salary',
61
- value: 'is greater than 100 and is less than 200 or is equal to 500',
62
- },
63
- ]);
64
- });
65
- });
66
- });