@truedat/core 6.13.4 → 6.13.5

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,220 +0,0 @@
1
- import _ from "lodash/fp";
2
- import React from "react";
3
- import { render } from "@truedat/test/render";
4
- import { waitFor } from "@testing-library/react";
5
- import userEvent from "@testing-library/user-event";
6
- import BranchViewer from "../BranchViewer";
7
-
8
- const handleRedirect = jest.fn();
9
- const props = {
10
- branches: [
11
- {
12
- description: "No tiene padre",
13
- domain_group: null,
14
- external_id: "1",
15
- id: 1,
16
- name: "element_1",
17
- parent_id: null,
18
- parents: null,
19
- type: null,
20
- },
21
- {
22
- description: "No tiene padre",
23
- domain_group: null,
24
- external_id: "2",
25
- id: 2,
26
- name: "element_2",
27
- parent_id: null,
28
- parents: null,
29
- type: null,
30
- },
31
- {
32
- description: "el padre es element_2",
33
- domain_group: null,
34
- external_id: "3",
35
- id: 3,
36
- name: "element_3",
37
- parent_id: 2,
38
- parents: null,
39
- type: null,
40
- },
41
- {
42
- description: "el padre es element_2",
43
- domain_group: null,
44
- external_id: "4",
45
- id: 4,
46
- name: "element_4",
47
- parent_id: 2,
48
- parents: null,
49
- type: null,
50
- },
51
- {
52
- description: "No tiene padre",
53
- domain_group: null,
54
- external_id: "5",
55
- id: 5,
56
- name: "element_5",
57
- parent_id: null,
58
- parents: null,
59
- type: null,
60
- },
61
- {
62
- description: "el padre es element_5",
63
- domain_group: null,
64
- external_id: "6",
65
- id: 6,
66
- name: "element_6",
67
- parent_id: 5,
68
- parents: null,
69
- type: null,
70
- },
71
- {
72
- description: "el padre es element_6",
73
- domain_group: null,
74
- external_id: "7",
75
- id: 7,
76
- name: "element_7",
77
- parent_id: 6,
78
- parents: null,
79
- type: null,
80
- },
81
- ],
82
- handleRedirect,
83
- idSelectedBranch: undefined,
84
- };
85
-
86
- const renderOpts = {
87
- messages: {
88
- en: {
89
- "domains.search.results.count": "count",
90
- "domains.search.results.empty": "empty",
91
- "search.input.placeholder": "searchbox_placeholder",
92
- "domains.search.error.fields": "No fields for search",
93
- "domains.notExist": "notExistDomains",
94
- },
95
- },
96
- };
97
-
98
- describe("BranchViewer", () => {
99
- it("matches the latest snapshot", () => {
100
- const { container } = render(<BranchViewer {...props} />, renderOpts);
101
-
102
- expect(container).toMatchSnapshot();
103
- });
104
-
105
- it("should return 'no branches' messages if branch list empty", async () => {
106
- const customProps = { ...props, branches: [] };
107
- const { findByText } = render(
108
- <BranchViewer {...customProps} />,
109
- renderOpts
110
- );
111
-
112
- expect(await findByText("notExistDomains")).toBeInTheDocument();
113
- });
114
-
115
- it("should return 'no branches' messages if branch list undefined", async () => {
116
- const customProps = { ...props, branches: undefined };
117
- const { findByText } = render(
118
- <BranchViewer {...customProps} />,
119
- renderOpts
120
- );
121
-
122
- expect(await findByText("notExistDomains")).toBeInTheDocument();
123
- });
124
-
125
- it("should return 'no branches' messages if branch list null", async () => {
126
- const customProps = { ...props, branches: null };
127
- const { findByText } = render(
128
- <BranchViewer {...customProps} />,
129
- renderOpts
130
- );
131
-
132
- expect(await findByText("notExistDomains")).toBeInTheDocument();
133
- });
134
-
135
- it("with a valid idSelectedBranch should return 'branches' highlighting selected branch and ancestors expanded", async () => {
136
- const customProps = { ...props, idSelectedBranch: 7 };
137
- const { container } = render(<BranchViewer {...customProps} />, renderOpts);
138
-
139
- const expandedElements = container.querySelectorAll(".expanded");
140
-
141
- expect(expandedElements.length).toBe(2);
142
-
143
- expandedElements.forEach((element) => {
144
- const input = element.querySelector("input");
145
- if (input) {
146
- if (input.classList.contains("selectedBranch")) {
147
- expect(input.value).toBe("element_7");
148
- } else {
149
- expect(input.value).toBe("element_6");
150
- }
151
- }
152
- });
153
- });
154
- });
155
-
156
- describe("organizeBranches", () => {
157
- it("organizeBranches creates 'childs' and 'parents' properties", async () => {
158
- const { queryByText, getByDisplayValue, queryByDisplayValue } = render(
159
- <BranchViewer {...props} />,
160
- renderOpts
161
- );
162
-
163
- const input1 = getByDisplayValue("element_1");
164
- const parent1 = input1.closest("div");
165
- await waitFor(() =>
166
- expect(parent1.querySelector("i")).not.toBeInTheDocument()
167
- );
168
-
169
- await waitFor(() => expect(queryByText("element_3")).toBeNull());
170
- await waitFor(() => expect(queryByText("element_4")).toBeNull());
171
-
172
- const input2 = getByDisplayValue("element_2");
173
- const parent2 = input2.closest("div");
174
- const sibling2 = parent2.querySelector("i");
175
- userEvent.click(sibling2);
176
-
177
- await waitFor(() => {
178
- expect(queryByDisplayValue(/element_3/)).toBeInTheDocument();
179
- expect(queryByDisplayValue(/element_4/)).toBeInTheDocument();
180
- });
181
-
182
- await waitFor(() => expect(queryByText("element_6")).toBeNull());
183
- await waitFor(() => expect(queryByText("element_7")).toBeNull());
184
-
185
- const input3 = getByDisplayValue("element_5");
186
- const parent3 = input3.closest("div");
187
- const sibling3 = parent3.querySelector("i");
188
- userEvent.click(sibling3);
189
-
190
- await waitFor(() => {
191
- expect(queryByDisplayValue(/element_6/)).toBeInTheDocument();
192
-
193
- const input4 = getByDisplayValue("element_6");
194
- const parent4 = input4.closest("div");
195
- const sibling4 = parent4.querySelector("i");
196
- userEvent.click(sibling4);
197
-
198
- waitFor(() => {
199
- expect(queryByDisplayValue(/element_7/)).toBeInTheDocument();
200
- });
201
- });
202
- });
203
-
204
- it("organizeBranches creates 'path' property", async () => {
205
- const { container, getByPlaceholderText } = render(
206
- <BranchViewer {...props} />,
207
- renderOpts
208
- );
209
- const searchBox = getByPlaceholderText("searchbox_placeholder");
210
-
211
- userEvent.click(searchBox);
212
- userEvent.type(searchBox, "element_7");
213
-
214
- await waitFor(() => {
215
- const element = container.querySelector(".brancheViewerSearchResultMeta");
216
- expect(element).toBeInTheDocument();
217
- expect(element).toHaveTextContent("element_5 > element_6");
218
- });
219
- });
220
- });
@@ -1,209 +0,0 @@
1
- import _ from "lodash/fp";
2
-
3
- import LocalCustomSearch from "../LocalCustomSearch";
4
-
5
- const collection = [
6
- {
7
- description: "No tiene padre",
8
- domain_group: null,
9
- external_id: "1",
10
- id: 1,
11
- name: "element_1",
12
- parent_id: null,
13
- parents: null,
14
- type: null,
15
- },
16
- {
17
- description: "No tiene padre",
18
- domain_group: null,
19
- external_id: "2",
20
- id: 2,
21
- name: "element_2",
22
- parent_id: null,
23
- parents: null,
24
- type: null,
25
- },
26
- {
27
- description: "el padre es element_2",
28
- domain_group: null,
29
- external_id: "3",
30
- id: 3,
31
- name: "element_3",
32
- parent_id: 2,
33
- parents: null,
34
- type: null,
35
- },
36
- {
37
- description: "el padre es element_2",
38
- domain_group: null,
39
- external_id: "4",
40
- id: 4,
41
- name: "element_4",
42
- parent_id: 2,
43
- parents: null,
44
- type: null,
45
- },
46
- {
47
- description: "No tiene padre",
48
- domain_group: null,
49
- external_id: "5",
50
- id: 5,
51
- name: "element_5",
52
- parent_id: null,
53
- parents: null,
54
- type: null,
55
- },
56
- {
57
- description: "el padre es element_5",
58
- domain_group: null,
59
- external_id: "6",
60
- id: 6,
61
- name: "element_6",
62
- parent_id: 5,
63
- parents: null,
64
- type: null,
65
- },
66
- {
67
- description: "el padre es element_6",
68
- domain_group: null,
69
- external_id: "7",
70
- id: 7,
71
- name: "element_7",
72
- parent_id: 6,
73
- parents: null,
74
- type: null,
75
- },
76
- ];
77
-
78
- const searchFields = ["description", "name"];
79
- const getOneOrMany = false;
80
-
81
- describe("LocalCustomSearch", () => {
82
- it("LocalCustomSearch filters collection successfully", () => {
83
- const firstSearch = "No tiene padre";
84
- const callbackMock = jest.fn();
85
- const countFirstSearch = 3;
86
- const resultFirstSearch = collection.filter((element) =>
87
- element.description.includes(firstSearch)
88
- );
89
-
90
- expect(
91
- LocalCustomSearch(
92
- collection,
93
- firstSearch,
94
- callbackMock,
95
- searchFields,
96
- getOneOrMany
97
- )
98
- ).toBe(countFirstSearch);
99
-
100
- expect(callbackMock).toHaveBeenCalledWith(resultFirstSearch);
101
-
102
- const secondSearch = "padre";
103
- const countSecondSearch = 7;
104
-
105
- const resultSecondSearch = collection.filter((element) =>
106
- element.description.includes(secondSearch)
107
- );
108
-
109
- expect(
110
- LocalCustomSearch(
111
- collection,
112
- secondSearch,
113
- callbackMock,
114
- searchFields,
115
- getOneOrMany
116
- )
117
- ).toBe(countSecondSearch);
118
-
119
- expect(callbackMock).toHaveBeenCalledWith(resultSecondSearch);
120
- });
121
-
122
- it("LocalCustomSearch filters empty collection", () => {
123
- const search = "custom search";
124
- const customCollection = [];
125
- const callbackMock = jest.fn();
126
-
127
- expect(
128
- LocalCustomSearch(
129
- customCollection,
130
- search,
131
- callbackMock,
132
- searchFields,
133
- getOneOrMany
134
- )
135
- ).toBe(customCollection.length);
136
-
137
- expect(callbackMock).toHaveBeenCalledWith(customCollection);
138
- });
139
-
140
- it("LocalCustomSearch filters collection but searchFields is empty", () => {
141
- const search = "custom search";
142
- const customSearchFields = [];
143
- const callbackMock = jest.fn();
144
-
145
- expect(
146
- LocalCustomSearch(
147
- collection,
148
- search,
149
- callbackMock,
150
- customSearchFields,
151
- getOneOrMany
152
- )
153
- ).toBe(-1);
154
-
155
- expect(callbackMock).not.toHaveBeenCalled();
156
- });
157
-
158
- it("LocalCustomSearch filters collection but searchFields has fields that not exists in elements", () => {
159
- const search = "custom search";
160
- const callbackMock = jest.fn();
161
-
162
- expect(
163
- LocalCustomSearch(
164
- collection,
165
- search,
166
- callbackMock,
167
- ["external_id", "title"],
168
- getOneOrMany
169
- )
170
- ).toBe(0);
171
-
172
- expect(callbackMock).toHaveBeenCalledWith([]);
173
- });
174
-
175
- it("LocalCustomSearch filters collection but searchFields is null", () => {
176
- const search = "custom search";
177
- const customSearchFields = null;
178
- const callbackMock = jest.fn();
179
-
180
- expect(
181
- LocalCustomSearch(
182
- collection,
183
- search,
184
- callbackMock,
185
- customSearchFields,
186
- getOneOrMany
187
- )
188
- ).toBe(-1);
189
-
190
- expect(callbackMock).not.toHaveBeenCalled();
191
- });
192
-
193
- it("LocalCustomSearch returns original collection when searchString is empty", () => {
194
- const search = "";
195
- const callbackMock = jest.fn();
196
-
197
- expect(
198
- LocalCustomSearch(
199
- collection,
200
- search,
201
- callbackMock,
202
- searchFields,
203
- getOneOrMany
204
- )
205
- ).toBe(collection.length);
206
-
207
- expect(callbackMock).toHaveBeenCalledWith(collection);
208
- });
209
- });
@@ -1,203 +0,0 @@
1
- import _ from "lodash/fp";
2
- import React from "react";
3
- import { render } from "@truedat/test/render";
4
- import { waitFor } from "@testing-library/react";
5
- import userEvent from "@testing-library/user-event";
6
- import LocalSearchInput from "../LocalSearchInput";
7
-
8
- const searchFields = ["description", "name"];
9
- const props = {
10
- collection: [
11
- {
12
- description: "No tiene padre",
13
- domain_group: null,
14
- external_id: "1",
15
- id: 1,
16
- name: "element_1",
17
- parent_id: null,
18
- parents: null,
19
- type: null,
20
- },
21
- {
22
- description: "No tiene padre",
23
- domain_group: null,
24
- external_id: "2",
25
- id: 2,
26
- name: "element_2",
27
- parent_id: null,
28
- parents: null,
29
- type: null,
30
- },
31
- {
32
- description: "el padre es element_2",
33
- domain_group: null,
34
- external_id: "3",
35
- id: 3,
36
- name: "element_3",
37
- parent_id: 2,
38
- parents: null,
39
- type: null,
40
- },
41
- {
42
- description: "el padre es element_2",
43
- domain_group: null,
44
- external_id: "4",
45
- id: 4,
46
- name: "element_4",
47
- parent_id: 2,
48
- parents: null,
49
- type: null,
50
- },
51
- {
52
- description: "No tiene padre",
53
- domain_group: null,
54
- external_id: "5",
55
- id: 5,
56
- name: "element_5",
57
- parent_id: null,
58
- parents: null,
59
- type: null,
60
- },
61
- {
62
- description: "el padre es element_5",
63
- domain_group: null,
64
- external_id: "6",
65
- id: 6,
66
- name: "element_6",
67
- parent_id: 5,
68
- parents: null,
69
- type: null,
70
- },
71
- {
72
- description: "el padre es element_6",
73
- domain_group: null,
74
- external_id: "7",
75
- id: 7,
76
- name: "element_7",
77
- parent_id: 6,
78
- parents: null,
79
- type: null,
80
- },
81
- ],
82
- searchFields,
83
- enabled: true,
84
- };
85
-
86
- const renderOpts = {
87
- messages: {
88
- en: {
89
- "domains.search.results.count": "count",
90
- "domains.search.results.empty": "empty",
91
- "search.input.placeholder": "searchbox_placeholder",
92
- "domains.search.error.fields": "No fields for search",
93
- "domains.notExist": "notExistDomains",
94
- },
95
- },
96
- };
97
-
98
- describe("LocalSearchInput", () => {
99
- it("matches the latest snapshot", async () => {
100
- const searchFunction = jest.fn();
101
-
102
- const customProps = {
103
- ...props,
104
- callback: jest.fn,
105
- searchFunction: searchFunction,
106
- };
107
-
108
- const { container, getByPlaceholderText } = render(
109
- <LocalSearchInput {...customProps} />,
110
- renderOpts
111
- );
112
-
113
- const searchBox = getByPlaceholderText("searchbox_placeholder");
114
- userEvent.click(searchBox);
115
- userEvent.type(searchBox, "padre");
116
-
117
- await waitFor(() => {
118
- expect(searchFunction).toHaveBeenCalled();
119
- expect(container).toMatchSnapshot();
120
- });
121
- });
122
-
123
- it("should return 'no branches' messages if branch list empty", async () => {
124
- const searchFunction = () => {
125
- return -1;
126
- };
127
-
128
- const customProps = {
129
- ...props,
130
- collection: [],
131
- callback: jest.fn,
132
- searchFunction: searchFunction,
133
- };
134
-
135
- const { queryByText, getByPlaceholderText } = render(
136
- <LocalSearchInput {...customProps} />,
137
- renderOpts
138
- );
139
-
140
- const searchBox = getByPlaceholderText("searchbox_placeholder");
141
-
142
- userEvent.click(searchBox);
143
- userEvent.type(searchBox, "padre");
144
-
145
- await waitFor(() => {
146
- expect(queryByText(/No fields for search/)).toBeInTheDocument();
147
- });
148
- });
149
-
150
- it("should return 'no branches' messages if branch list undefined", async () => {
151
- const searchFunction = () => {
152
- return -1;
153
- };
154
-
155
- const customProps = {
156
- ...props,
157
- collection: undefined,
158
- callback: jest.fn,
159
- searchFunction: searchFunction,
160
- };
161
-
162
- const { queryByText, getByPlaceholderText } = render(
163
- <LocalSearchInput {...customProps} />,
164
- renderOpts
165
- );
166
-
167
- const searchBox = getByPlaceholderText("searchbox_placeholder");
168
-
169
- userEvent.click(searchBox);
170
- userEvent.type(searchBox, "padre");
171
-
172
- await waitFor(() => {
173
- expect(queryByText(/No fields for search/)).toBeInTheDocument();
174
- });
175
- });
176
-
177
- it("should return 'no branches' messages if branch list null", async () => {
178
- const searchFunction = () => {
179
- return -1;
180
- };
181
-
182
- const customProps = {
183
- ...props,
184
- collection: null,
185
- callback: jest.fn,
186
- searchFunction: searchFunction,
187
- };
188
-
189
- const { queryByText, getByPlaceholderText } = render(
190
- <LocalSearchInput {...customProps} />,
191
- renderOpts
192
- );
193
-
194
- const searchBox = getByPlaceholderText("searchbox_placeholder");
195
-
196
- userEvent.click(searchBox);
197
- userEvent.type(searchBox, "padre");
198
-
199
- await waitFor(() => {
200
- expect(queryByText(/No fields for search/)).toBeInTheDocument();
201
- });
202
- });
203
- });