@zeedhi/teknisa-components-common 1.88.0 → 1.90.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@zeedhi/teknisa-components-common",
3
- "version": "1.88.0",
3
+ "version": "1.90.0",
4
4
  "description": "Teknisa Components Common",
5
5
  "author": "Zeedhi <zeedhi@teknisa.com>",
6
6
  "license": "ISC",
@@ -18,6 +18,7 @@
18
18
  "watch": "npm run build -- -w"
19
19
  },
20
20
  "dependencies": {
21
+ "@zeedhi/zd-drag-grid-common": "*",
21
22
  "@zeedhi/zd-user-info-common": "*",
22
23
  "lodash.debounce": "4.0.*",
23
24
  "lodash.get": "4.4.*",
@@ -31,5 +32,5 @@
31
32
  "peerDependencies": {
32
33
  "@zeedhi/core": "*"
33
34
  },
34
- "gitHead": "a1c73be520b15a08069998ea866a092204ef74b2"
35
+ "gitHead": "85a8108906ad118d851958914b4fb8d3719e9051"
35
36
  }
@@ -0,0 +1,112 @@
1
+ import { IDictionary } from '@zeedhi/core';
2
+ import { TekDragGrid } from '../../../../src/components/tek-drag-grid/tek-drag-grid';
3
+
4
+ const dragFromXToY = (from: number, to: number, data: IDictionary[]) => {
5
+ const row = data[from];
6
+ data.splice(from, 1);
7
+ data.splice(to, 0, row);
8
+ const event = {
9
+ oldIndex: from,
10
+ newIndex: to,
11
+ } as any;
12
+ const element = {} as HTMLElement;
13
+
14
+ return { event, element, row };
15
+ };
16
+
17
+ describe('DragGrid', () => {
18
+ describe('constructor()', () => {
19
+ it('create instance', () => {
20
+ const instance = new TekDragGrid({
21
+ name: 'DragGrid',
22
+ component: 'DragGrid',
23
+ orderColumnName: 'order',
24
+ });
25
+
26
+ expect(instance.orderColumnName).toBe('order');
27
+ expect(instance.orderMode).toBe('asc');
28
+
29
+ instance.orderColumnName = 'newOrder';
30
+ instance.orderMode = 'desc';
31
+
32
+ expect(instance.orderColumnName).toBe('newOrder');
33
+ expect(instance.orderMode).toBe('desc');
34
+ });
35
+ });
36
+
37
+ describe('onDragMove', () => {
38
+ it('should call onDragMove event', () => {
39
+ const onDragMove = jest.fn();
40
+
41
+ const instance = new TekDragGrid({
42
+ name: 'DragGrid',
43
+ component: 'DragGrid',
44
+ orderColumnName: 'order',
45
+ events: {
46
+ onDragMove,
47
+ },
48
+ });
49
+
50
+ const event = {} as Event;
51
+ const row = {};
52
+ const element = {} as HTMLElement;
53
+
54
+ instance.onDragMove(event, row, element);
55
+
56
+ expect(onDragMove).toHaveBeenCalled();
57
+ });
58
+ });
59
+
60
+ describe('onDragStart', () => {
61
+ it('should call onDragStart event', () => {
62
+ const onDragStart = jest.fn();
63
+
64
+ const instance = new TekDragGrid({
65
+ name: 'DragGrid',
66
+ component: 'DragGrid',
67
+ orderColumnName: 'order',
68
+ events: {
69
+ onDragStart,
70
+ },
71
+ });
72
+
73
+ const event = {} as Event;
74
+ const row = {};
75
+ const element = {} as HTMLElement;
76
+
77
+ instance.onDragStart(event, row, element);
78
+
79
+ expect(onDragStart).toHaveBeenCalled();
80
+ });
81
+ });
82
+
83
+ describe('onDragEnd()', () => {
84
+ it('when called, should change order columns of the rows', () => {
85
+ const instance = new TekDragGrid({
86
+ name: 'DragGrid',
87
+ component: 'DragGrid',
88
+ orderColumnName: 'order',
89
+ datasource: {
90
+ uniqueKey: 'id',
91
+ data: [
92
+ { id: 1, name: 'a', order: 0 },
93
+ { id: 2, name: 'b', order: 1 },
94
+ { id: 3, name: 'c', order: 2 },
95
+ { id: 4, name: 'd', order: 3 },
96
+ ],
97
+ },
98
+ });
99
+
100
+ const { event, row, element } = dragFromXToY(0, 1, instance.datasource.data);
101
+ instance.onDragEnd(event, row, element);
102
+
103
+ const editedrows = instance.getEditedRows();
104
+ expect(editedrows).toEqual(
105
+ expect.arrayContaining([
106
+ { id: 1, name: 'a', order: 1 },
107
+ { id: 2, name: 'b', order: 0 },
108
+ ]),
109
+ );
110
+ });
111
+ });
112
+ });