@truedat/dd 4.49.9 → 4.50.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 (38) hide show
  1. package/CHANGELOG.md +6 -0
  2. package/package.json +5 -5
  3. package/src/api/queries.js +16 -0
  4. package/src/api.js +2 -0
  5. package/src/components/GrantChangeRequest.js +32 -0
  6. package/src/components/GrantRequestCancel.js +47 -0
  7. package/src/components/GrantRequestHeader.js +9 -1
  8. package/src/components/MyGrantRequests.js +1 -0
  9. package/src/components/StructureGrantButton.js +24 -44
  10. package/src/components/StructureGrantCart.js +2 -2
  11. package/src/components/StructureGrantCartCheckout.js +20 -15
  12. package/src/components/StructureGrantCartTemplate.js +15 -61
  13. package/src/components/StructureGrantDropdown.js +201 -0
  14. package/src/components/StructureGrantRequestButton.js +15 -14
  15. package/src/components/StructureGrants.js +1 -1
  16. package/src/components/StructureSummary.js +13 -6
  17. package/src/components/StructureView.js +7 -8
  18. package/src/components/__tests__/MyGrantRequests.spec.js +5 -0
  19. package/src/components/__tests__/StructureGrantButton.spec.js +107 -34
  20. package/src/components/__tests__/StructureGrantCartTemplate.spec.js +11 -100
  21. package/src/components/__tests__/StructureGrantDropdown.spec.js +148 -0
  22. package/src/components/__tests__/StructureGrantRequestButton.spec.js +9 -10
  23. package/src/components/__tests__/__snapshots__/MyGrantRequests.spec.js.snap +14 -0
  24. package/src/components/__tests__/__snapshots__/StructureGrantButton.spec.js.snap +162 -16
  25. package/src/components/__tests__/__snapshots__/StructureGrantCartTemplate.spec.js.snap +0 -3
  26. package/src/components/__tests__/__snapshots__/StructureGrantDropdown.spec.js.snap +271 -0
  27. package/src/components/__tests__/__snapshots__/StructureGrantRequestButton.spec.js.snap +11 -10
  28. package/src/components/__tests__/__snapshots__/StructureSummary.spec.js.snap +6 -0
  29. package/src/messages/en.js +17 -1
  30. package/src/messages/es.js +17 -3
  31. package/src/reducers/__tests__/grantRequestsCart.spec.js +223 -9
  32. package/src/reducers/grantRequestsCart.js +20 -26
  33. package/src/routines.js +2 -1
  34. package/src/sagas/__tests__/createGrantRequestStatus.spec.js +82 -0
  35. package/src/sagas/createGrantRequestStatus.js +32 -0
  36. package/src/sagas/index.js +3 -0
  37. package/src/sagas/operateGrantRequestCart.js +2 -27
  38. package/src/selectors/getGrantRequestsColumns.js +18 -3
