@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,70 +0,0 @@
|
|
|
1
|
-
// @vitest-environment jsdom
|
|
2
|
-
import React from 'react';
|
|
3
|
-
import { cleanup, fireEvent, render, screen } from '@testing-library/react';
|
|
4
|
-
import { afterEach, describe, expect, it, vi } from 'vitest';
|
|
5
|
-
|
|
6
|
-
vi.mock('react-i18next', () => ({
|
|
7
|
-
useTranslation: () => ({ t: (key, fallback) => (typeof fallback === 'string' ? fallback : key) }),
|
|
8
|
-
}));
|
|
9
|
-
|
|
10
|
-
import { PasswordSetForm } from '../src/components/PasswordSetForm';
|
|
11
|
-
|
|
12
|
-
afterEach(() => {
|
|
13
|
-
cleanup();
|
|
14
|
-
});
|
|
15
|
-
|
|
16
|
-
function fillAndSubmit(password1, password2) {
|
|
17
|
-
fireEvent.change(screen.getByLabelText('Auth.NEW_PASSWORD_LABEL'), { target: { value: password1 } });
|
|
18
|
-
fireEvent.change(screen.getByLabelText('Auth.PASSWORD_CONFIRM_LABEL'), { target: { value: password2 } });
|
|
19
|
-
fireEvent.click(screen.getByRole('button', { name: 'Auth.PASSWORD_SET_BUTTON' }));
|
|
20
|
-
}
|
|
21
|
-
|
|
22
|
-
describe('PasswordSetForm', () => {
|
|
23
|
-
it('renders the default password-rules helperText', () => {
|
|
24
|
-
render(<PasswordSetForm onSubmit={vi.fn()} />);
|
|
25
|
-
expect(screen.getAllByText('Auth.PASSWORD_RULES_HINT').length).toBeGreaterThan(0);
|
|
26
|
-
});
|
|
27
|
-
|
|
28
|
-
it('lets a caller override the helperText via passwordRulesHint', () => {
|
|
29
|
-
render(<PasswordSetForm onSubmit={vi.fn()} passwordRulesHint="Custom rule text" />);
|
|
30
|
-
expect(screen.getAllByText('Custom rule text').length).toBeGreaterThan(0);
|
|
31
|
-
expect(screen.queryByText('Auth.PASSWORD_RULES_HINT')).toBeNull();
|
|
32
|
-
});
|
|
33
|
-
|
|
34
|
-
it('blocks submit and shows the local error for a password shorter than 8 characters', () => {
|
|
35
|
-
const onSubmit = vi.fn();
|
|
36
|
-
render(<PasswordSetForm onSubmit={onSubmit} />);
|
|
37
|
-
fillAndSubmit('short1', 'short1');
|
|
38
|
-
expect(screen.getByText('Auth.PASSWORD_TOO_SHORT_LOCAL')).toBeTruthy();
|
|
39
|
-
expect(onSubmit).not.toHaveBeenCalled();
|
|
40
|
-
});
|
|
41
|
-
|
|
42
|
-
it('blocks submit and shows the local error for an entirely numeric password', () => {
|
|
43
|
-
const onSubmit = vi.fn();
|
|
44
|
-
render(<PasswordSetForm onSubmit={onSubmit} />);
|
|
45
|
-
fillAndSubmit('12345678', '12345678');
|
|
46
|
-
expect(screen.getByText('Auth.PASSWORD_NUMERIC_LOCAL')).toBeTruthy();
|
|
47
|
-
expect(onSubmit).not.toHaveBeenCalled();
|
|
48
|
-
});
|
|
49
|
-
|
|
50
|
-
it('calls onSubmit for a valid, non-numeric password of sufficient length', () => {
|
|
51
|
-
const onSubmit = vi.fn();
|
|
52
|
-
render(<PasswordSetForm onSubmit={onSubmit} />);
|
|
53
|
-
fillAndSubmit('correct-horse-1', 'correct-horse-1');
|
|
54
|
-
expect(onSubmit).toHaveBeenCalledWith('correct-horse-1');
|
|
55
|
-
});
|
|
56
|
-
|
|
57
|
-
it('honours a custom minPasswordLength for an app with a looser backend policy', () => {
|
|
58
|
-
const onSubmit = vi.fn();
|
|
59
|
-
render(<PasswordSetForm onSubmit={onSubmit} minPasswordLength={4} />);
|
|
60
|
-
fillAndSubmit('ab12', 'ab12');
|
|
61
|
-
expect(onSubmit).toHaveBeenCalledWith('ab12');
|
|
62
|
-
});
|
|
63
|
-
|
|
64
|
-
it('allows an entirely numeric password when allowNumericPassword is set', () => {
|
|
65
|
-
const onSubmit = vi.fn();
|
|
66
|
-
render(<PasswordSetForm onSubmit={onSubmit} allowNumericPassword />);
|
|
67
|
-
fillAndSubmit('12345678', '12345678');
|
|
68
|
-
expect(onSubmit).toHaveBeenCalledWith('12345678');
|
|
69
|
-
});
|
|
70
|
-
});
|
|
@@ -1,142 +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 } from '@testing-library/react';
|
|
5
|
-
|
|
6
|
-
vi.mock('react-i18next', () => ({
|
|
7
|
-
useTranslation: () => ({
|
|
8
|
-
t: (key, params) => (params && Object.keys(params).length ? `${key}:${JSON.stringify(params)}` : key),
|
|
9
|
-
}),
|
|
10
|
-
}));
|
|
11
|
-
|
|
12
|
-
const onboardingModule = vi.hoisted(() => ({ useOnboarding: vi.fn() }));
|
|
13
|
-
vi.mock('../src/onboarding/OnboardingProvider', () => onboardingModule);
|
|
14
|
-
|
|
15
|
-
const notificationsModule = vi.hoisted(() => ({ useNotifications: vi.fn() }));
|
|
16
|
-
vi.mock('../src/notifications/NotificationsProvider', () => notificationsModule);
|
|
17
|
-
|
|
18
|
-
const realtimeModule = vi.hoisted(() => ({ useRealtime: vi.fn(), DEFAULT_ENVELOPE: 'notification' }));
|
|
19
|
-
vi.mock('../src/notifications/realtime', () => realtimeModule);
|
|
20
|
-
|
|
21
|
-
import { PopupSurface } from '../src/notifications/PopupSurface';
|
|
22
|
-
|
|
23
|
-
describe('PopupSurface (NOTIF-12 scope B/C)', () => {
|
|
24
|
-
let handler;
|
|
25
|
-
let subscribeFn;
|
|
26
|
-
let markSeen;
|
|
27
|
-
let markDismissed;
|
|
28
|
-
|
|
29
|
-
beforeEach(() => {
|
|
30
|
-
vi.clearAllMocks();
|
|
31
|
-
handler = null;
|
|
32
|
-
subscribeFn = (envelope, fn) => {
|
|
33
|
-
handler = fn;
|
|
34
|
-
return () => { handler = null; };
|
|
35
|
-
};
|
|
36
|
-
markSeen = vi.fn();
|
|
37
|
-
markDismissed = vi.fn();
|
|
38
|
-
notificationsModule.useNotifications.mockReturnValue({ markSeen, markDismissed, markDone: vi.fn() });
|
|
39
|
-
onboardingModule.useOnboarding.mockReturnValue({ activeSteps: [] });
|
|
40
|
-
realtimeModule.useRealtime.mockImplementation(() => ({ subscribe: subscribeFn }));
|
|
41
|
-
});
|
|
42
|
-
|
|
43
|
-
afterEach(() => {
|
|
44
|
-
cleanup();
|
|
45
|
-
});
|
|
46
|
-
|
|
47
|
-
function push(data) {
|
|
48
|
-
act(() => {
|
|
49
|
-
handler(data);
|
|
50
|
-
});
|
|
51
|
-
}
|
|
52
|
-
|
|
53
|
-
it('renders nothing when no popup-eligible notification is present', () => {
|
|
54
|
-
render(<PopupSurface />);
|
|
55
|
-
|
|
56
|
-
expect(screen.queryByRole('dialog')).toBeNull();
|
|
57
|
-
});
|
|
58
|
-
|
|
59
|
-
it('renders a popup-eligible notification once, marking seen exactly once on display, and shows the notification title (not the onboarding header)', () => {
|
|
60
|
-
render(<PopupSurface />);
|
|
61
|
-
|
|
62
|
-
push({ notification_id: 1, channel: 'popup', content: { title_key: 'T', body_key: 'B', params: {} } });
|
|
63
|
-
|
|
64
|
-
expect(screen.getByRole('dialog')).toBeTruthy();
|
|
65
|
-
expect(screen.getByText('T')).toBeTruthy();
|
|
66
|
-
expect(screen.queryByText('Onboarding.SETUP')).toBeNull();
|
|
67
|
-
expect(markSeen).toHaveBeenCalledTimes(1);
|
|
68
|
-
expect(markSeen).toHaveBeenCalledWith([1]);
|
|
69
|
-
});
|
|
70
|
-
|
|
71
|
-
it('marks using the wire recipient_id (feed/mark/ id-space), not the notification_id, when present', () => {
|
|
72
|
-
render(<PopupSurface />);
|
|
73
|
-
|
|
74
|
-
push({ notification_id: 10, recipient_id: 999, channel: 'popup', content: { title_key: 'T' } });
|
|
75
|
-
|
|
76
|
-
expect(markSeen).toHaveBeenCalledWith([999]);
|
|
77
|
-
|
|
78
|
-
fireEvent.click(screen.getByRole('button', { name: 'PopupSurface.CLOSE' }));
|
|
79
|
-
|
|
80
|
-
expect(markDismissed).toHaveBeenCalledWith([999]);
|
|
81
|
-
});
|
|
82
|
-
|
|
83
|
-
it('fires markDismissed, never markDone, when the popup is closed', () => {
|
|
84
|
-
const { markDone } = notificationsModule.useNotifications();
|
|
85
|
-
render(<PopupSurface />);
|
|
86
|
-
push({ notification_id: 1, channel: 'popup', content: { title_key: 'T' } });
|
|
87
|
-
|
|
88
|
-
fireEvent.click(screen.getByRole('button', { name: 'PopupSurface.CLOSE' }));
|
|
89
|
-
|
|
90
|
-
expect(markDismissed).toHaveBeenCalledWith([1]);
|
|
91
|
-
expect(markDone).not.toHaveBeenCalled();
|
|
92
|
-
expect(screen.queryByRole('dialog')).toBeNull();
|
|
93
|
-
});
|
|
94
|
-
|
|
95
|
-
it('ignores a chip-channel message and a channel-less legacy message — no popup storm', () => {
|
|
96
|
-
render(<PopupSurface />);
|
|
97
|
-
|
|
98
|
-
push({ notification_id: 2, channel: 'chip', content: { title_key: 'T' } });
|
|
99
|
-
push({ notification_id: 3, content: { title_key: 'T' } });
|
|
100
|
-
|
|
101
|
-
expect(screen.queryByRole('dialog')).toBeNull();
|
|
102
|
-
expect(markSeen).not.toHaveBeenCalled();
|
|
103
|
-
});
|
|
104
|
-
|
|
105
|
-
it('ignores a notification.status message regardless of its channel field', () => {
|
|
106
|
-
render(<PopupSurface />);
|
|
107
|
-
|
|
108
|
-
push({ type: 'notification.status', notification_id: 4, channel: 'popup', status: {} });
|
|
109
|
-
|
|
110
|
-
expect(screen.queryByRole('dialog')).toBeNull();
|
|
111
|
-
});
|
|
112
|
-
|
|
113
|
-
it('coexistence: a blocking onboarding step suppresses the popup; it appears once the step clears, never stacking two dialogs', () => {
|
|
114
|
-
onboardingModule.useOnboarding.mockReturnValue({ activeSteps: [{ id: 'cookie_consent', blocking: true }] });
|
|
115
|
-
const { rerender } = render(<PopupSurface />);
|
|
116
|
-
|
|
117
|
-
push({ notification_id: 5, channel: 'popup', content: { title_key: 'T' } });
|
|
118
|
-
expect(screen.queryByRole('dialog')).toBeNull();
|
|
119
|
-
expect(markSeen).not.toHaveBeenCalled();
|
|
120
|
-
|
|
121
|
-
onboardingModule.useOnboarding.mockReturnValue({ activeSteps: [] });
|
|
122
|
-
rerender(<PopupSurface />);
|
|
123
|
-
|
|
124
|
-
expect(screen.getAllByRole('dialog')).toHaveLength(1);
|
|
125
|
-
expect(markSeen).toHaveBeenCalledWith([5]);
|
|
126
|
-
});
|
|
127
|
-
|
|
128
|
-
it('coexistence: a non-blocking onboarding step also suppresses the popup, never stacking two dialogs', () => {
|
|
129
|
-
onboardingModule.useOnboarding.mockReturnValue({ activeSteps: [{ id: 'browser_push', blocking: false }] });
|
|
130
|
-
const { rerender } = render(<PopupSurface />);
|
|
131
|
-
|
|
132
|
-
push({ notification_id: 6, channel: 'popup', content: { title_key: 'T' } });
|
|
133
|
-
expect(screen.queryByRole('dialog')).toBeNull();
|
|
134
|
-
expect(markSeen).not.toHaveBeenCalled();
|
|
135
|
-
|
|
136
|
-
onboardingModule.useOnboarding.mockReturnValue({ activeSteps: [] });
|
|
137
|
-
rerender(<PopupSurface />);
|
|
138
|
-
|
|
139
|
-
expect(screen.getAllByRole('dialog')).toHaveLength(1);
|
|
140
|
-
expect(markSeen).toHaveBeenCalledWith([6]);
|
|
141
|
-
});
|
|
142
|
-
});
|
|
@@ -1,194 +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
|
-
import { ThemeProvider, createTheme } from '@mui/material/styles';
|
|
6
|
-
|
|
7
|
-
vi.mock('react-i18next', () => ({
|
|
8
|
-
useTranslation: () => ({
|
|
9
|
-
t: (key, fallback) => ({
|
|
10
|
-
'Profile.USERNAME_LABEL': 'Username',
|
|
11
|
-
'Auth.EMAIL_LABEL': 'Email',
|
|
12
|
-
'Profile.FIRST_NAME_LABEL': 'First name',
|
|
13
|
-
'Profile.LAST_NAME_LABEL': 'Last name',
|
|
14
|
-
'Profile.ACCEPT_PRIVACY_LABEL': 'Accept privacy statement',
|
|
15
|
-
'Profile.ACCEPT_COOKIES_LABEL': 'Accept convenience cookies',
|
|
16
|
-
'Profile.SAVE_BUTTON': 'Save',
|
|
17
|
-
}[key] ?? fallback ?? key),
|
|
18
|
-
i18n: { exists: () => true },
|
|
19
|
-
}),
|
|
20
|
-
}));
|
|
21
|
-
|
|
22
|
-
vi.mock('../src/auth/authApi', () => ({
|
|
23
|
-
fetchCookieStatement: vi.fn(),
|
|
24
|
-
fetchPrivacyStatement: vi.fn(),
|
|
25
|
-
}));
|
|
26
|
-
|
|
27
|
-
import { AuthContext } from '../src/auth/AuthContext';
|
|
28
|
-
import { ProfileComponent } from '../src/components/ProfileComponent';
|
|
29
|
-
|
|
30
|
-
const theme = createTheme();
|
|
31
|
-
|
|
32
|
-
function makeUser(overrides = {}) {
|
|
33
|
-
return {
|
|
34
|
-
id: 17,
|
|
35
|
-
username: 'pat',
|
|
36
|
-
email: 'pat@example.com',
|
|
37
|
-
first_name: 'Pat',
|
|
38
|
-
last_name: 'Example',
|
|
39
|
-
accepted_privacy_statement: false,
|
|
40
|
-
accepted_convenience_cookies: true,
|
|
41
|
-
...overrides,
|
|
42
|
-
};
|
|
43
|
-
}
|
|
44
|
-
|
|
45
|
-
function profileTree(user, onSubmit) {
|
|
46
|
-
return (
|
|
47
|
-
<ThemeProvider theme={theme}>
|
|
48
|
-
<AuthContext.Provider value={{ user, loading: false }}>
|
|
49
|
-
<ProfileComponent onSubmit={onSubmit} showStatements={false} />
|
|
50
|
-
</AuthContext.Provider>
|
|
51
|
-
</ThemeProvider>
|
|
52
|
-
);
|
|
53
|
-
}
|
|
54
|
-
|
|
55
|
-
function renderProfile(user, onSubmit = vi.fn()) {
|
|
56
|
-
const view = render(profileTree(user, onSubmit));
|
|
57
|
-
return {
|
|
58
|
-
...view,
|
|
59
|
-
onSubmit,
|
|
60
|
-
setUser: (nextUser) => view.rerender(profileTree(nextUser, onSubmit)),
|
|
61
|
-
};
|
|
62
|
-
}
|
|
63
|
-
|
|
64
|
-
afterEach(() => {
|
|
65
|
-
cleanup();
|
|
66
|
-
vi.clearAllMocks();
|
|
67
|
-
});
|
|
68
|
-
|
|
69
|
-
describe('ProfileComponent user refresh', () => {
|
|
70
|
-
it('refreshes untouched editable fields while retaining the independently edited field', () => {
|
|
71
|
-
const { setUser } = renderProfile(makeUser());
|
|
72
|
-
fireEvent.change(screen.getByRole('textbox', { name: 'First name' }), {
|
|
73
|
-
target: { value: 'Local first' },
|
|
74
|
-
});
|
|
75
|
-
|
|
76
|
-
setUser(makeUser({
|
|
77
|
-
first_name: 'Server first',
|
|
78
|
-
last_name: 'Server last',
|
|
79
|
-
accepted_privacy_statement: true,
|
|
80
|
-
accepted_convenience_cookies: false,
|
|
81
|
-
}));
|
|
82
|
-
|
|
83
|
-
expect(screen.getByRole('textbox', { name: 'First name' }).value).toBe('Local first');
|
|
84
|
-
expect(screen.getByRole('textbox', { name: 'Last name' }).value).toBe('Server last');
|
|
85
|
-
expect(screen.getByRole('checkbox', { name: 'Accept privacy statement' }).checked).toBe(true);
|
|
86
|
-
expect(screen.getByRole('checkbox', { name: 'Accept convenience cookies' }).checked).toBe(false);
|
|
87
|
-
});
|
|
88
|
-
|
|
89
|
-
it('preserves edits for the same identity and refreshes untouched fields', async () => {
|
|
90
|
-
const { onSubmit, setUser } = renderProfile(makeUser());
|
|
91
|
-
fireEvent.change(screen.getByRole('textbox', { name: 'First name' }), {
|
|
92
|
-
target: { value: 'Patricia' },
|
|
93
|
-
});
|
|
94
|
-
fireEvent.change(screen.getByRole('textbox', { name: 'Last name' }), {
|
|
95
|
-
target: { value: 'Newname' },
|
|
96
|
-
});
|
|
97
|
-
fireEvent.click(screen.getByRole('checkbox', { name: 'Accept privacy statement' }));
|
|
98
|
-
fireEvent.click(screen.getByRole('checkbox', { name: 'Accept convenience cookies' }));
|
|
99
|
-
|
|
100
|
-
setUser(makeUser({
|
|
101
|
-
username: 'pat-updated',
|
|
102
|
-
email: 'new@example.com',
|
|
103
|
-
first_name: 'Server first',
|
|
104
|
-
last_name: 'Server last',
|
|
105
|
-
accepted_privacy_statement: false,
|
|
106
|
-
accepted_convenience_cookies: true,
|
|
107
|
-
}));
|
|
108
|
-
|
|
109
|
-
await waitFor(() => {
|
|
110
|
-
expect(screen.getByRole('textbox', { name: 'Username' }).value).toBe('pat-updated');
|
|
111
|
-
expect(screen.getByRole('textbox', { name: 'Email' }).value).toBe('new@example.com');
|
|
112
|
-
});
|
|
113
|
-
expect(screen.getByRole('textbox', { name: 'First name' }).value).toBe('Patricia');
|
|
114
|
-
expect(screen.getByRole('textbox', { name: 'Last name' }).value).toBe('Newname');
|
|
115
|
-
expect(screen.getByRole('checkbox', { name: 'Accept privacy statement' }).checked).toBe(true);
|
|
116
|
-
expect(screen.getByRole('checkbox', { name: 'Accept convenience cookies' }).checked).toBe(false);
|
|
117
|
-
|
|
118
|
-
fireEvent.click(screen.getByRole('button', { name: 'Save' }));
|
|
119
|
-
await waitFor(() => {
|
|
120
|
-
expect(onSubmit).toHaveBeenCalledWith({
|
|
121
|
-
first_name: 'Patricia',
|
|
122
|
-
last_name: 'Newname',
|
|
123
|
-
accepted_privacy_statement: true,
|
|
124
|
-
accepted_convenience_cookies: false,
|
|
125
|
-
});
|
|
126
|
-
});
|
|
127
|
-
});
|
|
128
|
-
|
|
129
|
-
it('resets every field when the identity changes', async () => {
|
|
130
|
-
const { setUser } = renderProfile(makeUser());
|
|
131
|
-
fireEvent.change(screen.getByRole('textbox', { name: 'First name' }), {
|
|
132
|
-
target: { value: 'Unsaved first' },
|
|
133
|
-
});
|
|
134
|
-
fireEvent.change(screen.getByRole('textbox', { name: 'Last name' }), {
|
|
135
|
-
target: { value: 'Unsaved last' },
|
|
136
|
-
});
|
|
137
|
-
fireEvent.click(screen.getByRole('checkbox', { name: 'Accept privacy statement' }));
|
|
138
|
-
fireEvent.click(screen.getByRole('checkbox', { name: 'Accept convenience cookies' }));
|
|
139
|
-
|
|
140
|
-
setUser(makeUser({
|
|
141
|
-
id: 18,
|
|
142
|
-
username: 'lee',
|
|
143
|
-
email: 'lee@example.com',
|
|
144
|
-
first_name: 'Lee',
|
|
145
|
-
last_name: 'Newperson',
|
|
146
|
-
accepted_privacy_statement: false,
|
|
147
|
-
accepted_convenience_cookies: true,
|
|
148
|
-
}));
|
|
149
|
-
|
|
150
|
-
await waitFor(() => {
|
|
151
|
-
expect(screen.getByRole('textbox', { name: 'First name' }).value).toBe('Lee');
|
|
152
|
-
});
|
|
153
|
-
expect(screen.getByRole('textbox', { name: 'Username' }).value).toBe('lee');
|
|
154
|
-
expect(screen.getByRole('textbox', { name: 'Email' }).value).toBe('lee@example.com');
|
|
155
|
-
expect(screen.getByRole('textbox', { name: 'Last name' }).value).toBe('Newperson');
|
|
156
|
-
expect(screen.getByRole('checkbox', { name: 'Accept privacy statement' }).checked).toBe(false);
|
|
157
|
-
expect(screen.getByRole('checkbox', { name: 'Accept convenience cookies' }).checked).toBe(true);
|
|
158
|
-
});
|
|
159
|
-
|
|
160
|
-
it('clears edits on logout before initializing the next login', async () => {
|
|
161
|
-
const { setUser } = renderProfile(makeUser());
|
|
162
|
-
fireEvent.change(screen.getByRole('textbox', { name: 'First name' }), {
|
|
163
|
-
target: { value: 'Unsaved first' },
|
|
164
|
-
});
|
|
165
|
-
fireEvent.click(screen.getByRole('checkbox', { name: 'Accept privacy statement' }));
|
|
166
|
-
fireEvent.click(screen.getByRole('checkbox', { name: 'Accept convenience cookies' }));
|
|
167
|
-
|
|
168
|
-
setUser(null);
|
|
169
|
-
expect(await screen.findByText('User not logged in.')).toBeTruthy();
|
|
170
|
-
setUser(makeUser({
|
|
171
|
-
first_name: 'Pat after login',
|
|
172
|
-
accepted_privacy_statement: false,
|
|
173
|
-
accepted_convenience_cookies: true,
|
|
174
|
-
}));
|
|
175
|
-
|
|
176
|
-
await waitFor(() => {
|
|
177
|
-
expect(screen.getByRole('textbox', { name: 'First name' }).value).toBe('Pat after login');
|
|
178
|
-
});
|
|
179
|
-
expect(screen.getByRole('checkbox', { name: 'Accept privacy statement' }).checked).toBe(false);
|
|
180
|
-
expect(screen.getByRole('checkbox', { name: 'Accept convenience cookies' }).checked).toBe(true);
|
|
181
|
-
});
|
|
182
|
-
|
|
183
|
-
it('hydrates fields when the current user arrives asynchronously', async () => {
|
|
184
|
-
const { setUser } = renderProfile(null);
|
|
185
|
-
setUser(makeUser({ first_name: 'Hydrated' }));
|
|
186
|
-
|
|
187
|
-
await waitFor(() => {
|
|
188
|
-
expect(screen.getByRole('textbox', { name: 'First name' }).value).toBe('Hydrated');
|
|
189
|
-
expect(screen.getByRole('textbox', { name: 'Last name' }).value).toBe('Example');
|
|
190
|
-
});
|
|
191
|
-
expect(screen.getByRole('checkbox', { name: 'Accept privacy statement' }).checked).toBe(false);
|
|
192
|
-
expect(screen.getByRole('checkbox', { name: 'Accept convenience cookies' }).checked).toBe(true);
|
|
193
|
-
});
|
|
194
|
-
});
|
|
@@ -1,106 +0,0 @@
|
|
|
1
|
-
// @vitest-environment jsdom
|
|
2
|
-
|
|
3
|
-
import React from 'react';
|
|
4
|
-
import { cleanup, fireEvent, render, screen, waitFor } from '@testing-library/react';
|
|
5
|
-
import { afterEach, describe, expect, it, vi } from 'vitest';
|
|
6
|
-
|
|
7
|
-
const mockState = vi.hoisted(() => ({
|
|
8
|
-
createSignupQr: vi.fn().mockResolvedValue({
|
|
9
|
-
signup_url: 'https://example.test/signup?rt=token',
|
|
10
|
-
expires_at: '2026-09-01T12:00:00Z',
|
|
11
|
-
}),
|
|
12
|
-
}));
|
|
13
|
-
|
|
14
|
-
vi.mock('../src/auth/authApi', () => ({
|
|
15
|
-
createSignupQr: mockState.createSignupQr,
|
|
16
|
-
}));
|
|
17
|
-
|
|
18
|
-
vi.mock('qrcode.react', () => ({
|
|
19
|
-
QRCodeSVG: () => null,
|
|
20
|
-
}));
|
|
21
|
-
|
|
22
|
-
// A stable `t` reference matters here: it's an effect dependency in QrSignupManager, and
|
|
23
|
-
// the real react-i18next memoizes it across renders. A fresh function per render (a common
|
|
24
|
-
// shorthand mock elsewhere in this repo) would make that effect re-fire on every unrelated
|
|
25
|
-
// re-render (e.g. the setBusy(true) inside it), which is a mock artifact this test file must
|
|
26
|
-
// not reintroduce given it asserts exact createSignupQr call counts.
|
|
27
|
-
const stableT = (_key, fallback) => fallback;
|
|
28
|
-
// resolveErrorText (AUTH-10) reads i18n.exists/i18n.t off the object
|
|
29
|
-
// useTranslation() returns — kept module-scoped/stable for the same reason
|
|
30
|
-
// `stableT` is, above.
|
|
31
|
-
const stableI18n = { exists: () => false, t: stableT };
|
|
32
|
-
vi.mock('react-i18next', () => ({
|
|
33
|
-
useTranslation: () => ({ t: stableT, i18n: stableI18n }),
|
|
34
|
-
}));
|
|
35
|
-
|
|
36
|
-
import { QrSignupManager } from '../src/components/QrSignupManager';
|
|
37
|
-
|
|
38
|
-
describe('QrSignupManager registration context', () => {
|
|
39
|
-
afterEach(() => {
|
|
40
|
-
cleanup();
|
|
41
|
-
});
|
|
42
|
-
|
|
43
|
-
it('passes the department context and practical redemption default to the API', async () => {
|
|
44
|
-
mockState.createSignupQr.mockClear();
|
|
45
|
-
|
|
46
|
-
render(
|
|
47
|
-
<QrSignupManager
|
|
48
|
-
enabled
|
|
49
|
-
expiryDays={365}
|
|
50
|
-
registrationContext={{ group_ref: '42' }}
|
|
51
|
-
defaultMaxRedemptions={5000}
|
|
52
|
-
/>,
|
|
53
|
-
);
|
|
54
|
-
|
|
55
|
-
await waitFor(() => expect(mockState.createSignupQr).toHaveBeenCalledWith({
|
|
56
|
-
expires_minutes: 365 * 24 * 60,
|
|
57
|
-
max_redemptions: 5000,
|
|
58
|
-
registration_context: { group_ref: '42' },
|
|
59
|
-
}));
|
|
60
|
-
});
|
|
61
|
-
|
|
62
|
-
it('behaves exactly as before when the new props are omitted (existing AccountPage-style call)', async () => {
|
|
63
|
-
mockState.createSignupQr.mockClear();
|
|
64
|
-
|
|
65
|
-
render(<QrSignupManager enabled expiryDays={90} />);
|
|
66
|
-
|
|
67
|
-
await waitFor(() => expect(mockState.createSignupQr).toHaveBeenCalledWith({
|
|
68
|
-
expires_minutes: 90 * 24 * 60,
|
|
69
|
-
max_redemptions: 1,
|
|
70
|
-
}));
|
|
71
|
-
expect(mockState.createSignupQr).toHaveBeenCalledTimes(1);
|
|
72
|
-
});
|
|
73
|
-
|
|
74
|
-
it('fires exactly one create call when the context changes after a custom redemption count was set', async () => {
|
|
75
|
-
mockState.createSignupQr.mockClear();
|
|
76
|
-
|
|
77
|
-
const { rerender } = render(
|
|
78
|
-
<QrSignupManager
|
|
79
|
-
enabled
|
|
80
|
-
expiryDays={90}
|
|
81
|
-
registrationContext={{ group_ref: '1' }}
|
|
82
|
-
defaultMaxRedemptions={5000}
|
|
83
|
-
/>,
|
|
84
|
-
);
|
|
85
|
-
await waitFor(() => expect(mockState.createSignupQr).toHaveBeenCalledTimes(1));
|
|
86
|
-
|
|
87
|
-
fireEvent.change(screen.getByLabelText('Max redemptions'), { target: { value: '250' } });
|
|
88
|
-
|
|
89
|
-
mockState.createSignupQr.mockClear();
|
|
90
|
-
rerender(
|
|
91
|
-
<QrSignupManager
|
|
92
|
-
enabled
|
|
93
|
-
expiryDays={90}
|
|
94
|
-
registrationContext={{ group_ref: '2' }}
|
|
95
|
-
defaultMaxRedemptions={5000}
|
|
96
|
-
/>,
|
|
97
|
-
);
|
|
98
|
-
|
|
99
|
-
await waitFor(() => expect(mockState.createSignupQr).toHaveBeenCalledWith({
|
|
100
|
-
expires_minutes: 90 * 24 * 60,
|
|
101
|
-
max_redemptions: 5000,
|
|
102
|
-
registration_context: { group_ref: '2' },
|
|
103
|
-
}));
|
|
104
|
-
expect(mockState.createSignupQr).toHaveBeenCalledTimes(1);
|
|
105
|
-
});
|
|
106
|
-
});
|
|
@@ -1,49 +0,0 @@
|
|
|
1
|
-
// @vitest-environment jsdom
|
|
2
|
-
|
|
3
|
-
import React from 'react';
|
|
4
|
-
import { ThemeProvider } from '@mui/material/styles';
|
|
5
|
-
import { cleanup, render, screen } from '@testing-library/react';
|
|
6
|
-
import { afterEach, describe, expect, it, vi } from 'vitest';
|
|
7
|
-
|
|
8
|
-
vi.mock('../src/auth/authApi', () => ({
|
|
9
|
-
createSignupQr: vi.fn().mockResolvedValue({
|
|
10
|
-
signup_url: 'https://example.test/signup?rt=token',
|
|
11
|
-
expires_at: '2026-09-01T12:00:00Z',
|
|
12
|
-
}),
|
|
13
|
-
}));
|
|
14
|
-
|
|
15
|
-
vi.mock('qrcode.react', () => ({
|
|
16
|
-
QRCodeSVG: () => null,
|
|
17
|
-
}));
|
|
18
|
-
|
|
19
|
-
const stableT = (_key, fallback) => fallback;
|
|
20
|
-
const stableI18n = { exists: () => false, t: stableT };
|
|
21
|
-
vi.mock('react-i18next', () => ({
|
|
22
|
-
useTranslation: () => ({ t: stableT, i18n: stableI18n }),
|
|
23
|
-
}));
|
|
24
|
-
|
|
25
|
-
import { QrSignupManager } from '../src/components/QrSignupManager';
|
|
26
|
-
import { createAppTheme } from '../src/theme';
|
|
27
|
-
|
|
28
|
-
// jsdom serialises the resolved colour as rgb(), so compare against the theme's own value in that form.
|
|
29
|
-
function toRgb(hex) {
|
|
30
|
-
const [r, g, b] = [1, 3, 5].map((i) => parseInt(hex.slice(i, i + 2), 16));
|
|
31
|
-
return `rgb(${r}, ${g}, ${b})`;
|
|
32
|
-
}
|
|
33
|
-
|
|
34
|
-
describe('QrSignupManager info box', () => {
|
|
35
|
-
afterEach(cleanup);
|
|
36
|
-
|
|
37
|
-
it.each(['light', 'dark'])('paints background.subtle of the %s theme', async (mode) => {
|
|
38
|
-
const theme = createAppTheme({ palette: { mode, primary: { main: '#468AB2' } } });
|
|
39
|
-
render(
|
|
40
|
-
<ThemeProvider theme={theme}>
|
|
41
|
-
<QrSignupManager enabled expiryDays={90} />
|
|
42
|
-
</ThemeProvider>,
|
|
43
|
-
);
|
|
44
|
-
|
|
45
|
-
const title = await screen.findByText('Signup Access');
|
|
46
|
-
const box = title.parentElement;
|
|
47
|
-
expect(getComputedStyle(box).backgroundColor).toBe(toRgb(theme.palette.background.subtle));
|
|
48
|
-
});
|
|
49
|
-
});
|