@truedat/dd 8.12.1 → 8.12.4

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 (82) hide show
  1. package/package.json +3 -3
  2. package/src/api/__tests__/queries.spec.js +55 -0
  3. package/src/api/queries.js +31 -0
  4. package/src/components/Grant.js +106 -16
  5. package/src/components/GrantRequest.js +2 -2
  6. package/src/components/GrantRequestBulkApprovalPopup.js +0 -1
  7. package/src/components/GrantRequestTemplateForm.js +76 -0
  8. package/src/components/GrantsDownloadButton.js +9 -1
  9. package/src/components/GrantsTable.js +4 -1
  10. package/src/components/StructureFields.js +7 -4
  11. package/src/components/StructureGrantCartCheckout.js +122 -59
  12. package/src/components/StructureGrantCartInformation.js +38 -9
  13. package/src/components/StructureGrantCartUserSelector.js +29 -4
  14. package/src/components/StructureGrantDropdown.js +7 -1
  15. package/src/components/StructureGrants.js +4 -1
  16. package/src/components/StructuresUpdateOption.js +2 -2
  17. package/src/components/SystemStructures.js +3 -3
  18. package/src/components/__tests__/CatalogViewConfigForm.spec.js +2 -0
  19. package/src/components/__tests__/EditDomainForm.spec.js +3 -1
  20. package/src/components/__tests__/Grant.spec.js +171 -0
  21. package/src/components/__tests__/GrantApprovalRuleForm.spec.js +2 -0
  22. package/src/components/__tests__/GrantApprovalRuleNew.spec.js +8 -0
  23. package/src/components/__tests__/GrantApprovalRules.spec.js +4 -0
  24. package/src/components/__tests__/GrantRequest.spec.js +4 -4
  25. package/src/components/__tests__/GrantRequestBulkActions.spec.js +1 -4
  26. package/src/components/__tests__/GrantRequestsSearchResults.spec.js +2 -0
  27. package/src/components/__tests__/GrantsDownloadButton.spec.js +58 -2
  28. package/src/components/__tests__/GrantsTable.spec.js +22 -2
  29. package/src/components/__tests__/LineageDefs.spec.js +6 -1
  30. package/src/components/__tests__/LineageForm.spec.js +1 -0
  31. package/src/components/__tests__/LineageGraphToolbar.spec.js +19 -17
  32. package/src/components/__tests__/LineageInspectorPanel.spec.js +17 -9
  33. package/src/components/__tests__/ProfileGroup.spec.js +7 -1
  34. package/src/components/__tests__/ReferenceDatasetForm.spec.js +2 -0
  35. package/src/components/__tests__/ReferenceDatasetRoutes.spec.js +9 -0
  36. package/src/components/__tests__/StructureGrantCartCheckout.grouping.spec.js +95 -0
  37. package/src/components/__tests__/StructureGrantCartCheckout.selection.spec.js +416 -0
  38. package/src/components/__tests__/StructureGrantCartCheckout.spec.js +216 -4
  39. package/src/components/__tests__/StructureGrantCartInformation.spec.js +5 -2
  40. package/src/components/__tests__/StructureGrantCartUserSelector.spec.js +128 -0
  41. package/src/components/__tests__/StructureGrantDropdown.spec.js +92 -0
  42. package/src/components/__tests__/StructureGrantListButton.spec.js +70 -0
  43. package/src/components/__tests__/StructureGrantSummaryButton.spec.js +36 -1
  44. package/src/components/__tests__/StructureGrants.spec.js +12 -0
  45. package/src/components/__tests__/StructureRelationRow.spec.js +72 -4
  46. package/src/components/__tests__/StructureRelations.spec.js +18 -0
  47. package/src/components/__tests__/StructureRoles.spec.js +9 -0
  48. package/src/components/__tests__/StructureRow.spec.js +13 -4
  49. package/src/components/__tests__/StructureSelector.spec.js +2 -0
  50. package/src/components/__tests__/StructureTag.spec.js +2 -0
  51. package/src/components/__tests__/StructureTagForm.spec.js +2 -0
  52. package/src/components/__tests__/StructureType.spec.js +3 -1
  53. package/src/components/__tests__/StructureTypeForm.spec.js +3 -1
  54. package/src/components/__tests__/StructureView.spec.js +17 -1
  55. package/src/components/__tests__/StructuresGrantRequestView.spec.js +2 -0
  56. package/src/components/__tests__/StructuresView.spec.js +2 -1
  57. package/src/components/__tests__/Tag.spec.js +4 -1
  58. package/src/components/__tests__/Tags.spec.js +7 -1
  59. package/src/components/__tests__/__snapshots__/GrantsTable.spec.js.snap +34 -2
  60. package/src/components/__tests__/__snapshots__/LineageDefs.spec.js.snap +32 -30
  61. package/src/components/__tests__/__snapshots__/StructureFields.spec.js.snap +1 -16
  62. package/src/components/__tests__/__snapshots__/StructureGrantCartCheckout.spec.js.snap +217 -1
  63. package/src/components/__tests__/__snapshots__/StructureGrantCartInformation.spec.js.snap +54 -0
  64. package/src/components/__tests__/__snapshots__/StructureRelationRow.spec.js.snap +23 -19
  65. package/src/components/__tests__/__snapshots__/StructureRow.spec.js.snap +28 -24
  66. package/src/components/__tests__/__snapshots__/StructuresUpdateOption.spec.js.snap +7 -3
  67. package/src/messages/en.js +2 -2
  68. package/src/messages/es.js +2 -2
  69. package/src/reducers/__tests__/grantRequestsCart.spec.js +86 -0
  70. package/src/reducers/__tests__/structureRelations.spec.js +28 -0
  71. package/src/reducers/grantRequestsCart.js +20 -2
  72. package/src/selectors/__tests__/__snapshots__/getGrantsColumns.spec.js.snap +1 -9
  73. package/src/selectors/__tests__/getGrantRequestsSearchColumns.spec.js +11 -4
  74. package/src/selectors/__tests__/getGrantsColumns.spec.js +295 -0
  75. package/src/selectors/getBusinessConceptsLinksToStructuresColumnsSelector.js +3 -5
  76. package/src/selectors/getGrantRequestsSearchColumns.js +3 -5
  77. package/src/selectors/getGrantsColumns.js +85 -11
  78. package/src/selectors/getLinkedImplementationsToStructuresColumns.js +3 -7
  79. package/src/selectors/getStructureFieldColumns.js +7 -6
  80. package/src/selectors/getStructureProperties.js +2 -5
  81. package/src/selectors/getStructuresUploadEventColumns.js +2 -7
  82. package/src/selectors/structureColumnsSelector.js +13 -16
