@zeedhi/teknisa-components-common 1.114.0 → 3.0.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 +40 -0
- package/dist/teknisa-components-common.js +112 -0
- package/dist/teknisa-components-common.min.js +112 -0
- package/dist/types/components/index.d.ts +2 -0
- package/{types → dist/types}/components/tek-breadcrumb-header/breadcrumb-header.d.ts +12 -12
- package/{types → dist/types}/components/tek-breadcrumb-header/interfaces.d.ts +6 -6
- package/{types → dist/types}/error/delete-rows-error.d.ts +6 -6
- package/dist/types/index.d.ts +1 -0
- package/environments.json +14 -0
- package/package.json +26 -18
- package/src/components/index.ts +108 -0
- package/src/components/tek-breadcrumb-header/breadcrumb-header.ts +29 -0
- package/src/components/tek-breadcrumb-header/interfaces.ts +7 -0
- package/src/error/delete-rows-error.ts +11 -0
- package/src/index.ts +1 -0
- package/tests/__helpers__/component-event-helper.ts +1 -1
- package/tests/__helpers__/get-child-helper.ts +1 -1
- package/tests/__helpers__/mock-created-helper.ts +1 -1
- package/tests/unit/components/crud/crud-button.spec.ts +1 -1
- package/tests/unit/components/tek-datasource/memory-datasource.spec.ts +1 -11
- package/tests/unit/components/tek-datasource/rest-datasource.spec.ts +5 -7
- package/tests/unit/components/tek-drag-grid/tek-drag-grid.spec.ts +1 -1
- package/tests/unit/components/tek-grid/grid-column.spec.ts +4 -4
- package/tests/unit/components/tek-grid/grid-filter-button.spec.ts +17 -11
- package/tests/unit/components/tek-grid/grid.spec.ts +45 -721
- package/tests/unit/components/tek-grid/layout_options.spec.ts +5 -7
- package/tests/unit/components/tek-user-info/tek-user-info-list.spec.ts +1 -1
- package/tests/unit/components/tek-user-info/tek-user-info.spec.ts +10 -14
- package/tests/unit/components/tree-grid/tree-grid.spec.ts +4 -28
- package/tests/unit/utils/grid-base/export-options/multi-option.spec.ts +2 -2
- package/tests/unit/utils/grid-base/grid-controller.spec.ts +17 -152
- package/tsconfig.build.json +7 -0
- package/dist/tek-components-common.esm.js +0 -4830
- package/dist/tek-components-common.umd.js +0 -4867
- package/tests/unit/utils/grid-base/delete-rows-error.spec.ts +0 -24
- package/types/components/crud/crud-add-button.d.ts +0 -38
- package/types/components/crud/crud-button.d.ts +0 -27
- package/types/components/crud/crud-cancel-button.d.ts +0 -28
- package/types/components/crud/crud-delete-button.d.ts +0 -42
- package/types/components/crud/crud-form.d.ts +0 -46
- package/types/components/crud/crud-save-button.d.ts +0 -24
- package/types/components/crud/interfaces.d.ts +0 -15
- package/types/components/index.d.ts +0 -41
- package/types/components/tek-card-title/card-title.d.ts +0 -14
- package/types/components/tek-card-title/interfaces.d.ts +0 -9
- package/types/components/tek-datasource/interfaces.d.ts +0 -16
- package/types/components/tek-datasource/memory-datasource.d.ts +0 -100
- package/types/components/tek-datasource/rest-datasource.d.ts +0 -103
- package/types/components/tek-drag-grid/interfaces.d.ts +0 -7
- package/types/components/tek-drag-grid/tek-drag-grid.d.ts +0 -36
- package/types/components/tek-grid/filter-helper.d.ts +0 -7
- package/types/components/tek-grid/grid-column.d.ts +0 -45
- package/types/components/tek-grid/grid-columns-button-controller.d.ts +0 -8
- package/types/components/tek-grid/grid-columns-button.d.ts +0 -12
- package/types/components/tek-grid/grid-filter-button.d.ts +0 -31
- package/types/components/tek-grid/grid.d.ts +0 -267
- package/types/components/tek-grid/interfaces.d.ts +0 -203
- package/types/components/tek-grid/layout-options.d.ts +0 -31
- package/types/components/tek-image/image.d.ts +0 -55
- package/types/components/tek-image/interfaces.d.ts +0 -12
- package/types/components/tek-iterable-carousel/interfaces.d.ts +0 -5
- package/types/components/tek-iterable-carousel/iterable-carousel.d.ts +0 -13
- package/types/components/tek-iterable-component-render/interfaces.d.ts +0 -3
- package/types/components/tek-iterable-component-render/iterable-component-render.d.ts +0 -10
- package/types/components/tek-loading/interfaces.d.ts +0 -6
- package/types/components/tek-loading/loading.d.ts +0 -24
- package/types/components/tek-notifications/interfaces.d.ts +0 -22
- package/types/components/tek-notifications/notifications.d.ts +0 -35
- package/types/components/tek-product-card/interfaces.d.ts +0 -19
- package/types/components/tek-product-card/product-card.d.ts +0 -66
- package/types/components/tek-tree-grid/interfaces.d.ts +0 -30
- package/types/components/tek-tree-grid/tree-grid.d.ts +0 -102
- package/types/components/tek-user-info/TekUserInfoController.d.ts +0 -21
- package/types/components/tek-user-info/interfaces.d.ts +0 -27
- package/types/components/tek-user-info/tek-user-info-list.d.ts +0 -31
- package/types/components/tek-user-info/tek-user-info.d.ts +0 -37
- package/types/error/incomplete-groups-error.d.ts +0 -8
- package/types/index.d.ts +0 -2
- package/types/utils/config/config.d.ts +0 -7
- package/types/utils/extract-properties.d.ts +0 -7
- package/types/utils/grid-base/export-options/button-option.d.ts +0 -16
- package/types/utils/grid-base/export-options/index.d.ts +0 -3
- package/types/utils/grid-base/export-options/interfaces.d.ts +0 -5
- package/types/utils/grid-base/export-options/multi-option.d.ts +0 -12
- package/types/utils/grid-base/grid-base.d.ts +0 -59
- package/types/utils/grid-base/grid-controller.d.ts +0 -27
- package/types/utils/index.d.ts +0 -6
- package/types/utils/report-filter/report-filter.d.ts +0 -12
|
@@ -1,26 +1,23 @@
|
|
|
1
1
|
/* eslint-disable no-underscore-dangle */
|
|
2
2
|
|
|
3
3
|
import {
|
|
4
|
-
Button, Dropdown, IModal, Modal, ModalService, Search, TextInput, Text, Report,
|
|
4
|
+
Button, Dropdown, type IModal, Modal, ModalService, Search, TextInput, Text, Report,
|
|
5
5
|
AlertService,
|
|
6
6
|
EmptyDataError,
|
|
7
|
-
IComponentRender,
|
|
8
7
|
} from '@zeedhi/common';
|
|
9
8
|
import {
|
|
10
|
-
KeyMap, Http, Metadata, IDictionary, IEventParam,
|
|
9
|
+
KeyMap, Http, Metadata, type IDictionary, type IEventParam,
|
|
11
10
|
Datasource,
|
|
12
11
|
init,
|
|
13
12
|
} from '@zeedhi/core';
|
|
14
13
|
import {
|
|
15
|
-
ITekGrid,
|
|
16
|
-
ITekGridFilterButton,
|
|
17
|
-
ITekGridGroupFooter,
|
|
14
|
+
type ITekGrid,
|
|
15
|
+
type ITekGridFilterButton,
|
|
18
16
|
TekGrid, TekGridColumn, TekGridFilterButton, TekRestDatasource,
|
|
19
17
|
} from '../../../../src';
|
|
20
18
|
import { ReportFilter } from '../../../../src/utils';
|
|
21
19
|
import { setClick, getChild } from '../../../__helpers__';
|
|
22
20
|
import { flushPromises } from '../../../__helpers__/flush-promises-helper';
|
|
23
|
-
import { TekGridDeleteRowsError } from '../../../../src/error/delete-rows-error';
|
|
24
21
|
|
|
25
22
|
jest.mock('lodash.debounce', () => jest.fn((fn) => fn));
|
|
26
23
|
|
|
@@ -47,54 +44,6 @@ const createAndMount = (props: ITekGrid) => {
|
|
|
47
44
|
return instance;
|
|
48
45
|
};
|
|
49
46
|
|
|
50
|
-
const createGroupedGrid = async (props: Partial<ITekGrid> = {}) => {
|
|
51
|
-
const grid = createAndMount({
|
|
52
|
-
name: 'grid',
|
|
53
|
-
component: 'TekGrid',
|
|
54
|
-
columns: [
|
|
55
|
-
{ name: 'id' },
|
|
56
|
-
{ name: 'name' },
|
|
57
|
-
{ name: 'month' },
|
|
58
|
-
{ name: 'department', grouped: true },
|
|
59
|
-
],
|
|
60
|
-
datasource: {
|
|
61
|
-
uniqueKey: 'id',
|
|
62
|
-
data: [
|
|
63
|
-
{
|
|
64
|
-
id: '1', name: 'First', month: 11, department: 1, salary: 10,
|
|
65
|
-
},
|
|
66
|
-
{
|
|
67
|
-
id: '2', name: 'Second', month: 11, department: 1, salary: 10,
|
|
68
|
-
},
|
|
69
|
-
{
|
|
70
|
-
id: '3', name: 'Third', month: 11, department: 2, salary: 10,
|
|
71
|
-
},
|
|
72
|
-
{
|
|
73
|
-
id: '4', name: 'Fourth', month: 12, department: 1, salary: 10,
|
|
74
|
-
},
|
|
75
|
-
{
|
|
76
|
-
id: '5', name: 'Fifth', month: 12, department: 2, salary: 10,
|
|
77
|
-
},
|
|
78
|
-
],
|
|
79
|
-
},
|
|
80
|
-
...props,
|
|
81
|
-
});
|
|
82
|
-
|
|
83
|
-
await flushPromises();
|
|
84
|
-
return grid;
|
|
85
|
-
};
|
|
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
|
-
|
|
98
47
|
describe('TekGrid', () => {
|
|
99
48
|
beforeEach(() => {
|
|
100
49
|
// clear all metadata instances before testing
|
|
@@ -311,34 +260,6 @@ describe('TekGrid', () => {
|
|
|
311
260
|
spy.mockReset();
|
|
312
261
|
});
|
|
313
262
|
|
|
314
|
-
it('when reportLabelFormatter is defined, it should be passed to getReport', async () => {
|
|
315
|
-
(window as any).open = jest.fn();
|
|
316
|
-
const reportLabelFormatter = jest.fn();
|
|
317
|
-
const spy = jest.spyOn(Report.prototype, 'getReport').mockImplementationOnce(async () => '');
|
|
318
|
-
|
|
319
|
-
const instance = new TekGrid({
|
|
320
|
-
reportLabelFormatter,
|
|
321
|
-
name: 'grid',
|
|
322
|
-
component: 'TekGrid',
|
|
323
|
-
columns: [
|
|
324
|
-
{
|
|
325
|
-
name: 'id',
|
|
326
|
-
label: 'ID',
|
|
327
|
-
aggregation: 'COUNT',
|
|
328
|
-
},
|
|
329
|
-
{
|
|
330
|
-
name: 'department_id',
|
|
331
|
-
label: 'Department ID',
|
|
332
|
-
grouped: true,
|
|
333
|
-
},
|
|
334
|
-
],
|
|
335
|
-
});
|
|
336
|
-
|
|
337
|
-
await instance.getReport('pdf');
|
|
338
|
-
|
|
339
|
-
expect(spy).toHaveBeenLastCalledWith('pdf', undefined, expect.any(Object), undefined, reportLabelFormatter);
|
|
340
|
-
});
|
|
341
|
-
|
|
342
263
|
it('when called with a dynamicFilter, should format the filter values', async () => {
|
|
343
264
|
(window as any).open = jest.fn();
|
|
344
265
|
const spy = jest.spyOn(Report.prototype, 'getReport').mockImplementationOnce(async () => '');
|
|
@@ -427,7 +348,7 @@ describe('TekGrid', () => {
|
|
|
427
348
|
metaData: expect.objectContaining({
|
|
428
349
|
filter,
|
|
429
350
|
}),
|
|
430
|
-
}), undefined
|
|
351
|
+
}), undefined);
|
|
431
352
|
(window as any).open.mockClear();
|
|
432
353
|
spy.mockReset();
|
|
433
354
|
});
|
|
@@ -493,7 +414,7 @@ describe('TekGrid', () => {
|
|
|
493
414
|
metaData: {
|
|
494
415
|
columns: {}, filter: undefined, groups: [], xlsDefaultType: undefined,
|
|
495
416
|
},
|
|
496
|
-
}, undefined
|
|
417
|
+
}, undefined);
|
|
497
418
|
});
|
|
498
419
|
|
|
499
420
|
it('when data is empty, should show alert', async () => {
|
|
@@ -539,7 +460,7 @@ describe('TekGrid', () => {
|
|
|
539
460
|
instance.onCreated();
|
|
540
461
|
const toolbarDiv = instance.toolbarSlot[2];
|
|
541
462
|
if (toolbarDiv.children) {
|
|
542
|
-
const button = new Button(toolbarDiv.children[
|
|
463
|
+
const button = new Button(toolbarDiv.children[1]);
|
|
543
464
|
const event = new Event('click');
|
|
544
465
|
button.click(event, {} as HTMLElement);
|
|
545
466
|
expect(spy).toBeCalled();
|
|
@@ -563,7 +484,7 @@ describe('TekGrid', () => {
|
|
|
563
484
|
instance.onCreated();
|
|
564
485
|
const toolbarDiv = instance.toolbarSlot[2];
|
|
565
486
|
if (toolbarDiv.children) {
|
|
566
|
-
const button = new Button(toolbarDiv.children[
|
|
487
|
+
const button = new Button(toolbarDiv.children[1]);
|
|
567
488
|
const event = new Event('click');
|
|
568
489
|
button.click(event, {} as HTMLElement);
|
|
569
490
|
expect(beforeSaveCalled).toBeTruthy();
|
|
@@ -587,7 +508,7 @@ describe('TekGrid', () => {
|
|
|
587
508
|
instance.onCreated();
|
|
588
509
|
const toolbarDiv = instance.toolbarSlot[2];
|
|
589
510
|
if (toolbarDiv.children) {
|
|
590
|
-
const button = new Button(toolbarDiv.children[
|
|
511
|
+
const button = new Button(toolbarDiv.children[1]);
|
|
591
512
|
button.click({ defaultPrevented: true } as Event, {} as HTMLElement);
|
|
592
513
|
expect(beforeSaveCalled).toBeTruthy();
|
|
593
514
|
expect(afterSaveCalled).toBeFalsy();
|
|
@@ -608,7 +529,7 @@ describe('TekGrid', () => {
|
|
|
608
529
|
instance.onCreated();
|
|
609
530
|
const toolbarDiv = instance.toolbarSlot[2];
|
|
610
531
|
if (toolbarDiv.children) {
|
|
611
|
-
const button = new Button(toolbarDiv.children[
|
|
532
|
+
const button = new Button(toolbarDiv.children[2]);
|
|
612
533
|
const event = new Event('click');
|
|
613
534
|
button.click(event, {} as HTMLElement);
|
|
614
535
|
expect(spy).toBeCalled();
|
|
@@ -632,7 +553,7 @@ describe('TekGrid', () => {
|
|
|
632
553
|
instance.onCreated();
|
|
633
554
|
const toolbarDiv = instance.toolbarSlot[2];
|
|
634
555
|
if (toolbarDiv.children) {
|
|
635
|
-
const button = new Button(toolbarDiv.children[
|
|
556
|
+
const button = new Button(toolbarDiv.children[2]);
|
|
636
557
|
const event = new Event('click');
|
|
637
558
|
button.click(event, {} as HTMLElement);
|
|
638
559
|
expect(beforeCancelCalled).toBeTruthy();
|
|
@@ -656,7 +577,7 @@ describe('TekGrid', () => {
|
|
|
656
577
|
instance.onCreated();
|
|
657
578
|
const toolbarDiv = instance.toolbarSlot[2];
|
|
658
579
|
if (toolbarDiv.children) {
|
|
659
|
-
const button = new Button(toolbarDiv.children[
|
|
580
|
+
const button = new Button(toolbarDiv.children[2]);
|
|
660
581
|
button.click({ defaultPrevented: true } as Event, {} as HTMLElement);
|
|
661
582
|
expect(beforeCancelCalled).toBeTruthy();
|
|
662
583
|
expect(afterCancelCalled).toBeFalsy();
|
|
@@ -701,65 +622,57 @@ describe('TekGrid', () => {
|
|
|
701
622
|
});
|
|
702
623
|
});
|
|
703
624
|
|
|
704
|
-
describe('hideButtonClick', () => {
|
|
705
|
-
it('
|
|
625
|
+
describe('hideButtonClick()', () => {
|
|
626
|
+
it('should hide toolbar', () => {
|
|
706
627
|
const instance = new TekGrid({
|
|
707
|
-
name: '
|
|
628
|
+
name: 'grid_deleteClick2',
|
|
708
629
|
component: 'TekGrid',
|
|
709
630
|
});
|
|
710
|
-
instance.onCreated();
|
|
711
631
|
|
|
712
|
-
|
|
713
|
-
const mockIcon = { cssClass: '' };
|
|
714
|
-
const mockTooltip = { label: 'TEKGRID_HIDE' };
|
|
632
|
+
instance.onCreated();
|
|
715
633
|
|
|
716
|
-
|
|
717
|
-
|
|
718
|
-
if (name.includes('_hideButton')) return mockIcon;
|
|
719
|
-
if (name.includes('_hideTooltip')) return mockTooltip;
|
|
720
|
-
return null;
|
|
721
|
-
});
|
|
634
|
+
const toolbarMock = { isVisible: true };
|
|
635
|
+
jest.spyOn(Metadata, 'getInstance').mockImplementation(() => toolbarMock);
|
|
722
636
|
|
|
723
637
|
const hideTooltip = instance.toolbarSlot[1];
|
|
724
|
-
|
|
725
|
-
const button = new Button(hideButtonDef);
|
|
726
|
-
const event = new Event('click');
|
|
638
|
+
expect(toolbarMock.isVisible).toBeTruthy();
|
|
727
639
|
|
|
728
|
-
|
|
640
|
+
if (hideTooltip.children) {
|
|
641
|
+
const hideButton = hideTooltip.children[0];
|
|
642
|
+
const button = new Button(hideButton);
|
|
643
|
+
const event = new Event('click');
|
|
644
|
+
button.click(event, {} as HTMLElement);
|
|
729
645
|
|
|
730
|
-
|
|
731
|
-
|
|
732
|
-
expect(mockTooltip.label).toBe('TEKGRID_SHOW');
|
|
646
|
+
expect(toolbarMock.isVisible).toBeFalsy();
|
|
647
|
+
}
|
|
733
648
|
});
|
|
734
649
|
|
|
735
|
-
it('
|
|
650
|
+
it('should show toolbar', () => {
|
|
736
651
|
const instance = new TekGrid({
|
|
737
|
-
name: '
|
|
652
|
+
name: 'grid_deleteClick2',
|
|
738
653
|
component: 'TekGrid',
|
|
654
|
+
toolbarOpened: false,
|
|
739
655
|
});
|
|
740
|
-
instance.onCreated();
|
|
741
656
|
|
|
742
|
-
|
|
743
|
-
const mockIcon = { cssClass: 'is-rotated' };
|
|
744
|
-
const mockTooltip = { label: 'TEKGRID_SHOW' };
|
|
657
|
+
instance.onCreated();
|
|
745
658
|
|
|
746
|
-
|
|
747
|
-
|
|
748
|
-
if (name.includes('_hideButton')) return mockIcon;
|
|
749
|
-
if (name.includes('_hideTooltip')) return mockTooltip;
|
|
750
|
-
return null;
|
|
751
|
-
});
|
|
659
|
+
const toolbarMock = { isVisible: true };
|
|
660
|
+
jest.spyOn(Metadata, 'getInstance').mockImplementation(() => toolbarMock);
|
|
752
661
|
|
|
753
662
|
const hideTooltip = instance.toolbarSlot[1];
|
|
754
|
-
const hideButtonDef = hideTooltip.children![0];
|
|
755
|
-
const button = new Button(hideButtonDef);
|
|
756
|
-
const event = new Event('click');
|
|
757
663
|
|
|
758
|
-
|
|
664
|
+
if (hideTooltip.children) {
|
|
665
|
+
const hideButton = hideTooltip.children[0];
|
|
666
|
+
const button = new Button(hideButton);
|
|
667
|
+
const event = new Event('click');
|
|
668
|
+
button.click(event, {} as HTMLElement);
|
|
669
|
+
|
|
670
|
+
expect(toolbarMock.isVisible).toBeFalsy();
|
|
671
|
+
|
|
672
|
+
button.click(event, {} as HTMLElement);
|
|
759
673
|
|
|
760
|
-
|
|
761
|
-
|
|
762
|
-
expect(mockTooltip.label).toBe('TEKGRID_HIDE');
|
|
674
|
+
expect(toolbarMock.isVisible).toBeTruthy();
|
|
675
|
+
}
|
|
763
676
|
});
|
|
764
677
|
});
|
|
765
678
|
|
|
@@ -2015,79 +1928,6 @@ describe('TekGrid', () => {
|
|
|
2015
1928
|
});
|
|
2016
1929
|
});
|
|
2017
1930
|
|
|
2018
|
-
describe('updateSummary()', () => {
|
|
2019
|
-
it('should update aggregation data always using the visible cell value', async () => {
|
|
2020
|
-
const instance = await createGroupedGrid({
|
|
2021
|
-
columns: [
|
|
2022
|
-
{ name: 'id' },
|
|
2023
|
-
{ name: 'name' },
|
|
2024
|
-
{ name: 'department', grouped: true },
|
|
2025
|
-
{ name: 'salary', aggregation: 'SUM' },
|
|
2026
|
-
],
|
|
2027
|
-
});
|
|
2028
|
-
|
|
2029
|
-
await flushPromises();
|
|
2030
|
-
instance.buildGroupedData();
|
|
2031
|
-
|
|
2032
|
-
let firstFooter = getNthFooter(instance, 0);
|
|
2033
|
-
let secondFooter = getNthFooter(instance, 1);
|
|
2034
|
-
let thirdFooter = getNthFooter(instance, 2);
|
|
2035
|
-
expect(firstFooter.salary).toBe(30);
|
|
2036
|
-
expect(secondFooter.salary).toBe(20);
|
|
2037
|
-
expect(thirdFooter.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
|
-
expect(firstFooter.salary).toBe(40);
|
|
2048
|
-
expect(secondFooter.salary).toBe(20);
|
|
2049
|
-
expect(thirdFooter.salary).toBe(60);
|
|
2050
|
-
});
|
|
2051
|
-
|
|
2052
|
-
it('should update aggregation data with many groups', async () => {
|
|
2053
|
-
const instance = await createGroupedGrid({
|
|
2054
|
-
columns: [
|
|
2055
|
-
{ name: 'id' },
|
|
2056
|
-
{ name: 'name' },
|
|
2057
|
-
{ name: 'month', grouped: true },
|
|
2058
|
-
{ name: 'department', grouped: true },
|
|
2059
|
-
{ name: 'salary', aggregation: 'SUM' },
|
|
2060
|
-
],
|
|
2061
|
-
});
|
|
2062
|
-
|
|
2063
|
-
await flushPromises();
|
|
2064
|
-
instance.buildGroupedData();
|
|
2065
|
-
|
|
2066
|
-
let firstFooter = getNthFooter(instance, 0);
|
|
2067
|
-
let secondFooter = getNthFooter(instance, 1);
|
|
2068
|
-
let thirdFooter = getNthFooter(instance, 2);
|
|
2069
|
-
let lastFooter = getLastFooter(instance);
|
|
2070
|
-
expect(firstFooter.salary).toBe(20);
|
|
2071
|
-
expect(secondFooter.salary).toBe(10);
|
|
2072
|
-
expect(thirdFooter.salary).toBe(30);
|
|
2073
|
-
expect(lastFooter.salary).toBe(50);
|
|
2074
|
-
|
|
2075
|
-
instance.editing = true;
|
|
2076
|
-
instance.updateCell('1', 'salary', 20);
|
|
2077
|
-
|
|
2078
|
-
instance.updateSummary();
|
|
2079
|
-
|
|
2080
|
-
firstFooter = getNthFooter(instance, 0);
|
|
2081
|
-
secondFooter = getNthFooter(instance, 1);
|
|
2082
|
-
thirdFooter = getNthFooter(instance, 2);
|
|
2083
|
-
lastFooter = getLastFooter(instance);
|
|
2084
|
-
expect(firstFooter.salary).toBe(30);
|
|
2085
|
-
expect(secondFooter.salary).toBe(10);
|
|
2086
|
-
expect(thirdFooter.salary).toBe(40);
|
|
2087
|
-
expect(lastFooter.salary).toBe(60);
|
|
2088
|
-
});
|
|
2089
|
-
});
|
|
2090
|
-
|
|
2091
1931
|
describe('setSearch()', () => {
|
|
2092
1932
|
let baseProps: ITekGrid;
|
|
2093
1933
|
let httpSpy: jest.SpyInstance;
|
|
@@ -2273,19 +2113,6 @@ describe('TekGrid', () => {
|
|
|
2273
2113
|
|
|
2274
2114
|
expect(instance.datasource.page).toBe(1);
|
|
2275
2115
|
});
|
|
2276
|
-
|
|
2277
|
-
it('deve retornar true se a coluna tiver filtro simples com dados (datasource comum)', () => {
|
|
2278
|
-
const column = { name: 'categoria' } as TekGridColumn;
|
|
2279
|
-
const grid = new TekGrid({ name: 'grid2', component: 'TekGrid' }) as any;
|
|
2280
|
-
|
|
2281
|
-
grid.datasource = {
|
|
2282
|
-
filter: {
|
|
2283
|
-
categoria: ['A'],
|
|
2284
|
-
},
|
|
2285
|
-
};
|
|
2286
|
-
|
|
2287
|
-
expect(grid.columnHasFilterData(column)).toBe(true);
|
|
2288
|
-
});
|
|
2289
2116
|
});
|
|
2290
2117
|
|
|
2291
2118
|
describe('rowClick', () => {
|
|
@@ -2470,6 +2297,7 @@ describe('TekGrid', () => {
|
|
|
2470
2297
|
row: grid.groupedData[0],
|
|
2471
2298
|
component: grid,
|
|
2472
2299
|
});
|
|
2300
|
+
expect(grid.datasource.currentRow).toEqual({});
|
|
2473
2301
|
});
|
|
2474
2302
|
|
|
2475
2303
|
it('should not call events.groupRowClick if cellClick prevents it', async () => {
|
|
@@ -2544,6 +2372,7 @@ describe('TekGrid', () => {
|
|
|
2544
2372
|
row: grid.groupedData[0],
|
|
2545
2373
|
component: grid,
|
|
2546
2374
|
});
|
|
2375
|
+
expect(grid.datasource.currentRow).toEqual({});
|
|
2547
2376
|
});
|
|
2548
2377
|
|
|
2549
2378
|
it('should not call events.groupRowDoubleClick if cellDoubleClick prevents it', async () => {
|
|
@@ -2869,509 +2698,4 @@ describe('TekGrid', () => {
|
|
|
2869
2698
|
expect(spy).toHaveBeenCalledTimes(1);
|
|
2870
2699
|
});
|
|
2871
2700
|
});
|
|
2872
|
-
|
|
2873
|
-
describe('addNewRow', () => {
|
|
2874
|
-
it('when not using groups, should add a new row to the datasource', async () => {
|
|
2875
|
-
const instance = new TekGrid({
|
|
2876
|
-
name: 'Grid',
|
|
2877
|
-
component: 'TekGrid',
|
|
2878
|
-
datasource: {
|
|
2879
|
-
page: 1,
|
|
2880
|
-
data: [
|
|
2881
|
-
{ id: 1 },
|
|
2882
|
-
],
|
|
2883
|
-
},
|
|
2884
|
-
});
|
|
2885
|
-
await instance.datasource.get();
|
|
2886
|
-
const newRow1 = { id: 2 };
|
|
2887
|
-
await instance.addNewRow(newRow1, 'start');
|
|
2888
|
-
expect(instance.datasource.data[0]).toMatchObject({ id: 2, __added_row: true });
|
|
2889
|
-
expect(instance.datasource.data[1]).toMatchObject({ id: 1 });
|
|
2890
|
-
});
|
|
2891
|
-
|
|
2892
|
-
it('should add a new row to the groupedData array', async () => {
|
|
2893
|
-
const grid = await createGroupedGrid();
|
|
2894
|
-
|
|
2895
|
-
expect(grid.groupedData).toMatchObject([
|
|
2896
|
-
{ groupValue: 1 },
|
|
2897
|
-
{ id: '1', groupHeaders: [{ groupValue: 1 }] },
|
|
2898
|
-
{ id: '2', groupHeaders: [{ groupValue: 1 }] },
|
|
2899
|
-
{ id: '4', groupHeaders: [{ groupValue: 1 }] },
|
|
2900
|
-
{ groupValue: 2 },
|
|
2901
|
-
{ id: '3', groupHeaders: [{ groupValue: 2 }] },
|
|
2902
|
-
{ id: '5', groupHeaders: [{ groupValue: 2 }] },
|
|
2903
|
-
]);
|
|
2904
|
-
expect(grid.groupedData[0].children).toMatchObject([
|
|
2905
|
-
{ id: '1' },
|
|
2906
|
-
{ id: '2' },
|
|
2907
|
-
{ id: '4' },
|
|
2908
|
-
]);
|
|
2909
|
-
|
|
2910
|
-
await grid.addNewRow({ id: '999', name: 'new', department: 1 });
|
|
2911
|
-
|
|
2912
|
-
expect(grid.groupedData).toMatchObject([
|
|
2913
|
-
{ groupValue: 1 },
|
|
2914
|
-
{ id: '1', groupHeaders: [{ groupValue: 1 }] },
|
|
2915
|
-
{ id: '2', groupHeaders: [{ groupValue: 1 }] },
|
|
2916
|
-
{ id: '4', groupHeaders: [{ groupValue: 1 }] },
|
|
2917
|
-
{ id: '999', groupHeaders: [{ groupValue: 1 }] },
|
|
2918
|
-
{ groupValue: 2 },
|
|
2919
|
-
{ id: '3', groupHeaders: [{ groupValue: 2 }] },
|
|
2920
|
-
{ id: '5', groupHeaders: [{ groupValue: 2 }] },
|
|
2921
|
-
]);
|
|
2922
|
-
expect(grid.groupedData[0].children).toMatchObject([
|
|
2923
|
-
{ id: '1' },
|
|
2924
|
-
{ id: '2' },
|
|
2925
|
-
{ id: '4' },
|
|
2926
|
-
{ id: '999' },
|
|
2927
|
-
]);
|
|
2928
|
-
});
|
|
2929
|
-
|
|
2930
|
-
it('should add a new row to the groupedData array using nested groups', async () => {
|
|
2931
|
-
const grid = await createGroupedGrid({
|
|
2932
|
-
columns: [
|
|
2933
|
-
{ name: 'id' },
|
|
2934
|
-
{ name: 'name' },
|
|
2935
|
-
{ name: 'month', grouped: true },
|
|
2936
|
-
{ name: 'department', grouped: true },
|
|
2937
|
-
],
|
|
2938
|
-
});
|
|
2939
|
-
|
|
2940
|
-
expect(grid.groupedData).toMatchObject([
|
|
2941
|
-
{ groupValue: 11 },
|
|
2942
|
-
{ groupValue: 1, groupHeaders: [{ groupValue: 11 }] },
|
|
2943
|
-
{ id: '1', groupHeaders: [{ groupValue: 11 }, { groupValue: 1 }] },
|
|
2944
|
-
{ id: '2', groupHeaders: [{ groupValue: 11 }, { groupValue: 1 }] },
|
|
2945
|
-
{ groupValue: 2, groupHeaders: [{ groupValue: 11 }] },
|
|
2946
|
-
{ id: '3', groupHeaders: [{ groupValue: 11 }, { groupValue: 2 }] },
|
|
2947
|
-
{ groupValue: 12 },
|
|
2948
|
-
{ groupValue: 1, groupHeaders: [{ groupValue: 12 }] },
|
|
2949
|
-
{ id: '4', groupHeaders: [{ groupValue: 12 }, { groupValue: 1 }] },
|
|
2950
|
-
{ groupValue: 2, groupHeaders: [{ groupValue: 12 }] },
|
|
2951
|
-
{ id: '5', groupHeaders: [{ groupValue: 12 }, { groupValue: 2 }] },
|
|
2952
|
-
]);
|
|
2953
|
-
|
|
2954
|
-
await grid.addNewRow({
|
|
2955
|
-
id: '999', name: 'new', month: 12, department: 1,
|
|
2956
|
-
}, 'start');
|
|
2957
|
-
|
|
2958
|
-
expect(grid.groupedData).toMatchObject([
|
|
2959
|
-
{ groupValue: 11 },
|
|
2960
|
-
{ groupValue: 1, groupHeaders: [{ groupValue: 11 }] },
|
|
2961
|
-
{ id: '1', groupHeaders: [{ groupValue: 11 }, { groupValue: 1 }] },
|
|
2962
|
-
{ id: '2', groupHeaders: [{ groupValue: 11 }, { groupValue: 1 }] },
|
|
2963
|
-
{ groupValue: 2, groupHeaders: [{ groupValue: 11 }] },
|
|
2964
|
-
{ id: '3', groupHeaders: [{ groupValue: 11 }, { groupValue: 2 }] },
|
|
2965
|
-
{ groupValue: 12 },
|
|
2966
|
-
{ groupValue: 1, groupHeaders: [{ groupValue: 12 }] },
|
|
2967
|
-
{ id: '999', groupHeaders: [{ groupValue: 12 }, { groupValue: 1 }] },
|
|
2968
|
-
{ id: '4', groupHeaders: [{ groupValue: 12 }, { groupValue: 1 }] },
|
|
2969
|
-
{ groupValue: 2, groupHeaders: [{ groupValue: 12 }] },
|
|
2970
|
-
{ id: '5', groupHeaders: [{ groupValue: 12 }, { groupValue: 2 }] },
|
|
2971
|
-
]);
|
|
2972
|
-
|
|
2973
|
-
expect(grid.groupedData[6].children).toMatchObject([
|
|
2974
|
-
{ id: '999' },
|
|
2975
|
-
{ id: '4' },
|
|
2976
|
-
{ id: '5' },
|
|
2977
|
-
]);
|
|
2978
|
-
expect(grid.groupedData[7].children).toMatchObject([
|
|
2979
|
-
{ id: '999' },
|
|
2980
|
-
{ id: '4' },
|
|
2981
|
-
]);
|
|
2982
|
-
});
|
|
2983
|
-
|
|
2984
|
-
it('should add a new row to a group that doesnt exist', async () => {
|
|
2985
|
-
const grid = await createGroupedGrid();
|
|
2986
|
-
|
|
2987
|
-
await grid.addNewRow({ id: '999', name: 'new', department: 999 }, 'end');
|
|
2988
|
-
|
|
2989
|
-
expect(grid.groupedData).toMatchObject([
|
|
2990
|
-
{ groupValue: 1 },
|
|
2991
|
-
{ id: '1', groupHeaders: [{ groupValue: 1 }] },
|
|
2992
|
-
{ id: '2', groupHeaders: [{ groupValue: 1 }] },
|
|
2993
|
-
{ id: '4', groupHeaders: [{ groupValue: 1 }] },
|
|
2994
|
-
{ groupValue: 2 },
|
|
2995
|
-
{ id: '3', groupHeaders: [{ groupValue: 2 }] },
|
|
2996
|
-
{ id: '5', groupHeaders: [{ groupValue: 2 }] },
|
|
2997
|
-
{ groupValue: 999 },
|
|
2998
|
-
{ id: '999', groupHeaders: [{ groupValue: 999 }] },
|
|
2999
|
-
]);
|
|
3000
|
-
});
|
|
3001
|
-
|
|
3002
|
-
it('should add a new row to a group that doesnt exist using nested groups', async () => {
|
|
3003
|
-
const grid = await createGroupedGrid({
|
|
3004
|
-
columns: [
|
|
3005
|
-
{ name: 'id' },
|
|
3006
|
-
{ name: 'name' },
|
|
3007
|
-
{ name: 'month', grouped: true },
|
|
3008
|
-
{ name: 'department', grouped: true },
|
|
3009
|
-
],
|
|
3010
|
-
});
|
|
3011
|
-
|
|
3012
|
-
await grid.addNewRow({
|
|
3013
|
-
id: '999', name: 'new', month: 999, department: 1,
|
|
3014
|
-
}, 'end');
|
|
3015
|
-
|
|
3016
|
-
expect(grid.groupedData).toMatchObject([
|
|
3017
|
-
{ groupValue: 11 },
|
|
3018
|
-
{ groupValue: 1, groupHeaders: [{ groupValue: 11 }] },
|
|
3019
|
-
{ id: '1', groupHeaders: [{ groupValue: 11 }, { groupValue: 1 }] },
|
|
3020
|
-
{ id: '2', groupHeaders: [{ groupValue: 11 }, { groupValue: 1 }] },
|
|
3021
|
-
{ groupValue: 2, groupHeaders: [{ groupValue: 11 }] },
|
|
3022
|
-
{ id: '3', groupHeaders: [{ groupValue: 11 }, { groupValue: 2 }] },
|
|
3023
|
-
{ groupValue: 12 },
|
|
3024
|
-
{ groupValue: 1, groupHeaders: [{ groupValue: 12 }] },
|
|
3025
|
-
{ id: '4', groupHeaders: [{ groupValue: 12 }, { groupValue: 1 }] },
|
|
3026
|
-
{ groupValue: 2, groupHeaders: [{ groupValue: 12 }] },
|
|
3027
|
-
{ id: '5', groupHeaders: [{ groupValue: 12 }, { groupValue: 2 }] },
|
|
3028
|
-
// new group
|
|
3029
|
-
{ groupValue: 999 },
|
|
3030
|
-
{ groupValue: 1, groupHeaders: [{ groupValue: 999 }] },
|
|
3031
|
-
{ id: '999', groupHeaders: [{ groupValue: 999 }, { groupValue: 1 }] },
|
|
3032
|
-
]);
|
|
3033
|
-
});
|
|
3034
|
-
|
|
3035
|
-
it('should add a new row to a group that doesnt inside a group that exists', async () => {
|
|
3036
|
-
const grid = await createGroupedGrid({
|
|
3037
|
-
columns: [
|
|
3038
|
-
{ name: 'id' },
|
|
3039
|
-
{ name: 'name' },
|
|
3040
|
-
{ name: 'month', grouped: true },
|
|
3041
|
-
{ name: 'department', grouped: true },
|
|
3042
|
-
],
|
|
3043
|
-
});
|
|
3044
|
-
|
|
3045
|
-
await grid.addNewRow({
|
|
3046
|
-
id: '999', name: 'new', month: 11, department: 999,
|
|
3047
|
-
}, 'end');
|
|
3048
|
-
|
|
3049
|
-
expect(grid.groupedData).toMatchObject([
|
|
3050
|
-
{ groupValue: 11 },
|
|
3051
|
-
{ groupValue: 999, groupHeaders: [{ groupValue: 11 }] },
|
|
3052
|
-
{ id: '999', groupHeaders: [{ groupValue: 11 }, { groupValue: 999 }] },
|
|
3053
|
-
{ groupValue: 1, groupHeaders: [{ groupValue: 11 }] },
|
|
3054
|
-
{ id: '1', groupHeaders: [{ groupValue: 11 }, { groupValue: 1 }] },
|
|
3055
|
-
{ id: '2', groupHeaders: [{ groupValue: 11 }, { groupValue: 1 }] },
|
|
3056
|
-
{ groupValue: 2, groupHeaders: [{ groupValue: 11 }] },
|
|
3057
|
-
{ id: '3', groupHeaders: [{ groupValue: 11 }, { groupValue: 2 }] },
|
|
3058
|
-
{ groupValue: 12 },
|
|
3059
|
-
{ groupValue: 1, groupHeaders: [{ groupValue: 12 }] },
|
|
3060
|
-
{ id: '4', groupHeaders: [{ groupValue: 12 }, { groupValue: 1 }] },
|
|
3061
|
-
{ groupValue: 2, groupHeaders: [{ groupValue: 12 }] },
|
|
3062
|
-
{ id: '5', groupHeaders: [{ groupValue: 12 }, { groupValue: 2 }] },
|
|
3063
|
-
]);
|
|
3064
|
-
});
|
|
3065
|
-
|
|
3066
|
-
it('should add a new row inside nested groups that doesnt exist', async () => {
|
|
3067
|
-
const grid = await createGroupedGrid({
|
|
3068
|
-
columns: [
|
|
3069
|
-
{ name: 'id' },
|
|
3070
|
-
{ name: 'name' },
|
|
3071
|
-
{ name: 'year', grouped: true },
|
|
3072
|
-
{ name: 'month', grouped: true },
|
|
3073
|
-
{ name: 'department', grouped: true },
|
|
3074
|
-
],
|
|
3075
|
-
datasource: {
|
|
3076
|
-
uniqueKey: 'id',
|
|
3077
|
-
data: [
|
|
3078
|
-
{
|
|
3079
|
-
id: '1', name: 'First', year: 2000, month: 11, department: 1,
|
|
3080
|
-
},
|
|
3081
|
-
{
|
|
3082
|
-
id: '2', name: 'Second', year: 2000, month: 11, department: 1,
|
|
3083
|
-
},
|
|
3084
|
-
{
|
|
3085
|
-
id: '3', name: 'Third', year: 2000, month: 11, department: 2,
|
|
3086
|
-
},
|
|
3087
|
-
{
|
|
3088
|
-
id: '4', name: 'Fourth', year: 2010, month: 11, department: 1,
|
|
3089
|
-
},
|
|
3090
|
-
{
|
|
3091
|
-
id: '5', name: 'Fifth', year: 2010, month: 12, department: 2,
|
|
3092
|
-
},
|
|
3093
|
-
],
|
|
3094
|
-
},
|
|
3095
|
-
});
|
|
3096
|
-
|
|
3097
|
-
await grid.addNewRow({
|
|
3098
|
-
id: '999', name: 'new', year: 2010, month: 999, department: 999,
|
|
3099
|
-
}, 'end');
|
|
3100
|
-
await grid.addNewRow({
|
|
3101
|
-
id: '998', name: 'new', year: 2010, month: 999, department: 999,
|
|
3102
|
-
}, 'end');
|
|
3103
|
-
|
|
3104
|
-
expect(grid.groupedData).toMatchObject([
|
|
3105
|
-
{ groupValue: 2000 },
|
|
3106
|
-
{ groupValue: 11, groupHeaders: [{ groupValue: 2000 }] },
|
|
3107
|
-
{ groupValue: 1, groupHeaders: [{ groupValue: 2000 }, { groupValue: 11 }] },
|
|
3108
|
-
{ id: '1', groupHeaders: [{ groupValue: 2000 }, { groupValue: 11 }, { groupValue: 1 }] },
|
|
3109
|
-
{ id: '2', groupHeaders: [{ groupValue: 2000 }, { groupValue: 11 }, { groupValue: 1 }] },
|
|
3110
|
-
{ groupValue: 2, groupHeaders: [{ groupValue: 2000 }, { groupValue: 11 }] },
|
|
3111
|
-
{ id: '3', groupHeaders: [{ groupValue: 2000 }, { groupValue: 11 }, { groupValue: 2 }] },
|
|
3112
|
-
{ groupValue: 2010 },
|
|
3113
|
-
{ groupValue: 999, groupHeaders: [{ groupValue: 2010 }] },
|
|
3114
|
-
{ groupValue: 999, groupHeaders: [{ groupValue: 2010 }, { groupValue: 999 }] },
|
|
3115
|
-
{ id: '999', groupHeaders: [{ groupValue: 2010 }, { groupValue: 999 }, { groupValue: 999 }] },
|
|
3116
|
-
{ id: '998', groupHeaders: [{ groupValue: 2010 }, { groupValue: 999 }, { groupValue: 999 }] },
|
|
3117
|
-
{ groupValue: 11, groupHeaders: [{ groupValue: 2010 }] },
|
|
3118
|
-
{ groupValue: 1, groupHeaders: [{ groupValue: 2010 }, { groupValue: 11 }] },
|
|
3119
|
-
{ id: '4', groupHeaders: [{ groupValue: 2010 }, { groupValue: 11 }, { groupValue: 1 }] },
|
|
3120
|
-
{ groupValue: 12, groupHeaders: [{ groupValue: 2010 }] },
|
|
3121
|
-
{ groupValue: 2, groupHeaders: [{ groupValue: 2010 }, { groupValue: 12 }] },
|
|
3122
|
-
{ id: '5', groupHeaders: [{ groupValue: 2010 }, { groupValue: 12 }, { groupValue: 2 }] },
|
|
3123
|
-
]);
|
|
3124
|
-
});
|
|
3125
|
-
|
|
3126
|
-
it('should throw an error when row groups are not defined or incomplete', async () => {
|
|
3127
|
-
const grid = await createGroupedGrid({
|
|
3128
|
-
columns: [
|
|
3129
|
-
{ name: 'id' },
|
|
3130
|
-
{ name: 'name' },
|
|
3131
|
-
{ name: 'month', grouped: true },
|
|
3132
|
-
{ name: 'department', grouped: true },
|
|
3133
|
-
],
|
|
3134
|
-
});
|
|
3135
|
-
|
|
3136
|
-
// month group is undefined, should throw
|
|
3137
|
-
expect(async () => grid.addNewRow({ id: '999', name: 'new', department: 1 }, 'end')).rejects.toThrow();
|
|
3138
|
-
});
|
|
3139
|
-
});
|
|
3140
|
-
|
|
3141
|
-
describe('addToSelection', () => {
|
|
3142
|
-
it('should add a row to the selected group', async () => {
|
|
3143
|
-
const grid = await createGroupedGrid();
|
|
3144
|
-
|
|
3145
|
-
[grid.datasource.currentRow] = grid.groupedData;
|
|
3146
|
-
|
|
3147
|
-
grid.addToSelection({ id: '999', name: 'new', month: 12 });
|
|
3148
|
-
|
|
3149
|
-
expect(grid.groupedData).toMatchObject([
|
|
3150
|
-
{ groupValue: 1 },
|
|
3151
|
-
{ id: '1', groupHeaders: [{ groupValue: 1 }] },
|
|
3152
|
-
{ id: '2', groupHeaders: [{ groupValue: 1 }] },
|
|
3153
|
-
{ id: '4', groupHeaders: [{ groupValue: 1 }] },
|
|
3154
|
-
{ id: '999', groupHeaders: [{ groupValue: 1 }] },
|
|
3155
|
-
{ groupValue: 2 },
|
|
3156
|
-
{ id: '3', groupHeaders: [{ groupValue: 2 }] },
|
|
3157
|
-
{ id: '5', groupHeaders: [{ groupValue: 2 }] },
|
|
3158
|
-
]);
|
|
3159
|
-
});
|
|
3160
|
-
|
|
3161
|
-
it('should add a row to the selected group when using nested groups', async () => {
|
|
3162
|
-
const grid = await createGroupedGrid();
|
|
3163
|
-
|
|
3164
|
-
[grid.datasource.currentRow] = grid.groupedData;
|
|
3165
|
-
|
|
3166
|
-
grid.addToSelection({ id: '999', name: 'new', month: 12 });
|
|
3167
|
-
|
|
3168
|
-
expect(grid.groupedData).toMatchObject([
|
|
3169
|
-
{ groupValue: 1 },
|
|
3170
|
-
{ id: '1', groupHeaders: [{ groupValue: 1 }] },
|
|
3171
|
-
{ id: '2', groupHeaders: [{ groupValue: 1 }] },
|
|
3172
|
-
{ id: '4', groupHeaders: [{ groupValue: 1 }] },
|
|
3173
|
-
{ id: '999', groupHeaders: [{ groupValue: 1 }] },
|
|
3174
|
-
{ groupValue: 2 },
|
|
3175
|
-
{ id: '3', groupHeaders: [{ groupValue: 2 }] },
|
|
3176
|
-
{ id: '5', groupHeaders: [{ groupValue: 2 }] },
|
|
3177
|
-
]);
|
|
3178
|
-
});
|
|
3179
|
-
|
|
3180
|
-
it('when selected row is not a group, should add a row to the same group as the selected row', async () => {
|
|
3181
|
-
const grid = await createGroupedGrid({
|
|
3182
|
-
columns: [
|
|
3183
|
-
{ name: 'id' },
|
|
3184
|
-
{ name: 'name' },
|
|
3185
|
-
{ name: 'month', grouped: true },
|
|
3186
|
-
{ name: 'department', grouped: true },
|
|
3187
|
-
],
|
|
3188
|
-
});
|
|
3189
|
-
|
|
3190
|
-
grid.datasource.currentRow = grid.groupedData.find((row) => row.id === '3')!;
|
|
3191
|
-
|
|
3192
|
-
grid.addToSelection({ id: '999', name: 'new', month: 12 });
|
|
3193
|
-
|
|
3194
|
-
expect(grid.groupedData).toMatchObject([
|
|
3195
|
-
{ groupValue: 11 },
|
|
3196
|
-
{ groupValue: 1, groupHeaders: [{ groupValue: 11 }] },
|
|
3197
|
-
{ id: '1', groupHeaders: [{ groupValue: 11 }, { groupValue: 1 }] },
|
|
3198
|
-
{ id: '2', groupHeaders: [{ groupValue: 11 }, { groupValue: 1 }] },
|
|
3199
|
-
{ groupValue: 2, groupHeaders: [{ groupValue: 11 }] },
|
|
3200
|
-
{ id: '3', groupHeaders: [{ groupValue: 11 }, { groupValue: 2 }] },
|
|
3201
|
-
{ id: '999', groupHeaders: [{ groupValue: 11 }, { groupValue: 2 }] },
|
|
3202
|
-
{ groupValue: 12 },
|
|
3203
|
-
{ groupValue: 1, groupHeaders: [{ groupValue: 12 }] },
|
|
3204
|
-
{ id: '4', groupHeaders: [{ groupValue: 12 }, { groupValue: 1 }] },
|
|
3205
|
-
{ groupValue: 2, groupHeaders: [{ groupValue: 12 }] },
|
|
3206
|
-
{ id: '5', groupHeaders: [{ groupValue: 12 }, { groupValue: 2 }] },
|
|
3207
|
-
]);
|
|
3208
|
-
});
|
|
3209
|
-
|
|
3210
|
-
it('when selected row is not the most internal group, should add a row to the first most internal group', async () => {
|
|
3211
|
-
const grid = await createGroupedGrid({
|
|
3212
|
-
columns: [
|
|
3213
|
-
{ name: 'id' },
|
|
3214
|
-
{ name: 'name' },
|
|
3215
|
-
{ name: 'month', grouped: true },
|
|
3216
|
-
{ name: 'department', grouped: true },
|
|
3217
|
-
],
|
|
3218
|
-
});
|
|
3219
|
-
|
|
3220
|
-
[grid.datasource.currentRow] = grid.groupedData;
|
|
3221
|
-
|
|
3222
|
-
grid.addToSelection({ id: '999', name: 'new', month: 12 });
|
|
3223
|
-
|
|
3224
|
-
expect(grid.groupedData).toMatchObject([
|
|
3225
|
-
{ groupValue: 11 },
|
|
3226
|
-
{ groupValue: 1, groupHeaders: [{ groupValue: 11 }] },
|
|
3227
|
-
{ id: '1', groupHeaders: [{ groupValue: 11 }, { groupValue: 1 }] },
|
|
3228
|
-
{ id: '2', groupHeaders: [{ groupValue: 11 }, { groupValue: 1 }] },
|
|
3229
|
-
{ id: '999', groupHeaders: [{ groupValue: 11 }, { groupValue: 1 }] },
|
|
3230
|
-
{ groupValue: 2, groupHeaders: [{ groupValue: 11 }] },
|
|
3231
|
-
{ id: '3', groupHeaders: [{ groupValue: 11 }, { groupValue: 2 }] },
|
|
3232
|
-
{ groupValue: 12 },
|
|
3233
|
-
{ groupValue: 1, groupHeaders: [{ groupValue: 12 }] },
|
|
3234
|
-
{ id: '4', groupHeaders: [{ groupValue: 12 }, { groupValue: 1 }] },
|
|
3235
|
-
{ groupValue: 2, groupHeaders: [{ groupValue: 12 }] },
|
|
3236
|
-
{ id: '5', groupHeaders: [{ groupValue: 12 }, { groupValue: 2 }] },
|
|
3237
|
-
]);
|
|
3238
|
-
});
|
|
3239
|
-
});
|
|
3240
|
-
|
|
3241
|
-
describe('toolbar creation', () => {
|
|
3242
|
-
it('should render predefined items in toolbarConfig', () => {
|
|
3243
|
-
const grid = new TekGrid({
|
|
3244
|
-
name: 'grid',
|
|
3245
|
-
component: 'TekGrid',
|
|
3246
|
-
toolbarConfig: ['addButton'],
|
|
3247
|
-
});
|
|
3248
|
-
grid.onCreated();
|
|
3249
|
-
|
|
3250
|
-
expect(grid.toolbarSlot.length).toBe(3);
|
|
3251
|
-
const toolbarDiv = grid.toolbarSlot[2];
|
|
3252
|
-
expect(toolbarDiv.children?.length).toBe(1);
|
|
3253
|
-
expect(toolbarDiv.children?.[0].name).toContain('_add_tooltip');
|
|
3254
|
-
});
|
|
3255
|
-
|
|
3256
|
-
it('should render custom components in toolbarConfig', () => {
|
|
3257
|
-
const grid = new TekGrid({
|
|
3258
|
-
name: 'grid',
|
|
3259
|
-
component: 'TekGrid',
|
|
3260
|
-
toolbarConfig: [{ component: 'ZdButton', name: 'customButton' }],
|
|
3261
|
-
});
|
|
3262
|
-
grid.onCreated();
|
|
3263
|
-
|
|
3264
|
-
const toolbarDiv = grid.toolbarSlot[2];
|
|
3265
|
-
expect(toolbarDiv.children?.length).toBe(1);
|
|
3266
|
-
expect(toolbarDiv.children?.[0].name).toBe('customButton');
|
|
3267
|
-
});
|
|
3268
|
-
|
|
3269
|
-
it('should alert about invalid items of string type in toolbarConfig', () => {
|
|
3270
|
-
const warnSpy = jest.spyOn(console, 'warn').mockImplementation(() => {});
|
|
3271
|
-
const grid = new TekGrid({
|
|
3272
|
-
name: 'grid',
|
|
3273
|
-
component: 'TekGrid',
|
|
3274
|
-
toolbarConfig: ['invalidItem'],
|
|
3275
|
-
});
|
|
3276
|
-
grid.onCreated();
|
|
3277
|
-
|
|
3278
|
-
expect(warnSpy).toHaveBeenCalledWith('Predefined toolbar item "invalidItem" not found.');
|
|
3279
|
-
warnSpy.mockRestore();
|
|
3280
|
-
});
|
|
3281
|
-
|
|
3282
|
-
it('should alert about invalid items in toolbarConfig', () => {
|
|
3283
|
-
const warnSpy = jest.spyOn(console, 'warn').mockImplementation(() => {});
|
|
3284
|
-
const grid = new TekGrid({
|
|
3285
|
-
name: 'grid',
|
|
3286
|
-
component: 'TekGrid',
|
|
3287
|
-
toolbarConfig: [123 as any],
|
|
3288
|
-
});
|
|
3289
|
-
grid.onCreated();
|
|
3290
|
-
|
|
3291
|
-
expect(warnSpy).toHaveBeenCalledWith('Invalid item in toolbarConfig:', 123);
|
|
3292
|
-
warnSpy.mockRestore();
|
|
3293
|
-
});
|
|
3294
|
-
});
|
|
3295
|
-
|
|
3296
|
-
describe('addButtonClick', () => {
|
|
3297
|
-
it('should set editingNewRows as true when editNewRowsOnly is enabled', () => {
|
|
3298
|
-
const grid = new TekGrid({
|
|
3299
|
-
name: 'grid',
|
|
3300
|
-
component: 'TekGrid',
|
|
3301
|
-
addButton: true,
|
|
3302
|
-
editNewRowsOnly: true,
|
|
3303
|
-
});
|
|
3304
|
-
|
|
3305
|
-
(grid as any).gridBase.addButtonClick({ event: new Event('click') });
|
|
3306
|
-
|
|
3307
|
-
expect((grid as any).editingNewRows).toBe(true);
|
|
3308
|
-
});
|
|
3309
|
-
});
|
|
3310
|
-
|
|
3311
|
-
describe('deleteButtonClick', () => {
|
|
3312
|
-
it('should throw TekGridDeleteRowsError when selectAllPages is true', () => {
|
|
3313
|
-
const grid = new TekGrid({
|
|
3314
|
-
name: 'grid',
|
|
3315
|
-
component: 'TekGrid',
|
|
3316
|
-
deleteButton: 'selection',
|
|
3317
|
-
selectAllPages: true,
|
|
3318
|
-
});
|
|
3319
|
-
|
|
3320
|
-
const deleteFn = () => {
|
|
3321
|
-
(grid as any).gridBase.deleteButtonClick({ event: new Event('click') });
|
|
3322
|
-
};
|
|
3323
|
-
|
|
3324
|
-
expect(deleteFn).toThrow(TekGridDeleteRowsError);
|
|
3325
|
-
});
|
|
3326
|
-
});
|
|
3327
|
-
|
|
3328
|
-
describe('reloadGrid', () => {
|
|
3329
|
-
it('should call grid.reload() if beforeReload event is not prevented', () => {
|
|
3330
|
-
const grid = new TekGrid({
|
|
3331
|
-
name: 'grid',
|
|
3332
|
-
component: 'TekGrid',
|
|
3333
|
-
});
|
|
3334
|
-
const reloadSpy = jest.spyOn(grid, 'reload');
|
|
3335
|
-
const event = new Event('click');
|
|
3336
|
-
|
|
3337
|
-
(grid as any).gridBase.reloadGrid({ event });
|
|
3338
|
-
|
|
3339
|
-
expect(reloadSpy).toHaveBeenCalledTimes(1);
|
|
3340
|
-
|
|
3341
|
-
reloadSpy.mockRestore();
|
|
3342
|
-
});
|
|
3343
|
-
|
|
3344
|
-
it('should not call grid.reload() if beforeReload event is prevented', () => {
|
|
3345
|
-
const grid = new TekGrid({
|
|
3346
|
-
name: 'grid',
|
|
3347
|
-
component: 'TekGrid',
|
|
3348
|
-
});
|
|
3349
|
-
const reloadSpy = jest.spyOn(grid, 'reload');
|
|
3350
|
-
const mockEvent = { defaultPrevented: true };
|
|
3351
|
-
|
|
3352
|
-
(grid as any).gridBase.reloadGrid({ event: mockEvent });
|
|
3353
|
-
|
|
3354
|
-
expect(reloadSpy).not.toHaveBeenCalled();
|
|
3355
|
-
|
|
3356
|
-
reloadSpy.mockRestore();
|
|
3357
|
-
});
|
|
3358
|
-
});
|
|
3359
|
-
|
|
3360
|
-
describe('toolbar creation', () => {
|
|
3361
|
-
it('should create toolbar with default items', () => {
|
|
3362
|
-
const grid = new TekGrid({
|
|
3363
|
-
name: 'grid',
|
|
3364
|
-
component: 'TekGrid',
|
|
3365
|
-
});
|
|
3366
|
-
const { gridBase } = grid as any;
|
|
3367
|
-
delete (gridBase as any).defaultToolbar.title;
|
|
3368
|
-
delete (gridBase as any).defaultToolbar.hideButton;
|
|
3369
|
-
|
|
3370
|
-
const toolbarSlot = gridBase.createToolbarProps();
|
|
3371
|
-
|
|
3372
|
-
expect(toolbarSlot.find((c: IComponentRender) => c.name?.includes('_title'))).toBeUndefined();
|
|
3373
|
-
expect(toolbarSlot.find((c: IComponentRender) => c.name?.includes('_hideTooltip'))).toBeUndefined();
|
|
3374
|
-
expect(toolbarSlot[0].name).toBe('grid_toolbarDiv');
|
|
3375
|
-
});
|
|
3376
|
-
});
|
|
3377
2701
|
});
|