@truedat/dd 6.8.1 → 6.8.3

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 (27) hide show
  1. package/package.json +6 -6
  2. package/src/components/DictionaryRoutes.js +5 -1
  3. package/src/components/GrantRequest.js +6 -3
  4. package/src/components/PendingStructureNoteRow.js +18 -26
  5. package/src/components/PendingStructureNotes.js +58 -111
  6. package/src/components/PendingStructureNotesLabelResults.js +17 -0
  7. package/src/components/PendingStructureNotesPagination.js +16 -0
  8. package/src/components/PendingStructureNotesTable.js +44 -35
  9. package/src/components/StructureNotes.js +1 -1
  10. package/src/components/SystemCards.js +20 -18
  11. package/src/components/SystemView.js +7 -4
  12. package/src/components/__tests__/GrantRequest.spec.js +2 -2
  13. package/src/components/__tests__/PendingStructureNoteRow.spec.js +95 -18
  14. package/src/components/__tests__/PendingStructureNotes.spec.js +57 -44
  15. package/src/components/__tests__/PendingStructureNotesLabelResults.spec.js +44 -0
  16. package/src/components/__tests__/PendingStructureNotesPagination.spec.js +43 -0
  17. package/src/components/__tests__/PendingStructureNotesTable.spec.js +52 -38
  18. package/src/components/__tests__/SystemCards.spec.js +6 -6
  19. package/src/components/__tests__/__snapshots__/PendingStructureNoteRow.spec.js.snap +8 -3
  20. package/src/components/__tests__/__snapshots__/PendingStructureNotes.spec.js.snap +159 -77
  21. package/src/components/__tests__/__snapshots__/PendingStructureNotesLabelResults.spec.js.snap +11 -0
  22. package/src/components/__tests__/__snapshots__/PendingStructureNotesPagination.spec.js.snap +96 -0
  23. package/src/components/__tests__/__snapshots__/PendingStructureNotesTable.spec.js.snap +36 -18
  24. package/src/selectors/__tests__/getSortedStructureNotes.spec.js +4 -4
  25. package/src/selectors/getSortedStructureNotes.js +5 -1
  26. package/src/selectors/index.js +4 -0
  27. package/src/selectors/structureNotesColumnsSelector.js +65 -0
@@ -1,36 +1,113 @@
1
1
  import React from "react";
2
- import { waitFor } from "@testing-library/react";
3
2
  import { render } from "@truedat/test/render";
3
+ import userEvent from "@testing-library/user-event";
4
+ import { getStructureNotesColumnsSelector } from "../../selectors";
4
5
  import PendingStructureNoteRow from "../PendingStructureNoteRow";
5
6
 