@@ -1,6 +1,7 @@
1
1
  import userEvent from "@testing-library/user-event";
2
2
  import { render, waitForLoad } from "@truedat/test/render";
3
3
  import { singleTemplateMock, domainsMock } from "@truedat/test/mocks";
4
+ import { DOMAINS_QUERY, FUNCTIONS_QUERY } from "@truedat/core/api/queries";
4
5
  import { StructureGrantCartCheckout } from "../StructureGrantCartCheckout";
5
6
 
6
7
  jest.mock("@truedat/core/webContext", () => ({
@@ -23,6 +24,10 @@ jest.mock("@truedat/auth/hooks/useUsers", () => ({
23
24
  useGrantRequestableUsers: jest.fn(),
24
25
  }));
25
26
 
27
+ jest.mock("@truedat/auth/hooks/useRoles", () => ({
28
+ useRoles: () => ({ data: undefined }),
29
+ }));
30
+
26
31
  jest.mock("react-redux", () => {
27
32
  const actual = jest.requireActual("react-redux");
28
33
  return {
@@ -177,15 +182,28 @@ const grantRequestsCartSingleDomain = {
177
182
  };
178
183
 
179
184
  describe("StructureGrantCartCheckout", () => {
185
+ const domainQueryErrorMock = {
186
+ request: {
187
+ query: DOMAINS_QUERY,
188
+ variables: { action: "createForeignGrantRequest" },
189
+ },
190
+ error: new Error("Domains are not used by this checkout test"),
191
+ };
192
+ const functionsQueryErrorMock = {
193
+ request: { query: FUNCTIONS_QUERY },
194
+ error: new Error("Functions are not used by this checkout test"),
195
+ };
180
196
  const mockTrigger = jest.fn().mockResolvedValue({});
181
197
  const mockDispatch = jest.fn();
182
198
  const mockInitGroupTemplates = jest.fn();
199
+ const mockSelectGrantRequestTemplate = jest.fn();
183
200
  const mockSelectGrantRequestTemplateForGroup = jest.fn();
184
201
  const mockUpdateGrantRequestTemplateContentForGroup = jest.fn();
185
202
 
186
203
  const defaultProps = {
187
204
  grantRequestsCart: grantRequestsCartWithModification,
188
205
  initGroupTemplates: mockInitGroupTemplates,
206
+ selectGrantRequestTemplate: mockSelectGrantRequestTemplate,
189
207
  selectGrantRequestTemplateForGroup: mockSelectGrantRequestTemplateForGroup,
190
208
  updateGrantRequestTemplateContentForGroup:
191
209
  mockUpdateGrantRequestTemplateContentForGroup,
@@ -206,7 +224,11 @@ describe("StructureGrantCartCheckout", () => {
206
224
 
207
225
  const variables = { scope: "gr" };
208
226
  const renderOpts = {
209
- mocks: [singleTemplateMock(variables)],
227
+ mocks: [
228
+ singleTemplateMock(variables),
229
+ functionsQueryErrorMock,
230
+ domainQueryErrorMock,
231
+ ],
210
232
  };
211
233
 
212
234
  it("matches snapshot when modification grant (single flow)", async () => {
@@ -220,6 +242,28 @@ describe("StructureGrantCartCheckout", () => {
220
242
  expect(rendered.container).toMatchSnapshot();
221
243
  });
222
244
 
245
+ it("applies the default template when an update has no selection", async () => {
246
+ useWebContext.mockReturnValue({ scopesWithRelations: ["gr"] });
247
+ useTemplateRelations.mockReturnValue({
248
+ resource: [],
249
+ default: { template_id: 3 },
250
+ });
251
+ useTemplatesByIds.mockReturnValue({
252
+ 3: { id: 3, name: "Default template", content: [] },
253
+ });
254
+
255
+ const rendered = render(
256
+ <StructureGrantCartCheckout {...defaultProps} />,
257
+ renderOpts,
258
+ );
259
+ await waitForLoad(rendered);
260
+
261
+ expect(useTemplatesByIds).toHaveBeenCalledWith([3]);
262
+ expect(mockSelectGrantRequestTemplate).toHaveBeenCalledWith(
263
+ "Default template",
264
+ );
265
+ });
266
+
223
267
  it("matches snapshot when single flow without modification and empty cart", async () => {
224
268
  useWebContext.mockReturnValue({ scopesWithRelations: [] });
225
269
  useTemplateRelations.mockReturnValue({ resource: [] });
@@ -248,6 +292,8 @@ describe("StructureGrantCartCheckout", () => {
248
292
  mocks: [
249
293
  singleTemplateMock({ scope: "gr" }),
250
294
  domainsMock({ action: "createForeignGrantRequest" }),
295
+ functionsQueryErrorMock,
296
+ domainQueryErrorMock,
251
297
  ],
252
298
  };
253
299
  const rendered = render(
@@ -273,6 +319,8 @@ describe("StructureGrantCartCheckout", () => {
273
319
  mocks: [
274
320
  singleTemplateMock({ scope: "gr" }),
275
321
  domainsMock({ action: "createForeignGrantRequest" }),
322
+ functionsQueryErrorMock,
323
+ domainQueryErrorMock,
276
324
  ],
277
325
  };
278
326
  const rendered = render(
@@ -300,6 +348,8 @@ describe("StructureGrantCartCheckout", () => {
300
348
  mocks: [
301
349
  singleTemplateMock({ scope: "gr" }),
302
350
  domainsMock({ action: "createForeignGrantRequest" }),
351
+ functionsQueryErrorMock,
352
+ domainQueryErrorMock,
303
353
  ],
304
354
  };
305
355
  const rendered = render(
@@ -324,6 +374,8 @@ describe("StructureGrantCartCheckout", () => {
324
374
  mocks: [
325
375
  singleTemplateMock({ scope: "gr" }),
326
376
  domainsMock({ action: "createForeignGrantRequest" }),
377
+ functionsQueryErrorMock,
378
+ domainQueryErrorMock,
327
379
  ],
328
380
  };
329
381
  const rendered = render(
@@ -334,7 +386,7 @@ describe("StructureGrantCartCheckout", () => {
334
386
  expect(rendered.container).toMatchSnapshot();
335
387
  });
336
388
 
337
- it("matches snapshot with single domain - shows singular domain message", async () => {
389
+ it("matches snapshot with single domain - uses single-group information panel", async () => {
338
390
  useWebContext.mockReturnValue({ scopesWithRelations: ["gr"] });
339
391
  useTemplateRelations.mockReturnValue({
340
392
  resource: [{ resource_id: 10, template_id: 1, group_by_domain: true }],
@@ -349,6 +401,8 @@ describe("StructureGrantCartCheckout", () => {
349
401
  mocks: [
350
402
  singleTemplateMock({ scope: "gr" }),
351
403
  domainsMock({ action: "createForeignGrantRequest" }),
404
+ functionsQueryErrorMock,
405
+ domainQueryErrorMock,
352
406
  ],
353
407
  };
354
408
  const rendered = render(
@@ -371,15 +425,21 @@ describe("StructureGrantCartCheckout", () => {
371
425
  1: { name: "Template A", content: [] },
372
426
  2: { name: "Template B", content: [] },
373
427
  });
428
+ const grantRequestsCart = {
429
+ ...grantRequestsCartMultiGroup,
430
+ groupTemplates: {},
431
+ };
374
432
  const props = {
375
433
  ...defaultProps,
376
- grantRequestsCart: grantRequestsCartMultiGroup,
434
+ grantRequestsCart,
377
435
  };
378
436
  const renderOpts = {
379
- state: { grantRequestsCart: grantRequestsCartMultiGroup },
437
+ state: { grantRequestsCart },
380
438
  mocks: [
381
439
  singleTemplateMock({ scope: "gr" }),
382
440
  domainsMock({ action: "createForeignGrantRequest" }),
441
+ functionsQueryErrorMock,
442
+ domainQueryErrorMock,
383
443
  ],
384
444
  };
385
445
  const rendered = render(
@@ -399,6 +459,49 @@ describe("StructureGrantCartCheckout", () => {
399
459
  expect(mockInitGroupTemplates).not.toHaveBeenCalled();
400
460
  });
401
461
 
462
+ it("preserves group selections when no automatic template is assigned", async () => {
463
+ useWebContext.mockReturnValue({ scopesWithRelations: ["gr"] });
464
+ useTemplateRelations.mockReturnValue({
465
+ resource: [
466
+ { resource_id: 10, template_id: null },
467
+ { resource_id: 20, template_id: null },
468
+ ],
469
+ });
470
+ const grantRequestsCart = {
471
+ ...grantRequestsCartMultiGroup,
472
+ groupTemplates: {
473
+ nodomain_10_notype: {
474
+ template: "user template A",
475
+ templateContent: {},
476
+ valid: true,
477
+ },
478
+ nodomain_20_notype: {
479
+ template: "user template B",
480
+ templateContent: {},
481
+ valid: true,
482
+ },
483
+ },
484
+ };
485
+ const props = { ...defaultProps, grantRequestsCart };
486
+ const renderOpts = {
487
+ state: { grantRequestsCart },
488
+ mocks: [
489
+ singleTemplateMock({ scope: "gr" }),
490
+ domainsMock({ action: "createForeignGrantRequest" }),
491
+ functionsQueryErrorMock,
492
+ domainQueryErrorMock,
493
+ ],
494
+ };
495
+
496
+ const rendered = render(
497
+ <StructureGrantCartCheckout {...props} />,
498
+ renderOpts,
499
+ );
500
+ await waitForLoad(rendered);
501
+
502
+ expect(mockInitGroupTemplates).not.toHaveBeenCalled();
503
+ });
504
+
402
505
  it("sends user_group_id and not user_id on single checkout", async () => {
403
506
  const user = userEvent.setup({ delay: null });
404
507
  useWebContext.mockReturnValue({ scopesWithRelations: [] });
@@ -438,4 +541,113 @@ describe("StructureGrantCartCheckout", () => {
438
541
  expect(grant_request_group.user_group_id).toBe(10);
439
542
  expect(grant_request_group.user_id).toBeUndefined();
440
543
  });
544
+
545
+ it("preselects default template for groups without a system relation", async () => {
546
+ useWebContext.mockReturnValue({ scopesWithRelations: ["gr"] });
547
+ useTemplateRelations.mockReturnValue({
548
+ resource: [
549
+ { resource_id: 10, template_id: 1 },
550
+ { resource_id: 20, template_id: 2 },
551
+ ],
552
+ default: { template_id: 3 },
553
+ });
554
+ useTemplatesByIds.mockReturnValue({
555
+ 1: { name: "foo", content: [] },
556
+ 2: { name: "bar", content: [] },
557
+ 3: { name: "baz", content: [] },
558
+ });
559
+ const grantRequestsCart = {
560
+ ...grantRequestsCartMultiGroup,
561
+ structures: [
562
+ ...grantRequestsCartMultiGroup.structures,
563
+ {
564
+ id: 301,
565
+ system_id: 30,
566
+ system: { id: 30, name: "foo system" },
567
+ domain_ids: [3],
568
+ domains: [{ id: 3, name: "foo domain" }],
569
+ },
570
+ ],
571
+ };
572
+ const props = {
573
+ ...defaultProps,
574
+ grantRequestsCart,
575
+ };
576
+ const renderOpts = {
577
+ state: { grantRequestsCart },
578
+ mocks: [
579
+ singleTemplateMock({ scope: "gr" }),
580
+ domainsMock({ action: "createForeignGrantRequest" }),
581
+ functionsQueryErrorMock,
582
+ domainQueryErrorMock,
583
+ ],
584
+ };
585
+ const rendered = render(
586
+ <StructureGrantCartCheckout {...props} />,
587
+ renderOpts,
588
+ );
589
+ await waitForLoad(rendered);
590
+ expect(mockSelectGrantRequestTemplateForGroup).toHaveBeenCalledWith({
591
+ key: "nodomain_others_notype",
592
+ template: "baz",
593
+ });
594
+ });
595
+
596
+ it("preserves a selected template when revisiting a defaulted group", async () => {
597
+ useWebContext.mockReturnValue({ scopesWithRelations: ["gr"] });
598
+ useTemplateRelations.mockReturnValue({
599
+ resource: [
600
+ { resource_id: 10, template_id: 1 },
601
+ { resource_id: 20, template_id: 2 },
602
+ ],
603
+ default: { template_id: 3 },
604
+ });
605
+ useTemplatesByIds.mockReturnValue({
606
+ 1: { name: "foo", content: [] },
607
+ 2: { name: "bar", content: [] },
608
+ 3: { name: "baz", content: [] },
609
+ });
610
+ const grantRequestsCart = {
611
+ ...grantRequestsCartMultiGroup,
612
+ structures: [
613
+ ...grantRequestsCartMultiGroup.structures,
614
+ {
615
+ id: 301,
616
+ system_id: 30,
617
+ system: { id: 30, name: "foo system" },
618
+ domain_ids: [3],
619
+ domains: [{ id: 3, name: "foo domain" }],
620
+ },
621
+ ],
622
+ groupTemplates: {
623
+ ...grantRequestsCartMultiGroup.groupTemplates,
624
+ nodomain_others_notype: {
625
+ template: "user selected template",
626
+ templateContent: {},
627
+ valid: true,
628
+ },
629
+ },
630
+ };
631
+ const props = { ...defaultProps, grantRequestsCart };
632
+ const renderOpts = {
633
+ state: { grantRequestsCart },
634
+ mocks: [
635
+ singleTemplateMock({ scope: "gr" }),
636
+ domainsMock({ action: "createForeignGrantRequest" }),
637
+ functionsQueryErrorMock,
638
+ domainQueryErrorMock,
639
+ ],
640
+ };
641
+
642
+ const rendered = render(
643
+ <StructureGrantCartCheckout {...props} />,
644
+ renderOpts,
645
+ );
646
+ await waitForLoad(rendered);
647
+
648
+ expect(mockSelectGrantRequestTemplateForGroup).not.toHaveBeenCalledWith({
649
+ key: "nodomain_others_notype",
650
+ template: "baz",
651
+ });
652
+ });
441
653
  });
@@ -1,5 +1,5 @@
1
1
  import { render, waitForLoad } from "@truedat/test/render";
2
- import { singleTemplateMock } from "@truedat/test/mocks";
2
+ import { singleTemplateMock, domainsMock } from "@truedat/test/mocks";
3
3
  import { StructureGrantCartInformation } from "../StructureGrantCartInformation";
4
4
 
5
5
  jest.mock("@truedat/auth/hooks/useRoles", () => {
@@ -38,7 +38,10 @@ describe("<StructureGrantCartInformation />", () => {
38
38
  };
39
39
 
40
40
  const renderOpts = {
41
- mocks: [singleTemplateMock(variables)],
41
+ mocks: [
42
+ singleTemplateMock(variables),
43
+ domainsMock({ action: "createForeignGrantRequest" }, []),
44
+ ],
42
45
  };
43
46
 
44
47
  it("matches the latest snapshot", async () => {
@@ -4,6 +4,10 @@ import { render, waitForLoad } from "@truedat/test/render";
4
4
  import { useGrantRequestableUsers } from "@truedat/auth/hooks/useUsers";
5
5
  import StructureGrantCartUserSelector from "../StructureGrantCartUserSelector";
6
6
 
7
+ jest.mock("@truedat/auth/hooks/useRoles", () => ({
8
+ useRoles: () => ({ data: undefined }),
9
+ }));
10
+
7
11
  jest.mock("@truedat/auth/hooks/useUsers", () => ({
8
12
  useGrantRequestableUsers: jest.fn(() => ({
9
13
  users: [
@@ -179,4 +183,128 @@ describe("<StructureGrantCartUserSelector />", () => {
179
183
  );
180
184
  expect(payloads.some((payload) => payload?.id === "group:10")).toBe(false);
181
185
  });
186
+
187
+ it("preselects user group when modificationGrant has user_group_id", async () => {
188
+ const dispatch = jest.fn();
189
+ useGrantRequestableUsers.mockImplementation(() => ({
190
+ users: [{ id: 1, full_name: "foo user" }],
191
+ groups: [{ id: 10, name: "foo", alias: "bar" }],
192
+ trigger: jest.fn(),
193
+ }));
194
+
195
+ const rendered = render(<StructureGrantCartUserSelector />, {
196
+ state: {
197
+ grantRequestsCart: {
198
+ modificationGrant: {
199
+ user_group_id: 10,
200
+ user_group: { id: 10, name: "foo", alias: "bar" },
201
+ user_id: null,
202
+ },
203
+ },
204
+ },
205
+ dispatch,
206
+ });
207
+ await waitForLoad(rendered);
208
+
209
+ await waitFor(() => {
210
+ const payloads = dispatch.mock.calls.map(
211
+ ([action]) => action?.payload ?? action,
212
+ );
213
+ expect(payloads.some((payload) => payload?.user_group_id === 10)).toBe(
214
+ true,
215
+ );
216
+ });
217
+ });
218
+
219
+ it("shows group alias in the modification header", async () => {
220
+ const rendered = render(<StructureGrantCartUserSelector />, {
221
+ state: {
222
+ grantRequestsCart: {
223
+ modificationGrant: {
224
+ user_group_id: 10,
225
+ user_group: { id: 10, alias: "bar", name: "foo" },
226
+ user_id: null,
227
+ },
228
+ },
229
+ },
230
+ messages: {
231
+ en: {
232
+ "grantRequestCart.user.label": "Request for:",
233
+ },
234
+ },
235
+ });
236
+ await waitForLoad(rendered);
237
+
238
+ expect(rendered.getByText(/bar/i)).toBeInTheDocument();
239
+ expect(rendered.queryByText(/undefined/i)).not.toBeInTheDocument();
240
+ });
241
+
242
+ it("shows group name in the modification header when alias is empty", async () => {
243
+ const rendered = render(<StructureGrantCartUserSelector />, {
244
+ state: {
245
+ grantRequestsCart: {
246
+ modificationGrant: {
247
+ user_group_id: 10,
248
+ user_group: { id: 10, alias: "", name: "foo" },
249
+ user_id: null,
250
+ },
251
+ },
252
+ },
253
+ messages: {
254
+ en: {
255
+ "grantRequestCart.user.label": "Request for:",
256
+ },
257
+ },
258
+ });
259
+ await waitForLoad(rendered);
260
+
261
+ expect(rendered.getByText(/foo/i)).toBeInTheDocument();
262
+ expect(rendered.queryByText(/bar/i)).not.toBeInTheDocument();
263
+ expect(rendered.queryByText(/undefined/i)).not.toBeInTheDocument();
264
+ });
265
+
266
+ it("shows deleted group in the modification header when the group is missing", async () => {
267
+ const rendered = render(<StructureGrantCartUserSelector />, {
268
+ state: {
269
+ grantRequestsCart: {
270
+ modificationGrant: {
271
+ user_group_id: 10,
272
+ user_group: null,
273
+ user_id: null,
274
+ },
275
+ },
276
+ },
277
+ messages: {
278
+ en: {
279
+ "grantRequestCart.user.label": "Request for:",
280
+ "deleted.group": "Deleted group",
281
+ },
282
+ },
283
+ });
284
+ await waitForLoad(rendered);
285
+
286
+ expect(rendered.getByText(/deleted group/i)).toBeInTheDocument();
287
+ expect(rendered.queryByText(/undefined/i)).not.toBeInTheDocument();
288
+ });
289
+
290
+ it("shows user full name in the modification header for a personal grant", async () => {
291
+ const rendered = render(<StructureGrantCartUserSelector />, {
292
+ state: {
293
+ grantRequestsCart: {
294
+ modificationGrant: {
295
+ user: { full_name: "foo user" },
296
+ },
297
+ },
298
+ },
299
+ messages: {
300
+ en: {
301
+ "grantRequestCart.user.label": "Request for:",
302
+ },
303
+ },
304
+ });
305
+ await waitForLoad(rendered);
306
+
307
+ expect(rendered.getByText(/foo user/i)).toBeInTheDocument();
308
+ expect(rendered.queryByText(/undefined/i)).not.toBeInTheDocument();
309
+ });
182
310
  });
@@ -276,4 +276,96 @@ describe("<StructureGrantDropdown />", () => {
276
276
  rendered.getByText(/grant.actions.viewrequest.confirmation.header/i),
277
277
  ).toBeInTheDocument();
278
278
  });
279
+
280
+ it("shows users icon and change action for active group grant", async () => {
281
+ const user = userEvent.setup({ delay: null });
282
+ const grant = {
283
+ pending_removal: false,
284
+ user_group_id: 10,
285
+ user_group: { id: 10, name: "foo", alias: "bar" },
286
+ };
287
+ const props = {
288
+ ...propsBuilder(grant),
289
+ grantRequest: null,
290
+ grantRequestStatus: null,
291
+ };
292
+ const rendered = render(<StructureGrantDropdown {...props} />);
293
+ await waitForLoad(rendered);
294
+
295
+ expect(
296
+ rendered.container.querySelector(".button.group-actions .users.icon"),
297
+ ).not.toBeInTheDocument();
298
+
299
+ fireEvent.mouseOver(await rendered.findByRole("listbox"));
300
+ expect(
301
+ await rendered.findByText(/structure.grant.has_grant/i),
302
+ ).toBeInTheDocument();
303
+ expect(
304
+ rendered.baseElement.querySelector(".users.icon"),
305
+ ).toBeInTheDocument();
306
+
307
+ await user.click(await rendered.findByRole("listbox"));
308
+ expect(
309
+ rendered.getByText(/structure.grant.request_grant_change/i),
310
+ ).toBeInTheDocument();
311
+ });
312
+
313
+ it("shows users icon in popup for pending group grant request", async () => {
314
+ const grantRequest = {
315
+ group: {
316
+ user_group_id: 10,
317
+ _embedded: {
318
+ user_group: { id: 10, name: "foo" },
319
+ },
320
+ },
321
+ };
322
+ const props = {
323
+ ...propsBuilder(null),
324
+ grantRequest,
325
+ grantRequestStatus: "pending",
326
+ };
327
+ const rendered = render(<StructureGrantDropdown {...props} />, {
328
+ state: { authentication: { user_name: "foo" } },
329
+ });
330
+ await waitForLoad(rendered);
331
+
332
+ expect(
333
+ rendered.container.querySelector(".button.group-actions .users.icon"),
334
+ ).not.toBeInTheDocument();
335
+
336
+ fireEvent.mouseOver(await rendered.findByRole("listbox"));
337
+ expect(
338
+ await rendered.findByText(/structure.grant.requested_access/i),
339
+ ).toBeInTheDocument();
340
+ expect(
341
+ rendered.baseElement.querySelector(".users.icon"),
342
+ ).toBeInTheDocument();
343
+ });
344
+
345
+ it("shows users icon in popup for active group grant", async () => {
346
+ const grant = {
347
+ pending_removal: false,
348
+ user_group_id: 10,
349
+ user_group: { id: 10, name: "foo", alias: "bar" },
350
+ };
351
+ const props = {
352
+ ...propsBuilder(grant),
353
+ grantRequest: null,
354
+ grantRequestStatus: null,
355
+ };
356
+ const rendered = render(<StructureGrantDropdown {...props} />);
357
+ await waitForLoad(rendered);
358
+
359
+ expect(
360
+ rendered.container.querySelector(".button.group-actions .users.icon"),
361
+ ).not.toBeInTheDocument();
362
+
363
+ fireEvent.mouseOver(await rendered.findByRole("listbox"));
364
+ expect(
365
+ await rendered.findByText(/structure.grant.has_grant/i),
366
+ ).toBeInTheDocument();
367
+ expect(
368
+ rendered.baseElement.querySelector(".users.icon"),
369
+ ).toBeInTheDocument();
370
+ });
279
371
  });
@@ -1,4 +1,5 @@
1
1
  import userEvent from "@testing-library/user-event";
2
+ import { fireEvent } from "@testing-library/react";
2
3
  import { render, waitForLoad } from "@truedat/test/render";
3
4
  import SearchContextWrapper from "@truedat/core/components/common/SearchContextWrapper";
4
5
  import StructureGrantListButton from "../StructureGrantListButton";
@@ -117,4 +118,73 @@ describe("<StructureGrantListButton />", () => {
117
118
  onSuccess();
118
119
  expect(refreshSearch).toHaveBeenCalled();
119
120
  });
121
+
122
+ it("shows users icon in popup for group grant in my_grants", async () => {
123
+ const groupStructure = {
124
+ ...structure,
125
+ my_grants: [
126
+ {
127
+ id: 2,
128
+ user_group_id: 10,
129
+ user_group: { id: 10, name: "foo" },
130
+ },
131
+ ],
132
+ };
133
+
134
+ const rendered = render(
135
+ <SearchContextWrapper props={searchProps}>
136
+ <StructureGrantListButton structure={groupStructure} />
137
+ </SearchContextWrapper>,
138
+ renderOpts,
139
+ );
140
+ await waitForLoad(rendered);
141
+
142
+ expect(
143
+ rendered.container.querySelector(".button.group-actions .users.icon"),
144
+ ).not.toBeInTheDocument();
145
+
146
+ fireEvent.mouseOver(await rendered.findByRole("listbox"));
147
+ expect(
148
+ await rendered.findByText(/structure.grant.has_grant/i),
149
+ ).toBeInTheDocument();
150
+ expect(
151
+ rendered.baseElement.querySelector(".users.icon"),
152
+ ).toBeInTheDocument();
153
+ });
154
+
155
+ it("shows users icon in popup for pending group grant request in my_grant_request", async () => {
156
+ const pendingGroupStructure = {
157
+ ...structure,
158
+ my_grant_request: {
159
+ status: "pending",
160
+ _embedded: { group: { user_group_id: 10 } },
161
+ },
162
+ };
163
+
164
+ const rendered = render(
165
+ <SearchContextWrapper props={searchProps}>
166
+ <StructureGrantListButton structure={pendingGroupStructure} />
167
+ </SearchContextWrapper>,
168
+ {
169
+ ...renderOpts,
170
+ state: {
171
+ ...renderOpts.state,
172
+ authentication: { user_name: "foo" },
173
+ },
174
+ },
175
+ );
176
+ await waitForLoad(rendered);
177
+
178
+ expect(
179
+ rendered.container.querySelector(".button.group-actions .users.icon"),
180
+ ).not.toBeInTheDocument();
181
+
182
+ fireEvent.mouseOver(await rendered.findByRole("listbox"));
183
+ expect(
184
+ await rendered.findByText(/structure.grant.requested_access/i),
185
+ ).toBeInTheDocument();
186
+ expect(
187
+ rendered.baseElement.querySelector(".users.icon"),
188
+ ).toBeInTheDocument();
189
+ });
120
190
  });