slick-table 1.1.6 → 1.1.8
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 +730 -732
- package/dist/types/shared/lib/slickgrid/ui/SlickgridTable/lib/hooks/useGrid.d.ts.map +1 -1
- package/package.json +1 -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
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useGrid.d.ts","sourceRoot":"","sources":["../../../../../../../../../src/shared/lib/slickgrid/ui/SlickgridTable/lib/hooks/useGrid.ts"],"names":[],"mappings":"AACA,OAAO,EACN,OAAO,EACP,oBAAoB,EACpB,qBAAqB,EAOrB,MAAM,WAAW,CAAC;AAYnB,OAAO,EAAE,KAAK,EAAkB,MAAM,aAAa,CAAC;AAEpD,wBAAgB,OAAO,CAAC,EACvB,aAAiC,EACjC,kBAAkB,EAClB,SAAiB,EACjB,YAAqB,EACrB,OAAO,EACP,eAAe,EACf,MAAM,EACN,cAAqB,EACrB,KAAK,EACL,WAAW,EACX,gBAAgB,EAChB,YAAY,EACZ,OAAO,EACP,UAAU,EACV,mBAAmB,EACnB,iBAAkC,EAClC,qBAAqB,EACrB,OAAY,EACZ,KAAK,GACL,EAAE,KAAK,GAAG;IACV,WAAW,EAAE,OAAO,CAAC,oBAAoB,CAAC,CAAC;IAC3C,YAAY,EAAE,OAAO,CAAC,qBAAqB,CAAC,CAAC;CAC7C,
|
|
1
|
+
{"version":3,"file":"useGrid.d.ts","sourceRoot":"","sources":["../../../../../../../../../src/shared/lib/slickgrid/ui/SlickgridTable/lib/hooks/useGrid.ts"],"names":[],"mappings":"AACA,OAAO,EACN,OAAO,EACP,oBAAoB,EACpB,qBAAqB,EAOrB,MAAM,WAAW,CAAC;AAYnB,OAAO,EAAE,KAAK,EAAkB,MAAM,aAAa,CAAC;AAEpD,wBAAgB,OAAO,CAAC,EACvB,aAAiC,EACjC,kBAAkB,EAClB,SAAiB,EACjB,YAAqB,EACrB,OAAO,EACP,eAAe,EACf,MAAM,EACN,cAAqB,EACrB,KAAK,EACL,WAAW,EACX,gBAAgB,EAChB,YAAY,EACZ,OAAO,EACP,UAAU,EACV,mBAAmB,EACnB,iBAAkC,EAClC,qBAAqB,EACrB,OAAY,EACZ,KAAK,GACL,EAAE,KAAK,GAAG;IACV,WAAW,EAAE,OAAO,CAAC,oBAAoB,CAAC,CAAC;IAC3C,YAAY,EAAE,OAAO,CAAC,qBAAqB,CAAC,CAAC;CAC7C,QAoHA"}
|
package/package.json
CHANGED
|
@@ -140,6 +140,21 @@ export function useGrid({
|
|
|
140
140
|
} else {
|
|
141
141
|
grid.setColumns(columns);
|
|
142
142
|
}
|
|
143
|
+
if (table.columnPicker) {
|
|
144
|
+
table.columnPicker.initialColumns = grid.getColumns();
|
|
145
|
+
if (!table.columnPicker.visibleColumnIds.length) {
|
|
146
|
+
table.columnPicker.visibleColumnIds = grid
|
|
147
|
+
.getColumns()
|
|
148
|
+
.map(({ id }) => id as string);
|
|
149
|
+
}
|
|
150
|
+
grid.setColumns(
|
|
151
|
+
grid.getColumns().filter(({ id }) => {
|
|
152
|
+
if (!table.columnPicker) return true;
|
|
153
|
+
if (!table.columnPicker.visibleColumnIds.length) return true;
|
|
154
|
+
return table.columnPicker.visibleColumnIds.includes(id as string);
|
|
155
|
+
}),
|
|
156
|
+
);
|
|
157
|
+
}
|
|
143
158
|
headerButtons.highlightAllColumns(table.filter.args, table.id);
|
|
144
159
|
table.filter.register(grid, table.id);
|
|
145
160
|
grid.invalidate();
|
|
@@ -147,14 +162,4 @@ export function useGrid({
|
|
|
147
162
|
table.notifyObservers();
|
|
148
163
|
columnSorter.restoreSorting(table);
|
|
149
164
|
}, [columns, items]);
|
|
150
|
-
|
|
151
|
-
useEffect(() => {
|
|
152
|
-
if (!table.columnPicker) return;
|
|
153
|
-
const grid = table.grid;
|
|
154
|
-
if (!grid) return;
|
|
155
|
-
table.columnPicker.initialColumns = grid.getColumns();
|
|
156
|
-
table.columnPicker.visibleColumnIds = grid
|
|
157
|
-
.getColumns()
|
|
158
|
-
.map(({ id }) => id as string);
|
|
159
|
-
}, [columns]);
|
|
160
165
|
}
|
|
@@ -1,19 +0,0 @@
|
|
|
1
|
-
import { fireEvent, render } from "@testing-library/react";
|
|
2
|
-
import userEvent from "@testing-library/user-event";
|
|
3
|
-
|
|
4
|
-
import { Overlay } from "./Overlay";
|
|
5
|
-
|
|
6
|
-
describe("Overlay", () => {
|
|
7
|
-
it("should call setIsOpened with false on click or right-click", async () => {
|
|
8
|
-
const user = userEvent.setup();
|
|
9
|
-
const setIsOpened = jest.fn();
|
|
10
|
-
const { getByTestId } = render(<Overlay setIsOpened={setIsOpened} />);
|
|
11
|
-
const div = getByTestId("overlay");
|
|
12
|
-
expect(div).toBeInTheDocument();
|
|
13
|
-
await user.click(div);
|
|
14
|
-
expect(setIsOpened).toHaveBeenCalledWith(false);
|
|
15
|
-
fireEvent.contextMenu(div);
|
|
16
|
-
expect(setIsOpened).toHaveBeenCalledWith(false);
|
|
17
|
-
expect(setIsOpened).toHaveBeenCalledTimes(2);
|
|
18
|
-
});
|
|
19
|
-
});
|
|
@@ -1,59 +0,0 @@
|
|
|
1
|
-
import { SlickGroup } from "slickgrid";
|
|
2
|
-
|
|
3
|
-
import { IColumn } from "shared/model/types";
|
|
4
|
-
|
|
5
|
-
import { formatterGroupTotals } from "./formatterGroupTotals";
|
|
6
|
-
|
|
7
|
-
describe("sumTotalsFormatter", () => {
|
|
8
|
-
it("should return an empty string when totals.sum is undefined", () => {
|
|
9
|
-
const totals = {
|
|
10
|
-
group: { level: 0 } as SlickGroup,
|
|
11
|
-
initialized: true,
|
|
12
|
-
sum: undefined,
|
|
13
|
-
};
|
|
14
|
-
const columnDef: IColumn = { field: "someField" };
|
|
15
|
-
|
|
16
|
-
const result = formatterGroupTotals(totals as any, columnDef);
|
|
17
|
-
|
|
18
|
-
expect(result).toBe("TOTAL: ");
|
|
19
|
-
});
|
|
20
|
-
|
|
21
|
-
it("should return 'TOTAL: 1,000.00' for group level 0", () => {
|
|
22
|
-
const totals = {
|
|
23
|
-
group: { level: 0 } as SlickGroup,
|
|
24
|
-
initialized: true,
|
|
25
|
-
sum: { someField: 1000 },
|
|
26
|
-
};
|
|
27
|
-
const columnDef: IColumn = { field: "someField" };
|
|
28
|
-
|
|
29
|
-
const result = formatterGroupTotals(totals as any, columnDef);
|
|
30
|
-
|
|
31
|
-
expect(result).toBe("TOTAL: 1,000.00");
|
|
32
|
-
});
|
|
33
|
-
|
|
34
|
-
it("should return 'total: 1,000.00' for group levels greater than 0", () => {
|
|
35
|
-
const totals = {
|
|
36
|
-
group: { level: 1 } as SlickGroup,
|
|
37
|
-
initialized: true,
|
|
38
|
-
sum: { someField: 1000 },
|
|
39
|
-
};
|
|
40
|
-
const columnDef: IColumn = { field: "someField" };
|
|
41
|
-
|
|
42
|
-
const result = formatterGroupTotals(totals as any, columnDef);
|
|
43
|
-
|
|
44
|
-
expect(result).toBe("total: 1,000.00");
|
|
45
|
-
});
|
|
46
|
-
|
|
47
|
-
it("should return an empty string when totals.sum[columnDef.field] is null", () => {
|
|
48
|
-
const totals = {
|
|
49
|
-
group: { level: 0 } as SlickGroup,
|
|
50
|
-
initialized: true,
|
|
51
|
-
sum: { someField: null },
|
|
52
|
-
};
|
|
53
|
-
const columnDef: IColumn = { field: "someField" };
|
|
54
|
-
|
|
55
|
-
const result = formatterGroupTotals(totals as any, columnDef);
|
|
56
|
-
|
|
57
|
-
expect(result).toBe("");
|
|
58
|
-
});
|
|
59
|
-
});
|
|
@@ -1,80 +0,0 @@
|
|
|
1
|
-
import { SlickGrid } from "slickgrid";
|
|
2
|
-
|
|
3
|
-
import { Filter } from "./Filter";
|
|
4
|
-
|
|
5
|
-
describe("shared | lib | slickgrid | Filter", () => {
|
|
6
|
-
it("should initialize with empty arguments and null grid", () => {
|
|
7
|
-
const filter = new Filter();
|
|
8
|
-
expect(filter.args).toEqual({});
|
|
9
|
-
expect(filter.grid).toBeNull();
|
|
10
|
-
});
|
|
11
|
-
|
|
12
|
-
it("should register the filter with the provided grid and table ID", () => {
|
|
13
|
-
const filter = new Filter();
|
|
14
|
-
const mockGrid = {
|
|
15
|
-
getData: jest.fn().mockReturnValue({
|
|
16
|
-
setFilter: jest.fn(),
|
|
17
|
-
setFilterArgs: jest.fn(),
|
|
18
|
-
refresh: jest.fn(),
|
|
19
|
-
}),
|
|
20
|
-
} as unknown as SlickGrid;
|
|
21
|
-
const tableId = "testTable";
|
|
22
|
-
|
|
23
|
-
filter.register(mockGrid, tableId);
|
|
24
|
-
|
|
25
|
-
expect(filter.grid).toBe(mockGrid);
|
|
26
|
-
expect(filter.tableId).toBe(tableId);
|
|
27
|
-
expect(mockGrid.getData().setFilter).toHaveBeenCalledWith(
|
|
28
|
-
expect.any(Function),
|
|
29
|
-
);
|
|
30
|
-
expect(mockGrid.getData().setFilterArgs).toHaveBeenCalledWith(filter.args);
|
|
31
|
-
expect(mockGrid.getData().refresh).toHaveBeenCalled();
|
|
32
|
-
});
|
|
33
|
-
|
|
34
|
-
it("should reset arguments to an empty object when reset is called", () => {
|
|
35
|
-
const filter = new Filter();
|
|
36
|
-
const mockGrid = {
|
|
37
|
-
getData: jest.fn().mockReturnValue({
|
|
38
|
-
setFilterArgs: jest.fn(),
|
|
39
|
-
refresh: jest.fn(),
|
|
40
|
-
}),
|
|
41
|
-
} as unknown as SlickGrid;
|
|
42
|
-
const initialArgs = { key: "value" };
|
|
43
|
-
|
|
44
|
-
filter.grid = mockGrid;
|
|
45
|
-
filter.args = initialArgs;
|
|
46
|
-
|
|
47
|
-
filter.reset();
|
|
48
|
-
|
|
49
|
-
expect(filter.args).toEqual({});
|
|
50
|
-
expect(mockGrid.getData().setFilterArgs).toHaveBeenCalledWith({});
|
|
51
|
-
expect(mockGrid.getData().refresh).toHaveBeenCalled();
|
|
52
|
-
});
|
|
53
|
-
|
|
54
|
-
it("should return an empty array from the print method", () => {
|
|
55
|
-
const filter = new Filter();
|
|
56
|
-
const result = filter.print();
|
|
57
|
-
expect(Array.isArray(result)).toBe(true);
|
|
58
|
-
expect(result).toEqual([]);
|
|
59
|
-
expect(result.length).toBe(0);
|
|
60
|
-
});
|
|
61
|
-
|
|
62
|
-
it("should not attempt to reset if grid is null", () => {
|
|
63
|
-
const filter = new Filter();
|
|
64
|
-
filter.grid = null;
|
|
65
|
-
|
|
66
|
-
filter.reset();
|
|
67
|
-
|
|
68
|
-
expect(filter.args).toEqual({});
|
|
69
|
-
});
|
|
70
|
-
|
|
71
|
-
it("should not attempt to update data view if grid is null when setting args", () => {
|
|
72
|
-
const filter = new Filter();
|
|
73
|
-
const newArgs = { key: "value" };
|
|
74
|
-
|
|
75
|
-
filter.grid = null;
|
|
76
|
-
filter.args = newArgs;
|
|
77
|
-
|
|
78
|
-
expect(filter.args).toEqual(newArgs);
|
|
79
|
-
});
|
|
80
|
-
});
|
|
@@ -1,216 +0,0 @@
|
|
|
1
|
-
import { SlickGrid } from "slickgrid";
|
|
2
|
-
|
|
3
|
-
import { headerButtons } from "shared/lib/slickgrid";
|
|
4
|
-
import { EColumnFilter, EColumnFiltersGroup } from "shared/model/enums";
|
|
5
|
-
import { IFilter } from "shared/model/types";
|
|
6
|
-
|
|
7
|
-
import { DecoratorColumnFilter } from "./DecoratorColumnFilter";
|
|
8
|
-
import { filter } from "./Filter";
|
|
9
|
-
|
|
10
|
-
jest.mock("app/store/store");
|
|
11
|
-
|
|
12
|
-
describe("DecoratorColumnFilter", () => {
|
|
13
|
-
let decoratorColumnFilter: DecoratorColumnFilter;
|
|
14
|
-
let mockFilter: IFilter;
|
|
15
|
-
|
|
16
|
-
beforeEach(() => {
|
|
17
|
-
mockFilter = {
|
|
18
|
-
getFilterFn: jest.fn(),
|
|
19
|
-
reset: jest.fn(),
|
|
20
|
-
print: jest.fn(),
|
|
21
|
-
args: {},
|
|
22
|
-
grid: {} as SlickGrid,
|
|
23
|
-
tableId: "test-table",
|
|
24
|
-
} as unknown as IFilter;
|
|
25
|
-
decoratorColumnFilter = new DecoratorColumnFilter(mockFilter);
|
|
26
|
-
});
|
|
27
|
-
|
|
28
|
-
it("should return true when args.columnFilters is undefined", () => {
|
|
29
|
-
const item = { id: 1, name: "Test" };
|
|
30
|
-
const args: any = {};
|
|
31
|
-
|
|
32
|
-
const result = decoratorColumnFilter.filterFn(item, args);
|
|
33
|
-
|
|
34
|
-
expect(result).toBe(true);
|
|
35
|
-
});
|
|
36
|
-
|
|
37
|
-
it("should return true when the grid is not available", () => {
|
|
38
|
-
const item = { id: 1, name: "Test" };
|
|
39
|
-
const args = {
|
|
40
|
-
columnFilters: {
|
|
41
|
-
name: {
|
|
42
|
-
filterId: EColumnFilter.TextContain,
|
|
43
|
-
group: EColumnFiltersGroup.Text,
|
|
44
|
-
value: { 1: "Test", 2: "" },
|
|
45
|
-
},
|
|
46
|
-
},
|
|
47
|
-
};
|
|
48
|
-
decoratorColumnFilter.grid = null;
|
|
49
|
-
|
|
50
|
-
const result = decoratorColumnFilter.filterFn(item, args);
|
|
51
|
-
|
|
52
|
-
expect(result).toBe(true);
|
|
53
|
-
});
|
|
54
|
-
|
|
55
|
-
it("should correctly apply filters for boolean column types", () => {
|
|
56
|
-
const mockGrid = {
|
|
57
|
-
getColumns: jest.fn(() => [{ id: "isActive", field: "isActive" }]),
|
|
58
|
-
getColumnIndex: jest.fn(() => 0),
|
|
59
|
-
} as unknown as SlickGrid;
|
|
60
|
-
decoratorColumnFilter.grid = mockGrid;
|
|
61
|
-
|
|
62
|
-
const item = { isActive: true };
|
|
63
|
-
const args = {
|
|
64
|
-
columnFilters: {
|
|
65
|
-
isActive: {
|
|
66
|
-
filterId: EColumnFilter.Boolean,
|
|
67
|
-
group: EColumnFiltersGroup.Boolean,
|
|
68
|
-
value: { 1: "true", 2: "" },
|
|
69
|
-
},
|
|
70
|
-
},
|
|
71
|
-
};
|
|
72
|
-
|
|
73
|
-
const result = decoratorColumnFilter.filterFn(item, args);
|
|
74
|
-
|
|
75
|
-
expect(result).toBe(true);
|
|
76
|
-
expect(mockGrid.getColumns).toHaveBeenCalled();
|
|
77
|
-
expect(mockGrid.getColumnIndex).toHaveBeenCalledWith("isActive");
|
|
78
|
-
});
|
|
79
|
-
|
|
80
|
-
it("should return false if any column filter fails", () => {
|
|
81
|
-
const mockGrid = {
|
|
82
|
-
getColumns: jest.fn(() => [
|
|
83
|
-
{ id: "name", field: "name" },
|
|
84
|
-
{ id: "age", field: "age" },
|
|
85
|
-
]),
|
|
86
|
-
getColumnIndex: jest.fn((id) => (id === "name" ? 0 : 1)),
|
|
87
|
-
} as unknown as SlickGrid;
|
|
88
|
-
decoratorColumnFilter.grid = mockGrid;
|
|
89
|
-
|
|
90
|
-
const item = { name: "John", age: 30 };
|
|
91
|
-
const args = {
|
|
92
|
-
columnFilters: {
|
|
93
|
-
name: {
|
|
94
|
-
filterId: EColumnFilter.TextContain,
|
|
95
|
-
group: EColumnFiltersGroup.Text,
|
|
96
|
-
value: { 1: "John", 2: "" },
|
|
97
|
-
},
|
|
98
|
-
age: {
|
|
99
|
-
filterId: EColumnFilter.NumberFrom,
|
|
100
|
-
group: EColumnFiltersGroup.Number,
|
|
101
|
-
value: { 1: "40", 2: "" },
|
|
102
|
-
},
|
|
103
|
-
},
|
|
104
|
-
};
|
|
105
|
-
|
|
106
|
-
jest
|
|
107
|
-
.spyOn(filter, "passed")
|
|
108
|
-
.mockReturnValueOnce(true) // For name filter
|
|
109
|
-
.mockReturnValueOnce(false); // For age filter
|
|
110
|
-
|
|
111
|
-
const result = decoratorColumnFilter.filterFn(item, args);
|
|
112
|
-
|
|
113
|
-
expect(result).toBe(false);
|
|
114
|
-
expect(mockGrid.getColumns).toHaveBeenCalled();
|
|
115
|
-
expect(mockGrid.getColumnIndex).toHaveBeenCalledWith("name");
|
|
116
|
-
expect(mockGrid.getColumnIndex).toHaveBeenCalledWith("age");
|
|
117
|
-
expect(filter.passed).toHaveBeenCalledTimes(2);
|
|
118
|
-
});
|
|
119
|
-
|
|
120
|
-
it("should use the formatter function for non-boolean and non-number column types", () => {
|
|
121
|
-
const mockGrid = {
|
|
122
|
-
getColumns: jest.fn(() => [
|
|
123
|
-
{
|
|
124
|
-
id: "name",
|
|
125
|
-
field: "name",
|
|
126
|
-
formatter: (_row: number, _cell: number, value: string) =>
|
|
127
|
-
`Formatted: ${value}`,
|
|
128
|
-
},
|
|
129
|
-
{ id: "age", field: "age" },
|
|
130
|
-
]),
|
|
131
|
-
getColumnIndex: jest.fn((id) => (id === "name" ? 0 : 1)),
|
|
132
|
-
} as unknown as SlickGrid;
|
|
133
|
-
decoratorColumnFilter.grid = mockGrid;
|
|
134
|
-
|
|
135
|
-
const item = { name: "John", age: 30 };
|
|
136
|
-
const args = {
|
|
137
|
-
columnFilters: {
|
|
138
|
-
name: {
|
|
139
|
-
filterId: EColumnFilter.TextContain,
|
|
140
|
-
group: EColumnFiltersGroup.Text,
|
|
141
|
-
value: { 1: "Formatted: John", 2: "" },
|
|
142
|
-
},
|
|
143
|
-
age: {
|
|
144
|
-
filterId: EColumnFilter.NumberFrom,
|
|
145
|
-
group: EColumnFiltersGroup.Number,
|
|
146
|
-
value: { 1: "30", 2: "" },
|
|
147
|
-
},
|
|
148
|
-
},
|
|
149
|
-
};
|
|
150
|
-
|
|
151
|
-
jest.spyOn(filter, "passed").mockReturnValue(true);
|
|
152
|
-
|
|
153
|
-
decoratorColumnFilter.filterFn(item, args);
|
|
154
|
-
|
|
155
|
-
expect(filter.passed).toHaveBeenCalledWith(
|
|
156
|
-
"Formatted: John",
|
|
157
|
-
{ 1: "Formatted: John", 2: "" },
|
|
158
|
-
EColumnFilter.TextContain,
|
|
159
|
-
);
|
|
160
|
-
expect(filter.passed).toHaveBeenCalledWith(
|
|
161
|
-
30,
|
|
162
|
-
{ 1: "30", 2: "" },
|
|
163
|
-
EColumnFilter.NumberFrom,
|
|
164
|
-
);
|
|
165
|
-
});
|
|
166
|
-
|
|
167
|
-
it("should correctly reset filters and highlight all columns", () => {
|
|
168
|
-
const mockFilter = {
|
|
169
|
-
reset: jest.fn(),
|
|
170
|
-
};
|
|
171
|
-
const mockHeaderButtons = {
|
|
172
|
-
highlightAllColumns: jest.fn(),
|
|
173
|
-
};
|
|
174
|
-
const mockArgs = { someArg: "value" };
|
|
175
|
-
const mockTableId = "test-table";
|
|
176
|
-
|
|
177
|
-
jest
|
|
178
|
-
.spyOn(headerButtons, "highlightAllColumns")
|
|
179
|
-
.mockImplementation(mockHeaderButtons.highlightAllColumns);
|
|
180
|
-
|
|
181
|
-
const decoratorColumnFilter = new DecoratorColumnFilter(mockFilter as any);
|
|
182
|
-
decoratorColumnFilter.args = mockArgs;
|
|
183
|
-
decoratorColumnFilter.tableId = mockTableId;
|
|
184
|
-
|
|
185
|
-
decoratorColumnFilter.reset();
|
|
186
|
-
|
|
187
|
-
expect(mockFilter.reset).toHaveBeenCalled();
|
|
188
|
-
expect(mockHeaderButtons.highlightAllColumns).toHaveBeenCalledWith(
|
|
189
|
-
mockArgs,
|
|
190
|
-
mockTableId,
|
|
191
|
-
);
|
|
192
|
-
});
|
|
193
|
-
it("should correctly reset filters and highlight all columns", () => {
|
|
194
|
-
const mockFilter = {
|
|
195
|
-
reset: jest.fn(),
|
|
196
|
-
};
|
|
197
|
-
const mockHeaderButtons = {
|
|
198
|
-
highlightAllColumns: jest.fn(),
|
|
199
|
-
};
|
|
200
|
-
const mockArgs = { someArg: "value" };
|
|
201
|
-
const mockTableId = "";
|
|
202
|
-
|
|
203
|
-
jest
|
|
204
|
-
.spyOn(headerButtons, "highlightAllColumns")
|
|
205
|
-
.mockImplementation(mockHeaderButtons.highlightAllColumns);
|
|
206
|
-
|
|
207
|
-
const decoratorColumnFilter = new DecoratorColumnFilter(mockFilter as any);
|
|
208
|
-
decoratorColumnFilter.args = mockArgs;
|
|
209
|
-
decoratorColumnFilter.tableId = mockTableId;
|
|
210
|
-
|
|
211
|
-
decoratorColumnFilter.reset();
|
|
212
|
-
|
|
213
|
-
expect(mockFilter.reset).toHaveBeenCalled();
|
|
214
|
-
expect(mockHeaderButtons.highlightAllColumns).not.toHaveBeenCalled();
|
|
215
|
-
});
|
|
216
|
-
});
|
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
|
-
});
|