6
- const props = {
7
- structureNote: {
8
- id: "7207",
9
- status: "draft",
10
- dataStructure: {
11
- currentVersion: {
12
- name: "bar",
13
- path: ["bar rute"],
14
- },
15
- domains: [{ name: "bar domain" }],
16
- system: { name: "bar system" },
17
- },
7
+ const mockHistory = {
8
+ push: jest.fn(),
9
+ };
10
+
11
+ jest.mock("react-router-dom", () => ({
12
+ ...jest.requireActual("react-router-dom"),
13
+ useHistory: () => mockHistory,
14
+ }));
15
+
16
+ const columns = getStructureNotesColumnsSelector({});
17
+
18
+ const structure = {
19
+ id: "7207",
20
+ note: { status: "draft" },
21
+ name: "bar",
22
+ path: ["bar rute"],
23
+ domains: [{ name: "bar domain" }, { name: "baz domain" }],
24
+ system: { name: "bar system" },
25
+ non_published_note: { id: 1, status: "draft" },
26
+ };
27
+
28
+ const messages = {
29
+ en: {
30
+ "pendingStructureNotes.props.domain": "Domain",
31
+ "pendingStructureNotes.props.status": "Status",
32
+ "pendingStructureNotes.props.name": "Name",
33
+ "search.placeholder": "Search...",
34
+ "pendingStructureNotes.props.path": "Path",
35
+ "pendingStructureNotes.props.system": "System",
36
+ "pendingStructureNotes.search.results.empty": "Empty",
37
+ "structures.retrieved.results": "{count} structures found",
38
+ "pendingStructureNotes.subheader": "Subheader",
39
+ "pendingStructureNotes.header": "Header",
40
+ "pendingStructureNotes.status.rejected": "Rejected",
41
+ "pendingStructureNotes.status.draft": "Draft",
18
42
  },
19
43
  };
20
44
 
45
+ const renderOpts = { messages };
46
+
47
+ const props = {
48
+ structure,
49
+ columns,
50
+ };
51
+
21
52
  describe("<PendingStructureNoteRow />", () => {
22
53
  it("matches the latest snapshot", async () => {
23
- const { container, queryByText } = render(
54
+ const { container } = render(
24
55
  <table>
25
56
  <tbody>
26
57
  <PendingStructureNoteRow {...props} />
27
58
  </tbody>
28
- </table>
59
+ </table>,
60
+ renderOpts
29
61
  );
62
+
30
63
  expect(container).toMatchSnapshot();
64
+ });
65
+
66
+ it("navigates to the job route when row is clicked", () => {
67
+ const props = { columns, structure };
68
+ const { getByText } = render(
69
+ <table>
70
+ <tbody>
71
+ <PendingStructureNoteRow {...props} />
72
+ </tbody>
73
+ </table>,
74
+ renderOpts
75
+ );
76
+ userEvent.click(getByText(/bar system/));
77
+ expect(mockHistory.push.mock.calls.length).toBe(1);
78
+ expect(mockHistory.push.mock.calls[0][0]).toBe("/structures/7207");
79
+ });
80
+
81
+ it("renders empty table if structure is empty", () => {
82
+ const emptyStructure = {};
83
+ const { queryByText } = render(
84
+ <table>
85
+ <tbody>
86
+ <PendingStructureNoteRow
87
+ structure={emptyStructure}
88
+ columns={columns}
89
+ />
90
+ </tbody>
91
+ </table>,
92
+ renderOpts
93
+ );
94
+ expect(queryByText("bar system")).not.toBeInTheDocument();
95
+ });
96
+
97
+ it("renders empty table columns are empty", () => {
98
+ const emptyColumns = [];
99
+ const { queryByText } = render(
100
+ <table>
101
+ <tbody>
102
+ <PendingStructureNoteRow
103
+ structure={structure}
104
+ columns={emptyColumns}
105
+ />
106
+ </tbody>
107
+ </table>,
108
+ renderOpts
109
+ );
31
110
 
32
- await waitFor(() => {
33
- expect(queryByText(/bar system/)).toBeTruthy();
34
- });
111
+ expect(queryByText("bar system")).not.toBeInTheDocument();
35
112
  });
36
113
  });
@@ -1,58 +1,75 @@
1
- import React, { Suspense } from "react";
1
+ import React from "react";
2
2
  import { waitFor } from "@testing-library/react";
3
3
  import { render } from "@truedat/test/render";
4
- import { domainsMock } from "@truedat/test/mocks";
5
- import { STRUCTURE_NOTES_QUERY } from "../../api/queries";
6
4
  import PendingStructureNotes from "../PendingStructureNotes";
7
5
 
8
- const domains = [
9
- { id: "1", name: "Domain 1", level: 0 },
10
- { id: "2", name: "Domain 2", level: 0 },
11
- ];
12
- const systems = [
13
- { external_id: "some_external_id", id: 10, name: "some system" },
14
- ];
15
-
16
- const structureNotes = {
17
- loading: false,
18
- structureNotes: [
6
+ const data = {
7
+ data: [
19
8
  {
20
9
  id: "7207",
21
- status: "draft",
22
- dataStructure: {
23
- currentVersion: {
24
- name: "bar",
25
- path: ["bar rute"],
26
- },
27
- domains: [{ name: "bar domain" }],
28
- system: { name: "bar system" },
29
- },
10
+ note: { status: "draft" },
11
+ name: "bar",
12
+ path: ["bar rute"],
13
+ domains: [{ name: "bar domain" }],
14
+ system: { name: "bar system" },
15
+ non_published_note: { id: 1, status: "draft" },
30
16
  },
31
17
  {
32
18
  id: "665214",
33
- status: "rejected",
34
- dataStructure: {
35
- currentVersion: {
36
- name: "foo",
37
- path: ["foo rute", "other route"],
38
- },
39
- domains: [{ name: "foo domain 1" }, { name: "foo domain 2" }],
40
- system: { name: "foo system" },
41
- },
19
+ note: { status: "rejected" },
20
+ name: "foo",
21
+ path: ["foo rute", "other route"],
22
+ domains: [{ name: "foo domain 1" }, { name: "foo domain 2" }],
23
+ system: { name: "foo system" },
24
+ non_published_note: { id: 2, status: "rejected" },
42
25
  },
43
26
  ],
44
27
  };
45
28
 
46
- const structureNotesMock = {
47
- request: { query: STRUCTURE_NOTES_QUERY },
48
- result: { data: { structureNotes } },
49
- };
29
+ jest.mock("@truedat/dd/hooks/useStructures", () => {
30
+ const originalModule = jest.requireActual("@truedat/dd/hooks/useStructures");
31
+ return {
32
+ __esModule: true,
33
+ ...originalModule,
34
+ useDataStructureFilters: () => ({
35
+ trigger: () => ({
36
+ then: (callback) =>
37
+ callback({
38
+ data: {},
39
+ }),
40
+ }),
41
+ }),
42
+ useDataStructureSearch: () => ({
43
+ trigger: () => ({
44
+ then: (callback) =>
45
+ callback({
46
+ data,
47
+ headers: {},
48
+ }),
49
+ }),
50
+ }),
51
+ };
52
+ });
50
53
 
51
- const renderOpts = {
52
- mocks: [structureNotesMock, domainsMock({ action: "publishStructureNote" })],
53
- state: { domains, systems },
54
+ const messages = {
55
+ en: {
56
+ "pendingStructureNotes.props.domain": "Domain",
57
+ "pendingStructureNotes.props.status": "Status",
58
+ "pendingStructureNotes.props.name": "Name",
59
+ "search.placeholder": "Search...",
60
+ "pendingStructureNotes.props.path": "Path",
61
+ "pendingStructureNotes.props.system": "System",
62
+ "pendingStructureNotes.search.results.empty": "Empty",
63
+ "structures.retrieved.results": "{count} structures found",
64
+ "pendingStructureNotes.subheader": "Subheader",
65
+ "pendingStructureNotes.header": "Header",
66
+ "pendingStructureNotes.status.rejected": "Rejected",
67
+ "pendingStructureNotes.status.draft": "Draft",
68
+ },
54
69
  };
55
70
 
71
+ const renderOpts = { messages };
72
+
56
73
  describe("<PendingStructureNotes />", () => {
57
74
  it("matches the latest snapshot", async () => {
58
75
  const { container, queryByText } = render(
@@ -62,11 +79,7 @@ describe("<PendingStructureNotes />", () => {
62
79
  expect(container).toMatchSnapshot();
63
80
 
64
81
  await waitFor(() => {
65
- expect(queryByText(/some system/)).toBeTruthy();
66
- });
67
-
68
- await waitFor(() => {
69
- expect(queryByText(/fooDomain/)).toBeTruthy();
82
+ expect(queryByText(/foo system/)).toBeTruthy();
70
83
  });
71
84
  });
72
85
  });
@@ -0,0 +1,44 @@
1
+ import React from "react";
2
+ import { render } from "@truedat/test/render";
3
+ import { SearchContextProvider } from "@truedat/core/search/SearchContext";
4
+ import PendingStructureNotesLabelResults from "../PendingStructureNotesLabelResults";
5
+
6
+ const useFilters = () => ({
7
+ trigger: () => ({
8
+ then: (callback) =>
9
+ callback({
10
+ data: { data: {} },
11
+ }),
12
+ }),
13
+ });
14
+
15
+ const useSearch = () => ({
16
+ trigger: () => ({
17
+ then: (callback) =>
18
+ callback({
19
+ data: { data: [] },
20
+ headers: { "x-total-count": 22 },
21
+ }),
22
+ }),
23
+ });
24
+
25
+ const searchProps = {
26
+ initialSortColumn: "name.raw",
27
+ initialSortDirection: "ascending",
28
+ useSearch: useSearch,
29
+ userFiltersType: "structures",
30
+ omitFilters: [],
31
+ useFilters: useFilters,
32
+ translations: jest.fn(),
33
+ };
34
+
35
+ describe("<PendingStructureNotesLabelResults />", () => {
36
+ it("matches the latest snapshot", () => {
37
+ const { container } = render(
38
+ <SearchContextProvider {...searchProps}>
39
+ <PendingStructureNotesLabelResults />
40
+ </SearchContextProvider>
41
+ );
42
+ expect(container).toMatchSnapshot();
43
+ });
44
+ });
@@ -0,0 +1,43 @@
1
+ import React from "react";
2
+ import { render } from "@truedat/test/render";
3
+ import { SearchContextProvider } from "@truedat/core/search/SearchContext";
4
+ import PendingStructureNotesPagination from "../PendingStructureNotesPagination";
5
+
6
+ const useFilters = () => ({
7
+ trigger: () => ({
8
+ then: (callback) =>
9
+ callback({
10
+ data: { data: {} },
11
+ }),
12
+ }),
13
+ });
14
+
15
+ const useSearch = () => ({
16
+ trigger: () => ({
17
+ then: (callback) =>
18
+ callback({
19
+ data: { data: [] },
20
+ headers: { "x-total-count": 22 },
21
+ }),
22
+ }),
23
+ });
24
+
25
+ const searchProps = {
26
+ useSearch: useSearch,
27
+ useFilters: useFilters,
28
+ count: 20,
29
+ size: 20,
30
+ page: 1,
31
+ selectPage: jest.fn(),
32
+ };
33
+
34
+ describe("<PendingStructureNotesPagination />", () => {
35
+ it("matches the latest snapshot", () => {
36
+ const { container } = render(
37
+ <SearchContextProvider {...searchProps}>
38
+ <PendingStructureNotesPagination />
39
+ </SearchContextProvider>
40
+ );
41
+ expect(container).toMatchSnapshot();
42
+ });
43
+ });
@@ -1,8 +1,39 @@
1
1
  import React from "react";
2
2
  import { waitFor } from "@testing-library/react";
3
3
  import { render } from "@truedat/test/render";
4
+ import SearchContext from "@truedat/core/search/SearchContext";
4
5
  import PendingStructureNotesTable from "../PendingStructureNotesTable";
5
6
 
7
+ const structures = {
8
+ data: [
9
+ {
10
+ id: "7207",
11
+ note: { status: "draft" },
12
+ name: "bar",
13
+ path: ["bar rute"],
14
+ domains: [{ name: "bar domain" }],
15
+ system: { name: "bar system" },
16
+ non_published_note: { id: 1, status: "draft" },
17
+ },
18
+ {
19
+ id: "665214",
20
+ note: { status: "rejected" },
21
+ name: "foo",
22
+ path: ["foo rute", "other route"],
23
+ domains: [{ name: "foo domain 1" }, { name: "foo domain 2" }],
24
+ system: { name: "foo system" },
25
+ non_published_note: { id: 2, status: "rejected" },
26
+ },
27
+ ],
28
+ };
29
+
30
+ const searchProps = {
31
+ searchData: structures,
32
+ sortColumn: "name.raw",
33
+ sortDirection: "descending",
34
+ handleSortSelection: jest.fn(),
35
+ };
36
+
6
37
  const renderOpts = {
7
38
  messages: {
8
39
  en: {
@@ -10,69 +41,52 @@ const renderOpts = {
10
41
  "pendingStructureNotes.props.structure": "Structure",
11
42
  "pendingStructureNotes.props.status": "Status",
12
43
  "pendingStructureNotes.props.system": "System",
13
- "pendingStructureNotes.props.domains": "Domains",
44
+ "pendingStructureNotes.props.domain": "Domain",
14
45
  "structure.notes.status.draft": "Draft",
15
46
  "structure.notes.status.rejected": "Rejected",
16
47
  "pendingStructureNotes.props.path": "Path",
48
+ "pendingStructureNotes.props.name": "Name",
49
+ "pendingStructureNotes.status.rejected": "Rejected",
50
+ "pendingStructureNotes.status.draft": "Draft",
17
51
  },
18
52
  },
19
53
  };
20
54
 
21
- const props = {
22
- loading: false,
23
- structureNotes: [
24
- {
25
- id: "7207",
26
- status: "draft",
27
- data_structure: {
28
- current_version: {
29
- name: "bar",
30
- path: ["bar rute"],
31
- },
32
- domains: [{ name: "bar domain" }],
33
- system: { name: "bar system" },
34
- },
35
- },
36
- {
37
- id: "665214",
38
- status: "rejected",
39
- data_structure: {
40
- current_version: {
41
- name: "foo",
42
- path: ["foo rute", "other route"],
43
- },
44
- domains: [{ name: "foo domain 1" }, { name: "foo domain 2" }],
45
- system: { name: "foo system" },
46
- },
47
- },
48
- ],
49
- };
50
-
51
55
  describe("<PendingStructureNotesTable />", () => {
56
+ const columns = [
57
+ { name: "foo", sort: { name: "name.raw" } },
58
+ { name: "bar", sort: { name: "bar.raw" } },
59
+ ];
60
+ const props = { columns };
61
+
52
62
  it("matches the latest snapshot", async () => {
53
63
  const { container, queryByText } = render(
54
- <PendingStructureNotesTable {...props} />,
64
+ <SearchContext.Provider value={searchProps}>
65
+ <PendingStructureNotesTable {...props} />
66
+ </SearchContext.Provider>,
55
67
  renderOpts
56
68
  );
57
69
  expect(container).toMatchSnapshot();
58
70
 
59
71
  await waitFor(() => {
60
- expect(queryByText(/Draft/)).toBeTruthy();
72
+ expect(queryByText(/bar system/)).toBeTruthy();
61
73
  });
62
74
 
63
75
  await waitFor(() => {
64
- expect(queryByText(/Rejected/)).toBeTruthy();
76
+ expect(queryByText(/foo system/)).toBeTruthy();
65
77
  });
66
78
  });
67
79
 
68
80
  it("matches when StructureNotes are empty and not loading", async () => {
69
- const props = {
70
- loading: false,
71
- structureNotes: [],
81
+ const newSearchProps = {
82
+ ...searchProps,
83
+ searchData: [],
72
84
  };
73
85
 
74
86
  const { container, queryByText } = render(
75
- <PendingStructureNotesTable {...props} />,
87
+ <SearchContext.Provider value={newSearchProps}>
88
+ <PendingStructureNotesTable {...props} />
89
+ </SearchContext.Provider>,
76
90
  renderOpts
77
91
  );
78
92
  expect(container).toMatchSnapshot();
@@ -42,7 +42,7 @@ describe("<SystemCards />", () => {
42
42
  const systems = [
43
43
  {
44
44
  ...system_with_structures,
45
- df_content: {
45
+ dynamic_content: {
46
46
  system_group: { value: "foo-group", origin: "user" },
47
47
  },
48
48
  },
@@ -77,7 +77,7 @@ describe("<SystemCards />", () => {
77
77
  const systems = [
78
78
  {
79
79
  ...system_with_structures,
80
- df_content: {
80
+ dynamic_content: {
81
81
  logo: { value: imageSrc, origin: "user" },
82
82
  },
83
83
  },
@@ -107,13 +107,13 @@ describe("<SystemCards />", () => {
107
107
  const systems = [
108
108
  {
109
109
  ...system_with_structures,
110
- df_content: {
110
+ dynamic_content: {
111
111
  system_group: { value: "foo-group", origin: "user" },
112
112
  },
113
113
  },
114
114
  {
115
115
  ...system_without_structures,
116
- df_content: {
116
+ dynamic_content: {
117
117
  system_group: { value: "foo-group", origin: "user" },
118
118
  },
119
119
  },
@@ -133,13 +133,13 @@ describe("<SystemCards />", () => {
133
133
  const systems = [
134
134
  {
135
135
  ...system_with_structures,
136
- df_content: {
136
+ dynamic_content: {
137
137
  system_group: { value: "foo-group", origin: "user" },
138
138
  },
139
139
  },
140
140
  {
141
141
  ...system_without_structures,
142
- df_content: {
142
+ dynamic_content: {
143
143
  system_group: { value: "", origin: "user" },
144
144
  },
145
145
  },
@@ -8,7 +8,8 @@ exports[`<PendingStructureNoteRow /> matches the latest snapshot 1`] = `
8
8
  class=""
9
9
  >
10
10
  <td
11
- class=""
11
+ class="structure-cell-overflow"
12
+ title="bar"
12
13
  >
13
14
  bar
14
15
  </td>
@@ -25,12 +26,16 @@ exports[`<PendingStructureNoteRow /> matches the latest snapshot 1`] = `
25
26
  <td
26
27
  class=""
27
28
  >
28
- bar domain
29
+ bar domain, baz domain
29
30
  </td>
30
31
  <td
31
32
  class=""
32
33
  >
33
- bar rute
34
+ <span
35
+ title="bar rute"
36
+ >
37
+ bar rute
38
+ </span>
34
39
  </td>
35
40
  </tr>
36
41
  </tbody>