@truedat/bg 4.51.2 → 4.51.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.
@@ -1,291 +1,86 @@
1
- import _ from "lodash/fp";
2
1
  import React from "react";
3
- import { shallow } from "enzyme";
4
- import { applyTemplateWithoutDefaults } from "@truedat/df/utils";
5
- import { ConceptsBulkUpdate } from "../ConceptsBulkUpdate";
2
+ import { waitFor } from "@testing-library/react";
3
+ import userEvent from "@testing-library/user-event";
4
+ import { render } from "@truedat/test/render";
5
+ import { domainsMock } from "@truedat/test/mocks";
6
+ import { bulkUpdate } from "../../routines";
7
+ import ConceptsBulkUpdate from "../ConceptsBulkUpdate";
6
8
 
7
- describe("<ConceptsBulkUpdate />", () => {
8
- const loading = false;
9
- const templateId = 1;
10
- const template = { id: templateId, template: "template1" };
11
- const selectTemplate = jest.fn();
12
- const selectedDomain = {};
13
- const concepts = [{ id: 1, type: "simple" }];
9
+ const content = [
10
+ { name: "g1", fields: [{ name: "f1", label: "f1", placeholder: "p1" }] },
11
+ ];
12
+ const template = { name: "t1", id: 123, content };
13
+ const state = {
14
+ conceptCount: 1,
15
+ concepts: [{ type: "t1" }],
16
+ template,
17
+ templates: [template],
18
+ };
14
19
 
15
- it("matches the latest snapshot", () => {
16
- const props = { loading, template, selectTemplate, concepts };
17
- const wrapper = shallow(<ConceptsBulkUpdate {...props} />);
18
- expect(wrapper).toMatchSnapshot();
19
- });
20
+ const renderOpts = {
21
+ fallback: "lazy",
22
+ mocks: [domainsMock({ action: "manageConcept" })],
23
+ state,
24
+ };
20
25
 
21
- it("calls selectTemplate when component mounts", () => {
22
- const props = {
23
- loading: false,
24
- template,
25
- selectTemplate: jest.fn(),
26
- concepts,
27
- selectedDomain,
28
- };
29
- jest.spyOn(ConceptsBulkUpdate.prototype, "componentDidMount");
30
- shallow(<ConceptsBulkUpdate {...props} />);
31
- expect(
32
- ConceptsBulkUpdate.prototype.componentDidMount.mock.calls.length
33
- ).toBe(1);
34
- expect(props.selectTemplate).toHaveBeenCalledTimes(1);
26
+ describe("<ConceptsBulkUpdate />", () => {
27
+ it("matches the latest snapshot", async () => {
28
+ const { container, queryByText } = render(
29
+ <ConceptsBulkUpdate />,
30
+ renderOpts
31
+ );
32
+ await waitFor(() => expect(queryByText(/lazy/i)).not.toBeInTheDocument());
33
+ expect(container).toMatchSnapshot();
35
34
  });
36
35
 
37
- it("calls setState when selectedDomain updates", () => {
38
- const props = {
39
- loading: false,
40
- template,
41
- selectTemplate: jest.fn(),
42
- concepts,
43
- selectedDomain,
44
- applyTemplate: jest.fn(),
45
- };
46
- jest.spyOn(ConceptsBulkUpdate.prototype, "setState");
47
- const wrapper = shallow(<ConceptsBulkUpdate {...props} />);
48
- wrapper.setProps({ selectedDomain: { id: 1 } });
49
- expect(ConceptsBulkUpdate.prototype.setState.mock.calls.length).toBe(1);
36
+ it("calls applyTemplate when selectedDomain changes", async () => {
37
+ const applyTemplate = jest.fn();
38
+ const { findByText, queryByText } = render(
39
+ <ConceptsBulkUpdate applyTemplate={applyTemplate} />,
40
+ renderOpts
41
+ );
42
+ await waitFor(() => expect(queryByText(/lazy/i)).not.toBeInTheDocument());
43
+ await waitFor(() => expect(queryByText(/fooDomain/)).toBeInTheDocument());
44
+ expect(applyTemplate).toHaveBeenCalledTimes(0);
45
+ userEvent.click(await findByText("fooDomain"));
46
+ expect(applyTemplate).toHaveBeenCalledTimes(1);
47
+ userEvent.click(await findByText("barDomain"));
48
+ expect(applyTemplate).toHaveBeenCalledTimes(2);
50
49
  });
51
50
 
52
- it("DynamicForm rendered if template, template_id, selectedDomain informed", () => {
53
- const props = {
54
- loading: false,
55
- template,
56
- selectTemplate,
57
- templateId,
58
- concepts,
59
- selectedDomain: { id: 1 },
60
- };
61
- const wrapper = shallow(<ConceptsBulkUpdate {...props} />);
62
- expect(wrapper.find({ fieldsToOmit: ["_confidential"] })).toHaveLength(1);
51
+ it("DynamicForm rendered if template, template_id, selectedDomain informed", async () => {
52
+ const props = { applyTemplate: jest.fn() };
53
+ const { findByText, queryByText } = render(
54
+ <ConceptsBulkUpdate {...props} />,
55
+ renderOpts
56
+ );
57
+ await waitFor(() => expect(queryByText(/lazy/i)).not.toBeInTheDocument());
58
+ userEvent.click(await findByText("fooDomain"));
59
+ await waitFor(() => expect(queryByText(/f1/)).toBeInTheDocument());
63
60
  });
64
61
 
65
- it("calls bulkUpdate on onClick", () => {
66
- const bulkUpdate = jest.fn();
67
- const domains = [
68
- {
69
- description: "a",
70
- id: 2,
71
- name: "Dos",
72
- },
73
- ];
74
- const template = {
75
- content: [
76
- {
77
- fields: [
78
- {
79
- cardinality: "1",
80
- default: 3,
81
- label: "bg_number",
82
- name: "bg_number",
83
- type: "number",
84
- values: null,
85
- widget: "number",
86
- },
87
- {
88
- cardinality: "1",
89
- default: "22-03-2020",
90
- label: "bg_date",
91
- name: "bg_date",
92
- type: "date",
93
- values: null,
94
- widget: "date",
95
- },
96
- {
97
- cardinality: "?",
98
- default: "19-05-2020 18:10:00",
99
- label: "bg_datetime",
100
- name: "bg_datetime",
101
- type: "datetime",
102
- values: null,
103
- widget: "datetime",
104
- },
105
- ],
106
- is_secret: false,
107
- name: "",
108
- },
109
- ],
110
- id: 10,
111
- label: "nuevos tipos",
112
- name: "nuevostipos",
113
- scope: "bg",
114
- };
115
-
116
- const concepts = [
62
+ it("calls bulkUpdate on onClick", async () => {
63
+ const dispatch = jest.fn();
64
+ const { findByText, queryByText, findByPlaceholderText } = render(
65
+ <ConceptsBulkUpdate />,
117
66
  {
118
- business_concept_id: 18,
119
- content: {
120
- _confidential: "No",
121
- bg_date: "2020-05-16",
122
- bg_datetime: "2020-05-02 18:00",
123
- bg_number: -1,
124
- },
125
- domain: { external_id: null, id: 2, name: "Dos" },
126
- id: 18,
127
- name: "numero",
128
- type: "nuevostipos",
129
- },
130
- {
131
- business_concept_id: 19,
132
- content: {
133
- _confidential: "No",
134
- bg_date: "2020-05-16",
135
- bg_datetime: "2020-05-02 18:00",
136
- bg_number: -1,
137
- },
138
- id: 19,
139
- name: "numero 2",
140
- type: "nuevostipos",
141
- },
142
- ];
143
-
144
- const props = {
145
- loading: false,
146
- template,
147
- selectTemplate,
148
- bulkUpdate,
149
- applyTemplate: applyTemplateWithoutDefaults(template),
150
- concepts,
151
- domains,
152
- selectedDomain: { id: 1 },
153
- };
154
- const wrapper = shallow(<ConceptsBulkUpdate {...props} />);
155
- wrapper.setState({
156
- content: {
157
- bg_number: 1,
158
- bg_date: "2020-05-14",
159
- bg_datetime: "2020-05-28 22:50",
160
- },
161
- domain_id: 1,
162
- });
163
- _.find({ key: "yes" })(
164
- wrapper
165
- .find("ConfirmModal")
166
- .dive()
167
- .find("Modal")
168
- .dive()
169
- .find("ModalActions")
170
- .props().actions
171
- ).onClick({ preventDefault() {} });
172
-
173
- expect(props.bulkUpdate.mock.calls.length).toBe(1);
174
- expect(props.bulkUpdate).toHaveBeenCalledWith({
175
- update_attributes: {
176
- domain_id: 1,
177
- content: {
178
- bg_date: "2020-05-14",
179
- bg_datetime: "2020-05-28 22:50",
180
- bg_number: 1,
181
- },
182
- },
183
- });
184
- });
185
-
186
- it("calls bulkUpdate excluding empty content on onClick", () => {
187
- const bulkUpdate = jest.fn();
188
- const domains = [
189
- {
190
- description: "a",
191
- id: 2,
192
- name: "Dos",
193
- },
194
- ];
195
- const template = {
196
- content: [
197
- {
198
- fields: [
199
- {
200
- cardinality: "1",
201
- default: 3,
202
- label: "bg_number",
203
- name: "bg_number",
204
- type: "number",
205
- values: null,
206
- widget: "number",
207
- },
208
- {
209
- cardinality: "1",
210
- default: "22-03-2020",
211
- label: "bg_date",
212
- name: "bg_date",
213
- type: "date",
214
- values: null,
215
- widget: "date",
216
- },
217
- {
218
- cardinality: "?",
219
- default: "19-05-2020 18:10:00",
220
- label: "bg_datetime",
221
- name: "bg_datetime",
222
- type: "datetime",
223
- values: null,
224
- widget: "datetime",
225
- },
226
- ],
227
- is_secret: false,
228
- name: "",
229
- },
230
- ],
231
- id: 10,
232
- label: "nuevos tipos",
233
- name: "nuevostipos",
234
- scope: "bg",
235
- };
236
-
237
- const concepts = [
238
- {
239
- business_concept_id: 18,
240
- id: 18,
241
- name: "numero",
242
- type: "nuevostipos",
243
- },
244
- {
245
- business_concept_id: 19,
246
- id: 19,
247
- name: "numero 2",
248
- type: "nuevostipos",
249
- },
250
- ];
251
-
252
- const props = {
253
- loading: false,
254
- template,
255
- selectTemplate,
256
- bulkUpdate,
257
- applyTemplate: applyTemplateWithoutDefaults(template),
258
- concepts,
259
- domains,
260
- selectedDomain: { id: 1 },
261
- };
262
- const wrapper = shallow(<ConceptsBulkUpdate {...props} />);
263
- wrapper.setState({
264
- content: {
265
- bg_number: 0,
266
- bg_date: "",
267
- bg_datetime: "",
268
- },
269
- domain_id: 1,
270
- });
271
- _.find({ key: "yes" })(
272
- wrapper
273
- .find("ConfirmModal")
274
- .dive()
275
- .find("Modal")
276
- .dive()
277
- .find("ModalActions")
278
- .props().actions
279
- ).onClick({ preventDefault() {} });
280
-
281
- expect(props.bulkUpdate.mock.calls.length).toBe(1);
282
- expect(props.bulkUpdate).toHaveBeenCalledWith({
283
- update_attributes: {
284
- domain_id: 1,
285
- content: {
286
- bg_number: 0,
287
- },
288
- },
67
+ ...renderOpts,
68
+ dispatch,
69
+ }
70
+ );
71
+ await waitFor(() => expect(queryByText(/lazy/i)).not.toBeInTheDocument());
72
+ userEvent.click(await findByText("fooDomain"));
73
+ await waitFor(() => expect(queryByText(/f1/)).toBeInTheDocument());
74
+ userEvent.type(await findByPlaceholderText("p1"), "abc123456");
75
+ await waitFor(() => expect(queryByText(/Save/)).toBeEnabled());
76
+ userEvent.click(await findByText("Save"));
77
+ userEvent.click(await findByText("Yes"));
78
+ await waitFor(() => {
79
+ expect(dispatch).toHaveBeenLastCalledWith(
80
+ bulkUpdate({
81
+ update_attributes: { content: { f1: "abc123456" }, domain_id: 1 },
82
+ })
83
+ );
289
84
  });
290
85
  });
291
86
  });
@@ -2,20 +2,18 @@ import React from "react";
2
2
  import { waitFor } from "@testing-library/react";
3
3
  import userEvent from "@testing-library/user-event";
4
4
  import { render } from "@truedat/test/render";
5
+ import { domainsMock } from "@truedat/test/mocks";
5
6
  import { SharedToForm } from "../SharedToForm";
6
7
 
8
+ const mocks = [domainsMock({ action: "shareConcept" })];
9
+ const renderOpts = { mocks };
10
+
7
11
  describe("<SharedToForm />", () => {
8
12
  const id = 5;
9
- const domainOptions = [
10
- { id: 1, name: "foo", level: 0 },
11
- { id: 2, name: "bar", level: 0 },
12
- { id: 3, name: "baz", level: 0 },
13
- ];
14
13
  const saveSharedTo = jest.fn();
15
14
  const saving = false;
16
15
  const sharedTo = [{ id: 2, name: "bar" }];
17
16
  const props = {
18
- domainOptions,
19
17
  id,
20
18
  saveSharedTo,
21
19
  saving,
@@ -23,27 +21,39 @@ describe("<SharedToForm />", () => {
23
21
  };
24
22
 
25
23
  it("matches the latest snapshot", async () => {
26
- const { container } = render(<SharedToForm {...props} />);
24
+ const { container, queryByText } = render(
25
+ <SharedToForm {...props} />,
26
+ renderOpts
27
+ );
28
+ await waitFor(() => {
29
+ expect(queryByText(/fooDomain/)).toBeInTheDocument();
30
+ });
27
31
  await waitFor(() => {
28
32
  expect(container).toMatchSnapshot();
29
33
  });
30
34
  });
31
35
 
32
36
  it("enables share button when we select a domain", async () => {
33
- const { findByText, queryByText } = render(<SharedToForm {...props} />);
37
+ const { findByText, queryByText } = render(
38
+ <SharedToForm {...props} />,
39
+ renderOpts
40
+ );
34
41
 
35
42
  expect(queryByText("Share")).toBeDisabled();
36
- userEvent.click(await findByText(/baz/));
43
+ userEvent.click(await findByText(/fooDomain/));
37
44
  await waitFor(() => {
38
45
  expect(queryByText("Share")).not.toBeDisabled();
39
46
  });
40
47
  });
41
48
 
42
49
  it("invokes function when submit button clicked", async () => {
43
- const { findByText, queryByText } = render(<SharedToForm {...props} />);
50
+ const { findByText, queryByText } = render(
51
+ <SharedToForm {...props} />,
52
+ renderOpts
53
+ );
44
54
 
45
55
  expect(queryByText("Share")).toBeDisabled();
46
- userEvent.click(await findByText(/baz/));
56
+ userEvent.click(await findByText(/fooDomain/));
47
57
  await waitFor(() => {
48
58
  expect(queryByText("Share")).not.toBeDisabled();
49
59
  });
@@ -52,7 +62,7 @@ describe("<SharedToForm />", () => {
52
62
  expect(saveSharedTo.mock.calls.length).toBe(1);
53
63
  });
54
64
  expect(saveSharedTo).toHaveBeenCalledWith(
55
- expect.objectContaining({ id, sharedTo: [2, 3] })
65
+ expect.objectContaining({ id, sharedTo: ["2", "1"] })
56
66
  );
57
67
  });
58
68
  });