@@ -0,0 +1,148 @@
1
+ import _ from "lodash/fp";
2
+ import React from "react";
3
+ import { fireEvent } from "@testing-library/react";
4
+ import { render } from "@truedat/test/render";
5
+ import userEvent from "@testing-library/user-event";
6
+ import StructureGrantDropdown from "../StructureGrantDropdown";
7
+ import en from "../../messages/en";
8
+
9
+ const renderOptsBuilder = (grant, structureGrantPopup) => ({
10
+ state: {
11
+ structure: { grant },
12
+ structureGrantPopup,
13
+ },
14
+ messages: { en },
15
+ });
16
+
17
+ const mockHistory = {
18
+ push: jest.fn(),
19
+ };
20
+
21
+ jest.mock("react-router-dom", () => ({
22
+ ...jest.requireActual("react-router-dom"),
23
+ useHistory: () => mockHistory,
24
+ }));
25
+
26
+ describe("<StructureGrantDropdown />", () => {
27
+ it("matches the latest snapshot for pendingRequest state", () => {
28
+ const grantRequest = {
29
+ status: { status: "pending" },
30
+ };
31
+ const renderOpts = renderOptsBuilder({});
32
+ const { container } = render(
33
+ <StructureGrantDropdown grantRequest={grantRequest} />,
34
+ renderOpts
35
+ );
36
+
37
+ expect(container).toMatchSnapshot();
38
+ });
39
+
40
+ it("matches the latest snapshot for pendingRequest state with modification", () => {
41
+ const grantRequest = {
42
+ group: { grant: { id: 1 } },
43
+ status: { status: "pending" },
44
+ };
45
+ const renderOpts = renderOptsBuilder({});
46
+ const { container } = render(
47
+ <StructureGrantDropdown grantRequest={grantRequest} />,
48
+ renderOpts
49
+ );
50
+
51
+ expect(container).toMatchSnapshot();
52
+ });
53
+
54
+ it("matches the latest snapshot for processingRequest state", () => {
55
+ const grantRequest = {
56
+ status: { status: "processing" },
57
+ };
58
+ const renderOpts = renderOptsBuilder({});
59
+ const { container } = render(
60
+ <StructureGrantDropdown grantRequest={grantRequest} />,
61
+ renderOpts
62
+ );
63
+
64
+ expect(container).toMatchSnapshot();
65
+ });
66
+
67
+ it("matches the latest snapshot for processingRequest state with modification", () => {
68
+ const grantRequest = {
69
+ group: { grant: { id: 1 } },
70
+ status: { status: "processing" },
71
+ };
72
+ const renderOpts = renderOptsBuilder({});
73
+ const { container } = render(
74
+ <StructureGrantDropdown grantRequest={grantRequest} />,
75
+ renderOpts
76
+ );
77
+
78
+ expect(container).toMatchSnapshot();
79
+ });
80
+
81
+ it("matches the latest snapshot for pendingRemovalGrant state", () => {
82
+ const grantRequest = null;
83
+ const renderOpts = renderOptsBuilder({ pending_removal: true });
84
+ const { container } = render(
85
+ <StructureGrantDropdown grantRequest={grantRequest} />,
86
+ renderOpts
87
+ );
88
+
89
+ expect(container).toMatchSnapshot();
90
+ });
91
+
92
+ it("matches the latest snapshot for activeGrant state", () => {
93
+ const grantRequest = null;
94
+ const renderOpts = renderOptsBuilder({ pending_removal: false });
95
+ const { container } = render(
96
+ <StructureGrantDropdown grantRequest={grantRequest} />,
97
+ renderOpts
98
+ );
99
+
100
+ expect(container).toMatchSnapshot();
101
+ });
102
+
103
+ it("when hovering on activeGrant state, renders grant detail", async () => {
104
+ const grantRequest = null;
105
+ const structureGrantPopup = [
106
+ { type: "date", field: "end_date" },
107
+ { field: "detail.foo" },
108
+ ];
109
+ const grant = {
110
+ pending_removal: false,
111
+ end_date: "2022-08-25",
112
+ detail: {
113
+ foo: "bar",
114
+ },
115
+ };
116
+ const renderOpts = renderOptsBuilder(grant, structureGrantPopup);
117
+ const { findByRole, findByText, debug } = render(
118
+ <StructureGrantDropdown grantRequest={grantRequest} />,
119
+ renderOpts
120
+ );
121
+
122
+ fireEvent.mouseOver(await findByRole("listbox"));
123
+ expect(
124
+ await findByText(en["structure.grant.has_grant"])
125
+ ).toBeInTheDocument();
126
+ expect(await findByText("2022-08-25")).toBeInTheDocument();
127
+ expect(await findByText("bar")).toBeInTheDocument();
128
+ });
129
+
130
+ it("when clicking on viewRequest action, will redirect to grantResquest page", async () => {
131
+ const grantRequest = {
132
+ id: 8,
133
+ status: { status: "pending" },
134
+ };
135
+ const renderOpts = renderOptsBuilder({});
136
+
137
+ const { findByText } = render(
138
+ <StructureGrantDropdown grantRequest={grantRequest} />,
139
+ renderOpts
140
+ );
141
+
142
+ userEvent.click(
143
+ await findByText(en["grant.actions.view_request.confirmation.header"])
144
+ );
145
+
146
+ expect(mockHistory.push).toHaveBeenCalledWith("/grant_requests/8");
147
+ });
148
+ });
@@ -5,13 +5,13 @@ import { render } from "@truedat/test/render";
5
5
  import { StructureGrantRequestButton } from "../StructureGrantRequestButton";
