@truedat/dd 6.10.1 → 6.10.2

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 (73) hide show
  1. package/package.json +5 -5
  2. package/src/components/GrantRequestBulkActions.js +67 -90
  3. package/src/components/GrantRequestBulkApprovalForm.js +1 -0
  4. package/src/components/GrantRequestBulkRoleSelector.js +0 -3
  5. package/src/components/GrantRequestRow.js +6 -8
  6. package/src/components/GrantRequestsLabelResults.js +31 -42
  7. package/src/components/GrantRequestsSearchResults.js +88 -107
  8. package/src/components/GrantRequestsTable.js +22 -51
  9. package/src/components/GrantRoutes.js +32 -19
  10. package/src/components/__tests__/GrantRequestBulkActions.spec.js +101 -8
  11. package/src/components/__tests__/GrantRequestRow.spec.js +3 -4
  12. package/src/components/__tests__/GrantRequestsLabelResults.spec.js +21 -9
  13. package/src/components/__tests__/GrantRequestsSearchResults.spec.js +21 -21
  14. package/src/components/__tests__/GrantRequestsTable.spec.js +26 -9
  15. package/src/components/__tests__/__snapshots__/GrantRequestBulkActions.spec.js.snap +48 -34
  16. package/src/components/__tests__/__snapshots__/GrantRequestBulkApprovalForm.spec.js.snap +1 -0
  17. package/src/components/__tests__/__snapshots__/GrantRequestBulkRoleSelector.spec.js.snap +0 -1
  18. package/src/components/__tests__/__snapshots__/GrantRequestRow.spec.js.snap +20 -0
  19. package/src/components/__tests__/__snapshots__/GrantRequestsLabelResults.spec.js.snap +25 -12
  20. package/src/components/__tests__/__snapshots__/GrantRequestsSearchResults.spec.js.snap +182 -120
  21. package/src/components/__tests__/__snapshots__/GrantRequestsTable.spec.js.snap +109 -11
  22. package/src/components/index.js +0 -4
  23. package/src/hooks/useGrantRequest.js +13 -0
  24. package/src/reducers/index.js +0 -24
  25. package/src/routines.js +2 -33
  26. package/src/sagas/index.js +0 -3
  27. package/src/selectors/index.js +0 -6
  28. package/src/components/GrantRequestPagination.js +0 -18
  29. package/src/components/GrantRequestSearchFilters.js +0 -23
  30. package/src/components/GrantRequestsFiltersLoader.js +0 -33
  31. package/src/components/GrantRequestsSearch.js +0 -35
  32. package/src/components/GrantRequestsSearchLoader.js +0 -47
  33. package/src/components/GrantRequestsSelectedFilters.js +0 -55
  34. package/src/components/__tests__/GrantRequestFiltersLoader.spec.js +0 -20
  35. package/src/components/__tests__/GrantRequestSearchFilters.spec.js +0 -19
  36. package/src/components/__tests__/GrantRequestsSearch.spec.js +0 -23
  37. package/src/components/__tests__/GrantRequestsSearchLoader.spec.js +0 -15
  38. package/src/components/__tests__/__snapshots__/GrantRequestSearchFilters.spec.js.snap +0 -47
  39. package/src/components/__tests__/__snapshots__/GrantRequestsSearch.spec.js.snap +0 -50
  40. package/src/components/__tests__/__snapshots__/GrantRequestsSearchLoader.spec.js.snap +0 -3
  41. package/src/reducers/__tests__/grantRequestCount.spec.js +0 -38
  42. package/src/reducers/__tests__/grantRequestPageSize.spec.js +0 -36
  43. package/src/reducers/__tests__/grantRequestPermissions.spec.js +0 -66
  44. package/src/reducers/__tests__/grantRequestsActiveFilters.spec.js +0 -90
  45. package/src/reducers/__tests__/grantRequestsFiltersLoading.spec.js +0 -34
  46. package/src/reducers/__tests__/grantRequestsSearch.spec.js +0 -38
  47. package/src/reducers/__tests__/grantRequestsSearchLoading.spec.js +0 -36
  48. package/src/reducers/__tests__/grantRequestsSearchQuery.spec.js +0 -96
  49. package/src/reducers/__tests__/grantRequestsSelectedFilter.spec.js +0 -72
  50. package/src/reducers/grantRequestCount.js +0 -23
  51. package/src/reducers/grantRequestPageSize.js +0 -15
  52. package/src/reducers/grantRequestPermissions.js +0 -36
  53. package/src/reducers/grantRequestSearchQuery.js +0 -60
  54. package/src/reducers/grantRequestsActiveFilters.js +0 -58
  55. package/src/reducers/grantRequestsFilters.js +0 -23
  56. package/src/reducers/grantRequestsFiltersLoading.js +0 -14
  57. package/src/reducers/grantRequestsSearch.js +0 -19
  58. package/src/reducers/grantRequestsSearchLoading.js +0 -14
  59. package/src/reducers/grantRequestsSelectedFilter.js +0 -34
  60. package/src/sagas/__tests__/fetchGrantRequestsSearch.spec.js +0 -92
  61. package/src/sagas/fetchGrantRequestsSearch.js +0 -30
  62. package/src/selectors/__tests__/getGrantRequestsAvailableFilters.spec.js +0 -15
  63. package/src/selectors/__tests__/getGrantRequestsFilterTypes.spec.js +0 -19
  64. package/src/selectors/__tests__/getGrantRequestsSearchQuery.spec.js +0 -24
  65. package/src/selectors/__tests__/getGrantRequestsSelectedFilterActiveValues.spec.js +0 -15
  66. package/src/selectors/__tests__/getGrantRequestsSelectedFilterValues.spec.js +0 -15
  67. package/src/selectors/__tests__/getGrantRequestsSelectedFilters.spec.js +0 -13
  68. package/src/selectors/getGrantRequestsAvailableFilters.js +0 -17
  69. package/src/selectors/getGrantRequestsFilterTypes.js +0 -7
  70. package/src/selectors/getGrantRequestsSearchQuery.js +0 -19
  71. package/src/selectors/getGrantRequestsSelectedFilterActiveValues.js +0 -8
  72. package/src/selectors/getGrantRequestsSelectedFilterValues.js +0 -12
  73. package/src/selectors/getGrantRequestsSelectedFilters.js +0 -10
