@truedat/cx 7.5.9 → 7.5.11

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 (110) hide show
  1. package/package.json +40 -70
  2. package/src/configurations/components/Configuration.js +3 -3
  3. package/src/configurations/components/ConfigurationActions.js +1 -2
  4. package/src/configurations/components/ConfigurationBreadcrumbs.js +2 -3
  5. package/src/configurations/components/ConfigurationCards.js +1 -2
  6. package/src/configurations/components/ConfigurationForm.js +6 -11
  7. package/src/configurations/components/ConfigurationLoader.js +1 -2
  8. package/src/configurations/components/ConfigurationRoutes.js +61 -72
  9. package/src/configurations/components/ConfigurationTokenLoader.js +0 -1
  10. package/src/configurations/components/Configurations.js +2 -2
  11. package/src/configurations/components/ConfigurationsLoader.js +0 -1
  12. package/src/configurations/components/DynamicConfigurationForm.js +5 -7
  13. package/src/configurations/components/EditConfiguration.js +0 -1
  14. package/src/configurations/components/NewConfiguration.js +0 -1
  15. package/src/configurations/components/__tests__/Configuration.spec.js +17 -10
  16. package/src/configurations/components/__tests__/ConfigurationCards.spec.js +22 -13
  17. package/src/configurations/components/__tests__/ConfigurationForm.spec.js +5 -5
  18. package/src/configurations/components/__tests__/ConfigurationLoader.spec.js +44 -36
  19. package/src/configurations/components/__tests__/ConfigurationTokenLoader.spec.js +46 -45
  20. package/src/configurations/components/__tests__/Configurations.spec.js +20 -22
  21. package/src/configurations/components/__tests__/ConfigurationsLoader.spec.js +32 -33
  22. package/src/configurations/components/__tests__/EditConfiguration.spec.js +5 -5
  23. package/src/configurations/components/__tests__/NewConfiguration.spec.js +0 -1
  24. package/src/configurations/components/__tests__/__snapshots__/Configuration.spec.js.snap +122 -57
  25. package/src/configurations/components/__tests__/__snapshots__/ConfigurationCards.spec.js.snap +160 -361
  26. package/src/configurations/components/__tests__/__snapshots__/ConfigurationForm.spec.js.snap +7 -6
  27. package/src/configurations/components/__tests__/__snapshots__/ConfigurationLoader.spec.js.snap +5 -31
  28. package/src/configurations/components/__tests__/__snapshots__/ConfigurationTokenLoader.spec.js.snap +5 -9
  29. package/src/configurations/components/__tests__/__snapshots__/Configurations.spec.js.snap +91 -72
  30. package/src/configurations/components/__tests__/__snapshots__/ConfigurationsLoader.spec.js.snap +5 -27
  31. package/src/configurations/components/__tests__/__snapshots__/EditConfiguration.spec.js.snap +12 -10
  32. package/src/configurations/components/__tests__/__snapshots__/NewConfiguration.spec.js.snap +11 -9
  33. package/src/configurations/components/index.js +1 -1
  34. package/src/configurations/reducers/configurationRedirect.js +1 -1
  35. package/src/configurations/reducers/configurations.js +1 -1
  36. package/src/configurations/reducers/index.js +1 -1
  37. package/src/configurations/reducers/systemConfigurations.js +1 -1
  38. package/src/configurations/sagas/signConfiguration.js +3 -1
  39. package/src/jobs/components/Job.js +0 -1
  40. package/src/jobs/components/JobBreadcrumbs.js +2 -3
  41. package/src/jobs/components/JobLoader.js +2 -2
  42. package/src/jobs/components/JobRoutes.js +28 -40
  43. package/src/jobs/components/JobRow.js +4 -4
  44. package/src/jobs/components/Jobs.js +5 -4
  45. package/src/jobs/components/JobsLabelResults.js +2 -3
  46. package/src/jobs/components/JobsSearch.js +0 -1
  47. package/src/jobs/components/JobsTable.js +3 -3
  48. package/src/jobs/components/JobsView.js +0 -1
  49. package/src/jobs/components/SourceJobs.js +0 -1
  50. package/src/jobs/components/__tests__/Job.spec.js +9 -11
  51. package/src/jobs/components/__tests__/JobBreadcrumbs.spec.js +5 -5
  52. package/src/jobs/components/__tests__/JobLoader.spec.js +12 -12
  53. package/src/jobs/components/__tests__/JobRow.spec.js +21 -20
  54. package/src/jobs/components/__tests__/Jobs.spec.js +1 -7
  55. package/src/jobs/components/__tests__/JobsLoader.spec.js +9 -9
  56. package/src/jobs/components/__tests__/JobsTable.spec.js +33 -28
  57. package/src/jobs/components/__tests__/JobsView.spec.js +1 -7
  58. package/src/jobs/components/__tests__/SourceJobs.spec.js +1 -7
  59. package/src/jobs/components/__tests__/__snapshots__/Job.spec.js.snap +143 -36
  60. package/src/jobs/components/__tests__/__snapshots__/JobBreadcrumbs.spec.js.snap +20 -30
  61. package/src/jobs/components/__tests__/__snapshots__/Jobs.spec.js.snap +10 -23
  62. package/src/jobs/components/__tests__/__snapshots__/JobsTable.spec.js.snap +7 -7
  63. package/src/jobs/components/__tests__/__snapshots__/JobsView.spec.js.snap +12 -24
  64. package/src/jobs/components/__tests__/__snapshots__/SourceJobs.spec.js.snap +8 -21
  65. package/src/jobs/reducers/jobActiveFilters.js +1 -1
  66. package/src/jobs/sagas/fetchJob.js +1 -1
  67. package/src/jobs/selectors/jobColumnsSelector.js +0 -1
  68. package/src/jobs/selectors/sourceJobColumnsSelector.js +0 -1
  69. package/src/sources/components/EditSource.js +0 -1
  70. package/src/sources/components/JobForm.js +1 -1
  71. package/src/sources/components/NewJob.js +0 -1
  72. package/src/sources/components/NewSource.js +0 -1
  73. package/src/sources/components/Source.js +0 -1
  74. package/src/sources/components/SourceActions.js +1 -2
  75. package/src/sources/components/SourceBreadcrumbs.js +1 -2
  76. package/src/sources/components/SourceConfiguration.js +3 -3
  77. package/src/sources/components/SourceDetail.js +46 -50
  78. package/src/sources/components/SourceForm.js +4 -7
  79. package/src/sources/components/SourceHeader.js +0 -1
  80. package/src/sources/components/SourceRoutes.js +30 -23
  81. package/src/sources/components/SourceSelector.js +0 -1
  82. package/src/sources/components/SourceTabs.js +14 -7
  83. package/src/sources/components/Sources.js +2 -2
  84. package/src/sources/components/SourcesTable.js +1 -2
  85. package/src/sources/components/__tests__/EditSource.spec.js +10 -12
  86. package/src/sources/components/__tests__/NewSource.spec.js +5 -10
  87. package/src/sources/components/__tests__/Source.spec.js +19 -27
  88. package/src/sources/components/__tests__/SourceActions.spec.js +1 -2
  89. package/src/sources/components/__tests__/SourceBreadcrumbs.spec.js +0 -1
  90. package/src/sources/components/__tests__/SourceDetail.spec.js +62 -38
  91. package/src/sources/components/__tests__/SourceForm.spec.js +109 -86
  92. package/src/sources/components/__tests__/SourceHeader.spec.js +1 -2
  93. package/src/sources/components/__tests__/SourceRoutes.spec.js +79 -7
  94. package/src/sources/components/__tests__/SourceSelector.spec.js +0 -1
  95. package/src/sources/components/__tests__/SourceTabs.spec.js +3 -4
  96. package/src/sources/components/__tests__/Sources.spec.js +24 -39
  97. package/src/sources/components/__tests__/SourcesTable.spec.js +48 -65
  98. package/src/sources/components/__tests__/__snapshots__/EditSource.spec.js.snap +134 -15
  99. package/src/sources/components/__tests__/__snapshots__/NewSource.spec.js.snap +36 -23
  100. package/src/sources/components/__tests__/__snapshots__/Source.spec.js.snap +28 -31
  101. package/src/sources/components/__tests__/__snapshots__/SourceActions.spec.js.snap +1 -1
  102. package/src/sources/components/__tests__/__snapshots__/SourceBreadcrumbs.spec.js.snap +2 -1
  103. package/src/sources/components/__tests__/__snapshots__/SourceDetail.spec.js.snap +13 -172
  104. package/src/sources/components/__tests__/__snapshots__/SourceForm.spec.js.snap +132 -106
  105. package/src/sources/components/__tests__/__snapshots__/SourceHeader.spec.js.snap +4 -4
  106. package/src/sources/components/__tests__/__snapshots__/SourceRoutes.spec.js.snap +47 -5
  107. package/src/sources/components/__tests__/__snapshots__/SourceTabs.spec.js.snap +5 -3
  108. package/src/sources/components/__tests__/__snapshots__/Sources.spec.js.snap +14 -11
  109. package/src/sources/components/__tests__/__snapshots__/SourcesTable.spec.js.snap +17 -12
  110. package/src/jobs/components/ConfigurationRoutes.js +0 -31
