slick-table 1.1.5 → 1.1.7
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/dist/index.cjs.js +51 -51
- package/dist/index.es.js +736 -737
- package/dist/types/features/header-context-menu/model/consts/id.d.ts +1 -1
- package/dist/types/features/header-context-menu/ui/Title/Title.d.ts.map +1 -1
- package/dist/types/features/header-context-menu/ui/Title/Title.style.d.ts.map +1 -1
- package/dist/types/shared/lib/slickgrid/ui/SlickgridTable/lib/hooks/useGrid.d.ts.map +1 -1
- package/package.json +1 -1
- package/src/features/header-context-menu/model/consts/id.ts +1 -1
- package/src/features/header-context-menu/ui/HeaderContextMenu.style.ts +1 -1
- package/src/features/header-context-menu/ui/HeaderContextMenu.tsx +1 -1
- package/src/features/header-context-menu/ui/Title/Title.style.ts +2 -1
- package/src/features/header-context-menu/ui/Title/Title.tsx +5 -1
- package/src/shared/lib/slickgrid/ui/SlickgridTable/lib/hooks/useGrid.ts +15 -10
- package/src/entities/popup/ui/Overlay/Overlay.test.tsx +0 -19
- package/src/shared/lib/slickgrid/lib/grouping/formatterGroupTotals.test.ts +0 -59
- package/src/shared/lib/slickgrid/model/SlickTable/filters/Filter.test.ts +0 -80
- package/src/shared/lib/slickgrid/model/SlickTable/filters/decorators/ColumnFilter/DecoratorColumnFilter.test.ts +0 -216
- package/src/shared/lib/slickgrid/model/SlickTable/filters/decorators/ColumnFilter/Filter.test.ts +0 -264
- package/src/shared/lib/slickgrid/model/SlickTable/filters/decorators/DecoratorFilter.test.ts +0 -139
- package/src/shared/lib/slickgrid/model/SlickTable/printer/DefaultPrinter.test.ts +0 -226
- package/src/shared/lib/slickgrid/model/SlickTable/table/SlickTable.test.ts +0 -72
package/src/shared/lib/slickgrid/model/SlickTable/filters/decorators/ColumnFilter/Filter.test.ts
DELETED
|
@@ -1,264 +0,0 @@
|
|
|
1
|
-
import { EColumnFilter } from "shared/model/enums";
|
|
2
|
-
|
|
3
|
-
import { filter } from "./Filter";
|
|
4
|
-
|
|
5
|
-
describe("Filter", () => {
|
|
6
|
-
const spring = "2024-03-20",
|
|
7
|
-
summer = "2024-06-21",
|
|
8
|
-
automn = "2024-09-23",
|
|
9
|
-
winter = "2024-12-21";
|
|
10
|
-
|
|
11
|
-
it("should filter EColumnFilter.Boolean", () => {
|
|
12
|
-
const trueResult = filter.passed(
|
|
13
|
-
"1",
|
|
14
|
-
{ 1: "true", 2: "" },
|
|
15
|
-
EColumnFilter.Boolean,
|
|
16
|
-
);
|
|
17
|
-
const falseResult = filter.passed(
|
|
18
|
-
"0",
|
|
19
|
-
{ 1: "", 2: "false" },
|
|
20
|
-
EColumnFilter.Boolean,
|
|
21
|
-
);
|
|
22
|
-
const falseResult_ = filter.passed(
|
|
23
|
-
"10",
|
|
24
|
-
{ 1: "", 2: "false" },
|
|
25
|
-
EColumnFilter.Boolean,
|
|
26
|
-
);
|
|
27
|
-
const emptyResult = filter.passed(
|
|
28
|
-
"",
|
|
29
|
-
{ 1: "", 2: "false" },
|
|
30
|
-
EColumnFilter.Boolean,
|
|
31
|
-
);
|
|
32
|
-
const defaultResult = filter.passed(
|
|
33
|
-
"0",
|
|
34
|
-
{ 1: "", 2: "" },
|
|
35
|
-
EColumnFilter.Boolean,
|
|
36
|
-
);
|
|
37
|
-
|
|
38
|
-
expect(trueResult).toBe(true);
|
|
39
|
-
expect(falseResult).toBe(true);
|
|
40
|
-
expect(falseResult_).toBe(false);
|
|
41
|
-
expect(emptyResult).toBe(true);
|
|
42
|
-
expect(defaultResult).toBe(true);
|
|
43
|
-
});
|
|
44
|
-
|
|
45
|
-
it("should filter EColumnFilter.DateBetween", () => {
|
|
46
|
-
const between = filter.passed(
|
|
47
|
-
summer,
|
|
48
|
-
{ 1: spring, 2: automn },
|
|
49
|
-
EColumnFilter.DateBetween,
|
|
50
|
-
);
|
|
51
|
-
const before = filter.passed(
|
|
52
|
-
summer,
|
|
53
|
-
{ 1: automn, 2: winter },
|
|
54
|
-
EColumnFilter.DateBetween,
|
|
55
|
-
);
|
|
56
|
-
const after = filter.passed(
|
|
57
|
-
winter,
|
|
58
|
-
{ 1: spring, 2: automn },
|
|
59
|
-
EColumnFilter.DateBetween,
|
|
60
|
-
);
|
|
61
|
-
|
|
62
|
-
const before2 = filter.passed(
|
|
63
|
-
winter,
|
|
64
|
-
{ 1: spring, 2: "" },
|
|
65
|
-
EColumnFilter.DateBetween,
|
|
66
|
-
);
|
|
67
|
-
const after2 = filter.passed(
|
|
68
|
-
winter,
|
|
69
|
-
{ 1: "", 2: automn },
|
|
70
|
-
EColumnFilter.DateBetween,
|
|
71
|
-
);
|
|
72
|
-
|
|
73
|
-
expect(between).toBe(true);
|
|
74
|
-
expect(before).toBe(false);
|
|
75
|
-
expect(after).toBe(false);
|
|
76
|
-
expect(before2).toBe(true);
|
|
77
|
-
expect(after2).toBe(false);
|
|
78
|
-
});
|
|
79
|
-
|
|
80
|
-
it("should filter EColumnFilter.DateEqual", () => {
|
|
81
|
-
const dateEqual = filter.passed(
|
|
82
|
-
summer,
|
|
83
|
-
{ 1: summer, 2: "" },
|
|
84
|
-
EColumnFilter.DateEqual,
|
|
85
|
-
);
|
|
86
|
-
const dateNotEqual = filter.passed(
|
|
87
|
-
summer,
|
|
88
|
-
{ 1: winter, 2: "" },
|
|
89
|
-
EColumnFilter.DateEqual,
|
|
90
|
-
);
|
|
91
|
-
|
|
92
|
-
expect(dateEqual).toBe(true);
|
|
93
|
-
expect(dateNotEqual).toBe(false);
|
|
94
|
-
});
|
|
95
|
-
|
|
96
|
-
it("should filter EColumnFilter.DateTo", () => {
|
|
97
|
-
const dateBefore = filter.passed(
|
|
98
|
-
spring,
|
|
99
|
-
{ 1: summer, 2: "" },
|
|
100
|
-
EColumnFilter.DateTo,
|
|
101
|
-
);
|
|
102
|
-
const sameDay = filter.passed(
|
|
103
|
-
summer,
|
|
104
|
-
{ 1: summer, 2: "" },
|
|
105
|
-
EColumnFilter.DateTo,
|
|
106
|
-
);
|
|
107
|
-
const dateAfter = filter.passed(
|
|
108
|
-
summer,
|
|
109
|
-
{ 1: spring, 2: "" },
|
|
110
|
-
EColumnFilter.DateTo,
|
|
111
|
-
);
|
|
112
|
-
|
|
113
|
-
expect(dateBefore).toBe(true);
|
|
114
|
-
expect(sameDay).toBe(true);
|
|
115
|
-
expect(dateAfter).toBe(false);
|
|
116
|
-
});
|
|
117
|
-
|
|
118
|
-
it("should filter EColumnFilter.DateFrom", () => {
|
|
119
|
-
const dateBefore = filter.passed(
|
|
120
|
-
spring,
|
|
121
|
-
{ 1: summer, 2: "" },
|
|
122
|
-
EColumnFilter.DateFrom,
|
|
123
|
-
);
|
|
124
|
-
const sameDay = filter.passed(
|
|
125
|
-
summer,
|
|
126
|
-
{ 1: summer, 2: "" },
|
|
127
|
-
EColumnFilter.DateFrom,
|
|
128
|
-
);
|
|
129
|
-
const dateAfter = filter.passed(
|
|
130
|
-
summer,
|
|
131
|
-
{ 1: spring, 2: "" },
|
|
132
|
-
EColumnFilter.DateFrom,
|
|
133
|
-
);
|
|
134
|
-
|
|
135
|
-
expect(dateBefore).toBe(false);
|
|
136
|
-
expect(sameDay).toBe(true);
|
|
137
|
-
expect(dateAfter).toBe(true);
|
|
138
|
-
});
|
|
139
|
-
|
|
140
|
-
it("should filter EColumnFilter.NumberBetween", () => {
|
|
141
|
-
const value = { 1: "25", 2: "75" };
|
|
142
|
-
const result1 = filter.passed("50", value, EColumnFilter.NumberBetween);
|
|
143
|
-
const result2 = filter.passed("20", value, EColumnFilter.NumberBetween);
|
|
144
|
-
const result3 = filter.passed("80", value, EColumnFilter.NumberBetween);
|
|
145
|
-
|
|
146
|
-
const result4 = filter.passed(
|
|
147
|
-
"20",
|
|
148
|
-
{ 1: "", 2: "50" },
|
|
149
|
-
EColumnFilter.NumberBetween,
|
|
150
|
-
);
|
|
151
|
-
|
|
152
|
-
const result5 = filter.passed(
|
|
153
|
-
"20",
|
|
154
|
-
{ 1: "10", 2: "" },
|
|
155
|
-
EColumnFilter.NumberBetween,
|
|
156
|
-
);
|
|
157
|
-
|
|
158
|
-
expect(result1).toBe(true);
|
|
159
|
-
expect(result2).toBe(false);
|
|
160
|
-
expect(result3).toBe(false);
|
|
161
|
-
expect(result4).toBe(true);
|
|
162
|
-
expect(result5).toBe(true);
|
|
163
|
-
});
|
|
164
|
-
|
|
165
|
-
it("should filter EColumnFilter.NumberFrom", () => {
|
|
166
|
-
const value = { 1: "25", 2: "" };
|
|
167
|
-
const result1 = filter.passed("50", value, EColumnFilter.NumberFrom);
|
|
168
|
-
const result2 = filter.passed("25", value, EColumnFilter.NumberFrom);
|
|
169
|
-
const result3 = filter.passed("20", value, EColumnFilter.NumberFrom);
|
|
170
|
-
|
|
171
|
-
expect(result1).toBe(true);
|
|
172
|
-
expect(result2).toBe(true);
|
|
173
|
-
expect(result3).toBe(false);
|
|
174
|
-
});
|
|
175
|
-
|
|
176
|
-
it("should filter EColumnFilter.NumberTo", () => {
|
|
177
|
-
const value = { 1: "25", 2: "" };
|
|
178
|
-
const result1 = filter.passed("50", value, EColumnFilter.NumberTo);
|
|
179
|
-
const result2 = filter.passed("25", value, EColumnFilter.NumberTo);
|
|
180
|
-
const result3 = filter.passed("20", value, EColumnFilter.NumberTo);
|
|
181
|
-
|
|
182
|
-
expect(result1).toBe(false);
|
|
183
|
-
expect(result2).toBe(true);
|
|
184
|
-
expect(result3).toBe(true);
|
|
185
|
-
});
|
|
186
|
-
|
|
187
|
-
it("should filter EColumnFilter.NumberEqual", () => {
|
|
188
|
-
const value = { 1: "25", 2: "" };
|
|
189
|
-
const result1 = filter.passed("50", value, EColumnFilter.NumberEqual);
|
|
190
|
-
const result2 = filter.passed("25", value, EColumnFilter.NumberEqual);
|
|
191
|
-
const result3 = filter.passed("20", value, EColumnFilter.NumberEqual);
|
|
192
|
-
|
|
193
|
-
expect(result1).toBe(false);
|
|
194
|
-
expect(result2).toBe(true);
|
|
195
|
-
expect(result3).toBe(false);
|
|
196
|
-
});
|
|
197
|
-
|
|
198
|
-
it("should filter EColumnFilter.TextEqual", () => {
|
|
199
|
-
const value = { 1: "hello world", 2: "" };
|
|
200
|
-
const result1 = filter.passed(
|
|
201
|
-
"Hello World",
|
|
202
|
-
value,
|
|
203
|
-
EColumnFilter.TextEqual,
|
|
204
|
-
);
|
|
205
|
-
const result2 = filter.passed(
|
|
206
|
-
"HELLO WORLD",
|
|
207
|
-
value,
|
|
208
|
-
EColumnFilter.TextEqual,
|
|
209
|
-
);
|
|
210
|
-
const result3 = filter.passed(
|
|
211
|
-
"Goodbye World",
|
|
212
|
-
value,
|
|
213
|
-
EColumnFilter.TextEqual,
|
|
214
|
-
);
|
|
215
|
-
|
|
216
|
-
expect(result1).toBe(true);
|
|
217
|
-
expect(result2).toBe(true);
|
|
218
|
-
expect(result3).toBe(false);
|
|
219
|
-
});
|
|
220
|
-
|
|
221
|
-
it("should filter EColumnFilter.TextNotEqual", () => {
|
|
222
|
-
const value = { 1: "hello world", 2: "" };
|
|
223
|
-
const result1 = filter.passed(
|
|
224
|
-
"Hello World",
|
|
225
|
-
value,
|
|
226
|
-
EColumnFilter.TextNotEqual,
|
|
227
|
-
);
|
|
228
|
-
const result2 = filter.passed(
|
|
229
|
-
"HELLO WORLD",
|
|
230
|
-
value,
|
|
231
|
-
EColumnFilter.TextNotEqual,
|
|
232
|
-
);
|
|
233
|
-
const result3 = filter.passed(
|
|
234
|
-
"Goodbye World",
|
|
235
|
-
value,
|
|
236
|
-
EColumnFilter.TextNotEqual,
|
|
237
|
-
);
|
|
238
|
-
|
|
239
|
-
expect(result1).toBe(false);
|
|
240
|
-
expect(result2).toBe(false);
|
|
241
|
-
expect(result3).toBe(true);
|
|
242
|
-
});
|
|
243
|
-
|
|
244
|
-
it("should filter EColumnFilter.TextContain (returns an array of matching string)", () => {
|
|
245
|
-
const string = "any value",
|
|
246
|
-
matching = "an";
|
|
247
|
-
const result = filter.passed(
|
|
248
|
-
string,
|
|
249
|
-
{ 1: matching, 2: "" },
|
|
250
|
-
EColumnFilter.TextContain,
|
|
251
|
-
);
|
|
252
|
-
|
|
253
|
-
expect(result).toBeTruthy();
|
|
254
|
-
});
|
|
255
|
-
|
|
256
|
-
it("should filter EColumnFilter.TextNotContain", () => {
|
|
257
|
-
const result = filter.passed(
|
|
258
|
-
"any value",
|
|
259
|
-
{ 1: " val", 2: "" },
|
|
260
|
-
EColumnFilter.TextNotContain,
|
|
261
|
-
);
|
|
262
|
-
expect(result).toBe(false);
|
|
263
|
-
});
|
|
264
|
-
});
|
package/src/shared/lib/slickgrid/model/SlickTable/filters/decorators/DecoratorFilter.test.ts
DELETED
|
@@ -1,139 +0,0 @@
|
|
|
1
|
-
import { SlickGrid } from "slickgrid";
|
|
2
|
-
|
|
3
|
-
import { ISlickRow } from "shared/model/types";
|
|
4
|
-
import { IFilter } from "shared/model/types";
|
|
5
|
-
|
|
6
|
-
import { SlickTable } from "../../table";
|
|
7
|
-
import { DecoratorFilter } from "./DecoratorFilter";
|
|
8
|
-
|
|
9
|
-
class TestDecoratorFilter extends DecoratorFilter {
|
|
10
|
-
filterFn(): boolean {
|
|
11
|
-
return true;
|
|
12
|
-
}
|
|
13
|
-
}
|
|
14
|
-
|
|
15
|
-
describe("DecoratorFilter", () => {
|
|
16
|
-
let decoratorFilter: TestDecoratorFilter;
|
|
17
|
-
let mockFilter: IFilter;
|
|
18
|
-
|
|
19
|
-
beforeEach(() => {
|
|
20
|
-
mockFilter = {
|
|
21
|
-
getFilterFn: jest.fn(),
|
|
22
|
-
reset: jest.fn(),
|
|
23
|
-
print: jest.fn(),
|
|
24
|
-
args: {},
|
|
25
|
-
grid: {} as SlickGrid,
|
|
26
|
-
tableId: "test-table",
|
|
27
|
-
} as unknown as IFilter;
|
|
28
|
-
|
|
29
|
-
decoratorFilter = new TestDecoratorFilter(mockFilter);
|
|
30
|
-
});
|
|
31
|
-
|
|
32
|
-
it("should combine the decorator's filterFn with the wrapped filter's filterFn", () => {
|
|
33
|
-
jest
|
|
34
|
-
.spyOn(mockFilter, "getFilterFn")
|
|
35
|
-
.mockReturnValue((row) => row.id % 2 === 0);
|
|
36
|
-
|
|
37
|
-
jest
|
|
38
|
-
.spyOn(decoratorFilter, "filterFn")
|
|
39
|
-
.mockImplementation((row: ISlickRow) => row.value > 10);
|
|
40
|
-
|
|
41
|
-
const combinedFilterFn = decoratorFilter.getFilterFn();
|
|
42
|
-
|
|
43
|
-
const row1 = { id: 1, value: 15 };
|
|
44
|
-
const row2 = { id: 2, value: 5 };
|
|
45
|
-
const row3 = { id: 3, value: 20 };
|
|
46
|
-
const row4 = { id: 4, value: 25 };
|
|
47
|
-
|
|
48
|
-
expect(combinedFilterFn(row1, {})).toBe(false);
|
|
49
|
-
expect(combinedFilterFn(row2, {})).toBe(false);
|
|
50
|
-
expect(combinedFilterFn(row3, {})).toBe(false);
|
|
51
|
-
expect(combinedFilterFn(row4, {})).toBe(true);
|
|
52
|
-
|
|
53
|
-
expect(mockFilter.getFilterFn).toHaveBeenCalledTimes(1);
|
|
54
|
-
});
|
|
55
|
-
|
|
56
|
-
it("should set and get args through the decorator", () => {
|
|
57
|
-
const testArgs = { key: "value" };
|
|
58
|
-
|
|
59
|
-
decoratorFilter.args = testArgs;
|
|
60
|
-
expect(decoratorFilter.args).toEqual(testArgs);
|
|
61
|
-
expect(mockFilter.args).toEqual(testArgs);
|
|
62
|
-
|
|
63
|
-
const retrievedArgs = decoratorFilter.args;
|
|
64
|
-
|
|
65
|
-
expect(retrievedArgs).toEqual(testArgs);
|
|
66
|
-
});
|
|
67
|
-
|
|
68
|
-
it("should set and get grid through the decorator", () => {
|
|
69
|
-
mockFilter.grid = null;
|
|
70
|
-
decoratorFilter = new TestDecoratorFilter(mockFilter);
|
|
71
|
-
const testGrid = {} as SlickGrid;
|
|
72
|
-
decoratorFilter.grid = testGrid;
|
|
73
|
-
|
|
74
|
-
expect(decoratorFilter.grid).toBe(testGrid);
|
|
75
|
-
expect(mockFilter.grid).toBe(testGrid);
|
|
76
|
-
|
|
77
|
-
const retrievedGrid = decoratorFilter.grid;
|
|
78
|
-
|
|
79
|
-
expect(retrievedGrid).toBe(testGrid);
|
|
80
|
-
});
|
|
81
|
-
|
|
82
|
-
it("should set and get tableId through the decorator", () => {
|
|
83
|
-
const testTableId = "test-table-id";
|
|
84
|
-
|
|
85
|
-
mockFilter.tableId = "";
|
|
86
|
-
decoratorFilter.tableId = testTableId;
|
|
87
|
-
|
|
88
|
-
expect(decoratorFilter.tableId).toBe(testTableId);
|
|
89
|
-
expect(mockFilter.tableId).toBe(testTableId);
|
|
90
|
-
|
|
91
|
-
const retrievedTableId = decoratorFilter.tableId;
|
|
92
|
-
expect(retrievedTableId).toBe(testTableId);
|
|
93
|
-
});
|
|
94
|
-
|
|
95
|
-
it("should register the filter with the grid and apply it to the data view", () => {
|
|
96
|
-
mockFilter.args = { testArg: "value" };
|
|
97
|
-
mockFilter.grid = null;
|
|
98
|
-
jest.spyOn(mockFilter, "getFilterFn").mockReturnValue(() => true);
|
|
99
|
-
|
|
100
|
-
const mockDataView = {
|
|
101
|
-
setFilter: jest.fn(),
|
|
102
|
-
setFilterArgs: jest.fn(),
|
|
103
|
-
refresh: jest.fn(),
|
|
104
|
-
};
|
|
105
|
-
|
|
106
|
-
const mockGrid = {
|
|
107
|
-
getData: jest.fn().mockReturnValue(mockDataView),
|
|
108
|
-
} as unknown as SlickGrid;
|
|
109
|
-
|
|
110
|
-
decoratorFilter.register(mockGrid, "test-table-id");
|
|
111
|
-
|
|
112
|
-
expect(decoratorFilter.tableId).toBe("test-table-id");
|
|
113
|
-
expect(decoratorFilter.grid).toBe(mockGrid);
|
|
114
|
-
expect(mockGrid.getData).toHaveBeenCalled();
|
|
115
|
-
expect(mockDataView.setFilter).toHaveBeenCalledWith(expect.any(Function));
|
|
116
|
-
expect(mockDataView.setFilterArgs).toHaveBeenCalledWith(mockFilter.args);
|
|
117
|
-
expect(mockDataView.refresh).toHaveBeenCalled();
|
|
118
|
-
});
|
|
119
|
-
|
|
120
|
-
it("should return the wrapped filter's print result when print is called", () => {
|
|
121
|
-
const mockTable = {} as SlickTable;
|
|
122
|
-
const mockPrintResult = [
|
|
123
|
-
document.createElement("tr"),
|
|
124
|
-
document.createElement("tr"),
|
|
125
|
-
];
|
|
126
|
-
|
|
127
|
-
jest.spyOn(mockFilter, "print").mockReturnValue(mockPrintResult);
|
|
128
|
-
const result = decoratorFilter.print(mockTable);
|
|
129
|
-
|
|
130
|
-
expect(mockFilter.print).toHaveBeenCalledWith(mockTable);
|
|
131
|
-
expect(result).toBe(mockPrintResult);
|
|
132
|
-
});
|
|
133
|
-
|
|
134
|
-
it("should reset both the decorator and the wrapped filter when reset is called", () => {
|
|
135
|
-
decoratorFilter.reset();
|
|
136
|
-
|
|
137
|
-
expect(mockFilter.reset).toHaveBeenCalledTimes(1);
|
|
138
|
-
});
|
|
139
|
-
});
|
|
@@ -1,226 +0,0 @@
|
|
|
1
|
-
import { SlickGrid } from "slickgrid";
|
|
2
|
-
|
|
3
|
-
import { injectStore } from "shared/model/redux";
|
|
4
|
-
|
|
5
|
-
// eslint-disable-next-line import/no-internal-modules
|
|
6
|
-
import * as getDisplayedRowsModule from "../../../lib/functions/getDisplayedRows";
|
|
7
|
-
import { SlickTable } from "../table";
|
|
8
|
-
import { DefaultPrinter } from "./DefaultPrinter";
|
|
9
|
-
import { Printer } from "./model";
|
|
10
|
-
|
|
11
|
-
jest.mock("app/store/store");
|
|
12
|
-
|
|
13
|
-
describe("shared | slickgrid | DefaultPrinter", () => {
|
|
14
|
-
let defaultPrinter: Printer;
|
|
15
|
-
let mockTable: SlickTable;
|
|
16
|
-
let mockStore: any;
|
|
17
|
-
|
|
18
|
-
beforeEach(() => {
|
|
19
|
-
defaultPrinter = new DefaultPrinter();
|
|
20
|
-
mockTable = {
|
|
21
|
-
id: "mock_table",
|
|
22
|
-
name: "Mock Table",
|
|
23
|
-
grid: {
|
|
24
|
-
getColumns: jest.fn().mockReturnValue([]),
|
|
25
|
-
getData: jest.fn().mockReturnValue({
|
|
26
|
-
getItem: jest.fn(),
|
|
27
|
-
getItemMetadata: jest.fn(),
|
|
28
|
-
}),
|
|
29
|
-
} as unknown as SlickGrid,
|
|
30
|
-
} as unknown as SlickTable;
|
|
31
|
-
|
|
32
|
-
mockStore = {
|
|
33
|
-
getState: jest.fn().mockReturnValue({
|
|
34
|
-
client: {
|
|
35
|
-
clientInfo: {
|
|
36
|
-
value: "Test Client",
|
|
37
|
-
},
|
|
38
|
-
},
|
|
39
|
-
}),
|
|
40
|
-
};
|
|
41
|
-
injectStore(mockStore);
|
|
42
|
-
});
|
|
43
|
-
|
|
44
|
-
it("should create a client name row with correct colspan when client name is provided", () => {
|
|
45
|
-
const instance = new DefaultPrinter();
|
|
46
|
-
const result = instance.clientName();
|
|
47
|
-
|
|
48
|
-
expect(result.tagName).toBe("TR");
|
|
49
|
-
expect(result.children.length).toBe(1);
|
|
50
|
-
expect(result.children[0].tagName).toBe("TH");
|
|
51
|
-
expect(result.children[0].classList.contains("client")).toBe(true);
|
|
52
|
-
expect(result.children[0].getAttribute("colspan")).toBe("4");
|
|
53
|
-
expect(result.children[0].innerText).toBe("Test Client");
|
|
54
|
-
});
|
|
55
|
-
|
|
56
|
-
it("should generate column names row with correct number of columns based on 'forPrint' property", () => {
|
|
57
|
-
const mockColumns = [
|
|
58
|
-
{ name: "Column 1", forPrint: true },
|
|
59
|
-
{ name: "Column 2", forPrint: false },
|
|
60
|
-
{ name: "Column 3", forPrint: true },
|
|
61
|
-
{ name: "Column 4", forPrint: true },
|
|
62
|
-
];
|
|
63
|
-
jest.spyOn(mockTable.grid, "getColumns").mockReturnValue(mockColumns);
|
|
64
|
-
const result = defaultPrinter.columnNames(mockTable);
|
|
65
|
-
|
|
66
|
-
expect(result.tagName).toBe("TR");
|
|
67
|
-
expect(result.children.length).toBe(3);
|
|
68
|
-
expect(
|
|
69
|
-
Array.from(result.children).every((child) => child.tagName === "TH"),
|
|
70
|
-
).toBe(true);
|
|
71
|
-
expect(
|
|
72
|
-
Array.from(result.children).every((child) =>
|
|
73
|
-
child.classList.contains("column_name"),
|
|
74
|
-
),
|
|
75
|
-
).toBe(true);
|
|
76
|
-
expect(result.children[0].innerText).toBe("Column 1");
|
|
77
|
-
expect(result.children[1].innerText).toBe("Column 3");
|
|
78
|
-
expect(result.children[2].innerText).toBe("Column 4");
|
|
79
|
-
});
|
|
80
|
-
|
|
81
|
-
it("should create table name and time row with current date in correct format", () => {
|
|
82
|
-
mockTable.name = "Test Table";
|
|
83
|
-
|
|
84
|
-
const result = defaultPrinter.tableNameAndTime(mockTable);
|
|
85
|
-
|
|
86
|
-
expect(result.tagName).toBe("TR");
|
|
87
|
-
expect(result.classList.contains("heading")).toBe(true);
|
|
88
|
-
expect(result.children.length).toBe(2);
|
|
89
|
-
|
|
90
|
-
const tableName = result.children[0] as HTMLTableCellElement;
|
|
91
|
-
expect(tableName.tagName).toBe("TH");
|
|
92
|
-
expect(tableName.getAttribute("colspan")).toBe("2");
|
|
93
|
-
expect(tableName.classList.contains("table_name")).toBe(true);
|
|
94
|
-
expect(tableName.innerText).toBe(mockTable.name);
|
|
95
|
-
|
|
96
|
-
const dateStamp = result.children[1] as HTMLTableCellElement;
|
|
97
|
-
expect(dateStamp.tagName).toBe("TH");
|
|
98
|
-
expect(dateStamp.getAttribute("colspan")).toBe("100%");
|
|
99
|
-
expect(dateStamp.classList.contains("date_stamp")).toBe(true);
|
|
100
|
-
|
|
101
|
-
const dateRegex = /^\d{2}\/\d{2}\/\d{4} \d{1,2}:\d{2} (AM|PM)$/;
|
|
102
|
-
expect(dateRegex.test(dateStamp.innerText)).toBe(true);
|
|
103
|
-
});
|
|
104
|
-
|
|
105
|
-
it("should create table body with correct number of rows and columns based on displayed data", () => {
|
|
106
|
-
const mockColumns = [
|
|
107
|
-
{ name: "Column 1", forPrint: true },
|
|
108
|
-
{ name: "Column 2", forPrint: false },
|
|
109
|
-
{ name: "Column 3", forPrint: true },
|
|
110
|
-
];
|
|
111
|
-
const mockDisplayedRows = [
|
|
112
|
-
{ id: 1, col1: "Value 1", col3: "Value 3" },
|
|
113
|
-
{ id: 2, col1: "Value 4", col3: "Value 6" },
|
|
114
|
-
];
|
|
115
|
-
const mockDataView = {
|
|
116
|
-
getItem: jest.fn((index) => mockDisplayedRows[index]),
|
|
117
|
-
getItemMetadata: jest.fn(),
|
|
118
|
-
};
|
|
119
|
-
|
|
120
|
-
// @ts-ignore
|
|
121
|
-
jest.spyOn(mockTable.grid, "getColumns").mockReturnValue(mockColumns);
|
|
122
|
-
// @ts-ignore
|
|
123
|
-
jest.spyOn(mockTable.grid, "getData").mockReturnValue(mockDataView);
|
|
124
|
-
|
|
125
|
-
jest.spyOn(defaultPrinter, "createTr").mockImplementation(() => {
|
|
126
|
-
const tr = document.createElement("tr");
|
|
127
|
-
tr.innerHTML = "<td></td><td></td>";
|
|
128
|
-
return tr;
|
|
129
|
-
});
|
|
130
|
-
jest.spyOn(defaultPrinter, "totals").mockReturnValue([]);
|
|
131
|
-
|
|
132
|
-
jest
|
|
133
|
-
.spyOn(getDisplayedRowsModule, "getDisplayedRows")
|
|
134
|
-
.mockImplementation(jest.fn())
|
|
135
|
-
.mockReturnValue(mockDisplayedRows);
|
|
136
|
-
|
|
137
|
-
const result = defaultPrinter.createTbody(mockTable);
|
|
138
|
-
|
|
139
|
-
expect(result.tagName).toBe("TBODY");
|
|
140
|
-
expect(result.children.length).toBe(2);
|
|
141
|
-
expect(result.children[0].children.length).toBe(2);
|
|
142
|
-
expect(result.children[1].children.length).toBe(2);
|
|
143
|
-
expect(defaultPrinter.totals).toHaveBeenCalledWith(mockTable);
|
|
144
|
-
expect(getDisplayedRowsModule.getDisplayedRows).toHaveBeenCalledWith(
|
|
145
|
-
mockDataView,
|
|
146
|
-
);
|
|
147
|
-
});
|
|
148
|
-
|
|
149
|
-
it("should create filters row when table has filters", () => {
|
|
150
|
-
const mockTable: SlickTable = {
|
|
151
|
-
filter: {
|
|
152
|
-
print: jest
|
|
153
|
-
.fn()
|
|
154
|
-
.mockReturnValue([
|
|
155
|
-
document.createElement("tr"),
|
|
156
|
-
document.createElement("tr"),
|
|
157
|
-
]),
|
|
158
|
-
},
|
|
159
|
-
} as unknown as SlickTable;
|
|
160
|
-
|
|
161
|
-
const result = defaultPrinter.filters(mockTable);
|
|
162
|
-
|
|
163
|
-
expect(result.length).toBe(3);
|
|
164
|
-
expect(result[0].tagName).toBe("TR");
|
|
165
|
-
expect(result[0].children[0].tagName).toBe("TH");
|
|
166
|
-
expect(result[0].children[0].getAttribute("colspan")).toBe("100%");
|
|
167
|
-
expect(result[0].children[0].classList.contains("client")).toBe(true);
|
|
168
|
-
expect(result[0].children[0].innerText).toBe("Applied filters");
|
|
169
|
-
expect(result[1].tagName).toBe("TR");
|
|
170
|
-
expect(result[2].tagName).toBe("TR");
|
|
171
|
-
expect(mockTable.filter.print).toHaveBeenCalledWith(mockTable);
|
|
172
|
-
});
|
|
173
|
-
|
|
174
|
-
it("should create a table element with correct structure and content", () => {
|
|
175
|
-
jest
|
|
176
|
-
.spyOn(defaultPrinter, "createThead")
|
|
177
|
-
.mockReturnValue(document.createElement("thead"));
|
|
178
|
-
jest
|
|
179
|
-
.spyOn(defaultPrinter, "createTbody")
|
|
180
|
-
.mockReturnValue(document.createElement("tbody"));
|
|
181
|
-
|
|
182
|
-
const result = defaultPrinter.createTableElement(mockTable);
|
|
183
|
-
|
|
184
|
-
expect(result.tagName).toBe("TABLE");
|
|
185
|
-
expect(result.children.length).toBe(2);
|
|
186
|
-
expect(result.children[0].tagName).toBe("THEAD");
|
|
187
|
-
expect(result.children[1].tagName).toBe("TBODY");
|
|
188
|
-
expect(defaultPrinter.createThead).toHaveBeenCalledWith(mockTable);
|
|
189
|
-
expect(defaultPrinter.createTbody).toHaveBeenCalledWith(mockTable);
|
|
190
|
-
});
|
|
191
|
-
|
|
192
|
-
it("should handle group titles in createTr method", () => {
|
|
193
|
-
const mockColumns = [
|
|
194
|
-
{ name: "Column 1", field: "col1", forPrint: true },
|
|
195
|
-
{ name: "Column 2", field: "col2", forPrint: true },
|
|
196
|
-
];
|
|
197
|
-
const mockRowIndex = 0;
|
|
198
|
-
const mockGrid = {
|
|
199
|
-
getData: jest.fn().mockReturnValue({
|
|
200
|
-
getItem: jest.fn().mockReturnValue({
|
|
201
|
-
__group: true,
|
|
202
|
-
title: "Group Title <span>with HTML</span>",
|
|
203
|
-
}),
|
|
204
|
-
getItemMetadata: jest.fn(),
|
|
205
|
-
}),
|
|
206
|
-
} as unknown as SlickGrid;
|
|
207
|
-
|
|
208
|
-
const result = defaultPrinter.createTr(mockColumns, mockRowIndex, mockGrid);
|
|
209
|
-
|
|
210
|
-
expect(result.tagName).toBe("TR");
|
|
211
|
-
expect(result.children.length).toBe(1);
|
|
212
|
-
expect(result.children[0].tagName).toBe("TD");
|
|
213
|
-
expect(result.children[0].getAttribute("colspan")).toBe("100%");
|
|
214
|
-
expect(result.children[0].innerText).toBe("Group Title with HTML");
|
|
215
|
-
});
|
|
216
|
-
|
|
217
|
-
it("should return an empty array for totals method in DefaultPrinter", () => {
|
|
218
|
-
mockTable = {} as SlickTable;
|
|
219
|
-
|
|
220
|
-
const result = defaultPrinter.totals(mockTable);
|
|
221
|
-
|
|
222
|
-
expect(result).toEqual([]);
|
|
223
|
-
expect(Array.isArray(result)).toBe(true);
|
|
224
|
-
expect(result.length).toBe(0);
|
|
225
|
-
});
|
|
226
|
-
});
|
|
@@ -1,72 +0,0 @@
|
|
|
1
|
-
import { SlickGrid } from "slickgrid";
|
|
2
|
-
|
|
3
|
-
import { IFilter, WithoutFilter } from "../filters";
|
|
4
|
-
import { DefaultPrinter, Printer } from "../printer";
|
|
5
|
-
import { SlickTable } from "./SlickTable";
|
|
6
|
-
|
|
7
|
-
jest.mock("app/store/store");
|
|
8
|
-
|
|
9
|
-
describe("SlickTable", () => {
|
|
10
|
-
let slickTable: SlickTable;
|
|
11
|
-
|
|
12
|
-
beforeEach(() => {
|
|
13
|
-
slickTable = new SlickTable({ id: "test-table" });
|
|
14
|
-
});
|
|
15
|
-
|
|
16
|
-
it("should create a SlickTable instance with default values when only 'id' is provided", () => {
|
|
17
|
-
expect(slickTable.id).toBe("test-table");
|
|
18
|
-
expect(slickTable.name).toBe("");
|
|
19
|
-
expect(slickTable.printer).toBeInstanceOf(DefaultPrinter);
|
|
20
|
-
expect(slickTable.filter).toBeInstanceOf(WithoutFilter);
|
|
21
|
-
});
|
|
22
|
-
|
|
23
|
-
it("should return null for grid property before createGrid is called", () => {
|
|
24
|
-
expect(slickTable.grid).toBeNull();
|
|
25
|
-
});
|
|
26
|
-
|
|
27
|
-
it("should return false for isReady property before createGrid is called", () => {
|
|
28
|
-
expect(slickTable.isReady).toBeFalsy();
|
|
29
|
-
expect(slickTable.isReady).toEqual(false);
|
|
30
|
-
});
|
|
31
|
-
|
|
32
|
-
it("should return false for isEdited property before createGrid is called", () => {
|
|
33
|
-
expect(slickTable.isEdited).toBeFalsy();
|
|
34
|
-
expect(slickTable.isEdited).toEqual(false);
|
|
35
|
-
});
|
|
36
|
-
|
|
37
|
-
it("should correctly set custom name, filter, and printer when provided in constructor", () => {
|
|
38
|
-
const mockFilter = {} as IFilter;
|
|
39
|
-
const mockPrinter = {} as Printer;
|
|
40
|
-
const slickTable = new SlickTable({
|
|
41
|
-
id: "custom-table",
|
|
42
|
-
name: "Custom Table",
|
|
43
|
-
filter: mockFilter,
|
|
44
|
-
printer: mockPrinter,
|
|
45
|
-
});
|
|
46
|
-
|
|
47
|
-
expect(slickTable.id).toBe("custom-table");
|
|
48
|
-
expect(slickTable.name).toBe("Custom Table");
|
|
49
|
-
expect(slickTable.filter).toBe(mockFilter);
|
|
50
|
-
expect(slickTable.printer).toBe(mockPrinter);
|
|
51
|
-
});
|
|
52
|
-
|
|
53
|
-
it("should clear selected rows when reset() is called if a selection model exists", () => {
|
|
54
|
-
const mockGrid = {
|
|
55
|
-
onKeyDown: { unsubscribe: jest.fn() },
|
|
56
|
-
getSelectionModel: jest.fn().mockReturnValue(true),
|
|
57
|
-
setSelectedRows: jest.fn(),
|
|
58
|
-
} as unknown as SlickGrid;
|
|
59
|
-
|
|
60
|
-
slickTable.grid = mockGrid;
|
|
61
|
-
slickTable.isEdited = true;
|
|
62
|
-
|
|
63
|
-
expect(slickTable.isEdited).toBeTruthy();
|
|
64
|
-
expect(slickTable.grid).toEqual(mockGrid);
|
|
65
|
-
|
|
66
|
-
slickTable.reset();
|
|
67
|
-
|
|
68
|
-
expect(mockGrid.setSelectedRows).toHaveBeenCalledWith([]);
|
|
69
|
-
expect(slickTable.isEdited).toBeFalsy();
|
|
70
|
-
expect(slickTable.grid).toBeNull();
|
|
71
|
-
});
|
|
72
|
-
});
|