6
6
 
7
7
  describe("<StructureGrantRequestButton />", () => {
8
- it("render a button", async () => {
8
+ it("matches latest snapshot", async () => {
9
9
  const props = {
10
10
  requested: false,
11
11
  authorized: true,
12
12
  };
13
- const { getByText } = render(<StructureGrantRequestButton {...props} />);
14
- expect(getByText("Request grant")).toMatchSnapshot();
13
+ const { container } = render(<StructureGrantRequestButton {...props} />);
14
+ expect(container).toMatchSnapshot();
15
15
  });
16
16
 
17
17
  it("can be clickable", async () => {
@@ -23,8 +23,8 @@ describe("<StructureGrantRequestButton />", () => {
23
23
  removeGrantRequestFromCart: removeRequest,
24
24
  authorized: true,
25
25
  };
26
- const { findByText } = render(<StructureGrantRequestButton {...props} />);
27
- userEvent.click(await findByText("Request grant"));
26
+ const { getByRole } = render(<StructureGrantRequestButton {...props} />);
27
+ userEvent.click(await getByRole("button"));
28
28
  await waitFor(() => {
29
29
  expect(addRequest.mock.calls.length).toBe(1);
30
30
  expect(removeRequest.mock.calls.length).toBe(0);
@@ -40,8 +40,8 @@ describe("<StructureGrantRequestButton />", () => {
40
40
  removeGrantRequestFromCart: removeRequest,
41
41
  authorized: true,
42
42
  };
43
- const { findByText } = render(<StructureGrantRequestButton {...props} />);
44
- userEvent.click(await findByText("Pending request"));
43
+ const { getByRole } = render(<StructureGrantRequestButton {...props} />);
44
+ userEvent.click(await getByRole("button"));
45
45
  await waitFor(() => {
46
46
  expect(addRequest.mock.calls.length).toBe(0);
47
47
  expect(removeRequest.mock.calls.length).toBe(1);
@@ -58,9 +58,8 @@ describe("<StructureGrantRequestButton />", () => {
58
58
  authorized: false,
59
59
  };
60
60
  const component = render(<StructureGrantRequestButton {...props} />);
61
- const { queryAllByText } = component;
62
- expect(queryAllByText("Request grant")).toHaveLength(0);
63
- expect(queryAllByText("Pending request")).toHaveLength(0);
61
+ const { queryAllByRole } = component;
62
+ expect(queryAllByRole("button")).toHaveLength(0);
64
63
  expect(component).toMatchSnapshot();
65
64
  });
66
65
  });
@@ -125,6 +125,20 @@ exports[`<MyGrantRequests /> matches the latest snapshot 1`] = `
125
125
  failed
126
126
  </label>
127
127
  </div>
128
+ <div
129
+ class="ui checkbox"
130
+ >
131
+ <input
132
+ class="hidden"
133
+ readonly=""
134
+ tabindex="0"
135
+ type="checkbox"
136
+ value=""
137
+ />
138
+ <label>
139
+ cancelled
140
+ </label>
141
+ </div>
128
142
  </div>
129
143
  </form>
130
144
  <div
@@ -1,37 +1,183 @@
1
1
  // Jest Snapshot v1, https://goo.gl/fbAQLP
2
2
 
3
- exports[`<StructureGrantButton /> matches the latest snapshot 1`] = `
3
+ exports[`<StructureGrantButton /> matches snapshot for active grant and active grantRequest 1`] = `
4
4
  <div>
5
5
  <div
6
- class="ui green label"
6
+ aria-expanded="false"
7
+ class="ui floating dropdown"
8
+ role="listbox"
9
+ tabindex="0"
7
10
  >
8
- <i
9
- aria-hidden="true"
10
- class="shield icon"
11
- />
12
- You have granted access on this structure
13
- <i
14
- aria-hidden="true"
15
- class="delete icon"
16
- />
11
+ <button
12
+ class="ui yellow icon button button basic icon group-actions"
13
+ >
14
+ <i
15
+ aria-hidden="true"
16
+ class="shield icon"
17
+ />
18
+ </button>
19
+ <div
20
+ class="menu transition left"
21
+ >
22
+ <div
23
+ class="item"
24
+ role="option"
25
+ >
26
+ <i
27
+ aria-hidden="true"
28
+ class="info icon"
29
+ />
30
+ <span
31
+ class="text"
32
+ >
33
+ View detail
34
+ </span>
35
+ </div>
36
+ <div
37
+ class="item"
38
+ role="option"
39
+ >
40
+ <i
41
+ aria-hidden="true"
42
+ class="delete icon"
43
+ />
44
+ <span
45
+ class="text"
46
+ >
47
+ Cancel request
48
+ </span>
49
+ </div>
50
+ </div>
51
+ </div>
52
+ </div>
53
+ `;
54
+
55
+ exports[`<StructureGrantButton /> matches snapshot for active grant and inactive grantRequest 1`] = `
56
+ <div>
57
+ <div
58
+ aria-expanded="false"
59
+ class="ui floating dropdown"
60
+ role="listbox"
61
+ tabindex="0"
62
+ >
63
+ <button
64
+ class="ui green icon button button basic icon group-actions"
65
+ >
66
+ <i
67
+ aria-hidden="true"
68
+ class="shield icon"
69
+ />
70
+ </button>
71
+ <div
72
+ class="menu transition left"
73
+ >
74
+ <div
75
+ class="item"
76
+ role="option"
77
+ >
78
+ <i
79
+ aria-hidden="true"
80
+ class="edit icon"
81
+ />
82
+ <span
83
+ class="text"
84
+ >
85
+ Request grant change
86
+ </span>
87
+ </div>
88
+ <div
89
+ class="item"
90
+ role="option"
91
+ >
92
+ <i
93
+ aria-hidden="true"
94
+ class="delete icon"
95
+ />
96
+ <span
97
+ class="text"
98
+ >
99
+ Request grant removal
100
+ </span>
101
+ </div>
102
+ </div>
17
103
  </div>
18
104
  </div>
19
105
  `;
20
106
 
21
- exports[`<StructureGrantButton /> matches the latest snapshot pending_removal 1`] = `
107
+ exports[`<StructureGrantButton /> matches snapshot for no grant and active grantRequest 1`] = `
22
108
  <div>
23
109
  <div
24
- class="ui orange label"
110
+ aria-expanded="false"
111
+ class="ui floating dropdown"
112
+ role="listbox"
113
+ tabindex="0"
114
+ >
115
+ <button
116
+ class="ui yellow icon button button basic icon group-actions"
117
+ >
118
+ <i
119
+ aria-hidden="true"
120
+ class="shield icon"
121
+ />
122
+ </button>
123
+ <div
124
+ class="menu transition left"
125
+ >
126
+ <div
127
+ class="item"
128
+ role="option"
129
+ >
130
+ <i
131
+ aria-hidden="true"
132
+ class="info icon"
133
+ />
134
+ <span
135
+ class="text"
136
+ >
137
+ View detail
138
+ </span>
139
+ </div>
140
+ <div
141
+ class="item"
142
+ role="option"
143
+ >
144
+ <i
145
+ aria-hidden="true"
146
+ class="delete icon"
147
+ />
148
+ <span
149
+ class="text"
150
+ >
151
+ Cancel request
152
+ </span>
153
+ </div>
154
+ </div>
155
+ </div>
156
+ </div>
157
+ `;
158
+
159
+ exports[`<StructureGrantButton /> matches snapshot for no grant and inactive grantRequest 1`] = `
160
+ <div>
161
+ <button
162
+ class="ui orange icon button button basic icon group-actions"
25
163
  >
26
164
  <i
27
165
  aria-hidden="true"
28
166
  class="shield icon"
29
167
  />
30
- You have granted access pending removal
168
+ </button>
169
+ </div>
170
+ `;
171
+
172
+ exports[`<StructureGrantButton /> matches snapshot for no grant and no grantRequest 1`] = `
173
+ <div>
174
+ <button
175
+ class="ui orange icon button button basic icon group-actions"
176
+ >
31
177
  <i
32
178
  aria-hidden="true"
33
- class="undo icon"
179
+ class="shield icon"
34
180
  />
35
- </div>
181
+ </button>
36
182
  </div>
37
183
  `;
@@ -15,9 +15,6 @@ exports[`<StructureGrantCartTemplate /> matches the latest snapshot 1`] = `
15
15
  <div
16
16
  class="ui divider"
17
17
  />
18
- <div
19
- class="ui divider"
20
- />
21
18
  <form
22
19
  class="ui form"
23
20
  />
@@ -0,0 +1,271 @@
1
+ // Jest Snapshot v1, https://goo.gl/fbAQLP
2
+
3
+ exports[`<StructureGrantDropdown /> matches the latest snapshot for activeGrant state 1`] = `
4
+ <div>
5
+ <div
6
+ aria-expanded="false"
7
+ class="ui floating dropdown"
8
+ role="listbox"
9
+ tabindex="0"
10
+ >
11
+ <button
12
+ class="ui green icon button button basic icon group-actions"
13
+ >
14
+ <i
15
+ aria-hidden="true"
16
+ class="shield icon"
17
+ />
18
+ </button>
19
+ <div
20
+ class="menu transition left"
21
+ >
22
+ <div
23
+ class="item"
24
+ role="option"
25
+ >
26
+ <i
27
+ aria-hidden="true"
28
+ class="edit icon"
29
+ />
30
+ <span
31
+ class="text"
32
+ >
33
+ Request grant change
34
+ </span>
35
+ </div>
36
+ <div
37
+ class="item"
38
+ role="option"
39
+ >
40
+ <i
41
+ aria-hidden="true"
42
+ class="delete icon"
43
+ />
44
+ <span
45
+ class="text"
46
+ >
47
+ Request grant removal
48
+ </span>
49
+ </div>
50
+ </div>
51
+ </div>
52
+ </div>
53
+ `;
54
+
55
+ exports[`<StructureGrantDropdown /> matches the latest snapshot for pendingRemovalGrant state 1`] = `
56
+ <div>
57
+ <div
58
+ aria-expanded="false"
59
+ class="ui floating dropdown"
60
+ role="listbox"
61
+ tabindex="0"
62
+ >
63
+ <button
64
+ class="ui red icon button button basic icon group-actions"
65
+ >
66
+ <i
67
+ aria-hidden="true"
68
+ class="shield icon"
69
+ />
70
+ </button>
71
+ <div
72
+ class="menu transition left"
73
+ >
74
+ <div
75
+ class="item"
76
+ role="option"
77
+ >
78
+ <i
79
+ aria-hidden="true"
80
+ class="delete icon"
81
+ />
82
+ <span
83
+ class="text"
84
+ >
85
+ Cancel grant removal
86
+ </span>
87
+ </div>
88
+ </div>
89
+ </div>
90
+ </div>
91
+ `;
92
+
93
+ exports[`<StructureGrantDropdown /> matches the latest snapshot for pendingRequest state 1`] = `
94
+ <div>
95
+ <div
96
+ aria-expanded="false"
97
+ class="ui floating dropdown"
98
+ role="listbox"
99
+ tabindex="0"
100
+ >
101
+ <button
102
+ class="ui yellow icon button button basic icon group-actions"
103
+ >
104
+ <i
105
+ aria-hidden="true"
106
+ class="shield icon"
107
+ />
108
+ </button>
109
+ <div
110
+ class="menu transition left"
111
+ >
112
+ <div
113
+ class="item"
114
+ role="option"
115
+ >
116
+ <i
117
+ aria-hidden="true"
118
+ class="info icon"
119
+ />
120
+ <span
121
+ class="text"
122
+ >
123
+ View detail
124
+ </span>
125
+ </div>
126
+ <div
127
+ class="item"
128
+ role="option"
129
+ >
130
+ <i
131
+ aria-hidden="true"
132
+ class="delete icon"
133
+ />
134
+ <span
135
+ class="text"
136
+ >
137
+ Cancel request
138
+ </span>
139
+ </div>
140
+ </div>
141
+ </div>
142
+ </div>
143
+ `;
144
+
145
+ exports[`<StructureGrantDropdown /> matches the latest snapshot for pendingRequest state with modification 1`] = `
146
+ <div>
147
+ <div
148
+ aria-expanded="false"
149
+ class="ui floating dropdown"
150
+ role="listbox"
151
+ tabindex="0"
152
+ >
153
+ <button
154
+ class="ui yellow icon button button basic icon group-actions"
155
+ >
156
+ <i
157
+ aria-hidden="true"
158
+ class="shield icon"
159
+ />
160
+ </button>
161
+ <div
162
+ class="menu transition left"
163
+ >
164
+ <div
165
+ class="item"
166
+ role="option"
167
+ >
168
+ <i
169
+ aria-hidden="true"
170
+ class="info icon"
171
+ />
172
+ <span
173
+ class="text"
174
+ >
175
+ View detail
176
+ </span>
177
+ </div>
178
+ <div
179
+ class="item"
180
+ role="option"
181
+ >
182
+ <i
183
+ aria-hidden="true"
184
+ class="delete icon"
185
+ />
186
+ <span
187
+ class="text"
188
+ >
189
+ Cancel request
190
+ </span>
191
+ </div>
192
+ </div>
193
+ </div>
194
+ </div>
195
+ `;
196
+
197
+ exports[`<StructureGrantDropdown /> matches the latest snapshot for processingRequest state 1`] = `
198
+ <div>
199
+ <div
200
+ aria-expanded="false"
201
+ class="ui floating dropdown"
202
+ role="listbox"
203
+ tabindex="0"
204
+ >
205
+ <button
206
+ class="ui grey icon button button basic icon group-actions"
207
+ >
208
+ <i
209
+ aria-hidden="true"
210
+ class="shield icon"
211
+ />
212
+ </button>
213
+ <div
214
+ class="menu transition left"
215
+ >
216
+ <div
217
+ class="item"
218
+ role="option"
219
+ >
220
+ <i
221
+ aria-hidden="true"
222
+ class="info icon"
223
+ />
224
+ <span
225
+ class="text"
226
+ >
227
+ View detail
228
+ </span>
229
+ </div>
230
+ </div>
231
+ </div>
232
+ </div>
233
+ `;
234
+
235
+ exports[`<StructureGrantDropdown /> matches the latest snapshot for processingRequest state with modification 1`] = `
236
+ <div>
237
+ <div
238
+ aria-expanded="false"
239
+ class="ui floating dropdown"
240
+ role="listbox"
241
+ tabindex="0"
242
+ >
243
+ <button
244
+ class="ui grey icon button button basic icon group-actions"
245
+ >
246
+ <i
247
+ aria-hidden="true"
248
+ class="shield icon"
249
+ />
250
+ </button>
251
+ <div
252
+ class="menu transition left"
253
+ >
254
+ <div
255
+ class="item"
256
+ role="option"
257
+ >
258
+ <i
259
+ aria-hidden="true"
260
+ class="info icon"
261
+ />
262
+ <span
263
+ class="text"
264
+ >
265
+ View detail
266
+ </span>
267
+ </div>
268
+ </div>
269
+ </div>
270
+ </div>
271
+ `;