@micha.bigler/ui-core-micha 3.14.3 → 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 +31 -0
- package/README.md +7 -0
- package/dist/auth/UserMenu.js +1 -1
- package/dist/auth/apiClient.js +7 -6
- package/dist/chat/ChatList.js +1 -1
- package/dist/chat/ChatThread.js +2 -1
- package/dist/chat/ChatWorkspace.js +1 -1
- package/dist/chat/ModelPicker.js +2 -5
- package/dist/chat/kitSxRegistry.js +9 -0
- package/dist/chat/useChatSocket.js +1 -1
- package/dist/components/LoginForm.js +1 -1
- package/dist/components/SecurityComponent.js +1 -1
- package/dist/components/UserListComponent.js +2 -8
- package/dist/components/charts/ChartFrame.js +1 -1
- package/dist/components/charts/ScatterChart.js +2 -1
- 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/layout/SectionNav.js +1 -1
- package/dist/messaging/AttachmentList.js +2 -2
- package/dist/messaging/Composer.js +2 -1
- package/dist/messaging/ConversationLaunchers.js +1 -4
- package/dist/messaging/ConversationList.js +1 -1
- package/dist/messaging/DirectMessageLauncher.js +1 -1
- package/dist/messaging/MessagingProvider.js +0 -0
- package/dist/messaging/PollCard.js +7 -5
- package/dist/messaging/ReadTicks.js +2 -2
- package/dist/messaging/Thread.js +5 -3
- package/dist/notifications/NotificationBell.js +4 -7
- package/dist/notifications/NotificationSettings.js +1 -1
- package/dist/onboarding/OnboardingProvider.js +3 -6
- package/dist/pages/AccountPage.js +1 -2
- package/dist/pages/LoginPage.js +2 -3
- package/dist/pages/PasswordChangePage.js +2 -3
- package/dist/pages/PasswordInvitePage.js +2 -3
- package/dist/pages/PasswordResetRequestPage.js +2 -3
- package/dist/pages/SignUpPage.js +2 -3
- package/dist/pages/SignupConfirmPage.js +2 -3
- package/dist/theme/createAppTheme.js +5 -4
- package/dist/theme/kitSxEntry.js +11 -0
- package/dist/theme/kitSxRegistry.js +2 -15
- package/dist/theme/themeCompleteness.js +3 -12
- package/dist/utils/auth-errors.js +4 -3
- package/package.json +41 -16
- package/.github/workflows/publish.yml +0 -126
- package/DESIGN.md +0 -60
- package/WORK_ORDERS.md +0 -148
- 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-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,367 +0,0 @@
|
|
|
1
|
-
// @vitest-environment jsdom
|
|
2
|
-
import React from 'react';
|
|
3
|
-
import i18next from 'i18next';
|
|
4
|
-
import { afterEach, describe, expect, it, vi } from 'vitest';
|
|
5
|
-
import { cleanup, fireEvent, render, screen } from '@testing-library/react';
|
|
6
|
-
import { I18nextProvider } from 'react-i18next';
|
|
7
|
-
import { ThemeProvider, createTheme } from '@mui/material/styles';
|
|
8
|
-
|
|
9
|
-
const chartSpy = vi.hoisted(() => vi.fn((props) => <div data-testid="mui-bar-chart" data-props={JSON.stringify(props)} />));
|
|
10
|
-
vi.mock('@mui/x-charts/BarChart', () => ({ BarChart: chartSpy }));
|
|
11
|
-
|
|
12
|
-
import { TimeSeriesChart } from '../src/components/charts/TimeSeriesChart';
|
|
13
|
-
|
|
14
|
-
const resources = {
|
|
15
|
-
en: {
|
|
16
|
-
translation: {
|
|
17
|
-
'TimeSeriesChart.RANGE_LABEL': 'Range',
|
|
18
|
-
'TimeSeriesChart.RANGE_1_DAY': '1 day',
|
|
19
|
-
'TimeSeriesChart.RANGE_1_WEEK': '1 week',
|
|
20
|
-
'TimeSeriesChart.RANGE_1_MONTH': '1 month',
|
|
21
|
-
'TimeSeriesChart.RANGE_1_YEAR': '1 year',
|
|
22
|
-
'TimeSeriesChart.SERIES_LABEL': 'Series',
|
|
23
|
-
'ChartFrame.EMPTY_DEFAULT': 'No data available.',
|
|
24
|
-
'ChartFrame.LOADING': 'Loading chart.',
|
|
25
|
-
'ChartFrame.ERROR_DEFAULT': 'The chart could not be loaded.',
|
|
26
|
-
},
|
|
27
|
-
},
|
|
28
|
-
};
|
|
29
|
-
|
|
30
|
-
const SAMPLE_DATA = {
|
|
31
|
-
xLabels: ['Mon', 'Tue', 'Wed'],
|
|
32
|
-
series: [
|
|
33
|
-
{ key: 'users', label: 'Users', data: [1, 2, 3] },
|
|
34
|
-
{ key: 'presence', label: 'Presence hours', data: [4, 5, 6] },
|
|
35
|
-
],
|
|
36
|
-
};
|
|
37
|
-
|
|
38
|
-
function renderChart(props = {}) {
|
|
39
|
-
const i18n = i18next.createInstance();
|
|
40
|
-
i18n.init({ lng: 'en', resources, interpolation: { escapeValue: false } });
|
|
41
|
-
const wrap = (chartProps) => (
|
|
42
|
-
<ThemeProvider theme={createTheme()}>
|
|
43
|
-
<I18nextProvider i18n={i18n}>
|
|
44
|
-
<TimeSeriesChart title="Activity" xAxisLabel="Day" yAxisLabel="Count" data={SAMPLE_DATA} {...chartProps} />
|
|
45
|
-
</I18nextProvider>
|
|
46
|
-
</ThemeProvider>
|
|
47
|
-
);
|
|
48
|
-
const view = render(wrap(props));
|
|
49
|
-
return { ...view, rerenderWith: (nextProps) => view.rerender(wrap(nextProps)) };
|
|
50
|
-
}
|
|
51
|
-
|
|
52
|
-
describe('TimeSeriesChart', () => {
|
|
53
|
-
afterEach(cleanup);
|
|
54
|
-
|
|
55
|
-
// Required test 1: selecting a range emits both the range AND the mapped
|
|
56
|
-
// granularity — asserts the emitted payload, not merely that the callback fired.
|
|
57
|
-
it('emits both the range and its mapped granularity when a preset is selected', () => {
|
|
58
|
-
const onRangeChange = vi.fn();
|
|
59
|
-
renderChart({ onRangeChange });
|
|
60
|
-
|
|
61
|
-
fireEvent.click(screen.getByRole('radio', { name: '1 day' }));
|
|
62
|
-
|
|
63
|
-
expect(onRangeChange).toHaveBeenCalledWith('1d', 'hour');
|
|
64
|
-
});
|
|
65
|
-
|
|
66
|
-
it.each([
|
|
67
|
-
['1 week', '1w', '4hour'],
|
|
68
|
-
['1 month', '1m', 'day'],
|
|
69
|
-
['1 year', '1y', 'month'],
|
|
70
|
-
])('maps %s to range=%s granularity=%s', (label, rangeKey, granularity) => {
|
|
71
|
-
const onRangeChange = vi.fn();
|
|
72
|
-
// defaultRange is '1w' — start from a different preset so every clicked
|
|
73
|
-
// option (including '1 week' itself) represents a real selection change.
|
|
74
|
-
renderChart({ onRangeChange, defaultRange: '1d' });
|
|
75
|
-
|
|
76
|
-
fireEvent.click(screen.getByRole('radio', { name: label }));
|
|
77
|
-
|
|
78
|
-
expect(onRangeChange).toHaveBeenCalledWith(rangeKey, granularity);
|
|
79
|
-
});
|
|
80
|
-
|
|
81
|
-
// Required test 2: toggling a series off removes it, leaves the others.
|
|
82
|
-
it('toggling a series off removes it from the rendered chart and leaves the other', () => {
|
|
83
|
-
renderChart();
|
|
84
|
-
|
|
85
|
-
fireEvent.click(screen.getByRole('checkbox', { name: 'Users' }));
|
|
86
|
-
|
|
87
|
-
const props = chartSpy.mock.calls.at(-1)[0];
|
|
88
|
-
expect(props.series).toHaveLength(1);
|
|
89
|
-
expect(props.series[0].label).toBe('Presence hours');
|
|
90
|
-
});
|
|
91
|
-
|
|
92
|
-
it('preserves the remaining series color when the other is toggled off', () => {
|
|
93
|
-
renderChart();
|
|
94
|
-
const initialProps = chartSpy.mock.calls.at(-1)[0];
|
|
95
|
-
const presenceColorBefore = initialProps.colors[1];
|
|
96
|
-
|
|
97
|
-
fireEvent.click(screen.getByRole('checkbox', { name: 'Users' }));
|
|
98
|
-
|
|
99
|
-
const afterProps = chartSpy.mock.calls.at(-1)[0];
|
|
100
|
-
expect(afterProps.colors[0]).toBe(presenceColorBefore);
|
|
101
|
-
});
|
|
102
|
-
|
|
103
|
-
// Required test 3: toggling all series off renders a stable empty chart.
|
|
104
|
-
it('toggling all series off renders a stable empty chart, no crash, no spinner', () => {
|
|
105
|
-
renderChart();
|
|
106
|
-
|
|
107
|
-
fireEvent.click(screen.getByRole('checkbox', { name: 'Users' }));
|
|
108
|
-
fireEvent.click(screen.getByRole('checkbox', { name: 'Presence hours' }));
|
|
109
|
-
|
|
110
|
-
expect(screen.getByText('No data available.')).toBeTruthy();
|
|
111
|
-
expect(screen.queryByLabelText('Loading chart.')).toBeNull();
|
|
112
|
-
expect(screen.queryByTestId('mui-bar-chart')).toBeNull();
|
|
113
|
-
});
|
|
114
|
-
|
|
115
|
-
// Required test 4: renders ChartFrame's empty state for empty data, exactly once.
|
|
116
|
-
it("renders ChartFrame's empty state for empty data, exactly once", () => {
|
|
117
|
-
renderChart({ data: { xLabels: [], series: [] } });
|
|
118
|
-
|
|
119
|
-
expect(screen.getAllByText('No data available.')).toHaveLength(1);
|
|
120
|
-
expect(screen.queryByTestId('mui-bar-chart')).toBeNull();
|
|
121
|
-
});
|
|
122
|
-
|
|
123
|
-
it('range picker and series toggles pass through loading and error to ChartFrame', () => {
|
|
124
|
-
renderChart({ loading: true });
|
|
125
|
-
expect(screen.getByLabelText('Loading chart.')).toBeTruthy();
|
|
126
|
-
});
|
|
127
|
-
|
|
128
|
-
// CHART-4 regression: neither ChartFrame nor BarChart ever received a
|
|
129
|
-
// height, so MUI X-Charts' responsive container measured a zero-height
|
|
130
|
-
// parent and drew no bars/axes (only the legend, sized by its own content,
|
|
131
|
-
// showed) -- confirmed live in production. A structural/rendered-size
|
|
132
|
-
// assertion in jsdom is NOT reliable here (verified: it stays green even
|
|
133
|
-
// without the fix, since jsdom's ResizeObserver handling doesn't reflect
|
|
134
|
-
// the real zero-height-parent browser behaviour) -- this asserts directly
|
|
135
|
-
// on the wiring instead: BarChart must receive a real, non-zero `height`,
|
|
136
|
-
// matching the confirmed-working dev/entries.jsx BarChartEntry reference
|
|
137
|
-
// (MUI's own native height prop, forwarded via BarChart's ...chartProps).
|
|
138
|
-
it('CHART-4: passes a real, non-zero height through to the underlying MUI BarChart', () => {
|
|
139
|
-
renderChart();
|
|
140
|
-
|
|
141
|
-
const props = chartSpy.mock.calls.at(-1)[0];
|
|
142
|
-
expect(props.height).toBeGreaterThan(0);
|
|
143
|
-
});
|
|
144
|
-
|
|
145
|
-
// CHART-3 regression: visibleKeys must not be captured only at first mount.
|
|
146
|
-
// Reproduces the live bug — host mounts with empty data, fetches
|
|
147
|
-
// asynchronously, then rerenders with real data. Before the fix this stayed
|
|
148
|
-
// on ChartFrame's empty state forever even with real series present.
|
|
149
|
-
it('CHART-3: renders the chart once data arrives after an empty-data mount', () => {
|
|
150
|
-
const { rerenderWith } = renderChart({ data: { xLabels: [], series: [] } });
|
|
151
|
-
expect(screen.getByText('No data available.')).toBeTruthy();
|
|
152
|
-
expect(screen.queryByTestId('mui-bar-chart')).toBeNull();
|
|
153
|
-
|
|
154
|
-
rerenderWith({ data: SAMPLE_DATA });
|
|
155
|
-
|
|
156
|
-
expect(screen.queryByText('No data available.')).toBeNull();
|
|
157
|
-
const props = chartSpy.mock.calls.at(-1)[0];
|
|
158
|
-
expect(props.series).toHaveLength(2);
|
|
159
|
-
});
|
|
160
|
-
|
|
161
|
-
it('CHART-3: preserves a manual toggle-off across a data update that keeps the same key', () => {
|
|
162
|
-
const { rerenderWith } = renderChart({ data: SAMPLE_DATA });
|
|
163
|
-
|
|
164
|
-
fireEvent.click(screen.getByRole('checkbox', { name: 'Users' }));
|
|
165
|
-
let props = chartSpy.mock.calls.at(-1)[0];
|
|
166
|
-
expect(props.series.map((series) => series.label)).toEqual(['Presence hours']);
|
|
167
|
-
|
|
168
|
-
rerenderWith({
|
|
169
|
-
data: {
|
|
170
|
-
xLabels: ['Mon', 'Tue', 'Wed', 'Thu'],
|
|
171
|
-
series: [
|
|
172
|
-
{ key: 'users', label: 'Users', data: [1, 2, 3, 4] },
|
|
173
|
-
{ key: 'presence', label: 'Presence hours', data: [4, 5, 6, 7] },
|
|
174
|
-
],
|
|
175
|
-
},
|
|
176
|
-
});
|
|
177
|
-
|
|
178
|
-
props = chartSpy.mock.calls.at(-1)[0];
|
|
179
|
-
expect(props.series.map((series) => series.label)).toEqual(['Presence hours']);
|
|
180
|
-
});
|
|
181
|
-
|
|
182
|
-
it('CHART-3: a series key appearing later defaults to visible while an earlier toggle-off survives', () => {
|
|
183
|
-
const { rerenderWith } = renderChart({
|
|
184
|
-
data: { xLabels: ['Mon'], series: [{ key: 'users', label: 'Users', data: [1] }] },
|
|
185
|
-
});
|
|
186
|
-
|
|
187
|
-
fireEvent.click(screen.getByRole('checkbox', { name: 'Users' }));
|
|
188
|
-
expect(screen.getByText('No data available.')).toBeTruthy();
|
|
189
|
-
|
|
190
|
-
rerenderWith({
|
|
191
|
-
data: {
|
|
192
|
-
xLabels: ['Mon'],
|
|
193
|
-
series: [
|
|
194
|
-
{ key: 'users', label: 'Users', data: [1] },
|
|
195
|
-
{ key: 'presence', label: 'Presence hours', data: [2] },
|
|
196
|
-
],
|
|
197
|
-
},
|
|
198
|
-
});
|
|
199
|
-
|
|
200
|
-
const props = chartSpy.mock.calls.at(-1)[0];
|
|
201
|
-
expect(props.series.map((series) => series.label)).toEqual(['Presence hours']);
|
|
202
|
-
});
|
|
203
|
-
|
|
204
|
-
// CHART-5: second y-axis (opt-in per series via `axis: 'secondary'`),
|
|
205
|
-
// auto-detected integer-only tick formatting per axis, and a deterministic
|
|
206
|
-
// x-axis tickLabelInterval. Learned from CHART-4's own history in this
|
|
207
|
-
// file: assertions here are on the captured functions/props passed to the
|
|
208
|
-
// mocked MuiBarChart, never on real jsdom-rendered tick visibility/position
|
|
209
|
-
// (proven vacuous for that in CHART-4 -- jsdom's layout/ResizeObserver
|
|
210
|
-
// handling doesn't reproduce real-browser collision behaviour).
|
|
211
|
-
const MIXED_DATA = {
|
|
212
|
-
xLabels: ['Mon', 'Tue', 'Wed'],
|
|
213
|
-
series: [
|
|
214
|
-
{ key: 'users', label: 'Users', data: [1, 2, 3] },
|
|
215
|
-
{ key: 'presence', label: 'Presence hours', data: [4.5, 5.2, 6.1] },
|
|
216
|
-
],
|
|
217
|
-
};
|
|
218
|
-
|
|
219
|
-
it('CHART-5: no custom (integer-blanking) yAxis formatter when the shared single axis is not all-integer (today\'s real case)', () => {
|
|
220
|
-
renderChart({ data: MIXED_DATA });
|
|
221
|
-
|
|
222
|
-
const props = chartSpy.mock.calls.at(-1)[0];
|
|
223
|
-
expect(props.yAxis).toHaveLength(1);
|
|
224
|
-
// THEME-9: BarChart now always supplies a default (locale-grouped, non-
|
|
225
|
-
// blanking) tick formatter, so this is no longer undefined -- but it
|
|
226
|
-
// must still be BarChart's generic default, not CHART-5's own
|
|
227
|
-
// integer-blanking one (which would wrongly blank the 4.5/5.2/6.1 ticks).
|
|
228
|
-
expect(typeof props.yAxis[0].valueFormatter).toBe('function');
|
|
229
|
-
expect(props.yAxis[0].valueFormatter(4.5, { location: 'tick' })).not.toBe('');
|
|
230
|
-
expect(props.yAxis[0].label).toBe('Count');
|
|
231
|
-
});
|
|
232
|
-
|
|
233
|
-
it('CHART-5: auto-applies an integer tick formatter to a single shared axis that is all-integer', () => {
|
|
234
|
-
renderChart(); // SAMPLE_DATA: both series are whole numbers
|
|
235
|
-
|
|
236
|
-
const props = chartSpy.mock.calls.at(-1)[0];
|
|
237
|
-
expect(props.yAxis).toHaveLength(1);
|
|
238
|
-
expect(typeof props.yAxis[0].valueFormatter).toBe('function');
|
|
239
|
-
});
|
|
240
|
-
|
|
241
|
-
it('CHART-5: dual axis activates with two labelled yAxis entries and correct yAxisId wiring', () => {
|
|
242
|
-
const data = {
|
|
243
|
-
xLabels: ['Mon', 'Tue', 'Wed'],
|
|
244
|
-
series: [
|
|
245
|
-
{ key: 'users', label: 'Users', data: [1, 2, 3] },
|
|
246
|
-
{ key: 'presence', label: 'Presence hours', data: [4.5, 5.2, 6.1], axis: 'secondary' },
|
|
247
|
-
],
|
|
248
|
-
};
|
|
249
|
-
renderChart({ data, secondaryYAxisLabel: 'Hours' });
|
|
250
|
-
|
|
251
|
-
const props = chartSpy.mock.calls.at(-1)[0];
|
|
252
|
-
expect(props.yAxis).toEqual([
|
|
253
|
-
expect.objectContaining({ id: 'primary', label: 'Count' }),
|
|
254
|
-
expect.objectContaining({ id: 'secondary', label: 'Hours' }),
|
|
255
|
-
]);
|
|
256
|
-
const usersSeries = props.series.find((series) => series.label === 'Users');
|
|
257
|
-
const presenceSeries = props.series.find((series) => series.label === 'Presence hours');
|
|
258
|
-
expect(usersSeries.yAxisId).toBeUndefined();
|
|
259
|
-
expect(presenceSeries.yAxisId).toBe('secondary');
|
|
260
|
-
});
|
|
261
|
-
|
|
262
|
-
// CHART-5 (found live via the ui-core-micha dev harness -- MUI defaultizes
|
|
263
|
-
// every yAxis entry after the first to `position: 'none'` unless told
|
|
264
|
-
// otherwise, per node_modules/@mui/x-charts/internals/.../defaultizeAxis.js
|
|
265
|
-
// (`defaultPosition = index === 0 ? 'left' : 'none'`), so the secondary
|
|
266
|
-
// axis never actually rendered in a real browser despite chartSpy's mocked
|
|
267
|
-
// props looking correct -- a class of bug no mocked-BarChart test in this
|
|
268
|
-
// file can catch by construction (the mock doesn't run MUI's own
|
|
269
|
-
// defaulting logic). Left here as the one explicit prop-shape assertion
|
|
270
|
-
// that would have caught it, plus the note above for future readers.
|
|
271
|
-
it('CHART-5: dual axis entries explicitly set position (left/right), not just id/label', () => {
|
|
272
|
-
const data = {
|
|
273
|
-
xLabels: ['Mon', 'Tue', 'Wed'],
|
|
274
|
-
series: [
|
|
275
|
-
{ key: 'users', label: 'Users', data: [1, 2, 3] },
|
|
276
|
-
{ key: 'presence', label: 'Presence hours', data: [4.5, 5.2, 6.1], axis: 'secondary' },
|
|
277
|
-
],
|
|
278
|
-
};
|
|
279
|
-
renderChart({ data, secondaryYAxisLabel: 'Hours' });
|
|
280
|
-
|
|
281
|
-
const props = chartSpy.mock.calls.at(-1)[0];
|
|
282
|
-
const primaryAxis = props.yAxis.find((axis) => axis.id === 'primary');
|
|
283
|
-
const secondaryAxis = props.yAxis.find((axis) => axis.id === 'secondary');
|
|
284
|
-
expect(primaryAxis.position).toBe('left');
|
|
285
|
-
expect(secondaryAxis.position).toBe('right');
|
|
286
|
-
});
|
|
287
|
-
|
|
288
|
-
it('CHART-5: dual axis applies the integer formatter only to the axis that is actually all-integer', () => {
|
|
289
|
-
const data = {
|
|
290
|
-
xLabels: ['Mon', 'Tue', 'Wed'],
|
|
291
|
-
series: [
|
|
292
|
-
{ key: 'users', label: 'Users', data: [1, 2, 3], axis: 'primary' },
|
|
293
|
-
{ key: 'presence', label: 'Presence hours', data: [4.5, 5.2, 6.1], axis: 'secondary' },
|
|
294
|
-
],
|
|
295
|
-
};
|
|
296
|
-
renderChart({ data, secondaryYAxisLabel: 'Hours' });
|
|
297
|
-
|
|
298
|
-
const props = chartSpy.mock.calls.at(-1)[0];
|
|
299
|
-
const primaryAxis = props.yAxis.find((axis) => axis.id === 'primary');
|
|
300
|
-
const secondaryAxis = props.yAxis.find((axis) => axis.id === 'secondary');
|
|
301
|
-
expect(primaryAxis.valueFormatter(2, { location: 'tick' })).toBe('2');
|
|
302
|
-
expect(primaryAxis.valueFormatter(2.5, { location: 'tick' })).toBe('');
|
|
303
|
-
// THEME-9: BarChart's own default formatter now covers the secondary
|
|
304
|
-
// axis too (a function, not undefined) -- distinguished from the
|
|
305
|
-
// integer-blanking one above by NOT blanking a non-integer tick.
|
|
306
|
-
expect(typeof secondaryAxis.valueFormatter).toBe('function');
|
|
307
|
-
expect(secondaryAxis.valueFormatter(4.5, { location: 'tick' })).not.toBe('');
|
|
308
|
-
});
|
|
309
|
-
|
|
310
|
-
it('CHART-5: throws when a series declares axis "secondary" without secondaryYAxisLabel', () => {
|
|
311
|
-
const data = {
|
|
312
|
-
xLabels: ['Mon'],
|
|
313
|
-
series: [{ key: 'presence', label: 'Presence hours', data: [4.5], axis: 'secondary' }],
|
|
314
|
-
};
|
|
315
|
-
expect(() => renderChart({ data })).toThrow(
|
|
316
|
-
'TimeSeriesChart requires secondaryYAxisLabel when a series uses axis: "secondary".',
|
|
317
|
-
);
|
|
318
|
-
});
|
|
319
|
-
|
|
320
|
-
it('CHART-5: the integer tick formatter blanks non-integer tick labels but not tooltip/legend values', () => {
|
|
321
|
-
renderChart(); // SAMPLE_DATA, single all-integer axis
|
|
322
|
-
|
|
323
|
-
const { valueFormatter } = chartSpy.mock.calls.at(-1)[0].yAxis[0];
|
|
324
|
-
expect(valueFormatter(2, { location: 'tick' })).toBe('2');
|
|
325
|
-
expect(valueFormatter(2.5, { location: 'tick' })).toBe('');
|
|
326
|
-
expect(valueFormatter(2.5, { location: 'tooltip' })).toBe('2.5');
|
|
327
|
-
});
|
|
328
|
-
|
|
329
|
-
it('CHART-5: toggling the non-integer series off switches the shared axis to integer-formatted', () => {
|
|
330
|
-
renderChart({ data: MIXED_DATA });
|
|
331
|
-
// THEME-9: BarChart's default formatter is present from the start now,
|
|
332
|
-
// so the CHART-5-specific signal is that a non-integer tick is NOT
|
|
333
|
-
// blanked yet -- the integer-blanking formatter isn't active.
|
|
334
|
-
expect(chartSpy.mock.calls.at(-1)[0].yAxis[0].valueFormatter(4.5, { location: 'tick' })).not.toBe('');
|
|
335
|
-
|
|
336
|
-
fireEvent.click(screen.getByRole('checkbox', { name: 'Presence hours' }));
|
|
337
|
-
|
|
338
|
-
const props = chartSpy.mock.calls.at(-1)[0];
|
|
339
|
-
expect(props.yAxis[0].valueFormatter(4.5, { location: 'tick' })).toBe('');
|
|
340
|
-
});
|
|
341
|
-
|
|
342
|
-
it('CHART-5: x-axis tickLabelInterval guarantees some labels always show, evenly spread', () => {
|
|
343
|
-
const manyLabels = Array.from({ length: 24 }, (_, i) => `Bucket ${i}`);
|
|
344
|
-
const data = { ...SAMPLE_DATA, xLabels: manyLabels, series: [SAMPLE_DATA.series[0]] };
|
|
345
|
-
renderChart({ data });
|
|
346
|
-
|
|
347
|
-
const { tickLabelInterval } = chartSpy.mock.calls.at(-1)[0].xAxis[0];
|
|
348
|
-
expect(typeof tickLabelInterval).toBe('function');
|
|
349
|
-
|
|
350
|
-
const visibleIndices = manyLabels.map((_, index) => index).filter((index) => tickLabelInterval(manyLabels[index], index));
|
|
351
|
-
expect(visibleIndices.length).toBeGreaterThanOrEqual(3);
|
|
352
|
-
expect(visibleIndices).toContain(0);
|
|
353
|
-
});
|
|
354
|
-
|
|
355
|
-
// CHART-5 (found by ui_reviewer): `index % step === 0` alone systematically
|
|
356
|
-
// drops the FINAL bucket unless it happens to land on a step boundary --
|
|
357
|
-
// e.g. 24 labels / step 3 covers 0..21, never 23. The most recent time
|
|
358
|
-
// bucket is usually the one that matters most on a time-series chart.
|
|
359
|
-
it.each([24, 12, 7, 1])('CHART-5: tickLabelInterval always includes the last bucket (labelCount=%i)', (labelCount) => {
|
|
360
|
-
const manyLabels = Array.from({ length: labelCount }, (_, i) => `Bucket ${i}`);
|
|
361
|
-
const data = { ...SAMPLE_DATA, xLabels: manyLabels, series: [SAMPLE_DATA.series[0]] };
|
|
362
|
-
renderChart({ data });
|
|
363
|
-
|
|
364
|
-
const { tickLabelInterval } = chartSpy.mock.calls.at(-1)[0].xAxis[0];
|
|
365
|
-
expect(tickLabelInterval(manyLabels.at(-1), labelCount - 1)).toBe(true);
|
|
366
|
-
});
|
|
367
|
-
});
|
|
@@ -1,192 +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, within } from '@testing-library/react';
|
|
5
|
-
|
|
6
|
-
const authApi = vi.hoisted(() => ({
|
|
7
|
-
fetchUsersList: vi.fn(),
|
|
8
|
-
updateUserRole: vi.fn(),
|
|
9
|
-
deleteUser: vi.fn(),
|
|
10
|
-
}));
|
|
11
|
-
|
|
12
|
-
vi.mock('../src/auth/authApi', () => authApi);
|
|
13
|
-
vi.mock('react-i18next', () => {
|
|
14
|
-
const KEYS = {
|
|
15
|
-
'UserList.TITLE': 'All Users',
|
|
16
|
-
'Common.SEARCH': 'Search',
|
|
17
|
-
'UserList.SEARCH_PLACEHOLDER': 'Search users...',
|
|
18
|
-
'Auth.EMAIL_LABEL': 'Email',
|
|
19
|
-
'Profile.NAME_LABEL': 'Name',
|
|
20
|
-
'UserList.ROLE': 'Role',
|
|
21
|
-
'UserList.ROLE_UPDATE_SUCCESS': 'Role updated.',
|
|
22
|
-
'Auth.USER_ROLE_UPDATE_FAILED': 'Role update failed.',
|
|
23
|
-
'UserList.NO_USERS': 'No users found.',
|
|
24
|
-
};
|
|
25
|
-
const t = (key, fallback) => KEYS[key] ?? (typeof fallback === 'string' ? fallback : key);
|
|
26
|
-
return {
|
|
27
|
-
useTranslation: () => ({
|
|
28
|
-
t,
|
|
29
|
-
// resolveErrorText (AUTH-10) reads i18n.exists/i18n.t off the object
|
|
30
|
-
// useTranslation() returns — this mock must carry both, not just `t`.
|
|
31
|
-
i18n: { exists: (key) => Object.hasOwn(KEYS, key), t },
|
|
32
|
-
}),
|
|
33
|
-
};
|
|
34
|
-
});
|
|
35
|
-
|
|
36
|
-
import { UserListComponent, formatDisplayedRowsLabel } from '../src/components/UserListComponent';
|
|
37
|
-
|
|
38
|
-
const currentUser = { id: 99, is_superuser: true, role: 'admin' };
|
|
39
|
-
const user = { id: 1, email: 'person@example.com', role: 'student' };
|
|
40
|
-
const ownUser = { id: 99, email: 'admin@example.com', role: 'admin' };
|
|
41
|
-
|
|
42
|
-
function renderDeleteList(props = {}) {
|
|
43
|
-
return render(
|
|
44
|
-
<UserListComponent
|
|
45
|
-
currentUser={currentUser}
|
|
46
|
-
showNewColumn={false}
|
|
47
|
-
showSuccessfulLoginColumn={false}
|
|
48
|
-
{...props}
|
|
49
|
-
/>,
|
|
50
|
-
);
|
|
51
|
-
}
|
|
52
|
-
|
|
53
|
-
function getRowByEmail(email) {
|
|
54
|
-
return screen.getByRole('cell', { name: email }).closest('tr');
|
|
55
|
-
}
|
|
56
|
-
|
|
57
|
-
function renderUserList() {
|
|
58
|
-
return render(
|
|
59
|
-
<UserListComponent
|
|
60
|
-
currentUser={currentUser}
|
|
61
|
-
showNewColumn={false}
|
|
62
|
-
showSuccessfulLoginColumn={false}
|
|
63
|
-
showDeleteAction={false}
|
|
64
|
-
/>,
|
|
65
|
-
);
|
|
66
|
-
}
|
|
67
|
-
|
|
68
|
-
async function chooseRole(role) {
|
|
69
|
-
fireEvent.mouseDown(screen.getAllByRole('combobox')[0]);
|
|
70
|
-
await waitFor(() => expect(screen.getByRole('listbox')).toBeTruthy());
|
|
71
|
-
fireEvent.click(screen.getByRole('option', { name: role }));
|
|
72
|
-
}
|
|
73
|
-
|
|
74
|
-
describe('UserListComponent role updates', () => {
|
|
75
|
-
beforeEach(() => {
|
|
76
|
-
vi.clearAllMocks();
|
|
77
|
-
authApi.fetchUsersList.mockResolvedValue([user]);
|
|
78
|
-
authApi.updateUserRole.mockResolvedValue({});
|
|
79
|
-
});
|
|
80
|
-
|
|
81
|
-
afterEach(() => {
|
|
82
|
-
cleanup();
|
|
83
|
-
vi.restoreAllMocks();
|
|
84
|
-
});
|
|
85
|
-
|
|
86
|
-
it('confirms a successful role update', async () => {
|
|
87
|
-
const alert = vi.spyOn(window, 'alert').mockImplementation(() => {});
|
|
88
|
-
renderUserList();
|
|
89
|
-
|
|
90
|
-
await waitFor(() => expect(screen.getAllByRole('combobox')[0]).toBeTruthy());
|
|
91
|
-
await chooseRole('teacher');
|
|
92
|
-
|
|
93
|
-
await waitFor(() => expect(authApi.updateUserRole).toHaveBeenCalledWith(1, 'teacher'));
|
|
94
|
-
expect(alert).toHaveBeenCalledWith('Role updated.');
|
|
95
|
-
});
|
|
96
|
-
|
|
97
|
-
it('keeps the failure feedback when a role update fails', async () => {
|
|
98
|
-
authApi.updateUserRole.mockRejectedValue({ code: 'Auth.USER_ROLE_UPDATE_FAILED' });
|
|
99
|
-
const alert = vi.spyOn(window, 'alert').mockImplementation(() => {});
|
|
100
|
-
renderUserList();
|
|
101
|
-
|
|
102
|
-
await waitFor(() => expect(screen.getAllByRole('combobox')[0]).toBeTruthy());
|
|
103
|
-
await chooseRole('teacher');
|
|
104
|
-
|
|
105
|
-
await waitFor(() => expect(alert).toHaveBeenCalledWith('Role update failed.'));
|
|
106
|
-
expect(authApi.fetchUsersList).toHaveBeenCalledTimes(1);
|
|
107
|
-
});
|
|
108
|
-
});
|
|
109
|
-
|
|
110
|
-
describe('UserListComponent delete actions', () => {
|
|
111
|
-
beforeEach(() => {
|
|
112
|
-
vi.clearAllMocks();
|
|
113
|
-
authApi.fetchUsersList.mockResolvedValue([ownUser, user]);
|
|
114
|
-
});
|
|
115
|
-
|
|
116
|
-
afterEach(() => {
|
|
117
|
-
cleanup();
|
|
118
|
-
vi.restoreAllMocks();
|
|
119
|
-
});
|
|
120
|
-
|
|
121
|
-
it('does not offer a superuser deletion of their own row', async () => {
|
|
122
|
-
renderDeleteList();
|
|
123
|
-
|
|
124
|
-
await waitFor(() => expect(screen.getAllByRole('button', { name: 'Delete' })).toHaveLength(1));
|
|
125
|
-
|
|
126
|
-
expect(within(getRowByEmail(ownUser.email)).queryByRole('button', { name: 'Delete' })).toBeNull();
|
|
127
|
-
expect(within(getRowByEmail(user.email)).getByRole('button', { name: 'Delete' }).disabled).toBe(false);
|
|
128
|
-
});
|
|
129
|
-
|
|
130
|
-
it('does not offer an admin deletion of their own row', async () => {
|
|
131
|
-
renderDeleteList({ currentUser: { id: 99, role: 'admin' } });
|
|
132
|
-
|
|
133
|
-
await waitFor(() => expect(screen.getAllByRole('button', { name: 'Delete' })).toHaveLength(1));
|
|
134
|
-
|
|
135
|
-
expect(within(getRowByEmail(ownUser.email)).queryByRole('button', { name: 'Delete' })).toBeNull();
|
|
136
|
-
expect(within(getRowByEmail(user.email)).getByRole('button', { name: 'Delete' }).disabled).toBe(false);
|
|
137
|
-
});
|
|
138
|
-
|
|
139
|
-
it('does not restore the own-row delete action when canDeleteUser returns true', async () => {
|
|
140
|
-
renderDeleteList({ canDeleteUser: () => true });
|
|
141
|
-
|
|
142
|
-
await waitFor(() => expect(screen.getAllByRole('button', { name: 'Delete' })).toHaveLength(1));
|
|
143
|
-
|
|
144
|
-
expect(within(getRowByEmail(ownUser.email)).queryByRole('button', { name: 'Delete' })).toBeNull();
|
|
145
|
-
expect(within(getRowByEmail(user.email)).getByRole('button', { name: 'Delete' }).disabled).toBe(false);
|
|
146
|
-
});
|
|
147
|
-
|
|
148
|
-
it('keeps unrelated rows and disabled delete actions when currentUser is not loaded', async () => {
|
|
149
|
-
authApi.fetchUsersList.mockResolvedValue([user]);
|
|
150
|
-
renderDeleteList({ currentUser: null });
|
|
151
|
-
|
|
152
|
-
await waitFor(() => expect(screen.getAllByRole('button', { name: 'Delete' })).toHaveLength(1));
|
|
153
|
-
|
|
154
|
-
expect(screen.getByRole('button', { name: 'Delete' }).disabled).toBe(true);
|
|
155
|
-
});
|
|
156
|
-
|
|
157
|
-
it('matches the own row even when the row id and current-user id have different types', async () => {
|
|
158
|
-
// The backend row's id can come back as a string while currentUser.id is a
|
|
159
|
-
// number (or vice versa) -- isOwnRow must compare by value, not by strict
|
|
160
|
-
// type, or this exact mismatch would silently show the button again.
|
|
161
|
-
authApi.fetchUsersList.mockResolvedValue([{ ...ownUser, id: String(ownUser.id) }, user]);
|
|
162
|
-
renderDeleteList();
|
|
163
|
-
|
|
164
|
-
await waitFor(() => expect(screen.getAllByRole('button', { name: 'Delete' })).toHaveLength(1));
|
|
165
|
-
|
|
166
|
-
expect(within(getRowByEmail(ownUser.email)).queryByRole('button', { name: 'Delete' })).toBeNull();
|
|
167
|
-
expect(within(getRowByEmail(user.email)).getByRole('button', { name: 'Delete' }).disabled).toBe(false);
|
|
168
|
-
});
|
|
169
|
-
});
|
|
170
|
-
|
|
171
|
-
describe('formatDisplayedRowsLabel (UCM-I18N-5)', () => {
|
|
172
|
-
// A real i18next instance's t() supports {{var}} interpolation; this fake mirrors just that,
|
|
173
|
-
// so these assertions pin the KEY and VARS formatDisplayedRowsLabel passes through -- the
|
|
174
|
-
// count === -1 ("more than") branch can never be reached by rendering UserListComponent itself
|
|
175
|
-
// (its own TablePagination always receives a real, non-negative count), so this is the only way
|
|
176
|
-
// to exercise it at all (UCM-I18N-5 review, tests lens).
|
|
177
|
-
function fakeT(key, fallback, vars = {}) {
|
|
178
|
-
const template = { [key]: fallback }[key] ?? fallback;
|
|
179
|
-
return template.replace(/\{\{(\w+)\}\}/g, (_, name) => String(vars[name] ?? `{{${name}}}`));
|
|
180
|
-
}
|
|
181
|
-
|
|
182
|
-
it('uses the exact-count key when count is a real number', () => {
|
|
183
|
-
const label = formatDisplayedRowsLabel(fakeT)({ from: 1, to: 10, count: 42 });
|
|
184
|
-
expect(label).toBe('1–10 of 42');
|
|
185
|
-
});
|
|
186
|
-
|
|
187
|
-
it('uses the "more than" key, without a literal count, when count is -1', () => {
|
|
188
|
-
const label = formatDisplayedRowsLabel(fakeT)({ from: 1, to: 10, count: -1 });
|
|
189
|
-
expect(label).toBe('1–10 of more than 10');
|
|
190
|
-
expect(label).not.toContain('-1');
|
|
191
|
-
});
|
|
192
|
-
});
|