@redacto.io/consent-sdk-react 10.0.0-beta.11 → 10.0.0-beta.12

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 (259) hide show
  1. package/NOTICE.md +17 -0
  2. package/README.md +67 -3
  3. package/dist/chunk-FEGTW73Q.mjs +182 -0
  4. package/dist/fonts.d.mts +35 -0
  5. package/dist/fonts.d.ts +35 -0
  6. package/dist/fonts.js +183 -0
  7. package/dist/fonts.mjs +10 -0
  8. package/dist/index.d.mts +12 -1
  9. package/dist/index.d.ts +12 -1
  10. package/dist/index.js +613 -249
  11. package/dist/index.mjs +235 -85
  12. package/dist/montserrat.generated-NBTECYRW.mjs +22 -0
  13. package/dist/types-6Aj7faxL.d.mts +57 -0
  14. package/dist/types-6Aj7faxL.d.ts +57 -0
  15. package/package.json +10 -1
  16. package/.turbo/turbo-build.log +0 -22
  17. package/.turbo/turbo-test.log +0 -203
  18. package/.turbo/turbo-verify-pack.log +0 -6
  19. package/CHANGELOG.md +0 -383
  20. package/src/RedactoNoticeAssisted/RedactoNoticeAssisted.test.tsx +0 -934
  21. package/src/RedactoNoticeAssisted/RedactoNoticeAssisted.tsx +0 -2160
  22. package/src/RedactoNoticeAssisted/api/index.ts +0 -275
  23. package/src/RedactoNoticeAssisted/api/types.ts +0 -182
  24. package/src/RedactoNoticeAssisted/assets/redacto-logo.png +0 -0
  25. package/src/RedactoNoticeAssisted/constants.ts +0 -51
  26. package/src/RedactoNoticeAssisted/i18n.ts +0 -1408
  27. package/src/RedactoNoticeAssisted/index.ts +0 -1
  28. package/src/RedactoNoticeAssisted/injectStyles.ts +0 -251
  29. package/src/RedactoNoticeAssisted/styles.ts +0 -730
  30. package/src/RedactoNoticeAssisted/types.ts +0 -26
  31. package/src/RedactoNoticeAssisted/useMediaQuery.ts +0 -36
  32. package/src/RedactoNoticeConsent/RedactoNoticeConsent.test.tsx +0 -1186
  33. package/src/RedactoNoticeConsent/RedactoNoticeConsent.tsx +0 -4299
  34. package/src/RedactoNoticeConsent/api/index.ts +0 -486
  35. package/src/RedactoNoticeConsent/api/sandbox.ts +0 -150
  36. package/src/RedactoNoticeConsent/api/types.ts +0 -505
  37. package/src/RedactoNoticeConsent/assets/redacto-logo.png +0 -0
  38. package/src/RedactoNoticeConsent/components/DigiLockerCallback.tsx +0 -602
  39. package/src/RedactoNoticeConsent/components/index.ts +0 -7
  40. package/src/RedactoNoticeConsent/constants.ts +0 -20
  41. package/src/RedactoNoticeConsent/index.ts +0 -1
  42. package/src/RedactoNoticeConsent/injectStyles.ts +0 -151
  43. package/src/RedactoNoticeConsent/language-codes.ts +0 -95
  44. package/src/RedactoNoticeConsent/services/storage.ts +0 -122
  45. package/src/RedactoNoticeConsent/styles.ts +0 -409
  46. package/src/RedactoNoticeConsent/types.ts +0 -80
  47. package/src/RedactoNoticeConsent/useMediaQuery.ts +0 -36
  48. package/src/RedactoNoticeConsentInline/RedactoNoticeConsentInline.test.tsx +0 -369
  49. package/src/RedactoNoticeConsentInline/RedactoNoticeConsentInline.tsx +0 -709
  50. package/src/RedactoNoticeConsentInline/api/index.ts +0 -115
  51. package/src/RedactoNoticeConsentInline/api/notice-read-routing.test.ts +0 -72
  52. package/src/RedactoNoticeConsentInline/api/types.ts +0 -185
  53. package/src/RedactoNoticeConsentInline/assets/redacto-logo.png +0 -0
  54. package/src/RedactoNoticeConsentInline/index.ts +0 -1
  55. package/src/RedactoNoticeConsentInline/injectStyles.ts +0 -40
  56. package/src/RedactoNoticeConsentInline/styles.ts +0 -397
  57. package/src/RedactoNoticeConsentInline/types.ts +0 -51
  58. package/src/RedactoNoticeConsentInline/useMediaQuery.ts +0 -36
  59. package/src/RedactoPrivacyCenter/NotificationsPage.tsx +0 -182
  60. package/src/RedactoPrivacyCenter/PrivacyCenterActivityPage.tsx +0 -19
  61. package/src/RedactoPrivacyCenter/PrivacyCenterCaseDetailsPage.tsx +0 -156
  62. package/src/RedactoPrivacyCenter/PrivacyCenterConsentManagerPage.tsx +0 -17
  63. package/src/RedactoPrivacyCenter/PrivacyCenterFormPage.tsx +0 -79
  64. package/src/RedactoPrivacyCenter/PrivacyCenterHomePage.tsx +0 -36
  65. package/src/RedactoPrivacyCenter/PrivacyCenterLayout.tsx +0 -177
  66. package/src/RedactoPrivacyCenter/PrivacyCenterMyReceiptPage.tsx +0 -26
  67. package/src/RedactoPrivacyCenter/RedactoPrivacyCenter.tsx +0 -93
  68. package/src/RedactoPrivacyCenter/api/actions.ts +0 -682
  69. package/src/RedactoPrivacyCenter/api/client.ts +0 -1003
  70. package/src/RedactoPrivacyCenter/api/config.ts +0 -33
  71. package/src/RedactoPrivacyCenter/api/fetcher.ts +0 -275
  72. package/src/RedactoPrivacyCenter/api/orgBranding.ts +0 -16
  73. package/src/RedactoPrivacyCenter/api/upload.ts +0 -93
  74. package/src/RedactoPrivacyCenter/assets/character.svg +0 -31
  75. package/src/RedactoPrivacyCenter/assets/fileAttach.svg +0 -9
  76. package/src/RedactoPrivacyCenter/assets/greenTick.svg +0 -4
  77. package/src/RedactoPrivacyCenter/assets/mail.svg +0 -3
  78. package/src/RedactoPrivacyCenter/assets/poweredByRedacto.svg +0 -9
  79. package/src/RedactoPrivacyCenter/assets/sentImg.svg +0 -9
  80. package/src/RedactoPrivacyCenter/assets/uploadFileIcon.svg +0 -9
  81. package/src/RedactoPrivacyCenter/components/ActivitiesList.tsx +0 -252
  82. package/src/RedactoPrivacyCenter/components/ActivityTimeline.tsx +0 -239
  83. package/src/RedactoPrivacyCenter/components/AppShell/AppShell.tsx +0 -268
  84. package/src/RedactoPrivacyCenter/components/AppShell/MobileNavDrawer.tsx +0 -218
  85. package/src/RedactoPrivacyCenter/components/AppShell/NavItem.tsx +0 -205
  86. package/src/RedactoPrivacyCenter/components/AppShell/PageHeader.tsx +0 -107
  87. package/src/RedactoPrivacyCenter/components/AppShell/SidebarNav.tsx +0 -100
  88. package/src/RedactoPrivacyCenter/components/AppShell/TopAppBar.tsx +0 -339
  89. package/src/RedactoPrivacyCenter/components/AppShell/UserMenu.tsx +0 -245
  90. package/src/RedactoPrivacyCenter/components/AppShell/hooks/useIsTruncated.ts +0 -28
  91. package/src/RedactoPrivacyCenter/components/AppShell/hooks/useKeyboardShortcut.ts +0 -40
  92. package/src/RedactoPrivacyCenter/components/AppShell/hooks/useSidebarState.ts +0 -62
  93. package/src/RedactoPrivacyCenter/components/AppShell/usePrivacyCenterExitAction.ts +0 -36
  94. package/src/RedactoPrivacyCenter/components/CaseDetails/AttachmentCard.tsx +0 -38
  95. package/src/RedactoPrivacyCenter/components/CaseDetails/ChatBubble.tsx +0 -31
  96. package/src/RedactoPrivacyCenter/components/CaseDetails/DocumentRequestCard.tsx +0 -79
  97. package/src/RedactoPrivacyCenter/components/CaseDetails/FinalizedTooltipWrapper.tsx +0 -25
  98. package/src/RedactoPrivacyCenter/components/CaseDetails/MessageComposer.tsx +0 -96
  99. package/src/RedactoPrivacyCenter/components/CaseDetails/MessageItem.tsx +0 -97
  100. package/src/RedactoPrivacyCenter/components/CaseDetails/MessagesTab.tsx +0 -156
  101. package/src/RedactoPrivacyCenter/components/CaseDetails/RequestDetailsTab.tsx +0 -171
  102. package/src/RedactoPrivacyCenter/components/CaseDetails/StatusEvent.tsx +0 -23
  103. package/src/RedactoPrivacyCenter/components/CaseDetails/useFileUpload.ts +0 -116
  104. package/src/RedactoPrivacyCenter/components/CaseDetails/useMessagePolling.ts +0 -43
  105. package/src/RedactoPrivacyCenter/components/CaseDetails/utils.ts +0 -71
  106. package/src/RedactoPrivacyCenter/components/CaseDetailsModal.tsx +0 -469
  107. package/src/RedactoPrivacyCenter/components/CaseHistory.tsx +0 -426
  108. package/src/RedactoPrivacyCenter/components/ConsentManager.tsx +0 -1199
  109. package/src/RedactoPrivacyCenter/components/ConsentManagerCells.tsx +0 -201
  110. package/src/RedactoPrivacyCenter/components/ConsentManagerColumns.tsx +0 -138
  111. package/src/RedactoPrivacyCenter/components/ConsentManagerConstants.ts +0 -7
  112. package/src/RedactoPrivacyCenter/components/ConsentManagerExpandedRow.tsx +0 -179
  113. package/src/RedactoPrivacyCenter/components/ConsentManagerGroupedColumns.tsx +0 -318
  114. package/src/RedactoPrivacyCenter/components/ConsentManagerProductCards.tsx +0 -333
  115. package/src/RedactoPrivacyCenter/components/ConsentManagerPurposeCards.tsx +0 -102
  116. package/src/RedactoPrivacyCenter/components/ConsentManagerTableSkeleton.tsx +0 -159
  117. package/src/RedactoPrivacyCenter/components/DataRequest/CorrectionDataSection.tsx +0 -189
  118. package/src/RedactoPrivacyCenter/components/DataRequest/GrievanceDataSection.tsx +0 -118
  119. package/src/RedactoPrivacyCenter/components/DataRequest/NominationDataSection.tsx +0 -66
  120. package/src/RedactoPrivacyCenter/components/DataRequest/ProductSelectionSection.tsx +0 -222
  121. package/src/RedactoPrivacyCenter/components/DataRequest/PurposeSelectionSection.tsx +0 -331
  122. package/src/RedactoPrivacyCenter/components/Form.tsx +0 -1821
  123. package/src/RedactoPrivacyCenter/components/GrievanceTable.tsx +0 -174
  124. package/src/RedactoPrivacyCenter/components/GrievanceTablePagination.tsx +0 -337
  125. package/src/RedactoPrivacyCenter/components/ModifyConsentModal.tsx +0 -334
  126. package/src/RedactoPrivacyCenter/components/NotificationHub/NotificationBell.tsx +0 -173
  127. package/src/RedactoPrivacyCenter/components/NotificationHub/NotificationCTAButton.tsx +0 -18
  128. package/src/RedactoPrivacyCenter/components/NotificationHub/NotificationDropdown.tsx +0 -54
  129. package/src/RedactoPrivacyCenter/components/NotificationHub/NotificationDropdownItem.tsx +0 -57
  130. package/src/RedactoPrivacyCenter/components/NotificationHub/NotificationIcon.tsx +0 -19
  131. package/src/RedactoPrivacyCenter/components/NotificationHub/NotificationListPanel.tsx +0 -92
  132. package/src/RedactoPrivacyCenter/components/NotificationHub/NotificationRefreshButton.tsx +0 -20
  133. package/src/RedactoPrivacyCenter/components/NotificationHub/NotificationRow.tsx +0 -58
  134. package/src/RedactoPrivacyCenter/components/NotificationHub/StatCard.tsx +0 -10
  135. package/src/RedactoPrivacyCenter/components/NotificationHub/useNotificationActions.ts +0 -112
  136. package/src/RedactoPrivacyCenter/components/NotificationHub/utils.ts +0 -27
  137. package/src/RedactoPrivacyCenter/components/Pagination.tsx +0 -140
  138. package/src/RedactoPrivacyCenter/components/PrivacyCenterEmptyState.tsx +0 -76
  139. package/src/RedactoPrivacyCenter/components/PrivacyCenterSessionExpired.tsx +0 -97
  140. package/src/RedactoPrivacyCenter/components/ReceiptsList.tsx +0 -454
  141. package/src/RedactoPrivacyCenter/components/RequestSubmit.tsx +0 -270
  142. package/src/RedactoPrivacyCenter/components/SelectUser.tsx +0 -95
  143. package/src/RedactoPrivacyCenter/components/SelectUserGate.tsx +0 -195
  144. package/src/RedactoPrivacyCenter/components/SideMenuBarPC/constants.tsx +0 -25
  145. package/src/RedactoPrivacyCenter/components/SideMenuBarPC/types.ts +0 -21
  146. package/src/RedactoPrivacyCenter/components/caseHistoryColumns.tsx +0 -159
  147. package/src/RedactoPrivacyCenter/components/constant.ts +0 -52
  148. package/src/RedactoPrivacyCenter/components/groupHelpers.ts +0 -155
  149. package/src/RedactoPrivacyCenter/components/receiptColumns.tsx +0 -203
  150. package/src/RedactoPrivacyCenter/components/types.ts +0 -123
  151. package/src/RedactoPrivacyCenter/components/utils.tsx +0 -10
  152. package/src/RedactoPrivacyCenter/config/routes.ts +0 -9
  153. package/src/RedactoPrivacyCenter/config/table.ts +0 -25
  154. package/src/RedactoPrivacyCenter/context/AuthContext.tsx +0 -252
  155. package/src/RedactoPrivacyCenter/context/BaseUrlContext.tsx +0 -47
  156. package/src/RedactoPrivacyCenter/context/BrandingContext.tsx +0 -52
  157. package/src/RedactoPrivacyCenter/context/DataAvailabilityContext.session-expired.test.tsx +0 -92
  158. package/src/RedactoPrivacyCenter/context/DataAvailabilityContext.tsx +0 -181
  159. package/src/RedactoPrivacyCenter/context/LocaleContext.tsx +0 -11
  160. package/src/RedactoPrivacyCenter/context/NavigationContext.tsx +0 -96
  161. package/src/RedactoPrivacyCenter/context/OrganizationContext.tsx +0 -30
  162. package/src/RedactoPrivacyCenter/context/PageChromeContext.tsx +0 -80
  163. package/src/RedactoPrivacyCenter/context/ProfileSwitchContext.tsx +0 -15
  164. package/src/RedactoPrivacyCenter/context/types.ts +0 -57
  165. package/src/RedactoPrivacyCenter/lib/api.ts +0 -759
  166. package/src/RedactoPrivacyCenter/lib/consent-manager/utils.tsx +0 -67
  167. package/src/RedactoPrivacyCenter/lib/constants.ts +0 -283
  168. package/src/RedactoPrivacyCenter/lib/i18n.ts +0 -81
  169. package/src/RedactoPrivacyCenter/lib/locales.ts +0 -102
  170. package/src/RedactoPrivacyCenter/lib/queries.ts +0 -141
  171. package/src/RedactoPrivacyCenter/lib/sandbox.ts +0 -104
  172. package/src/RedactoPrivacyCenter/lib/types.ts +0 -892
  173. package/src/RedactoPrivacyCenter/lib/useCurrentLanguage.ts +0 -37
  174. package/src/RedactoPrivacyCenter/lib/utils.refresh-circuit.test.ts +0 -127
  175. package/src/RedactoPrivacyCenter/lib/utils.refresh-storage.test.ts +0 -85
  176. package/src/RedactoPrivacyCenter/lib/utils.session-expired.test.ts +0 -109
  177. package/src/RedactoPrivacyCenter/lib/utils.ts +0 -798
  178. package/src/RedactoPrivacyCenter/locales/as/translation.json +0 -340
  179. package/src/RedactoPrivacyCenter/locales/bn/translation.json +0 -340
  180. package/src/RedactoPrivacyCenter/locales/brx/translation.json +0 -340
  181. package/src/RedactoPrivacyCenter/locales/doi/translation.json +0 -340
  182. package/src/RedactoPrivacyCenter/locales/en/translation.json +0 -355
  183. package/src/RedactoPrivacyCenter/locales/gom/translation.json +0 -340
  184. package/src/RedactoPrivacyCenter/locales/gu/translation.json +0 -340
  185. package/src/RedactoPrivacyCenter/locales/hi/translation.json +0 -343
  186. package/src/RedactoPrivacyCenter/locales/kn/translation.json +0 -340
  187. package/src/RedactoPrivacyCenter/locales/ks/translation.json +0 -340
  188. package/src/RedactoPrivacyCenter/locales/mai/translation.json +0 -340
  189. package/src/RedactoPrivacyCenter/locales/ml/translation.json +0 -340
  190. package/src/RedactoPrivacyCenter/locales/mni-Mtei/translation.json +0 -340
  191. package/src/RedactoPrivacyCenter/locales/mr/translation.json +0 -340
  192. package/src/RedactoPrivacyCenter/locales/ne/translation.json +0 -340
  193. package/src/RedactoPrivacyCenter/locales/or/translation.json +0 -340
  194. package/src/RedactoPrivacyCenter/locales/pa/translation.json +0 -340
  195. package/src/RedactoPrivacyCenter/locales/sa/translation.json +0 -340
  196. package/src/RedactoPrivacyCenter/locales/sat/translation.json +0 -340
  197. package/src/RedactoPrivacyCenter/locales/sd/translation.json +0 -340
  198. package/src/RedactoPrivacyCenter/locales/ta/translation.json +0 -340
  199. package/src/RedactoPrivacyCenter/locales/te/translation.json +0 -340
  200. package/src/RedactoPrivacyCenter/locales/ur/translation.json +0 -340
  201. package/src/RedactoPrivacyCenter/styles/applyBrandingTheme.ts +0 -66
  202. package/src/RedactoPrivacyCenter/styles/base.css +0 -117
  203. package/src/RedactoPrivacyCenter/styles/injectStyles.ts +0 -3108
  204. package/src/RedactoPrivacyCenter/styles/pcStyles.ts +0 -831
  205. package/src/RedactoPrivacyCenter/styles/responsive.ts +0 -138
  206. package/src/RedactoPrivacyCenter/styles/variables.css +0 -96
  207. package/src/RedactoPrivacyCenter/table/AdvancedTable.tsx +0 -387
  208. package/src/RedactoPrivacyCenter/table/AdvancedTablePagination.tsx +0 -468
  209. package/src/RedactoPrivacyCenter/table/index.ts +0 -2
  210. package/src/RedactoPrivacyCenter/types/images.d.ts +0 -29
  211. package/src/RedactoPrivacyCenter/ui/Footer.tsx +0 -69
  212. package/src/RedactoPrivacyCenter/ui/FormBlockWrapper.tsx +0 -54
  213. package/src/RedactoPrivacyCenter/ui/PCAccordion.tsx +0 -93
  214. package/src/RedactoPrivacyCenter/ui/PCActionIcon.tsx +0 -47
  215. package/src/RedactoPrivacyCenter/ui/PCAvatar.test.tsx +0 -83
  216. package/src/RedactoPrivacyCenter/ui/PCAvatar.tsx +0 -93
  217. package/src/RedactoPrivacyCenter/ui/PCBadge.tsx +0 -48
  218. package/src/RedactoPrivacyCenter/ui/PCButton.tsx +0 -77
  219. package/src/RedactoPrivacyCenter/ui/PCCheckbox.tsx +0 -55
  220. package/src/RedactoPrivacyCenter/ui/PCCollapse.tsx +0 -107
  221. package/src/RedactoPrivacyCenter/ui/PCEmpty.tsx +0 -35
  222. package/src/RedactoPrivacyCenter/ui/PCInput.tsx +0 -132
  223. package/src/RedactoPrivacyCenter/ui/PCLoader.tsx +0 -31
  224. package/src/RedactoPrivacyCenter/ui/PCModal.tsx +0 -106
  225. package/src/RedactoPrivacyCenter/ui/PCPopover.tsx +0 -206
  226. package/src/RedactoPrivacyCenter/ui/PCSelect.tsx +0 -433
  227. package/src/RedactoPrivacyCenter/ui/PCTable.tsx +0 -149
  228. package/src/RedactoPrivacyCenter/ui/PCText.tsx +0 -41
  229. package/src/RedactoPrivacyCenter/ui/PCTextarea.tsx +0 -43
  230. package/src/RedactoPrivacyCenter/ui/PCTitle.tsx +0 -37
  231. package/src/RedactoPrivacyCenter/ui/PCTooltip.tsx +0 -121
  232. package/src/RedactoPrivacyCenter/ui/SimpleBar.tsx +0 -25
  233. package/src/RedactoPrivacyCenter/ui/StatusBadge.tsx +0 -53
  234. package/src/RedactoPrivacyCenter/ui/index.ts +0 -18
  235. package/src/RedactoPrivacyCenter/utils/cn.ts +0 -28
  236. package/src/RedactoPrivacyCenter/utils/date.ts +0 -48
  237. package/src/RedactoPrivacyCenter/utils/status.ts +0 -111
  238. package/src/RedactoPrivacyCenter/utils/toast.ts +0 -130
  239. package/src/index.ts +0 -19
  240. package/src/privacy-center.ts +0 -113
  241. package/src/shared/api-errors.ts +0 -180
  242. package/src/shared/notice-consent-status.ts +0 -190
  243. package/src/shared/sandbox.ts +0 -6
  244. package/src/types/css.d.ts +0 -4
  245. package/src/types/images.d.ts +0 -19
  246. package/src/types/react-jsx.d.ts +0 -26
  247. package/tests/DataAvailabilityContext.test.tsx +0 -123
  248. package/tests/Form.test.tsx +0 -1424
  249. package/tests/ProductSelectionSection.test.tsx +0 -328
  250. package/tests/RequestSubmit.test.tsx +0 -135
  251. package/tests/RevokeWarningMessage.test.tsx +0 -151
  252. package/tests/consentClient.test.ts +0 -217
  253. package/tests/manageConsentServer.test.ts +0 -38
  254. package/tests/mocks.ts +0 -257
  255. package/tests/resolveContactFromJwt.test.ts +0 -44
  256. package/tests/setup.ts +0 -16
  257. package/tsconfig.json +0 -16
  258. package/tsup.config.ts +0 -31
  259. package/vitest.config.ts +0 -16
