@truedat/dd 6.6.0 → 6.6.1

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 (99) hide show
  1. package/package.json +6 -6
  2. package/src/components/CatalogCustomViewCards.js +9 -32
  3. package/src/components/DictionaryRoutes.js +1 -9
  4. package/src/components/GrantRemovalDirectButton.js +1 -3
  5. package/src/components/GrantRequestCancel.js +1 -1
  6. package/src/components/GrantRoutes.js +1 -14
  7. package/src/components/StructureGrantListButton.js +4 -4
  8. package/src/components/StructureSelector.js +70 -44
  9. package/src/components/StructureStructureForm.js +1 -1
  10. package/src/components/StructuresBulkUpdate.js +10 -14
  11. package/src/components/StructuresDownloadOption.js +31 -27
  12. package/src/components/StructuresEditableDownloadOption.js +12 -7
  13. package/src/components/StructuresGrantRequestView.js +55 -24
  14. package/src/components/StructuresLabelResults.js +5 -11
  15. package/src/components/StructuresPagination.js +13 -15
  16. package/src/components/StructuresRoutes.js +2 -18
  17. package/src/components/StructuresTable.js +79 -115
  18. package/src/components/StructuresUpdateOption.js +77 -9
  19. package/src/components/StructuresView.js +67 -52
  20. package/src/components/__tests__/CatalogCustomViewCards.spec.js +44 -7
  21. package/src/components/__tests__/StructureGrantListButton.spec.js +27 -17
  22. package/src/components/__tests__/StructureSelector.spec.js +70 -25
  23. package/src/components/__tests__/StructureStructureForm.spec.js +92 -60
  24. package/src/components/__tests__/StructureStructureLinks.spec.js +1 -1
  25. package/src/components/__tests__/StructuresBulkUpdate.spec.js +26 -14
  26. package/src/components/__tests__/StructuresDownloadOption.spec.js +38 -5
  27. package/src/components/__tests__/StructuresEditableDownloadOption.spec.js +20 -8
  28. package/src/components/__tests__/StructuresGrantRequestView.spec.js +43 -15
  29. package/src/components/__tests__/StructuresLabelResults.spec.js +37 -10
  30. package/src/components/__tests__/StructuresOptions.spec.js +62 -1
  31. package/src/components/__tests__/StructuresSearchResults.spec.js +67 -12
  32. package/src/components/__tests__/StructuresTable.spec.js +77 -88
  33. package/src/components/__tests__/StructuresUpdateOption.spec.js +53 -6
  34. package/src/components/__tests__/StructuresView.spec.js +126 -31
  35. package/src/components/__tests__/__snapshots__/StructureSelector.spec.js.snap +206 -42
  36. package/src/components/__tests__/__snapshots__/StructuresDownloadOption.spec.js.snap +17 -0
  37. package/src/components/__tests__/__snapshots__/StructuresGrantRequestView.spec.js.snap +68 -5
  38. package/src/components/__tests__/__snapshots__/StructuresLabelResults.spec.js.snap +7 -12
  39. package/src/components/__tests__/__snapshots__/StructuresSearchResults.spec.js.snap +72 -27
  40. package/src/components/__tests__/__snapshots__/StructuresTable.spec.js.snap +226 -153
  41. package/src/components/__tests__/__snapshots__/StructuresUpdateOption.spec.js.snap +3 -3
  42. package/src/components/index.js +0 -8
  43. package/src/hooks/useStructures.js +6 -6
  44. package/src/reducers/__tests__/selectedUserSearchFilter.spec.js +2 -23
  45. package/src/reducers/__tests__/structureQuery.spec.js +1 -63
  46. package/src/reducers/index.js +0 -18
  47. package/src/reducers/previousStructureQuery.js +3 -6
  48. package/src/reducers/selectedUserSearchFilter.js +1 -10
  49. package/src/reducers/structureQuery.js +1 -33
  50. package/src/routines.js +1 -15
  51. package/src/sagas/__tests__/bulkUpdateStructures.spec.js +7 -7
  52. package/src/sagas/__tests__/downloadEditableStructures.spec.js +1 -6
  53. package/src/sagas/__tests__/downloadStructures.spec.js +2 -7
  54. package/src/sagas/__tests__/fetchStructures.spec.js +4 -4
  55. package/src/sagas/bulkUpdateStructures.js +6 -4
  56. package/src/sagas/downloadEditableStructures.js +2 -3
  57. package/src/sagas/downloadStructures.js +2 -3
  58. package/src/sagas/index.js +0 -3
  59. package/src/selectors/__tests__/getGrantSelectedFilters.spec.js +1 -1
  60. package/src/selectors/__tests__/structureColumnsSelector.spec.js +5 -19
  61. package/src/selectors/__tests__/templateNamesSelector.spec.js +19 -0
  62. package/src/selectors/index.js +1 -8
  63. package/src/selectors/structureColumnsSelector.js +6 -46
  64. package/src/selectors/templateNamesSelector.js +7 -0
  65. package/src/utils/structureCustomTranslations.js +19 -0
  66. package/src/components/StructureDateFilter.js +0 -32
  67. package/src/components/StructureFilters.js +0 -19
  68. package/src/components/StructureFiltersLoader.js +0 -32
  69. package/src/components/StructureSelectedFilters.js +0 -94
  70. package/src/components/__tests__/StructureDateFilter.spec.js +0 -11
  71. package/src/components/__tests__/__snapshots__/StructureDateFilter.spec.js.snap +0 -13
  72. package/src/reducers/__tests__/structureActiveFilters.spec.js +0 -100
  73. package/src/reducers/__tests__/structureDateFilter.spec.js +0 -57
  74. package/src/reducers/__tests__/structureFilters.spec.js +0 -37
  75. package/src/reducers/__tests__/structureUserFilters.spec.js +0 -76
  76. package/src/reducers/__tests__/structuresActions.spec.js +0 -38
  77. package/src/reducers/__tests__/structuresLoading.spec.js +0 -26
  78. package/src/reducers/structureActiveFilters.js +0 -58
  79. package/src/reducers/structureCount.js +0 -20
  80. package/src/reducers/structureDateFilter.js +0 -33
  81. package/src/reducers/structureFilters.js +0 -21
  82. package/src/reducers/structureFiltersLoading.js +0 -14
  83. package/src/reducers/structureSelectedFilter.js +0 -34
  84. package/src/reducers/structuresActions.js +0 -18
  85. package/src/reducers/structuresLoading.js +0 -14
  86. package/src/reducers/structuresPageSize.js +0 -15
  87. package/src/sagas/fetchStructureFilters.js +0 -29
  88. package/src/selectors/__tests__/bulkUpdateDisabledSelector.spec.js +0 -72
  89. package/src/selectors/__tests__/getStructureAvailableFilters.spec.js +0 -15
  90. package/src/selectors/__tests__/getStructureSelectedFilterActiveValues.spec.js +0 -20
  91. package/src/selectors/__tests__/getStructureSelectedFilterValues.spec.js +0 -15
  92. package/src/selectors/__tests__/getStructureSelectedFilters.spec.js +0 -15
  93. package/src/selectors/bulkUpdateDisabledSelector.js +0 -46
  94. package/src/selectors/getPreviousStructureQuery.js +0 -2
  95. package/src/selectors/getStructureAvailableFilters.js +0 -15
  96. package/src/selectors/getStructureFilterTypes.js +0 -7
  97. package/src/selectors/getStructureSelectedFilterActiveValues.js +0 -9
  98. package/src/selectors/getStructureSelectedFilterValues.js +0 -12
  99. package/src/selectors/getStructureSelectedFilters.js +0 -7
