@truedat/dq 4.44.4 → 4.44.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.
Files changed (29) hide show
  1. package/CHANGELOG.md +11 -0
  2. package/package.json +24 -17
  3. package/src/components/NewRuleImplementation.js +6 -29
  4. package/src/components/RemediationForm.js +20 -47
  5. package/src/components/RemediationPlan.js +1 -1
  6. package/src/components/RuleFilters.js +1 -5
  7. package/src/components/RuleForm.js +20 -59
  8. package/src/components/RuleImplementationFilters.js +1 -5
  9. package/src/components/__tests__/ExecutionForm.spec.js +14 -12
  10. package/src/components/__tests__/NewRuleImplementation.spec.js +27 -15
  11. package/src/components/__tests__/RemediationForm.spec.js +11 -46
  12. package/src/components/__tests__/RemediationPlan.spec.js +49 -73
  13. package/src/components/__tests__/RuleForm.spec.js +22 -52
  14. package/src/components/__tests__/RuleProperties.spec.js +39 -27
  15. package/src/components/__tests__/__snapshots__/ExecutionForm.spec.js.snap +75 -5
  16. package/src/components/__tests__/__snapshots__/NewRuleImplementation.spec.js.snap +202 -2
  17. package/src/components/__tests__/__snapshots__/RemediationForm.spec.js.snap +77 -3
  18. package/src/components/__tests__/__snapshots__/RemediationPlan.spec.js.snap +40 -1
  19. package/src/components/__tests__/__snapshots__/RuleForm.spec.js.snap +156 -6
  20. package/src/components/__tests__/__snapshots__/RuleImplementationsSearch.spec.js.snap +1 -1
  21. package/src/components/__tests__/__snapshots__/RuleProperties.spec.js.snap +68 -56
  22. package/src/components/__tests__/__snapshots__/RuleSearch.spec.js.snap +1 -1
  23. package/src/components/ruleImplementationForm/InformationForm.js +14 -33
  24. package/src/components/ruleImplementationForm/RuleImplementationForm.js +7 -11
  25. package/src/components/ruleImplementationForm/RuleImplementationRawForm.js +20 -39
  26. package/src/components/ruleImplementationForm/__tests__/RuleImplementationForm.spec.js +11 -7
  27. package/src/components/ruleImplementationForm/__tests__/RuleImplementationRawForm.spec.js +175 -156
  28. package/src/components/ruleImplementationForm/__tests__/__snapshots__/RuleImplementationForm.spec.js.snap +75 -0
  29. package/src/components/ruleImplementationForm/__tests__/__snapshots__/RuleImplementationRawForm.spec.js.snap +412 -165
@@ -1,57 +1,22 @@
1
- import React, { Suspense } from "react";
1
+ import React from "react";
2
2
  import { waitFor } from "@testing-library/react";
3
- import userEvent from "@testing-library/user-event";
4
3
  import { render } from "@truedat/test/render";
5
- import { TEMPLATES_QUERY } from "@truedat/core/api/queries";
4
+ import { multipleTemplatesMock } from "@truedat/test/mocks";
6
5
  import RemediationForm from "../RemediationForm";
7
6
 
8
- const templatesMock = {
9
- request: { query: TEMPLATES_QUERY, variables: { scope: "remediation" } },
10
- result: {
11
- data: {
12
- templates: [
13
- {
14
- id: "1",
15
- name: "template1",
16
- label: "template1",
17
- scope: "remediation",
18
- content: [
19
- { name: "g1", fields: [{ name: "field1", label: "field1" }] },
20
- ],
21
- },
22
- {
23
- id: "2",
24
- name: "template2",
25
- label: "template2",
26
- scope: "remediation",
27
- content: {},
28
- },
29
- ],
30
- },
31
- },
32
- };
33
-
34
7
  const renderOpts = {
35
- mocks: [templatesMock],
36
- state: { remediation: {} },
8
+ mocks: [multipleTemplatesMock({ scope: "remediation", domainIds: [1] })],
9
+ state: { remediation: {}, ruleImplementation: { domain_id: 1 } },
10
+ fallback: "lazy",
37
11
  };
38
12
 