@@ -1,1424 +0,0 @@
1
- import { render, screen, fireEvent, waitFor, act, within } from '@testing-library/react';
2
- import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest';
3
-
4
- // ─── react-i18next stub ──────────────────────────────────────────────────────
5
- vi.mock('react-i18next', () => {
6
- const en: Record<string, string> = {
7
- raiseDataRequest: 'Raise a data request',
8
- contact: 'Contact',
9
- contactPlaceholder: 'Enter email',
10
- requestType: 'Request type',
11
- requestDetails: 'Request details',
12
- selectRequestType: 'Select request type',
13
- supportingDocumentation: 'Supporting documentation',
14
- confirmCheckBox: 'I confirm the details above are accurate',
15
- submit: 'Submit',
16
- cancel: 'Cancel',
17
- uploadFile: 'Upload file',
18
- uploadFileButton: 'Browse',
19
- description: 'Description',
20
- additionalNote: 'Additional note',
21
- reasonOptional: 'Reason (optional)',
22
- timePeriod: 'Time period',
23
- today: 'Today',
24
- last7Days: 'Last 7 days',
25
- last30Days: 'Last 30 days',
26
- last3Months: 'Last 3 months',
27
- access: 'access',
28
- correction: 'correction',
29
- erasure: 'erasure',
30
- grievance: 'grievance',
31
- nomination: 'nomination',
32
- forProduct: 'For {{productName}}',
33
- actingOnBehalfOfShort: 'acting on behalf of {{nominator}}',
34
- selectPurposesForThisProduct: 'Select purposes within this product.',
35
- selectProductsForRequest:
36
- 'Select a product for your {{requestType}} request',
37
- selectProductsForRequestGeneric: 'Select a product to continue',
38
- nominationChipSuffix: '· {{nominator}}',
39
- yourData: 'Your data',
40
- actingOnBehalfOf: 'Acting on behalf of {{nominator}}',
41
- activePurposes_one: '{{count}} purpose',
42
- activePurposes_other: '{{count}} purposes',
43
- autoSelected: 'Auto-selected',
44
- noProductsAvailable: 'No products available',
45
- noProductsAvailableDescription: 'You have no consents to manage yet.',
46
- requestSubmittedSuccess: 'Request submitted',
47
- requestSubmissionFailed: 'Request failed',
48
- submissionFailed: 'Submission failed',
49
- whatDataToAccess: 'What data to access',
50
- whatDataToDelete: 'What data to delete',
51
- selectAll: 'Select all',
52
- dataCollected: 'Data collected',
53
- revokeConsentNo: 'No',
54
- revokeConsentYes: 'Yes',
55
- revokeConsentModalTitle: 'Revoke consent?',
56
- revokeConsentModalQuestion: 'Do you also want to revoke consent?',
57
- revokeConsentModalPurposesLabel: 'Purposes',
58
- revokeConsentModalYourPurposes: 'Your purposes',
59
- revokeConsentModalIfYesLabel: 'If yes:',
60
- revokeConsentModalIfYesBody: 'Your consent will be revoked.',
61
- requestSubmittedSuccessfully: 'Request submitted successfully',
62
- thankYouForSubmittingYourRequest: 'Thanks',
63
- };
64
- const interpolate = (template: string, vars?: Record<string, unknown>) =>
65
- template.replace(/\{\{(\w+)\}\}/g, (_match, key: string) => {
66
- const value = vars?.[key];
67
- return value === undefined || value === null ? '' : String(value);
68
- });
69
- const t = (key: string, opts?: Record<string, unknown>) => {
70
- const count = typeof opts?.count === 'number' ? opts.count : undefined;
71
- const pluralKey =
72
- count !== undefined
73
- ? count === 1
74
- ? `${key}_one`
75
- : `${key}_other`
76
- : key;
77
- const template = en[pluralKey] ?? en[key] ?? key;
78
- return interpolate(template, opts);
79
- };
80
- return {
81
- useTranslation: () => ({
82
- t,
83
- i18n: { language: 'en', on: vi.fn(), off: vi.fn() },
84
- }),
85
- };
86
- });
87
-
88
- // ─── i18n module stub (used directly by Form.tsx for `on`/`off`) ─────────────
89
- vi.mock('../src/RedactoPrivacyCenter/lib/i18n', () => ({
90
- default: {
91
- language: 'en',
92
- on: vi.fn(),
93
- off: vi.fn(),
94
- },
95
- }));
96
-
97
- // ─── API stubs ───────────────────────────────────────────────────────────────
98
- // 1-form -> 1-case: only `createCaseRequest` is consumed by Form.tsx now.
99
- const createCaseRequest = vi.fn();
100
- const getFormData = vi.fn();
101
- const fetchUserConsents = vi.fn();
102
- vi.mock('../src/RedactoPrivacyCenter/lib/api', () => ({
103
- createCaseRequest: (...args: unknown[]) => createCaseRequest(...args),
104
- getFormData: (...args: unknown[]) => getFormData(...args),
105
- // Approach A sources the product picker from the ledger's user-consents.
106
- // Default to no ledger result so the form falls back to the getFormData
107
- // product groups these tests set up.
108
- fetchUserConsents: (...args: unknown[]) => fetchUserConsents(...args),
109
- }));
110
-
111
- // ─── upload stub ─────────────────────────────────────────────────────────────
112
- vi.mock('../src/RedactoPrivacyCenter/api/upload', () => ({
113
- uploadFileWithS2S: vi.fn(),
114
- }));
115
-
116
- // ─── tanstack/react-query stub ───────────────────────────────────────────────
117
- vi.mock('@tanstack/react-query', () => ({
118
- useQueryClient: () => ({ invalidateQueries: vi.fn() }),
119
- }));
120
-
121
- // ─── Toast stub ──────────────────────────────────────────────────────────────
122
- vi.mock('../src/RedactoPrivacyCenter/utils/toast', () => ({
123
- toast: {
124
- success: vi.fn(),
125
- error: vi.fn(),
126
- info: vi.fn(),
127
- },
128
- }));
129
-
130
- // ─── Auth / BaseUrl / Organization context stubs ─────────────────────────────
131
- // Stable references prevent identity churn from re-firing effects whose deps
132
- // include context-derived values (auth, consentClient, organization).
133
- vi.mock('../src/RedactoPrivacyCenter/context/AuthContext', () => {
134
- const auth = {
135
- accessToken: 'tok',
136
- refreshToken: 'rtok',
137
- onError: () => false,
138
- updateTokens: () => {},
139
- };
140
- return { useAuth: () => auth };
141
- });
142
-
143
- // Mutable so individual tests can drop `ledgerBaseUrl` to exercise the legacy
144
- // (no-ledger) mode; beforeEach restores the ledger default.
145
- const baseUrlStub = vi.hoisted(() => ({
146
- consentClient: { get: () => Promise.resolve(null), post: () => Promise.resolve(null) },
147
- baseUrl: 'https://consent.test',
148
- ledgerBaseUrl: 'https://ledger.test/consent-ledger' as string | undefined,
149
- }));
150
- vi.mock('../src/RedactoPrivacyCenter/context/BaseUrlContext', () => ({
151
- useBaseUrl: () => baseUrlStub,
152
- }));
153
-
154
- vi.mock('../src/RedactoPrivacyCenter/context/OrganizationContext', () => {
155
- const org = {
156
- organization: {
157
- uuid: 'org-uuid',
158
- slug: 'acme',
159
- name: 'Acme',
160
- workspaces: [{ uuid: 'ws-uuid' }],
161
- },
162
- };
163
- return { useOrganization: () => org };
164
- });
165
-
166
- // ─── Optional peer-dep icon libs: stub with concrete named exports.
167
- // `lucide-react` and `react-icons/*` are peer deps with no entry in the
168
- // package's own node_modules. Tests don't care about icon glyphs — we
169
- // stub every name imported by transitively-loaded SDK modules.
170
- vi.mock('lucide-react', () => {
171
- const S = () => null;
172
- return {
173
- X: S, ChevronDown: S, ChevronDownIcon: S, Check: S, Mail: S, Search: S,
174
- ArrowUpToLine: S, ArrowLeft: S, Filter: S, Circle: S, Smartphone: S,
175
- LaptopMinimal: S, ShieldCheck: S, Globe2: S, Menu: S, MessageCircleWarning: S,
176
- PanelLeftClose: S, PanelLeftOpen: S, LogOut: S, Activity: S, ReceiptText: S,
177
- };
178
- });
179
- vi.mock('react-icons/ai', () => ({ AiOutlineClose: () => null }));
180
- vi.mock('react-icons/pi', () => {
181
- const S = () => null;
182
- return {
183
- PiUploadBold: S, PiWarningCircleBold: S, PiCaretDownFill: S, PiCaretUpFill: S,
184
- };
185
- });
186
- vi.mock('react-icons/fi', () => {
187
- const S = () => null;
188
- return {
189
- FiAlertCircle: S, FiChevronDown: S, FiChevronUp: S, FiX: S,
190
- FiDownload: S, FiSearch: S, FiFilter: S,
191
- };
192
- });
193
- vi.mock('react-icons/io5', () => {
194
- const S = () => null;
195
- return {
196
- IoArrowBack: S, IoChevronBackOutline: S, IoAdd: S, IoAttach: S,
197
- IoDocumentText: S, IoNotificationsOutline: S, IoPersonOutline: S,
198
- IoRefresh: S, IoRefreshOutline: S, IoSend: S, IoTimeOutline: S,
199
- IoDocumentOutline: S, IoShieldCheckmarkOutline: S, IoAlertCircleOutline: S,
200
- IoSettingsOutline: S,
201
- };
202
- });
203
-
204
- // ─── PCSelect stub: replace at module source so the barrel re-export
205
- // picks up the stub. PCSelect uses lucide-react, which is fragile in
206
- // tests; stubbing also lets us drive it with a native <select>.
207
- vi.mock('../src/RedactoPrivacyCenter/ui/PCSelect', () => {
208
- type Option = { value: string | number; label: string };
209
- const PCSelect = ({
210
- options,
211
- value,
212
- onChange,
213
- label,
214
- disabled,
215
- }: {
216
- options: readonly Option[];
217
- value: Option | null;
218
- onChange?: (opt: Option | null) => void;
219
- label?: React.ReactNode;
220
- disabled?: boolean;
221
- }) => (
222
- <label>
223
- {typeof label === 'string' ? label : null}
224
- <select
225
- data-testid="pc-select"
226
- disabled={disabled}
227
- value={value ? String(value.value) : ''}
228
- onChange={(e) => {
229
- const opt = options.find((o) => String(o.value) === e.target.value);
230
- onChange?.(opt ?? null);
231
- }}
232
- >
233
- <option value="">--</option>
234
- {options.map((o) => (
235
- <option key={String(o.value)} value={String(o.value)}>
236
- {o.label}
237
- </option>
238
- ))}
239
- </select>
240
- </label>
241
- );
242
- return { PCSelect };
243
- });
244
-
245
- // ─── PCModal stub: render inline always when isOpen ──────────────────────────
246
- vi.mock('../src/RedactoPrivacyCenter/ui/PCModal', () => ({
247
- PCModal: ({
248
- isOpen,
249
- children,
250
- footer,
251
- }: {
252
- isOpen: boolean;
253
- children?: React.ReactNode;
254
- footer?: React.ReactNode;
255
- }) =>
256
- isOpen ? (
257
- <div data-testid="pc-modal">
258
- {children}
259
- {footer}
260
- </div>
261
- ) : null,
262
- }));
263
-
264
- // ─── Heavy/optional child stubs we don't want to exercise ────────────────────
265
- // CorrectionDataSection stub: light enough to render quickly, rich enough
266
- // for the per-product CORRECTION grouped-flow tests to drive selection
267
- // and value entry. Mirrors the real component's prop contract: a checkbox
268
- // per data-element plus two inputs (current / updated) per selected name.
269
- // Existing tests that don't interact with it still pass — they just see
270
- // an empty checklist when their request type isn't CORRECTION.
271
- vi.mock(
272
- '../src/RedactoPrivacyCenter/components/DataRequest/CorrectionDataSection',
273
- () => ({
274
- default: ({
275
- dataElements,
276
- selected,
277
- setSelected,
278
- correctionValues,
279
- setCorrectionValues,
280
- }: {
281
- dataElements: Array<{ uuid: string; name: string }>;
282
- selected: string[];
283
- setSelected: (values: string[]) => void;
284
- correctionValues: Record<
285
- string,
286
- { current: string; updated: string }
287
- >;
288
- setCorrectionValues: (
289
- values: Record<string, { current: string; updated: string }>,
290
- ) => void;
291
- }) => (
292
- <div data-testid="correction-section">
293
- {dataElements.map((de) => (
294
- <div key={de.uuid}>
295
- <label>
296
- <input
297
- type="checkbox"
298
- aria-label={`correction-de-${de.name}`}
299
- checked={selected.includes(de.name)}
300
- onChange={(e) =>
301
- setSelected(
302
- e.target.checked
303
- ? [...selected, de.name]
304
- : selected.filter((n) => n !== de.name),
305
- )
306
- }
307
- />
308
- {de.name}
309
- </label>
310
- {selected.includes(de.name) && (
311
- <>
312
- <input
313
- aria-label={`correction-current-${de.name}`}
314
- value={correctionValues[de.name]?.current ?? ''}
315
- onChange={(e) =>
316
- setCorrectionValues({
317
- ...correctionValues,
318
- [de.name]: {
319
- ...(correctionValues[de.name] ?? {
320
- current: '',
321
- updated: '',
322
- }),
323
- current: e.target.value,
324
- },
325
- })
326
- }
327
- />
328
- <input
329
- aria-label={`correction-updated-${de.name}`}
330
- value={correctionValues[de.name]?.updated ?? ''}
331
- onChange={(e) =>
332
- setCorrectionValues({
333
- ...correctionValues,
334
- [de.name]: {
335
- ...(correctionValues[de.name] ?? {
336
- current: '',
337
- updated: '',
338
- }),
339
- updated: e.target.value,
340
- },
341
- })
342
- }
343
- />
344
- </>
345
- )}
346
- </div>
347
- ))}
348
- </div>
349
- ),
350
- }),
351
- );
352
- vi.mock(
353
- '../src/RedactoPrivacyCenter/components/DataRequest/GrievanceDataSection',
354
- () => ({
355
- default: () => <div data-testid="grievance-section" />,
356
- }),
357
- );
358
- vi.mock(
359
- '../src/RedactoPrivacyCenter/components/DataRequest/NominationDataSection',
360
- () => ({
361
- // Test-only stub: exposes an email input that calls the real
362
- // `setNominationData` setter, so tests can drive the form to a
363
- // valid NOMINATION state and exercise the actual submit path
364
- // (not just the "button disabled" gate).
365
- default: ({ nominationData, setNominationData }: any) => (
366
- <div data-testid="nomination-section">
367
- <input
368
- data-testid="nominee-email-input"
369
- value={nominationData?.nominee_email ?? ''}
370
- onChange={(e) =>
371
- setNominationData((prev: any) => ({
372
- ...prev,
373
- nominee_email: e.target.value,
374
- }))
375
- }
376
- />
377
- </div>
378
- ),
379
- }),
380
- );
381
- vi.mock('../src/RedactoPrivacyCenter/components/RequestSubmit', () => ({
382
- default: ({
383
- result,
384
- }: {
385
- result: {
386
- case_id: string;
387
- uuid: string;
388
- product_uuid: string;
389
- product_name: string;
390
- };
391
- }) => (
392
- <div data-testid="request-submitted">
393
- <span data-testid="request-submitted-case-id">{result.case_id}</span>
394
- <span data-testid="request-submitted-product-uuid">
395
- {result.product_uuid}
396
- </span>
397
- <span data-testid="request-submitted-product-name">
398
- {result.product_name}
399
- </span>
400
- </div>
401
- ),
402
- }));
403
-
404
- // ─── Imports under test (must come after all vi.mock calls) ──────────────────
405
- import Form from '../src/RedactoPrivacyCenter/components/Form';
406
- import {
407
- RequestTypeEnum,
408
- type FormData,
409
- type FormProductGroup,
410
- } from '../src/RedactoPrivacyCenter/lib/types';
411
-
412
- const baseDataElement = (uuid: string, name: string) => ({
413
- uuid,
414
- name,
415
- description: '',
416
- enabled: true,
417
- required: false,
418
- given_consent: true,
419
- selected: true,
420
- });
421
-
422
- const basePurpose = (
423
- uuid: string,
424
- name: string,
425
- dataElements = [baseDataElement(`${uuid}-de1`, `${name}-data`)],
426
- ) => ({
427
- uuid,
428
- name,
429
- description: '',
430
- industries: '',
431
- selected: false,
432
- given_consent: true,
433
- data_elements: dataElements,
434
- });
435
-
436
- /**
437
- * Build a FormData stub.
438
- *
439
- * `formUuid` is the FormDataOut session uuid (a fresh uuid the backend
440
- * mints per call to `PrivacyCenterSDK._generate_uuid()`) — intentionally
441
- * distinct from any user / nominator ConsentUser uuid so tests catch
442
- * the regression where the SDK previously sent this as `data_principal_uuid`
443
- * on direct cards and the backend rejected it as `invalid_data_principal`.
444
- */
445
- const makeFormData = (
446
- overrides: Partial<FormData> = {},
447
- formUuid = 'form-session-uuid',
448
- ): FormData => ({
449
- uuid: formUuid,
450
- name: 'Jane Principal',
451
- contact: 'jane@example.com',
452
- grievance_options: [],
453
- purposes: [],
454
- direct_groups: [],
455
- nominated_groups: [],
456
- ...overrides,
457
- });
458
-
459
- const makeGroup = (
460
- overrides: Partial<FormProductGroup> = {},
461
- ): FormProductGroup => ({
462
- product_uuid: 'prod-1',
463
- product_name: 'Acme Loyalty',
464
- product_description: null,
465
- nominator: null,
466
- purposes: [basePurpose('purp-1', 'Marketing')],
467
- ...overrides,
468
- });
469
-
470
- const setupSession = (email = 'jane@example.com') => {
471
- sessionStorage.setItem('email', email);
472
- };
473
-
474
- const pickRequestType = (value: string) => {
475
- const select = screen.getByTestId('pc-select') as HTMLSelectElement;
476
- fireEvent.change(select, { target: { value } });
477
- };
478
-
479
- const clickProductChip = (groupKey: string) => {
480
- fireEvent.click(screen.getByTestId(`product-chip-${groupKey}`));
481
- };
482
-
483
- describe('Form (P2-SDK-3)', () => {
484
- beforeEach(() => {
485
- createCaseRequest.mockReset();
486
- getFormData.mockReset();
487
- fetchUserConsents.mockReset();
488
- baseUrlStub.ledgerBaseUrl = 'https://ledger.test/consent-ledger';
489
- sessionStorage.clear();
490
- });
491
-
492
- afterEach(() => {
493
- sessionStorage.clear();
494
- });
495
-
496
- it('blocks submit for product-scoped types when the DP has no consent groups', async () => {
497
- // 1-form -> 1-case -> 1-product means product-scoped request types
498
- // (ACCESS/ERASURE/CORRECTION) MUST have a product anchor. When the
499
- // DP has zero consent groups (direct + nominated), the picker shows
500
- // its empty state and submit must be hard-blocked at the validity
501
- // gate so the case can never be created without an anchor.
502
- setupSession();
503
- getFormData.mockResolvedValue(
504
- makeFormData({ direct_groups: [], nominated_groups: [] }),
505
- );
506
-
507
- render(<Form onCreateRequest={vi.fn()} />);
508
- await waitFor(() => expect(getFormData).toHaveBeenCalled());
509
-
510
- pickRequestType(RequestTypeEnum.ERASURE);
511
-
512
- // Confirm checkbox alone is not enough — the validity gate has to
513
- // see at least one product selected.
514
- const confirmCheckbox = (
515
- screen.getAllByRole('checkbox') as HTMLInputElement[]
516
- ).find((c) => c.closest('label')?.textContent?.includes('I confirm'));
517
- expect(confirmCheckbox).toBeTruthy();
518
- fireEvent.click(confirmCheckbox!);
519
-
520
- const submitButton = screen.getByRole(
521
- 'button',
522
- { name: /^submit$/i },
523
- ) as HTMLButtonElement;
524
- expect(submitButton.disabled).toBe(true);
525
- });
526
-
527
- it('runs the picker overlay against the legacy endpoint when no ledgerBaseUrl is configured', async () => {
528
- // `getUserConsents` serves the same grouped payload from either backend
529
- // (ledger `/public/...` or Python `/dsar/privacy-center/...`), so the
530
- // overlay must run in both modes — Python's form/data no longer emits
531
- // product groups, and skipping the read leaves the picker empty.
532
- baseUrlStub.ledgerBaseUrl = undefined;
533
- setupSession();
534
- fetchUserConsents.mockResolvedValue(null);
535
- getFormData.mockResolvedValue(
536
- makeFormData({
537
- direct_groups: [
538
- makeGroup(),
539
- makeGroup({
540
- product_uuid: 'prod-direct-2',
541
- product_name: 'Acme Rewards',
542
- purposes: [basePurpose('purp-2', 'Analytics')],
543
- }),
544
- ],
545
- }),
546
- );
547
-
548
- render(<Form onCreateRequest={vi.fn()} />);
549
- await waitFor(() => expect(getFormData).toHaveBeenCalled());
550
- await waitFor(() => expect(fetchUserConsents).toHaveBeenCalled());
551
-
552
- pickRequestType(RequestTypeEnum.ERASURE);
553
- await waitFor(() => {
554
- expect(screen.getByText('Acme Loyalty')).toBeInTheDocument();
555
- });
556
- });
557
-
558
- it('runs the ledger picker overlay when ledgerBaseUrl is configured', async () => {
559
- setupSession();
560
- getFormData.mockResolvedValue(
561
- makeFormData({ direct_groups: [makeGroup()] }),
562
- );
563
-
564
- render(<Form onCreateRequest={vi.fn()} />);
565
- await waitFor(() => expect(getFormData).toHaveBeenCalled());
566
-
567
- await waitFor(() => expect(fetchUserConsents).toHaveBeenCalled());
568
- });
569
-
570
- it('keeps the form/data groups when user-consents comes back with no groups', async () => {
571
- // A successful-but-empty read must never overwrite groups form/data did
572
- // supply — that turned a populated picker into "No products available".
573
- setupSession();
574
- fetchUserConsents.mockResolvedValue({ direct: [], nominated: [] });
575
- getFormData.mockResolvedValue(
576
- makeFormData({
577
- direct_groups: [
578
- makeGroup(),
579
- makeGroup({
580
- product_uuid: 'prod-direct-2',
581
- product_name: 'Acme Rewards',
582
- purposes: [basePurpose('purp-2', 'Analytics')],
583
- }),
584
- ],
585
- }),
586
- );
587
-
588
- render(<Form onCreateRequest={vi.fn()} />);
589
- await waitFor(() => expect(fetchUserConsents).toHaveBeenCalled());
590
-
591
- pickRequestType(RequestTypeEnum.ERASURE);
592
- await waitFor(() => {
593
- expect(screen.getByText('Acme Loyalty')).toBeInTheDocument();
594
- });
595
- expect(screen.getByText('Acme Rewards')).toBeInTheDocument();
596
- expect(screen.queryByText('No products available')).not.toBeInTheDocument();
597
- });
598
-
599
- it('falls back to the legacy flat purposes list when the backend exposes no product groups', async () => {
600
- // Pre-grouping backends return purposes without any product grouping.
601
- // Those consents must stay reachable under one synthetic group instead
602
- // of the picker claiming the principal has none.
603
- setupSession();
604
- fetchUserConsents.mockResolvedValue(null);
605
- getFormData.mockResolvedValue(
606
- makeFormData({
607
- direct_groups: [],
608
- nominated_groups: [],
609
- purposes: [{ purpose: basePurpose('purp-flat', 'Marketing') }],
610
- }),
611
- );
612
-
613
- render(<Form onCreateRequest={vi.fn()} />);
614
- await waitFor(() => expect(getFormData).toHaveBeenCalled());
615
-
616
- pickRequestType(RequestTypeEnum.ACCESS);
617
-
618
- await waitFor(() => {
619
- expect(screen.getByText('Your data')).toBeInTheDocument();
620
- });
621
- expect(screen.getByText('Marketing')).toBeInTheDocument();
622
- expect(screen.queryByText('No products available')).not.toBeInTheDocument();
623
- });
624
-
625
- it('keeps the empty state when the flat purposes carry no data elements', async () => {
626
- // Nothing selectable survives `buildGroupPurposes`, so the synthetic group
627
- // would render an unusable panel — the empty state is the honest answer.
628
- setupSession();
629
- fetchUserConsents.mockResolvedValue(null);
630
- getFormData.mockResolvedValue(
631
- makeFormData({
632
- direct_groups: [],
633
- nominated_groups: [],
634
- purposes: [{ purpose: basePurpose('purp-flat', 'Marketing', []) }],
635
- }),
636
- );
637
-
638
- render(<Form onCreateRequest={vi.fn()} />);
639
- await waitFor(() => expect(getFormData).toHaveBeenCalled());
640
-
641
- pickRequestType(RequestTypeEnum.ACCESS);
642
-
643
- await waitFor(() => {
644
- expect(screen.getByText('No products available')).toBeInTheDocument();
645
- });
646
- expect(screen.queryByText('Your data')).not.toBeInTheDocument();
647
- });
648
-
649
- it('submits the legacy flat fallback as an org-level case without a product anchor', async () => {
650
- // The synthetic group has no server-side product, so the case must go up
651
- // in the pre-grouping org-level shape rather than carrying a made-up
652
- // `product_uuid` the backend cannot resolve.
653
- setupSession();
654
- fetchUserConsents.mockResolvedValue(null);
655
- getFormData.mockResolvedValue(
656
- makeFormData({
657
- direct_groups: [],
658
- nominated_groups: [],
659
- purposes: [{ purpose: basePurpose('purp-flat', 'Marketing') }],
660
- }),
661
- );
662
- createCaseRequest.mockResolvedValueOnce({
663
- case_id: 'CASE-FLAT',
664
- uuid: 'uuid-flat',
665
- });
666
-
667
- render(<Form onCreateRequest={vi.fn()} />);
668
- await waitFor(() => expect(getFormData).toHaveBeenCalled());
669
-
670
- pickRequestType(RequestTypeEnum.ACCESS);
671
-
672
- await waitFor(() => {
673
- expect(screen.getByText('Marketing')).toBeInTheDocument();
674
- });
675
-
676
- const marketingCheckbox = screen
677
- .getByText('Marketing')
678
- .closest('label')
679
- ?.querySelector('input[type="checkbox"]') as HTMLInputElement | null;
680
- expect(marketingCheckbox).toBeTruthy();
681
- fireEvent.click(marketingCheckbox!);
682
-
683
- const confirmCheckbox = (
684
- screen.getAllByRole('checkbox') as HTMLInputElement[]
685
- ).find((c) => c.closest('label')?.textContent?.includes('I confirm'));
686
- expect(confirmCheckbox).toBeTruthy();
687
- fireEvent.click(confirmCheckbox!);
688
-
689
- const submitButton = screen.getByRole('button', { name: /^submit$/i });
690
- expect(submitButton).not.toBeDisabled();
691
- await act(async () => {
692
- fireEvent.click(submitButton);
693
- });
694
-
695
- await waitFor(() => expect(createCaseRequest).toHaveBeenCalledTimes(1));
696
-
697
- const payload = createCaseRequest.mock.calls[0][2];
698
- expect('product_uuid' in payload).toBe(false);
699
- expect('data_principal_uuid' in payload).toBe(false);
700
- expect(payload.request_details.purposes).toEqual([
701
- { purpose_uuid: 'purp-flat', data_element_uuids: ['purp-flat-de1'] },
702
- ]);
703
- });
704
-
705
- it('renders the product step for DSAR types when direct_groups is present', async () => {
706
- setupSession();
707
- const direct = makeGroup({
708
- product_uuid: 'prod-direct',
709
- product_name: 'Acme Loyalty',
710
- });
711
- const second = makeGroup({
712
- product_uuid: 'prod-direct-2',
713
- product_name: 'Acme Rewards',
714
- purposes: [basePurpose('purp-2', 'Analytics')],
715
- });
716
- getFormData.mockResolvedValue(
717
- makeFormData({ direct_groups: [direct, second] }),
718
- );
719
-
720
- render(<Form onCreateRequest={vi.fn()} />);
721
- await waitFor(() => expect(getFormData).toHaveBeenCalled());
722
-
723
- pickRequestType(RequestTypeEnum.ERASURE);
724
-
725
- await waitFor(() => {
726
- expect(screen.getByText('Acme Loyalty')).toBeInTheDocument();
727
- });
728
- expect(screen.getByText('Acme Rewards')).toBeInTheDocument();
729
- expect(
730
- screen.getByText(/Select a product for your erasure request/i),
731
- ).toBeInTheDocument();
732
- });
733
-
734
- it('skips the product selection step when only one consent group exists', async () => {
735
- // TECH-3712 UX: when the DP has exactly one consent group total
736
- // (direct + nominated combined), ProductSelectionSection is friction —
737
- // step 2 must not render at all. The lone group is auto-selected so
738
- // step 3 (per-product purpose picker) renders directly.
739
- setupSession();
740
- const soleGroup = makeGroup({
741
- product_uuid: 'prod-sole',
742
- product_name: 'Acme Loyalty',
743
- purposes: [basePurpose('purp-sole', 'Marketing')],
744
- });
745
- getFormData.mockResolvedValue(
746
- makeFormData({ direct_groups: [soleGroup], nominated_groups: [] }),
747
- );
748
-
749
- render(<Form onCreateRequest={vi.fn()} />);
750
- await waitFor(() => expect(getFormData).toHaveBeenCalled());
751
-
752
- pickRequestType(RequestTypeEnum.ERASURE);
753
-
754
- // Per-product card for the sole group should appear without the user
755
- // touching a product card (auto-selected at Form level).
756
- await waitFor(() => {
757
- expect(
758
- screen.getByTestId('per-product-purposes-prod-sole'),
759
- ).toBeInTheDocument();
760
- });
761
-
762
- // ProductSelectionSection itself must NOT render. The step-2 product
763
- // chip (data-testid `product-chip-prod-sole`) and the step-2 header
764
- // ("Select a product...") are both signals it rendered.
765
- expect(
766
- screen.queryByTestId('product-chip-prod-sole'),
767
- ).not.toBeInTheDocument();
768
- expect(
769
- screen.queryByText(/Select a product/i),
770
- ).not.toBeInTheDocument();
771
-
772
- // Step 3 (per-product purpose picker) is fully wired up: the purpose
773
- // checkbox is present and tickable.
774
- await waitFor(() => {
775
- expect(screen.getByText('Marketing')).toBeInTheDocument();
776
- });
777
- const marketingCheckbox = screen
778
- .getByText('Marketing')
779
- .closest('label')
780
- ?.querySelector('input[type="checkbox"]') as HTMLInputElement | null;
781
- expect(marketingCheckbox).toBeTruthy();
782
- });
783
-
784
- it('skips the product step for nomination and grievance', async () => {
785
- setupSession();
786
- const direct = makeGroup();
787
- getFormData.mockResolvedValue(
788
- makeFormData({
789
- direct_groups: [direct],
790
- grievance_options: [
791
- { value: 'consent_violation', label: 'Consent violation' },
792
- ],
793
- }),
794
- );
795
-
796
- render(<Form onCreateRequest={vi.fn()} />);
797
- await waitFor(() => expect(getFormData).toHaveBeenCalled());
798
-
799
- pickRequestType(RequestTypeEnum.GRIEVANCE);
800
-
801
- await waitFor(() => {
802
- expect(screen.getByTestId('grievance-section')).toBeInTheDocument();
803
- });
804
- expect(
805
- screen.queryByText(/Select a product/i),
806
- ).not.toBeInTheDocument();
807
-
808
- pickRequestType(RequestTypeEnum.NOMINATION);
809
-
810
- await waitFor(() => {
811
- expect(screen.getByTestId('nomination-section')).toBeInTheDocument();
812
- });
813
- expect(
814
- screen.queryByText(/Select a product/i),
815
- ).not.toBeInTheDocument();
816
- });
817
-
818
- it('fires one createCaseRequest with correct anchors on single-product erasure submit', async () => {
819
- setupSession();
820
- const directGroup = makeGroup({
821
- product_uuid: 'prod-direct',
822
- product_name: 'Acme Loyalty',
823
- purposes: [basePurpose('purp-direct', 'Marketing')],
824
- });
825
- const nominatedGroup = makeGroup({
826
- product_uuid: 'prod-nominated',
827
- product_name: 'Partner Bank',
828
- nominator: {
829
- uuid: 'nominator-uuid',
830
- org_user_id: 'org-user-1',
831
- name: 'Alice',
832
- email: 'alice@example.com',
833
- },
834
- purposes: [basePurpose('purp-nominated', 'Analytics')],
835
- });
836
- getFormData.mockResolvedValue(
837
- makeFormData({
838
- direct_groups: [directGroup],
839
- nominated_groups: [nominatedGroup],
840
- }),
841
- );
842
- createCaseRequest.mockResolvedValueOnce({
843
- case_id: 'CASE-1',
844
- uuid: 'uuid-1',
845
- });
846
-
847
- render(<Form onCreateRequest={vi.fn()} />);
848
- await waitFor(() => expect(getFormData).toHaveBeenCalled());
849
-
850
- pickRequestType(RequestTypeEnum.ERASURE);
851
-
852
- await waitFor(() =>
853
- expect(screen.getByText('Acme Loyalty')).toBeInTheDocument(),
854
- );
855
- clickProductChip('prod-direct');
856
-
857
- await waitFor(() => {
858
- expect(
859
- screen.getByTestId('per-product-purposes-prod-direct'),
860
- ).toBeInTheDocument();
861
- });
862
-
863
- const marketingCheckbox = screen
864
- .getByText('Marketing')
865
- .closest('label')
866
- ?.querySelector('input[type="checkbox"]') as HTMLInputElement | null;
867
- expect(marketingCheckbox).toBeTruthy();
868
- fireEvent.click(marketingCheckbox!);
869
-
870
- const allCheckboxes = screen.getAllByRole(
871
- 'checkbox',
872
- ) as HTMLInputElement[];
873
- const confirmCheckbox = allCheckboxes.find((c) =>
874
- c.closest('label')?.textContent?.includes('I confirm'),
875
- );
876
- expect(confirmCheckbox).toBeTruthy();
877
- fireEvent.click(confirmCheckbox!);
878
-
879
- const submitButton = screen.getByRole('button', { name: /^submit$/i });
880
- expect(submitButton).not.toBeDisabled();
881
- await act(async () => {
882
- fireEvent.click(submitButton);
883
- });
884
-
885
- // ERASURE asks whether to also revoke consent before it submits.
886
- // Choosing "Yes" (revokeConsentYes) sets revoke_consent_on_fulfilment=true.
887
- const revokeYesButton = await screen.findByRole('button', { name: 'Yes' });
888
- await act(async () => {
889
- fireEvent.click(revokeYesButton);
890
- });
891
-
892
- await waitFor(() => {
893
- expect(createCaseRequest).toHaveBeenCalledTimes(1);
894
- });
895
-
896
- const payload = createCaseRequest.mock.calls[0][2];
897
- expect(payload.product_uuid).toBe('prod-direct');
898
- expect('data_principal_uuid' in payload).toBe(false);
899
- expect(payload.uuid).toBe('form-session-uuid');
900
- expect(payload.request_type).toBe('erasure');
901
- // The user chose "Yes" in the consent-revoke modal, so the backend's
902
- // auto-revoke task fires when the case is fulfilled (DPDPA Sec 12:
903
- // erasing data implies revoking the consent that authorized
904
- // processing it).
905
- expect(payload.revoke_consent_on_fulfilment).toBe(true);
906
-
907
- await waitFor(() => {
908
- expect(screen.getByTestId('request-submitted')).toBeInTheDocument();
909
- });
910
- });
911
-
912
- it('opens the consent-revoke modal on erasure and sends revoke_consent_on_fulfilment=false when the user declines', async () => {
913
- setupSession();
914
- const directGroup = makeGroup({
915
- product_uuid: 'prod-direct',
916
- product_name: 'Acme Loyalty',
917
- purposes: [basePurpose('purp-direct', 'Marketing')],
918
- });
919
- const nominatedGroup = makeGroup({
920
- product_uuid: 'prod-nominated',
921
- product_name: 'Partner Bank',
922
- nominator: {
923
- uuid: 'nominator-uuid',
924
- org_user_id: 'org-user-1',
925
- name: 'Alice',
926
- email: 'alice@example.com',
927
- },
928
- purposes: [basePurpose('purp-nominated', 'Analytics')],
929
- });
930
- getFormData.mockResolvedValue(
931
- makeFormData({
932
- direct_groups: [directGroup],
933
- nominated_groups: [nominatedGroup],
934
- }),
935
- );
936
- createCaseRequest.mockResolvedValueOnce({
937
- case_id: 'CASE-2',
938
- uuid: 'uuid-2',
939
- });
940
-
941
- render(<Form onCreateRequest={vi.fn()} />);
942
- await waitFor(() => expect(getFormData).toHaveBeenCalled());
943
-
944
- pickRequestType(RequestTypeEnum.ERASURE);
945
-
946
- await waitFor(() =>
947
- expect(screen.getByText('Acme Loyalty')).toBeInTheDocument(),
948
- );
949
- clickProductChip('prod-direct');
950
-
951
- await waitFor(() => {
952
- expect(
953
- screen.getByTestId('per-product-purposes-prod-direct'),
954
- ).toBeInTheDocument();
955
- });
956
-
957
- const marketingCheckbox = screen
958
- .getByText('Marketing')
959
- .closest('label')
960
- ?.querySelector('input[type="checkbox"]') as HTMLInputElement | null;
961
- expect(marketingCheckbox).toBeTruthy();
962
- fireEvent.click(marketingCheckbox!);
963
-
964
- const confirmCheckbox = (
965
- screen.getAllByRole('checkbox') as HTMLInputElement[]
966
- ).find((c) => c.closest('label')?.textContent?.includes('I confirm'));
967
- expect(confirmCheckbox).toBeTruthy();
968
- fireEvent.click(confirmCheckbox!);
969
-
970
- await act(async () => {
971
- fireEvent.click(screen.getByRole('button', { name: /^submit$/i }));
972
- });
973
-
974
- // The consent-revoke modal must appear, and no request fires until the
975
- // user makes a choice. ('Revoke consent?' === revokeConsentModalTitle stub.)
976
- expect(await screen.findByText('Revoke consent?')).toBeInTheDocument();
977
- expect(createCaseRequest).not.toHaveBeenCalled();
978
-
979
- // Declining ('No' === revokeConsentNo) submits with the flag explicitly false.
980
- await act(async () => {
981
- fireEvent.click(screen.getByRole('button', { name: 'No' }));
982
- });
983
-
984
- await waitFor(() => {
985
- expect(createCaseRequest).toHaveBeenCalledTimes(1);
986
- });
987
- const payload = createCaseRequest.mock.calls[0][2];
988
- expect(payload.request_type).toBe('erasure');
989
- expect(payload.revoke_consent_on_fulfilment).toBe(false);
990
- });
991
-
992
- it('switches the inline purpose panel when another product chip is selected', async () => {
993
- setupSession();
994
- const creditCard = makeGroup({
995
- product_uuid: 'prod-cc',
996
- product_name: 'Credit Card',
997
- purposes: [basePurpose('purp-cc', 'Marketing')],
998
- });
999
- const savings = makeGroup({
1000
- product_uuid: 'prod-sav',
1001
- product_name: 'Savings Account',
1002
- purposes: [basePurpose('purp-sav', 'Analytics')],
1003
- });
1004
- getFormData.mockResolvedValue(
1005
- makeFormData({ direct_groups: [creditCard, savings] }),
1006
- );
1007
-
1008
- render(<Form onCreateRequest={vi.fn()} />);
1009
- await waitFor(() => expect(getFormData).toHaveBeenCalled());
1010
-
1011
- pickRequestType(RequestTypeEnum.ERASURE);
1012
-
1013
- await waitFor(() =>
1014
- expect(screen.getByText('Credit Card')).toBeInTheDocument(),
1015
- );
1016
- clickProductChip('prod-cc');
1017
-
1018
- const ccPanel = await screen.findByTestId('per-product-purposes-prod-cc');
1019
- expect(within(ccPanel).getByText('Credit Card')).toBeInTheDocument();
1020
- expect(within(ccPanel).getByText('Marketing')).toBeInTheDocument();
1021
- expect(
1022
- screen.queryByTestId('per-product-purposes-prod-sav'),
1023
- ).not.toBeInTheDocument();
1024
-
1025
- clickProductChip('prod-sav');
1026
-
1027
- const savPanel = await screen.findByTestId('per-product-purposes-prod-sav');
1028
- expect(within(savPanel).getByText('Savings Account')).toBeInTheDocument();
1029
- expect(within(savPanel).getByText('Analytics')).toBeInTheDocument();
1030
- expect(
1031
- screen.queryByTestId('per-product-purposes-prod-cc'),
1032
- ).not.toBeInTheDocument();
1033
-
1034
- clickProductChip('prod-cc');
1035
- await screen.findByTestId('per-product-purposes-prod-cc');
1036
- expect(screen.getByText('Marketing')).toBeInTheDocument();
1037
- });
1038
-
1039
- it('disambiguates direct vs nominated chips on the same product via inline panel header', async () => {
1040
- setupSession();
1041
- const direct = makeGroup({
1042
- product_uuid: 'prod-cc',
1043
- product_name: 'Credit Card',
1044
- purposes: [basePurpose('purp-direct', 'Marketing')],
1045
- });
1046
- const nominated = makeGroup({
1047
- product_uuid: 'prod-cc',
1048
- product_name: 'Credit Card',
1049
- nominator: {
1050
- uuid: 'alice-uuid',
1051
- org_user_id: 'org-user-alice',
1052
- name: 'Alice',
1053
- email: 'alice@example.com',
1054
- },
1055
- purposes: [basePurpose('purp-nominated', 'Analytics')],
1056
- });
1057
- getFormData.mockResolvedValue(
1058
- makeFormData({
1059
- direct_groups: [direct],
1060
- nominated_groups: [nominated],
1061
- }),
1062
- );
1063
-
1064
- render(<Form onCreateRequest={vi.fn()} />);
1065
- await waitFor(() => expect(getFormData).toHaveBeenCalled());
1066
-
1067
- pickRequestType(RequestTypeEnum.ERASURE);
1068
-
1069
- await waitFor(() =>
1070
- expect(screen.getByTestId('product-chip-prod-cc')).toBeInTheDocument(),
1071
- );
1072
- clickProductChip('prod-cc');
1073
-
1074
- const directPanel = await screen.findByTestId(
1075
- 'per-product-purposes-prod-cc',
1076
- );
1077
- expect(within(directPanel).getByText('Credit Card')).toBeInTheDocument();
1078
- expect(
1079
- within(directPanel).queryByText(/acting on behalf of/i),
1080
- ).not.toBeInTheDocument();
1081
-
1082
- clickProductChip('prod-cc:alice-uuid');
1083
-
1084
- const nominatedPanel = await screen.findByTestId(
1085
- 'per-product-purposes-prod-cc:alice-uuid',
1086
- );
1087
- expect(within(nominatedPanel).getByText('Credit Card')).toBeInTheDocument();
1088
- expect(
1089
- within(nominatedPanel).getByText(/acting on behalf of Alice/i),
1090
- ).toBeInTheDocument();
1091
- });
1092
-
1093
- it('fires one createCaseRequest with per-product correction_data on single-product correction submit', async () => {
1094
- setupSession();
1095
- const loyalty = makeGroup({
1096
- product_uuid: 'prod-loyalty',
1097
- product_name: 'Acme Loyalty',
1098
- purposes: [
1099
- basePurpose('purp-loyalty', 'Marketing', [
1100
- baseDataElement('de-loyalty-email', 'email'),
1101
- ]),
1102
- ],
1103
- });
1104
- const rewards = makeGroup({
1105
- product_uuid: 'prod-rewards',
1106
- product_name: 'Acme Rewards',
1107
- purposes: [
1108
- basePurpose('purp-rewards', 'Analytics', [
1109
- baseDataElement('de-rewards-phone', 'phone'),
1110
- ]),
1111
- ],
1112
- });
1113
- getFormData.mockResolvedValue(
1114
- makeFormData({
1115
- direct_groups: [loyalty, rewards],
1116
- purposes: [
1117
- {
1118
- purpose: basePurpose('purp-loyalty', 'Marketing', [
1119
- baseDataElement('de-loyalty-email', 'email'),
1120
- ]),
1121
- },
1122
- {
1123
- purpose: basePurpose('purp-rewards', 'Analytics', [
1124
- baseDataElement('de-rewards-phone', 'phone'),
1125
- ]),
1126
- },
1127
- ],
1128
- }),
1129
- );
1130
- createCaseRequest.mockResolvedValueOnce({
1131
- case_id: 'CASE-1',
1132
- uuid: 'uuid-1',
1133
- });
1134
-
1135
- render(<Form onCreateRequest={vi.fn()} />);
1136
- await waitFor(() => expect(getFormData).toHaveBeenCalled());
1137
-
1138
- pickRequestType(RequestTypeEnum.CORRECTION);
1139
-
1140
- await waitFor(() =>
1141
- expect(screen.getByText('Acme Loyalty')).toBeInTheDocument(),
1142
- );
1143
- clickProductChip('prod-loyalty');
1144
-
1145
- const loyaltyPanel = await screen.findByTestId(
1146
- 'per-product-purposes-prod-loyalty',
1147
- );
1148
-
1149
- expect(
1150
- within(loyaltyPanel).getByLabelText('correction-de-email'),
1151
- ).toBeInTheDocument();
1152
- expect(
1153
- within(loyaltyPanel).queryByLabelText('correction-de-phone'),
1154
- ).not.toBeInTheDocument();
1155
-
1156
- fireEvent.click(within(loyaltyPanel).getByLabelText('correction-de-email'));
1157
- fireEvent.change(
1158
- within(loyaltyPanel).getByLabelText('correction-current-email'),
1159
- { target: { value: 'old@x.com' } },
1160
- );
1161
- fireEvent.change(
1162
- within(loyaltyPanel).getByLabelText('correction-updated-email'),
1163
- { target: { value: 'new@x.com' } },
1164
- );
1165
-
1166
- const allCheckboxes = screen.getAllByRole(
1167
- 'checkbox',
1168
- ) as HTMLInputElement[];
1169
- const confirmCheckbox = allCheckboxes.find((c) =>
1170
- c.closest('label')?.textContent?.includes('I confirm'),
1171
- );
1172
- expect(confirmCheckbox).toBeTruthy();
1173
- fireEvent.click(confirmCheckbox!);
1174
-
1175
- const submitButton = screen.getByRole('button', { name: /^submit$/i });
1176
- expect(submitButton).not.toBeDisabled();
1177
- await act(async () => {
1178
- fireEvent.click(submitButton);
1179
- });
1180
-
1181
- await waitFor(() => {
1182
- expect(createCaseRequest).toHaveBeenCalledTimes(1);
1183
- });
1184
-
1185
- const payload = createCaseRequest.mock.calls[0][2];
1186
- expect(payload.product_uuid).toBe('prod-loyalty');
1187
- expect(payload.request_type).toBe('correction');
1188
- expect('data_principal_uuid' in payload).toBe(false);
1189
- expect(payload.request_details.purposes).toEqual([]);
1190
- expect(payload.request_details.correction_data).toEqual([
1191
- { name: 'email', curr_value: 'old@x.com', new_value: 'new@x.com' },
1192
- ]);
1193
-
1194
- await waitFor(() => {
1195
- expect(screen.getByTestId('request-submitted')).toBeInTheDocument();
1196
- });
1197
- });
1198
-
1199
- it('submits NOMINATION as an org-level case without product_uuid or data_principal_uuid', async () => {
1200
- // NOMINATION is org-level — the picker is not rendered and the
1201
- // payload must omit `product_uuid` (backend rejects it on these
1202
- // types) AND `data_principal_uuid` (this is a direct grant, not a
1203
- // nominee acting on someone's behalf). Even when the contact has
1204
- // consent groups available, NOMINATION must not leak them onto
1205
- // the case anchor.
1206
- setupSession();
1207
- const direct = makeGroup();
1208
- getFormData.mockResolvedValue(
1209
- makeFormData({ direct_groups: [direct], nominated_groups: [] }),
1210
- );
1211
- createCaseRequest.mockResolvedValueOnce({
1212
- case_id: 'CASE-NOM',
1213
- uuid: 'uuid-nom',
1214
- });
1215
-
1216
- render(<Form onCreateRequest={vi.fn()} />);
1217
- await waitFor(() => expect(getFormData).toHaveBeenCalled());
1218
-
1219
- pickRequestType(RequestTypeEnum.NOMINATION);
1220
-
1221
- await waitFor(() => {
1222
- expect(screen.getByTestId('nomination-section')).toBeInTheDocument();
1223
- });
1224
- // Product picker must not render for NOMINATION even with groups.
1225
- expect(
1226
- screen.queryByText(/Select a product/i),
1227
- ).not.toBeInTheDocument();
1228
-
1229
- const submitButton = screen.getByRole(
1230
- 'button',
1231
- { name: /^submit$/i },
1232
- ) as HTMLButtonElement;
1233
- // Sanity: gate is closed before a valid nominee email is provided.
1234
- expect(submitButton.disabled).toBe(true);
1235
-
1236
- // Drive the form to a valid NOMINATION state via the stubbed
1237
- // nomination input (see vi.mock above).
1238
- const emailInput = screen.getByTestId('nominee-email-input');
1239
- fireEvent.change(emailInput, { target: { value: 'nominee@example.com' } });
1240
-
1241
- const confirmCheckbox = (
1242
- screen.getAllByRole('checkbox') as HTMLInputElement[]
1243
- ).find((c) => c.closest('label')?.textContent?.includes('I confirm'));
1244
- expect(confirmCheckbox).toBeTruthy();
1245
- fireEvent.click(confirmCheckbox!);
1246
-
1247
- await waitFor(() => {
1248
- const btn = screen.getByRole(
1249
- 'button',
1250
- { name: /^submit$/i },
1251
- ) as HTMLButtonElement;
1252
- expect(btn.disabled).toBe(false);
1253
- });
1254
-
1255
- fireEvent.click(
1256
- screen.getByRole('button', { name: /^submit$/i }),
1257
- );
1258
-
1259
- await waitFor(() => expect(createCaseRequest).toHaveBeenCalled());
1260
-
1261
- const payload = createCaseRequest.mock.calls[0][2];
1262
- expect(payload.request_type).toBe('nomination');
1263
- expect(payload).not.toHaveProperty('product_uuid');
1264
- expect(payload).not.toHaveProperty('data_principal_uuid');
1265
- expect(payload.request_details.nomination_data).toMatchObject({
1266
- nominee_email: 'nominee@example.com',
1267
- });
1268
- });
1269
-
1270
- it('sends data_principal_uuid and product anchors on a nominated-card submit', async () => {
1271
- setupSession();
1272
- const otherDirect = makeGroup({
1273
- product_uuid: 'prod-other',
1274
- product_name: 'Other Product',
1275
- purposes: [basePurpose('purp-other', 'Other')],
1276
- });
1277
- const nominated = makeGroup({
1278
- product_uuid: 'prod-cc',
1279
- product_name: 'Credit Card',
1280
- nominator: {
1281
- uuid: 'alice-uuid',
1282
- org_user_id: 'org-user-alice',
1283
- name: 'Alice',
1284
- email: 'alice@example.com',
1285
- },
1286
- purposes: [basePurpose('purp-nominated', 'Analytics')],
1287
- });
1288
- getFormData.mockResolvedValue(
1289
- makeFormData({
1290
- direct_groups: [otherDirect],
1291
- nominated_groups: [nominated],
1292
- }),
1293
- );
1294
- createCaseRequest.mockResolvedValueOnce({
1295
- case_id: 'CASE-NOMINATED',
1296
- uuid: 'uuid-nominated',
1297
- });
1298
-
1299
- render(<Form onCreateRequest={vi.fn()} />);
1300
- await waitFor(() => expect(getFormData).toHaveBeenCalled());
1301
-
1302
- pickRequestType(RequestTypeEnum.ERASURE);
1303
-
1304
- await waitFor(() =>
1305
- expect(
1306
- screen.getByTestId('product-chip-prod-cc:alice-uuid'),
1307
- ).toBeInTheDocument(),
1308
- );
1309
- clickProductChip('prod-cc:alice-uuid');
1310
-
1311
- const nominatedPanel = await screen.findByTestId(
1312
- 'per-product-purposes-prod-cc:alice-uuid',
1313
- );
1314
- fireEvent.click(
1315
- within(nominatedPanel)
1316
- .getByText('Analytics')
1317
- .closest('label')!
1318
- .querySelector('input[type="checkbox"]')!,
1319
- );
1320
-
1321
- const confirmCheckbox = (
1322
- screen.getAllByRole('checkbox') as HTMLInputElement[]
1323
- ).find((c) => c.closest('label')?.textContent?.includes('I confirm'));
1324
- fireEvent.click(confirmCheckbox!);
1325
-
1326
- await act(async () => {
1327
- fireEvent.click(screen.getByRole('button', { name: /^submit$/i }));
1328
- });
1329
-
1330
- // ERASURE routes through the consent-revoke modal before submitting.
1331
- await act(async () => {
1332
- fireEvent.click(await screen.findByRole('button', { name: 'Yes' }));
1333
- });
1334
-
1335
- await waitFor(() => {
1336
- expect(createCaseRequest).toHaveBeenCalledTimes(1);
1337
- });
1338
-
1339
- const payload = createCaseRequest.mock.calls[0][2];
1340
- expect(payload.product_uuid).toBe('prod-cc');
1341
- // Nominated cards send data_principal_uuid sourced from the
1342
- // nominator's ConsentUser uuid — NOT from formData.uuid.
1343
- expect(payload.data_principal_uuid).toBe('alice-uuid');
1344
-
1345
- await waitFor(() => {
1346
- expect(screen.getByTestId('request-submitted')).toBeInTheDocument();
1347
- });
1348
- expect(
1349
- screen.getByTestId('request-submitted-product-uuid').textContent,
1350
- ).toBe('prod-cc');
1351
- expect(
1352
- screen.getByTestId('request-submitted-case-id').textContent,
1353
- ).toBe('CASE-NOMINATED');
1354
- });
1355
-
1356
- it('disables submit when the selected CORRECTION product has incomplete entries', async () => {
1357
- setupSession();
1358
- const loyalty = makeGroup({
1359
- product_uuid: 'prod-loyalty',
1360
- product_name: 'Acme Loyalty',
1361
- purposes: [
1362
- basePurpose('purp-loyalty', 'Marketing', [
1363
- baseDataElement('de-loyalty-email', 'email'),
1364
- ]),
1365
- ],
1366
- });
1367
- const rewards = makeGroup({
1368
- product_uuid: 'prod-rewards',
1369
- product_name: 'Acme Rewards',
1370
- purposes: [
1371
- basePurpose('purp-rewards', 'Analytics', [
1372
- baseDataElement('de-rewards-phone', 'phone'),
1373
- ]),
1374
- ],
1375
- });
1376
- getFormData.mockResolvedValue(
1377
- makeFormData({ direct_groups: [loyalty, rewards] }),
1378
- );
1379
-
1380
- render(<Form onCreateRequest={vi.fn()} />);
1381
- await waitFor(() => expect(getFormData).toHaveBeenCalled());
1382
-
1383
- pickRequestType(RequestTypeEnum.CORRECTION);
1384
-
1385
- await waitFor(() =>
1386
- expect(screen.getByText('Acme Loyalty')).toBeInTheDocument(),
1387
- );
1388
- clickProductChip('prod-loyalty');
1389
-
1390
- const loyaltyPanel = await screen.findByTestId(
1391
- 'per-product-purposes-prod-loyalty',
1392
- );
1393
-
1394
- const allCheckboxes = screen.getAllByRole(
1395
- 'checkbox',
1396
- ) as HTMLInputElement[];
1397
- const confirmCheckbox = allCheckboxes.find((c) =>
1398
- c.closest('label')?.textContent?.includes('I confirm'),
1399
- );
1400
- expect(confirmCheckbox).toBeTruthy();
1401
- fireEvent.click(confirmCheckbox!);
1402
-
1403
- const submitButton = screen.getByRole(
1404
- 'button',
1405
- { name: /^submit$/i },
1406
- ) as HTMLButtonElement;
1407
- expect(submitButton.disabled).toBe(true);
1408
-
1409
- fireEvent.click(within(loyaltyPanel).getByLabelText('correction-de-email'));
1410
- fireEvent.change(
1411
- within(loyaltyPanel).getByLabelText('correction-current-email'),
1412
- { target: { value: 'old@x.com' } },
1413
- );
1414
- fireEvent.change(
1415
- within(loyaltyPanel).getByLabelText('correction-updated-email'),
1416
- { target: { value: 'new@x.com' } },
1417
- );
1418
-
1419
- expect(
1420
- (screen.getByRole('button', { name: /^submit$/i }) as HTMLButtonElement)
1421
- .disabled,
1422
- ).toBe(false);
1423
- });
1424
- });