@@ -11,12 +11,16 @@ describe("<StructuresBulkUpdate />", () => {
11
11
  const renderOpts = {
12
12
  mocks: [templateByNameMock({ name: "template1", domainIds: [1] })],
13
13
  state: {
14
- structureCount: 10,
15
- structureTypes: [{ name: "structType", template: { name: "template1" } }],
16
- structureFilters: {
17
- "type.raw": { values: ["structType"] },
18
- taxonomy: { values: [{ id: 1 }], type: "domain" },
14
+ previousStructureQuery: {
15
+ structureCount: 10,
16
+ allFilters: {
17
+ "type.raw": { values: ["structType"] },
18
+ taxonomy: { values: [{ id: 1 }], type: "domain" },
19
+ },
20
+ actions: {},
21
+ searchParams: {},
19
22
  },
23
+ structureTypes: [{ name: "structType", template: { name: "template1" } }],
20
24
  },
21
25
  fallback: "lazy",
22
26
  };
@@ -31,25 +35,31 @@ describe("<StructuresBulkUpdate />", () => {
31
35
  await waitFor(() =>
32
36
  expect(queryByText(/loading/i)).not.toBeInTheDocument()
33
37
  );
34
-
35
38
  expect(container).toMatchSnapshot();
36
39
  });
37
40
 
38
41
  it("renders empty when no filters are selected", async () => {
39
- const thisRenderOpts = _.update("state.structureFilters", () => ({}))(
40
- renderOpts
42
+ const thisRenderOpts = _.update(
43
+ "state.previousStructureQuery.allFilters",
44
+ () => ({})
45
+ )(renderOpts);
46
+ const { container, getByText } = render(
47
+ <StructuresBulkUpdate />,
48
+ thisRenderOpts
41
49
  );
42
-
43
- const { container } = render(<StructuresBulkUpdate />, thisRenderOpts);
44
-
50
+ const emptySearchText = getByText("Empty Search");
51
+ expect(emptySearchText).toBeInTheDocument();
45
52
  expect(container).toMatchSnapshot();
46
53
  });
47
54
 
48
55
  it("Publish button is available with autoPublish action", async () => {
49
56
  const dispatch = jest.fn();
50
- const thisRenderOpts = _.update("state.structuresActions", () => ({
51
- autoPublish: { method: "POST" },
52
- }))(renderOpts);
57
+ const thisRenderOpts = _.update(
58
+ "state.previousStructureQuery.actions",
59
+ () => ({
60
+ autoPublish: { method: "POST" },
61
+ })
62
+ )(renderOpts);
53
63
 
54
64
  const { container, findByText, queryByText, findByRole } = render(
55
65
  <StructuresBulkUpdate />,
@@ -75,6 +85,7 @@ describe("<StructuresBulkUpdate />", () => {
75
85
  ...bulkUpdateStructures(),
76
86
  payload: {
77
87
  autoPublish: true,
88
+ searchParams: {},
78
89
  structureCount: 10,
79
90
  update_attributes: {
80
91
  df_content: {
@@ -111,6 +122,7 @@ describe("<StructuresBulkUpdate />", () => {
111
122
  ...bulkUpdateStructures(),
112
123
  payload: {
113
124
  autoPublish: false,
125
+ searchParams: {},
114
126
  structureCount: 10,
115
127
  update_attributes: {
116
128
  df_content: {
@@ -1,11 +1,12 @@
1
1
  import React from "react";
2
2
  import { render } from "@truedat/test/render";
3
+ import SearchContextWrapper from "@truedat/core/components/common/SearchContextWrapper";
3
4
  import { StructuresDownloadOption } from "../StructuresDownloadOption";
4
5
  import en from "../../messages/en";
5
6
 
6
7
  describe("<StructuresDownloadOption />", () => {
7
8
  const downloadStructures = jest.fn();
8
- const structuresLoading = false;
9
+
9
10
  const renderOpts = {
10
11
  messages: {
11
12
  en: {
@@ -17,18 +18,50 @@ describe("<StructuresDownloadOption />", () => {
17
18
  };
18
19
 
19
20
  it("matches the latest snapshot", () => {
20
- const props = { downloadStructures, structuresLoading };
21
+ const props = { downloadStructures };
22
+ const searchProps = {
23
+ loading: false,
24
+ searchParams: {},
25
+ searchData: { data: [{ id: 1 }] },
26
+ };
27
+
28
+ const { container } = render(
29
+ <SearchContextWrapper props={searchProps}>
30
+ <StructuresDownloadOption {...props} />
31
+ </SearchContextWrapper>,
32
+ renderOpts
33
+ );
34
+ expect(container).toMatchSnapshot();
35
+ });
36
+
37
+ it("has filter applied", () => {
38
+ const props = { downloadStructures, hasFilterApplied: true };
39
+ const searchProps = {
40
+ loading: false,
41
+ searchParams: {},
42
+ searchData: { data: [{ id: 1 }] },
43
+ };
44
+
21
45
  const { container } = render(
22
- <StructuresDownloadOption {...props} />,
46
+ <SearchContextWrapper props={searchProps}>
47
+ <StructuresDownloadOption {...props} />
48
+ </SearchContextWrapper>,
23
49
  renderOpts
24
50
  );
25
51
  expect(container).toMatchSnapshot();
26
52
  });
27
53
 
28
54
  it("is disabled if there are no structures to be downloaded", () => {
29
- const props = { downloadStructures, structuresLoading, structures: [] };
55
+ const props = { downloadStructures };
56
+ const searchProps = {
57
+ loading: false,
58
+ searchData: { data: [] },
59
+ searchParams: {},
60
+ };
30
61
  const { getByRole, queryByText } = render(
31
- <StructuresDownloadOption {...props} />,
62
+ <SearchContextWrapper props={searchProps}>
63
+ <StructuresDownloadOption {...props} />
64
+ </SearchContextWrapper>,
32
65
  renderOpts
33
66
  );
34
67
  expect(getByRole("option")).toHaveAttribute("aria-disabled");
@@ -1,10 +1,11 @@
1
1
  import React from "react";
2
2
  import { render } from "@truedat/test/render";
3
+ import SearchContextWrapper from "@truedat/core/components/common/SearchContextWrapper";
3
4
  import { StructuresEditableDownloadOption } from "../StructuresEditableDownloadOption";
4
5
 
5
6
  describe("<StructuresEditableDownloadOption />", () => {
6
7
  const downloadEditableStructures = jest.fn();
7
- const structuresLoading = false;
8
+
8
9
  const renderOpts = {
9
10
  messages: {
10
11
  en: {
@@ -15,22 +16,33 @@ describe("<StructuresEditableDownloadOption />", () => {
15
16
  };
16
17
 
17
18
  it("matches the latest snapshot", () => {
18
- const props = { downloadEditableStructures, structuresLoading };
19
+ const searchProps = {
20
+ loading: false,
21
+ searchData: { data: [{ id: 1 }] },
22
+ searchParams: {},
23
+ };
24
+ const props = { downloadEditableStructures };
19
25
  const { container } = render(
20
- <StructuresEditableDownloadOption {...props} />,
26
+ <SearchContextWrapper props={searchProps}>
27
+ <StructuresEditableDownloadOption {...props} />
28
+ </SearchContextWrapper>,
21
29
  renderOpts
22
30
  );
23
31
  expect(container).toMatchSnapshot();
24
32
  });
25
33
 
26
34
  it("is disabled if there are no structures to be downloaded", () => {
27
- const props = {
28
- downloadEditableStructures,
29
- structuresLoading,
30
- structures: {},
35
+ const props = { downloadEditableStructures };
36
+ const searchProps = {
37
+ loading: false,
38
+ searchData: { data: [] },
39
+ searchParams: {},
31
40
  };
41
+
32
42
  const { getByRole, queryByText } = render(
33
- <StructuresEditableDownloadOption {...props} />,
43
+ <SearchContextWrapper props={searchProps}>
44
+ <StructuresEditableDownloadOption {...props} />
45
+ </SearchContextWrapper>,
34
46
  renderOpts
35
47
  );
36
48
  expect(getByRole("option")).toHaveAttribute("aria-disabled");
@@ -4,8 +4,8 @@ import { waitFor } from "@testing-library/react";
4
4
  import { within } from "@testing-library/dom";
5
5
  import userEvent from "@testing-library/user-event";
6
6
  import { functionsMock } from "@truedat/test/mocks";
7
-
8
- import StructuresGrantRequestView from "../StructuresGrantRequestView";
7
+ import { StructuresGrantRequestView } from "../StructuresGrantRequestView";
8
+ import en from "../../messages/en";
9
9
 
10
10
  const mockHistory = { push: jest.fn() };
11
11
 
@@ -15,8 +15,8 @@ jest.mock("react-router-dom", () => ({
15
15
  useHistory: () => mockHistory,
16
16
  }));
17
17
 
18
- const dispatch = jest.fn();
19
- describe("<StructuresGrantRequestView />", () => {
18
+ jest.mock("@truedat/dd/hooks/useStructures", () => {
19
+ const originalModule = jest.requireActual("@truedat/dd/hooks/useStructures");
20
20
  const structures = [1, 2, 3].map((id) => ({
21
21
  id,
22
22
  name: `structure_${id}`,
@@ -30,19 +30,47 @@ describe("<StructuresGrantRequestView />", () => {
30
30
  updated_at: "2023-04-27",
31
31
  }));
32
32
 
33
- const renderOpts = {
34
- mocks: [functionsMock],
35
- state: {
36
- structures,
37
- structureCount: 3,
38
- userPermissions: {
39
- request_grant: true,
40
- },
41
- },
42
- dispatch,
43
- fallback: "lazy",
33
+ const data = { data: structures };
34
+
35
+ return {
36
+ __esModule: true,
37
+ ...originalModule,
38
+ useDataStructureFilters: () => ({
39
+ trigger: () => ({
40
+ then: (callback) =>
41
+ callback({
42
+ data: { data: {} },
43
+ }),
44
+ }),
45
+ }),
46
+ useDataStructureSearch: () => ({
47
+ trigger: () => ({
48
+ then: (callback) =>
49
+ callback({
50
+ data,
51
+ headers: { "x-total-count": 3 },
52
+ }),
53
+ }),
54
+ }),
44
55
  };
56
+ });
57
+
58
+ const messages = {
59
+ en: {
60
+ ...en,
61
+ "search.placeholder": "Searching ...",
62
+ },
63
+ };
64
+ const dispatch = jest.fn();
45
65
 
66
+ const renderOpts = {
67
+ messages,
68
+ mocks: [functionsMock],
69
+ dispatch,
70
+ fallback: "lazy",
71
+ };
72
+
73
+ describe("<StructuresGrantRequestView />", () => {
46
74
  it("Clicking a grant request button triggers action", async () => {
47
75
  const { container, queryByText } = render(
48
76
  <StructuresGrantRequestView />,
@@ -1,17 +1,44 @@
1
1
  import React from "react";
2
- import { shallow } from "enzyme";
3
- import { intl } from "@truedat/test/intl-stub";
4
- import { StructuresLabelResults } from "../StructuresLabelResults";
2
+ import { render } from "@truedat/test/render";
3
+ import { SearchContextProvider } from "@truedat/core/search/SearchContext";
4
+ import StructuresLabelResults from "../StructuresLabelResults";
5
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);
6
+ const useFilters = () => ({
7
+ trigger: () => ({
8
+ then: (callback) =>
9
+ callback({
10
+ data: { data: {} },
11
+ }),
12
+ }),
13
+ });
9
14
 
10
- describe("<StructuresLabelResults />", () => {
11
- const props = { structureCount: 22 };
15
+ const useSearch = () => ({
16
+ trigger: () => ({
17
+ then: (callback) =>
18
+ callback({
19
+ data: { data: [] },
20
+ headers: { "x-total-count": 22 },
21
+ }),
22
+ }),
23
+ });
12
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("<StructuresLabelResults />", () => {
13
36
  it("matches the latest snapshot", () => {
14
- const wrapper = shallow(<StructuresLabelResults {...props} />);
15
- expect(wrapper).toMatchSnapshot();
37
+ const { container } = render(
38
+ <SearchContextProvider {...searchProps}>
39
+ <StructuresLabelResults />
40
+ </SearchContextProvider>
41
+ );
42
+ expect(container).toMatchSnapshot();
16
43
  });
17
44
  });
@@ -1,8 +1,38 @@
1
1
  import React from "react";
2
2
  import { waitFor } from "@testing-library/react";
3
3
  import { render } from "@truedat/test/render";
4
+ import { SearchContextProvider } from "@truedat/core/search/SearchContext";
4
5
  import StructuresOptions from "../StructuresOptions";
5
6
 
7
+ const useFilters = () => ({
8
+ trigger: () => ({
9
+ then: (callback) =>
10
+ callback({
11
+ data: { data: {} },
12
+ }),
13
+ }),
14
+ });
15
+
16
+ const useSearch = () => ({
17
+ trigger: () => ({
18
+ then: (callback) =>
19
+ callback({
20
+ data: [],
21
+ headers: { "x-total-count": 22 },
22
+ }),
23
+ }),
24
+ });
25
+
26
+ const searchProps = {
27
+ initialSortColumn: "name.raw",
28
+ initialSortDirection: "ascending",
29
+ useSearch: useSearch,
30
+ userFiltersType: "structures",
31
+ omitFilters: [],
32
+ useFilters: useFilters,
33
+ translations: jest.fn(),
34
+ };
35
+
6
36
  describe("<StructuresOptions />", () => {
7
37
  const props = {
8
38
  bulkUpload: {},
@@ -12,7 +42,38 @@ describe("<StructuresOptions />", () => {
12
42
  };
13
43
 
14
44
  it("matches the latest snapshot", async () => {
15
- const { container } = render(<StructuresOptions {...props} />);
45
+ const { container } = render(
46
+ <SearchContextProvider {...searchProps}>
47
+ <StructuresOptions {...props} />
48
+ </SearchContextProvider>
49
+ );
50
+
16
51
  await waitFor(() => expect(container).toMatchSnapshot());
17
52
  });
53
+
54
+ it("Dont have permissions to upload notes", async () => {
55
+ const newProps = {};
56
+ const { queryByText } = render(
57
+ <SearchContextProvider {...searchProps}>
58
+ <StructuresOptions {...newProps} />
59
+ </SearchContextProvider>
60
+ );
61
+
62
+ await waitFor(() =>
63
+ expect(queryByText("Upload structure notes")).not.toBeInTheDocument()
64
+ );
65
+ });
66
+
67
+ it("Dont have permissions to upload domains", async () => {
68
+ const newProps = {};
69
+ const { queryByText } = render(
70
+ <SearchContextProvider {...searchProps}>
71
+ <StructuresOptions {...newProps} />
72
+ </SearchContextProvider>
73
+ );
74
+
75
+ await waitFor(() =>
76
+ expect(queryByText("Update structure domains")).not.toBeInTheDocument()
77
+ );
78
+ });
18
79
  });
@@ -1,23 +1,78 @@
1
1
  import React from "react";
2
- import { shallow } from "enzyme";
3
- import { StructuresSearchResults } from "../StructuresSearchResults";
4
- import StructuresTable from "../StructuresTable";
2
+ import { render } from "@truedat/test/render";
3
+ import userEvent from "@testing-library/user-event";
4
+ import { waitFor } from "@testing-library/react";
5
+ import SearchContextWrapper from "@truedat/core/components/common/SearchContextWrapper";
6
+ import StructuresSearchResults from "../StructuresSearchResults";
7
+
8
+ const renderOpts = {
9
+ messages: {
10
+ en: {
11
+ "structure.bar": "Bar",
12
+ "structure.foo": "Foo",
13
+ "search.placeholder": "Search...",
14
+ "structure.group": "Group",
15
+ "structure.system": "System",
16
+ "structure.name": "Name",
17
+ "structures.retrieved.results": "Results",
18
+ "structures.loading.header": "Header",
19
+ },
20
+ },
21
+ };
22
+
23
+ const structures = [1, 2, 3].map((id) => ({ id: id, foo: id }));
24
+
25
+ const searchProps = {
26
+ searchData: {
27
+ _actions: {},
28
+ data: structures,
29
+ },
30
+ sortColumn: jest.fn(),
31
+ sortDirection: jest.fn(),
32
+ defaultFilters: jest.fn(),
33
+ handleSortSelection: jest.fn(),
34
+ };
5
35
 
6
36
  describe("<StructuresSearchResults />", () => {
7
- const structures = [1, 2, 3].map(id => ({ id }));
37
+ const columns = [{ name: "foo", sort: { name: "name.raw" } }];
8
38
 
9
39
  it("matches the latest snapshot", () => {
10
- const props = { structures };
11
- const wrapper = shallow(<StructuresSearchResults {...props} />);
12
- expect(wrapper).toMatchSnapshot();
40
+ const props = { structures, columns };
41
+ const { container } = render(
42
+ <SearchContextWrapper props={searchProps}>
43
+ <StructuresSearchResults {...props} />
44
+ </SearchContextWrapper>,
45
+ renderOpts
46
+ );
47
+ expect(container).toMatchSnapshot();
13
48
  });
14
49
 
15
- it("selecting a structure in the table will call onSelect passing the structure", () => {
50
+ it("selecting a structure in the table will call onSelect passing the structure", async () => {
16
51
  const onSelect = jest.fn();
17
- const props = { onSelect, structures };
18
- const structure = { id: 42 };
19
- const wrapper = shallow(<StructuresSearchResults {...props} />);
20
- wrapper.find(StructuresTable).simulate("structureSelected", structure);
52
+ const structure = { id: 1, foo: 1 };
53
+ const props = {
54
+ onSelect,
55
+ structures,
56
+ columns,
57
+ selectedStructure: structure,
58
+ };
59
+
60
+ const { getByRole } = render(
61
+ <SearchContextWrapper props={searchProps}>
62
+ <StructuresSearchResults {...props} />
63
+ </SearchContextWrapper>,
64
+ renderOpts
65
+ );
66
+
67
+ const structureRow = getByRole("cell", { name: /1/i });
68
+
69
+ userEvent.click(structureRow);
70
+
71
+ await waitFor(() => {
72
+ expect(onSelect).toHaveBeenCalledTimes(1);
73
+ });
74
+ expect(onSelect).toHaveBeenCalledWith(structures[0]);
75
+
21
76
  expect(onSelect.mock.calls.length).toBe(1);
22
77
  expect(onSelect.mock.calls[0][0]).toEqual(structure);
23
78
  });