@zeedhi/teknisa-components-common 1.48.0 → 1.53.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.
@@ -1,16 +1,29 @@
1
1
  /* eslint-disable no-underscore-dangle */
2
2
 
3
3
  import {
4
- Button, Date, Dropdown, Form, IButton, IForm, IModal, Modal, ModalService, Search, Text, TextInput,
4
+ Button, Date, Dropdown, Form, IButton, IForm, IModal, Modal, ModalService, Search, TextInput, Text,
5
5
  } from '@zeedhi/common';
6
6
  import {
7
- KeyMap, Http, Metadata, IDictionary, DateHelper,
7
+ KeyMap, Http, Metadata, DateHelper, IDictionary,
8
8
  } from '@zeedhi/core';
9
9
  import {
10
10
  IFilterPropsComponent,
11
11
  ITekGrid,
12
12
  TekGrid, TekGridColumn, TekRestDatasource,
13
13
  } from '../../../../src';
14
+ import { setClick, getChild } from '../../../__helpers__';
15
+
16
+ jest.mock('lodash.debounce', () => jest.fn((fn) => fn));
17
+
18
+ jest.useFakeTimers();
19
+
20
+ const clickOnFilterButton = (grid: TekGrid, event?: any) => {
21
+ const buttonProps = getChild<IButton>(grid.toolbarSlot, `${grid.name}_filterButton`);
22
+ const button = new Button(buttonProps);
23
+ setClick(button, event);
24
+
25
+ return button;
26
+ };
14
27
 
