@micha.bigler/ui-core-micha 3.14.4 → 4.0.0

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 (341) hide show
  1. package/CHANGELOG.md +25 -0
  2. package/README.md +7 -0
  3. package/dist/chat/kitSxRegistry.js +9 -0
  4. package/dist/components/charts/kitSxRegistry.js +6 -0
  5. package/dist/entries/charts.js +6 -0
  6. package/dist/entries/chat.js +8 -0
  7. package/dist/entries/markdown.js +1 -0
  8. package/dist/index.js +0 -14
  9. package/dist/pages/AccountPage.js +1 -2
  10. package/dist/pages/LoginPage.js +1 -2
  11. package/dist/pages/PasswordChangePage.js +1 -2
  12. package/dist/pages/PasswordInvitePage.js +1 -2
  13. package/dist/pages/PasswordResetRequestPage.js +1 -2
  14. package/dist/pages/SignUpPage.js +1 -2
  15. package/dist/pages/SignupConfirmPage.js +1 -2
  16. package/dist/theme/kitSxEntry.js +11 -0
  17. package/dist/theme/kitSxRegistry.js +2 -15
  18. package/package.json +32 -7
  19. package/.github/workflows/ci.yml +0 -35
  20. package/.github/workflows/publish.yml +0 -126
  21. package/DESIGN.md +0 -60
  22. package/WORK_ORDERS.md +0 -150
  23. package/dev/entries.jsx +0 -721
  24. package/dev/fixtures.js +0 -26
  25. package/dev/main.jsx +0 -75
  26. package/dev/mockTransport.jsx +0 -128
  27. package/docs/CHART-LAYOUT.md +0 -157
  28. package/docs/DARK-TOKENS.md +0 -140
  29. package/docs/TYPE-SCALE.md +0 -111
  30. package/docs/messaging-deviations.md +0 -118
  31. package/index.html +0 -12
  32. package/renovate.json +0 -10
  33. package/scripts/chart-api-census.mjs +0 -415
  34. package/src/auth/AuthContext.jsx +0 -158
  35. package/src/auth/ReauthModal.jsx +0 -82
  36. package/src/auth/UserMenu.jsx +0 -121
  37. package/src/auth/apiClient.jsx +0 -232
  38. package/src/auth/authApi.jsx +0 -539
  39. package/src/auth/authConfig.jsx +0 -34
  40. package/src/auth/reauth.js +0 -47
  41. package/src/chat/ChatComposer.jsx +0 -36
  42. package/src/chat/ChatList.jsx +0 -87
  43. package/src/chat/ChatThread.jsx +0 -128
  44. package/src/chat/ChatWorkspace.jsx +0 -244
  45. package/src/chat/MarkdownReply.jsx +0 -22
  46. package/src/chat/ModelPicker.jsx +0 -85
  47. package/src/chat/api.js +0 -18
  48. package/src/chat/useChatSocket.js +0 -32
  49. package/src/chat/wire.js +0 -7
  50. package/src/components/AccessCodeManager.jsx +0 -288
  51. package/src/components/AccessCodeSingleUseToggle.jsx +0 -92
  52. package/src/components/AllowedEmailDomainsManager.jsx +0 -92
  53. package/src/components/AuthFactorRequirementCard.jsx +0 -95
  54. package/src/components/BulkInviteCsvTab.jsx +0 -198
  55. package/src/components/EmptyState.jsx +0 -38
  56. package/src/components/LoginForm.jsx +0 -159
  57. package/src/components/MFAComponent.jsx +0 -350
  58. package/src/components/MfaLoginComponent.jsx +0 -252
  59. package/src/components/MobileBottomNav.jsx +0 -82
  60. package/src/components/PasskeysComponent.jsx +0 -252
  61. package/src/components/PasswordChangeForm.jsx +0 -87
  62. package/src/components/PasswordResetRequestForm.jsx +0 -43
  63. package/src/components/PasswordSetForm.jsx +0 -97
  64. package/src/components/ProfileComponent.jsx +0 -348
  65. package/src/components/QrSignupManager.jsx +0 -404
  66. package/src/components/QrSignupValidityManager.jsx +0 -106
  67. package/src/components/RegistrationMethodsManager.jsx +0 -150
  68. package/src/components/SecurityComponent.jsx +0 -141
  69. package/src/components/SocialLoginButtons.jsx +0 -83
  70. package/src/components/SoftChip.jsx +0 -93
  71. package/src/components/StatTile.jsx +0 -39
  72. package/src/components/SupportRecoveryRequestsTab.jsx +0 -482
  73. package/src/components/TurnstileWidget.jsx +0 -99
  74. package/src/components/UserInviteComponent.jsx +0 -76
  75. package/src/components/UserListComponent.jsx +0 -618
  76. package/src/components/charts/BarChart.jsx +0 -102
  77. package/src/components/charts/ChartFrame.jsx +0 -214
  78. package/src/components/charts/LineChart.jsx +0 -126
  79. package/src/components/charts/ScatterChart.jsx +0 -299
  80. package/src/components/charts/TimeSeriesChart.jsx +0 -300
  81. package/src/components/charts/chartDefaults.js +0 -644
  82. package/src/components/charts/chartLabels.js +0 -36
  83. package/src/components/charts/exportChart.js +0 -258
  84. package/src/components/charts/formatters.js +0 -39
  85. package/src/components/charts/palette.js +0 -33
  86. package/src/components/charts/yearTickInterval.js +0 -7
  87. package/src/i18n/authTranslations.ts +0 -2651
  88. package/src/i18n/chartsTranslations.ts +0 -91
  89. package/src/i18n/chatTranslations.ts +0 -55
  90. package/src/i18n/messagingTranslations.ts +0 -120
  91. package/src/i18n/notificationsTranslations.ts +0 -32
  92. package/src/i18n/onboardingTranslations.ts +0 -29
  93. package/src/i18n/sectionNavTranslations.ts +0 -20
  94. package/src/i18n/uiCoreTranslations.js +0 -29
  95. package/src/i18n/userMenuTranslations.ts +0 -5
  96. package/src/index.js +0 -158
  97. package/src/layout/PageLayout.jsx +0 -36
  98. package/src/layout/SectionNav.jsx +0 -320
  99. package/src/messaging/AttachmentList.jsx +0 -145
  100. package/src/messaging/Composer.jsx +0 -197
  101. package/src/messaging/ConversationLaunchers.jsx +0 -51
  102. package/src/messaging/ConversationList.jsx +0 -109
  103. package/src/messaging/DirectMessageLauncher.jsx +0 -112
  104. package/src/messaging/MessageBubble.jsx +0 -183
  105. package/src/messaging/MessagingProvider.jsx +0 -0
  106. package/src/messaging/MessagingScopeConfig.jsx +0 -24
  107. package/src/messaging/PollCard.jsx +0 -163
  108. package/src/messaging/ReactionBar.jsx +0 -43
  109. package/src/messaging/ReadTicks.jsx +0 -82
  110. package/src/messaging/Thread.jsx +0 -195
  111. package/src/messaging/api.js +0 -48
  112. package/src/messaging/composerImageCompression.js +0 -35
  113. package/src/messaging/linkifyText.jsx +0 -37
  114. package/src/notifications/NotificationBell.jsx +0 -84
  115. package/src/notifications/NotificationSettings.jsx +0 -330
  116. package/src/notifications/NotificationsProvider.jsx +0 -224
  117. package/src/notifications/PopupSurface.jsx +0 -105
  118. package/src/notifications/api.js +0 -55
  119. package/src/notifications/feedApi.js +0 -18
  120. package/src/notifications/realtime.jsx +0 -138
  121. package/src/notifications/serviceWorker/sw.js +0 -50
  122. package/src/onboarding/OnboardingProvider.jsx +0 -326
  123. package/src/onboarding/OnboardingWizard.jsx +0 -61
  124. package/src/onboarding/WizardDialogShell.jsx +0 -51
  125. package/src/onboarding/api.js +0 -13
  126. package/src/onboarding/stepSelection.js +0 -16
  127. package/src/onboarding/steps/BrowserPushStep.jsx +0 -121
  128. package/src/onboarding/steps/CompleteNameStep.jsx +0 -46
  129. package/src/onboarding/steps/CookieConsentStep.jsx +0 -133
  130. package/src/onboarding/steps/PwaInstallStep.jsx +0 -47
  131. package/src/pages/AccountPage.jsx +0 -394
  132. package/src/pages/LoginPage.jsx +0 -343
  133. package/src/pages/PasswordChangePage.jsx +0 -62
  134. package/src/pages/PasswordInvitePage.jsx +0 -177
  135. package/src/pages/PasswordResetRequestPage.jsx +0 -68
  136. package/src/pages/SignUpPage.jsx +0 -268
  137. package/src/pages/SignupConfirmPage.jsx +0 -155
  138. package/src/testing/checkKitIntegration.js +0 -233
  139. package/src/theme/createAppTheme.js +0 -423
  140. package/src/theme/fonts.js +0 -3
  141. package/src/theme/index.js +0 -21
  142. package/src/theme/kitSxRegistry.js +0 -285
  143. package/src/theme/themeCompleteness.js +0 -1045
  144. package/src/theme/tokens.js +0 -478
  145. package/src/utils/auth-errors.js +0 -76
  146. package/src/utils/authService.js +0 -223
  147. package/src/utils/resolveErrorText.js +0 -28
  148. package/src/utils/webauthn.js +0 -51
  149. package/tests/AccountPage.profileStatements.test.jsx +0 -162
  150. package/tests/AccountPage.test.jsx +0 -200
  151. package/tests/AuthContext.test.jsx +0 -129
  152. package/tests/BarChart.test.jsx +0 -112
  153. package/tests/BrowserPushStep.test.jsx +0 -110
  154. package/tests/ChartFrame.test.jsx +0 -336
  155. package/tests/ConversationList.test.jsx +0 -144
  156. package/tests/CookieConsentStep.test.jsx +0 -69
  157. package/tests/EmptyState.test.jsx +0 -62
  158. package/tests/LineChart.test.jsx +0 -80
  159. package/tests/MessagingProvider.test.jsx +0 -50
  160. package/tests/MobileBottomNav.test.jsx +0 -319
  161. package/tests/NotificationBell.test.jsx +0 -60
  162. package/tests/NotificationSettings.test.jsx +0 -276
  163. package/tests/NotificationsProvider.test.jsx +0 -240
  164. package/tests/OnboardingProvider.test.jsx +0 -294
  165. package/tests/OnboardingWizard.test.jsx +0 -143
  166. package/tests/PasswordChangeForm.test.jsx +0 -70
  167. package/tests/PasswordInvitePage.test.jsx +0 -142
  168. package/tests/PasswordSetForm.test.jsx +0 -70
  169. package/tests/PopupSurface.test.jsx +0 -142
  170. package/tests/ProfileComponent.refresh.test.jsx +0 -194
  171. package/tests/QrSignupManager.registrationContext.test.jsx +0 -106
  172. package/tests/QrSignupManagerInfoBox.test.jsx +0 -49
  173. package/tests/ScatterChart.test.jsx +0 -270
  174. package/tests/SectionNav.test.jsx +0 -363
  175. package/tests/SignUpPage.test.jsx +0 -208
  176. package/tests/SoftChip.test.jsx +0 -105
  177. package/tests/StatTile.test.jsx +0 -57
  178. package/tests/Thread.test.jsx +0 -151
  179. package/tests/TimeSeriesChart.test.jsx +0 -367
  180. package/tests/UserListComponent.test.jsx +0 -192
  181. package/tests/UserMenu.test.jsx +0 -171
  182. package/tests/apiClientLanguage.test.js +0 -33
  183. package/tests/apiClientPublicPaths.test.js +0 -178
  184. package/tests/authApiLogin.test.js +0 -42
  185. package/tests/authApiRegistration.test.js +0 -31
  186. package/tests/authErrorCodeRendering.test.jsx +0 -77
  187. package/tests/authErrors.test.js +0 -74
  188. package/tests/authTranslations.test.js +0 -74
  189. package/tests/chart-api-census.test.js +0 -366
  190. package/tests/chartAxisTickBand.test.jsx +0 -95
  191. package/tests/chartDefaults.test.js +0 -902
  192. package/tests/chartLabels.test.js +0 -50
  193. package/tests/chartsPalette.test.js +0 -99
  194. package/tests/chatApi.test.js +0 -48
  195. package/tests/chatDriverNames.test.jsx +0 -71
  196. package/tests/chatExports.test.js +0 -3
  197. package/tests/chatList.test.jsx +0 -84
  198. package/tests/chatPicker.test.jsx +0 -82
  199. package/tests/chatSocket.test.jsx +0 -26
  200. package/tests/chatThread.test.jsx +0 -116
  201. package/tests/chatTranslations.test.js +0 -47
  202. package/tests/chatWorkspace.test.jsx +0 -234
  203. package/tests/checkKitIntegration.test.jsx +0 -219
  204. package/tests/createAppTheme.test.js +0 -132
  205. package/tests/createAppThemeDark.test.js +0 -127
  206. package/tests/createAppThemeLightGuard.test.js +0 -40
  207. package/tests/createAppThemePageContrast.test.js +0 -108
  208. package/tests/createAppThemeTypography.test.js +0 -53
  209. package/tests/errorCallSiteGuard.test.js +0 -32
  210. package/tests/exportChart.test.js +0 -313
  211. package/tests/feedApi.test.js +0 -46
  212. package/tests/fixtures/light-theme-baseline.json +0 -2234
  213. package/tests/i18nAggregate.test.js +0 -120
  214. package/tests/i18nGermanVariant.test.js +0 -65
  215. package/tests/loginPageErrorResolution.test.jsx +0 -102
  216. package/tests/messagingApi.test.js +0 -32
  217. package/tests/messagingChunk6.test.jsx +0 -116
  218. package/tests/messagingCompactBubble.test.jsx +0 -64
  219. package/tests/messagingComposer.test.jsx +0 -136
  220. package/tests/messagingComposerChunk5.test.jsx +0 -113
  221. package/tests/messagingContractConformance.test.js +0 -69
  222. package/tests/messagingDirectMessageLauncher.test.jsx +0 -151
  223. package/tests/messagingExports.test.js +0 -21
  224. package/tests/messagingInteractions.test.jsx +0 -136
  225. package/tests/messagingLastMessagePreview.test.jsx +0 -93
  226. package/tests/messagingLinkify.test.jsx +0 -51
  227. package/tests/messagingMessageActions.test.jsx +0 -163
  228. package/tests/messagingMsg6.test.jsx +0 -105
  229. package/tests/messagingMsg6f.test.jsx +0 -155
  230. package/tests/messagingMsg6g.test.jsx +0 -166
  231. package/tests/messagingMsg6h.test.jsx +0 -136
  232. package/tests/messagingMsg6i.test.jsx +0 -129
  233. package/tests/messagingPollRendering.test.jsx +0 -142
  234. package/tests/messagingReactionMerge.test.jsx +0 -77
  235. package/tests/messagingReadTicksTooltip.test.jsx +0 -36
  236. package/tests/messagingThreadReceipts.test.jsx +0 -178
  237. package/tests/messagingThreadingQuoting.test.jsx +0 -87
  238. package/tests/messagingUnreadLifecycle.test.jsx +0 -78
  239. package/tests/notificationsApi.test.js +0 -41
  240. package/tests/notificationsExports.test.js +0 -34
  241. package/tests/onboardingDescriptors.test.js +0 -132
  242. package/tests/packageTreeShaking.test.js +0 -126
  243. package/tests/realtime.test.jsx +0 -219
  244. package/tests/resolveErrorText.test.js +0 -72
  245. package/tests/stepSelection.test.js +0 -53
  246. package/tests/themeCompleteness.test.js +0 -626
  247. package/tests/timeSeriesLegend.test.js +0 -99
  248. package/tests/userScreenTranslations.test.jsx +0 -218
  249. package/tsconfig.build.json +0 -18
  250. package/vite.config.mjs +0 -6
  251. package/work-orders/AUTH-1.md +0 -74
  252. package/work-orders/AUTH-2.md +0 -74
  253. package/work-orders/AUTH-4.md +0 -183
  254. package/work-orders/AUTH-5.md +0 -154
  255. package/work-orders/AUTH-7.md +0 -181
  256. package/work-orders/AUTH-8.md +0 -184
  257. package/work-orders/CHART-1.md +0 -285
  258. package/work-orders/CHART-2.md +0 -222
  259. package/work-orders/CHART-3.md +0 -163
  260. package/work-orders/CHART-4.md +0 -203
  261. package/work-orders/CHART-5.md +0 -226
  262. package/work-orders/CHART-6.md +0 -428
  263. package/work-orders/CHART-7.md +0 -175
  264. package/work-orders/DX-1.md +0 -169
  265. package/work-orders/DX-2.md +0 -188
  266. package/work-orders/DX-3.md +0 -195
  267. package/work-orders/I18N-1.md +0 -254
  268. package/work-orders/I18N-3.md +0 -207
  269. package/work-orders/MSG-3.md +0 -375
  270. package/work-orders/MSG-3b.md +0 -1002
  271. package/work-orders/MSG-3c.md +0 -378
  272. package/work-orders/MSG-3d.md +0 -268
  273. package/work-orders/MSG-3e.md +0 -164
  274. package/work-orders/MSG-3f.md +0 -391
  275. package/work-orders/MSG-6e.md +0 -308
  276. package/work-orders/MSG-6f.md +0 -214
  277. package/work-orders/MSG-6g.md +0 -244
  278. package/work-orders/MSG-6h.md +0 -238
  279. package/work-orders/MSG-6i.md +0 -271
  280. package/work-orders/MSG-6j.md +0 -117
  281. package/work-orders/NOTIF-12.md +0 -214
  282. package/work-orders/NOTIF-13.md +0 -142
  283. package/work-orders/NOTIF-14.md +0 -151
  284. package/work-orders/PRIM-1.md +0 -177
  285. package/work-orders/SHELL-1.md +0 -255
  286. package/work-orders/SHELL-2.md +0 -197
  287. package/work-orders/SHELL-3.md +0 -359
  288. package/work-orders/SHELL-4.md +0 -351
  289. package/work-orders/SHELL-5.md +0 -345
  290. package/work-orders/SHELL-6.md +0 -210
  291. package/work-orders/THEME-1.md +0 -587
  292. package/work-orders/THEME-10.md +0 -303
  293. package/work-orders/THEME-11.md +0 -208
  294. package/work-orders/THEME-2.md +0 -339
  295. package/work-orders/THEME-3.md +0 -210
  296. package/work-orders/THEME-4.md +0 -271
  297. package/work-orders/THEME-5.md +0 -341
  298. package/work-orders/THEME-6.md +0 -247
  299. package/work-orders/THEME-7.md +0 -82
  300. package/work-orders/THEME-8.md +0 -211
  301. package/work-orders/THEME-9.md +0 -194
  302. package/work-orders/UCM-AUTH-10.md +0 -490
  303. package/work-orders/UCM-AUTH-11.md +0 -185
  304. package/work-orders/UCM-AUTH-12.md +0 -98
  305. package/work-orders/UCM-AUTH-13.md +0 -47
  306. package/work-orders/UCM-AUTH-9.md +0 -207
  307. package/work-orders/UCM-CHART-10.md +0 -150
  308. package/work-orders/UCM-CHART-11.md +0 -132
  309. package/work-orders/UCM-CHART-12.md +0 -348
  310. package/work-orders/UCM-CHART-13.md +0 -122
  311. package/work-orders/UCM-CHART-14.md +0 -198
  312. package/work-orders/UCM-CHART-15.md +0 -187
  313. package/work-orders/UCM-CHART-16.md +0 -169
  314. package/work-orders/UCM-CHART-17.md +0 -195
  315. package/work-orders/UCM-CHART-18.md +0 -200
  316. package/work-orders/UCM-CHART-8.md +0 -147
  317. package/work-orders/UCM-CHART-9.md +0 -265
  318. package/work-orders/UCM-CHAT-1.md +0 -190
  319. package/work-orders/UCM-CHAT-2.md +0 -75
  320. package/work-orders/UCM-CI-1.md +0 -65
  321. package/work-orders/UCM-DEP-1.md +0 -63
  322. package/work-orders/UCM-I18N-4.md +0 -226
  323. package/work-orders/UCM-I18N-5.md +0 -211
  324. package/work-orders/UCM-MSG-20.md +0 -192
  325. package/work-orders/UCM-PRIM-2.md +0 -114
  326. package/work-orders/UCM-SHELL-7.md +0 -134
  327. package/work-orders/UCM-SHELL-8.md +0 -125
  328. package/work-orders/UCM-TEST-1.md +0 -304
  329. package/work-orders/UCM-THEME-13.md +0 -69
  330. package/work-orders/UCM-THEME-14.md +0 -312
  331. package/work-orders/UCM-THEME-15.md +0 -356
  332. package/work-orders/UCM-THEME-16.md +0 -80
  333. package/work-orders/UCM-THEME-17.md +0 -111
  334. package/work-orders/UCM-THEME-18.md +0 -184
  335. package/work-orders/assets/AUTH-4-user-list-card.html +0 -407
  336. package/work-orders/assets/PRIM-1-dashboard-primitives.html +0 -624
  337. package/work-orders/assets/SHELL-2-account-navigation.html +0 -1159
  338. package/work-orders/assets/THEME-1-baseline-reference-sheet.html +0 -1352
  339. package/work-orders/assets/UCM-CHAT-1-ai-chat.html +0 -447
  340. package/work-orders/assets/UCM-THEME-13-dark-prototype.html +0 -390
  341. package/work-orders/assets/UCM-THEME-17-type-scale.html +0 -391
