@truedat/core 7.2.3 → 7.2.4
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": "@truedat/core",
|
|
3
|
-
"version": "7.2.
|
|
3
|
+
"version": "7.2.4",
|
|
4
4
|
"description": "Truedat Web Core",
|
|
5
5
|
"sideEffects": false,
|
|
6
6
|
"jsnext:main": "src/index.js",
|
|
@@ -36,7 +36,7 @@
|
|
|
36
36
|
"@testing-library/react": "^12.0.0",
|
|
37
37
|
"@testing-library/react-hooks": "^8.0.1",
|
|
38
38
|
"@testing-library/user-event": "^13.2.1",
|
|
39
|
-
"@truedat/test": "7.2.
|
|
39
|
+
"@truedat/test": "7.2.4",
|
|
40
40
|
"babel-jest": "^28.1.0",
|
|
41
41
|
"babel-plugin-dynamic-import-node": "^2.3.3",
|
|
42
42
|
"babel-plugin-lodash": "^3.3.4",
|
|
@@ -118,5 +118,5 @@
|
|
|
118
118
|
"react-dom": ">= 16.8.6 < 17",
|
|
119
119
|
"semantic-ui-react": ">= 2.0.3 < 2.2"
|
|
120
120
|
},
|
|
121
|
-
"gitHead": "
|
|
121
|
+
"gitHead": "3371f59270a344803524395e395f6a422d879d01"
|
|
122
122
|
}
|
|
@@ -214,7 +214,8 @@ export const SearchContextProvider = (props) => {
|
|
|
214
214
|
|
|
215
215
|
const filterParam = {
|
|
216
216
|
...(!_.isEmpty(query) && { query }),
|
|
217
|
-
must: filterMust,
|
|
217
|
+
must: getMustFilters(filterMust),
|
|
218
|
+
must_not: getMustNotFilters(filterMust),
|
|
218
219
|
};
|
|
219
220
|
debouncedTriggerSearchFilters(filterParam);
|
|
220
221
|
}, [query, filterMust]);
|
|
@@ -226,7 +227,8 @@ export const SearchContextProvider = (props) => {
|
|
|
226
227
|
|
|
227
228
|
const filterParam = {
|
|
228
229
|
...(!_.isEmpty(query) && { query }),
|
|
229
|
-
must: searchMust,
|
|
230
|
+
must: getMustFilters(searchMust),
|
|
231
|
+
must_not: getMustNotFilters(searchMust),
|
|
230
232
|
...enrichSearchPayload,
|
|
231
233
|
sort,
|
|
232
234
|
page: page - 1,
|
|
@@ -245,6 +247,15 @@ export const SearchContextProvider = (props) => {
|
|
|
245
247
|
enrichSearchPayload,
|
|
246
248
|
]);
|
|
247
249
|
|
|
250
|
+
const getMustFilters = (filters) =>
|
|
251
|
+
_.pickBy((value, key) => !key.startsWith("mustnot."))(filters);
|
|
252
|
+
|
|
253
|
+
const getMustNotFilters = (filters) =>
|
|
254
|
+
_.flow(
|
|
255
|
+
_.pickBy((value, key) => key.startsWith("mustnot.")),
|
|
256
|
+
_.mapKeys((key) => key.replace("mustnot.", ""))
|
|
257
|
+
)(filters);
|
|
258
|
+
|
|
248
259
|
const makeFiltersGroup = (filters, groups) =>
|
|
249
260
|
_.flow(
|
|
250
261
|
_.groupBy((filter) =>
|
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
import React from "react";
|
|
2
|
+
import { render } from "@truedat/test/render";
|
|
3
|
+
import { SearchContextProvider } from "@truedat/core/search/SearchContext";
|
|
4
|
+
|
|
5
|
+
jest.mock("react-router-dom", () => ({
|
|
6
|
+
...jest.requireActual("react-router-dom"),
|
|
7
|
+
useLocation: jest.fn(),
|
|
8
|
+
}));
|
|
9
|
+
|
|
10
|
+
const useFilters = () => ({
|
|
11
|
+
trigger: () => ({
|
|
12
|
+
then: (callback) =>
|
|
13
|
+
callback({
|
|
14
|
+
data: [],
|
|
15
|
+
}),
|
|
16
|
+
}),
|
|
17
|
+
});
|
|
18
|
+
|
|
19
|
+
const useSearch = () => ({
|
|
20
|
+
trigger: () => ({
|
|
21
|
+
then: (callback) =>
|
|
22
|
+
callback({
|
|
23
|
+
data,
|
|
24
|
+
headers: {},
|
|
25
|
+
}),
|
|
26
|
+
}),
|
|
27
|
+
});
|
|
28
|
+
|
|
29
|
+
const data = {
|
|
30
|
+
data: [
|
|
31
|
+
{
|
|
32
|
+
id: 1,
|
|
33
|
+
name: "concept",
|
|
34
|
+
status: "draft",
|
|
35
|
+
last_change_at: "2020-01-01T00:00:00.000Z",
|
|
36
|
+
},
|
|
37
|
+
],
|
|
38
|
+
};
|
|
39
|
+
|
|
40
|
+
const searchProps = {
|
|
41
|
+
initialSortColumn: "name.raw",
|
|
42
|
+
initialSortDirection: "ascending",
|
|
43
|
+
useSearch: useSearch,
|
|
44
|
+
useFilters: useFilters,
|
|
45
|
+
userFiltersType: "business_concept_user_filters",
|
|
46
|
+
omitFilters: [],
|
|
47
|
+
translations: jest.fn(),
|
|
48
|
+
};
|
|
49
|
+
|
|
50
|
+
const renderOpts = {
|
|
51
|
+
messages: {
|
|
52
|
+
en: {
|
|
53
|
+
"concepts.props.type": "Type",
|
|
54
|
+
"concepts.props.name": "Term",
|
|
55
|
+
},
|
|
56
|
+
},
|
|
57
|
+
};
|
|
58
|
+
|
|
59
|
+
describe("<SearchContextProvider />", () => {
|
|
60
|
+
const ChildComponent = () => <div>Child Component</div>;
|
|
61
|
+
|
|
62
|
+
it(`matches the latest snapshot`, async () => {
|
|
63
|
+
jest
|
|
64
|
+
.spyOn(require("react-router-dom"), "useLocation")
|
|
65
|
+
.mockReturnValue({ pathname: "/concepts" });
|
|
66
|
+
|
|
67
|
+
const { container, findByText } = render(
|
|
68
|
+
<SearchContextProvider {...searchProps} defaultFilters={{}}>
|
|
69
|
+
<ChildComponent />
|
|
70
|
+
</SearchContextProvider>,
|
|
71
|
+
renderOpts
|
|
72
|
+
);
|
|
73
|
+
await findByText(/Child Component/);
|
|
74
|
+
expect(container).toMatchSnapshot();
|
|
75
|
+
});
|
|
76
|
+
});
|