15
28
  describe('TekGrid', () => {
16
29
  beforeEach(() => {
@@ -19,6 +32,8 @@ describe('TekGrid', () => {
19
32
  Object.keys(instances).forEach((key) => {
20
33
  Metadata.clearInstance(key, instances[key].componentId);
21
34
  });
35
+
36
+ jest.clearAllTimers();
22
37
  });
23
38
 
24
39
  describe('constructor()', () => {
@@ -191,7 +206,7 @@ describe('TekGrid', () => {
191
206
  });
192
207
 
193
208
  afterEach(() => {
194
- httpReportSpy.mockClear();
209
+ httpReportSpy.mockReset();
195
210
  });
196
211
 
197
212
  it('should call getReport on export button click', () => {
@@ -212,7 +227,7 @@ describe('TekGrid', () => {
212
227
  button.click(event, {} as HTMLElement);
213
228
 
214
229
  expect(spy).toBeCalledTimes(1);
215
- spy.mockClear();
230
+ spy.mockReset();
216
231
 
217
232
  (window as any).open.mockClear();
218
233
  });
@@ -262,8 +277,8 @@ describe('TekGrid', () => {
262
277
  expect(spy).toHaveBeenCalledTimes(1);
263
278
 
264
279
  (window as any).open.mockClear();
265
- spy.mockClear();
266
- httpSpy.mockClear();
280
+ spy.mockReset();
281
+ httpSpy.mockReset();
267
282
  });
268
283
  });
269
284
 
@@ -281,7 +296,7 @@ describe('TekGrid', () => {
281
296
  button.click(event, {} as HTMLElement);
282
297
  expect(spy).toBeCalled();
283
298
  expect(button.isVisible).toBeFalsy();
284
- spy.mockClear();
299
+ spy.mockReset();
285
300
  });
286
301
 
287
302
  it('should call events', () => {
@@ -323,7 +338,7 @@ describe('TekGrid', () => {
323
338
  expect(beforeSaveCalled).toBeTruthy();
324
339
  expect(afterSaveCalled).toBeFalsy();
325
340
  expect(spy).not.toBeCalled();
326
- spy.mockClear();
341
+ spy.mockReset();
327
342
  });
328
343
  });
329
344
 
@@ -341,7 +356,7 @@ describe('TekGrid', () => {
341
356
  button.click(event, {} as HTMLElement);
342
357
  expect(spy).toBeCalled();
343
358
  expect(button.isVisible).toBeFalsy();
344
- spy.mockClear();
359
+ spy.mockReset();
345
360
  });
346
361
 
347
362
  it('should call events', () => {
@@ -383,7 +398,7 @@ describe('TekGrid', () => {
383
398
  expect(beforeCancelCalled).toBeTruthy();
384
399
  expect(afterCancelCalled).toBeFalsy();
385
400
  expect(spy).not.toBeCalled();
386
- spy.mockClear();
401
+ spy.mockReset();
387
402
  });
388
403
  });
389
404
 
@@ -440,7 +455,7 @@ describe('TekGrid', () => {
440
455
  expect(button.disabled).toBeTruthy();
441
456
  }
442
457
  }
443
- spy.mockClear();
458
+ spy.mockReset();
444
459
  });
445
460
 
446
461
  it('should call events', () => {
@@ -496,7 +511,7 @@ describe('TekGrid', () => {
496
511
  expect(spy).not.toBeCalled();
497
512
  }
498
513
  }
499
- spy.mockClear();
514
+ spy.mockReset();
500
515
  });
501
516
  });
502
517
 
@@ -509,6 +524,16 @@ describe('TekGrid', () => {
509
524
  };
510
525
 
511
526
  it('should navigate through grid lines using keys', async () => {
527
+ const httpSpy = jest.spyOn(Http, 'get').mockImplementation(() => Promise.resolve({
528
+ data: {
529
+ data: [],
530
+ pagination: {
531
+ page: 1,
532
+ total: 0,
533
+ limit: 10,
534
+ },
535
+ },
536
+ }));
512
537
  const flushPromises = () => new Promise(setImmediate);
513
538
  const instance = new TekGrid({
514
539
  name: 'grid_navigation_1',
@@ -560,9 +585,21 @@ describe('TekGrid', () => {
560
585
 
561
586
  dispatchEvent(37, {}); // arrow left
562
587
  expect(instance.datasource.currentRow).toEqual(instance.datasource.data[0]);
588
+
589
+ httpSpy.mockReset();
563
590
  });
564
591
 
565
- it('should navigate through grid lines using keys when grouped', async (done) => {
592
+ it('should navigate through grid lines using keys when grouped', async () => {
593
+ const httpSpy = jest.spyOn(Http, 'get').mockImplementation(() => Promise.resolve({
594
+ data: {
595
+ data: [],
596
+ pagination: {
597
+ page: 1,
598
+ total: 0,
599
+ limit: 10,
600
+ },
601
+ },
602
+ }));
566
603
  const flushPromises = () => new Promise(setImmediate);
567
604
  const instance = new TekGrid({
568
605
  name: 'grid_navigation_2',
@@ -597,68 +634,66 @@ describe('TekGrid', () => {
597
634
 
598
635
  await flushPromises();
599
636
 
600
- setTimeout(() => {
601
- const elem = document.createElement('DIV');
602
- (KeyMap as any).isElementActive = () => true;
603
- instance.onCreated();
604
- instance.onMounted(elem);
637
+ const elem = document.createElement('DIV');
638
+ (KeyMap as any).isElementActive = () => true;
639
+ instance.onCreated();
640
+ instance.onMounted(elem);
605
641
 
606
- dispatchEvent(40, {}); // arrow down
607
- expect(instance.datasource.currentRow).toEqual(instance.groupedData[0]);
642
+ dispatchEvent(40, {}); // arrow down
643
+ expect(instance.datasource.currentRow).toEqual(instance.groupedData[0]);
608
644
 
609
- dispatchEvent(40, {}); // arrow down
610
- expect(instance.datasource.currentRow).toEqual(instance.groupedData[4]);
645
+ dispatchEvent(40, {}); // arrow down
646
+ expect(instance.datasource.currentRow).toEqual(instance.groupedData[4]);
611
647
 
612
- dispatchEvent(40, {}); // arrow down
613
- expect(instance.datasource.currentRow).toEqual(instance.groupedData[4]);
648
+ dispatchEvent(40, {}); // arrow down
649
+ expect(instance.datasource.currentRow).toEqual(instance.groupedData[4]);
614
650
 
615
- dispatchEvent(38, {}); // arrow up
616
- expect(instance.datasource.currentRow).toEqual(instance.groupedData[0]);
651
+ dispatchEvent(38, {}); // arrow up
652
+ expect(instance.datasource.currentRow).toEqual(instance.groupedData[0]);
617
653
 
618
- dispatchEvent(38, {}); // arrow up
619
- expect(instance.datasource.currentRow).toEqual(instance.groupedData[0]);
654
+ dispatchEvent(38, {}); // arrow up
655
+ expect(instance.datasource.currentRow).toEqual(instance.groupedData[0]);
620
656
 
621
- instance.datasource.currentRow = {};
622
- dispatchEvent(38, {}); // arrow up
623
- expect(instance.datasource.currentRow).toEqual(instance.groupedData[4]);
657
+ instance.datasource.currentRow = {};
658
+ dispatchEvent(38, {}); // arrow up
659
+ expect(instance.datasource.currentRow).toEqual(instance.groupedData[4]);
624
660
 
625
- [instance.datasource.currentRow] = instance.groupedData;
626
- expect(instance.datasource.currentRow.groupOpened).toBeFalsy();
627
- dispatchEvent(39, {}); // arrow right
628
- expect(instance.datasource.currentRow.groupOpened).toBeTruthy();
661
+ [instance.datasource.currentRow] = instance.groupedData;
662
+ expect(instance.datasource.currentRow.groupOpened).toBeFalsy();
663
+ dispatchEvent(39, {}); // arrow right
664
+ expect(instance.datasource.currentRow.groupOpened).toBeTruthy();
629
665
 
630
- dispatchEvent(40, {}); // arrow down
631
- expect(instance.datasource.currentRow).toEqual(instance.groupedData[1]);
666
+ dispatchEvent(40, {}); // arrow down
667
+ expect(instance.datasource.currentRow).toEqual(instance.groupedData[1]);
632
668
 
633
- dispatchEvent(40, {}); // arrow down
634
- expect(instance.datasource.currentRow).toEqual(instance.groupedData[2]);
669
+ dispatchEvent(40, {}); // arrow down
670
+ expect(instance.datasource.currentRow).toEqual(instance.groupedData[2]);
635
671
 
636
- dispatchEvent(38, {}); // arrow up
637
- expect(instance.datasource.currentRow).toEqual(instance.groupedData[1]);
672
+ dispatchEvent(38, {}); // arrow up
673
+ expect(instance.datasource.currentRow).toEqual(instance.groupedData[1]);
638
674
 
639
- dispatchEvent(37, {}); // arrow left
640
- expect(instance.datasource.currentRow).toEqual(instance.groupedData[0]);
675
+ dispatchEvent(37, {}); // arrow left
676
+ expect(instance.datasource.currentRow).toEqual(instance.groupedData[0]);
641
677
 
642
- expect(instance.datasource.currentRow.groupOpened).toBeTruthy();
643
- dispatchEvent(37, {}); // arrow left
644
- expect(instance.datasource.currentRow.groupOpened).toBeFalsy();
678
+ expect(instance.datasource.currentRow.groupOpened).toBeTruthy();
679
+ dispatchEvent(37, {}); // arrow left
680
+ expect(instance.datasource.currentRow.groupOpened).toBeFalsy();
645
681
 
646
- [, , , , instance.datasource.currentRow] = instance.groupedData;
647
- expect(instance.datasource.currentRow.groupOpened).toBeFalsy();
648
- dispatchEvent(39, {}); // arrow right
649
- expect(instance.datasource.currentRow.groupOpened).toBeTruthy();
682
+ [, , , , instance.datasource.currentRow] = instance.groupedData;
683
+ expect(instance.datasource.currentRow.groupOpened).toBeFalsy();
684
+ dispatchEvent(39, {}); // arrow right
685
+ expect(instance.datasource.currentRow.groupOpened).toBeTruthy();
650
686
 
651
- dispatchEvent(40, {}); // arrow down
652
- expect(instance.datasource.currentRow).toEqual(instance.groupedData[5]);
687
+ dispatchEvent(40, {}); // arrow down
688
+ expect(instance.datasource.currentRow).toEqual(instance.groupedData[5]);
653
689
 
654
- dispatchEvent(40, {}); // arrow down
655
- expect(instance.datasource.currentRow).toEqual(instance.groupedData[6]);
690
+ dispatchEvent(40, {}); // arrow down
691
+ expect(instance.datasource.currentRow).toEqual(instance.groupedData[6]);
656
692
 
657
- dispatchEvent(40, {}); // arrow down
658
- expect(instance.datasource.currentRow).toEqual(instance.groupedData[6]);
693
+ dispatchEvent(40, {}); // arrow down
694
+ expect(instance.datasource.currentRow).toEqual(instance.groupedData[6]);
659
695
 
660
- done();
661
- }, 1000);
696
+ httpSpy.mockReset();
662
697
  });
663
698
 
664
699
  it('should open filter modal input with keymap', async () => {
@@ -693,7 +728,7 @@ describe('TekGrid', () => {
693
728
 
694
729
  expect(method).toHaveBeenCalled();
695
730
  (KeyMap as any).isElementActive = () => false;
696
- spyMetadata.mockClear();
731
+ spyMetadata.mockReset();
697
732
  });
698
733
 
699
734
  it('should open action dropdown with keymap', async () => {
@@ -731,8 +766,8 @@ describe('TekGrid', () => {
731
766
  await flushPromises();
732
767
 
733
768
  (KeyMap as any).isElementActive = () => false;
734
- spyMetadata.mockClear();
735
- instanceDropDownSpy.mockClear();
769
+ spyMetadata.mockReset();
770
+ instanceDropDownSpy.mockReset();
736
771
  });
737
772
 
738
773
  it('should focus in searchInput with keymap', async () => {
@@ -765,8 +800,8 @@ describe('TekGrid', () => {
765
800
  await flushPromises();
766
801
 
767
802
  (KeyMap as any).isElementActive = () => false;
768
- spySetFocus.mockClear();
769
- spyMetadata.mockClear();
803
+ spySetFocus.mockReset();
804
+ spyMetadata.mockReset();
770
805
  });
771
806
  });
772
807
 
@@ -790,12 +825,12 @@ describe('TekGrid', () => {
790
825
  expect(spy).toBeCalled();
791
826
  }
792
827
  }
793
- spy.mockClear();
828
+ spy.mockReset();
794
829
  });
795
830
  });
796
831
 
797
832
  describe('grouping', () => {
798
- it('should group data', async (done) => {
833
+ it('should group data based on columns that have grouped property', async () => {
799
834
  const flushPromises = () => new Promise(setImmediate);
800
835
  const instance = new TekGrid({
801
836
  name: 'grid_grouping_1',
@@ -830,23 +865,19 @@ describe('TekGrid', () => {
830
865
 
831
866
  await flushPromises();
832
867
 
833
- setTimeout(() => {
834
- instance.getCellWithAppliedConditions(instance.columns, instance.datasource.data[0]);
835
- expect(instance.datasource.data.length).toBe(5);
836
- expect(instance.datasource.order).toEqual(['department.asc', 'name.asc']);
837
- expect(instance.groupedData.length).toBe(7);
838
- expect(instance.groupedData[0].group).toBeTruthy();
839
- expect(instance.groupedData[0].groupLabel).toBe('department');
840
- expect(instance.groupedData[0].groupValue).toBe(1);
841
- expect(instance.groupedData[1].groupHeaders.length).toBe(1);
842
- expect(instance.groupedData[1].name).toBe('employee 1');
843
-
844
- done();
845
- }, 1000);
868
+ instance.getCellWithAppliedConditions(instance.columns, instance.datasource.data[0]);
869
+ expect(instance.datasource.data.length).toBe(5);
870
+ expect(instance.datasource.order).toEqual(['department.asc', 'name.asc']);
871
+ expect(instance.groupedData.length).toBe(7);
872
+ expect(instance.groupedData[0].group).toBeTruthy();
873
+ expect(instance.groupedData[0].groupLabel).toBe('department');
874
+ expect(instance.groupedData[0].groupValue).toBe(1);
875
+ expect(instance.groupedData[1].groupHeaders.length).toBe(1);
876
+ expect(instance.groupedData[1].name).toBe('employee 1');
846
877
  });
847
878
 
848
- it('should call debounced updateGroupData', async (done) => {
849
- const flushPromises = () => new Promise(setImmediate);
879
+ it('should call debounced updateGroupData', () => {
880
+ const spy = jest.spyOn(TekGrid.prototype, 'updateGroupedData');
850
881
  const instance = new TekGrid({
851
882
  name: 'grid_grouping_1',
852
883
  component: 'TekGrid',
@@ -877,18 +908,16 @@ describe('TekGrid', () => {
877
908
  },
878
909
  });
879
910
 
880
- await flushPromises();
911
+ jest.runAllTimers();
881
912
 
882
- instance.updateGroupedData = jest.fn();
883
913
  instance.columns[2].grouped = true;
884
914
 
885
- setTimeout(() => {
886
- expect(instance.updateGroupedData).toBeCalled();
887
- done();
888
- }, 1000);
915
+ expect(spy).toHaveBeenCalled();
916
+
917
+ spy.mockClear();
889
918
  });
890
919
 
891
- it('should group data with aggregations', async (done) => {
920
+ it('should group data with aggregations', async () => {
892
921
  const flushPromises = () => new Promise(setImmediate);
893
922
  const instance = new TekGrid({
894
923
  name: 'grid_aggregate_1',
@@ -924,26 +953,22 @@ describe('TekGrid', () => {
924
953
 
925
954
  await flushPromises();
926
955
 
927
- setTimeout(() => {
928
- instance.getCellWithAppliedConditions(instance.columns, instance.datasource.data[0]);
929
- expect(instance.datasource.data.length).toBe(5);
930
- expect(instance.datasource.order).toEqual(['department.asc', 'name.asc']);
931
- expect(instance.groupedData.length).toBe(10);
932
- expect(instance.groupedData[0].group).toBeTruthy();
933
- expect(instance.groupedData[0].groupLabel).toBe('department');
934
- expect(instance.groupedData[0].groupValue).toBe(1);
935
- expect(instance.groupedData[1].groupHeaders.length).toBe(1);
936
- expect(instance.groupedData[1].name).toBe('employee 1');
937
- expect(instance.groupedData[4].groupFooter).toBeTruthy();
938
- expect(instance.groupedData[4].id).toBe(3);
939
- expect(instance.groupedData[9].groupSummary).toBeTruthy();
940
- expect(instance.groupedData[9].id).toBe(5);
941
-
942
- done();
943
- }, 1000);
944
- });
945
-
946
- it('should group data with multiple groups', async (done) => {
956
+ instance.getCellWithAppliedConditions(instance.columns, instance.datasource.data[0]);
957
+ expect(instance.datasource.data.length).toBe(5);
958
+ expect(instance.datasource.order).toEqual(['department.asc', 'name.asc']);
959
+ expect(instance.groupedData.length).toBe(10);
960
+ expect(instance.groupedData[0].group).toBeTruthy();
961
+ expect(instance.groupedData[0].groupLabel).toBe('department');
962
+ expect(instance.groupedData[0].groupValue).toBe(1);
963
+ expect(instance.groupedData[1].groupHeaders.length).toBe(1);
964
+ expect(instance.groupedData[1].name).toBe('employee 1');
965
+ expect(instance.groupedData[4].groupFooter).toBeTruthy();
966
+ expect(instance.groupedData[4].id).toBe(3);
967
+ expect(instance.groupedData[9].groupSummary).toBeTruthy();
968
+ expect(instance.groupedData[9].id).toBe(5);
969
+ });
970
+
971
+ it('should group data with multiple groups', async () => {
947
972
  const flushPromises = () => new Promise(setImmediate);
948
973
  let viewUpdateScrollDataCalled = false;
949
974
 
@@ -993,38 +1018,34 @@ describe('TekGrid', () => {
993
1018
 
994
1019
  await flushPromises();
995
1020
 
996
- setTimeout(() => {
997
- expect(instance.datasource.data.length).toBe(5);
998
- expect(instance.datasource.data[0].groupHeaders).toBeUndefined();
999
- expect(instance.datasource.order).toEqual(['department.asc', 'boss.asc', 'name.asc']);
1000
- expect(instance.groupedData.length).toBe(11);
1001
- expect(instance.groupedData[0].group).toBeTruthy();
1002
- expect(instance.groupedData[0].groupLabel).toBe('department');
1003
- expect(instance.groupedData[0].groupValue).toBe(1);
1004
- expect(instance.groupedData[1].group).toBeTruthy();
1005
- expect(instance.groupedData[1].groupLabel).toBe('boss');
1006
- expect(instance.groupedData[1].groupValue).toBe('boss');
1007
- expect(instance.groupedData[2].groupHeaders.length).toBe(2);
1008
- expect(instance.groupedData[2].name).toBe('employee 1');
1009
- expect(instance.groupedData[3].group).toBeTruthy();
1010
- expect(instance.groupedData[3].groupLabel).toBe('boss');
1011
- expect(instance.groupedData[3].groupValue).toBe(1);
1012
-
1013
- expect(instance.isItemVisible(instance.groupedData[2])).toBeFalsy();
1014
- instance.openGroup(instance.groupedData[0]);
1015
- expect(instance.isItemVisible(instance.groupedData[2])).toBeFalsy();
1016
- expect(viewUpdateScrollDataCalled).toBeFalsy();
1017
-
1018
- instance.viewUpdateScrollData = () => { viewUpdateScrollDataCalled = true; };
1019
- instance.openGroup(instance.groupedData[1]);
1020
- expect(instance.isItemVisible(instance.groupedData[2])).toBeTruthy();
1021
- expect(viewUpdateScrollDataCalled).toBeTruthy();
1022
-
1023
- done();
1024
- }, 1000);
1025
- });
1026
-
1027
- it('should group data with multiple groups and aggregation', async (done) => {
1021
+ expect(instance.datasource.data.length).toBe(5);
1022
+ expect(instance.datasource.data[0].groupHeaders).toBeUndefined();
1023
+ expect(instance.datasource.order).toEqual(['department.asc', 'boss.asc', 'name.asc']);
1024
+ expect(instance.groupedData.length).toBe(11);
1025
+ expect(instance.groupedData[0].group).toBeTruthy();
1026
+ expect(instance.groupedData[0].groupLabel).toBe('department');
1027
+ expect(instance.groupedData[0].groupValue).toBe(1);
1028
+ expect(instance.groupedData[1].group).toBeTruthy();
1029
+ expect(instance.groupedData[1].groupLabel).toBe('boss');
1030
+ expect(instance.groupedData[1].groupValue).toBe('boss');
1031
+ expect(instance.groupedData[2].groupHeaders.length).toBe(2);
1032
+ expect(instance.groupedData[2].name).toBe('employee 1');
1033
+ expect(instance.groupedData[3].group).toBeTruthy();
1034
+ expect(instance.groupedData[3].groupLabel).toBe('boss');
1035
+ expect(instance.groupedData[3].groupValue).toBe(1);
1036
+
1037
+ expect(instance.isItemVisible(instance.groupedData[2])).toBeFalsy();
1038
+ instance.openGroup(instance.groupedData[0]);
1039
+ expect(instance.isItemVisible(instance.groupedData[2])).toBeFalsy();
1040
+ expect(viewUpdateScrollDataCalled).toBeFalsy();
1041
+
1042
+ instance.viewUpdateScrollData = () => { viewUpdateScrollDataCalled = true; };
1043
+ instance.openGroup(instance.groupedData[1]);
1044
+ expect(instance.isItemVisible(instance.groupedData[2])).toBeTruthy();
1045
+ expect(viewUpdateScrollDataCalled).toBeTruthy();
1046
+ });
1047
+
1048
+ it('should group data with multiple groups and aggregation', async () => {
1028
1049
  const flushPromises = () => new Promise(setImmediate);
1029
1050
  const instance = new TekGrid({
1030
1051
  name: 'grid_aggredate_2',
@@ -1082,37 +1103,33 @@ describe('TekGrid', () => {
1082
1103
 
1083
1104
  await flushPromises();
1084
1105
 
1085
- setTimeout(() => {
1086
- expect(instance.datasource.data.length).toBe(5);
1087
- expect(instance.datasource.data[0].groupHeaders).toBeUndefined();
1088
- expect(instance.datasource.order).toEqual(['department.asc', 'boss.asc', 'name.asc']);
1089
- expect(instance.groupedData.length).toBe(17);
1090
- expect(instance.groupedData[0].group).toBeTruthy();
1091
- expect(instance.groupedData[0].groupLabel).toBe('department');
1092
- expect(instance.groupedData[0].groupValue).toBe(1);
1093
- expect(instance.groupedData[1].group).toBeTruthy();
1094
- expect(instance.groupedData[1].groupLabel).toBe('boss');
1095
- expect(instance.groupedData[1].groupValue).toBe('boss');
1096
- expect(instance.groupedData[2].groupHeaders.length).toBe(2);
1097
- expect(instance.groupedData[2].name).toBe('employee 1');
1098
- expect(instance.groupedData[3].groupFooter).toBeTruthy();
1099
- expect(instance.groupedData[3].id).toBe(1);
1100
- expect(instance.groupedData[3].salary).toBe(10);
1101
- expect(instance.groupedData[4].group).toBeTruthy();
1102
- expect(instance.groupedData[4].groupLabel).toBe('boss');
1103
- expect(instance.groupedData[4].groupValue).toBe(1);
1104
- expect(instance.groupedData[7].groupFooter).toBeTruthy();
1105
- expect(instance.groupedData[7].id).toBe(2);
1106
- expect(instance.groupedData[7].salary).toBe(20);
1107
- expect(instance.groupedData[8].groupFooter).toBeTruthy();
1108
- expect(instance.groupedData[8].id).toBe(3);
1109
- expect(instance.groupedData[8].salary).toBe(30);
1110
-
1111
- done();
1112
- }, 1000);
1113
- });
1114
-
1115
- it('should aggregate even without groups', async (done) => {
1106
+ expect(instance.datasource.data.length).toBe(5);
1107
+ expect(instance.datasource.data[0].groupHeaders).toBeUndefined();
1108
+ expect(instance.datasource.order).toEqual(['department.asc', 'boss.asc', 'name.asc']);
1109
+ expect(instance.groupedData.length).toBe(17);
1110
+ expect(instance.groupedData[0].group).toBeTruthy();
1111
+ expect(instance.groupedData[0].groupLabel).toBe('department');
1112
+ expect(instance.groupedData[0].groupValue).toBe(1);
1113
+ expect(instance.groupedData[1].group).toBeTruthy();
1114
+ expect(instance.groupedData[1].groupLabel).toBe('boss');
1115
+ expect(instance.groupedData[1].groupValue).toBe('boss');
1116
+ expect(instance.groupedData[2].groupHeaders.length).toBe(2);
1117
+ expect(instance.groupedData[2].name).toBe('employee 1');
1118
+ expect(instance.groupedData[3].groupFooter).toBeTruthy();
1119
+ expect(instance.groupedData[3].id).toBe(1);
1120
+ expect(instance.groupedData[3].salary).toBe(10);
1121
+ expect(instance.groupedData[4].group).toBeTruthy();
1122
+ expect(instance.groupedData[4].groupLabel).toBe('boss');
1123
+ expect(instance.groupedData[4].groupValue).toBe(1);
1124
+ expect(instance.groupedData[7].groupFooter).toBeTruthy();
1125
+ expect(instance.groupedData[7].id).toBe(2);
1126
+ expect(instance.groupedData[7].salary).toBe(20);
1127
+ expect(instance.groupedData[8].groupFooter).toBeTruthy();
1128
+ expect(instance.groupedData[8].id).toBe(3);
1129
+ expect(instance.groupedData[8].salary).toBe(30);
1130
+ });
1131
+
1132
+ it('should aggregate even without groups', async () => {
1116
1133
  const flushPromises = () => new Promise(setImmediate);
1117
1134
  const instance = new TekGrid({
1118
1135
  name: 'grid_aggredate_3',
@@ -1168,17 +1185,13 @@ describe('TekGrid', () => {
1168
1185
 
1169
1186
  await flushPromises();
1170
1187
 
1171
- setTimeout(() => {
1172
- expect(instance.datasource.data.length).toBe(5);
1173
- expect(instance.groupedData.length).toBe(6);
1174
- expect(instance.groupedData[5].groupSummary).toBeTruthy();
1175
- expect(instance.groupedData[5].salary).toBe(50);
1176
-
1177
- done();
1178
- }, 1000);
1188
+ expect(instance.datasource.data.length).toBe(5);
1189
+ expect(instance.groupedData.length).toBe(6);
1190
+ expect(instance.groupedData[5].groupSummary).toBeTruthy();
1191
+ expect(instance.groupedData[5].salary).toBe(50);
1179
1192
  });
1180
1193
 
1181
- it('should aggregation with different functions', async (done) => {
1194
+ it('should aggregation with different functions', async () => {
1182
1195
  const flushPromises = () => new Promise(setImmediate);
1183
1196
  const instance = new TekGrid({
1184
1197
  name: 'grid_aggregate_4',
@@ -1241,21 +1254,17 @@ describe('TekGrid', () => {
1241
1254
 
1242
1255
  await flushPromises();
1243
1256
 
1244
- setTimeout(() => {
1245
- expect(instance.datasource.data.length).toBe(4);
1246
- expect(instance.groupedData.length).toBe(7);
1247
- expect(instance.groupedData[6].groupSummary).toBeTruthy();
1248
- expect(instance.groupedData[6].column_sum).toBe(130);
1249
- expect(instance.groupedData[6].column_min).toBe(5);
1250
- expect(instance.groupedData[6].column_max).toBe('5');
1251
- expect(instance.groupedData[6].column_avg).toBe(33.75);
1252
- expect(instance.groupedData[6].column_count).toBe(3);
1253
-
1254
- done();
1255
- }, 1000);
1257
+ expect(instance.datasource.data.length).toBe(4);
1258
+ expect(instance.groupedData.length).toBe(7);
1259
+ expect(instance.groupedData[6].groupSummary).toBeTruthy();
1260
+ expect(instance.groupedData[6].column_sum).toBe(130);
1261
+ expect(instance.groupedData[6].column_min).toBe(5);
1262
+ expect(instance.groupedData[6].column_max).toBe('5');
1263
+ expect(instance.groupedData[6].column_avg).toBe(33.75);
1264
+ expect(instance.groupedData[6].column_count).toBe(3);
1256
1265
  });
1257
1266
 
1258
- it('should group data on rest datasource with lazyLoad', async (done) => {
1267
+ it('should group data on rest datasource with lazyLoad', async () => {
1259
1268
  const flushPromises = () => new Promise(setImmediate);
1260
1269
  const httpSpy = jest.spyOn(Http, 'get').mockImplementation(() => Promise.resolve({
1261
1270
  data: {
@@ -1306,14 +1315,11 @@ describe('TekGrid', () => {
1306
1315
  expect(instance.datasource.data.length).toBe(0);
1307
1316
 
1308
1317
  await instance.datasource.get();
1309
- setTimeout(() => {
1310
- expect(instance.datasource.data.length).toBe(5);
1311
- expect(instance.groupedData.length).toBe(7);
1312
1318
 
1313
- httpSpy.mockClear();
1319
+ expect(instance.datasource.data.length).toBe(5);
1320
+ expect(instance.groupedData.length).toBe(7);
1314
1321
 
1315
- done();
1316
- }, 1000);
1322
+ httpSpy.mockReset();
1317
1323
  });
1318
1324
 
1319
1325
  it('editedRows should return cleaned rows', async () => {
@@ -1392,7 +1398,7 @@ describe('TekGrid', () => {
1392
1398
  expect(instance.groupedData.length).toBe(0);
1393
1399
  });
1394
1400
 
1395
- it('should call view update methods', async (done) => {
1401
+ it('should call view update methods', async () => {
1396
1402
  const flushPromises = () => new Promise(setImmediate);
1397
1403
  let viewUpdateScrollDataCalled = false;
1398
1404
  let viewUpdateFixedColumnsCalled = false;
@@ -1433,16 +1439,12 @@ describe('TekGrid', () => {
1433
1439
 
1434
1440
  await flushPromises();
1435
1441
 
1436
- setTimeout(() => {
1437
- expect(viewUpdateScrollDataCalled).toBeTruthy();
1438
- expect(viewUpdateFixedColumnsCalled).toBeTruthy();
1439
-
1440
- done();
1441
- }, 1000);
1442
+ expect(viewUpdateScrollDataCalled).toBeTruthy();
1443
+ expect(viewUpdateFixedColumnsCalled).toBeTruthy();
1442
1444
  });
1443
1445
 
1444
- it('should call debounced updateGroupData', async (done) => {
1445
- const flushPromises = () => new Promise(setImmediate);
1446
+ it('should call debounced updateGroupData', () => {
1447
+ const spy = jest.spyOn(TekGrid.prototype, 'updateGroupedData');
1446
1448
  const instance = new TekGrid({
1447
1449
  name: 'grid_grouping_1',
1448
1450
  component: 'TekGrid',
@@ -1474,15 +1476,13 @@ describe('TekGrid', () => {
1474
1476
  },
1475
1477
  });
1476
1478
 
1477
- await flushPromises();
1479
+ jest.runAllTimers();
1478
1480
 
1479
- instance.updateGroupedData = jest.fn();
1480
1481
  instance.columns[2].groupOpened = true;
1481
1482
 
1482
- setTimeout(() => {
1483
- expect(instance.updateGroupedData).toBeCalled();
1484
- done();
1485
- }, 1000);
1483
+ expect(spy).toHaveBeenCalled();
1484
+
1485
+ spy.mockClear();
1486
1486
  });
1487
1487
  });
1488
1488
 
@@ -1495,18 +1495,14 @@ describe('TekGrid', () => {
1495
1495
 
1496
1496
  const spy = jest.spyOn(ModalService, 'create');
1497
1497
  instance.onCreated();
1498
- const filterTooltip = instance.toolbarSlot[6];
1499
- if (filterTooltip && filterTooltip.children && filterTooltip.children.length > 0) {
1500
- const button = new Button(filterTooltip.children[0]);
1501
- const event = new Event('click');
1502
- button.click(event, {} as HTMLElement);
1503
- expect(spy).toBeCalledTimes(1);
1504
- button.click(event, {} as HTMLElement);
1505
- expect(spy).toBeCalledTimes(1);
1506
- expect(button.isVisible).toBeFalsy();
1507
- (instance as any).gridBase.hideFilterModal();
1508
- }
1509
- spy.mockClear();
1498
+
1499
+ const button = clickOnFilterButton(instance);
1500
+ expect(spy).toBeCalledTimes(1);
1501
+ clickOnFilterButton(instance);
1502
+ expect(spy).toBeCalledTimes(1);
1503
+ expect(button.isVisible).toBeFalsy();
1504
+ (instance as any).gridBase.hideFilterModal();
1505
+ spy.mockReset();
1510
1506
  });
1511
1507
 
1512
1508
  it('should call events', () => {
@@ -1519,14 +1515,14 @@ describe('TekGrid', () => {
1519
1515
  },
1520
1516
  });
1521
1517
 
1518
+ const spy = jest.spyOn(ModalService, 'create').mockImplementation((modal) => new Modal(modal));
1519
+
1522
1520
  instance.onCreated();
1523
- const filterTooltip = instance.toolbarSlot[6];
1524
- if (filterTooltip && filterTooltip.children && filterTooltip.children.length > 0) {
1525
- const button = new Button(filterTooltip.children[0]);
1526
- const event = new Event('click');
1527
- button.click(event, {} as HTMLElement);
1528
- expect(filterClickCalled).toBeTruthy();
1529
- }
1521
+ clickOnFilterButton(instance);
1522
+
1523
+ expect(filterClickCalled).toBeTruthy();
1524
+
1525
+ spy.mockReset();
1530
1526
  });
1531
1527
 
1532
1528
  it('should not call saveEditedRows if filterClick call preventDefault', () => {
@@ -1540,16 +1536,14 @@ describe('TekGrid', () => {
1540
1536
  });
1541
1537
 
1542
1538
  const spy = jest.spyOn(ModalService, 'create');
1543
- spy.mockReset();
1539
+
1544
1540
  instance.onCreated();
1545
- const filterTooltip = instance.toolbarSlot[6];
1546
- if (filterTooltip && filterTooltip.children && filterTooltip.children.length > 0) {
1547
- const button = new Button(filterTooltip.children[0]);
1548
- button.click({ defaultPrevented: true } as Event, {} as HTMLElement);
1549
- expect(filterClickCalled).toBeTruthy();
1550
- expect(spy).not.toBeCalled();
1551
- }
1552
- spy.mockClear();
1541
+ clickOnFilterButton(instance, { defaultPrevented: true });
1542
+
1543
+ expect(filterClickCalled).toBeTruthy();
1544
+ expect(spy).not.toBeCalled();
1545
+
1546
+ spy.mockReset();
1553
1547
  });
1554
1548
 
1555
1549
  it('should create modal with no form elements', () => {
@@ -1564,22 +1558,16 @@ describe('TekGrid', () => {
1564
1558
 
1565
1559
  let formElements: any = [];
1566
1560
  const spy = jest.spyOn(ModalService, 'create').mockImplementation((modal: IModal) => {
1567
- if (modal.children && modal.children.length > 1) {
1568
- const form = modal.children[1];
1569
- formElements = form.children;
1570
- }
1561
+ const form = getChild<IForm>(modal.children || [], `${instance.name}-filter-form`);
1562
+ formElements = form.children;
1571
1563
 
1572
1564
  return new Modal(modal);
1573
1565
  });
1574
1566
  instance.onCreated();
1575
- const filterTooltip = instance.toolbarSlot[6];
1576
- if (filterTooltip && filterTooltip.children && filterTooltip.children.length > 0) {
1577
- const button = new Button(filterTooltip.children[0]);
1578
- const event = new Event('click');
1579
- button.click(event, {} as HTMLElement);
1580
- expect(formElements).toEqual([]);
1581
- }
1582
- spy.mockClear();
1567
+ clickOnFilterButton(instance);
1568
+
1569
+ expect(formElements).toEqual([]);
1570
+ spy.mockReset();
1583
1571
  });
1584
1572
 
1585
1573
  it('should create modal with filterable form elements', () => {
@@ -1594,22 +1582,17 @@ describe('TekGrid', () => {
1594
1582
 
1595
1583
  let formElements: any = [];
1596
1584
  const spy = jest.spyOn(ModalService, 'create').mockImplementation((modal: IModal) => {
1597
- if (modal.children && modal.children.length > 1) {
1598
- const form = modal.children[1];
1599
- formElements = form.children;
1600
- }
1585
+ const form = getChild<IForm>(modal.children || [], `${instance.name}-filter-form`);
1586
+ formElements = form.children;
1601
1587
 
1602
1588
  return new Modal(modal);
1603
1589
  });
1604
1590
  instance.onCreated();
1605
- const filterTooltip = instance.toolbarSlot[6];
1606
- if (filterTooltip && filterTooltip.children && filterTooltip.children.length > 0) {
1607
- const button = new Button(filterTooltip.children[0]);
1608
- const event = new Event('click');
1609
- button.click(event, {} as HTMLElement);
1610
- expect(formElements[0].name).toBe('grid_filterClick5-filter-AND-CONTAINS-name-0');
1611
- }
1612
- spy.mockClear();
1591
+ clickOnFilterButton(instance);
1592
+
1593
+ expect(formElements[0].name).toBe('grid_filterClick5-filter-AND-CONTAINS-name-0');
1594
+
1595
+ spy.mockReset();
1613
1596
  });
1614
1597
 
1615
1598
  it('should create modal with filterable and ordered form elements', () => {
@@ -1640,24 +1623,20 @@ describe('TekGrid', () => {
1640
1623
 
1641
1624
  let formElements: any = [];
1642
1625
  const spy = jest.spyOn(ModalService, 'create').mockImplementation((modal: IModal) => {
1643
- if (modal.children && modal.children.length > 1) {
1644
- const form = modal.children[1];
1645
- formElements = form.children;
1646
- }
1626
+ const form = getChild<IForm>(modal.children || [], `${instance.name}-filter-form`);
1627
+ formElements = form.children;
1647
1628
 
1648
1629
  return new Modal(modal);
1649
1630
  });
1650
1631
  instance.onCreated();
1651
- const filterTooltip = instance.toolbarSlot[6];
1652
- if (filterTooltip && filterTooltip.children && filterTooltip.children.length > 0) {
1653
- const button = new Button(filterTooltip.children[0]);
1654
- const event = new Event('click');
1655
- button.click(event, {} as HTMLElement);
1656
- expect(formElements[0].name).toBe('grid-filter-order-filter-AND-CONTAINS-dob-0');
1657
- expect(formElements[1].name).toBe('grid-filter-order-filter-AND-CONTAINS-last_name-0');
1658
- expect(formElements[2].name).toBe('grid-filter-order-filter-AND-CONTAINS-first_name-0');
1659
- }
1660
- spy.mockClear();
1632
+
1633
+ clickOnFilterButton(instance);
1634
+
1635
+ expect(formElements[0].name).toBe('grid-filter-order-filter-AND-CONTAINS-dob-0');
1636
+ expect(formElements[1].name).toBe('grid-filter-order-filter-AND-CONTAINS-last_name-0');
1637
+ expect(formElements[2].name).toBe('grid-filter-order-filter-AND-CONTAINS-first_name-0');
1638
+
1639
+ spy.mockReset();
1661
1640
  });
1662
1641
 
1663
1642
  it('should create modal with filterable form elements and TekRestDatasource', () => {
@@ -1666,6 +1645,7 @@ describe('TekGrid', () => {
1666
1645
  component: 'TekGrid',
1667
1646
  datasource: {
1668
1647
  type: 'tek-rest',
1648
+ lazyLoad: true,
1669
1649
  },
1670
1650
  columns: [
1671
1651
  {
@@ -1685,24 +1665,20 @@ describe('TekGrid', () => {
1685
1665
  let formElements: any = [];
1686
1666
  let form: IForm;
1687
1667
  const spy = jest.spyOn(ModalService, 'create').mockImplementation((modal: IModal) => {
1688
- if (modal.children && modal.children.length > 1) {
1689
- form = modal.children[1] as IForm;
1690
- formElements = form.children;
1691
- }
1668
+ form = getChild<IForm>(modal.children || [], `${instance.name}-filter-form`);
1669
+ formElements = form.children;
1692
1670
 
1693
1671
  return new Modal(modal);
1694
1672
  });
1695
1673
  instance.onCreated();
1696
- const filterTooltip = instance.toolbarSlot[6];
1697
- if (filterTooltip && filterTooltip.children && filterTooltip.children.length > 0) {
1698
- const button = new Button(filterTooltip.children[0]);
1699
- const event = new Event('click');
1700
- button.click(event, {} as HTMLElement);
1701
- expect(formElements[0].name).toBe('grid_filterClick6-filter-AND-CONTAINS-id-0');
1702
- expect(formElements[1].name).toBe('grid_filterClick6-filter-OR-NOT_EQUALS-name-0');
1703
- expect(formElements[1].component).toBe('ZdSelect');
1704
- }
1705
- spy.mockClear();
1674
+
1675
+ clickOnFilterButton(instance);
1676
+
1677
+ expect(formElements[0].name).toBe('grid_filterClick6-filter-AND-CONTAINS-id-0');
1678
+ expect(formElements[1].name).toBe('grid_filterClick6-filter-OR-NOT_EQUALS-name-0');
1679
+ expect(formElements[1].component).toBe('ZdSelect');
1680
+
1681
+ spy.mockReset();
1706
1682
  });
1707
1683
 
1708
1684
  it('should create modal with helper component', () => {
@@ -1711,6 +1687,7 @@ describe('TekGrid', () => {
1711
1687
  component: 'TekGrid',
1712
1688
  datasource: {
1713
1689
  type: 'tek-rest',
1690
+ lazyLoad: true,
1714
1691
  },
1715
1692
  columns: [
1716
1693
  {
@@ -1750,27 +1727,22 @@ describe('TekGrid', () => {
1750
1727
  let formElements: any = [];
1751
1728
  let form: IForm;
1752
1729
  const spy = jest.spyOn(ModalService, 'create').mockImplementation((modal: IModal) => {
1753
- if (modal.children && modal.children.length > 1) {
1754
- form = modal.children[1] as IForm;
1755
- formElements = form.children;
1756
- }
1730
+ form = getChild<IForm>(modal.children || [], `${instance.name}-filter-form`);
1731
+ formElements = form.children;
1757
1732
 
1758
1733
  return new Modal(modal);
1759
1734
  });
1760
1735
  const dateHelperSpy = jest.spyOn(DateHelper, 'getLabel').mockImplementation((name: string) => name);
1761
1736
 
1762
1737
  instance.onCreated();
1763
- const filterTooltip = instance.toolbarSlot[6];
1764
- if (filterTooltip && filterTooltip.children && filterTooltip.children.length > 0) {
1765
- const button = new Button(filterTooltip.children[0]);
1766
- const event = new Event('click');
1767
- button.click(event, {} as HTMLElement);
1768
- expect(formElements[0].name).toBe('grid_filterClick7-filter-AND-CONTAINS-id-0');
1769
- expect(formElements[1].name).toBe('grid_filterClick7-filter-OR-NOT_EQUALS-date-0');
1770
- expect(formElements[2].name).toBe('grid_filterClick7-filter-OR-NOT_EQUALS-date-1');
1771
- }
1772
- spy.mockClear();
1773
- dateHelperSpy.mockClear();
1738
+ clickOnFilterButton(instance);
1739
+
1740
+ expect(formElements[0].name).toBe('grid_filterClick7-filter-AND-CONTAINS-id-0');
1741
+ expect(formElements[1].name).toBe('grid_filterClick7-filter-OR-NOT_EQUALS-date-0');
1742
+ expect(formElements[2].name).toBe('grid_filterClick7-filter-OR-NOT_EQUALS-date-1');
1743
+
1744
+ spy.mockReset();
1745
+ dateHelperSpy.mockReset();
1774
1746
  });
1775
1747
 
1776
1748
  it('should apply helper value', () => {
@@ -1779,6 +1751,7 @@ describe('TekGrid', () => {
1779
1751
  component: 'TekGrid',
1780
1752
  datasource: {
1781
1753
  type: 'tek-rest',
1754
+ lazyLoad: true,
1782
1755
  },
1783
1756
  columns: [
1784
1757
  {
@@ -1825,35 +1798,30 @@ describe('TekGrid', () => {
1825
1798
  let formElements: any = [];
1826
1799
  let form: IForm;
1827
1800
  const spy = jest.spyOn(ModalService, 'create').mockImplementation((modal: IModal) => {
1828
- if (modal.children && modal.children.length > 1) {
1829
- form = modal.children[1] as IForm;
1830
- formElements = form.children;
1831
- }
1801
+ form = getChild<IForm>(modal.children || [], `${instance.name}-filter-form`);
1802
+ formElements = form.children;
1832
1803
 
1833
1804
  return new Modal(modal);
1834
1805
  });
1835
1806
  instance.onCreated();
1836
- const filterTooltip = instance.toolbarSlot[6];
1837
- if (filterTooltip && filterTooltip.children && filterTooltip.children.length > 0) {
1838
- const button = new Button(filterTooltip.children[0]);
1839
- const event = new Event('click');
1840
- button.click(event, {} as HTMLElement);
1841
- const dateComp = new Date(formElements[0]);
1842
- dateComp.helperValue = 'TODAY';
1843
- dateComp.change(event, {} as HTMLElement);
1844
- expect((instance.columns[0].filterProps as IFilterPropsComponent).helperValue).toBe('TODAY');
1845
-
1846
- const dateComp21 = new Date(formElements[1]);
1847
- dateComp21.helperValue = 'TODAY';
1848
- dateComp21.change(event, {} as HTMLElement);
1849
- expect((instance.columns[1].filterProps as IFilterPropsComponent[])[0].helperValue).toBe('TODAY');
1850
-
1851
- const dateComp22 = new Date(formElements[2]);
1852
- dateComp22.helperValue = 'TODAY';
1853
- dateComp22.change(event, {} as HTMLElement);
1854
- expect((instance.columns[1].filterProps as IFilterPropsComponent[])[1].helperValue).toBe('TODAY');
1855
- }
1856
- spy.mockClear();
1807
+ clickOnFilterButton(instance);
1808
+
1809
+ const dateComp = new Date(formElements[0]);
1810
+ dateComp.helperValue = 'TODAY';
1811
+ dateComp.change({} as Event, {} as HTMLElement);
1812
+ expect((instance.columns[0].filterProps as IFilterPropsComponent).helperValue).toBe('TODAY');
1813
+
1814
+ const dateComp21 = new Date(formElements[1]);
1815
+ dateComp21.helperValue = 'TODAY';
1816
+ dateComp21.change({} as Event, {} as HTMLElement);
1817
+ expect((instance.columns[1].filterProps as IFilterPropsComponent[])[0].helperValue).toBe('TODAY');
1818
+
1819
+ const dateComp22 = new Date(formElements[2]);
1820
+ dateComp22.helperValue = 'TODAY';
1821
+ dateComp22.change({} as Event, {} as HTMLElement);
1822
+ expect((instance.columns[1].filterProps as IFilterPropsComponent[])[1].helperValue).toBe('TODAY');
1823
+
1824
+ spy.mockReset();
1857
1825
  });
1858
1826
 
1859
1827
  it('should load form values from tekdatasource', () => {
@@ -1862,6 +1830,7 @@ describe('TekGrid', () => {
1862
1830
  component: 'TekGrid',
1863
1831
  datasource: {
1864
1832
  type: 'tek-rest',
1833
+ lazyLoad: true,
1865
1834
  dynamicFilter: {
1866
1835
  id: [],
1867
1836
  name: [
@@ -1909,35 +1878,30 @@ describe('TekGrid', () => {
1909
1878
  });
1910
1879
 
1911
1880
  let form: IForm = { name: 'form', component: 'ZdForm' };
1881
+ const dateHelperSpy = jest.spyOn(DateHelper, 'getLabel').mockImplementation((name: string) => name);
1912
1882
  const spy = jest.spyOn(ModalService, 'create').mockImplementation((modal: IModal) => {
1913
- if (modal.children && modal.children.length > 1) {
1914
- form = modal.children[1] as IForm;
1915
- }
1883
+ form = getChild<IForm>(modal.children || [], `${instance.name}-filter-form`);
1916
1884
 
1917
1885
  return new Modal(modal);
1918
1886
  });
1919
1887
  instance.onCreated();
1920
- const filterTooltip = instance.toolbarSlot[6];
1921
- if (filterTooltip && filterTooltip.children && filterTooltip.children.length > 0) {
1922
- const button = new Button(filterTooltip.children[0]);
1923
- const event = new Event('click');
1924
- button.click(event, {} as HTMLElement);
1925
- expect(form.name).toBe('grid_filterClick9-filter-form');
1926
- if (form) {
1927
- const formObject = new Form(form);
1928
- const dateObject = new Date({ name: 'date', component: 'ZdDate' });
1929
- const spyMetadata = jest.spyOn(Metadata, 'getInstances').mockImplementation(() => [dateObject]);
1930
- formObject.onMounted({} as HTMLElement);
1931
- expect(formObject.value).toEqual({
1932
- 'grid_filterClick9-filter-OR-NOT_EQUALS-name-0': 'teste',
1933
- 'grid_filterClick9-filter-AND-CONTAINS-phone-0': '9',
1934
- 'grid_filterClick9-filter-OR-IN-date-0': ['2021-11-12', '2021-12-12'],
1935
- });
1936
- expect(dateObject.hint).toBe('TODAY');
1937
- spyMetadata.mockClear();
1938
- }
1939
- }
1940
- spy.mockClear();
1888
+
1889
+ clickOnFilterButton(instance);
1890
+
1891
+ expect(form.name).toBe('grid_filterClick9-filter-form');
1892
+ const formObject = new Form(form);
1893
+ const dateObject = new Date({ name: 'date', component: 'ZdDate' });
1894
+ const spyMetadata = jest.spyOn(Metadata, 'getInstances').mockImplementation(() => [dateObject]);
1895
+ formObject.onMounted({} as HTMLElement);
1896
+ expect(formObject.value).toEqual({
1897
+ 'grid_filterClick9-filter-OR-NOT_EQUALS-name-0': 'teste',
1898
+ 'grid_filterClick9-filter-AND-CONTAINS-phone-0': '9',
1899
+ 'grid_filterClick9-filter-OR-IN-date-0': ['2021-11-12', '2021-12-12'],
1900
+ });
1901
+ expect(dateObject.hint).toBe('TODAY');
1902
+ spyMetadata.mockReset();
1903
+ dateHelperSpy.mockReset();
1904
+ spy.mockReset();
1941
1905
  });
1942
1906
 
1943
1907
  it('should load form values from datasource', () => {
@@ -1964,31 +1928,42 @@ describe('TekGrid', () => {
1964
1928
  ],
1965
1929
  });
1966
1930
 
1967
- let form: IForm = { name: 'form', component: 'ZdForm' };
1931
+ let formProps: IForm = {} as IForm;
1968
1932
  const spy = jest.spyOn(ModalService, 'create').mockImplementation((modal: IModal) => {
1969
- if (modal.children && modal.children.length > 1) {
1970
- form = modal.children[1] as IForm;
1971
- }
1933
+ formProps = getChild<IForm>(modal.children || [], `${instance.name}-filter-form`);
1972
1934
 
1973
1935
  return new Modal(modal);
1974
1936
  });
1975
1937
  instance.onCreated();
1976
- const filterTooltip = instance.toolbarSlot[6];
1977
- if (filterTooltip && filterTooltip.children && filterTooltip.children.length > 0) {
1978
- const button = new Button(filterTooltip.children[0]);
1979
- const event = new Event('click');
1980
- button.click(event, {} as HTMLElement);
1981
- const formObject = new Form(form);
1982
- formObject.onMounted({} as HTMLElement);
1983
- expect(formObject.value).toEqual({
1984
- 'grid_filterClick10-filter-AND-CONTAINS-name-0': 'teste',
1985
- 'grid_filterClick10-filter-AND-CONTAINS-phone-0': '9',
1986
- });
1987
- }
1988
- spy.mockClear();
1938
+ clickOnFilterButton(instance);
1939
+
1940
+ const formObject = new Form(formProps);
1941
+ formObject.onMounted({} as HTMLElement);
1942
+
1943
+ expect(formObject.value).toEqual({
1944
+ 'grid_filterClick10-filter-AND-CONTAINS-name-0': 'teste',
1945
+ 'grid_filterClick10-filter-AND-CONTAINS-phone-0': '9',
1946
+ });
1947
+ spy.mockReset();
1989
1948
  });
1990
1949
 
1991
1950
  it('should apply filter from form to tekdatasource', () => {
1951
+ const httpSpy = jest.spyOn(Http, 'get').mockImplementation(() => Promise.resolve({
1952
+ data: {
1953
+ data: [
1954
+ { id: 1, name: 'employee 1', department: 1 },
1955
+ { id: 2, name: 'employee 2', department: 1 },
1956
+ { id: 3, name: 'employee 3', department: 1 },
1957
+ { id: 4, name: 'employee 4', department: 2 },
1958
+ { id: 5, name: 'employee 5', department: 2 },
1959
+ ],
1960
+ pagination: {
1961
+ page: 1,
1962
+ total: 5,
1963
+ limit: 15,
1964
+ },
1965
+ },
1966
+ }));
1992
1967
  const instance = new TekGrid({
1993
1968
  name: 'grid_filterClick11',
1994
1969
  component: 'TekGrid',
@@ -2024,78 +1999,90 @@ describe('TekGrid', () => {
2024
1999
  let form: IForm = { name: 'form', component: 'ZdForm' };
2025
2000
  let applyButton: IButton = { name: 'apply', component: 'ZdButton' };
2026
2001
  const spyModalService = jest.spyOn(ModalService, 'create').mockImplementation((modal: IModal) => {
2027
- if (modal.children && modal.children.length > 2) {
2028
- form = modal.children[1] as IForm;
2029
- const modalFooter = modal.children[2];
2030
- if (modalFooter.rightSlot && modalFooter.rightSlot.length > 1) {
2031
- applyButton = modalFooter.rightSlot[1] as IButton;
2032
- }
2033
- }
2002
+ form = getChild(modal.children || [], `${instance.name}-filter-form`);
2003
+
2004
+ const modalFooter = getChild(modal.children || [], `${instance.name}-filter-footer`);
2005
+ applyButton = getChild(modalFooter.rightSlot, `${instance.name}-filter-okButton`);
2034
2006
 
2035
2007
  return new Modal(modal);
2036
2008
  });
2037
2009
 
2038
2010
  instance.onCreated();
2039
2011
 
2040
- const filterTooltip = instance.toolbarSlot[6];
2041
- if (filterTooltip && filterTooltip.children && filterTooltip.children.length > 0) {
2042
- const button = new Button(filterTooltip.children[0]);
2043
- const event = new Event('click');
2044
- button.click(event, {} as HTMLElement);
2045
- const formObject = new Form(form);
2046
- const spyMetadata = jest.spyOn(Metadata, 'getInstance').mockImplementation(() => formObject);
2047
- const spyDatasourceGet = jest.spyOn(instance.datasource, 'get');
2048
- formObject.value = {
2049
- 'grid_filterClick11-filter-AND-IN-id-0': ['1', '2', '3'],
2050
- 'grid_filterClick11-filter-OR-NOT_EQUALS-name-0': 'teste',
2051
- 'grid_filterClick11-filter-AND-CONTAINS-phone-0': '',
2052
- 'grid_filterClick11-filter-AND-GREATER_THAN_EQUALS-salary-0': '1000',
2053
- 'grid_filterClick11-filter-AND-LESS_THAN_EQUALS-salary-0': '2000',
2054
- };
2055
- const applyButtonObject = new Button(applyButton);
2056
- formObject.validate = () => false;
2057
- applyButtonObject.click(event, {} as HTMLElement);
2058
- expect((instance.datasource as TekRestDatasource).dynamicFilter).toEqual({});
2059
-
2060
- formObject.validate = () => true;
2061
- applyButtonObject.click(event, {} as HTMLElement);
2062
- expect((instance.datasource as TekRestDatasource).dynamicFilter).toEqual({
2063
- id: [
2064
- {
2065
- operation: 'IN',
2066
- relation: 'AND',
2067
- value: ['1', '2', '3'],
2068
- },
2069
- ],
2070
- name: [
2071
- {
2072
- operation: 'NOT_EQUALS',
2073
- relation: 'OR',
2074
- value: 'teste',
2075
- },
2076
- ],
2077
- salary: [
2078
- {
2079
- operation: 'GREATER_THAN_EQUALS',
2080
- relation: 'AND',
2081
- value: '1000',
2082
- },
2083
- {
2084
- operation: 'LESS_THAN_EQUALS',
2085
- relation: 'AND',
2086
- value: '2000',
2087
- },
2088
- ],
2089
- });
2090
- expect(instance.columnHasFilterData({ name: 'name' } as TekGridColumn)).toBeTruthy();
2091
- expect(spyDatasourceGet).toBeCalled();
2092
- spyMetadata.mockClear();
2093
- spyDatasourceGet.mockClear();
2094
- }
2095
- spyModalService.mockClear();
2012
+ const buttonProps = getChild<IButton>(instance.toolbarSlot, `${instance.name}_filterButton`);
2013
+ const button = new Button(buttonProps);
2014
+ setClick(button);
2015
+
2016
+ const formObject = new Form(form);
2017
+ const spyMetadata = jest.spyOn(Metadata, 'getInstance').mockImplementation(() => formObject);
2018
+ const spyDatasourceGet = jest.spyOn(instance.datasource, 'get');
2019
+ formObject.value = {
2020
+ 'grid_filterClick11-filter-AND-IN-id-0': ['1', '2', '3'],
2021
+ 'grid_filterClick11-filter-OR-NOT_EQUALS-name-0': 'teste',
2022
+ 'grid_filterClick11-filter-AND-CONTAINS-phone-0': '',
2023
+ 'grid_filterClick11-filter-AND-GREATER_THAN_EQUALS-salary-0': '1000',
2024
+ 'grid_filterClick11-filter-AND-LESS_THAN_EQUALS-salary-0': '2000',
2025
+ };
2026
+ const applyButtonObject = new Button(applyButton);
2027
+ formObject.validate = () => false;
2028
+ setClick(applyButtonObject);
2029
+ expect((instance.datasource as TekRestDatasource).dynamicFilter).toEqual({});
2030
+
2031
+ formObject.validate = () => true;
2032
+ setClick(applyButtonObject);
2033
+ expect((instance.datasource as TekRestDatasource).dynamicFilter).toEqual({
2034
+ id: [
2035
+ {
2036
+ operation: 'IN',
2037
+ relation: 'AND',
2038
+ value: ['1', '2', '3'],
2039
+ },
2040
+ ],
2041
+ name: [
2042
+ {
2043
+ operation: 'NOT_EQUALS',
2044
+ relation: 'OR',
2045
+ value: 'teste',
2046
+ },
2047
+ ],
2048
+ salary: [
2049
+ {
2050
+ operation: 'GREATER_THAN_EQUALS',
2051
+ relation: 'AND',
2052
+ value: '1000',
2053
+ },
2054
+ {
2055
+ operation: 'LESS_THAN_EQUALS',
2056
+ relation: 'AND',
2057
+ value: '2000',
2058
+ },
2059
+ ],
2060
+ });
2061
+ expect(instance.columnHasFilterData({ name: 'name' } as TekGridColumn)).toBeTruthy();
2062
+ expect(spyDatasourceGet).toBeCalled();
2063
+ spyMetadata.mockReset();
2064
+ spyDatasourceGet.mockReset();
2065
+ spyModalService.mockReset();
2066
+ httpSpy.mockReset();
2096
2067
  });
2097
2068
 
2098
2069
  it('should clear data from form', () => {
2070
+ const httpSpy = jest.spyOn(Http, 'get').mockImplementation(() => Promise.resolve({
2071
+ data: {
2072
+ data: [
2073
+ { id: 1, name: 'employee 1', department: 1 },
2074
+ { id: 2, name: 'employee 2', department: 1 },
2075
+ { id: 3, name: 'employee 3', department: 1 },
2076
+ { id: 4, name: 'employee 4', department: 2 },
2077
+ { id: 5, name: 'employee 5', department: 2 },
2078
+ ],
2079
+ pagination: {
2080
+ page: 1,
2081
+ total: 5,
2082
+ limit: 15,
2083
+ },
2084
+ },
2085
+ }));
2099
2086
  const instance = new TekGrid({
2100
2087
  name: 'grid_filterClick12',
2101
2088
  component: 'TekGrid',
@@ -2131,47 +2118,43 @@ describe('TekGrid', () => {
2131
2118
  let form: IForm = { name: 'form', component: 'ZdForm' };
2132
2119
  let clearButton: IButton = { name: 'clear', component: 'ZdButton' };
2133
2120
  const spyModalService = jest.spyOn(ModalService, 'create').mockImplementation((modal: IModal) => {
2134
- if (modal.children && modal.children.length > 2) {
2135
- form = modal.children[1] as IForm;
2136
- const modalFooter = modal.children[2];
2137
- if (modalFooter.leftSlot && modalFooter.leftSlot.length > 0) {
2138
- clearButton = modalFooter.leftSlot[0] as IButton;
2139
- }
2140
- }
2121
+ form = getChild(modal.children || [], `${instance.name}-filter-form`);
2122
+
2123
+ const modalFooter = getChild(modal.children || [], `${instance.name}-filter-footer`);
2124
+ clearButton = getChild(modalFooter.leftSlot, `${instance.name}-filter-clearButton`);
2141
2125
 
2142
2126
  return new Modal(modal);
2143
2127
  });
2144
2128
 
2145
2129
  instance.onCreated();
2146
2130
 
2147
- const filterTooltip = instance.toolbarSlot[6];
2148
- if (filterTooltip && filterTooltip.children && filterTooltip.children.length > 0) {
2149
- const button = new Button(filterTooltip.children[0]);
2150
- const event = new Event('click');
2151
- button.click(event, {} as HTMLElement);
2152
- const formObject = new Form(form);
2153
- const spyMetadata = jest.spyOn(Metadata, 'getInstance').mockImplementation(() => formObject);
2154
- const spyDatasourceGet = jest.spyOn(instance.datasource, 'get');
2155
- formObject.value = {
2156
- 'grid_filterClick12-filter-AND-IN-id-0': ['1', '2', '3'],
2157
- 'grid_filterClick12-filter-OR-NOT_EQUALS-name-0': 'teste',
2158
- 'grid_filterClick12-filter-AND-CONTAINS-phone-0': '',
2159
- 'grid_filterClick12-filter-AND-GREATER_THAN_EQUALS-salary-0': '1000',
2160
- 'grid_filterClick12-filter-AND-LESS_THAN_EQUALS-salary-0': '2000',
2161
- };
2162
- const clearButtonObject = new Button(clearButton);
2163
- clearButtonObject.click(event, {} as HTMLElement);
2164
- expect(formObject.value).toEqual({
2165
- 'grid_filterClick12-filter-AND-IN-id-0': null,
2166
- 'grid_filterClick12-filter-OR-NOT_EQUALS-name-0': null,
2167
- 'grid_filterClick12-filter-AND-CONTAINS-phone-0': null,
2168
- 'grid_filterClick12-filter-AND-GREATER_THAN_EQUALS-salary-0': null,
2169
- 'grid_filterClick12-filter-AND-LESS_THAN_EQUALS-salary-0': null,
2170
- });
2171
- spyMetadata.mockClear();
2172
- spyDatasourceGet.mockClear();
2173
- }
2174
- spyModalService.mockClear();
2131
+ const buttonProps = getChild<IButton>(instance.toolbarSlot, `${instance.name}_filterButton`);
2132
+ const button = new Button(buttonProps);
2133
+ setClick(button);
2134
+
2135
+ const formObject = new Form(form);
2136
+ const spyMetadata = jest.spyOn(Metadata, 'getInstance').mockImplementation(() => formObject);
2137
+ const spyDatasourceGet = jest.spyOn(instance.datasource, 'get');
2138
+ formObject.value = {
2139
+ 'grid_filterClick12-filter-AND-IN-id-0': ['1', '2', '3'],
2140
+ 'grid_filterClick12-filter-OR-NOT_EQUALS-name-0': 'teste',
2141
+ 'grid_filterClick12-filter-AND-CONTAINS-phone-0': '',
2142
+ 'grid_filterClick12-filter-AND-GREATER_THAN_EQUALS-salary-0': '1000',
2143
+ 'grid_filterClick12-filter-AND-LESS_THAN_EQUALS-salary-0': '2000',
2144
+ };
2145
+ const clearButtonObject = new Button(clearButton);
2146
+ setClick(clearButtonObject);
2147
+ expect(formObject.value).toEqual({
2148
+ 'grid_filterClick12-filter-AND-IN-id-0': null,
2149
+ 'grid_filterClick12-filter-OR-NOT_EQUALS-name-0': null,
2150
+ 'grid_filterClick12-filter-AND-CONTAINS-phone-0': null,
2151
+ 'grid_filterClick12-filter-AND-GREATER_THAN_EQUALS-salary-0': null,
2152
+ 'grid_filterClick12-filter-AND-LESS_THAN_EQUALS-salary-0': null,
2153
+ });
2154
+ spyMetadata.mockReset();
2155
+ spyDatasourceGet.mockReset();
2156
+ spyModalService.mockReset();
2157
+ httpSpy.mockReset();
2175
2158
  });
2176
2159
 
2177
2160
  it('should apply filter from form to datasource', () => {
@@ -2203,48 +2186,41 @@ describe('TekGrid', () => {
2203
2186
  let form: IForm = { name: 'form', component: 'ZdForm' };
2204
2187
  let applyButton: IButton = { name: 'apply', component: 'ZdButton' };
2205
2188
  const spyModalService = jest.spyOn(ModalService, 'create').mockImplementation((modal: IModal) => {
2206
- if (modal.children && modal.children.length > 2) {
2207
- form = modal.children[1] as IForm;
2208
- const modalFooter = modal.children[2];
2209
- if (modalFooter.rightSlot && modalFooter.rightSlot.length > 1) {
2210
- applyButton = modalFooter.rightSlot[1] as IButton;
2211
- }
2212
- }
2189
+ form = getChild(modal.children || [], `${instance.name}-filter-form`);
2190
+
2191
+ const modalFooter = getChild(modal.children || [], `${instance.name}-filter-footer`);
2192
+ applyButton = getChild(modalFooter.rightSlot, `${instance.name}-filter-okButton`);
2213
2193
 
2214
2194
  return new Modal(modal);
2215
2195
  });
2216
2196
 
2217
2197
  instance.onCreated();
2218
2198
 
2219
- const filterTooltip = instance.toolbarSlot[6];
2220
- if (filterTooltip && filterTooltip.children && filterTooltip.children.length > 0) {
2221
- const button = new Button(filterTooltip.children[0]);
2222
- const event = new Event('click');
2223
- button.click(event, {} as HTMLElement);
2224
- const formObject = new Form(form);
2225
- const spyMetadata = jest.spyOn(Metadata, 'getInstance').mockImplementation(() => formObject);
2226
- const spyDatasourceGet = jest.spyOn(instance.datasource, 'get');
2227
- formObject.value = {
2228
- 'grid_filterClick13-filter-AND-CONTAINS-id-0': '1;2;3',
2229
- 'grid_filterClick13-filter-AND-CONTAINS-name-0': 'teste',
2230
- 'grid_filterClick13-filter-AND-CONTAINS-phone-0': '',
2231
- 'grid_filterClick13-filter-AND-CONTAINS-salary-0': '1000',
2232
- };
2233
- const applyButtonObject = new Button(applyButton);
2234
- applyButtonObject.click({ defaultPrevented: true } as Event, {} as HTMLElement);
2235
- expect((instance.datasource as TekRestDatasource).filter).toEqual({
2236
- id: '1;2;3',
2237
- name: 'teste',
2238
- salary: '1000',
2239
- });
2240
- expect(beforeApplyFilterCalled).toBeTruthy();
2241
- expect(changeLayoutCalled).toBeTruthy();
2242
- expect(instance.columnHasFilterData({ name: 'name' } as TekGridColumn)).toBeTruthy();
2243
- expect(spyDatasourceGet).not.toBeCalled();
2244
- spyMetadata.mockClear();
2245
- spyDatasourceGet.mockClear();
2246
- }
2247
- spyModalService.mockClear();
2199
+ clickOnFilterButton(instance);
2200
+
2201
+ const formObject = new Form(form);
2202
+ const spyMetadata = jest.spyOn(Metadata, 'getInstance').mockImplementation(() => formObject);
2203
+ const spyDatasourceGet = jest.spyOn(instance.datasource, 'get');
2204
+ formObject.value = {
2205
+ 'grid_filterClick13-filter-AND-CONTAINS-id-0': '1;2;3',
2206
+ 'grid_filterClick13-filter-AND-CONTAINS-name-0': 'teste',
2207
+ 'grid_filterClick13-filter-AND-CONTAINS-phone-0': '',
2208
+ 'grid_filterClick13-filter-AND-CONTAINS-salary-0': '1000',
2209
+ };
2210
+ const applyButtonObject = new Button(applyButton);
2211
+ setClick(applyButtonObject, { defaultPrevented: true });
2212
+ expect((instance.datasource as TekRestDatasource).filter).toEqual({
2213
+ id: '1;2;3',
2214
+ name: 'teste',
2215
+ salary: '1000',
2216
+ });
2217
+ expect(beforeApplyFilterCalled).toBeTruthy();
2218
+ expect(changeLayoutCalled).toBeTruthy();
2219
+ expect(instance.columnHasFilterData({ name: 'name' } as TekGridColumn)).toBeTruthy();
2220
+ expect(spyDatasourceGet).not.toBeCalled();
2221
+ spyMetadata.mockReset();
2222
+ spyDatasourceGet.mockReset();
2223
+ spyModalService.mockReset();
2248
2224
  });
2249
2225
  });
2250
2226
 
@@ -2336,22 +2312,23 @@ describe('TekGrid', () => {
2336
2312
  ],
2337
2313
  datasource: {
2338
2314
  type: 'tek-rest',
2339
- lazyLoad: false,
2315
+ lazyLoad: true,
2340
2316
  route: '/grid',
2341
2317
  },
2342
2318
  };
2343
-
2344
- httpSpy.mockClear();
2345
2319
  });
2346
2320
 
2347
- afterAll(() => {
2348
- httpSpy.mockClear();
2321
+ afterEach(() => {
2322
+ httpSpy.mockReset();
2349
2323
  });
2350
2324
 
2351
2325
  it('should set datasource search_join based on columns that have datasource', async () => {
2326
+ const flushPromises = () => new Promise(setImmediate);
2352
2327
  const instance = new TekGrid(baseProps);
2353
2328
 
2354
- await instance.setSearch('1');
2329
+ instance.setSearch('1');
2330
+ await flushPromises();
2331
+
2355
2332
  expect(instance.datasource).toBeInstanceOf(TekRestDatasource);
2356
2333
  expect((instance.datasource as TekRestDatasource).searchJoin).toEqual({ employee_id: [1, 15] });
2357
2334
  expect(httpSpy).toHaveBeenCalledTimes(2);
@@ -2403,7 +2380,7 @@ describe('TekGrid', () => {
2403
2380
  ],
2404
2381
  datasource: {
2405
2382
  type: 'tek-rest',
2406
- lazyLoad: false,
2383
+ lazyLoad: true,
2407
2384
  route: '/grid',
2408
2385
  },
2409
2386
  });
@@ -2422,6 +2399,17 @@ describe('TekGrid', () => {
2422
2399
  expect(instance.datasource).not.toBeInstanceOf(TekRestDatasource);
2423
2400
  expect(httpSpy).toHaveBeenCalledTimes(1);
2424
2401
  });
2402
+
2403
+ it('when called, should change datasource page to 1 before searching', async () => {
2404
+ const instance = new TekGrid({
2405
+ name: 'iterable',
2406
+ component: 'Iterable',
2407
+ });
2408
+ instance.datasource.page = 5;
2409
+ await instance.setSearch('search value');
2410
+
2411
+ expect(instance.datasource.page).toBe(1);
2412
+ });
2425
2413
  });
2426
2414
 
2427
2415
  describe('rowClick', () => {
@@ -2629,7 +2617,7 @@ describe('TekGrid', () => {
2629
2617
  const layoutOptionsComp = { name: 'grid_layout_options' };
2630
2618
  const spyMetadata = jest.spyOn(Metadata, 'getInstance').mockImplementation(() => layoutOptionsComp);
2631
2619
  expect(grid.layoutOptions).toEqual(layoutOptionsComp);
2632
- spyMetadata.mockClear();
2620
+ spyMetadata.mockReset();
2633
2621
  });
2634
2622
  });
2635
2623
 
@@ -2648,7 +2636,7 @@ describe('TekGrid', () => {
2648
2636
  const gridAtom = instance.getAtomInstance<Text>('TITLE');
2649
2637
 
2650
2638
  expect(gridAtom).toEqual(atom);
2651
- spyMetadata.mockClear();
2639
+ spyMetadata.mockReset();
2652
2640
  });
2653
2641
  });
2654
2642
 
@@ -2673,6 +2661,7 @@ describe('TekGrid', () => {
2673
2661
  };
2674
2662
 
2675
2663
  it('when called with null parameter, should return all the filter inputs', () => {
2664
+ const spyModalService = jest.spyOn(ModalService, 'create').mockImplementation((modal: IModal) => (new Modal(modal)));
2676
2665
  const instance = new TekGrid({
2677
2666
  name: 'grid',
2678
2667
  component: 'TekGrid',
@@ -2708,21 +2697,18 @@ describe('TekGrid', () => {
2708
2697
 
2709
2698
  const spy = mockMetadata(instance);
2710
2699
  instance.onCreated();
2711
- const filterTooltip = instance.toolbarSlot[6];
2712
- if (filterTooltip && filterTooltip.children && filterTooltip.children.length > 0) {
2713
- const button = new Button(filterTooltip.children[0]);
2714
- const event = new Event('click');
2715
- button.click(event, {} as HTMLElement);
2716
- }
2700
+ clickOnFilterButton(instance);
2717
2701
 
2718
2702
  const inputs = instance.getFilterInputs();
2719
2703
  expect(inputs[0].name).toBe('grid-filter-AND-CONTAINS-name-0');
2720
2704
  expect(inputs[1].name).toBe('grid-filter-AND-GREATER_THAN_EQUALS-salary-0');
2721
2705
  expect(inputs[2].name).toBe('grid-filter-AND-LESS_THAN_EQUALS-salary-1');
2722
- spy.mockClear();
2706
+ spy.mockReset();
2707
+ spyModalService.mockReset();
2723
2708
  });
2724
2709
 
2725
2710
  it('when called, should return the instances of filters with multiple inputs', () => {
2711
+ const spyModalService = jest.spyOn(ModalService, 'create').mockImplementation((modal: IModal) => (new Modal(modal)));
2726
2712
  const instance = new TekGrid({
2727
2713
  name: 'grid',
2728
2714
  component: 'TekGrid',
@@ -2758,17 +2744,14 @@ describe('TekGrid', () => {
2758
2744
 
2759
2745
  const spy = mockMetadata(instance);
2760
2746
  instance.onCreated();
2761
- const filterTooltip = instance.toolbarSlot[6];
2762
- if (filterTooltip && filterTooltip.children && filterTooltip.children.length > 0) {
2763
- const button = new Button(filterTooltip.children[0]);
2764
- const event = new Event('click');
2765
- button.click(event, {} as HTMLElement);
2766
- }
2747
+
2748
+ clickOnFilterButton(instance);
2767
2749
 
2768
2750
  const inputs = instance.getFilterInputs('salary');
2769
2751
  expect(inputs[0].name).toBe('grid-filter-AND-GREATER_THAN_EQUALS-salary-0');
2770
2752
  expect(inputs[1].name).toBe('grid-filter-AND-LESS_THAN_EQUALS-salary-1');
2771
- spy.mockClear();
2753
+ spy.mockReset();
2754
+ spyModalService.mockReset();
2772
2755
  });
2773
2756
  });
2774
2757
  });