@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.
- package/CHANGELOG.md +25 -0
- package/README.md +7 -0
- package/dist/chat/kitSxRegistry.js +9 -0
- package/dist/components/charts/kitSxRegistry.js +6 -0
- package/dist/entries/charts.js +6 -0
- package/dist/entries/chat.js +8 -0
- package/dist/entries/markdown.js +1 -0
- package/dist/index.js +0 -14
- package/dist/pages/AccountPage.js +1 -2
- package/dist/pages/LoginPage.js +1 -2
- package/dist/pages/PasswordChangePage.js +1 -2
- package/dist/pages/PasswordInvitePage.js +1 -2
- package/dist/pages/PasswordResetRequestPage.js +1 -2
- package/dist/pages/SignUpPage.js +1 -2
- package/dist/pages/SignupConfirmPage.js +1 -2
- package/dist/theme/kitSxEntry.js +11 -0
- package/dist/theme/kitSxRegistry.js +2 -15
- package/package.json +32 -7
- package/.github/workflows/ci.yml +0 -35
- package/.github/workflows/publish.yml +0 -126
- package/DESIGN.md +0 -60
- package/WORK_ORDERS.md +0 -150
- package/dev/entries.jsx +0 -721
- package/dev/fixtures.js +0 -26
- package/dev/main.jsx +0 -75
- package/dev/mockTransport.jsx +0 -128
- package/docs/CHART-LAYOUT.md +0 -157
- package/docs/DARK-TOKENS.md +0 -140
- package/docs/TYPE-SCALE.md +0 -111
- package/docs/messaging-deviations.md +0 -118
- package/index.html +0 -12
- package/renovate.json +0 -10
- package/scripts/chart-api-census.mjs +0 -415
- package/src/auth/AuthContext.jsx +0 -158
- package/src/auth/ReauthModal.jsx +0 -82
- package/src/auth/UserMenu.jsx +0 -121
- package/src/auth/apiClient.jsx +0 -232
- package/src/auth/authApi.jsx +0 -539
- package/src/auth/authConfig.jsx +0 -34
- package/src/auth/reauth.js +0 -47
- package/src/chat/ChatComposer.jsx +0 -36
- package/src/chat/ChatList.jsx +0 -87
- package/src/chat/ChatThread.jsx +0 -128
- package/src/chat/ChatWorkspace.jsx +0 -244
- package/src/chat/MarkdownReply.jsx +0 -22
- package/src/chat/ModelPicker.jsx +0 -85
- package/src/chat/api.js +0 -18
- package/src/chat/useChatSocket.js +0 -32
- package/src/chat/wire.js +0 -7
- package/src/components/AccessCodeManager.jsx +0 -288
- package/src/components/AccessCodeSingleUseToggle.jsx +0 -92
- package/src/components/AllowedEmailDomainsManager.jsx +0 -92
- package/src/components/AuthFactorRequirementCard.jsx +0 -95
- package/src/components/BulkInviteCsvTab.jsx +0 -198
- package/src/components/EmptyState.jsx +0 -38
- package/src/components/LoginForm.jsx +0 -159
- package/src/components/MFAComponent.jsx +0 -350
- package/src/components/MfaLoginComponent.jsx +0 -252
- package/src/components/MobileBottomNav.jsx +0 -82
- package/src/components/PasskeysComponent.jsx +0 -252
- package/src/components/PasswordChangeForm.jsx +0 -87
- package/src/components/PasswordResetRequestForm.jsx +0 -43
- package/src/components/PasswordSetForm.jsx +0 -97
- package/src/components/ProfileComponent.jsx +0 -348
- package/src/components/QrSignupManager.jsx +0 -404
- package/src/components/QrSignupValidityManager.jsx +0 -106
- package/src/components/RegistrationMethodsManager.jsx +0 -150
- package/src/components/SecurityComponent.jsx +0 -141
- package/src/components/SocialLoginButtons.jsx +0 -83
- package/src/components/SoftChip.jsx +0 -93
- package/src/components/StatTile.jsx +0 -39
- package/src/components/SupportRecoveryRequestsTab.jsx +0 -482
- package/src/components/TurnstileWidget.jsx +0 -99
- package/src/components/UserInviteComponent.jsx +0 -76
- package/src/components/UserListComponent.jsx +0 -618
- package/src/components/charts/BarChart.jsx +0 -102
- package/src/components/charts/ChartFrame.jsx +0 -214
- package/src/components/charts/LineChart.jsx +0 -126
- package/src/components/charts/ScatterChart.jsx +0 -299
- package/src/components/charts/TimeSeriesChart.jsx +0 -300
- package/src/components/charts/chartDefaults.js +0 -644
- package/src/components/charts/chartLabels.js +0 -36
- package/src/components/charts/exportChart.js +0 -258
- package/src/components/charts/formatters.js +0 -39
- package/src/components/charts/palette.js +0 -33
- package/src/components/charts/yearTickInterval.js +0 -7
- package/src/i18n/authTranslations.ts +0 -2651
- package/src/i18n/chartsTranslations.ts +0 -91
- package/src/i18n/chatTranslations.ts +0 -55
- package/src/i18n/messagingTranslations.ts +0 -120
- package/src/i18n/notificationsTranslations.ts +0 -32
- package/src/i18n/onboardingTranslations.ts +0 -29
- package/src/i18n/sectionNavTranslations.ts +0 -20
- package/src/i18n/uiCoreTranslations.js +0 -29
- package/src/i18n/userMenuTranslations.ts +0 -5
- package/src/index.js +0 -158
- package/src/layout/PageLayout.jsx +0 -36
- package/src/layout/SectionNav.jsx +0 -320
- package/src/messaging/AttachmentList.jsx +0 -145
- package/src/messaging/Composer.jsx +0 -197
- package/src/messaging/ConversationLaunchers.jsx +0 -51
- package/src/messaging/ConversationList.jsx +0 -109
- package/src/messaging/DirectMessageLauncher.jsx +0 -112
- package/src/messaging/MessageBubble.jsx +0 -183
- package/src/messaging/MessagingProvider.jsx +0 -0
- package/src/messaging/MessagingScopeConfig.jsx +0 -24
- package/src/messaging/PollCard.jsx +0 -163
- package/src/messaging/ReactionBar.jsx +0 -43
- package/src/messaging/ReadTicks.jsx +0 -82
- package/src/messaging/Thread.jsx +0 -195
- package/src/messaging/api.js +0 -48
- package/src/messaging/composerImageCompression.js +0 -35
- package/src/messaging/linkifyText.jsx +0 -37
- package/src/notifications/NotificationBell.jsx +0 -84
- package/src/notifications/NotificationSettings.jsx +0 -330
- package/src/notifications/NotificationsProvider.jsx +0 -224
- package/src/notifications/PopupSurface.jsx +0 -105
- package/src/notifications/api.js +0 -55
- package/src/notifications/feedApi.js +0 -18
- package/src/notifications/realtime.jsx +0 -138
- package/src/notifications/serviceWorker/sw.js +0 -50
- package/src/onboarding/OnboardingProvider.jsx +0 -326
- package/src/onboarding/OnboardingWizard.jsx +0 -61
- package/src/onboarding/WizardDialogShell.jsx +0 -51
- package/src/onboarding/api.js +0 -13
- package/src/onboarding/stepSelection.js +0 -16
- package/src/onboarding/steps/BrowserPushStep.jsx +0 -121
- package/src/onboarding/steps/CompleteNameStep.jsx +0 -46
- package/src/onboarding/steps/CookieConsentStep.jsx +0 -133
- package/src/onboarding/steps/PwaInstallStep.jsx +0 -47
- package/src/pages/AccountPage.jsx +0 -394
- package/src/pages/LoginPage.jsx +0 -343
- package/src/pages/PasswordChangePage.jsx +0 -62
- package/src/pages/PasswordInvitePage.jsx +0 -177
- package/src/pages/PasswordResetRequestPage.jsx +0 -68
- package/src/pages/SignUpPage.jsx +0 -268
- package/src/pages/SignupConfirmPage.jsx +0 -155
- package/src/testing/checkKitIntegration.js +0 -233
- package/src/theme/createAppTheme.js +0 -423
- package/src/theme/fonts.js +0 -3
- package/src/theme/index.js +0 -21
- package/src/theme/kitSxRegistry.js +0 -285
- package/src/theme/themeCompleteness.js +0 -1045
- package/src/theme/tokens.js +0 -478
- package/src/utils/auth-errors.js +0 -76
- package/src/utils/authService.js +0 -223
- package/src/utils/resolveErrorText.js +0 -28
- package/src/utils/webauthn.js +0 -51
- package/tests/AccountPage.profileStatements.test.jsx +0 -162
- package/tests/AccountPage.test.jsx +0 -200
- package/tests/AuthContext.test.jsx +0 -129
- package/tests/BarChart.test.jsx +0 -112
- package/tests/BrowserPushStep.test.jsx +0 -110
- package/tests/ChartFrame.test.jsx +0 -336
- package/tests/ConversationList.test.jsx +0 -144
- package/tests/CookieConsentStep.test.jsx +0 -69
- package/tests/EmptyState.test.jsx +0 -62
- package/tests/LineChart.test.jsx +0 -80
- package/tests/MessagingProvider.test.jsx +0 -50
- package/tests/MobileBottomNav.test.jsx +0 -319
- package/tests/NotificationBell.test.jsx +0 -60
- package/tests/NotificationSettings.test.jsx +0 -276
- package/tests/NotificationsProvider.test.jsx +0 -240
- package/tests/OnboardingProvider.test.jsx +0 -294
- package/tests/OnboardingWizard.test.jsx +0 -143
- package/tests/PasswordChangeForm.test.jsx +0 -70
- package/tests/PasswordInvitePage.test.jsx +0 -142
- package/tests/PasswordSetForm.test.jsx +0 -70
- package/tests/PopupSurface.test.jsx +0 -142
- package/tests/ProfileComponent.refresh.test.jsx +0 -194
- package/tests/QrSignupManager.registrationContext.test.jsx +0 -106
- package/tests/QrSignupManagerInfoBox.test.jsx +0 -49
- package/tests/ScatterChart.test.jsx +0 -270
- package/tests/SectionNav.test.jsx +0 -363
- package/tests/SignUpPage.test.jsx +0 -208
- package/tests/SoftChip.test.jsx +0 -105
- package/tests/StatTile.test.jsx +0 -57
- package/tests/Thread.test.jsx +0 -151
- package/tests/TimeSeriesChart.test.jsx +0 -367
- package/tests/UserListComponent.test.jsx +0 -192
- package/tests/UserMenu.test.jsx +0 -171
- package/tests/apiClientLanguage.test.js +0 -33
- package/tests/apiClientPublicPaths.test.js +0 -178
- package/tests/authApiLogin.test.js +0 -42
- package/tests/authApiRegistration.test.js +0 -31
- package/tests/authErrorCodeRendering.test.jsx +0 -77
- package/tests/authErrors.test.js +0 -74
- package/tests/authTranslations.test.js +0 -74
- package/tests/chart-api-census.test.js +0 -366
- package/tests/chartAxisTickBand.test.jsx +0 -95
- package/tests/chartDefaults.test.js +0 -902
- package/tests/chartLabels.test.js +0 -50
- package/tests/chartsPalette.test.js +0 -99
- package/tests/chatApi.test.js +0 -48
- package/tests/chatDriverNames.test.jsx +0 -71
- package/tests/chatExports.test.js +0 -3
- package/tests/chatList.test.jsx +0 -84
- package/tests/chatPicker.test.jsx +0 -82
- package/tests/chatSocket.test.jsx +0 -26
- package/tests/chatThread.test.jsx +0 -116
- package/tests/chatTranslations.test.js +0 -47
- package/tests/chatWorkspace.test.jsx +0 -234
- package/tests/checkKitIntegration.test.jsx +0 -219
- package/tests/createAppTheme.test.js +0 -132
- package/tests/createAppThemeDark.test.js +0 -127
- package/tests/createAppThemeLightGuard.test.js +0 -40
- package/tests/createAppThemePageContrast.test.js +0 -108
- package/tests/createAppThemeTypography.test.js +0 -53
- package/tests/errorCallSiteGuard.test.js +0 -32
- package/tests/exportChart.test.js +0 -313
- package/tests/feedApi.test.js +0 -46
- package/tests/fixtures/light-theme-baseline.json +0 -2234
- package/tests/i18nAggregate.test.js +0 -120
- package/tests/i18nGermanVariant.test.js +0 -65
- package/tests/loginPageErrorResolution.test.jsx +0 -102
- package/tests/messagingApi.test.js +0 -32
- package/tests/messagingChunk6.test.jsx +0 -116
- package/tests/messagingCompactBubble.test.jsx +0 -64
- package/tests/messagingComposer.test.jsx +0 -136
- package/tests/messagingComposerChunk5.test.jsx +0 -113
- package/tests/messagingContractConformance.test.js +0 -69
- package/tests/messagingDirectMessageLauncher.test.jsx +0 -151
- package/tests/messagingExports.test.js +0 -21
- package/tests/messagingInteractions.test.jsx +0 -136
- package/tests/messagingLastMessagePreview.test.jsx +0 -93
- package/tests/messagingLinkify.test.jsx +0 -51
- package/tests/messagingMessageActions.test.jsx +0 -163
- package/tests/messagingMsg6.test.jsx +0 -105
- package/tests/messagingMsg6f.test.jsx +0 -155
- package/tests/messagingMsg6g.test.jsx +0 -166
- package/tests/messagingMsg6h.test.jsx +0 -136
- package/tests/messagingMsg6i.test.jsx +0 -129
- package/tests/messagingPollRendering.test.jsx +0 -142
- package/tests/messagingReactionMerge.test.jsx +0 -77
- package/tests/messagingReadTicksTooltip.test.jsx +0 -36
- package/tests/messagingThreadReceipts.test.jsx +0 -178
- package/tests/messagingThreadingQuoting.test.jsx +0 -87
- package/tests/messagingUnreadLifecycle.test.jsx +0 -78
- package/tests/notificationsApi.test.js +0 -41
- package/tests/notificationsExports.test.js +0 -34
- package/tests/onboardingDescriptors.test.js +0 -132
- package/tests/packageTreeShaking.test.js +0 -126
- package/tests/realtime.test.jsx +0 -219
- package/tests/resolveErrorText.test.js +0 -72
- package/tests/stepSelection.test.js +0 -53
- package/tests/themeCompleteness.test.js +0 -626
- package/tests/timeSeriesLegend.test.js +0 -99
- package/tests/userScreenTranslations.test.jsx +0 -218
- package/tsconfig.build.json +0 -18
- package/vite.config.mjs +0 -6
- package/work-orders/AUTH-1.md +0 -74
- package/work-orders/AUTH-2.md +0 -74
- package/work-orders/AUTH-4.md +0 -183
- package/work-orders/AUTH-5.md +0 -154
- package/work-orders/AUTH-7.md +0 -181
- package/work-orders/AUTH-8.md +0 -184
- package/work-orders/CHART-1.md +0 -285
- package/work-orders/CHART-2.md +0 -222
- package/work-orders/CHART-3.md +0 -163
- package/work-orders/CHART-4.md +0 -203
- package/work-orders/CHART-5.md +0 -226
- package/work-orders/CHART-6.md +0 -428
- package/work-orders/CHART-7.md +0 -175
- package/work-orders/DX-1.md +0 -169
- package/work-orders/DX-2.md +0 -188
- package/work-orders/DX-3.md +0 -195
- package/work-orders/I18N-1.md +0 -254
- package/work-orders/I18N-3.md +0 -207
- package/work-orders/MSG-3.md +0 -375
- package/work-orders/MSG-3b.md +0 -1002
- package/work-orders/MSG-3c.md +0 -378
- package/work-orders/MSG-3d.md +0 -268
- package/work-orders/MSG-3e.md +0 -164
- package/work-orders/MSG-3f.md +0 -391
- package/work-orders/MSG-6e.md +0 -308
- package/work-orders/MSG-6f.md +0 -214
- package/work-orders/MSG-6g.md +0 -244
- package/work-orders/MSG-6h.md +0 -238
- package/work-orders/MSG-6i.md +0 -271
- package/work-orders/MSG-6j.md +0 -117
- package/work-orders/NOTIF-12.md +0 -214
- package/work-orders/NOTIF-13.md +0 -142
- package/work-orders/NOTIF-14.md +0 -151
- package/work-orders/PRIM-1.md +0 -177
- package/work-orders/SHELL-1.md +0 -255
- package/work-orders/SHELL-2.md +0 -197
- package/work-orders/SHELL-3.md +0 -359
- package/work-orders/SHELL-4.md +0 -351
- package/work-orders/SHELL-5.md +0 -345
- package/work-orders/SHELL-6.md +0 -210
- package/work-orders/THEME-1.md +0 -587
- package/work-orders/THEME-10.md +0 -303
- package/work-orders/THEME-11.md +0 -208
- package/work-orders/THEME-2.md +0 -339
- package/work-orders/THEME-3.md +0 -210
- package/work-orders/THEME-4.md +0 -271
- package/work-orders/THEME-5.md +0 -341
- package/work-orders/THEME-6.md +0 -247
- package/work-orders/THEME-7.md +0 -82
- package/work-orders/THEME-8.md +0 -211
- package/work-orders/THEME-9.md +0 -194
- package/work-orders/UCM-AUTH-10.md +0 -490
- package/work-orders/UCM-AUTH-11.md +0 -185
- package/work-orders/UCM-AUTH-12.md +0 -98
- package/work-orders/UCM-AUTH-13.md +0 -47
- package/work-orders/UCM-AUTH-9.md +0 -207
- package/work-orders/UCM-CHART-10.md +0 -150
- package/work-orders/UCM-CHART-11.md +0 -132
- package/work-orders/UCM-CHART-12.md +0 -348
- package/work-orders/UCM-CHART-13.md +0 -122
- package/work-orders/UCM-CHART-14.md +0 -198
- package/work-orders/UCM-CHART-15.md +0 -187
- package/work-orders/UCM-CHART-16.md +0 -169
- package/work-orders/UCM-CHART-17.md +0 -195
- package/work-orders/UCM-CHART-18.md +0 -200
- package/work-orders/UCM-CHART-8.md +0 -147
- package/work-orders/UCM-CHART-9.md +0 -265
- package/work-orders/UCM-CHAT-1.md +0 -190
- package/work-orders/UCM-CHAT-2.md +0 -75
- package/work-orders/UCM-CI-1.md +0 -65
- package/work-orders/UCM-DEP-1.md +0 -63
- package/work-orders/UCM-I18N-4.md +0 -226
- package/work-orders/UCM-I18N-5.md +0 -211
- package/work-orders/UCM-MSG-20.md +0 -192
- package/work-orders/UCM-PRIM-2.md +0 -114
- package/work-orders/UCM-SHELL-7.md +0 -134
- package/work-orders/UCM-SHELL-8.md +0 -125
- package/work-orders/UCM-TEST-1.md +0 -304
- package/work-orders/UCM-THEME-13.md +0 -69
- package/work-orders/UCM-THEME-14.md +0 -312
- package/work-orders/UCM-THEME-15.md +0 -356
- package/work-orders/UCM-THEME-16.md +0 -80
- package/work-orders/UCM-THEME-17.md +0 -111
- package/work-orders/UCM-THEME-18.md +0 -184
- package/work-orders/assets/AUTH-4-user-list-card.html +0 -407
- package/work-orders/assets/PRIM-1-dashboard-primitives.html +0 -624
- package/work-orders/assets/SHELL-2-account-navigation.html +0 -1159
- package/work-orders/assets/THEME-1-baseline-reference-sheet.html +0 -1352
- package/work-orders/assets/UCM-CHAT-1-ai-chat.html +0 -447
- package/work-orders/assets/UCM-THEME-13-dark-prototype.html +0 -390
- 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
|
-
});
|