@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,113 +0,0 @@
|
|
|
1
|
-
// @vitest-environment jsdom
|
|
2
|
-
import React from 'react';
|
|
3
|
-
import { afterEach, beforeEach, 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?.name ? `${key}:${options.name}` : key }) }));
|
|
7
|
-
vi.mock('../src/notifications/realtime', () => ({ useRealtime: () => ({ subscribe: () => () => {}, onReconnect: () => () => {} }) }));
|
|
8
|
-
|
|
9
|
-
import { Composer } from '../src/messaging/Composer';
|
|
10
|
-
import { MessagingProvider } from '../src/messaging/MessagingProvider';
|
|
11
|
-
|
|
12
|
-
function makeApi() {
|
|
13
|
-
return {
|
|
14
|
-
listConversations: vi.fn().mockResolvedValue({ results: [] }), listMessages: vi.fn().mockResolvedValue({ results: [] }), getUnreadCount: vi.fn().mockResolvedValue({ unread_count: 0, by_conversation: {} }),
|
|
15
|
-
createMessage: vi.fn().mockResolvedValue({ id: 1, conversation_id: 7 }), uploadAttachments: vi.fn().mockResolvedValue({ id: 2, conversation_id: 7 }), getAttachment: vi.fn(), getAttachmentThumbnail: vi.fn(),
|
|
16
|
-
};
|
|
17
|
-
}
|
|
18
|
-
function renderComposer(api = makeApi(), conversationId = 7) {
|
|
19
|
-
return render(<MessagingProvider api={api} active={false}><Composer conversationId={conversationId} /></MessagingProvider>);
|
|
20
|
-
}
|
|
21
|
-
function attachmentInput() { return document.querySelector('input[type=file]'); }
|
|
22
|
-
function messageInput() { return screen.getByLabelText('MessagingComposer.MESSAGE'); }
|
|
23
|
-
function imageFile(name = 'photo.png') { return new File(['image'], name, { type: 'image/png' }); }
|
|
24
|
-
|
|
25
|
-
beforeEach(() => {
|
|
26
|
-
URL.createObjectURL = vi.fn((file) => `blob:${file.name}`);
|
|
27
|
-
URL.revokeObjectURL = vi.fn();
|
|
28
|
-
});
|
|
29
|
-
afterEach(() => { cleanup(); vi.restoreAllMocks(); });
|
|
30
|
-
|
|
31
|
-
describe('Composer chunk 5 behavior', () => {
|
|
32
|
-
it('sends on Enter and leaves Shift+Enter available for a newline', async () => {
|
|
33
|
-
const api = makeApi(); renderComposer(api);
|
|
34
|
-
fireEvent.change(messageInput(), { target: { value: 'first' } });
|
|
35
|
-
fireEvent.keyDown(messageInput(), { key: 'Enter', code: 'Enter' });
|
|
36
|
-
await waitFor(() => expect(api.createMessage).toHaveBeenCalledTimes(1));
|
|
37
|
-
|
|
38
|
-
fireEvent.change(messageInput(), { target: { value: 'first' } });
|
|
39
|
-
fireEvent.keyDown(messageInput(), { key: 'Enter', code: 'Enter', shiftKey: true });
|
|
40
|
-
fireEvent.change(messageInput(), { target: { value: 'first\nsecond' } });
|
|
41
|
-
expect(api.createMessage).toHaveBeenCalledTimes(1);
|
|
42
|
-
expect(messageInput().value).toBe('first\nsecond');
|
|
43
|
-
});
|
|
44
|
-
|
|
45
|
-
it('shows staged image previews and removes only the chosen file before upload', async () => {
|
|
46
|
-
const api = makeApi(); renderComposer(api);
|
|
47
|
-
const first = imageFile('first.png'); const second = imageFile('second.png');
|
|
48
|
-
fireEvent.change(attachmentInput(), { target: { files: [first, second] } });
|
|
49
|
-
expect(screen.getByRole('img', { name: 'first.png' })).toBeTruthy();
|
|
50
|
-
expect(screen.getByRole('img', { name: 'second.png' })).toBeTruthy();
|
|
51
|
-
fireEvent.click(screen.getByRole('button', { name: 'MessagingComposer.REMOVE_ATTACHMENT:first.png' }));
|
|
52
|
-
expect(screen.queryByRole('img', { name: 'first.png' })).toBeNull();
|
|
53
|
-
fireEvent.click(screen.getByRole('button', { name: 'MessagingComposer.SEND' }));
|
|
54
|
-
await waitFor(() => expect(api.uploadAttachments).toHaveBeenCalledTimes(1));
|
|
55
|
-
const sentFiles = Array.from(api.uploadAttachments.mock.calls[0][1].getAll('files[]'));
|
|
56
|
-
expect(sentFiles).toHaveLength(1);
|
|
57
|
-
expect(sentFiles[0].name).toBe('second.png');
|
|
58
|
-
});
|
|
59
|
-
|
|
60
|
-
it('shows real byte-percentage upload progress while an attachment upload is in flight', async () => {
|
|
61
|
-
let resolveUpload; const api = makeApi(); api.uploadAttachments.mockReturnValue(new Promise((resolve) => { resolveUpload = resolve; }));
|
|
62
|
-
renderComposer(api); fireEvent.change(attachmentInput(), { target: { files: [imageFile()] } });
|
|
63
|
-
fireEvent.click(screen.getByRole('button', { name: 'MessagingComposer.SEND' }));
|
|
64
|
-
expect(await screen.findByRole('status')).toBeTruthy();
|
|
65
|
-
const { onUploadProgress } = api.uploadAttachments.mock.calls[0][2];
|
|
66
|
-
onUploadProgress({ loaded: 25, total: 100 });
|
|
67
|
-
await waitFor(() => expect(screen.getAllByRole('progressbar')[0].getAttribute('aria-valuenow')).toBe('25'));
|
|
68
|
-
resolveUpload({ id: 2, conversation_id: 7 });
|
|
69
|
-
await waitFor(() => expect(screen.queryByRole('status')).toBeNull());
|
|
70
|
-
});
|
|
71
|
-
|
|
72
|
-
it('compresses oversized images before adding them to FormData and falls back silently if compression fails', async () => {
|
|
73
|
-
const largeImage = new File([new Uint8Array(2 * 1024 * 1024 + 1)], 'large.png', { type: 'image/png' });
|
|
74
|
-
const api = makeApi();
|
|
75
|
-
class SuccessfulImage { naturalWidth = 5120; naturalHeight = 2560; set src(_) { this.onload(); } }
|
|
76
|
-
vi.stubGlobal('Image', SuccessfulImage);
|
|
77
|
-
vi.spyOn(HTMLCanvasElement.prototype, 'getContext').mockReturnValue({ drawImage: vi.fn() });
|
|
78
|
-
vi.spyOn(HTMLCanvasElement.prototype, 'toBlob').mockImplementation((callback) => callback(new Blob(['compressed'], { type: 'image/jpeg' })));
|
|
79
|
-
renderComposer(api); fireEvent.change(attachmentInput(), { target: { files: [largeImage] } }); fireEvent.click(screen.getByRole('button', { name: 'MessagingComposer.SEND' }));
|
|
80
|
-
await waitFor(() => expect(api.uploadAttachments).toHaveBeenCalledTimes(1));
|
|
81
|
-
const compressed = api.uploadAttachments.mock.calls[0][1].get('files[]');
|
|
82
|
-
expect(compressed.name).toBe('large.jpg'); expect(compressed.type).toBe('image/jpeg');
|
|
83
|
-
|
|
84
|
-
cleanup(); const fallbackApi = makeApi(); class FailingImage { set src(_) { this.onerror(); } }
|
|
85
|
-
vi.stubGlobal('Image', FailingImage);
|
|
86
|
-
renderComposer(fallbackApi); fireEvent.change(attachmentInput(), { target: { files: [largeImage] } }); fireEvent.click(screen.getByRole('button', { name: 'MessagingComposer.SEND' }));
|
|
87
|
-
await waitFor(() => expect(fallbackApi.uploadAttachments).toHaveBeenCalledTimes(1));
|
|
88
|
-
const fallback = fallbackApi.uploadAttachments.mock.calls[0][1].get('files[]');
|
|
89
|
-
expect(fallback.name).toBe('large.png'); expect(fallback.type).toBe('image/png');
|
|
90
|
-
});
|
|
91
|
-
|
|
92
|
-
it('inserts the selected emoji at the current cursor position', async () => {
|
|
93
|
-
// MSG-6i: the Composer's own picker is now a wider curated grid
|
|
94
|
-
// (IconButton per emoji), decoupled from ReactionBar's 5-entry
|
|
95
|
-
// QUICK_EMOJIS -- role is "button", not "menuitem".
|
|
96
|
-
renderComposer(); fireEvent.change(messageInput(), { target: { value: 'abCD' } });
|
|
97
|
-
messageInput().setSelectionRange(2, 2);
|
|
98
|
-
fireEvent.click(screen.getByRole('button', { name: 'MessagingComposer.ADD_EMOJI' }));
|
|
99
|
-
fireEvent.click(await screen.findByRole('button', { name: '👍' }));
|
|
100
|
-
await waitFor(() => expect(messageInput().value).toBe('ab👍CD'));
|
|
101
|
-
});
|
|
102
|
-
|
|
103
|
-
it('disables poll composing while an image is staged and resets drafts for a new conversation', async () => {
|
|
104
|
-
const api = makeApi(); const view = renderComposer(api, 7);
|
|
105
|
-
fireEvent.change(attachmentInput(), { target: { files: [imageFile()] } });
|
|
106
|
-
expect(screen.getByRole('button', { name: 'MessagingPoll.CREATE' }).disabled).toBe(true);
|
|
107
|
-
fireEvent.click(screen.getByRole('button', { name: 'MessagingComposer.REMOVE_ATTACHMENT:photo.png' }));
|
|
108
|
-
expect(screen.getByRole('button', { name: 'MessagingPoll.CREATE' }).disabled).toBe(false);
|
|
109
|
-
fireEvent.change(messageInput(), { target: { value: 'unsent draft' } });
|
|
110
|
-
view.rerender(<MessagingProvider api={api} active={false}><Composer conversationId={8} /></MessagingProvider>);
|
|
111
|
-
await waitFor(() => expect(messageInput().value).toBe(''));
|
|
112
|
-
});
|
|
113
|
-
});
|
|
@@ -1,69 +0,0 @@
|
|
|
1
|
-
import fs from 'node:fs';
|
|
2
|
-
import path from 'node:path';
|
|
3
|
-
import { describe, expect, it } from 'vitest';
|
|
4
|
-
|
|
5
|
-
const root = path.resolve(import.meta.dirname, '..');
|
|
6
|
-
const messagingRoot = path.join(root, 'src', 'messaging');
|
|
7
|
-
|
|
8
|
-
// These are deliberately named and time-bounded. Chunks 3 and 4 must remove
|
|
9
|
-
// their entries when they wire their existing adapters; the final three are
|
|
10
|
-
// retained only if their stated product rationale still holds at WO close.
|
|
11
|
-
const API_EXEMPTIONS = {
|
|
12
|
-
createManagedConversation: 'No managed-conversation launcher is in the current public surface.',
|
|
13
|
-
createObjectThreadConversation: 'Object-thread creation is host-owned routing/scope work.',
|
|
14
|
-
getMessage: 'Timeline data is loaded through listMessages and listThread.',
|
|
15
|
-
};
|
|
16
|
-
const FRAME_TYPES = ['conversation_upsert', 'conversation_archived', 'message', 'message_edited', 'message_deleted', 'attachment_ready', 'reaction', 'poll_updated', 'delivered', 'read_state', 'thread_read_state', 'participant_changed'];
|
|
17
|
-
const FRAME_EXEMPTIONS = {
|
|
18
|
-
attachment_ready: 'Reserved by the design and deliberately unemitted.',
|
|
19
|
-
delivered: 'Receipt synchronisation is outside MSG-3b.',
|
|
20
|
-
read_state: 'Receipt synchronisation is outside MSG-3b.',
|
|
21
|
-
thread_read_state: 'Receipt synchronisation is outside MSG-3b.',
|
|
22
|
-
};
|
|
23
|
-
|
|
24
|
-
const BLOCKED_LINE = /\*\*BLOCKED\*\*/;
|
|
25
|
-
const VERSION_PIN = /dcm \d+\.\d+\.\d+/;
|
|
26
|
-
|
|
27
|
-
// A BLOCKED row without a version pin is exactly how MSG-3b's seven blocked
|
|
28
|
-
// rows went stale unnoticed: dcm shipped what they needed mid-flight and the
|
|
29
|
-
// WO-end review had no cheap way to tell. This check can't know whether dcm
|
|
30
|
-
// has since shipped — it only guarantees the pin exists, which is what turns
|
|
31
|
-
// the re-check into a two-minute job instead of an archaeology exercise.
|
|
32
|
-
function unpinnedBlockedLines(markdown) {
|
|
33
|
-
return markdown.split('\n').filter((line) => BLOCKED_LINE.test(line) && !VERSION_PIN.test(line));
|
|
34
|
-
}
|
|
35
|
-
|
|
36
|
-
describe('messaging deviation-doc BLOCKED entries carry a dependency version pin', () => {
|
|
37
|
-
it('every BLOCKED line in docs/messaging-deviations.md names the dcm version it was blocked at', () => {
|
|
38
|
-
const markdown = fs.readFileSync(path.join(root, 'docs', 'messaging-deviations.md'), 'utf8');
|
|
39
|
-
expect(unpinnedBlockedLines(markdown)).toEqual([]);
|
|
40
|
-
});
|
|
41
|
-
|
|
42
|
-
// Required negative case (the WO is explicit: prove the check can fail,
|
|
43
|
-
// not only that the real file happens to pass).
|
|
44
|
-
it('flags a BLOCKED line that omits the version pin', () => {
|
|
45
|
-
const unpinned = '99. **BLOCKED** — some capability with no dependency version named.';
|
|
46
|
-
const pinned = '100. **BLOCKED** (blocked as of dcm 2.37.0) — some other capability.';
|
|
47
|
-
expect(unpinnedBlockedLines(`${unpinned}\n${pinned}`)).toEqual([unpinned]);
|
|
48
|
-
});
|
|
49
|
-
});
|
|
50
|
-
|
|
51
|
-
describe('messaging adapter and realtime contract conformance', () => {
|
|
52
|
-
it('has a caller for every API export unless it has an explicit rationale', () => {
|
|
53
|
-
const apiSource = fs.readFileSync(path.join(messagingRoot, 'api.js'), 'utf8');
|
|
54
|
-
const source = fs.readdirSync(messagingRoot).filter((file) => file.endsWith('.jsx')).map((file) => fs.readFileSync(path.join(messagingRoot, file), 'utf8')).join('\n');
|
|
55
|
-
const exports = [...apiSource.matchAll(/export function (\w+)\(/g)].map((match) => match[1]);
|
|
56
|
-
// Attachment readers are intentionally passed through the provider to the
|
|
57
|
-
// standalone AttachmentList, where they are called. All other adapters
|
|
58
|
-
// are invoked by the provider/component that owns the action.
|
|
59
|
-
const unwired = exports.filter((name) => !new RegExp(`api\\.${name}\\(|${name}: api\\.${name}`).test(source) && !API_EXEMPTIONS[name]);
|
|
60
|
-
expect(unwired).toEqual([]);
|
|
61
|
-
});
|
|
62
|
-
|
|
63
|
-
it('handles only design-listed frames and accounts for intentionally unhandled frames', () => {
|
|
64
|
-
const provider = fs.readFileSync(path.join(messagingRoot, 'MessagingProvider.jsx'), 'utf8');
|
|
65
|
-
const handled = [...provider.matchAll(/frame\.type === '([^']+)'/g)].map((match) => match[1]);
|
|
66
|
-
expect(handled.every((type) => FRAME_TYPES.includes(type))).toBe(true);
|
|
67
|
-
expect(FRAME_TYPES.filter((type) => !handled.includes(type) && !FRAME_EXEMPTIONS[type])).toEqual([]);
|
|
68
|
-
});
|
|
69
|
-
});
|
|
@@ -1,151 +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) => key }) }));
|
|
7
|
-
vi.mock('../src/notifications/realtime', () => ({ useRealtime: () => ({ subscribe: () => () => {}, onReconnect: () => () => {} }) }));
|
|
8
|
-
|
|
9
|
-
import { DirectMessageLauncher } from '../src/index';
|
|
10
|
-
import { MessagingProvider } from '../src/messaging/MessagingProvider';
|
|
11
|
-
|
|
12
|
-
const candidates = [{ id: 2, display_name: 'Alex' }, { id: 3, display_name: 'Sam' }];
|
|
13
|
-
|
|
14
|
-
function renderLauncher({ api = { createDirectConversation: vi.fn().mockResolvedValue({ id: 41, kind: 'direct' }) }, ...props } = {}) {
|
|
15
|
-
const onOpen = props.onOpen || vi.fn();
|
|
16
|
-
render(<MessagingProvider api={api} active={false}><DirectMessageLauncher candidates={candidates} onOpen={onOpen} {...props} /></MessagingProvider>);
|
|
17
|
-
return { api, onOpen };
|
|
18
|
-
}
|
|
19
|
-
function openPicker() { fireEvent.click(screen.getByRole('button', { name: 'MessagingDirect.LAUNCH' })); }
|
|
20
|
-
function selectCandidate(name) {
|
|
21
|
-
const input = screen.getByLabelText('MessagingDirect.CANDIDATES');
|
|
22
|
-
fireEvent.mouseDown(input);
|
|
23
|
-
fireEvent.click(screen.getByRole('option', { name }));
|
|
24
|
-
}
|
|
25
|
-
|
|
26
|
-
afterEach(() => {
|
|
27
|
-
cleanup();
|
|
28
|
-
window.matchMedia = undefined;
|
|
29
|
-
});
|
|
30
|
-
|
|
31
|
-
describe('DirectMessageLauncher', () => {
|
|
32
|
-
it('opens a picker with a searchable candidate autocomplete and renders a distinct empty state', () => {
|
|
33
|
-
renderLauncher();
|
|
34
|
-
openPicker();
|
|
35
|
-
expect(screen.getByRole('dialog')).toBeTruthy();
|
|
36
|
-
const input = screen.getByLabelText('MessagingDirect.CANDIDATES');
|
|
37
|
-
expect(input.getAttribute('placeholder')).toBe('MessagingDirect.SEARCH_PLACEHOLDER');
|
|
38
|
-
fireEvent.mouseDown(input);
|
|
39
|
-
expect(screen.getByRole('option', { name: 'Alex' })).toBeTruthy();
|
|
40
|
-
expect(screen.getByRole('option', { name: 'Sam' })).toBeTruthy();
|
|
41
|
-
|
|
42
|
-
cleanup();
|
|
43
|
-
renderLauncher({ candidates: [] });
|
|
44
|
-
openPicker();
|
|
45
|
-
expect(screen.getByText('MessagingDirect.EMPTY')).toBeTruthy();
|
|
46
|
-
expect(screen.queryByLabelText('MessagingDirect.CANDIDATES')).toBeNull();
|
|
47
|
-
});
|
|
48
|
-
|
|
49
|
-
it('filters candidates as the query is typed', () => {
|
|
50
|
-
renderLauncher();
|
|
51
|
-
openPicker();
|
|
52
|
-
const input = screen.getByLabelText('MessagingDirect.CANDIDATES');
|
|
53
|
-
fireEvent.mouseDown(input);
|
|
54
|
-
// MUI's Autocomplete only reacts to a typed value once the input is genuinely focused --
|
|
55
|
-
// mouseDown alone opens the listbox but doesn't focus the input in jsdom.
|
|
56
|
-
input.focus();
|
|
57
|
-
fireEvent.change(input, { target: { value: 'Sa' } });
|
|
58
|
-
expect(screen.getByRole('option', { name: 'Sam' })).toBeTruthy();
|
|
59
|
-
expect(screen.queryByRole('option', { name: 'Alex' })).toBeNull();
|
|
60
|
-
});
|
|
61
|
-
|
|
62
|
-
it('shows a localized message when a typed query matches nothing (ui_reviewer finding U1)', () => {
|
|
63
|
-
renderLauncher();
|
|
64
|
-
openPicker();
|
|
65
|
-
const input = screen.getByLabelText('MessagingDirect.CANDIDATES');
|
|
66
|
-
fireEvent.mouseDown(input);
|
|
67
|
-
input.focus();
|
|
68
|
-
fireEvent.change(input, { target: { value: 'zzz-no-such-person' } });
|
|
69
|
-
expect(screen.getByText('MessagingDirect.NO_MATCHES')).toBeTruthy();
|
|
70
|
-
});
|
|
71
|
-
|
|
72
|
-
it('requires a recipient, disables while starting, then opens the created conversation with scope', async () => {
|
|
73
|
-
let resolveRequest;
|
|
74
|
-
const api = { createDirectConversation: vi.fn(() => new Promise((resolve) => { resolveRequest = resolve; })) };
|
|
75
|
-
const { onOpen } = renderLauncher({ api, scope: { kind: 'event', id: 8 } });
|
|
76
|
-
openPicker();
|
|
77
|
-
const start = screen.getByRole('button', { name: 'MessagingDirect.START' });
|
|
78
|
-
expect(start.disabled).toBe(true);
|
|
79
|
-
selectCandidate('Alex');
|
|
80
|
-
expect(start.disabled).toBe(false);
|
|
81
|
-
fireEvent.click(start);
|
|
82
|
-
expect(api.createDirectConversation).toHaveBeenCalledWith({ target_user_id: 2, scope: { kind: 'event', id: 8 } });
|
|
83
|
-
expect(start.disabled).toBe(true);
|
|
84
|
-
expect(screen.getByRole('status')).toBeTruthy();
|
|
85
|
-
resolveRequest({ id: 41, kind: 'direct' });
|
|
86
|
-
await waitFor(() => expect(onOpen).toHaveBeenCalledWith({ id: 41, kind: 'direct' }));
|
|
87
|
-
await waitFor(() => expect(screen.queryByRole('dialog')).toBeNull());
|
|
88
|
-
});
|
|
89
|
-
|
|
90
|
-
it('uses the selected candidate scope over the launcher scope', () => {
|
|
91
|
-
const api = { createDirectConversation: vi.fn().mockResolvedValue({ id: 41, kind: 'direct' }) };
|
|
92
|
-
renderLauncher({
|
|
93
|
-
api,
|
|
94
|
-
candidates: [
|
|
95
|
-
{ id: 2, display_name: 'Alex', scope: 'scope-a' },
|
|
96
|
-
{ id: 3, display_name: 'Sam', scope: 'scope-b' },
|
|
97
|
-
],
|
|
98
|
-
scope: 'scope-prop',
|
|
99
|
-
});
|
|
100
|
-
openPicker();
|
|
101
|
-
selectCandidate('Sam');
|
|
102
|
-
fireEvent.click(screen.getByRole('button', { name: 'MessagingDirect.START' }));
|
|
103
|
-
expect(api.createDirectConversation).toHaveBeenCalledWith({ target_user_id: 3, scope: 'scope-b' });
|
|
104
|
-
});
|
|
105
|
-
|
|
106
|
-
it('falls back to the launcher scope when the selected candidate has none', () => {
|
|
107
|
-
const api = { createDirectConversation: vi.fn().mockResolvedValue({ id: 41, kind: 'direct' }) };
|
|
108
|
-
renderLauncher({
|
|
109
|
-
api,
|
|
110
|
-
candidates: [
|
|
111
|
-
{ id: 2, display_name: 'Alex' },
|
|
112
|
-
{ id: 3, display_name: 'Sam', scope: 'scope-b' },
|
|
113
|
-
],
|
|
114
|
-
scope: 'scope-prop',
|
|
115
|
-
});
|
|
116
|
-
openPicker();
|
|
117
|
-
selectCandidate('Alex');
|
|
118
|
-
fireEvent.click(screen.getByRole('button', { name: 'MessagingDirect.START' }));
|
|
119
|
-
expect(api.createDirectConversation).toHaveBeenCalledWith({ target_user_id: 2, scope: 'scope-prop' });
|
|
120
|
-
});
|
|
121
|
-
|
|
122
|
-
it('omits scope when neither the candidate nor launcher provides one', () => {
|
|
123
|
-
const api = { createDirectConversation: vi.fn().mockResolvedValue({ id: 41, kind: 'direct' }) };
|
|
124
|
-
renderLauncher({ api });
|
|
125
|
-
openPicker();
|
|
126
|
-
selectCandidate('Alex');
|
|
127
|
-
fireEvent.click(screen.getByRole('button', { name: 'MessagingDirect.START' }));
|
|
128
|
-
expect(Object.keys(api.createDirectConversation.mock.calls[0][0])).toEqual(['target_user_id']);
|
|
129
|
-
});
|
|
130
|
-
|
|
131
|
-
it('surfaces a policy rejection without closing the picker', async () => {
|
|
132
|
-
const api = { createDirectConversation: vi.fn().mockRejectedValue({ response: { data: { detail: 'Direct messages are restricted.' } } }) };
|
|
133
|
-
renderLauncher({ api });
|
|
134
|
-
openPicker();
|
|
135
|
-
selectCandidate('Alex');
|
|
136
|
-
fireEvent.click(screen.getByRole('button', { name: 'MessagingDirect.START' }));
|
|
137
|
-
expect((await screen.findByRole('alert')).textContent).toContain('Direct messages are restricted.');
|
|
138
|
-
expect(screen.getByRole('dialog')).toBeTruthy();
|
|
139
|
-
});
|
|
140
|
-
|
|
141
|
-
it('uses a fullscreen dialog at the small-viewport media query', () => {
|
|
142
|
-
window.matchMedia = vi.fn().mockImplementation(() => ({
|
|
143
|
-
matches: true,
|
|
144
|
-
addEventListener: vi.fn(),
|
|
145
|
-
removeEventListener: vi.fn(),
|
|
146
|
-
}));
|
|
147
|
-
renderLauncher();
|
|
148
|
-
openPicker();
|
|
149
|
-
expect(document.querySelector('.MuiDialog-paperFullScreen')).not.toBeNull();
|
|
150
|
-
});
|
|
151
|
-
});
|
|
@@ -1,21 +0,0 @@
|
|
|
1
|
-
import { describe, expect, it } from 'vitest';
|
|
2
|
-
import { AttachmentList, Composer, ConversationLaunchers, ConversationList, DirectMessageLauncher, MessageBubble, MessagingProvider, MessagingScopeConfig, messagingTranslations, PollCard, ReactionBar, ReadTicks, Thread, useMessaging } from '../src/index';
|
|
3
|
-
|
|
4
|
-
describe('messaging barrel exports', () => {
|
|
5
|
-
it('exports the provider, hook, standalone list and launchers', () => {
|
|
6
|
-
expect(MessagingProvider).toBeDefined();
|
|
7
|
-
expect(useMessaging).toBeDefined();
|
|
8
|
-
expect(ConversationList).toBeDefined();
|
|
9
|
-
expect(ConversationLaunchers).toBeDefined();
|
|
10
|
-
expect(DirectMessageLauncher).toBeDefined();
|
|
11
|
-
expect(Thread).toBeDefined();
|
|
12
|
-
expect(MessageBubble).toBeDefined();
|
|
13
|
-
expect(ReadTicks).toBeDefined();
|
|
14
|
-
expect(Composer).toBeDefined();
|
|
15
|
-
expect(AttachmentList).toBeDefined();
|
|
16
|
-
expect(ReactionBar).toBeDefined();
|
|
17
|
-
expect(PollCard).toBeDefined();
|
|
18
|
-
expect(MessagingScopeConfig).toBeDefined();
|
|
19
|
-
expect(messagingTranslations).toBeDefined();
|
|
20
|
-
});
|
|
21
|
-
});
|
|
@@ -1,136 +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 { Composer } from '../src/messaging/Composer';
|
|
10
|
-
import { MessagingProvider, useMessaging } from '../src/messaging/MessagingProvider';
|
|
11
|
-
import { PollCard } from '../src/messaging/PollCard';
|
|
12
|
-
import { ReactionBar } from '../src/messaging/ReactionBar';
|
|
13
|
-
import { MessagingScopeConfig } from '../src/messaging/MessagingScopeConfig';
|
|
14
|
-
|
|
15
|
-
function CacheState() { const { cache } = useMessaging(); return <output data-testid="cache">{JSON.stringify(cache)}</output>; }
|
|
16
|
-
|
|
17
|
-
const baseApi = () => ({ listConversations: vi.fn().mockResolvedValue({ results: [] }), listMessages: vi.fn().mockResolvedValue({ results: [] }), getUnreadCount: vi.fn().mockResolvedValue({ unread_count: 0, by_conversation: {} }), addReaction: vi.fn(), removeReaction: vi.fn(), votePoll: vi.fn(), closePoll: vi.fn(), createPoll: vi.fn() });
|
|
18
|
-
afterEach(cleanup);
|
|
19
|
-
|
|
20
|
-
describe('messaging reactions and polls', () => {
|
|
21
|
-
it('round-trips add and remove reactions through the cache-backed API', async () => {
|
|
22
|
-
// serialize_reactions (dcm) never returns a per-viewer `reacted` flag —
|
|
23
|
-
// {emoji, count} only, in every context.
|
|
24
|
-
const api = baseApi(); api.addReaction.mockResolvedValue({ reactions: [{ emoji: '👍', count: 1 }] }); api.removeReaction.mockResolvedValue({ reactions: [] });
|
|
25
|
-
const { rerender } = render(<MessagingProvider api={api} active={false}><ReactionBar message={{ id: 7, reactions: [{ emoji: '👍', count: 1, reacted: false }] }} /></MessagingProvider>);
|
|
26
|
-
fireEvent.click(screen.getByRole('button', { name: 'MessagingReactions.TOGGLE' })); await waitFor(() => expect(api.addReaction).toHaveBeenCalledWith(7, '👍'));
|
|
27
|
-
rerender(<MessagingProvider api={api} active={false}><ReactionBar message={{ id: 7, reactions: [{ emoji: '👍', count: 1, reacted: true }] }} /></MessagingProvider>);
|
|
28
|
-
fireEvent.click(screen.getByRole('button', { name: 'MessagingReactions.TOGGLE' })); await waitFor(() => expect(api.removeReaction).toHaveBeenCalledWith(7, '👍'));
|
|
29
|
-
});
|
|
30
|
-
|
|
31
|
-
it('taps vote immediately (no submit step): single-choice uses radios and only ever sends the last-tapped option, multi-select uses checkboxes and accumulates', async () => {
|
|
32
|
-
// MSG-6g: tap-to-vote, no separate "Abstimmen" button.
|
|
33
|
-
const single = baseApi(); single.votePoll.mockResolvedValue({ poll: { id: 1, options: [] } });
|
|
34
|
-
const { unmount } = render(<MessagingProvider api={single} active={false}><PollCard message={{ id: 7, poll: { id: 1, question: 'One', options: [{ id: 1, text: 'A' }, { id: 2, text: 'B' }], allow_multiple: false }}} /></MessagingProvider>);
|
|
35
|
-
const radios = screen.getAllByRole('radio');
|
|
36
|
-
fireEvent.click(radios[0]); await waitFor(() => expect(single.votePoll).toHaveBeenCalledWith(1, [1]));
|
|
37
|
-
fireEvent.click(radios[1]); await waitFor(() => expect(single.votePoll).toHaveBeenCalledWith(1, [2]));
|
|
38
|
-
expect(single.votePoll).toHaveBeenCalledTimes(2);
|
|
39
|
-
unmount();
|
|
40
|
-
const multiple = baseApi(); multiple.votePoll.mockResolvedValue({ poll: { id: 2, options: [] } }); render(<MessagingProvider api={multiple} active={false}><PollCard message={{ id: 8, poll: { id: 2, question: 'Many', options: [{ id: 1, text: 'A' }, { id: 2, text: 'B' }], allow_multiple: true }}} /></MessagingProvider>);
|
|
41
|
-
const multiChoices = screen.getAllByRole('checkbox');
|
|
42
|
-
fireEvent.click(multiChoices[0]); await waitFor(() => expect(multiple.votePoll).toHaveBeenCalledWith(2, [1]));
|
|
43
|
-
fireEvent.click(multiChoices[1]); await waitFor(() => expect(multiple.votePoll).toHaveBeenCalledWith(2, [1, 2]));
|
|
44
|
-
});
|
|
45
|
-
|
|
46
|
-
it('only exposes close to the creator/capability and surfaces a forbidden close', async () => {
|
|
47
|
-
const api = baseApi(); api.closePoll.mockRejectedValue({ response: { data: { detail: 'Not permitted' } } });
|
|
48
|
-
const { rerender } = render(<MessagingProvider api={api} active={false}><PollCard message={{ id: 7, poll: { id: 1, question: 'Q', options: [], created_by: 2 }}} /></MessagingProvider>);
|
|
49
|
-
expect(screen.queryByRole('button', { name: 'MessagingPoll.CLOSE' })).toBeNull();
|
|
50
|
-
rerender(<MessagingProvider api={api} active={false}><PollCard canClose message={{ id: 7, poll: { id: 1, question: 'Q', options: [] }}} /></MessagingProvider>);
|
|
51
|
-
fireEvent.click(screen.getByRole('button', { name: 'MessagingPoll.CLOSE' })); await screen.findByRole('alert');
|
|
52
|
-
});
|
|
53
|
-
|
|
54
|
-
it('creates polls with an idempotency key', async () => {
|
|
55
|
-
const api = baseApi(); api.createPoll.mockResolvedValue({ id: 70, conversation_id: 4, poll: { id: 1 } });
|
|
56
|
-
render(<MessagingProvider api={api} active={false}><Composer conversationId={4} /></MessagingProvider>);
|
|
57
|
-
fireEvent.click(screen.getByRole('button', { name: 'MessagingPoll.CREATE' })); fireEvent.change(screen.getByLabelText('MessagingPoll.QUESTION'), { target: { value: 'Where?' } });
|
|
58
|
-
const options = screen.getAllByLabelText(/MessagingPoll.OPTION/); fireEvent.change(options[0], { target: { value: 'Here' } }); fireEvent.change(options[1], { target: { value: 'There' } });
|
|
59
|
-
fireEvent.click(screen.getAllByRole('button', { name: 'MessagingPoll.CREATE' })[0]); await waitFor(() => expect(api.createPoll).toHaveBeenCalled());
|
|
60
|
-
expect(api.createPoll.mock.calls[0][2].idempotencyKey).toBeTruthy();
|
|
61
|
-
});
|
|
62
|
-
|
|
63
|
-
it('mounts the scope config as an independent provider collaborator', async () => {
|
|
64
|
-
const api = baseApi(); api.getConversationConfig = vi.fn().mockResolvedValue({ dm_policy: 'all', group_chat_enabled: true, everyone_can_post: false });
|
|
65
|
-
render(<MessagingProvider api={api} active={false}><MessagingScopeConfig conversationId={4} /></MessagingProvider>);
|
|
66
|
-
await screen.findByLabelText('MessagingConfig.LABEL');
|
|
67
|
-
expect(api.getConversationConfig).toHaveBeenCalledWith(4);
|
|
68
|
-
});
|
|
69
|
-
|
|
70
|
-
it('creates an announcement with a title, body and host-supplied link target', async () => {
|
|
71
|
-
const api = baseApi(); api.createMessage = vi.fn().mockResolvedValue({ id: 90, conversation_id: 4, kind: 'announcement', title: 'Heads up' });
|
|
72
|
-
render(<MessagingProvider api={api} active={false}><Composer conversationId={4} allowAnnouncement linkTarget="/events/4/info" /></MessagingProvider>);
|
|
73
|
-
fireEvent.click(screen.getByRole('button', { name: 'MessagingAnnouncement.CREATE' }));
|
|
74
|
-
fireEvent.change(screen.getByLabelText('MessagingAnnouncement.TITLE'), { target: { value: 'Heads up' } });
|
|
75
|
-
fireEvent.change(screen.getByLabelText('MessagingAnnouncement.BODY'), { target: { value: 'Schedule changed.' } });
|
|
76
|
-
fireEvent.click(screen.getAllByRole('button', { name: 'MessagingAnnouncement.SEND' })[0]);
|
|
77
|
-
await waitFor(() => expect(api.createMessage).toHaveBeenCalled());
|
|
78
|
-
const [, payload] = api.createMessage.mock.calls[0];
|
|
79
|
-
expect(payload).toMatchObject({ kind: 'announcement', title: 'Heads up', body: 'Schedule changed.', link_target: '/events/4/info' });
|
|
80
|
-
});
|
|
81
|
-
|
|
82
|
-
it('carries title and link_target into the optimistic row, not just the final REST payload', async () => {
|
|
83
|
-
const api = baseApi(); api.createMessage = vi.fn().mockReturnValue(new Promise(() => {}));
|
|
84
|
-
render(<MessagingProvider api={api} active={false}><Composer conversationId={4} allowAnnouncement linkTarget="/events/4/info" /><CacheState /></MessagingProvider>);
|
|
85
|
-
fireEvent.click(screen.getByRole('button', { name: 'MessagingAnnouncement.CREATE' }));
|
|
86
|
-
fireEvent.change(screen.getByLabelText('MessagingAnnouncement.TITLE'), { target: { value: 'Heads up' } });
|
|
87
|
-
fireEvent.click(screen.getAllByRole('button', { name: 'MessagingAnnouncement.SEND' })[0]);
|
|
88
|
-
await waitFor(() => {
|
|
89
|
-
const [optimistic] = Object.values(JSON.parse(screen.getByTestId('cache').textContent).messages);
|
|
90
|
-
expect(optimistic.status).toBe('pending');
|
|
91
|
-
expect(optimistic.title).toBe('Heads up');
|
|
92
|
-
expect(optimistic.link_target).toBe('/events/4/info');
|
|
93
|
-
});
|
|
94
|
-
});
|
|
95
|
-
|
|
96
|
-
it('does not offer announcement composing unless the host opts in', () => {
|
|
97
|
-
const api = baseApi();
|
|
98
|
-
render(<MessagingProvider api={api} active={false}><Composer conversationId={4} /></MessagingProvider>);
|
|
99
|
-
expect(screen.queryByRole('button', { name: 'MessagingAnnouncement.CREATE' })).toBeNull();
|
|
100
|
-
});
|
|
101
|
-
|
|
102
|
-
it('never offers announcement composing in a direct conversation, even when the host allows it', () => {
|
|
103
|
-
// A host's allowAnnouncement is typically an event-manager permission check
|
|
104
|
-
// with no notion of which conversation is currently open — broadcasting to
|
|
105
|
-
// a 1:1 direct chat is never meaningful regardless of that permission.
|
|
106
|
-
const api = baseApi();
|
|
107
|
-
render(<MessagingProvider api={api} active={false}><Composer conversationId={4} allowAnnouncement conversation={{ kind: 'direct' }} /></MessagingProvider>);
|
|
108
|
-
expect(screen.queryByRole('button', { name: 'MessagingAnnouncement.CREATE' })).toBeNull();
|
|
109
|
-
});
|
|
110
|
-
|
|
111
|
-
it('still offers announcement composing for a non-direct conversation when the host allows it', () => {
|
|
112
|
-
const api = baseApi();
|
|
113
|
-
render(<MessagingProvider api={api} active={false}><Composer conversationId={4} allowAnnouncement conversation={{ kind: 'group' }} /></MessagingProvider>);
|
|
114
|
-
expect(screen.getByRole('button', { name: 'MessagingAnnouncement.CREATE' })).toBeTruthy();
|
|
115
|
-
});
|
|
116
|
-
|
|
117
|
-
it('disables the chip while pending, then rolls back and re-enables it on API failure', async () => {
|
|
118
|
-
let rejectAdd; const api = baseApi(); api.addReaction.mockReturnValue(new Promise((_, reject) => { rejectAdd = reject; }));
|
|
119
|
-
render(<MessagingProvider api={api} active={false}><ReactionBar message={{ id: 7, reactions: [{ emoji: '👍', count: 1, reacted: false }] }} /></MessagingProvider>);
|
|
120
|
-
const chip = screen.getByRole('button', { name: 'MessagingReactions.TOGGLE' });
|
|
121
|
-
fireEvent.click(chip);
|
|
122
|
-
await waitFor(() => expect(chip.className.includes('Mui-disabled')).toBe(true));
|
|
123
|
-
rejectAdd({ response: { data: { detail: 'Reactions disabled' } } });
|
|
124
|
-
await screen.findByRole('alert');
|
|
125
|
-
expect(chip.className.includes('Mui-disabled')).toBe(false);
|
|
126
|
-
});
|
|
127
|
-
|
|
128
|
-
it('ignores a second click on the same reaction while the first toggle is still in flight', async () => {
|
|
129
|
-
let resolveAdd; const api = baseApi(); api.addReaction.mockReturnValue(new Promise((resolve) => { resolveAdd = resolve; }));
|
|
130
|
-
render(<MessagingProvider api={api} active={false}><ReactionBar message={{ id: 7, reactions: [{ emoji: '👍', count: 1, reacted: false }] }} /></MessagingProvider>);
|
|
131
|
-
const chip = screen.getByRole('button', { name: 'MessagingReactions.TOGGLE' });
|
|
132
|
-
fireEvent.click(chip); fireEvent.click(chip);
|
|
133
|
-
resolveAdd({ reactions: [{ emoji: '👍', count: 2, reacted: true }] });
|
|
134
|
-
await waitFor(() => expect(api.addReaction).toHaveBeenCalledTimes(1));
|
|
135
|
-
});
|
|
136
|
-
});
|
|
@@ -1,93 +0,0 @@
|
|
|
1
|
-
// @vitest-environment jsdom
|
|
2
|
-
import React from 'react';
|
|
3
|
-
import { afterEach, describe, expect, it, vi } from 'vitest';
|
|
4
|
-
import { cleanup, render, screen, waitFor } from '@testing-library/react';
|
|
5
|
-
|
|
6
|
-
vi.mock('react-i18next', () => ({ useTranslation: () => ({ t: (key) => 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 { ConversationList } from '../src/messaging/ConversationList';
|
|
18
|
-
import { applyFrame, MessagingProvider, useMessaging } from '../src/messaging/MessagingProvider';
|
|
19
|
-
|
|
20
|
-
function cache() { return { conversations: {}, messages: {}, threads: {}, polls: {}, reactions: {}, receipts: {}, unread: { unread_count: 0, by_conversation: {} }, cursors: { conversations: null, messages: {}, threads: {} } }; }
|
|
21
|
-
|
|
22
|
-
afterEach(() => { cleanup(); realtimeSubscribers.clear(); });
|
|
23
|
-
|
|
24
|
-
describe('last-message preview and conversation reorder', () => {
|
|
25
|
-
it('moves a conversation to the top and updates its preview from a server-shaped conversation_upsert frame', async () => {
|
|
26
|
-
const api = {
|
|
27
|
-
listConversations: vi.fn().mockResolvedValue({
|
|
28
|
-
results: [
|
|
29
|
-
{ id: 1, title: 'Older', last_message_at: '2026-07-31T09:00:00Z', last_message: { excerpt: 'Old preview' } },
|
|
30
|
-
{ id: 2, title: 'Newer', last_message_at: '2026-07-31T10:00:00Z', last_message: { excerpt: 'Newer preview' } },
|
|
31
|
-
],
|
|
32
|
-
next_cursor: null,
|
|
33
|
-
}),
|
|
34
|
-
getUnreadCount: vi.fn().mockResolvedValue({ unread_count: 0, by_conversation: {} }),
|
|
35
|
-
listMessages: vi.fn().mockResolvedValue({ results: [] }),
|
|
36
|
-
};
|
|
37
|
-
render(<MessagingProvider api={api}><ConversationList /></MessagingProvider>);
|
|
38
|
-
await screen.findByText('Newer preview');
|
|
39
|
-
// Server-shaped conversation_upsert payload: serialize_conversation_core's
|
|
40
|
-
// real keys (id, last_message_at, last_message: {excerpt}), not a
|
|
41
|
-
// client-invented shape.
|
|
42
|
-
dispatchMessagingFrame({
|
|
43
|
-
envelope: 'messaging', type: 'conversation_upsert', event_id: 'evt-1', conversation_id: 1,
|
|
44
|
-
id: '1', last_message_at: '2026-07-31T12:00:00Z', last_message: { excerpt: 'Fresh reply' },
|
|
45
|
-
});
|
|
46
|
-
await screen.findByText('Fresh reply');
|
|
47
|
-
const rows = screen.getAllByRole('button').map((el) => el.textContent);
|
|
48
|
-
const olderIndex = rows.findIndex((text) => text.includes('Older'));
|
|
49
|
-
const newerIndex = rows.findIndex((text) => text.includes('Newer'));
|
|
50
|
-
expect(olderIndex).toBeGreaterThanOrEqual(0);
|
|
51
|
-
expect(olderIndex).toBeLessThan(newerIndex);
|
|
52
|
-
});
|
|
53
|
-
|
|
54
|
-
it('reflects an edited or deleted last message through a REST refresh', async () => {
|
|
55
|
-
const api = {
|
|
56
|
-
listConversations: vi.fn()
|
|
57
|
-
.mockResolvedValueOnce({ results: [{ id: 1, title: 'Chat', last_message: { excerpt: 'Original text' } }], next_cursor: null })
|
|
58
|
-
.mockResolvedValueOnce({ results: [{ id: 1, title: 'Chat', last_message: { excerpt: '' } }], next_cursor: null }),
|
|
59
|
-
getUnreadCount: vi.fn().mockResolvedValue({ unread_count: 0, by_conversation: {} }),
|
|
60
|
-
listMessages: vi.fn().mockResolvedValue({ results: [] }),
|
|
61
|
-
};
|
|
62
|
-
function Refresher() {
|
|
63
|
-
const { refreshConversations } = useMessaging();
|
|
64
|
-
return <button onClick={() => refreshConversations()}>refresh</button>;
|
|
65
|
-
}
|
|
66
|
-
render(<MessagingProvider api={api}><ConversationList /><Refresher /></MessagingProvider>);
|
|
67
|
-
await screen.findByText('Original text');
|
|
68
|
-
screen.getByText('refresh').click();
|
|
69
|
-
await waitFor(() => expect(screen.queryByText('Original text')).toBeNull());
|
|
70
|
-
await screen.findByText('MessagingList.NO_MESSAGES');
|
|
71
|
-
});
|
|
72
|
-
|
|
73
|
-
it('applies a real message_edited frame (dcm always attaches frame.message) and updates the edited body', () => {
|
|
74
|
-
const state = { ...cache(), messages: { 'msg-1': { id: 'msg-1', conversation_id: 'conv-1', body: 'Before' } } };
|
|
75
|
-
// dcm's publish_messaging_event (realtime.py) always attaches a full
|
|
76
|
-
// frame.message = serialize_message(message) for message_edited, never
|
|
77
|
-
// just {message_id} alone — verified against django_core_micha's actual
|
|
78
|
-
// realtime.py. This is the real wire shape, not a client-invented one.
|
|
79
|
-
const next = applyFrame(state, {
|
|
80
|
-
envelope: 'messaging', type: 'message_edited', event_id: 'evt-2', conversation_id: 'conv-1', message_id: 'msg-1',
|
|
81
|
-
message: { id: 'msg-1', conversation_id: 'conv-1', body: 'After edit', edited_at: '2026-07-31T12:00:00Z' },
|
|
82
|
-
}, null);
|
|
83
|
-
expect(next.messages['msg-1'].body).toBe('After edit');
|
|
84
|
-
expect(next.messages['msg-1'].edited_at).toBe('2026-07-31T12:00:00Z');
|
|
85
|
-
});
|
|
86
|
-
|
|
87
|
-
it('keys a message_edited frame by message_id defensively, even if a producer ever omitted frame.message', () => {
|
|
88
|
-
const state = { ...cache(), messages: { 'msg-1': { id: 'msg-1', conversation_id: 'conv-1', body: 'Before' } } };
|
|
89
|
-
const next = applyFrame(state, { envelope: 'messaging', type: 'message_edited', event_id: 'evt-3', conversation_id: 'conv-1', message_id: 'msg-1' }, null);
|
|
90
|
-
expect(next.messages['msg-1']).toBeTruthy();
|
|
91
|
-
expect(next.messages['conv-1']).toBeUndefined();
|
|
92
|
-
});
|
|
93
|
-
});
|
|
@@ -1,51 +0,0 @@
|
|
|
1
|
-
// @vitest-environment jsdom
|
|
2
|
-
import React from 'react';
|
|
3
|
-
import { afterEach, describe, expect, it, vi } from 'vitest';
|
|
4
|
-
import { cleanup, render, screen } from '@testing-library/react';
|
|
5
|
-
|
|
6
|
-
vi.mock('react-i18next', () => ({ useTranslation: () => ({ t: (key) => key, i18n: { language: 'en' } }) }));
|
|
7
|
-
vi.mock('../src/notifications/realtime', () => ({ useRealtime: () => ({ subscribe: () => () => {}, onReconnect: () => () => {} }) }));
|
|
8
|
-
|
|
9
|
-
import { MessageBubble } from '../src/messaging/MessageBubble';
|
|
10
|
-
import { MessagingProvider } from '../src/messaging/MessagingProvider';
|
|
11
|
-
|
|
12
|
-
function makeApi() {
|
|
13
|
-
return {
|
|
14
|
-
getReadStatus: vi.fn().mockResolvedValue({ all_read: false }),
|
|
15
|
-
getAttachment: vi.fn(), getAttachmentThumbnail: vi.fn(), addReaction: vi.fn(), removeReaction: vi.fn(),
|
|
16
|
-
votePoll: vi.fn(), closePoll: vi.fn(),
|
|
17
|
-
};
|
|
18
|
-
}
|
|
19
|
-
function renderMessage(body) {
|
|
20
|
-
return render(<MessagingProvider api={makeApi()} active={false}><MessageBubble message={{ id: 1, body, sender: { display_name: 'Ava' } }} conversation={{ kind: 'group' }} /></MessagingProvider>);
|
|
21
|
-
}
|
|
22
|
-
|
|
23
|
-
afterEach(cleanup);
|
|
24
|
-
|
|
25
|
-
describe('message URL linkification', () => {
|
|
26
|
-
it('renders http(s) URLs as safe external links', () => {
|
|
27
|
-
renderMessage('Open https://example.com/path for details.');
|
|
28
|
-
const link = screen.getByRole('link', { name: 'https://example.com/path' });
|
|
29
|
-
expect(link.getAttribute('href')).toBe('https://example.com/path');
|
|
30
|
-
expect(link.getAttribute('target')).toBe('_blank');
|
|
31
|
-
expect(link.getAttribute('rel')).toBe('noopener noreferrer');
|
|
32
|
-
});
|
|
33
|
-
|
|
34
|
-
it('does not turn javascript URLs into links', () => {
|
|
35
|
-
renderMessage('javascript:alert(1)');
|
|
36
|
-
expect(screen.queryByRole('link')).toBeNull();
|
|
37
|
-
expect(screen.getByText('javascript:alert(1)')).toBeTruthy();
|
|
38
|
-
});
|
|
39
|
-
|
|
40
|
-
it('leaves surrounding prose outside the link and trims sentence punctuation', () => {
|
|
41
|
-
const { container } = renderMessage('See https://example.com/path, then continue reading.');
|
|
42
|
-
const link = screen.getByRole('link');
|
|
43
|
-
expect(link.textContent).toBe('https://example.com/path');
|
|
44
|
-
// MUI's `Link` itself carries a `MuiTypography-root` class (it is a
|
|
45
|
-
// Typography variant), so `.closest('.MuiTypography-root')` would match
|
|
46
|
-
// the link, not its containing paragraph -- `.closest('p')` skips past it
|
|
47
|
-
// to the actual message-body Typography (MUI's default root tag for the
|
|
48
|
-
// unvaried `body1` variant used here).
|
|
49
|
-
expect(link.closest('p').textContent).toBe('See https://example.com/path, then continue reading.');
|
|
50
|
-
});
|
|
51
|
-
});
|