@@ -1,11 +1,10 @@
1
1
  import _ from "lodash/fp";
2
- import React, { useEffect, useState } from "react";
2
+ import React from "react";
3
3
  import PropTypes from "prop-types";
4
4
  import { connect } from "react-redux";
5
5
  import { useIntl } from "react-intl";
6
- import { getSortInfo, sortColumn } from "@truedat/core/services/sort";
6
+ import { useSearchContext } from "@truedat/core/search/SearchContext";
7
7
  import { Checkbox, Table, Header, Icon } from "semantic-ui-react";
8
- import { sortGrantRequests } from "../routines";
9
8
  import { getGrantRequestsSearchColumns } from "../selectors";
10
9
  import { GrantRequestRow } from "./GrantRequestRow";
11
10
 
@@ -14,29 +13,19 @@ export const GrantRequestsTable = ({
14
13
  checkedAll,
15
14
  checkRow,
16
15
  isRowChecked,
17
- grantRequests,
18
- grantRequestsSearchLoading,
19
16
  columns,
20
- grantRequestsSort,
21
- sortGrantRequests,
22
- roleSelected,
23
- canApprove,
17
+ approveView,
24
18
  }) => {
25
19
  const { formatMessage } = useIntl();
20
+ const {
21
+ searchData,
22
+ loading,
23
+ sortColumn,
24
+ sortDirection,
25
+ handleSortSelection,
26
+ } = useSearchContext();
26
27
 
27
- const [sortedColumn, setColumn] = useState(
28
- _.prop("column")(getSortInfo(grantRequestsSort))
29
- );
30
- const [direction, setDirection] = useState(
31
- _.prop("direction")(getSortInfo(grantRequestsSort))
32
- );
33
-
34
- useEffect(() => {
35
- const { column: sortedColumn, direction: direction } =
36
- getSortInfo(grantRequestsSort);
37
- setColumn(sortedColumn);
38
- setDirection(direction);
39
- }, [grantRequestsSort]);
28
+ const grantRequests = _.propOr([], "data")(searchData);
40
29
 
41
30
  return (
42
31
  <>
@@ -44,7 +33,7 @@ export const GrantRequestsTable = ({
44
33
  <Table sortable selectable>
45
34
  <Table.Header>
46
35
  <Table.Row>
47
- {roleSelected && canApprove ? (
36
+ {approveView ? (
48
37
  <Table.HeaderCell textAlign="center">
49
38
  <Checkbox
50
39
  id="selectGrantRequest"
@@ -62,21 +51,14 @@ export const GrantRequestsTable = ({
62
51
  defaultMessage: column.name,
63
52
  })}
64
53
  sorted={
65
- _.path("sort.name")(column) === sortedColumn
66
- ? direction
54
+ _.path("sort.name")(column) === sortColumn
55
+ ? sortDirection
67
56
  : null
68
57
  }
69
58
  className={_.path("sort.name")(column) ? "" : "disabled"}
70
- onClick={() => {
71
- sortColumn(
72
- column,
73
- sortGrantRequests,
74
- setDirection,
75
- setColumn,
76
- direction,
77
- sortedColumn
78
- );
79
- }}
59
+ onClick={() =>
60
+ handleSortSelection(_.path("sort.name")(column))
61
+ }
80
62
  />
81
63
  ))}
82
64
  </Table.Row>
@@ -84,19 +66,18 @@ export const GrantRequestsTable = ({
84
66
  <Table.Body>
85
67
  {grantRequests.map((gr, key) => (
86
68
  <GrantRequestRow
87
- roleSelected={roleSelected}
88
69
  key={key}
89
70
  checked={isRowChecked && isRowChecked(gr)}
90
71
  grantRequest={gr}
91
72
  columns={columns}
92
- canApprove={canApprove}
93
- onChange={() => checkRow && checkRow(gr)}
73
+ approveView={approveView}
74
+ onCheckboxChange={() => checkRow && checkRow(gr)}
94
75
  />
95
76
  ))}
96
77
  </Table.Body>
97
78
  </Table>
98
79
  ) : null}
99
- {_.isEmpty(grantRequests) && !grantRequestsSearchLoading ? (
80
+ {_.isEmpty(grantRequests) && !loading ? (
100
81
  <Header as="h4">
101
82
  <Icon name="search" />
102
83
  <Header.Content>
@@ -110,25 +91,15 @@ export const GrantRequestsTable = ({
110
91
 
111
92
  GrantRequestsTable.propTypes = {
112
93
  columns: PropTypes.array,
113
- grantRequests: PropTypes.array,
114
- grantRequestsSort: PropTypes.array,
115
- roleSelected: PropTypes.string,
116
- canApprove: PropTypes.bool,
94
+ approveView: PropTypes.bool,
117
95
  checkedAll: PropTypes.bool,
118
- grantRequestsSearchLoading: PropTypes.bool,
119
96
  addAll: PropTypes.func,
120
97
  checkRow: PropTypes.func,
121
98
  isRowChecked: PropTypes.func,
122
- sortGrantRequests: PropTypes.func,
123
99
  };
124
100
 
125
101
  const mapStateToProps = (state) => ({
126
102
  columns: getGrantRequestsSearchColumns(state),
127
- grantRequests: state.grantRequestsSearch,
128
- grantRequestsSearchLoading: state.grantRequestsSearchLoading,
129
- grantRequestsSort: _.path("grantRequestSearchQuery.sort")(state),
130
103
  });
131
104
 
132
- export default connect(mapStateToProps, { sortGrantRequests })(
133
- GrantRequestsTable
134
- );
105
+ export default connect(mapStateToProps)(GrantRequestsTable);
@@ -19,6 +19,14 @@ import {
19
19
  MY_GRANTS,
20
20
  STRUCTURES_GRANT_REQUEST,
21
21
  } from "@truedat/core/routes";
22
+
23
+ import { SearchContextProvider } from "@truedat/core/search/SearchContext";
24
+
25
+ import {
26
+ useGrantRequestsSearch,
27
+ useGrantRequestsFilters,
28
+ } from "../hooks/useGrantRequest";
29
+
22
30
  import GrantView from "./Grant";
23
31
  import GrantApprovalRule from "./GrantApprovalRule";
24
32
  import GrantApprovalRuleEdit from "./GrantApprovalRuleEdit";
@@ -30,13 +38,11 @@ import GrantRequestLoader from "./GrantRequestLoader";
30
38
  import GrantRequestsLoader from "./GrantRequestsLoader";
31
39
  import GrantRequestsSearchResults from "./GrantRequestsSearchResults";
32
40
  import GrantRequestApprovalResults from "./GrantRequestApprovalResults";
33
- import GrantRequestsSearchLoader from "./GrantRequestsSearchLoader";
34
41
  import Grants from "./Grants";
35
42
  import GrantsLoader from "./GrantsLoader";
36
43
  import MyGrantRequests from "./MyGrantRequests";
37
44
  import StructureGrantCartCheckout from "./StructureGrantCartCheckout";
38
45
  import StructuresGrantRequestView from "./StructuresGrantRequestView";
39
- import GrantRequestsFiltersLoader from "./GrantRequestsFiltersLoader";
40
46
 
41
47
  const TemplatesLoader = React.lazy(() =>
42
48
  import("@truedat/df/templates/components/TemplatesLoader")
@@ -47,12 +53,17 @@ const GrantRequestGroup = () => {
47
53
  const defaultFilters = {
48
54
  group_id: [id],
49
55
  };
56
+ const searchProps = {
57
+ initialSortColumn: "inserted_at",
58
+ initialSortDirection: "ascending",
59
+ useSearch: useGrantRequestsSearch,
60
+ useFilters: useGrantRequestsFilters,
61
+ pageSize: 20,
62
+ };
50
63
  return (
51
- <>
52
- <GrantRequestsSearchLoader defaultFilters={defaultFilters} />
53
- <GrantRequestsFiltersLoader defaultFilters={defaultFilters} />
54
- <GrantRequestsSearchResults defaultFilters={defaultFilters} />
55
- </>
64
+ <SearchContextProvider {...searchProps} defaultFilters={defaultFilters}>
65
+ <GrantRequestsSearchResults />
66
+ </SearchContextProvider>
56
67
  );
57
68
  };
58
69
 
@@ -151,20 +162,22 @@ export const GrantRoutes = ({ grantRequestLoaded }) => {
151
162
  path={GRANT_REQUESTS}
152
163
  render={() => {
153
164
  const defaultFilters = {};
154
- return (
155
- <>
156
- <GrantRequestsSearchLoader
157
- defaultFilters={defaultFilters}
158
- />
159
165
 
160
- <GrantRequestsFiltersLoader
161
- defaultFilters={defaultFilters}
162
- />
166
+ const searchProps = {
167
+ initialSortColumn: "inserted_at",
168
+ initialSortDirection: "ascending",
169
+ useSearch: useGrantRequestsSearch,
170
+ useFilters: useGrantRequestsFilters,
171
+ pageSize: 20,
172
+ };
163
173
 
164
- <GrantRequestsSearchResults
165
- defaultFilters={defaultFilters}
166
- />
167
- </>
174
+ return (
175
+ <SearchContextProvider
176
+ {...searchProps}
177
+ defaultFilters={defaultFilters}
178
+ >
179
+ <GrantRequestsSearchResults />
180
+ </SearchContextProvider>
168
181
  );
169
182
  }}
170
183
  />
@@ -1,12 +1,63 @@
1
1
  import React from "react";
2
2
  import { render } from "@truedat/test/render";
3
+ import { act } from "@testing-library/react";
4
+ import userEvent from "@testing-library/user-event";
5
+ import SearchContext from "@truedat/core/search/SearchContext";
3
6
  import GrantRequestBulkActions from "../GrantRequestBulkActions";
7
+ // import { useGrantRequestBulkApproval } from "@truedat/dd/hooks/useGrantRequest";
8
+
9
+ jest.mock("react-router-dom", () => ({
10
+ ...jest.requireActual("react-router-dom"),
11
+ useHistory: () => ({
12
+ push: jest.fn(),
13
+ }),
14
+ }));
15
+
16
+ jest.mock("@truedat/dd/hooks/useGrantRequest", () => {
17
+ const originalModule = jest.requireActual(
18
+ "@truedat/dd/hooks/useGrantRequest"
19
+ );
20
+
21
+ return {
22
+ __esModule: true,
23
+ ...originalModule,
24
+ useGrantRequestBulkApproval: jest.fn(() => ({
25
+ trigger: jest.fn(() => ({
26
+ then: (callback) =>
27
+ callback({
28
+ data: { data: { id: 1 } },
29
+ }),
30
+ })),
31
+ })),
32
+ };
33
+ });
4
34
 
5
35
  describe("<GrantRequestBulkActions />", () => {
6
36
  const cleanSelectedGrantRequests = jest.fn();
7
37
  const props = {
8
38
  cleanSelectedGrantRequests,
9
- canApprove: true,
39
+ selectedGrantRequests: [],
40
+ };
41
+
42
+ const baseSearchContext = {
43
+ searchData: { data: [] },
44
+ loading: false,
45
+ toggleHiddenFilterValue: jest.fn(),
46
+ resetFilters: jest.fn(),
47
+ searchMust: { foo: "bar" },
48
+ cleanQuery: jest.fn(),
49
+ };
50
+
51
+ const searchContextWithData = {
52
+ searchData: {
53
+ data: [{ foo: "bar" }],
54
+ _permissions: ["role1", "role2"],
55
+ },
56
+ loading: false,
57
+ toggleHiddenFilterValue: jest.fn(),
58
+ resetFilters: jest.fn(),
59
+ searchMust: { foo: "bar" },
60
+ cleanQuery: jest.fn(),
10
61
  };
11
62
 
12
63
  const renderOpts = {
@@ -24,22 +75,64 @@ describe("<GrantRequestBulkActions />", () => {
24
75
 
25
76
  it("matches the latest snapshot", () => {
26
77
  const { container } = render(
27
- <GrantRequestBulkActions {...props} />,
78
+ <SearchContext.Provider value={searchContextWithData}>
79
+ <GrantRequestBulkActions {...props} />
80
+ </SearchContext.Provider>,
28
81
  renderOpts
29
82
  );
30
83
  expect(container).toMatchSnapshot();
31
84
  });
32
85
 
33
- it("disable acctions when canApprove is false", () => {
34
- const newProps = {
35
- ...props,
36
- canApprove: false,
37
- };
86
+ it("enabled actions when there are results", () => {
87
+ const { getByRole } = render(
88
+ <SearchContext.Provider value={searchContextWithData}>
89
+ <GrantRequestBulkActions {...props} />,
90
+ </SearchContext.Provider>,
91
+ renderOpts
92
+ );
93
+ expect(getByRole("button", { name: /approve_request/i })).toBeEnabled();
94
+ expect(getByRole("button", { name: /reject/i })).toBeEnabled();
95
+ });
96
+
97
+ it("disable actions when no results", () => {
38
98
  const { getByRole } = render(
39
- <GrantRequestBulkActions {...newProps} />,
99
+ <SearchContext.Provider value={baseSearchContext}>
100
+ <GrantRequestBulkActions {...props} />,
101
+ </SearchContext.Provider>,
40
102
  renderOpts
41
103
  );
42
104
  expect(getByRole("button", { name: /approve_request/i })).toBeDisabled();
43
105
  expect(getByRole("button", { name: /reject/i })).toBeDisabled();
44
106
  });
107
+
108
+ it("changing selected role, clears selection", async () => {
109
+ const { findByText, getByRole, getByTestId } = render(
110
+ <SearchContext.Provider value={searchContextWithData}>
111
+ <GrantRequestBulkActions {...props} />,
112
+ </SearchContext.Provider>,
113
+ renderOpts
114
+ );
115
+
116
+ const { toggleHiddenFilterValue, resetFilters, cleanQuery } =
117
+ searchContextWithData;
118
+
119
+ cleanSelectedGrantRequests.mockReset();
120
+ resetFilters.mockReset();
121
+ cleanQuery.mockReset();
122
+ toggleHiddenFilterValue.mockReset();
123
+
124
+ userEvent.click(await findByText(/role2/i));
125
+ expect(resetFilters).toHaveBeenCalledTimes(1);
126
+ expect(cleanSelectedGrantRequests).toHaveBeenCalledTimes(1);
127
+ expect(cleanQuery).toHaveBeenCalledTimes(1);
128
+ expect(toggleHiddenFilterValue).toHaveBeenCalledWith({
129
+ filter: "must_not_approved_by",
130
+ value: ["role2"],
131
+ });
132
+
133
+ userEvent.click(await findByText(/approve_request/i));
134
+ userEvent.type(await getByRole("textbox"), "Approve comment");
135
+
136
+ await act(async () => userEvent.click(getByTestId("approve-button-id")));
137
+ });
45
138
  });
@@ -33,7 +33,7 @@ const grantRequest = {
33
33
  };
34
34
 
35
35
  describe("<GrantRequestRow />", () => {
36
- const onChange = jest.fn();
36
+ const onCheckboxChange = jest.fn();
37
37
  const onClick = jest.fn();
38
38
 
39
39
  const props = {
@@ -42,10 +42,9 @@ describe("<GrantRequestRow />", () => {
42
42
  columns,
43
43
  disabled: false,
44
44
  onClick,
45
- onChange,
45
+ onCheckboxChange,
46
46
  grantRequest,
47
- roleSelected: "foo",
48
- canApprove: true,
47
+ approveView: true,
49
48
  };
50
49
 
51
50
  it("matches the latest snapshot", () => {
@@ -1,5 +1,6 @@
1
1
  import React from "react";
2
2
  import { render } from "@truedat/test/render";
3
+ import SearchContext from "@truedat/core/search/SearchContext";
3
4
  import GrantRequestsLabelResults from "../GrantRequestsLabelResults";
4
5
 
5
6
  describe("<GrantRequestsLabelResults />", () => {
@@ -8,36 +9,47 @@ describe("<GrantRequestsLabelResults />", () => {
8
9
  en: {
9
10
  "grantRequests.retrieved.results": "results",
10
11
  "grantRequests.bulk.selected": "selected",
12
+ "grantRequests.searching": "searching",
11
13
  },
12
14
  },
13
15
  };
14
16
  const props = {
15
- grantRequestCount: 4,
16
- grantRequestsSearchLoading: false,
17
- grantRequestToExecute: 1,
17
+ selectedCount: 1,
18
+ approveView: true,
19
+ };
20
+
21
+ const searchContext = {
22
+ count: 4,
23
+ loading: false,
18
24
  };
19
25
 
20
26
  it("matches the latest snapshot", () => {
21
27
  const { container } = render(
22
- <GrantRequestsLabelResults {...props} />,
28
+ <SearchContext.Provider value={searchContext}>
29
+ <GrantRequestsLabelResults {...props} />
30
+ </SearchContext.Provider>,
23
31
  renderOpts
24
32
  );
25
33
  expect(container).toMatchSnapshot();
26
34
  });
27
35
 
28
- it("When role is not selected", () => {
29
- const newProps = { ...props, roleSelected: "foo" };
36
+ it("When not in approve view", () => {
37
+ const newProps = { ...props, approveView: false };
30
38
  const { container } = render(
31
- <GrantRequestsLabelResults {...newProps} />,
39
+ <SearchContext.Provider value={searchContext}>
40
+ <GrantRequestsLabelResults {...newProps} />
41
+ </SearchContext.Provider>,
32
42
  renderOpts
33
43
  );
34
44
  expect(container).toMatchSnapshot();
35
45
  });
36
46
 
37
47
  it("When is loading", () => {
38
- const newProps = { ...props, grantRequestsSearchLoading: true };
48
+ const newSearchContext = { ...searchContext, loading: true };
39
49
  const { container } = render(
40
- <GrantRequestsLabelResults {...newProps} />,
50
+ <SearchContext.Provider value={newSearchContext}>
51
+ <GrantRequestsLabelResults {...props} />,
52
+ </SearchContext.Provider>,
41
53
  renderOpts
42
54
  );
43
55
  expect(container).toMatchSnapshot();
@@ -1,23 +1,14 @@
1
1
  import React from "react";
2
2
  import userEvent from "@testing-library/user-event";
3
3
  import { render } from "@truedat/test/render";
4
+ import SearchContext from "@truedat/core/search/SearchContext";
4
5
  import GrantRequestsSearchResults from "../GrantRequestsSearchResults";
5
6
 
6
7
  describe("<GrantRequestsSearchResults />", () => {
7
8
  const grantRequests = [{ id: 1 }, { id: 2 }];
8
- const toggleGrantRequestsFilterValue = jest.fn();
9
9
  const rolesPermission = ["foo", "bar"];
10
- const activeFilters = { current_status: ["pending"] };
11
10
 
12
- const state = {
13
- grantRequests,
14
- grantRequestsSearch: grantRequests,
15
- rolesPermission,
16
- grantRequestPermissions: rolesPermission,
17
- grantRequestsActiveFilters: activeFilters,
18
- };
19
-
20
- const renderOpts = (state) => ({
11
+ const renderOpts = {
21
12
  messages: {
22
13
  en: {
23
14
  "grantRequestApproval.form.role.select": "select",
@@ -30,30 +21,39 @@ describe("<GrantRequestsSearchResults />", () => {
30
21
  "grantRequests.retrieved.results": "results",
31
22
  "search.applied_filters": "Filters:",
32
23
  "search.clear_filters": "Clear filters",
24
+ "search.placeholder": "placeholder",
25
+ "grantRequests.empty": "empty",
33
26
  },
34
27
  },
35
- state: state,
36
- });
28
+ };
37
29
 
38
- const props = {
30
+ const baseSearchContext = {
31
+ searchData: { data: grantRequests, _permissions: rolesPermission },
39
32
  loading: false,
40
- rolesPermission,
41
- toggleGrantRequestsFilterValue,
42
- grantRequests,
33
+ setOnSearchChange: jest.fn(),
34
+ setHiddenFilters: jest.fn(),
35
+ toggleHiddenFilterValue: jest.fn(),
36
+ resetFilters: jest.fn(),
37
+ searchMust: {},
38
+ cleanQuery: jest.fn(),
43
39
  };
44
40
 
45
41
  it("matches the latest snapshot", () => {
46
42
  const { container } = render(
47
- <GrantRequestsSearchResults {...props} />,
48
- renderOpts(state)
43
+ <SearchContext.Provider value={baseSearchContext}>
44
+ <GrantRequestsSearchResults />,
45
+ </SearchContext.Provider>,
46
+ renderOpts
49
47
  );
50
48
  expect(container).toMatchSnapshot();
51
49
  });
52
50
 
53
51
  it("select a role", async () => {
54
52
  const { getByRole } = render(
55
- <GrantRequestsSearchResults {...props} />,
56
- renderOpts(state)
53
+ <SearchContext.Provider value={baseSearchContext}>
54
+ <GrantRequestsSearchResults />,
55
+ </SearchContext.Provider>,
56
+ renderOpts
57
57
  );
58
58
  userEvent.click(getByRole("option", { name: /foo/i }));
59
59
  });
@@ -1,5 +1,6 @@
1
1
  import React from "react";
2
2
  import { render } from "@truedat/test/render";
3
+ import SearchContext from "@truedat/core/search/SearchContext";
3
4
  import { GrantRequestsTable } from "../GrantRequestsTable";
4
5
  import { defaultGrantRequestsSearchTableColumns } from "../../selectors/getGrantRequestsSearchColumns";
5
6
 
@@ -12,25 +13,41 @@ const grantsRequests = [
12
13
  ];
13
14
 
14
15
  describe("<GrantRequestsTable />", () => {
15
- const grantRequestsSort = [{ inserted_at: "asc" }];
16
- const sortGrantRequests = jest.fn();
16
+ const renderOpts = {
17
+ messages: {
18
+ en: {
19
+ "grantRequest.current_status.pending": "pending",
20
+ },
21
+ },
22
+ };
23
+
24
+ const searchContext = {
25
+ searchData: {
26
+ data: grantsRequests,
27
+ },
28
+ loading: false,
29
+
30
+ sortColumn: "inserted_at",
31
+ sortDirection: "ascending",
32
+ handleSortSelection: jest.fn(),
33
+ };
17
34
 
18
35
  const props = {
19
36
  addAll: jest.fn(),
20
37
  checkedAll: true,
21
38
  checkRow: jest.fn(),
22
39
  isRowChecked: jest.fn(),
23
- grantsRequests,
24
- grantRequestsSearchLoading: false,
25
40
  columns: defaultGrantRequestsSearchTableColumns,
26
- grantRequestsSort,
27
- sortGrantRequests,
28
- roleSelected: "foo",
29
- canApprove: true,
41
+ approveView: true,
30
42
  };
31
43
 
32
44
  it("matches the latest snapshot", () => {
33
- const { container } = render(<GrantRequestsTable {...props} />);
45
+ const { container } = render(
46
+ <SearchContext.Provider value={searchContext}>
47
+ <GrantRequestsTable {...props} />
48
+ </SearchContext.Provider>,
49
+ renderOpts
50
+ );
34
51
  expect(container).toMatchSnapshot();
35
52
  });
36
53
  });
@@ -3,49 +3,63 @@
3
3
  exports[`<GrantRequestBulkActions /> matches the latest snapshot 1`] = `
4
4
  <div>
5
5
  <div
6
- class="grant-requests-bulk-actions"
6
+ aria-expanded="false"
7
+ class="ui selection dropdown grant-requests-bulk-role-selector"
8
+ role="listbox"
9
+ tabindex="0"
7
10
  >
8
11
  <div
9
- class="right aligned four wide column"
12
+ aria-atomic="true"
13
+ aria-live="polite"
14
+ class="divider text"
15
+ role="alert"
16
+ >
17
+ role1
18
+ </div>
19
+ <i
20
+ aria-hidden="true"
21
+ class="dropdown icon"
22
+ />
23
+ <div
24
+ class="menu transition"
10
25
  >
11
26
  <div
12
- aria-disabled="false"
13
- aria-expanded="false"
14
- class="ui selection dropdown grant-requests-bulk-role-selector"
15
- role="listbox"
16
- tabindex="0"
27
+ aria-checked="true"
28
+ aria-selected="true"
29
+ class="active selected item"
30
+ role="option"
31
+ style="pointer-events: all;"
17
32
  >
18
- <div
19
- aria-atomic="true"
20
- aria-live="polite"
21
- class="divider default text"
22
- role="alert"
33
+ <span
34
+ class="text"
23
35
  >
24
- select
25
- </div>
26
- <i
27
- aria-hidden="true"
28
- class="dropdown icon"
29
- />
30
- <div
31
- class="menu transition"
32
- />
36
+ role1
37
+ </span>
33
38
  </div>
34
- <button
35
- class="ui primary disabled button button icon group-actions"
36
- disabled=""
37
- tabindex="-1"
38
- >
39
- approve_request
40
- </button>
41
- <button
42
- class="ui secondary disabled button button icon group-actions"
43
- disabled=""
44
- tabindex="-1"
39
+ <div
40
+ aria-checked="false"
41
+ aria-selected="false"
42
+ class="item"
43
+ role="option"
44
+ style="pointer-events: all;"
45
45
  >
46
- reject
47
- </button>
46
+ <span
47
+ class="text"
48
+ >
49
+ role2
50
+ </span>
51
+ </div>
48
52
  </div>
49
53
  </div>
54
+ <button
55
+ class="ui primary button button icon group-actions"
56
+ >
57
+ approve_request
58
+ </button>
59
+ <button
60
+ class="ui secondary button button icon group-actions"
61
+ >
62
+ reject
63
+ </button>
50
64
  </div>
51
65
  `;