@@ -1,163 +0,0 @@
1
- // @vitest-environment jsdom
2
- import React from 'react';
3
- import { afterEach, describe, expect, it, vi } from 'vitest';
4
- import { cleanup, fireEvent, render, screen, waitFor } from '@testing-library/react';
5
-
6
- vi.mock('react-i18next', () => ({ useTranslation: () => ({ t: (key, options) => options?.message ? `${key}:${options.message}` : key }) }));
7
- vi.mock('../src/notifications/realtime', () => ({ useRealtime: () => ({ subscribe: () => () => {}, onReconnect: () => () => {} }) }));
8
-
9
- import { AuthContext } from '../src/auth/AuthContext';
10
- import { Composer } from '../src/messaging/Composer';
11
- import { MessageBubble } from '../src/messaging/MessageBubble';
12
- import { MessagingProvider } from '../src/messaging/MessagingProvider';
13
-
14
- function makeApi() {
15
- return {
16
- patchMessage: vi.fn().mockImplementation(async (id, patch) => ({ id, ...patch, edited_at: '2026-07-31T10:01:00Z' })),
17
- deleteMessage: vi.fn().mockImplementation(async (id) => ({ id, deleted_at: '2026-07-31T10:01:00Z' })),
18
- };
19
- }
20
- function renderBubble(message, { userId = 1, canModerateMessages = false, api = makeApi(), onReply } = {}) {
21
- const result = render(<AuthContext.Provider value={{ user: { id: userId } }}><MessagingProvider api={api} active={false}><MessageBubble message={message} canModerateMessages={canModerateMessages} onReply={onReply} /></MessagingProvider></AuthContext.Provider>);
22
- return { ...result, api };
23
- }
24
- function openActions() { fireEvent.click(screen.getByRole('button', { name: 'MessagingActions.MENU' })); }
25
-
26
- afterEach(cleanup);
27
-
28
- describe('message actions', () => {
29
- it('offers Reply, React and Copy for incoming messages, adding Edit and Delete only for authors or moderators', () => {
30
- const mine = { id: 1, body: 'Mine', sender: { id: 1 } };
31
- const theirs = { id: 2, body: 'Theirs', sender: { id: 2 } };
32
- const { unmount } = renderBubble(mine);
33
- expect(screen.getByRole('button', { name: 'MessagingActions.MENU' })).toBeTruthy();
34
- openActions();
35
- ['MessagingThread.REPLY', 'MessagingReactions.ADD', 'MessagingActions.EDIT', 'MessagingActions.DELETE', 'MessagingActions.COPY'].forEach((name) => expect(screen.getByRole('menuitem', { name })).toBeTruthy());
36
- fireEvent.click(screen.getByRole('menuitem', { name: 'MessagingReactions.ADD' }));
37
- expect(screen.getByLabelText('MessagingReactions.LABEL')).toBeTruthy();
38
- expect(screen.getByText('👍')).toBeTruthy();
39
- unmount();
40
- renderBubble(theirs);
41
- expect(screen.getByRole('button', { name: 'MessagingActions.MENU' })).toBeTruthy();
42
- openActions();
43
- ['MessagingThread.REPLY', 'MessagingReactions.ADD', 'MessagingActions.COPY'].forEach((name) => expect(screen.getByRole('menuitem', { name })).toBeTruthy());
44
- expect(screen.queryByRole('menuitem', { name: 'MessagingActions.EDIT' })).toBeNull();
45
- expect(screen.queryByRole('menuitem', { name: 'MessagingActions.DELETE' })).toBeNull();
46
- cleanup();
47
- renderBubble(theirs, { canModerateMessages: true });
48
- expect(screen.getByRole('button', { name: 'MessagingActions.MENU' })).toBeTruthy();
49
- cleanup();
50
- renderBubble({ ...mine, deleted_at: '2026-07-31T10:00:00Z' });
51
- expect(screen.queryByRole('button', { name: 'MessagingActions.MENU' })).toBeNull();
52
- cleanup();
53
- renderBubble({ ...mine, kind: 'poll' });
54
- expect(screen.getByRole('button', { name: 'MessagingActions.MENU' })).toBeTruthy();
55
- });
56
-
57
- it('opens the affordance from a tap and lets a keyboard user reveal and operate it', () => {
58
- const onReply = vi.fn();
59
- const { container } = renderBubble({ id: 3, body: 'Touch me', sender: { id: 2 } }, { onReply });
60
- const bubble = container.querySelector('[data-message-id="3"] .MuiPaper-root');
61
- fireEvent.click(bubble);
62
- expect(bubble.getAttribute('data-actions-visible')).toBe('true');
63
- const actions = screen.getByRole('button', { name: 'MessagingActions.MENU' });
64
- fireEvent.focus(actions);
65
- fireEvent.click(actions);
66
- fireEvent.click(screen.getByRole('menuitem', { name: 'MessagingThread.REPLY' }));
67
- expect(onReply).toHaveBeenCalledWith(expect.objectContaining({ id: 3 }));
68
- });
69
-
70
- it('dismisses the tap-revealed affordance again on an outside interaction, but not on a reaction-picker click inside the same bubble', () => {
71
- const { container } = renderBubble({ id: 3, body: 'Touch me', sender: { id: 2 }, reactions: [{ emoji: '👍', count: 1, reacted: false }] });
72
- const bubble = container.querySelector('[data-message-id="3"] .MuiPaper-root');
73
- fireEvent.click(bubble);
74
- expect(bubble.getAttribute('data-actions-visible')).toBe('true');
75
- // A pointerdown inside the same message's own reaction row (a sibling of
76
- // the Paper, still within the article) must not count as "outside" —
77
- // otherwise every reaction click would prematurely hide the affordance.
78
- fireEvent.pointerDown(screen.getByText('👍 1'));
79
- expect(bubble.getAttribute('data-actions-visible')).toBe('true');
80
- // A pointerdown genuinely outside the message dismisses it — this is the
81
- // U1 fix: without it, the affordance stayed pinned visible forever after
82
- // any click that bubbled up to the bubble (Part A's "no visible
83
- // affordance at rest" requirement).
84
- fireEvent.pointerDown(document.body);
85
- expect(bubble.getAttribute('data-actions-visible')).toBeNull();
86
- });
87
-
88
- it('keeps each message bubble\'s tap-reveal state independent — revealing one does not dismiss another', () => {
89
- const api = makeApi();
90
- const { container } = render(
91
- <AuthContext.Provider value={{ user: { id: 1 } }}>
92
- <MessagingProvider api={api} active={false}>
93
- <MessageBubble message={{ id: 10, body: 'First', sender: { id: 2 } }} />
94
- <MessageBubble message={{ id: 11, body: 'Second', sender: { id: 2 } }} />
95
- </MessagingProvider>
96
- </AuthContext.Provider>
97
- );
98
- const bubbleA = container.querySelector('[data-message-id="10"] .MuiPaper-root');
99
- const bubbleB = container.querySelector('[data-message-id="11"] .MuiPaper-root');
100
- fireEvent.pointerDown(bubbleA);
101
- fireEvent.click(bubbleA);
102
- expect(bubbleA.getAttribute('data-actions-visible')).toBe('true');
103
- expect(bubbleB.getAttribute('data-actions-visible')).toBeNull();
104
- // Tapping bubble B is, from bubble A's perspective, an outside
105
- // interaction — A dismisses, B reveals; the two must never share state.
106
- // (A real tap fires pointerdown before click; fireEvent.click alone
107
- // wouldn't exercise the pointerdown-driven dismiss listener.)
108
- fireEvent.pointerDown(bubbleB);
109
- fireEvent.click(bubbleB);
110
- expect(bubbleA.getAttribute('data-actions-visible')).toBeNull();
111
- expect(bubbleB.getAttribute('data-actions-visible')).toBe('true');
112
- });
113
-
114
- it('edits an author message through the API and auto-cancels when deleted elsewhere', async () => {
115
- const api = makeApi();
116
- const message = { id: 4, body: 'Before', sender: { id: 1 } };
117
- const { rerender } = renderBubble(message, { api });
118
- openActions();
119
- fireEvent.click(screen.getByRole('menuitem', { name: 'MessagingActions.EDIT' }));
120
- const field = screen.getByRole('textbox', { name: 'MessagingActions.EDIT' });
121
- fireEvent.change(field, { target: { value: 'After' } });
122
- fireEvent.click(screen.getByRole('button', { name: 'MessagingActions.SAVE' }));
123
- await waitFor(() => expect(api.patchMessage).toHaveBeenCalledWith(4, { body: 'After' }));
124
- openActions();
125
- fireEvent.click(screen.getByRole('menuitem', { name: 'MessagingActions.EDIT' }));
126
- expect(screen.getByRole('textbox', { name: 'MessagingActions.EDIT' })).toBeTruthy();
127
- rerender(<AuthContext.Provider value={{ user: { id: 1 } }}><MessagingProvider api={api} active={false}><MessageBubble message={{ ...message, deleted_at: '2026-07-31T10:02:00Z' }} /></MessagingProvider></AuthContext.Provider>);
128
- await waitFor(() => expect(screen.queryByRole('textbox', { name: 'MessagingActions.EDIT' })).toBeNull());
129
- });
130
-
131
- it('requires confirmation before author or moderator deletion reaches the API', async () => {
132
- const api = makeApi();
133
- const { rerender } = renderBubble({ id: 5, body: 'Delete me', sender: { id: 1 } }, { api });
134
- openActions();
135
- fireEvent.click(screen.getByRole('menuitem', { name: 'MessagingActions.DELETE' }));
136
- expect(api.deleteMessage).not.toHaveBeenCalled();
137
- fireEvent.click(screen.getByRole('button', { name: 'MessagingActions.DELETE' }));
138
- await waitFor(() => expect(api.deleteMessage).toHaveBeenCalledWith(5));
139
- await waitFor(() => expect(screen.queryByRole('dialog')).toBeNull());
140
- const moderatorApi = makeApi();
141
- rerender(<AuthContext.Provider value={{ user: { id: 1 } }}><MessagingProvider api={moderatorApi} active={false}><MessageBubble message={{ id: 6, body: 'Moderator delete', sender: { id: 2 } }} canModerateMessages /></MessagingProvider></AuthContext.Provider>);
142
- openActions();
143
- fireEvent.click(screen.getByRole('menuitem', { name: 'MessagingActions.DELETE' }));
144
- fireEvent.click(screen.getByRole('button', { name: 'MessagingActions.DELETE' }));
145
- await waitFor(() => expect(moderatorApi.deleteMessage).toHaveBeenCalledWith(6));
146
- });
147
-
148
- it('clears a deleted reply target and copies the exact message body', async () => {
149
- const onReplyTargetChange = vi.fn();
150
- const replyTarget = { id: 7, body: 'Reply source', sender: { display_name: 'Ava' } };
151
- const { rerender } = render(<MessagingProvider api={makeApi()} active={false}><Composer conversationId={1} replyTarget={replyTarget} onReplyTargetChange={onReplyTargetChange} /></MessagingProvider>);
152
- onReplyTargetChange.mockClear();
153
- rerender(<MessagingProvider api={makeApi()} active={false}><Composer conversationId={1} replyTarget={{ ...replyTarget, deleted_at: '2026-07-31T10:00:00Z' }} onReplyTargetChange={onReplyTargetChange} /></MessagingProvider>);
154
- await waitFor(() => expect(onReplyTargetChange).toHaveBeenCalledWith(null));
155
-
156
- const writeText = vi.fn().mockResolvedValue(undefined);
157
- Object.defineProperty(navigator, 'clipboard', { configurable: true, value: { writeText } });
158
- renderBubble({ id: 8, body: 'Copy exactly this', sender: { id: 1 } });
159
- openActions();
160
- fireEvent.click(screen.getByRole('menuitem', { name: 'MessagingActions.COPY' }));
161
- await waitFor(() => expect(writeText).toHaveBeenCalledWith('Copy exactly this'));
162
- });
163
- });
@@ -1,105 +0,0 @@
1
- // @vitest-environment jsdom
2
- import React from 'react';
3
- import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest';
4
- import { act, cleanup, fireEvent, render, screen, waitFor } from '@testing-library/react';
5
-
6
- // Thread.jsx (MSG-6f scope C) now subscribes to the messaging envelope
7
- // independently of MessagingProvider's own subscription -- a Set of handlers,
8
- // not a single captured variable, so frameHandler(...) still reaches every
9
- // current subscriber, matching the real registry's multi-handler support.
10
- let frameHandlers;
11
- function frameHandler(frame) { frameHandlers.forEach((handler) => handler(frame)); }
12
- vi.mock('react-i18next', () => ({ useTranslation: () => ({ t: (key, options) => options?.count != null ? `${key}:${options.count}` : key, i18n: { language: 'de-DE' } }) }));
13
- vi.mock('../src/notifications/realtime', () => ({ useRealtime: () => ({ subscribe: (_envelope, handler) => { frameHandlers.add(handler); return () => frameHandlers.delete(handler); }, onReconnect: () => () => {} }) }));
14
-
15
- import { MessageBubble } from '../src/messaging/MessageBubble';
16
- import { ConversationList } from '../src/messaging/ConversationList';
17
- import { applyFrame, MessagingProvider, useMessaging } from '../src/messaging/MessagingProvider';
18
- import { ReadTicks } from '../src/messaging/ReadTicks';
19
- import { Thread } from '../src/messaging/Thread';
20
- import { messagingTranslations } from '../src/i18n/messagingTranslations';
21
- import { AuthContext } from '../src/auth/AuthContext';
22
-
23
- const api = (overrides = {}) => ({ listConversations: vi.fn().mockResolvedValue({ results: [{ id: 'c1', kind: 'group' }] }), listMessages: vi.fn().mockResolvedValue({ results: [] }), listThread: vi.fn().mockResolvedValue({ results: [] }), getUnreadCount: vi.fn().mockResolvedValue({ unread_count: 0, by_conversation: {} }), getReadStatus: vi.fn().mockResolvedValue({ all_read: false, read_count: 0, recipient_count: 1, recipient_detail: [{ user_id: 'u2', display_name: 'Ava' }] }), markConversationRead: vi.fn().mockResolvedValue({}), ...overrides });
24
- const state = () => ({ conversations: {}, messages: {}, threads: {}, polls: {}, reactions: {}, receipts: {}, unread: { unread_count: 0, by_conversation: {} }, cursors: { conversations: null, messages: {}, threads: {} } });
25
- beforeEach(() => { frameHandlers = new Set(); });
26
- afterEach(cleanup);
27
-
28
- function PollHarness() { const { createConversationPoll, cache } = useMessaging(); return <><button onClick={() => createConversationPoll('c1', { question: 'Q' })}>create</button><output>{JSON.stringify(cache.messages)}</output></>; }
29
-
30
- describe('MSG-6 messaging regressions', () => {
31
- it('uses the server message_id, never the poll id, for a newly-created poll cache row', async () => {
32
- const client = api({ createPoll: vi.fn().mockResolvedValue({ id: 'poll-9', message_id: 'message-9', question: 'Q', options: [] }) });
33
- render(<MessagingProvider api={client} active={false}><PollHarness /></MessagingProvider>);
34
- await act(async () => screen.getByText('create').click());
35
- const messages = JSON.parse(screen.getByText((_, node) => node.tagName === 'OUTPUT').textContent);
36
- expect(Object.keys(messages)).toEqual(['message-9']);
37
- expect(messages['message-9'].created_at).toBeTruthy();
38
- expect(messages['poll-9']).toBeUndefined();
39
- });
40
-
41
- it('renders time-only metadata in the active locale and one separator per changed root day', async () => {
42
- const time = vi.spyOn(Date.prototype, 'toLocaleTimeString'); time.mockReturnValue('10:41');
43
- render(<MessageBubble message={{ id: 1, body: 'Hi', created_at: '2026-08-03T10:41:00Z' }} />);
44
- expect(await screen.findByText('10:41')).toBeTruthy();
45
- expect(time).toHaveBeenCalledWith('de-DE', { hour: '2-digit', minute: '2-digit' });
46
- time.mockRestore();
47
- const client = api({ listMessages: vi.fn().mockResolvedValue({ results: [{ id: 1, conversation_id: 'c1', body: 'one', created_at: '2026-08-01T10:00:00Z' }, { id: 2, conversation_id: 'c1', body: 'two', created_at: '2026-08-01T11:00:00Z' }, { id: 3, conversation_id: 'c1', body: 'three', created_at: '2026-08-02T10:00:00Z' }] }) });
48
- render(<MessagingProvider api={client}><Thread conversationId="c1" /></MessagingProvider>);
49
- await screen.findByText('three');
50
- expect(screen.getAllByTestId('day-separator')).toHaveLength(1);
51
- });
52
-
53
- it('applies read frames to cache (for the per-person popover) but the group read ratio stays dcm\'s own numbers, not recomputed', async () => {
54
- const client = api();
55
- render(<MessagingProvider api={client} active={false}><ReadTicks messageId="m1" conversation={{ id: 'c1', kind: 'group' }} /></MessagingProvider>);
56
- const tick = await screen.findByLabelText('MessagingReadTicks.READ_RATIO');
57
- expect(tick.textContent).toBe('0/1');
58
- act(() => frameHandler({ type: 'read_state', conversation_id: 'c1', user_id: 'u2', last_read_at: '2026-08-03T10:00:00Z' }));
59
- // Deliberate, documented trade-off (see ReadTicks.jsx): the numeric ratio
60
- // is dcm's own read_count/recipient_count verbatim, never recomputed from
61
- // recipientDetail -- recipientDetail has no way to threshold against
62
- // this specific message's created_at, only dcm's own aggregate does.
63
- // So a read_state frame updates the *popover's* per-person list (proven
64
- // by the receipts assertion below) but the ratio digits only change on
65
- // the next read-status fetch, same as before this frame arrived.
66
- await new Promise((resolve) => setTimeout(resolve, 20));
67
- expect(screen.getByLabelText('MessagingReadTicks.READ_RATIO').textContent).toBe('0/1');
68
- expect(client.getReadStatus).toHaveBeenCalledTimes(1);
69
- const next = applyFrame(state(), { type: 'thread_read_state', root_id: 'root-1', user_id: 'u2', last_read_at: '2026-08-03T10:00:00Z' });
70
- expect(next.receipts['thread:root-1:u2'].last_read_at).toBe('2026-08-03T10:00:00Z');
71
- });
72
-
73
- it('updates direct-conversation ReadTicks from a read frame without another REST call', async () => {
74
- const client = api({ getReadStatus: vi.fn().mockResolvedValue({ all_read: false }) });
75
- render(<MessagingProvider api={client} active={false}><ReadTicks messageId="m1" conversation={{ id: 'c1', kind: 'direct', other_user_id: 'u2' }} /></MessagingProvider>);
76
- await screen.findByLabelText('MessagingReadTicks.SENT');
77
- act(() => frameHandler({ type: 'read_state', conversation_id: 'c1', user_id: 'u2', last_read_at: '2026-08-03T10:00:00Z' }));
78
- await screen.findByLabelText('MessagingReadTicks.ALL_READ');
79
- expect(client.getReadStatus).toHaveBeenCalledTimes(1);
80
- });
81
-
82
- it('keeps Thread as the sole read-mark owner for direct mounts and list opens', async () => {
83
- const client = api({ listMessages: vi.fn().mockResolvedValue({ results: [] }) });
84
- function Surface() { const [conversationId, setConversationId] = React.useState(null); return <MessagingProvider api={client}><ConversationList onOpen={(conversation) => setConversationId(conversation.id)} />{conversationId && <Thread conversationId={conversationId} />}</MessagingProvider>; }
85
- render(<Surface />);
86
- await screen.findByText('MessagingList.UNTITLED');
87
- fireEvent.click(screen.getByText('MessagingList.UNTITLED'));
88
- await waitFor(() => expect(client.markConversationRead).toHaveBeenCalledTimes(1));
89
- client.markConversationRead.mockClear();
90
- render(<MessagingProvider api={client} active={false}><Thread conversationId="c1" /></MessagingProvider>);
91
- await waitFor(() => expect(client.markConversationRead).toHaveBeenCalledTimes(1));
92
- });
93
-
94
- it('updates the rendered thread unread state from a thread_read_state frame', async () => {
95
- const client = api({ listMessages: vi.fn().mockResolvedValue({ results: [{ id: 'root-1', conversation_id: 'c1', body: 'Root', sender: { id: 'u1' }, reply_count: 1, last_reply_at: '2026-08-03T10:00:00Z', thread_last_read_at: null }] }) });
96
- render(<AuthContext.Provider value={{ user: { id: 'u2' } }}><MessagingProvider api={client}><Thread conversationId="c1" /></MessagingProvider></AuthContext.Provider>);
97
- await screen.findByLabelText(/MessagingThread.UNREAD_REPLIES/);
98
- act(() => frameHandler({ type: 'thread_read_state', root_id: 'root-1', user_id: 'u2', last_read_at: '2026-08-03T11:00:00Z' }));
99
- await waitFor(() => expect(screen.queryByLabelText(/MessagingThread.UNREAD_REPLIES/)).toBeNull());
100
- });
101
-
102
- it('defines singular reply labels for de, en, fr, and sw', () => {
103
- expect(messagingTranslations['MessagingThread.SHOW_REPLIES_one']).toEqual({ de: '{{count}} Antwort anzeigen', en: 'Show {{count}} reply', fr: 'Afficher {{count}} réponse', sw: 'Onyesha jibu {{count}}' });
104
- });
105
- });
@@ -1,155 +0,0 @@
1
- // @vitest-environment jsdom
2
- import React from 'react';
3
- import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest';
4
- import { act, cleanup, render, screen, waitFor } from '@testing-library/react';
5
- import { ThemeProvider, createTheme } from '@mui/material/styles';
6
-
7
- // Thread.jsx (scope C) subscribes to the messaging envelope independently of
8
- // MessagingProvider's own subscription -- a Set of handlers per envelope, not
9
- // one, so a dispatched frame reaches every current subscriber.
10
- let frameHandlers;
11
- function dispatchFrame(frame) { frameHandlers.forEach((handler) => handler(frame)); }
12
- vi.mock('react-i18next', () => ({ useTranslation: () => ({ t: (key, options) => options && Object.keys(options).length ? `${key}:${JSON.stringify(options)}` : key, i18n: { language: 'en' } }) }));
13
- vi.mock('../src/notifications/realtime', () => ({
14
- useRealtime: () => ({
15
- subscribe: (_envelope, handler) => { frameHandlers.add(handler); return () => frameHandlers.delete(handler); },
16
- onReconnect: () => () => {},
17
- }),
18
- }));
19
-
20
- import { AuthContext } from '../src/auth/AuthContext';
21
- import { MessagingProvider } from '../src/messaging/MessagingProvider';
22
- import { ReadTicks } from '../src/messaging/ReadTicks';
23
- import { Thread } from '../src/messaging/Thread';
24
-
25
- const theme = createTheme();
26
- function withTheme(children) { return <ThemeProvider theme={theme}>{children}</ThemeProvider>; }
27
-
28
- function makeApi(overrides = {}) {
29
- return {
30
- listConversations: vi.fn().mockResolvedValue({ results: [] }),
31
- listMessages: vi.fn().mockResolvedValue({ results: [] }),
32
- listThread: vi.fn().mockResolvedValue({ results: [] }),
33
- getUnreadCount: vi.fn().mockResolvedValue({ unread_count: 0, by_conversation: {} }),
34
- markConversationRead: vi.fn().mockResolvedValue({}),
35
- getReadStatus: vi.fn().mockResolvedValue({ all_read: false }),
36
- ...overrides,
37
- };
38
- }
39
-
40
- beforeEach(() => { frameHandlers = new Set(); });
41
- afterEach(cleanup);
42
-
43
- describe('MSG-6f scope B: read ratio vs two-state tick', () => {
44
- it('4a: a direct conversation renders a two-state tick, and the two states resolve to visibly different colours', async () => {
45
- const api = makeApi({ getReadStatus: vi.fn().mockResolvedValue({ all_read: false }) });
46
- const { rerender } = render(withTheme(
47
- <MessagingProvider api={api} active={false}><ReadTicks messageId="m1" conversation={{ id: 'c1', kind: 'direct' }} /></MessagingProvider>
48
- ));
49
- const sentIcon = await screen.findByLabelText('MessagingReadTicks.SENT');
50
- const sentColor = getComputedStyle(sentIcon).color;
51
-
52
- api.getReadStatus.mockResolvedValue({ all_read: true });
53
- cleanup();
54
- render(withTheme(
55
- <MessagingProvider api={api} active={false}><ReadTicks messageId="m1" conversation={{ id: 'c1', kind: 'direct' }} /></MessagingProvider>
56
- ));
57
- const readIcon = await screen.findByLabelText('MessagingReadTicks.ALL_READ');
58
- const readColor = getComputedStyle(readIcon).color;
59
-
60
- expect(sentColor).toBeTruthy();
61
- expect(readColor).toBeTruthy();
62
- expect(sentColor).not.toBe(readColor);
63
- });
64
-
65
- it('4b: a group WITH counts renders dcm\'s own read_count/recipient_count verbatim, never recomputed from recipientDetail (must fail if recomputed -- recipientDetail is not thresholded against this message\'s created_at, only dcm\'s own counts are)', async () => {
66
- // Deliberately inconsistent with read_count/recipient_count: every
67
- // participant has SOME last_read_at (e.g. from reading the conversation
68
- // long before this message existed), which is exactly the shape that
69
- // would make a naive "count non-null last_read_at" recomputation report
70
- // 40/40 -- the bug caught in review. dcm's own read_count (18) is the
71
- // only correct source; recipientDetail must not be trusted for the ratio.
72
- const allEverRead = Array.from({ length: 40 }, (_, i) => ({ user_id: `u-${i}`, last_read_at: '2020-01-01T00:00:00Z' }));
73
- const api = makeApi({ getReadStatus: vi.fn().mockResolvedValue({ all_read: false, read_count: 18, recipient_count: 40, recipient_detail: allEverRead }) });
74
- render(<MessagingProvider api={api} active={false}><ReadTicks messageId="m1" conversation={{ id: 'c1', kind: 'group' }} /></MessagingProvider>);
75
- const ratio = await screen.findByLabelText(/READ_RATIO/);
76
- expect(ratio.textContent).toBe('18/40');
77
- expect(document.body.querySelector('[data-testid="DoneOutlinedIcon"]')).toBeNull();
78
- expect(document.body.querySelector('[data-testid="DoneAllOutlinedIcon"]')).toBeNull();
79
- expect(document.body.textContent).not.toMatch(/Zugestellt/);
80
- });
81
-
82
- it('4c: a group WITHOUT counts (an ordinary participant) renders no indicator at all', async () => {
83
- const api = makeApi({ getReadStatus: vi.fn().mockResolvedValue({ all_read: false }) });
84
- const { container } = render(<MessagingProvider api={api} active={false}><ReadTicks messageId="m1" conversation={{ id: 'c1', kind: 'group' }} /></MessagingProvider>);
85
- await waitFor(() => expect(api.getReadStatus).toHaveBeenCalled());
86
- expect(container.textContent).toBe('');
87
- expect(container.querySelector('svg')).toBeNull();
88
- });
89
-
90
- it('5: all_read still renders the double check with its own unchanged label', async () => {
91
- const api = makeApi({ getReadStatus: vi.fn().mockResolvedValue({ all_read: true }) });
92
- render(<MessagingProvider api={api} active={false}><ReadTicks messageId="m1" conversation={{ id: 'c1', kind: 'direct' }} /></MessagingProvider>);
93
- const icon = await screen.findByLabelText('MessagingReadTicks.ALL_READ');
94
- expect(icon.getAttribute('data-testid')).toBe('DoneAllOutlinedIcon');
95
- });
96
- });
97
-
98
- describe('MSG-6f scope C: re-mark read on a live message frame for the open conversation', () => {
99
- function renderThread(api, { userId = 1 } = {}) {
100
- return render(
101
- <AuthContext.Provider value={{ user: { id: userId } }}>
102
- <MessagingProvider api={api}><Thread conversationId="c1" /></MessagingProvider>
103
- </AuthContext.Provider>
104
- );
105
- }
106
-
107
- it('marks read again when a message frame arrives for the currently-open conversation', async () => {
108
- const api = makeApi();
109
- renderThread(api);
110
- await waitFor(() => expect(api.markConversationRead).toHaveBeenCalledTimes(1));
111
- api.markConversationRead.mockClear();
112
-
113
- act(() => dispatchFrame({ type: 'message', conversation_id: 'c1', message: { id: 'm2', conversation_id: 'c1', sender: { id: 2 } } }));
114
-
115
- await waitFor(() => expect(api.markConversationRead).toHaveBeenCalled());
116
- expect(api.markConversationRead.mock.calls[0][0]).toBe('c1');
117
- });
118
-
119
- it('does not re-mark for a message frame belonging to a different conversation', async () => {
120
- const api = makeApi();
121
- renderThread(api);
122
- await waitFor(() => expect(api.markConversationRead).toHaveBeenCalledTimes(1));
123
- api.markConversationRead.mockClear();
124
-
125
- act(() => dispatchFrame({ type: 'message', conversation_id: 'other-conversation', message: { id: 'm2' } }));
126
-
127
- await new Promise((resolve) => setTimeout(resolve, 50));
128
- expect(api.markConversationRead).not.toHaveBeenCalled();
129
- });
130
-
131
- it('does not re-mark while the document is hidden', async () => {
132
- const api = makeApi();
133
- renderThread(api);
134
- await waitFor(() => expect(api.markConversationRead).toHaveBeenCalledTimes(1));
135
- api.markConversationRead.mockClear();
136
-
137
- const visibilitySpy = vi.spyOn(document, 'visibilityState', 'get').mockReturnValue('hidden');
138
- act(() => dispatchFrame({ type: 'message', conversation_id: 'c1', message: { id: 'm2' } }));
139
- await new Promise((resolve) => setTimeout(resolve, 50));
140
- expect(api.markConversationRead).not.toHaveBeenCalled();
141
- visibilitySpy.mockRestore();
142
- });
143
-
144
- it('does not re-mark for a non-message frame type (e.g. reaction) for the same conversation', async () => {
145
- const api = makeApi();
146
- renderThread(api);
147
- await waitFor(() => expect(api.markConversationRead).toHaveBeenCalledTimes(1));
148
- api.markConversationRead.mockClear();
149
-
150
- act(() => dispatchFrame({ type: 'reaction', conversation_id: 'c1', message_id: 'm2' }));
151
-
152
- await new Promise((resolve) => setTimeout(resolve, 50));
153
- expect(api.markConversationRead).not.toHaveBeenCalled();
154
- });
155
- });
@@ -1,166 +0,0 @@
1
- // @vitest-environment jsdom
2
- import React from 'react';
3
- import { afterEach, describe, expect, it, vi } from 'vitest';
4
- import { cleanup, fireEvent, render, screen, waitFor } from '@testing-library/react';
5
-
6
- vi.mock('react-i18next', () => ({ useTranslation: () => ({ t: (key, options) => options && Object.keys(options).length ? `${key}:${JSON.stringify(options)}` : key }) }));
7
-
8
- const realtimeSubscribers = new Map();
9
- vi.mock('../src/notifications/realtime', () => ({
10
- useRealtime: () => ({
11
- subscribe: (envelope, handler) => { realtimeSubscribers.set(envelope, handler); return () => realtimeSubscribers.delete(envelope); },
12
- onReconnect: () => () => {},
13
- }),
14
- }));
15
- function dispatchMessagingFrame(frame) { realtimeSubscribers.get('messaging')?.(frame); }
16
-
17
- import { PollCard } from '../src/messaging/PollCard';
18
- import { MessagingProvider, useMessaging } from '../src/messaging/MessagingProvider';
19
-
20
- function baseApi(overrides = {}) {
21
- return {
22
- listConversations: vi.fn().mockResolvedValue({ results: [] }), listMessages: vi.fn().mockResolvedValue({ results: [] }),
23
- getUnreadCount: vi.fn().mockResolvedValue({ unread_count: 0, by_conversation: {} }),
24
- votePoll: vi.fn(), closePoll: vi.fn(),
25
- ...overrides,
26
- };
27
- }
28
- function serverPoll(overrides = {}) {
29
- return {
30
- id: 'poll-1', question: 'Q', allow_multiple: false, closed_at: null, created_by_id: 'user-9',
31
- options: [
32
- { id: 'opt-a', text: 'A', order: 0, vote_count: 0, voters: [] },
33
- { id: 'opt-b', text: 'B', order: 1, vote_count: 0, voters: [] },
34
- ],
35
- ...overrides,
36
- };
37
- }
38
- function ConnectedPollCard({ messageId }) {
39
- const { cache } = useMessaging();
40
- return <PollCard message={cache.messages[messageId]} />;
41
- }
42
- function CachePollState({ messageId }) {
43
- const { cache } = useMessaging();
44
- return <output data-testid="cache-poll">{JSON.stringify(cache.messages[messageId]?.poll)}</output>;
45
- }
46
-
47
- afterEach(() => { cleanup(); realtimeSubscribers.clear(); });
48
-
49
- describe('MSG-6g: tap-to-vote poll UI with result bars', () => {
50
- it('1. single-choice: tapping an option votes without further interaction; tapping a second option moves the vote', async () => {
51
- const api = baseApi();
52
- api.votePoll.mockResolvedValueOnce({ poll: { ...serverPoll(), voted_option_ids: ['opt-a'], options: [{ id: 'opt-a', text: 'A', order: 0, vote_count: 1, voters: ['me'] }, { id: 'opt-b', text: 'B', order: 1, vote_count: 0, voters: [] }] } });
53
- api.votePoll.mockResolvedValueOnce({ poll: { ...serverPoll(), voted_option_ids: ['opt-b'], options: [{ id: 'opt-a', text: 'A', order: 0, vote_count: 0, voters: [] }, { id: 'opt-b', text: 'B', order: 1, vote_count: 1, voters: ['me'] }] } });
54
- render(<MessagingProvider api={api} active={false}><PollCard message={{ id: 'msg-1', poll: serverPoll() }} /></MessagingProvider>);
55
- const radios = screen.getAllByRole('radio');
56
-
57
- fireEvent.click(radios[0]);
58
- await waitFor(() => expect(api.votePoll).toHaveBeenCalledWith('poll-1', ['opt-a']));
59
- expect(radios[0].checked).toBe(true);
60
-
61
- fireEvent.click(radios[1]);
62
- await waitFor(() => expect(api.votePoll).toHaveBeenCalledWith('poll-1', ['opt-b']));
63
- await waitFor(() => expect(radios[1].checked).toBe(true));
64
- expect(radios[0].checked).toBe(false);
65
- });
66
-
67
- it('2. multi-select: tapping toggles one option on and off, and each tap sends the complete option-id set', async () => {
68
- const api = baseApi();
69
- api.votePoll.mockResolvedValue({ poll: serverPoll({ allow_multiple: true }) });
70
- render(<MessagingProvider api={api} active={false}><PollCard message={{ id: 'msg-1', poll: serverPoll({ allow_multiple: true }) }} /></MessagingProvider>);
71
- const checkboxes = screen.getAllByRole('checkbox');
72
-
73
- fireEvent.click(checkboxes[0]);
74
- await waitFor(() => expect(api.votePoll).toHaveBeenCalledWith('poll-1', ['opt-a']));
75
- fireEvent.click(checkboxes[1]);
76
- await waitFor(() => expect(api.votePoll).toHaveBeenCalledWith('poll-1', ['opt-a', 'opt-b']));
77
- fireEvent.click(checkboxes[0]);
78
- await waitFor(() => expect(api.votePoll).toHaveBeenCalledWith('poll-1', ['opt-b']));
79
- expect(api.votePoll).toHaveBeenCalledTimes(3);
80
- });
81
-
82
- it('3. a rejected vote reverts the optimistic state and surfaces an error -- the reverted value, not merely an error message', async () => {
83
- const api = baseApi();
84
- api.votePoll.mockRejectedValue({ response: { data: { detail: 'Voting disabled' } } });
85
- render(<MessagingProvider api={api} active={false}><PollCard message={{ id: 'msg-1', poll: serverPoll() }} /></MessagingProvider>);
86
- const radios = screen.getAllByRole('radio');
87
-
88
- fireEvent.click(radios[0]);
89
- // Optimistic: briefly checked before the rejection resolves.
90
- await waitFor(() => expect(radios[0].checked).toBe(true));
91
- await screen.findByRole('alert');
92
- await waitFor(() => expect(radios[0].checked).toBe(false));
93
- expect(radios[1].checked).toBe(false);
94
- });
95
-
96
- it('4. bars render proportionally, including the zero-vote case, with no NaN and no division error', () => {
97
- render(<MessagingProvider api={baseApi()} active={false}><PollCard message={{ id: 'msg-1', poll: serverPoll() }} /></MessagingProvider>);
98
- // vote_count 0/0 for both options -> 0%, never NaN%.
99
- const results = screen.getAllByText(/MessagingPoll\.OPTION_RESULT/);
100
- expect(results).toHaveLength(2);
101
- results.forEach((node) => {
102
- expect(node.textContent).toMatch(/"count":0/);
103
- expect(node.textContent).toMatch(/"percent":0/);
104
- expect(node.textContent).not.toMatch(/NaN/);
105
- });
106
- });
107
-
108
- it('5. the viewer\'s own selection survives a poll_updated frame that does not carry voted_option_ids (merge-trap guard)', async () => {
109
- const api = baseApi();
110
- render(<MessagingProvider api={api} active={false}><ConnectedPollCard messageId="msg-1" /></MessagingProvider>);
111
- dispatchMessagingFrame({ envelope: 'messaging', type: 'message', event_id: 'seed', conversation_id: 'conv-1', message: { id: 'msg-1', conversation_id: 'conv-1', kind: 'poll', poll: serverPoll({ voted_option_ids: ['opt-a'], options: [{ id: 'opt-a', text: 'A', order: 0, vote_count: 1, voters: ['me'] }, { id: 'opt-b', text: 'B', order: 1, vote_count: 0, voters: [] }] }) } });
112
- await waitFor(() => expect(screen.getAllByRole('radio')[0].checked).toBe(true));
113
-
114
- // A poll_updated frame never carries voted_option_ids (dcm's serialize_poll
115
- // is viewer-independent) -- must not wipe the REST-known selection.
116
- dispatchMessagingFrame({
117
- envelope: 'messaging', type: 'poll_updated', event_id: 'evt-1', conversation_id: 'conv-1', message_id: 'msg-1', poll_id: 'poll-1',
118
- poll: serverPoll({ options: [{ id: 'opt-a', text: 'A', order: 0, vote_count: 2, voters: ['me', 'other'] }, { id: 'opt-b', text: 'B', order: 1, vote_count: 0, voters: [] }] }),
119
- });
120
- await waitFor(() => expect(screen.getByText(/MessagingPoll\.OPTION_RESULT.*"count":2/)).toBeTruthy());
121
- expect(screen.getAllByRole('radio')[0].checked).toBe(true);
122
- });
123
-
124
- it('6. a closed poll is non-interactive: tapping an option does nothing and issues no request', () => {
125
- const api = baseApi();
126
- render(<MessagingProvider api={api} active={false}><PollCard message={{ id: 'msg-1', poll: serverPoll({ closed_at: '2026-08-01T00:00:00Z' }) }} /></MessagingProvider>);
127
- const radios = screen.getAllByRole('radio');
128
- fireEvent.click(radios[0]);
129
- expect(api.votePoll).not.toHaveBeenCalled();
130
- expect(radios[0].checked).toBe(false);
131
- });
132
-
133
- it('a rapid switch (A then B, before the first vote confirms) projects counts from the freshest cache state, not a stale prop (regression)', async () => {
134
- // MessagingProvider.castPollVote must build its optimistic count delta from
135
- // `previousPoll` (freshly read from the shared cache at call time), never
136
- // from the caller-supplied `poll` argument. PollCard is deliberately given
137
- // a STATIC message prop here (never re-rendered with a fresh one between
138
- // taps, exactly like PollCard's own documented "dumb, prop-driven"
139
- // contract, and exactly how a host that doesn't re-connect it to live
140
- // cache updates would behave) -- a separate, genuinely cache-connected
141
- // reader (CachePollState) is what must show the correct number. Starting
142
- // counts are non-zero so a wrong baseline isn't masked by the
143
- // Math.max(0, ...) clamp.
144
- const api = baseApi();
145
- api.votePoll.mockReturnValue(new Promise(() => {})); // never resolves -- isolate the optimistic phase
146
- const seedPoll = serverPoll({
147
- voted_option_ids: [],
148
- options: [
149
- { id: 'opt-a', text: 'A', order: 0, vote_count: 5, voters: ['u1', 'u2', 'u3', 'u4', 'u5'] },
150
- { id: 'opt-b', text: 'B', order: 1, vote_count: 2, voters: ['u6', 'u7'] },
151
- ],
152
- });
153
- render(<MessagingProvider api={api} active={false}><PollCard message={{ id: 'msg-1', poll: seedPoll }} /><CachePollState messageId="msg-1" /></MessagingProvider>);
154
- const radios = screen.getAllByRole('radio');
155
-
156
- fireEvent.click(radios[0]); // vote A: 5 -> 6
157
- await waitFor(() => expect(JSON.parse(screen.getByTestId('cache-poll').textContent).options.find((option) => option.id === 'opt-a').vote_count).toBe(6));
158
-
159
- fireEvent.click(radios[1]); // switch to B: A must go 6 -> 5 in the shared cache (a stale-prop baseline of 5 would wrongly compute 4)
160
- await waitFor(() => {
161
- const poll = JSON.parse(screen.getByTestId('cache-poll').textContent);
162
- expect(poll.options.find((option) => option.id === 'opt-a').vote_count).toBe(5);
163
- expect(poll.options.find((option) => option.id === 'opt-b').vote_count).toBe(3);
164
- });
165
- });
166
- });