@zeedhi/teknisa-components-common 1.107.2 → 1.109.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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@zeedhi/teknisa-components-common",
3
- "version": "1.107.2",
3
+ "version": "1.109.0",
4
4
  "description": "Teknisa Components Common",
5
5
  "author": "Zeedhi <zeedhi@teknisa.com>",
6
6
  "license": "ISC",
@@ -32,5 +32,5 @@
32
32
  "peerDependencies": {
33
33
  "@zeedhi/core": "^1.97.0"
34
34
  },
35
- "gitHead": "22ed04e302519474cdb354aeb93ad1a29ad0407d"
35
+ "gitHead": "5b0e3a375f2b42bb3486f4b1bdf6b7dffcda1421"
36
36
  }
@@ -316,7 +316,7 @@ describe('TekRestDatasource', () => {
316
316
  search_in: [],
317
317
  page: 1,
318
318
  limit: 10,
319
- search_in_params: '{}',
319
+ search_in_params: undefined,
320
320
  },
321
321
  });
322
322
  });
@@ -545,17 +545,17 @@ describe('TekGridFilterButton', () => {
545
545
 
546
546
  const dateComp = new Date(formElements[0]);
547
547
  dateComp.helperValue = 'TODAY';
548
- dateComp.change({} as Event, {} as HTMLElement);
548
+ dateComp.changeEvent({} as Event, {} as HTMLElement);
549
549
  expect((instance.columns[0].filterProps as IFilterPropsComponent).helperValue).toBe('TODAY');
550
550
 
551
551
  const dateComp21 = new Date(formElements[1]);
552
552
  dateComp21.helperValue = 'TODAY';
553
- dateComp21.change({} as Event, {} as HTMLElement);
553
+ dateComp21.changeEvent({} as Event, {} as HTMLElement);
554
554
  expect((instance.columns[1].filterProps as IFilterPropsComponent[])[0].helperValue).toBe('TODAY');
555
555
 
556
556
  const dateComp22 = new Date(formElements[2]);
557
557
  dateComp22.helperValue = 'TODAY';
558
- dateComp22.change({} as Event, {} as HTMLElement);
558
+ dateComp22.changeEvent({} as Event, {} as HTMLElement);
559
559
  expect((instance.columns[1].filterProps as IFilterPropsComponent[])[1].helperValue).toBe('TODAY');
560
560
 
561
561
  spy.mockReset();
@@ -4,6 +4,7 @@ import {
4
4
  Button, Dropdown, IModal, Modal, ModalService, Search, TextInput, Text, Report,
5
5
  AlertService,
6
6
  EmptyDataError,
7
+ IComponentRender,
7
8
  } from '@zeedhi/common';
8
9
  import {
9
10
  KeyMap, Http, Metadata, IDictionary, IEventParam,
@@ -13,11 +14,13 @@ import {
13
14
  import {
14
15
  ITekGrid,
15
16
  ITekGridFilterButton,
17
+ ITekGridGroupFooter,
16
18
  TekGrid, TekGridColumn, TekGridFilterButton, TekRestDatasource,
17
19
  } from '../../../../src';
18
20
  import { ReportFilter } from '../../../../src/utils';
19
21
  import { setClick, getChild } from '../../../__helpers__';
20
22
  import { flushPromises } from '../../../__helpers__/flush-promises-helper';
23
+ import { TekGridDeleteRowsError } from '../../../../src/error/delete-rows-error';
21
24
 
22
25
  jest.mock('lodash.debounce', () => jest.fn((fn) => fn));
23
26
 
@@ -58,19 +61,19 @@ const createGroupedGrid = async (props: Partial<ITekGrid> = {}) => {
58
61
  uniqueKey: 'id',
59
62
  data: [
60
63
  {
61
- id: '1', name: 'First', month: 11, department: 1,
64
+ id: '1', name: 'First', month: 11, department: 1, salary: 10,
62
65
  },
63
66
  {
64
- id: '2', name: 'Second', month: 11, department: 1,
67
+ id: '2', name: 'Second', month: 11, department: 1, salary: 10,
65
68
  },
66
69
  {
67
- id: '3', name: 'Third', month: 11, department: 2,
70
+ id: '3', name: 'Third', month: 11, department: 2, salary: 10,
68
71
  },
69
72
  {
70
- id: '4', name: 'Fourth', month: 12, department: 1,
73
+ id: '4', name: 'Fourth', month: 12, department: 1, salary: 10,
71
74
  },
72
75
  {
73
- id: '5', name: 'Fifth', month: 12, department: 2,
76
+ id: '5', name: 'Fifth', month: 12, department: 2, salary: 10,
74
77
  },
75
78
  ],
76
79
  },
@@ -81,6 +84,17 @@ const createGroupedGrid = async (props: Partial<ITekGrid> = {}) => {
81
84
  return grid;
82
85
  };
83
86
 
87
+ const getNthFooter = (grid: TekGrid, n: number): ITekGridGroupFooter => {
88
+ const { groupedData } = grid;
89
+
90
+ return groupedData.filter((row) => row.groupFooter)[n] as ITekGridGroupFooter;
91
+ };
92
+
93
+ const getLastFooter = (grid: TekGrid) : ITekGridGroupFooter => {
94
+ const { groupedData } = grid;
95
+ return groupedData.filter((row) => row.groupFooter).reverse()[0] as ITekGridGroupFooter;
96
+ };
97
+
84
98
  describe('TekGrid', () => {
85
99
  beforeEach(() => {
86
100
  // clear all metadata instances before testing
@@ -497,7 +511,7 @@ describe('TekGrid', () => {
497
511
  instance.onCreated();
498
512
  const toolbarDiv = instance.toolbarSlot[2];
499
513
  if (toolbarDiv.children) {
500
- const button = new Button(toolbarDiv.children[1]);
514
+ const button = new Button(toolbarDiv.children[10]);
501
515
  const event = new Event('click');
502
516
  button.click(event, {} as HTMLElement);
503
517
  expect(spy).toBeCalled();
@@ -521,7 +535,7 @@ describe('TekGrid', () => {
521
535
  instance.onCreated();
522
536
  const toolbarDiv = instance.toolbarSlot[2];
523
537
  if (toolbarDiv.children) {
524
- const button = new Button(toolbarDiv.children[1]);
538
+ const button = new Button(toolbarDiv.children[10]);
525
539
  const event = new Event('click');
526
540
  button.click(event, {} as HTMLElement);
527
541
  expect(beforeSaveCalled).toBeTruthy();
@@ -545,7 +559,7 @@ describe('TekGrid', () => {
545
559
  instance.onCreated();
546
560
  const toolbarDiv = instance.toolbarSlot[2];
547
561
  if (toolbarDiv.children) {
548
- const button = new Button(toolbarDiv.children[1]);
562
+ const button = new Button(toolbarDiv.children[10]);
549
563
  button.click({ defaultPrevented: true } as Event, {} as HTMLElement);
550
564
  expect(beforeSaveCalled).toBeTruthy();
551
565
  expect(afterSaveCalled).toBeFalsy();
@@ -566,7 +580,7 @@ describe('TekGrid', () => {
566
580
  instance.onCreated();
567
581
  const toolbarDiv = instance.toolbarSlot[2];
568
582
  if (toolbarDiv.children) {
569
- const button = new Button(toolbarDiv.children[2]);
583
+ const button = new Button(toolbarDiv.children[11]);
570
584
  const event = new Event('click');
571
585
  button.click(event, {} as HTMLElement);
572
586
  expect(spy).toBeCalled();
@@ -590,7 +604,7 @@ describe('TekGrid', () => {
590
604
  instance.onCreated();
591
605
  const toolbarDiv = instance.toolbarSlot[2];
592
606
  if (toolbarDiv.children) {
593
- const button = new Button(toolbarDiv.children[2]);
607
+ const button = new Button(toolbarDiv.children[11]);
594
608
  const event = new Event('click');
595
609
  button.click(event, {} as HTMLElement);
596
610
  expect(beforeCancelCalled).toBeTruthy();
@@ -614,7 +628,7 @@ describe('TekGrid', () => {
614
628
  instance.onCreated();
615
629
  const toolbarDiv = instance.toolbarSlot[2];
616
630
  if (toolbarDiv.children) {
617
- const button = new Button(toolbarDiv.children[2]);
631
+ const button = new Button(toolbarDiv.children[11]);
618
632
  button.click({ defaultPrevented: true } as Event, {} as HTMLElement);
619
633
  expect(beforeCancelCalled).toBeTruthy();
620
634
  expect(afterCancelCalled).toBeFalsy();
@@ -1965,6 +1979,79 @@ describe('TekGrid', () => {
1965
1979
  });
1966
1980
  });
1967
1981
 
1982
+ describe('updateSummary()', () => {
1983
+ it('should update aggregation data always using the visible cell value', async () => {
1984
+ const instance = await createGroupedGrid({
1985
+ columns: [
1986
+ { name: 'id' },
1987
+ { name: 'name' },
1988
+ { name: 'department', grouped: true },
1989
+ { name: 'salary', aggregation: 'SUM' },
1990
+ ],
1991
+ });
1992
+
1993
+ await flushPromises();
1994
+ instance.buildGroupedData();
1995
+
1996
+ let firstFooter = getNthFooter(instance, 0);
1997
+ let secondFooter = getNthFooter(instance, 1);
1998
+ let thirdFooter = getNthFooter(instance, 2);
1999
+ expect(firstFooter.salary).toBe(30);
2000
+ expect(secondFooter.salary).toBe(20);
2001
+ expect(thirdFooter.salary).toBe(50);
2002
+
2003
+ instance.editing = true;
2004
+ instance.updateCell('1', 'salary', 20);
2005
+
2006
+ instance.updateSummary();
2007
+
2008
+ firstFooter = getNthFooter(instance, 0);
2009
+ secondFooter = getNthFooter(instance, 1);
2010
+ thirdFooter = getNthFooter(instance, 2);
2011
+ expect(firstFooter.salary).toBe(40);
2012
+ expect(secondFooter.salary).toBe(20);
2013
+ expect(thirdFooter.salary).toBe(60);
2014
+ });
2015
+
2016
+ it('should update aggregation data with many groups', async () => {
2017
+ const instance = await createGroupedGrid({
2018
+ columns: [
2019
+ { name: 'id' },
2020
+ { name: 'name' },
2021
+ { name: 'month', grouped: true },
2022
+ { name: 'department', grouped: true },
2023
+ { name: 'salary', aggregation: 'SUM' },
2024
+ ],
2025
+ });
2026
+
2027
+ await flushPromises();
2028
+ instance.buildGroupedData();
2029
+
2030
+ let firstFooter = getNthFooter(instance, 0);
2031
+ let secondFooter = getNthFooter(instance, 1);
2032
+ let thirdFooter = getNthFooter(instance, 2);
2033
+ let lastFooter = getLastFooter(instance);
2034
+ expect(firstFooter.salary).toBe(20);
2035
+ expect(secondFooter.salary).toBe(10);
2036
+ expect(thirdFooter.salary).toBe(30);
2037
+ expect(lastFooter.salary).toBe(50);
2038
+
2039
+ instance.editing = true;
2040
+ instance.updateCell('1', 'salary', 20);
2041
+
2042
+ instance.updateSummary();
2043
+
2044
+ firstFooter = getNthFooter(instance, 0);
2045
+ secondFooter = getNthFooter(instance, 1);
2046
+ thirdFooter = getNthFooter(instance, 2);
2047
+ lastFooter = getLastFooter(instance);
2048
+ expect(firstFooter.salary).toBe(30);
2049
+ expect(secondFooter.salary).toBe(10);
2050
+ expect(thirdFooter.salary).toBe(40);
2051
+ expect(lastFooter.salary).toBe(60);
2052
+ });
2053
+ });
2054
+
1968
2055
  describe('setSearch()', () => {
1969
2056
  let baseProps: ITekGrid;
1970
2057
  let httpSpy: jest.SpyInstance;
@@ -3113,4 +3200,141 @@ describe('TekGrid', () => {
3113
3200
  ]);
3114
3201
  });
3115
3202
  });
3203
+
3204
+ describe('toolbar creation', () => {
3205
+ it('should render predefined items in toolbarConfig', () => {
3206
+ const grid = new TekGrid({
3207
+ name: 'grid',
3208
+ component: 'TekGrid',
3209
+ toolbarConfig: ['addButton'],
3210
+ });
3211
+ grid.onCreated();
3212
+
3213
+ expect(grid.toolbarSlot.length).toBe(3);
3214
+ const toolbarDiv = grid.toolbarSlot[2];
3215
+ expect(toolbarDiv.children?.length).toBe(1);
3216
+ expect(toolbarDiv.children?.[0].name).toContain('_add_tooltip');
3217
+ });
3218
+
3219
+ it('should render custom components in toolbarConfig', () => {
3220
+ const grid = new TekGrid({
3221
+ name: 'grid',
3222
+ component: 'TekGrid',
3223
+ toolbarConfig: [{ component: 'ZdButton', name: 'customButton' }],
3224
+ });
3225
+ grid.onCreated();
3226
+
3227
+ const toolbarDiv = grid.toolbarSlot[2];
3228
+ expect(toolbarDiv.children?.length).toBe(1);
3229
+ expect(toolbarDiv.children?.[0].name).toBe('customButton');
3230
+ });
3231
+
3232
+ it('should alert about invalid items of string type in toolbarConfig', () => {
3233
+ const warnSpy = jest.spyOn(console, 'warn').mockImplementation(() => {});
3234
+ const grid = new TekGrid({
3235
+ name: 'grid',
3236
+ component: 'TekGrid',
3237
+ toolbarConfig: ['invalidItem'],
3238
+ });
3239
+ grid.onCreated();
3240
+
3241
+ expect(warnSpy).toHaveBeenCalledWith('Predefined toolbar item "invalidItem" not found.');
3242
+ warnSpy.mockRestore();
3243
+ });
3244
+
3245
+ it('should alert about invalid items in toolbarConfig', () => {
3246
+ const warnSpy = jest.spyOn(console, 'warn').mockImplementation(() => {});
3247
+ const grid = new TekGrid({
3248
+ name: 'grid',
3249
+ component: 'TekGrid',
3250
+ toolbarConfig: [123 as any],
3251
+ });
3252
+ grid.onCreated();
3253
+
3254
+ expect(warnSpy).toHaveBeenCalledWith('Invalid item in toolbarConfig:', 123);
3255
+ warnSpy.mockRestore();
3256
+ });
3257
+ });
3258
+
3259
+ describe('addButtonClick', () => {
3260
+ it('should set editingNewRows as true when editNewRowsOnly is enabled', () => {
3261
+ const grid = new TekGrid({
3262
+ name: 'grid',
3263
+ component: 'TekGrid',
3264
+ addButton: true,
3265
+ editNewRowsOnly: true,
3266
+ });
3267
+
3268
+ (grid as any).gridBase.addButtonClick({ event: new Event('click') });
3269
+
3270
+ expect((grid as any).editingNewRows).toBe(true);
3271
+ });
3272
+ });
3273
+
3274
+ describe('deleteButtonClick', () => {
3275
+ it('should throw TekGridDeleteRowsError when selectAllPages is true', () => {
3276
+ const grid = new TekGrid({
3277
+ name: 'grid',
3278
+ component: 'TekGrid',
3279
+ deleteButton: 'selection',
3280
+ selectAllPages: true,
3281
+ });
3282
+
3283
+ const deleteFn = () => {
3284
+ (grid as any).gridBase.deleteButtonClick({ event: new Event('click') });
3285
+ };
3286
+
3287
+ expect(deleteFn).toThrow(TekGridDeleteRowsError);
3288
+ });
3289
+ });
3290
+
3291
+ describe('reloadGrid', () => {
3292
+ it('should call grid.reload() if beforeReload event is not prevented', () => {
3293
+ const grid = new TekGrid({
3294
+ name: 'grid',
3295
+ component: 'TekGrid',
3296
+ });
3297
+ const reloadSpy = jest.spyOn(grid, 'reload');
3298
+ const event = new Event('click');
3299
+
3300
+ (grid as any).gridBase.reloadGrid({ event });
3301
+
3302
+ expect(reloadSpy).toHaveBeenCalledTimes(1);
3303
+
3304
+ reloadSpy.mockRestore();
3305
+ });
3306
+
3307
+ it('should not call grid.reload() if beforeReload event is prevented', () => {
3308
+ const grid = new TekGrid({
3309
+ name: 'grid',
3310
+ component: 'TekGrid',
3311
+ });
3312
+ const reloadSpy = jest.spyOn(grid, 'reload');
3313
+ const mockEvent = { defaultPrevented: true };
3314
+
3315
+ (grid as any).gridBase.reloadGrid({ event: mockEvent });
3316
+
3317
+ expect(reloadSpy).not.toHaveBeenCalled();
3318
+
3319
+ reloadSpy.mockRestore();
3320
+ });
3321
+ });
3322
+
3323
+ describe('toolbar creation', () => {
3324
+ it('should create toolbar with default items', () => {
3325
+ const grid = new TekGrid({
3326
+ name: 'grid',
3327
+ component: 'TekGrid',
3328
+ });
3329
+ const { gridBase } = grid as any;
3330
+ delete (gridBase as any).defaultToolbar.title;
3331
+ delete (gridBase as any).defaultToolbar.hideButton;
3332
+
3333
+ const toolbarSlot = gridBase.createToolbarProps();
3334
+
3335
+ expect(toolbarSlot.find((c: IComponentRender) => c.name?.includes('_title'))).toBeUndefined();
3336
+ expect(toolbarSlot.find((c: IComponentRender) => c.name?.includes('_hideTooltip'))).toBeUndefined();
3337
+ expect(toolbarSlot[0].name).toBe('grid_toolbarDiv');
3338
+ });
3339
+ });
3116
3340
  });
@@ -0,0 +1,24 @@
1
+ import { TekGridDeleteRowsError } from '../../../../src/error/delete-rows-error';
2
+
3
+ describe('TekGridDeleteRowsError', () => {
4
+ describe('constructor()', () => {
5
+ it('should create an instance of the error with the correct name and message', () => {
6
+ // Cria uma nova instância do erro
7
+ const error = new TekGridDeleteRowsError();
8
+
9
+ // Verifica se a instância foi criada corretamente
10
+ expect(error).toBeInstanceOf(TekGridDeleteRowsError);
11
+ expect(error).toBeInstanceOf(Error);
12
+
13
+ // Verifica se o nome do erro está correto
14
+ expect(error.name).toBe('TekGridDeleteRowsError');
15
+
16
+ // Verifica se a mensagem de erro está correta
17
+ expect(error.message).toBe(
18
+ 'TekGrid can\'t automatically delete rows when selectAllPages property is true.'
19
+ + ' You should delete them manually using the beforeDelete event and preventing'
20
+ + ' the default execution',
21
+ );
22
+ });
23
+ });
24
+ });
@@ -26,7 +26,7 @@ describe('GridController', () => {
26
26
  showReloadButton: true,
27
27
  actions: [{ name: 'button', component: 'ZdButton' }],
28
28
  });
29
- grid.editing = true;
29
+ grid.editing = false;
30
30
  const instance = new GridController(grid);
31
31
  expect(instance.gridTitle).toBe('title');
32
32
  expect(instance.showAddButton).toBeFalsy();
@@ -39,15 +39,13 @@ describe('GridController', () => {
39
39
  expect(instance.showToolbar).toBeTruthy();
40
40
  expect(instance.toolbarStyle).toBe('');
41
41
  expect(instance.tooltipName).toBe('TEKGRID_HIDE');
42
- expect(instance.showDivider2).toBeTruthy();
43
- expect(instance.showDivider3).toBeTruthy();
44
42
  expect(instance.showColumnsButton).toBeTruthy();
45
43
  expect(instance.columnsButtonIgnore).toEqual([]);
46
44
  expect(instance.showLayoutOptionsButton).toBeTruthy();
47
45
  expect(instance.showReloadButton).toBeTruthy();
48
- expect(instance.showDivider1).toBeTruthy();
49
- expect(instance.isEditing).toBeTruthy();
50
- expect(instance.isNotEditing).toBeFalsy();
46
+ expect(instance.showDivider).toBeTruthy();
47
+ expect(instance.isEditing).toBeFalsy();
48
+ expect(instance.isNotEditing).toBeTruthy();
51
49
  expect(instance.showEditButtons).toBeFalsy();
52
50
  expect(instance.disableDeleteButton).toBeTruthy();
53
51
  expect(instance.showModalFilterProps).toEqual(
@@ -94,7 +92,6 @@ describe('GridController', () => {
94
92
  });
95
93
  const instance = new GridController(grid);
96
94
 
97
- expect(instance.showDivider3).toBeFalsy();
98
95
  expect(instance.showActionsButton).toBeFalsy();
99
96
  expect(instance.showExportButton).toBeFalsy();
100
97
  expect(instance.showSearchInput).toBeFalsy();
@@ -139,7 +136,6 @@ describe('GridController', () => {
139
136
  });
140
137
  const instance = new GridController(grid);
141
138
 
142
- expect(instance.showDivider2).toBeFalsy();
143
139
  expect(instance.showActionsButton).toBeFalsy();
144
140
  expect(instance.showSearchInput).toBeFalsy();
145
141
  expect(instance.showColumnsButton).toBeFalsy();
@@ -163,7 +159,6 @@ describe('GridController', () => {
163
159
  });
164
160
  const instance = new GridController(grid);
165
161
 
166
- expect(instance.showDivider1).toBeFalsy();
167
162
  expect(instance.showActionsButton).toBeFalsy();
168
163
  expect(instance.showSearchInput).toBeFalsy();
169
164
  expect(instance.showColumnsButton).toBeFalsy();
@@ -171,4 +166,102 @@ describe('GridController', () => {
171
166
  expect(instance.showReloadButton).toBeFalsy();
172
167
  });
173
168
  });
169
+ describe('showAddButton', () => {
170
+ it('should return true when addButton is true, not editing, and toolbar is open', () => {
171
+ const grid = new TekGrid({
172
+ name: 'Grid', component: 'TekGrid', addButton: true, editing: false,
173
+ });
174
+ const instance = new GridController(grid);
175
+ instance.openToolbar = true;
176
+ expect(instance.showAddButton).toBe(true);
177
+ });
178
+
179
+ it('should return false when grid is in editing mode', () => {
180
+ const grid = new TekGrid({
181
+ name: 'Grid', component: 'TekGrid', addButton: true, editing: true,
182
+ });
183
+ const instance = new GridController(grid);
184
+ expect(instance.showAddButton).toBe(true);
185
+ });
186
+
187
+ it('should return false when toolbar is closed', () => {
188
+ const grid = new TekGrid({
189
+ name: 'Grid', component: 'TekGrid', addButton: true, editing: false,
190
+ });
191
+ const instance = new GridController(grid);
192
+ instance.openToolbar = false;
193
+ expect(instance.showAddButton).toBe(false);
194
+ });
195
+ });
196
+
197
+ describe('disableDeleteButton', () => {
198
+ it('should be disabled if selectAllPages is true, allSelected is true, and all items are exceptions', () => {
199
+ const grid = new TekGrid({
200
+ name: 'Grid', component: 'TekGrid', deleteButton: 'selection', selectAllPages: true,
201
+ });
202
+ grid.datasource.total = 3;
203
+ grid.selectionState = { allSelected: true, except: [{ id: 1 }, { id: 2 }, { id: 3 }] };
204
+ const instance = new GridController(grid);
205
+ expect(instance.disableDeleteButton).toBe(true);
206
+ });
207
+
208
+ it('should be disabled if selectAllPages is true, allSelected is false, and no items are exceptions', () => {
209
+ const grid = new TekGrid({
210
+ name: 'Grid', component: 'TekGrid', deleteButton: 'selection', selectAllPages: true,
211
+ });
212
+ grid.selectionState = { allSelected: false, except: [] };
213
+ const instance = new GridController(grid);
214
+ expect(instance.disableDeleteButton).toBe(true);
215
+ });
216
+
217
+ it('should be enabled if selectAllPages is true and there is a valid selection', () => {
218
+ const grid = new TekGrid({
219
+ name: 'Grid', component: 'TekGrid', deleteButton: 'selection', selectAllPages: true,
220
+ });
221
+ grid.datasource.total = 5;
222
+ grid.selectionState = { allSelected: true, except: [{ id: 1 }] };
223
+ const instance = new GridController(grid);
224
+ expect(instance.disableDeleteButton).toBe(false);
225
+ });
226
+
227
+ it('should not be disabled when deleteButton is "none"', () => {
228
+ const grid = new TekGrid({ name: 'Grid', component: 'TekGrid', deleteButton: 'none' }); //
229
+ const instance = new GridController(grid);
230
+ expect(instance.disableDeleteButton).toBe(false);
231
+ });
232
+ });
233
+
234
+ describe('showEditButtons', () => {
235
+ it('deve retornar true quando o grid está em modo de edição e a propriedade showEditButtons é true', () => {
236
+ const grid = new TekGrid({
237
+ name: 'Grid',
238
+ component: 'TekGrid',
239
+ });
240
+ grid.editing = true;
241
+ const instance = new GridController(grid);
242
+ expect(instance.showEditButtons).toBe(true);
243
+ });
244
+
245
+ it('deve retornar false quando o grid não está em modo de edição', () => {
246
+ const grid = new TekGrid({
247
+ name: 'Grid',
248
+ component: 'TekGrid',
249
+ editing: false,
250
+ showEditButtons: true,
251
+ });
252
+ const instance = new GridController(grid);
253
+ expect(instance.showEditButtons).toBe(false);
254
+ });
255
+
256
+ it('deve retornar false quando a propriedade showEditButtons do grid é false', () => {
257
+ const grid = new TekGrid({
258
+ name: 'Grid',
259
+ component: 'TekGrid',
260
+ editing: true,
261
+ showEditButtons: false,
262
+ });
263
+ const instance = new GridController(grid);
264
+ expect(instance.showEditButtons).toBe(false);
265
+ });
266
+ });
174
267
  });
@@ -1,8 +1,8 @@
1
- import { GridEditable, IComponentRender } from '@zeedhi/common';
1
+ import { GridEditable, IComponentRender, IGridColumnEditable, Input } from '@zeedhi/common';
2
2
  import { Datasource, IDictionary, IEventParam } from '@zeedhi/core';
3
3
  import { ITekGridAtoms } from '../../utils';
4
4
  import { TekGridColumn } from './grid-column';
5
- import { IGroupedData, IModalFilterProps, ITekGrid, ITekGridColumn, ITekGridEvents, ITekGridExportConfig } from './interfaces';
5
+ import { IGroupedData, IModalFilterProps, ITekGrid, ITekGridColumn, ITekGridEvents, ITekGridExportConfig, ITekGridGroup, ITekGridGroupFooter } from './interfaces';
6
6
  import { TekGridLayoutOptions } from './layout-options';
7
7
  export declare class TekGrid extends GridEditable implements ITekGrid {
8
8
  title: string;
@@ -22,6 +22,10 @@ export declare class TekGrid extends GridEditable implements ITekGrid {
22
22
  * @public
23
23
  */
24
24
  dragColumns: boolean;
25
+ /**
26
+ * Components that will be rendered on toolbar slot
27
+ */
28
+ toolbarConfig: (IComponentRender | string)[];
25
29
  /**
26
30
  * Enables column resizing
27
31
  * @public
@@ -65,8 +69,8 @@ export declare class TekGrid extends GridEditable implements ITekGrid {
65
69
  groupColumnNames: string[];
66
70
  summaryColumns: TekGridColumn[];
67
71
  groupColumns: TekGridColumn[];
68
- groupedData: IGroupedData[];
69
72
  private toolbarSlotProps;
73
+ groupedData: IGroupedData[];
70
74
  viewUpdateScrollData?: () => void;
71
75
  private gridBase;
72
76
  filterRelationsDatasource: Datasource;
@@ -129,12 +133,39 @@ export declare class TekGrid extends GridEditable implements ITekGrid {
129
133
  private initSummaryColumns;
130
134
  private addGroupHeader;
131
135
  private addGroupFooters;
136
+ /**
137
+ * Creates a group footer, calculating its summary data
138
+ * @param group Group to which this footer is related
139
+ * @param groupIndex Index of the group
140
+ * @returns new group footer
141
+ */
142
+ getGroupFooter(group: ITekGridGroup, groupIndex: number): ITekGridGroupFooter;
143
+ /**
144
+ * Gets all of the group headers that belong to the group at the specified index
145
+ * This method should be called only during the groups creation process because it depends on the
146
+ * group creation order (because it accesses lastGroupHeaderRow that changes during the creation process)
147
+ * @param groupIndex
148
+ * @returns
149
+ */
150
+ private getGroupHeaders;
151
+ /**
152
+ * Updates all footers summary data and the summary total
153
+ */
154
+ updateSummary(): void;
155
+ /**
156
+ * Takes a group footer and updates its summary data
157
+ */
158
+ private updateGroupFooterSummary;
159
+ /**
160
+ * Updates the total summary data
161
+ */
162
+ private updateSummaryTotal;
132
163
  private resetFooterVariables;
133
164
  private isUndefined;
134
165
  private calcSummaryValues;
135
166
  private calcSummary;
136
- private addSummary;
137
- private summaryData;
167
+ private getSummary;
168
+ private getSummaryData;
138
169
  openGroup(group: IDictionary<any>): void;
139
170
  isItemVisible(row: IDictionary<any>): any;
140
171
  private getGroupValue;
@@ -172,7 +203,7 @@ export declare class TekGrid extends GridEditable implements ITekGrid {
172
203
  */
173
204
  selectGroupClick(row: IDictionary<any>, isSelected: boolean, event: Event, element: HTMLElement): void;
174
205
  getAtomInstance<T>(key: keyof ITekGridAtoms): T;
175
- getFilterInputs(columnName?: string): import("@zeedhi/common").Input[];
206
+ getFilterInputs(columnName?: string): Input[];
176
207
  isColumnSearchable(column: TekGridColumn): boolean;
177
208
  getColumn(name: string): TekGridColumn;
178
209
  /**
@@ -214,8 +245,21 @@ export declare class TekGrid extends GridEditable implements ITekGrid {
214
245
  * Checks if a row is a group header, adding typescript type-checking
215
246
  */
216
247
  private isGroupHeader;
248
+ /**
249
+ * Checks if a row is a group footer, adding typescript type-checking
250
+ */
251
+ private isGroupFooter;
252
+ /**
253
+ * Checks if a row is a summary, adding typescript type-checking
254
+ */
255
+ private isGroupSummary;
217
256
  /**
218
257
  * Checks if a row is the last grouping of the grid (the most internal grouping)
219
258
  */
220
259
  private isLastGrouping;
260
+ /**
261
+ * change event of editable components
262
+ * - override to call updateSummary on change
263
+ */
264
+ protected changeEditableComponent(column: IGridColumnEditable, row: IDictionary<any>, value: any, component?: Input): void;
221
265
  }
@@ -184,16 +184,18 @@ export interface ITekGridGroupFooter {
184
184
  groupHeaders: ITekGridGroupHeader[];
185
185
  groupLabel: string;
186
186
  groupValue: any;
187
+ [key: string]: any;
187
188
  }
189
+ export declare type ITekGridSummaryTotal = ITekGridGroupFooter & {
190
+ [key: string]: any;
191
+ };
188
192
  export declare type IGroupedData = (ITekGridGroupHeader & {
189
193
  [key: string]: any;
190
194
  }) | {
191
195
  [key: string]: any;
192
196
  groupFooter: boolean;
193
197
  groupSummary: boolean;
194
- } | (ITekGridGroupFooter & {
195
- [key: string]: any;
196
- }) | {
198
+ } | ITekGridSummaryTotal | {
197
199
  [key: string]: any;
198
200
  groupHeaders: ITekGridGroupHeader[];
199
201
  };