39
13
  describe("<RemediationForm />", () => {
40
- it("matches the latest snapshot", () => {
41
- const { container } = render(<RemediationForm />, renderOpts);
42
- expect(container).toMatchSnapshot();
43
- });
44
-
45
- it("selecting a template switches the dynamic form", async () => {
46
- const { getByText, findByText } = render(
47
- <Suspense fallback="loading...">
48
- <RemediationForm />
49
- </Suspense>,
50
- renderOpts
14
+ it("matches the latest snapshot", async () => {
15
+ const { container, queryByText } = render(<RemediationForm />, renderOpts);
16
+ await waitFor(() =>
17
+ expect(queryByText(/loading/i)).not.toBeInTheDocument()
51
18
  );
52
- userEvent.click(await findByText("template1"));
53
- await waitFor(() => {
54
- expect(getByText("field1")).toBeInTheDocument();
55
- });
19
+ await waitFor(() => expect(queryByText(/lazy/i)).not.toBeInTheDocument());
20
+ expect(container).toMatchSnapshot();
56
21
  });
57
22
  });
@@ -1,106 +1,82 @@
1
- import React, { Suspense } from "react";
2
- import { render } from "@truedat/test/render";
1
+ import React from "react";
2
+ import { waitFor } from "@testing-library/react";
3
3
  import userEvent from "@testing-library/user-event";
4
- import { RemediationPlan } from "../RemediationPlan";
5
-
6
- // workaround for enzyme issue with React.useContext
7
- // see https://github.com/airbnb/enzyme/issues/2176#issuecomment-532361526
8
- //jest.spyOn(React, "useContext").mockImplementation(() => intl);
4
+ import { render } from "@truedat/test/render";
5
+ import { multipleTemplatesMock } from "@truedat/test/mocks";
6
+ import RemediationPlan from "../RemediationPlan";
9
7
 
10
8
  jest.mock("react-router-dom", () => ({
11
- ...jest.requireActual("react-router-dom"), // use actual for all non-hook parts
9
+ ...jest.requireActual("react-router-dom"),
12
10
  useParams: () => ({
13
11
  id: 777,
14
12
  implementation_id: 862,
15
13
  rule_result_id: 66322,
16
14
  }),
17
- useRouteMatch: () => ({
18
- url: "/rules/777/implementations/862/results/66322",
19
- }),
20
15
  }));
21
16
 
22
- describe("<RemediationPlan />", () => {
23
- const template1 = { id: 1, name: "remediation_template1" };
24
- const template2 = { id: 2, name: "remediation_template2" };
25
- const props = {
26
- remediationLoading: false,
27
- clearRemediation: jest.fn(),
28
- fetchRemediation: jest.fn(),
29
- templates: [template1, template2],
30
- lastResultId: undefined,
31
- manageRemediations: true,
32
- };
33
- const remediation = {
34
- df_content: {
35
- texto: "66322_cambiado",
36
- },
37
- df_name: "remediation_template",
38
- id: 60,
39
- };
17
+ const remediation = {
18
+ df_content: {
19
+ texto: "66322_cambiado",
20
+ },
21
+ df_name: "template1",
22
+ id: 60,
23
+ };
40
24
 
41
- const renderOpts = {
42
- messages: {
43
- en: {
44
- "actions.cancel": "Cancel",
45
- "actions.edit": "Edit",
46
- "actions.save": "Save",
47
- remediation: "Remediation plan",
48
- "remediation.actions.create": "Create Remediation Plan",
49
- "remediation.actions.edit": "Edit Remediation Plan",
50
- "template.not_found.message": "Error: Invalid template",
51
- },
52
- },
53
- };
25
+ const state = {
26
+ remediation,
27
+ remediationLoading: false,
28
+ remediationActions: { create: true },
29
+ };
54
30
 
55
- it("matches the latest snapshot", () => {
56
- const { container } = render(
57
- <Suspense fallback={null}>
58
- <RemediationPlan {...props} />
59
- </Suspense>,
60
- renderOpts
31
+ const renderOpts = {
32
+ state,
33
+ routes: ["/rules/777/implementations/862/results/66322"],
34
+ fallback: "lazy",
35
+ mocks: [multipleTemplatesMock({ scope: "remediation", domainIds: [1] })],
36
+ };
37
+
38
+ describe("<RemediationPlan />", () => {
39
+ it("matches the latest snapshot", async () => {
40
+ const { container, queryByText } = render(<RemediationPlan />, renderOpts);
41
+ await waitFor(() =>
42
+ expect(queryByText(/loading/i)).not.toBeInTheDocument()
61
43
  );
44
+ await waitFor(() => expect(queryByText(/lazy/i)).not.toBeInTheDocument());
62
45
  expect(container).toMatchSnapshot();
63
46
  });
64
47
 
65
- it("New remediation component is shown if there is no existing remediation", () => {
48
+ it("New remediation component is shown if there is no existing remediation", async () => {
66
49
  const state = {
67
- remediationActions: {
68
- create: { href: "something" },
69
- },
70
- templates: props.templates,
50
+ remediationActions: { create: true },
51
+ templates: [{ id: 1 }],
71
52
  };
72
-
73
- const { queryByText } = render(<RemediationPlan {...props} />, {
53
+ const { queryByText } = render(<RemediationPlan />, {
74
54
  ...renderOpts,
75
55
  state,
76
56
  });
77
-
78
- expect(queryByText(/Create Remediation Plan/)).toBeInTheDocument();
57
+ await waitFor(() =>
58
+ expect(queryByText(/Create Remediation Plan/)).toBeInTheDocument()
59
+ );
79
60
  });
80
61
 
81
- it("Remediation view is shown if there is an existing remediation", () => {
82
- const { queryByText } = render(
83
- <Suspense fallback={null}>
84
- <RemediationPlan {...props} remediation={remediation} />
85
- </Suspense>,
86
- renderOpts
87
- );
62
+ it("Remediation view is shown if there is an existing remediation", async () => {
63
+ const { queryByText } = render(<RemediationPlan />, renderOpts);
88
64
 
89
- expect(queryByText(/Edit/)).toBeInTheDocument();
65
+ await waitFor(() => expect(queryByText(/Edit/)).toBeInTheDocument());
90
66
  });
91
67
 
92
68
  it("Remediation form is shown if edit button is clicked", async () => {
93
- const { queryByText, findByRole } = await render(
94
- <Suspense fallback={null}>
95
- <RemediationPlan {...props} remediation={remediation} />
96
- </Suspense>,
69
+ const { queryByText, queryByRole } = render(
70
+ <RemediationPlan />,
97
71
  renderOpts
98
72
  );
99
73
 
74
+ await waitFor(() => expect(queryByText("loading")).not.toBeInTheDocument());
100
75
  userEvent.click(await queryByText(/Edit/));
101
-
102
- expect(
103
- await findByRole("form", { name: "remediation-form" })
104
- ).toBeInTheDocument();
76
+ await waitFor(() =>
77
+ expect(
78
+ queryByRole("form", { name: "remediation-form" })
79
+ ).toBeInTheDocument()
80
+ );
105
81
  });
106
82
  });
@@ -1,36 +1,10 @@
1
1
  import React from "react";
2
2
  import { waitFor } from "@testing-library/react";
3
- import userEvent from "@testing-library/user-event";
4
3
  import { render } from "@truedat/test/render";
5
- import { TEMPLATES_QUERY } from "@truedat/core/api/queries";
4
+ import userEvent from "@testing-library/user-event";
5
+ import { multipleTemplatesMock } from "@truedat/test/mocks";
6
6
  import RuleForm from "../RuleForm";
7
7
 
8
- const templatesMock = {
9
- request: { query: TEMPLATES_QUERY, variables: { scope: "remediation" } },
10
- result: {
11
- data: {
12
- templates: [
13
- {
14
- id: "1",
15
- name: "template1",
16
- label: "template1",
17
- scope: "remediation",
18
- content: [
19
- { name: "g1", fields: [{ name: "field1", label: "field1" }] },
20
- ],
21
- },
22
- {
23
- id: "2",
24
- name: "template2",
25
- label: "template2",
26
- scope: "remediation",
27
- content: {},
28
- },
29
- ],
30
- },
31
- },
32
- };
33
-
34
8
  const rule = {
35
9
  id: 123,
36
10
  business_concept_id: "2D2B3",
@@ -43,49 +17,45 @@ const state = {
43
17
  domains: [{ id: 1, name: "domain1" }],
44
18
  };
45
19
 
46
- const renderOpts = { mocks: [templatesMock], state };
20
+ const renderOpts = {
21
+ mocks: [multipleTemplatesMock({ scope: "dq", domainIds: [1] })],
22
+ state,
23
+ fallback: "lazy",
24
+ };
47
25
 
48
26
  describe("<RuleForm />", () => {
49
27
  it("matches the latest snapshot", async () => {
50
28
  const props = { onSubmit: jest.fn() };
51
29
  const { container, queryByText } = render(
52
- <React.Suspense fallback="loading...">
53
- <RuleForm {...props} />
54
- </React.Suspense>,
30
+ <RuleForm {...props} />,
55
31
  renderOpts
56
32
  );
57
- await waitFor(() => {
58
- expect(queryByText(/loading/i)).not.toBeInTheDocument();
59
- });
33
+ await waitFor(() =>
34
+ expect(queryByText(/loading/i)).not.toBeInTheDocument()
35
+ );
36
+ await waitFor(() => expect(queryByText(/lazy/i)).not.toBeInTheDocument());
60
37
  expect(container).toMatchSnapshot();
61
38
  });
62
39
 
63
40
  it("matches the latest snapshot (edit mode)", async () => {
64
41
  const props = { onSubmit: jest.fn(), editMode: true };
65
- const { container, queryByText } = render(
66
- <React.Suspense fallback="loading...">
67
- <RuleForm {...props} />
68
- </React.Suspense>,
69
- { ...renderOpts, state: { ...state, rule } }
70
- );
71
- await waitFor(() => {
72
- expect(queryByText(/loading/i)).not.toBeInTheDocument();
42
+ const { container, queryByText } = render(<RuleForm {...props} />, {
43
+ ...renderOpts,
44
+ state: { ...state, rule },
73
45
  });
46
+ await waitFor(() =>
47
+ expect(queryByText(/loading/i)).not.toBeInTheDocument()
48
+ );
49
+ await waitFor(() => expect(queryByText(/lazy/i)).not.toBeInTheDocument());
74
50
  expect(container).toMatchSnapshot();
75
51
  });
76
52
 
77
53
  it("enables save button after name and domain are specified", async () => {
78
54
  const props = { onSubmit: jest.fn() };
79
- const { getByRole, queryByText } = render(
80
- <React.Suspense fallback="loading...">
81
- <RuleForm {...props} />
82
- </React.Suspense>,
83
- renderOpts
55
+ const { getByRole } = render(<RuleForm {...props} />, renderOpts);
56
+ await waitFor(() =>
57
+ expect(getByRole("button", { name: /save/i })).toBeDisabled()
84
58
  );
85
- await waitFor(() => {
86
- expect(queryByText(/loading/i)).not.toBeInTheDocument();
87
- });
88
- expect(getByRole("button", { name: /save/i })).toBeDisabled();
89
59
  userEvent.click(getByRole("option", { name: "domain1" }));
90
60
  userEvent.type(getByRole("textbox", { name: /rule name/i }), "rule1");
91
61
  await waitFor(() => {
@@ -1,37 +1,49 @@
1
1
  import React from "react";
2
- import { shallowWithIntl } from "@truedat/test/intl-stub";
3
- import { RuleProperties } from "../RuleProperties";
2
+ import { waitFor } from "@testing-library/react";
3
+ import { render } from "@truedat/test/render";
4
+ import RuleProperties from "../RuleProperties";
4
5
 
5
- const mockHistory = {
6
- push: jest.fn(),
7
- };
8
-
9
- jest.mock("react-router-dom", () => ({
10
- ...jest.requireActual("react-router-dom"),
11
- useHistory: () => mockHistory,
12
- }));
13
-
14
- describe("<RuleProperties />", () => {
15
- it("matches the latest snapshot", () => {
16
- const props = {
17
- business_concept_id: "2D2B3",
18
- domain_id: 1,
19
- domain: { id: 1, name: "foo", external_id: "bar" },
20
- description: {
21
- document: {
6
+ const rule = {
7
+ active: true,
8
+ business_concept_id: "2D2B3",
9
+ domain_id: 1,
10
+ domain: { id: 1, name: "foo", external_id: "bar" },
11
+ description: {
12
+ document: {
13
+ data: {},
14
+ nodes: [
15
+ {
22
16
  data: {},
23
- object: "document",
24
17
  nodes: [
25
18
  {
26
- data: {},
27
- nodes: [{ marks: [{ data: {}, object: "text", text: "desc1" }] }],
19
+ marks: [],
20
+ object: "text",
21
+ text: "desc",
28
22
  },
29
23
  ],
24
+ object: "block",
25
+ type: "paragraph",
30
26
  },
31
- },
32
- rule_type: { name: "type1" },
33
- };
34
- const wrapper = shallowWithIntl(<RuleProperties {...props} />);
35
- expect(wrapper).toMatchSnapshot();
27
+ ],
28
+ object: "document",
29
+ },
30
+ object: "value",
31
+ },
32
+ rule_type: { name: "type1" },
33
+ };
34
+
35
+ const renderOpts = {
36
+ state: { rule },
37
+ fallback: "lazy",
38
+ };
39
+
40
+ describe("<RuleProperties />", () => {
41
+ it("matches the latest snapshot", async () => {
42
+ const { container, queryByText } = render(<RuleProperties />, renderOpts);
43
+ await waitFor(() =>
44
+ expect(queryByText(/loading/i)).not.toBeInTheDocument()
45
+ );
46
+ await waitFor(() => expect(queryByText(/lazy/i)).not.toBeInTheDocument());
47
+ expect(container).toMatchSnapshot();
36
48
  });
37
49
  });
@@ -5,13 +5,83 @@ exports[`<ExecutionForm /> matches the latest snapshot 1`] = `
5
5
  <h2
6
6
  class="ui header"
7
7
  >
8
- header
8
+ Implementations execution
9
9
  </h2>
10
10
  <form
11
- class="ui loading form"
11
+ class="ui form"
12
12
  >
13
+ <div
14
+ class="field"
15
+ >
16
+ <label>
17
+ Template
18
+ </label>
19
+ <div
20
+ class="field"
21
+ >
22
+ <div
23
+ aria-busy="false"
24
+ aria-expanded="false"
25
+ class="ui search selection dropdown"
26
+ name="template"
27
+ role="combobox"
28
+ >
29
+ <input
30
+ aria-autocomplete="list"
31
+ autocomplete="off"
32
+ class="search"
33
+ tabindex="0"
34
+ type="text"
35
+ value=""
36
+ />
37
+ <div
38
+ aria-atomic="true"
39
+ aria-live="polite"
40
+ class="divider default text"
41
+ role="alert"
42
+ >
43
+ Select a template...
44
+ </div>
45
+ <i
46
+ aria-hidden="true"
47
+ class="dropdown icon"
48
+ />
49
+ <div
50
+ class="menu transition"
51
+ role="listbox"
52
+ >
53
+ <div
54
+ aria-checked="false"
55
+ aria-selected="true"
56
+ class="selected item"
57
+ role="option"
58
+ style="pointer-events: all;"
59
+ >
60
+ <span
61
+ class="text"
62
+ >
63
+ template1
64
+ </span>
65
+ </div>
66
+ <div
67
+ aria-checked="false"
68
+ aria-selected="false"
69
+ class="item"
70
+ role="option"
71
+ style="pointer-events: all;"
72
+ >
73
+ <span
74
+ class="text"
75
+ >
76
+ template2
77
+ </span>
78
+ </div>
79
+ </div>
80
+ </div>
81
+ </div>
82
+ </div>
13
83
  <p>
14
- content
84
+ This implementation will be executed. Are you sure?
15
85
  </p>
16
86
  <div
17
87
  class="actions"
@@ -19,12 +89,12 @@ exports[`<ExecutionForm /> matches the latest snapshot 1`] = `
19
89
  <button
20
90
  class="ui secondary button"
21
91
  >
22
- cancel
92
+ Cancel
23
93
  </button>
24
94
  <button
25
95
  class="ui primary button"
26
96
  >
27
- create
97
+ Create
28
98
  </button>
29
99
  </div>
30
100
  </form>