@@ -1,12 +1,7 @@
1
- import React from "react";
2
- import { shallow } from "enzyme";
3
- import { intl } from "@truedat/test/intl-stub";
1
+ import { render, waitForLoad } from "@truedat/test/render";
2
+ import { multipleTemplatesMock } from "@truedat/test/mocks";
4
3
  import { EditSource } from "../EditSource";
5
4
 
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);
9
-
10
5
  describe("<EditSource />", () => {
11
6
  const updateSource = jest.fn();
12
7
  const source = {
@@ -14,11 +9,14 @@ describe("<EditSource />", () => {
14
9
  config: { a: { value: 1, origin: "user" } },
15
10
  type: "micro",
16
11
  };
17
- const formatMessage = jest.fn();
18
- const props = { source, updateSource, formatMessage };
12
+ const props = { source, updateSource };
19
13
 
20
- it("matches the latest snapshot", () => {
21
- const wrapper = shallow(<EditSource {...props} />);
22
- expect(wrapper).toMatchSnapshot();
14
+ it("matches the latest snapshot", async () => {
15
+ const renderOpts = {
16
+ mocks: [multipleTemplatesMock({ scope: "cx" })],
17
+ };
18
+ const rendered = render(<EditSource {...props} />, renderOpts);
19
+ await waitForLoad(rendered);
20
+ expect(rendered.container).toMatchSnapshot();
23
21
  });
24
22
  });
@@ -1,18 +1,13 @@
1
- import React from "react";
2
- import { shallow } from "enzyme";
3
- import { intl } from "@truedat/test/intl-stub";
1
+ import { render, waitForLoad } from "@truedat/test/render";
4
2
  import { NewSource } from "../NewSource";
5
3
 
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);
9
-
10
4
  describe("<NewSource />", () => {
11
5
  const createSource = jest.fn();
12
6
  const props = { createSource };
13
7
 
14
- it("matches the latest snapshot", () => {
15
- const wrapper = shallow(<NewSource {...props} />);
16
- expect(wrapper).toMatchSnapshot();
8
+ it("matches the latest snapshot", async () => {
9
+ const rendered = render(<NewSource {...props} />);
10
+ await waitForLoad(rendered);
11
+ expect(rendered.container).toMatchSnapshot();
17
12
  });
18
13
  });
@@ -1,37 +1,29 @@
1
- import React from "react";
2
- import { shallow } from "enzyme";
3
- import { Source } from "../Source";
1
+ import { render, waitForLoad } from "@truedat/test/render";
2
+ import Source from "../Source";
3
+
4
+ jest.mock("../SourceDetail", () => {
5
+ return {
6
+ __esModule: true,
7
+ default: () => <div>Mocked Source Detail</div>,
8
+ };
9
+ });
10
+ jest.mock("../SourceHeader", () => {
11
+ return {
12
+ __esModule: true,
13
+ default: () => <div>Mocked Source Header</div>,
14
+ };
15
+ });
4
16
 
5
17
  describe("<Source />", () => {
6
18
  const props = {
7
- updateSource: jest.fn(),
8
19
  source: {
9
20
  external_id: "Micro1",
10
- config: { a: { value: 1, origin: "user" } },
11
- type: "micro",
12
- },
13
- template: {
14
- content: [
15
- {
16
- cardinality: "1",
17
- disabled: true,
18
- group: "New Group 1",
19
- label: "a",
20
- name: "a",
21
- type: "string",
22
- widget: "string",
23
- },
24
- ],
25
- id: 36,
26
- label: "app-admin",
27
- name: "micro",
28
- scope: "cx",
29
21
  },
30
- match: { params: { external_id: "Micro" } },
31
22
  };
32
23
 
33
- it("matches the latest snapshot", () => {
34
- const wrapper = shallow(<Source {...props} />);
35
- expect(wrapper).toMatchSnapshot();
24
+ it("matches the latest snapshot", async () => {
25
+ const rendered = render(<Source {...props} />);
26
+ await waitForLoad(rendered);
27
+ expect(rendered.container).toMatchSnapshot();
36
28
  });
37
29
  });
@@ -1,4 +1,3 @@
1
- import React from "react";
2
1
  import { render } from "@truedat/test/render";
3
2
  import { SourceActions } from "../SourceActions";
4
3
 
@@ -22,7 +21,7 @@ const renderOpts = {
22
21
  describe("<SourceActions />", () => {
23
22
  const source = {
24
23
  __typename: "Source",
25
- id: 123,
24
+ id: "123",
26
25
  externalId: "Micro1",
27
26
  config: { a: { value: 1, origin: "user" } },
28
27
  type: "micro",
@@ -1,4 +1,3 @@
1
- import React from "react";
2
1
  import { render } from "@truedat/test/render";
3
2
  import SourceBreadcrumbs from "../SourceBreadcrumbs";
4
3
 
@@ -1,43 +1,67 @@
1
- import React, { Suspense } from "react";
2
- import { waitFor } from "@testing-library/react";
3
- import { render } from "@truedat/test/render";
4
- import SourceDetail from "../SourceDetail";
1
+ import React from "react";
2
+ import { render, waitForLoad } from "@truedat/test/render";
3
+ import { SourceDetail } from "../SourceDetail";
4
+ import {
5
+ SOURCE,
6
+ SOURCE_EDIT,
7
+ SOURCE_JOBS,
8
+ SOURCE_JOBS_NEW,
9
+ } from "@truedat/core/routes";
5
10
 
6
- const jobs = [
7
- {
8
- external_id: "job1",
9
- source_id: 123,
10
- end_date: "2022-02-02T00:00:00.000Z",
11
- type: "catalog",
12
- status: "SUCCESS",
13
- },
14
- {
15
- external_id: "job2",
16
- source_id: 123,
17
- end_date: "2020-02-01T00:00:00.000Z",
18
- type: "catalog",
19
- status: "FAILED",
20
- message: "Something went wrong",
21
- },
22
- ];
23
-
24
- const source = {
25
- externalId: "foo",
26
- id: 123,
27
- };
28
- const renderOpts = {
29
- routes: ["/sources/123/jobs"],
30
- state: { jobs, jobCount: 42 },
31
- };
11
+ jest.mock("../../../jobs/components/Job", () => () => <div>Job</div>);
12
+ jest.mock("../../../jobs/components/JobLoader", () => () => (
13
+ <div>JobLoader</div>
14
+ ));
15
+ jest.mock("../../../jobs/components/SourceJobs", () => () => (
16
+ <div>SourceJobs</div>
17
+ ));
18
+ jest.mock("../EditSource", () => () => <div>EditSource</div>);
19
+ jest.mock("../NewJob", () => () => <div>NewJob</div>);
20
+ jest.mock("../SourceConfiguration", () => () => <div>SourceConfiguration</div>);
21
+ jest.mock("../SourceTabs", () => () => <div>SourceTabs</div>);
32
22
 
33
23
  describe("<SourceDetail />", () => {
34
- it("matches the latest snapshot (jobs tab)", async () => {
35
- const { container } = render(
36
- <Suspense fallback={null}>
37
- <SourceDetail source={source} />
38
- </Suspense>,
39
- renderOpts
40
- );
41
- await waitFor(() => expect(container).toMatchSnapshot());
24
+ const source = {
25
+ id: 1,
26
+ type: "test",
27
+ externalId: "test-1",
28
+ };
29
+
30
+ it("renders correctly with default route", async () => {
31
+ const rendered = render(<SourceDetail source={source} />);
32
+ await waitForLoad(rendered);
33
+ expect(rendered.container).toMatchSnapshot();
34
+ });
35
+
36
+ it("renders correctly with edit route", async () => {
37
+ const rendered = render(<SourceDetail source={source} />, {
38
+ routes: [SOURCE_EDIT.replace(":id", "1")],
39
+ });
40
+ await waitForLoad(rendered);
41
+ expect(rendered.container).toMatchSnapshot();
42
+ });
43
+
44
+ it("renders correctly with jobs route", async () => {
45
+ const rendered = render(<SourceDetail source={source} />, {
46
+ routes: [SOURCE_JOBS.replace(":id", "1")],
47
+ });
48
+ await waitForLoad(rendered);
49
+ expect(rendered.container).toMatchSnapshot();
50
+ });
51
+
52
+ it("renders correctly with new job route", async () => {
53
+ const rendered = render(<SourceDetail source={source} />, {
54
+ routes: [SOURCE_JOBS_NEW.replace(":id", "1")],
55
+ });
56
+ await waitForLoad(rendered);
57
+ expect(rendered.container).toMatchSnapshot();
58
+ });
59
+
60
+ it("renders correctly with specific job route", async () => {
61
+ const rendered = render(<SourceDetail source={source} />, {
62
+ routes: [`${SOURCE_JOBS.replace(":id", "1")}/123`],
63
+ });
64
+ await waitForLoad(rendered);
65
+ expect(rendered.container).toMatchSnapshot();
42
66
  });
43
67
  });
@@ -1,16 +1,34 @@
1
- import React from "react";
2
- import { shallowWithIntl } from "@truedat/test/intl-stub";
3
- import { SourceForm } from "../SourceForm";
1
+ import userEvent from "@testing-library/user-event";
2
+ import { within } from "@testing-library/dom";
3
+ import { render, waitForLoad } from "@truedat/test/render";
4
+ import { templatesMockWith } from "@truedat/test/mocks";
5
+ import SourceForm from "../SourceForm";
4
6
 
5
- describe("<SourceForm />", () => {
6
- const applyTemplate = (x) => x;
7
- const templatesLoaded = true;
8
- const source = {
9
- external_id: "Micro1",
10
- config: { a: { value: 1, origin: "user" } },
11
- type: "micro",
12
- };
13
- const template = {
7
+ const source = {
8
+ external_id: "Micro1",
9
+ config: { a: { value: 1, origin: "user" } },
10
+ type: "micro",
11
+ };
12
+ const template = {
13
+ content: [
14
+ {
15
+ cardinality: "1",
16
+ disabled: true,
17
+ group: "New Group 1",
18
+ label: "a",
19
+ name: "a",
20
+ type: "string",
21
+ widget: "string",
22
+ },
23
+ ],
24
+ id: 36,
25
+ label: "app-admin",
26
+ name: "micro",
27
+ scope: "cx",
28
+ };
29
+
30
+ const templates = [
31
+ {
14
32
  content: [
15
33
  {
16
34
  cardinality: "1",
@@ -26,91 +44,96 @@ describe("<SourceForm />", () => {
26
44
  label: "app-admin",
27
45
  name: "micro",
28
46
  scope: "cx",
29
- };
47
+ },
48
+ {
49
+ content: [
50
+ {
51
+ cardinality: "*",
52
+ disabled: true,
53
+ group: "New Group 1",
54
+ label: "url",
55
+ name: "url_cx",
56
+ type: "url",
57
+ widget: "pair_list",
58
+ },
59
+ {
60
+ cardinality: "?",
61
+ disabled: true,
62
+ group: "New Group 1",
63
+ label: "a",
64
+ name: "a",
65
+ type: "string",
66
+ widget: "string",
67
+ },
68
+ {
69
+ cardinality: "+",
70
+ disabled: true,
71
+ group: "New Group 1",
72
+ label: "lista",
73
+ name: "lista",
74
+ type: "string",
75
+ widget: "string",
76
+ },
77
+ ],
78
+ id: 35,
79
+ label: "a",
80
+ name: "a",
81
+ scope: "cx",
82
+ },
83
+ ];
30
84
 
31
- const templates = [
32
- {
33
- content: [
34
- {
35
- cardinality: "1",
36
- disabled: true,
37
- group: "New Group 1",
38
- label: "a",
39
- name: "a",
40
- type: "string",
41
- widget: "string",
42
- },
43
- ],
44
- id: 36,
45
- label: "app-admin",
46
- name: "micro",
47
- scope: "cx",
48
- },
49
- {
50
- content: [
51
- {
52
- cardinality: "*",
53
- disabled: true,
54
- group: "New Group 1",
55
- label: "url",
56
- name: "url_cx",
57
- type: "url",
58
- widget: "pair_list",
59
- },
60
- {
61
- cardinality: "?",
62
- disabled: true,
63
- group: "New Group 1",
64
- label: "a",
65
- name: "a",
66
- type: "string",
67
- widget: "string",
68
- },
69
- {
70
- cardinality: "+",
71
- disabled: true,
72
- group: "New Group 1",
73
- label: "lista",
74
- name: "lista",
75
- type: "string",
76
- widget: "string",
77
- },
78
- ],
79
- id: 35,
80
- label: "a",
81
- name: "a",
82
- scope: "cx",
83
- },
84
- ];
85
+ const renderOpts = {
86
+ mocks: [templatesMockWith({ scope: "cx" }, templates)],
87
+ };
85
88
 
89
+ describe("<SourceForm />", () => {
86
90
  const props = {
87
- applyTemplate,
88
- templatesLoaded,
91
+ onSubmit: jest.fn(),
89
92
  source,
90
93
  template,
91
- templates,
92
94
  };
93
95
 
94
- describe("with multiple templates", () => {
95
- const wrapper = shallowWithIntl(
96
- <SourceForm templates={templates} {...props} />
97
- );
96
+ describe("SourceForm", () => {
97
+ it("matches the latest snapshot", async () => {
98
+ const rendered = render(<SourceForm {...props} />, renderOpts);
98
99
 
99
- it("matches the latest snapshot", () => {
100
- expect(wrapper).toMatchSnapshot();
100
+ await waitForLoad(rendered);
101
+ expect(rendered.container).toMatchSnapshot();
101
102
  });
102
- });
103
103
 
104
- describe("content changes", () => {
105
- it("sets name in state when name field changes", () => {
106
- const wrapper = shallowWithIntl(<SourceForm {...props} />);
107
- const name = "external_id";
108
- const value = "micro2";
109
- const e = { preventDefault: jest.fn() };
104
+ it("submits", async () => {
105
+ const rendered = render(
106
+ <SourceForm {...props} source={undefined} />,
107
+ renderOpts
108
+ );
109
+ await waitForLoad(rendered);
110
+
111
+ const user = userEvent.setup({ delay: null });
110
112
 
111
- wrapper.find({ name }).simulate("change", e, { name, value });
112
- expect(e.preventDefault.mock.calls.length).toBe(1);
113
- expect(wrapper.state(name)).toBe(value);
113
+ const externalIdField =
114
+ rendered.queryByText(/source.external_id/i).parentNode;
115
+ await user.type(
116
+ within(externalIdField).getByRole("textbox"),
117
+ "My External Id"
118
+ );
119
+
120
+ const sourceTypeField =
121
+ rendered.queryByText(/type.selector.label/i).parentNode;
122
+ await user.click(
123
+ within(sourceTypeField).getByRole("option", { name: /app-admin/i })
124
+ );
125
+
126
+ await waitForLoad(rendered);
127
+
128
+ await user.click(rendered.getByRole("button", { name: /create/i }));
129
+
130
+ expect(props.onSubmit).toHaveBeenCalledWith({
131
+ source: {
132
+ config: {},
133
+ external_id: "My External Id",
134
+ type: "micro",
135
+ },
136
+ });
114
137
  });
115
138
  });
116
139
  });
@@ -1,8 +1,7 @@
1
- import React from "react";
2
1
  import { render } from "@truedat/test/render";
3
2
  import SourceHeader from "../SourceHeader";
4
3
 
5
- const source = { externalId: "foo", id: 123 };
4
+ const source = { externalId: "foo", id: "123" };
6
5
 
7
6
  describe("<SourceHeader />", () => {
8
7
  it("matches the latest snapshot", () => {
@@ -1,14 +1,86 @@
1
- import React from "react";
2
- import { shallow } from "enzyme";
1
+ import { render, waitForLoad } from "@truedat/test/render";
2
+ import { SOURCES, SOURCES_NEW, linkTo } from "@truedat/core/routes";
3
+ import { useAuthorized } from "@truedat/core/hooks/useAuthorized";
3
4
  import { SourceRoutes } from "../SourceRoutes";
5
+ import { SOURCE_QUERY } from "../../api/queries";
4
6
 
5
- jest.mock("@truedat/core/hooks", () => ({
6
- useAuthorized: jest.fn(() => true)
7
+ // Mock child components
8
+ jest.mock("../NewSource", () => () => <div>NewSource</div>);
9
+ jest.mock("../Sources", () => () => <div>Sources</div>);
10
+ jest.mock("../Source", () => () => <div>Source</div>);
11
+
12
+ // Mock hooks
13
+ jest.mock("@truedat/core/hooks/useAuthorized", () => ({
14
+ useAuthorized: jest.fn(() => true),
7
15
  }));
8
16
 
17
+ const sourceMock = {
18
+ request: {
19
+ query: SOURCE_QUERY,
20
+ variables: { sourceId: "123" },
21
+ },
22
+ result: {
23
+ data: {
24
+ loading: false,
25
+ source: {
26
+ __typename: "Source",
27
+ id: "123",
28
+ externalId: "ext-123",
29
+ active: true,
30
+ type: "test",
31
+ config: {},
32
+ jobTypes: [],
33
+ template: {
34
+ id: "template-1",
35
+ content: "test content",
36
+ },
37
+ },
38
+ },
39
+ },
40
+ };
41
+
42
+ const renderOpts = {
43
+ mocks: [sourceMock],
44
+ };
45
+
9
46
  describe("<SourceRoutes />", () => {
10
- it("matches the latest snapshot", () => {
11
- const wrapper = shallow(<SourceRoutes />);
12
- expect(wrapper).toMatchSnapshot();
47
+ it("matches the latest snapshot for route SOURCES when authorized", async () => {
48
+ useAuthorized.mockReturnValueOnce(true);
49
+ const rendered = render(<SourceRoutes />, {
50
+ ...renderOpts,
51
+ routes: [SOURCES],
52
+ });
53
+ await waitForLoad(rendered);
54
+ expect(rendered.container).toMatchSnapshot();
55
+ });
56
+
57
+ it("matches the latest snapshot for route SOURCES_NEW when authorized", async () => {
58
+ useAuthorized.mockReturnValueOnce(true);
59
+ const rendered = render(<SourceRoutes />, {
60
+ ...renderOpts,
61
+ routes: [SOURCES_NEW],
62
+ });
63
+ await waitForLoad(rendered);
64
+ expect(rendered.container).toMatchSnapshot();
65
+ });
66
+
67
+ it("matches the latest snapshot for route SOURCE when authorized", async () => {
68
+ useAuthorized.mockReturnValueOnce(true);
69
+ const rendered = render(<SourceRoutes />, {
70
+ ...renderOpts,
71
+ routes: [linkTo.SOURCE({ sourceId: "123" })],
72
+ });
73
+ await waitForLoad(rendered);
74
+ expect(rendered.container).toMatchSnapshot();
75
+ });
76
+
77
+ it("shows unauthorized message when not authorized", async () => {
78
+ useAuthorized.mockReturnValueOnce(false);
79
+ const rendered = render(<SourceRoutes />, {
80
+ ...renderOpts,
81
+ routes: [SOURCES],
82
+ });
83
+ await waitForLoad(rendered);
84
+ expect(rendered.container).toMatchSnapshot();
13
85
  });
14
86
  });
@@ -1,4 +1,3 @@
1
- import React from "react";
2
1
  import { waitFor } from "@testing-library/react";
3
2
  import { render } from "@truedat/test/render";
4
3
  import { SOURCE_OPTIONS_QUERY } from "../../api/queries";
@@ -1,10 +1,9 @@
1
- import React from "react";
2
1
  import { render } from "@truedat/test/render";
3
2
  import SourceTabs from "../SourceTabs";
4
3
 
5
- jest.mock("react-router-dom", () => ({
6
- ...jest.requireActual("react-router-dom"),
7
- useRouteMatch: () => ({ path: "/sources/123" }),
4
+ jest.mock("react-router", () => ({
5
+ ...jest.requireActual("react-router"),
6
+ useMatch: () => ({ path: "/sources/123" }),
8
7
  }));
9
8
 
10
9
  const source = { externalId: "foo", id: 123 };
@@ -1,30 +1,10 @@
1
- import React from "react";
1
+ import { waitFor } from "@testing-library/react";
2
2
  import userEvent from "@testing-library/user-event";
3
- import { render } from "@truedat/test/render";
3
+ import { render, waitForLoad } from "@truedat/test/render";
4
4
  import { SOURCES_QUERY } from "../../api/queries";
5
5
  import { Sources } from "../Sources";
6
6
 
7
- const messages = {
8
- en: {
9
- "sources.actions.create": "create",
10
- "sources.header": "header",
11
- "sources.search.placeholder": "search",
12
- "sources.count": "{count} sources found",
13
- "sources.subheader": "subheader",
14
- "source.latestEvent.insertedAt": "insertedAt",
15
- "source.latestEvent.message": "message",
16
- "source.latestEvent.type": "type",
17
- "source.status": "status",
18
- "source.type": "type",
19
- "source.external_id": "external_id",
20
- },
21
- };
22
-
23
7
  describe("<Sources />", () => {
24
- const props = {
25
- loading: false,
26
- sources: [],
27
- };
28
8
  const event = {
29
9
  id: 456,
30
10
  type: "eventType",
@@ -52,31 +32,36 @@ describe("<Sources />", () => {
52
32
  request: { query: SOURCES_QUERY },
53
33
  result: { data: { sources } },
54
34
  };
55
- const renderOpts = { mocks: [sourcesMock], messages };
35
+ const renderOpts = { mocks: [sourcesMock] };
56
36
 
57
37
  it("matches the latest snapshot", async () => {
58
- const { container, findByText } = render(
59
- <Sources {...props} />,
60
- renderOpts
38
+ const rendered = render(<Sources />, renderOpts);
39
+ await waitForLoad(rendered);
40
+ await waitFor(() =>
41
+ expect(rendered.getByText(/sources.count/i)).toBeInTheDocument()
61
42
  );
62
- await findByText("2 sources found");
63
- expect(container).toMatchSnapshot();
43
+ expect(rendered.container).toMatchSnapshot();
64
44
  });
65
45
 
66
46
  it("renders count and filters rows matching search term", async () => {
67
- const { findByText, getByRole, queryAllByRole } = render(
68
- <Sources {...props} />,
69
- renderOpts
47
+ const rendered = render(<Sources />, renderOpts);
48
+ await waitForLoad(rendered);
49
+ await waitFor(() =>
50
+ expect(rendered.getByText(/sources.count/i)).toBeInTheDocument()
70
51
  );
71
- await findByText("2 sources found");
72
- expect(queryAllByRole("row")).toHaveLength(3); // 2 rows + header
52
+ expect(rendered.queryAllByRole("row")).toHaveLength(3); // 2 rows + header
73
53
 
74
- userEvent.type(getByRole("textbox"), source1.externalId);
75
- await findByText("1 sources found");
76
- expect(queryAllByRole("row")).toHaveLength(2); // 1 row + header
54
+ const user = userEvent.setup({ delay: null });
55
+ await user.type(rendered.getByRole("textbox"), source1.externalId);
56
+ await waitFor(() =>
57
+ expect(rendered.getByText(/sources.count/i)).toBeInTheDocument()
58
+ );
59
+ expect(rendered.queryAllByRole("row")).toHaveLength(2); // 1 row + header
77
60
 
78
- userEvent.type(getByRole("textbox"), "x");
79
- await findByText("0 sources found");
80
- expect(queryAllByRole("row")).toHaveLength(1); // header only
61
+ await user.type(rendered.getByRole("textbox"), "x");
62
+ await waitFor(() =>
63
+ expect(rendered.getByText(/sources.count/i)).toBeInTheDocument()
64
+ );
65
+ expect(rendered.queryAllByRole("row")).toHaveLength(1); // header only
81
66
  });
82
67
  });