@ploykit/ui 0.6.0 → 0.6.2
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/dist/AppProviders.js +2 -2
- package/dist/components/ConfirmDialog.js +1 -1
- package/dist/components/CronInput.js +3 -3
- package/dist/components/DataTable.js +4 -4
- package/dist/components/FormField.js +1 -1
- package/dist/components/ImpersonationBanner.js +1 -1
- package/dist/components/NotificationBell.js +1 -1
- package/dist/components/OnboardingChecklist.js +3 -3
- package/dist/components/Page.js +2 -2
- package/dist/components/ReauthDialog.js +4 -4
- package/dist/components/SecretModal.js +2 -2
- package/dist/components/SettingsCard.js +2 -2
- package/dist/components/SiteBanner.js +1 -1
- package/dist/components/SiteBannerLayer.js +1 -1
- package/dist/components/StatusBadge.js +1 -1
- package/dist/components/UserMenu.js +3 -3
- package/dist/components/WorkspaceSwitcher.js +7 -7
- package/dist/components/ui/alert-dialog.js +2 -2
- package/dist/components/ui/avatar.js +1 -1
- package/dist/components/ui/badge.js +1 -1
- package/dist/components/ui/breadcrumb.js +1 -1
- package/dist/components/ui/button.js +1 -1
- package/dist/components/ui/card.js +1 -1
- package/dist/components/ui/checkbox.js +1 -1
- package/dist/components/ui/dialog.js +2 -2
- package/dist/components/ui/dropdown-menu.js +1 -1
- package/dist/components/ui/empty.js +1 -1
- package/dist/components/ui/field.js +3 -3
- package/dist/components/ui/input.js +1 -1
- package/dist/components/ui/label.js +1 -1
- package/dist/components/ui/popover.js +1 -1
- package/dist/components/ui/progress.js +1 -1
- package/dist/components/ui/select.js +1 -1
- package/dist/components/ui/separator.js +1 -1
- package/dist/components/ui/sheet.js +2 -2
- package/dist/components/ui/sidebar.js +8 -8
- package/dist/components/ui/skeleton.js +1 -1
- package/dist/components/ui/switch.js +1 -1
- package/dist/components/ui/tabs.js +1 -1
- package/dist/components/ui/textarea.js +1 -1
- package/dist/components/ui/tooltip.js +1 -1
- package/dist/index.js +78 -78
- package/dist/layouts/AppShell.js +4 -4
- package/dist/layouts/SettingsShell.js +4 -4
- package/dist/pages/LoginPage.js +5 -5
- package/dist/pages/account/NotificationPreferencesPage.js +3 -3
- package/dist/pages/account/ProfileSettingsPage.js +9 -9
- package/dist/pages/account/SecuritySettingsPage.js +13 -13
- package/dist/pages/account/TokensPage.js +12 -12
- package/dist/pages/admin/AdminSettingsPage.js +11 -11
- package/dist/pages/admin/AdminShell.js +3 -3
- package/dist/pages/admin/AuditPage.js +8 -8
- package/dist/pages/admin/OrdersPage.js +12 -12
- package/dist/pages/admin/OverviewPage.js +13 -13
- package/dist/pages/admin/SSOPage.js +6 -6
- package/dist/pages/admin/UserDetailPage.js +13 -13
- package/dist/pages/admin/UsersPage.js +13 -13
- package/dist/pages/admin/WebhookDeliveriesPage.js +9 -9
- package/dist/pages/admin/WorkspaceDetailPage.js +14 -14
- package/dist/pages/admin/WorkspacesPage.js +9 -9
- package/dist/pages/admin/shared.js +1 -1
- package/dist/pages/auth/ForgotPasswordPage.js +4 -4
- package/dist/pages/auth/InviteAcceptPage.js +6 -6
- package/dist/pages/auth/RegisterPage.js +7 -7
- package/dist/pages/auth/ResetPasswordPage.js +5 -5
- package/dist/pages/auth/VerifyEmailPage.js +3 -3
- package/dist/pages/workspace/BillingPage.js +11 -11
- package/dist/pages/workspace/BillingSuccessPage.js +2 -2
- package/dist/pages/workspace/MembersPage.js +15 -15
- package/dist/pages/workspace/RolePermissionsPage.js +9 -9
- package/dist/pages/workspace/SchedulesPage.js +12 -12
- package/dist/pages/workspace/UsagePage.js +6 -6
- package/dist/pages/workspace/WebhooksPage.js +16 -16
- package/dist/pages/workspace/WorkspaceAuditPage.js +7 -7
- package/dist/pages/workspace/WorkspaceGeneralPage.js +9 -9
- package/package.json +6 -5
- package/src/AppProviders.tsx +29 -0
- package/src/components/ConfirmDialog.tsx +77 -0
- package/src/components/CronInput.tsx +195 -0
- package/src/components/DataTable.tsx +152 -0
- package/src/components/ErrorBoundary.tsx +46 -0
- package/src/components/FormField.tsx +56 -0
- package/src/components/ImpersonationBanner.tsx +23 -0
- package/src/components/NotificationBell.tsx +135 -0
- package/src/components/OnboardingChecklist.tsx +114 -0
- package/src/components/Page.tsx +67 -0
- package/src/components/ReauthDialog.tsx +94 -0
- package/src/components/SecretModal.tsx +147 -0
- package/src/components/SettingsCard.tsx +39 -0
- package/src/components/SiteBanner.tsx +32 -0
- package/src/components/SiteBannerLayer.tsx +29 -0
- package/src/components/StatusBadge.tsx +12 -0
- package/src/components/UserMenu.tsx +103 -0
- package/src/components/WorkspaceSwitcher.tsx +159 -0
- package/src/components/__tests__/AppProviders.test.tsx +111 -0
- package/src/components/__tests__/CronInput.test.tsx +180 -0
- package/src/components/__tests__/DataTable.test.tsx +208 -0
- package/src/components/__tests__/ErrorBoundary.test.tsx +61 -0
- package/src/components/__tests__/ImpersonationBanner.test.tsx +59 -0
- package/src/components/__tests__/NotificationBell.test.tsx +207 -0
- package/src/components/__tests__/OnboardingChecklist.test.tsx +97 -0
- package/src/components/__tests__/SecretModal.test.tsx +112 -0
- package/src/components/__tests__/SiteBannerLayer.test.tsx +44 -0
- package/src/components/__tests__/UserMenu.test.tsx +98 -0
- package/src/components/__tests__/WorkspaceSwitcher.test.tsx +162 -0
- package/src/components/__tests__/form.test.tsx +133 -0
- package/src/components/__tests__/semantic-tokens.test.ts +41 -0
- package/src/components/__tests__/smoke.test.tsx +11 -0
- package/src/components/__tests__/toast.test.tsx +27 -0
- package/src/components/toast.tsx +23 -0
- package/src/components/ui/__tests__/alert-dialog.test.tsx +66 -0
- package/src/components/ui/__tests__/avatar.test.tsx +30 -0
- package/src/components/ui/__tests__/checkbox.test.tsx +18 -0
- package/src/components/ui/__tests__/dropdown-menu.test.tsx +33 -0
- package/src/components/ui/__tests__/field.test.tsx +43 -0
- package/src/components/ui/__tests__/overlay-size.test.tsx +84 -0
- package/src/components/ui/__tests__/popover.test.tsx +32 -0
- package/src/components/ui/__tests__/progress.test.tsx +24 -0
- package/src/components/ui/__tests__/select-callback.test.tsx +72 -0
- package/src/components/ui/__tests__/select.test.tsx +48 -0
- package/src/components/ui/__tests__/sidebar.test.tsx +121 -0
- package/src/components/ui/__tests__/stock-mirror.test.ts +39 -0
- package/src/components/ui/__tests__/subpath.test.tsx +38 -0
- package/src/components/ui/__tests__/switch.test.tsx +24 -0
- package/src/components/ui/__tests__/tabs.test.tsx +24 -0
- package/src/components/ui/__tests__/textarea.test.tsx +41 -0
- package/src/components/ui/alert-dialog.tsx +187 -0
- package/src/components/ui/avatar.tsx +108 -0
- package/src/components/ui/badge.tsx +51 -0
- package/src/components/ui/breadcrumb.tsx +124 -0
- package/src/components/ui/button.tsx +57 -0
- package/src/components/ui/card.tsx +102 -0
- package/src/components/ui/checkbox.tsx +28 -0
- package/src/components/ui/dialog.tsx +166 -0
- package/src/components/ui/dropdown-menu.tsx +265 -0
- package/src/components/ui/empty.tsx +103 -0
- package/src/components/ui/field.tsx +238 -0
- package/src/components/ui/input.tsx +19 -0
- package/src/components/ui/label.tsx +17 -0
- package/src/components/ui/popover.tsx +89 -0
- package/src/components/ui/progress.tsx +82 -0
- package/src/components/ui/select.tsx +235 -0
- package/src/components/ui/separator.tsx +24 -0
- package/src/components/ui/sheet.tsx +146 -0
- package/src/components/ui/sidebar.tsx +723 -0
- package/src/components/ui/skeleton.tsx +13 -0
- package/src/components/ui/switch.tsx +29 -0
- package/src/components/ui/tabs.tsx +79 -0
- package/src/components/ui/textarea.tsx +26 -0
- package/src/components/ui/tooltip.tsx +63 -0
- package/src/dev.css +1 -0
- package/src/hooks/use-mobile.ts +19 -0
- package/src/index.ts +150 -0
- package/src/layouts/AppShell.tsx +163 -0
- package/src/layouts/AuthShell.tsx +24 -0
- package/src/layouts/SettingsShell.tsx +129 -0
- package/src/layouts/__tests__/AppShell.test.tsx +163 -0
- package/src/layouts/__tests__/SettingsShell.test.tsx +146 -0
- package/src/lib/__tests__/api-error.test.ts +163 -0
- package/src/lib/__tests__/utils.test.ts +21 -0
- package/src/lib/api-error.ts +98 -0
- package/src/lib/utils.ts +109 -0
- package/src/pages/LandingPage.tsx +88 -0
- package/src/pages/LoginPage.tsx +291 -0
- package/src/pages/__tests__/LandingPage.test.tsx +58 -0
- package/src/pages/__tests__/LoginPage.test.tsx +229 -0
- package/src/pages/__tests__/RegisterPage.test.tsx +138 -0
- package/src/pages/__tests__/ssr-smoke.test.tsx +99 -0
- package/src/pages/account/NotificationPreferencesPage.tsx +138 -0
- package/src/pages/account/ProfileSettingsPage.tsx +189 -0
- package/src/pages/account/SecuritySettingsPage.tsx +214 -0
- package/src/pages/account/TokensPage.tsx +211 -0
- package/src/pages/account/__tests__/NotificationPreferencesPage.test.tsx +150 -0
- package/src/pages/account/__tests__/ProfileSettingsPage.test.tsx +173 -0
- package/src/pages/account/__tests__/SecuritySettingsPage.test.tsx +212 -0
- package/src/pages/account/__tests__/TokensPage.test.tsx +180 -0
- package/src/pages/admin/AdminSettingsPage.tsx +564 -0
- package/src/pages/admin/AdminShell.tsx +199 -0
- package/src/pages/admin/AuditPage.tsx +338 -0
- package/src/pages/admin/OrdersPage.tsx +642 -0
- package/src/pages/admin/OverviewPage.tsx +559 -0
- package/src/pages/admin/SSOPage.tsx +166 -0
- package/src/pages/admin/UserDetailPage.tsx +641 -0
- package/src/pages/admin/UsersPage.tsx +462 -0
- package/src/pages/admin/WebhookDeliveriesPage.tsx +318 -0
- package/src/pages/admin/WorkspaceDetailPage.tsx +551 -0
- package/src/pages/admin/WorkspacesPage.tsx +299 -0
- package/src/pages/admin/__tests__/AdminSettingsPage.test.tsx +260 -0
- package/src/pages/admin/__tests__/OrdersPageMarkPaid.test.tsx +207 -0
- package/src/pages/admin/__tests__/OverviewPageActivity.test.tsx +213 -0
- package/src/pages/admin/__tests__/SSOPage.test.tsx +128 -0
- package/src/pages/admin/__tests__/UsersPageActions.test.tsx +188 -0
- package/src/pages/admin/__tests__/WorkspaceDetailPageTransfer.test.tsx +170 -0
- package/src/pages/admin/__tests__/WorkspacesPagePlans.test.tsx +138 -0
- package/src/pages/admin/shared.ts +42 -0
- package/src/pages/auth/ForgotPasswordPage.tsx +83 -0
- package/src/pages/auth/InviteAcceptPage.tsx +105 -0
- package/src/pages/auth/RegisterPage.tsx +204 -0
- package/src/pages/auth/ResetPasswordPage.tsx +150 -0
- package/src/pages/auth/VerifyEmailPage.tsx +76 -0
- package/src/pages/auth/__tests__/ForgotPasswordPage.test.tsx +67 -0
- package/src/pages/auth/__tests__/InviteAcceptPage.test.tsx +86 -0
- package/src/pages/auth/__tests__/ResetPasswordPage.test.tsx +115 -0
- package/src/pages/auth/__tests__/VerifyEmailPage.test.tsx +74 -0
- package/src/pages/workspace/BillingPage.tsx +361 -0
- package/src/pages/workspace/BillingSuccessPage.tsx +115 -0
- package/src/pages/workspace/MembersPage.tsx +568 -0
- package/src/pages/workspace/RolePermissionsPage.tsx +202 -0
- package/src/pages/workspace/SchedulesPage.tsx +387 -0
- package/src/pages/workspace/UsagePage.tsx +207 -0
- package/src/pages/workspace/WebhooksPage.tsx +506 -0
- package/src/pages/workspace/WorkspaceAuditPage.tsx +229 -0
- package/src/pages/workspace/WorkspaceGeneralPage.tsx +184 -0
- package/src/pages/workspace/__tests__/BillingPage.test.tsx +302 -0
- package/src/pages/workspace/__tests__/BillingSuccessPage.test.tsx +134 -0
- package/src/pages/workspace/__tests__/MembersPage.test.tsx +347 -0
- package/src/pages/workspace/__tests__/RolePermissionsPage.test.tsx +138 -0
- package/src/pages/workspace/__tests__/SchedulesPage.test.tsx +239 -0
- package/src/pages/workspace/__tests__/UsagePage.test.tsx +223 -0
- package/src/pages/workspace/__tests__/WebhooksPage.test.tsx +309 -0
- package/src/pages/workspace/__tests__/WorkspaceAuditPage.test.tsx +112 -0
- package/src/pages/workspace/__tests__/WorkspaceGeneralPage.test.tsx +164 -0
|
@@ -0,0 +1,150 @@
|
|
|
1
|
+
import '@testing-library/jest-dom/vitest'
|
|
2
|
+
import { fireEvent, render, screen, waitFor } from '@testing-library/react'
|
|
3
|
+
import { describe, it, expect, vi, beforeEach } from 'vitest'
|
|
4
|
+
import { NotificationPreferencesPage } from '../NotificationPreferencesPage'
|
|
5
|
+
|
|
6
|
+
const mocks = vi.hoisted(() => ({
|
|
7
|
+
prefs: [] as Array<Record<string, unknown>>,
|
|
8
|
+
loading: false,
|
|
9
|
+
error: null as Error | null,
|
|
10
|
+
setPref: vi.fn(),
|
|
11
|
+
}))
|
|
12
|
+
vi.mock('../../../../../hooks/src/hooks/useNotificationPrefs', () => ({
|
|
13
|
+
useNotificationPrefs: () => ({ prefs: mocks.prefs, loading: mocks.loading, error: mocks.error, refetch: vi.fn() }),
|
|
14
|
+
useSetNotificationPref: () => ({ setPref: mocks.setPref, loading: false, error: null }),
|
|
15
|
+
}))
|
|
16
|
+
|
|
17
|
+
function pref(over: Record<string, unknown> = {}) {
|
|
18
|
+
return {
|
|
19
|
+
notification_type: 'workspace.invited', email_enabled: true, in_app_enabled: true,
|
|
20
|
+
updated_at: '2026-10-01T00:00:00Z', ...over,
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
beforeEach(() => {
|
|
25
|
+
mocks.setPref.mockReset().mockResolvedValue(pref())
|
|
26
|
+
mocks.loading = false
|
|
27
|
+
mocks.error = null
|
|
28
|
+
mocks.prefs = []
|
|
29
|
+
|
|
30
|
+
document.title = ''
|
|
31
|
+
})
|
|
32
|
+
|
|
33
|
+
describe('NotificationPreferencesPage', () => {
|
|
34
|
+
it('loading 时渲染加载态', () => {
|
|
35
|
+
mocks.loading = true
|
|
36
|
+
render(<NotificationPreferencesPage />)
|
|
37
|
+
expect(screen.getByText('加载中…')).toBeInTheDocument()
|
|
38
|
+
})
|
|
39
|
+
|
|
40
|
+
it('error 时渲染错误重试', () => {
|
|
41
|
+
mocks.error = new Error('boom')
|
|
42
|
+
render(<NotificationPreferencesPage />)
|
|
43
|
+
expect(screen.getByText('boom')).toBeInTheDocument()
|
|
44
|
+
expect(screen.getByRole('button', { name: '重试' })).toBeInTheDocument()
|
|
45
|
+
})
|
|
46
|
+
|
|
47
|
+
it('无 types prop 时以 API 行生成清单(值取行内字段)', () => {
|
|
48
|
+
mocks.prefs = [pref({ notification_type: 'workspace.invited', email_enabled: false })]
|
|
49
|
+
render(<NotificationPreferencesPage />)
|
|
50
|
+
expect(screen.getByText('workspace.invited')).toBeInTheDocument()
|
|
51
|
+
expect(screen.getByRole('switch', { name: '邮件(workspace.invited)' })).toHaveAttribute('aria-checked', 'false')
|
|
52
|
+
expect(screen.getByRole('switch', { name: '站内(workspace.invited)' })).toHaveAttribute('aria-checked', 'true')
|
|
53
|
+
})
|
|
54
|
+
|
|
55
|
+
it('types prop 清单 × 缺行 = 双渠道默认开启', () => {
|
|
56
|
+
mocks.prefs = [pref({ notification_type: 'other.type' })]
|
|
57
|
+
render(
|
|
58
|
+
<NotificationPreferencesPage
|
|
59
|
+
types={[
|
|
60
|
+
{ type: 'workspace.invited', label: '工作区邀请', description: '被邀请加入工作区时' },
|
|
61
|
+
]}
|
|
62
|
+
/>,
|
|
63
|
+
)
|
|
64
|
+
expect(screen.getByText('工作区邀请')).toBeInTheDocument()
|
|
65
|
+
expect(screen.getByText('被邀请加入工作区时')).toBeInTheDocument()
|
|
66
|
+
expect(screen.getByRole('switch', { name: '站内(工作区邀请)' })).toHaveAttribute('aria-checked', 'true')
|
|
67
|
+
expect(screen.getByRole('switch', { name: '邮件(工作区邀请)' })).toHaveAttribute('aria-checked', 'true')
|
|
68
|
+
})
|
|
69
|
+
|
|
70
|
+
it('切换站内开关 → setPref(type, {in_app_enabled:false})', async () => {
|
|
71
|
+
mocks.prefs = [pref()]
|
|
72
|
+
render(<NotificationPreferencesPage />)
|
|
73
|
+
fireEvent.click(screen.getByRole('switch', { name: '站内(workspace.invited)' }))
|
|
74
|
+
await waitFor(() =>
|
|
75
|
+
expect(mocks.setPref).toHaveBeenCalledWith('workspace.invited', { in_app_enabled: false }),
|
|
76
|
+
)
|
|
77
|
+
})
|
|
78
|
+
|
|
79
|
+
it('空清单渲染空态', () => {
|
|
80
|
+
render(<NotificationPreferencesPage types={[]} />)
|
|
81
|
+
expect(screen.getByText('暂无可配置的通知类型')).toBeInTheDocument()
|
|
82
|
+
})
|
|
83
|
+
|
|
84
|
+
|
|
85
|
+
it('emailChannelNote 传入时渲染邮件渠道说明行', () => {
|
|
86
|
+
mocks.prefs = [pref()]
|
|
87
|
+
render(
|
|
88
|
+
<NotificationPreferencesPage emailChannelNote="当前环境未接邮件发送(偏好仍会保存)" />,
|
|
89
|
+
)
|
|
90
|
+
expect(
|
|
91
|
+
screen.getByText('邮件渠道:当前环境未接邮件发送(偏好仍会保存)'),
|
|
92
|
+
).toBeInTheDocument()
|
|
93
|
+
})
|
|
94
|
+
|
|
95
|
+
it('emailChannelNote 缺省不渲染说明行(默认假定渠道可用)', () => {
|
|
96
|
+
mocks.prefs = [pref()]
|
|
97
|
+
render(<NotificationPreferencesPage />)
|
|
98
|
+
expect(screen.queryByText(/^邮件渠道:/)).not.toBeInTheDocument()
|
|
99
|
+
})
|
|
100
|
+
|
|
101
|
+
|
|
102
|
+
|
|
103
|
+
|
|
104
|
+
|
|
105
|
+
it('渠道文字是 label:htmlFor 落到内部 checkbox,开关名经 aria-labelledby 关联', () => {
|
|
106
|
+
mocks.prefs = [pref()]
|
|
107
|
+
render(<NotificationPreferencesPage />)
|
|
108
|
+
const inAppSwitch = screen.getByRole('switch', { name: '站内(workspace.invited)' })
|
|
109
|
+
const emailSwitch = screen.getByRole('switch', { name: '邮件(workspace.invited)' })
|
|
110
|
+
const inAppLabel = screen.getByText(/^站内/, { selector: 'label' })
|
|
111
|
+
const emailLabel = screen.getByText(/^邮件/, { selector: 'label' })
|
|
112
|
+
|
|
113
|
+
expect(inAppLabel).toHaveAttribute('for')
|
|
114
|
+
expect(emailLabel).toHaveAttribute('for')
|
|
115
|
+
|
|
116
|
+
const inAppTarget = document.getElementById(inAppLabel.getAttribute('for')!)
|
|
117
|
+
const emailTarget = document.getElementById(emailLabel.getAttribute('for')!)
|
|
118
|
+
expect(inAppTarget).toBeTruthy()
|
|
119
|
+
expect(emailTarget).toBeTruthy()
|
|
120
|
+
expect(inAppTarget).toHaveAttribute('type', 'checkbox')
|
|
121
|
+
expect(emailTarget).toHaveAttribute('type', 'checkbox')
|
|
122
|
+
|
|
123
|
+
expect(inAppSwitch).toHaveAttribute('aria-labelledby', inAppLabel.id)
|
|
124
|
+
expect(emailSwitch).toHaveAttribute('aria-labelledby', emailLabel.id)
|
|
125
|
+
})
|
|
126
|
+
|
|
127
|
+
it('点击"邮件"文字 → 触发对应开关切换(label 关联可达)', async () => {
|
|
128
|
+
mocks.prefs = [pref()]
|
|
129
|
+
render(<NotificationPreferencesPage />)
|
|
130
|
+
fireEvent.click(screen.getByText(/^邮件/, { selector: 'label' }))
|
|
131
|
+
await waitFor(() =>
|
|
132
|
+
expect(mocks.setPref).toHaveBeenCalledWith('workspace.invited', { email_enabled: false }),
|
|
133
|
+
)
|
|
134
|
+
})
|
|
135
|
+
|
|
136
|
+
|
|
137
|
+
it('siteName 传入时挂"通知偏好 · <产品名>"式页题', () => {
|
|
138
|
+
mocks.prefs = [pref()]
|
|
139
|
+
render(<NotificationPreferencesPage siteName="MyProduct" />)
|
|
140
|
+
expect(document.title).toBe('通知偏好 · MyProduct')
|
|
141
|
+
})
|
|
142
|
+
|
|
143
|
+
it('siteName 缺省只挂页题;自定义 title prop 同样生效', () => {
|
|
144
|
+
mocks.prefs = [pref()]
|
|
145
|
+
const { rerender } = render(<NotificationPreferencesPage />)
|
|
146
|
+
expect(document.title).toBe('通知偏好')
|
|
147
|
+
rerender(<NotificationPreferencesPage title="通知设置" siteName="MyProduct" />)
|
|
148
|
+
expect(document.title).toBe('通知设置 · MyProduct')
|
|
149
|
+
})
|
|
150
|
+
})
|
|
@@ -0,0 +1,173 @@
|
|
|
1
|
+
import '@testing-library/jest-dom/vitest'
|
|
2
|
+
import { fireEvent, render, screen, waitFor } from '@testing-library/react'
|
|
3
|
+
import { describe, it, expect, vi, beforeEach } from 'vitest'
|
|
4
|
+
import { ApiError } from '@ploykit/client'
|
|
5
|
+
import { ProfileSettingsPage } from '../ProfileSettingsPage'
|
|
6
|
+
import type { PKUser } from '../../../provider/PloykitProvider'
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
const mocks = vi.hoisted(() => ({
|
|
10
|
+
patch: vi.fn(),
|
|
11
|
+
post: vi.fn(),
|
|
12
|
+
del: vi.fn(),
|
|
13
|
+
refresh: vi.fn(),
|
|
14
|
+
logout: vi.fn(),
|
|
15
|
+
toastSuccess: vi.fn(),
|
|
16
|
+
toastError: vi.fn(),
|
|
17
|
+
user: null as PKUser | null,
|
|
18
|
+
loading: false,
|
|
19
|
+
}))
|
|
20
|
+
vi.mock('../../../../../hooks/src/hooks/useApi', () => ({
|
|
21
|
+
useApi: () => ({ patch: mocks.patch, post: mocks.post, delete: mocks.del, get: vi.fn(), put: vi.fn() }),
|
|
22
|
+
}))
|
|
23
|
+
vi.mock('../../../../../hooks/src/hooks/useAuth', () => ({
|
|
24
|
+
useAuth: () => ({ user: mocks.user, loading: mocks.loading, refresh: mocks.refresh, logout: mocks.logout, workspaces: [] }),
|
|
25
|
+
}))
|
|
26
|
+
vi.mock('../../../components/toast', () => ({
|
|
27
|
+
toast: { success: mocks.toastSuccess, error: mocks.toastError, info: vi.fn() },
|
|
28
|
+
}))
|
|
29
|
+
|
|
30
|
+
function fakeUser(over: Partial<PKUser> = {}): PKUser {
|
|
31
|
+
return {
|
|
32
|
+
id: 'u1', email: 'user@example.com', display_name: '小明', avatar_url: '',
|
|
33
|
+
status: 'active', is_platform_admin: false, email_verified: false, created_at: '2026-01-01T00:00:00Z',
|
|
34
|
+
...over,
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
beforeEach(() => {
|
|
39
|
+
mocks.patch.mockReset().mockResolvedValue(fakeUser())
|
|
40
|
+
mocks.post.mockReset().mockResolvedValue(undefined)
|
|
41
|
+
mocks.del.mockReset().mockResolvedValue(undefined)
|
|
42
|
+
mocks.refresh.mockReset().mockResolvedValue(undefined)
|
|
43
|
+
mocks.logout.mockReset().mockResolvedValue(undefined)
|
|
44
|
+
mocks.toastSuccess.mockReset()
|
|
45
|
+
mocks.toastError.mockReset()
|
|
46
|
+
mocks.loading = false
|
|
47
|
+
mocks.user = fakeUser()
|
|
48
|
+
})
|
|
49
|
+
|
|
50
|
+
describe('ProfileSettingsPage', () => {
|
|
51
|
+
it('loading 时渲染加载骨架', () => {
|
|
52
|
+
mocks.loading = true
|
|
53
|
+
render(<ProfileSettingsPage />)
|
|
54
|
+
expect(screen.getByText('加载账号信息…')).toBeInTheDocument()
|
|
55
|
+
})
|
|
56
|
+
|
|
57
|
+
it('渲染资料表单与邮箱行;未验证邮箱展示徽标 + 重发按钮', () => {
|
|
58
|
+
render(<ProfileSettingsPage />)
|
|
59
|
+
expect((screen.getByLabelText(/昵称/) as HTMLInputElement).value).toBe('小明')
|
|
60
|
+
expect(screen.getByTestId('profile-email')).toHaveTextContent('user@example.com')
|
|
61
|
+
expect(screen.getByText('未验证')).toBeInTheDocument()
|
|
62
|
+
expect(screen.getByRole('button', { name: '重新发送验证邮件' })).toBeInTheDocument()
|
|
63
|
+
})
|
|
64
|
+
|
|
65
|
+
it('已验证邮箱不渲染重发按钮', () => {
|
|
66
|
+
mocks.user = fakeUser({ email_verified: true })
|
|
67
|
+
render(<ProfileSettingsPage />)
|
|
68
|
+
expect(screen.getByText('已验证')).toBeInTheDocument()
|
|
69
|
+
expect(screen.queryByRole('button', { name: '重新发送验证邮件' })).toBeNull()
|
|
70
|
+
})
|
|
71
|
+
|
|
72
|
+
it('保存资料 → PATCH /auth/me 携带 display_name/avatar_url', async () => {
|
|
73
|
+
render(<ProfileSettingsPage />)
|
|
74
|
+
fireEvent.change(screen.getByLabelText(/昵称/), { target: { value: '大明' } })
|
|
75
|
+
fireEvent.click(screen.getByRole('button', { name: '保存' }))
|
|
76
|
+
|
|
77
|
+
await waitFor(() => expect(mocks.patch).toHaveBeenCalledTimes(1))
|
|
78
|
+
expect(mocks.patch).toHaveBeenCalledWith('/auth/me', {
|
|
79
|
+
display_name: '大明', avatar_url: '',
|
|
80
|
+
})
|
|
81
|
+
await waitFor(() => expect(mocks.refresh).toHaveBeenCalledTimes(1))
|
|
82
|
+
})
|
|
83
|
+
|
|
84
|
+
it('点击重发验证邮件 → POST /auth/send-verification', async () => {
|
|
85
|
+
render(<ProfileSettingsPage />)
|
|
86
|
+
fireEvent.click(screen.getByRole('button', { name: '重新发送验证邮件' }))
|
|
87
|
+
await waitFor(() => expect(mocks.post).toHaveBeenCalledTimes(1))
|
|
88
|
+
expect(mocks.post).toHaveBeenCalledWith('/auth/send-verification')
|
|
89
|
+
})
|
|
90
|
+
|
|
91
|
+
it('删除账号:输入邮箱匹配后按钮可用,Impact 确认后 DELETE /auth/me', async () => {
|
|
92
|
+
render(<ProfileSettingsPage />)
|
|
93
|
+
const deleteBtn = screen.getByRole('button', { name: '删除账号' })
|
|
94
|
+
expect(deleteBtn).toBeDisabled()
|
|
95
|
+
|
|
96
|
+
fireEvent.change(screen.getByLabelText('输入登录邮箱以确认'), {
|
|
97
|
+
target: { value: 'USER@example.com' }, // 大小写不敏感匹配
|
|
98
|
+
})
|
|
99
|
+
expect(deleteBtn).toBeEnabled()
|
|
100
|
+
fireEvent.click(deleteBtn)
|
|
101
|
+
|
|
102
|
+
|
|
103
|
+
const confirm = await screen.findByRole('button', { name: '永久删除' })
|
|
104
|
+
expect(confirm).toBeDisabled()
|
|
105
|
+
fireEvent.click(screen.getByLabelText('我理解并接受以上影响'))
|
|
106
|
+
fireEvent.click(confirm)
|
|
107
|
+
|
|
108
|
+
await waitFor(() => expect(mocks.del).toHaveBeenCalledWith('/auth/me'))
|
|
109
|
+
})
|
|
110
|
+
|
|
111
|
+
|
|
112
|
+
it('B5:昵称为必填字段(aria-required + 视觉星号)', () => {
|
|
113
|
+
render(<ProfileSettingsPage />)
|
|
114
|
+
const input = screen.getByLabelText(/昵称/)
|
|
115
|
+
expect(input).toHaveAttribute('aria-required', 'true')
|
|
116
|
+
expect(screen.getByText('*')).toHaveAttribute('aria-hidden', 'true')
|
|
117
|
+
|
|
118
|
+
expect(screen.getByLabelText(/头像链接/)).not.toHaveAttribute('aria-required')
|
|
119
|
+
})
|
|
120
|
+
|
|
121
|
+
|
|
122
|
+
it('G7.3:昵称校验失败 → aria-invalid=true 且 aria-describedby 指向错误节点', async () => {
|
|
123
|
+
render(<ProfileSettingsPage />)
|
|
124
|
+
const input = screen.getByLabelText(/昵称/)
|
|
125
|
+
fireEvent.change(input, { target: { value: '' } })
|
|
126
|
+
fireEvent.click(screen.getByRole('button', { name: '保存' }))
|
|
127
|
+
|
|
128
|
+
expect(await screen.findByText('请输入昵称')).toBeInTheDocument()
|
|
129
|
+
expect(input).toHaveAttribute('aria-invalid', 'true')
|
|
130
|
+
expect(input.getAttribute('aria-describedby')).toContain('profile-name-error')
|
|
131
|
+
expect(document.getElementById('profile-name-error')).toHaveAttribute('role', 'alert')
|
|
132
|
+
})
|
|
133
|
+
|
|
134
|
+
|
|
135
|
+
it('B2:头像链接 javascript: 与超长均被前端校验拦截(不发请求)', async () => {
|
|
136
|
+
render(<ProfileSettingsPage />)
|
|
137
|
+
const avatar = screen.getByLabelText(/头像链接/)
|
|
138
|
+
fireEvent.change(avatar, { target: { value: 'javascript:alert(1)' } })
|
|
139
|
+
fireEvent.click(screen.getByRole('button', { name: '保存' }))
|
|
140
|
+
expect(await screen.findByText('头像链接需以 http(s):// 开头')).toBeInTheDocument()
|
|
141
|
+
expect(mocks.patch).not.toHaveBeenCalled()
|
|
142
|
+
|
|
143
|
+
fireEvent.change(avatar, { target: { value: 'https://' + 'a'.repeat(2049) } })
|
|
144
|
+
fireEvent.click(screen.getByRole('button', { name: '保存' }))
|
|
145
|
+
expect(await screen.findByText('头像链接最多 2048 字符')).toBeInTheDocument()
|
|
146
|
+
expect(mocks.patch).not.toHaveBeenCalled()
|
|
147
|
+
})
|
|
148
|
+
|
|
149
|
+
|
|
150
|
+
it('B2:头像字段呈现"外部图片可能被拦截"的如实说明', () => {
|
|
151
|
+
render(<ProfileSettingsPage />)
|
|
152
|
+
expect(screen.getByText(/外部图片可能被内容安全策略拦截/)).toBeInTheDocument()
|
|
153
|
+
})
|
|
154
|
+
|
|
155
|
+
|
|
156
|
+
it('B3:邮箱行说明"暂不支持自助修改",页头不含登录邮箱承诺', () => {
|
|
157
|
+
render(<ProfileSettingsPage />)
|
|
158
|
+
expect(screen.getByText(/暂不支持自助修改/)).toBeInTheDocument()
|
|
159
|
+
expect(screen.getByText('个人资料').textContent).toBe('个人资料')
|
|
160
|
+
})
|
|
161
|
+
|
|
162
|
+
|
|
163
|
+
it('B8:保存失败(E_VALIDATION 英文 message)→ toast 中文文案', async () => {
|
|
164
|
+
mocks.patch.mockRejectedValueOnce(
|
|
165
|
+
new ApiError(400, 'E_VALIDATION', 'display_name must be 1-100 characters after trim'),
|
|
166
|
+
)
|
|
167
|
+
render(<ProfileSettingsPage />)
|
|
168
|
+
fireEvent.click(screen.getByRole('button', { name: '保存' }))
|
|
169
|
+
|
|
170
|
+
await waitFor(() => expect(mocks.toastError).toHaveBeenCalledTimes(1))
|
|
171
|
+
expect(mocks.toastError).toHaveBeenCalledWith('请求参数有误,请检查填写内容后重试')
|
|
172
|
+
})
|
|
173
|
+
})
|
|
@@ -0,0 +1,212 @@
|
|
|
1
|
+
import '@testing-library/jest-dom/vitest'
|
|
2
|
+
import { fireEvent, render, screen, waitFor } from '@testing-library/react'
|
|
3
|
+
import { describe, it, expect, vi, beforeEach } from 'vitest'
|
|
4
|
+
import { ApiError } from '@ploykit/client'
|
|
5
|
+
import { SecuritySettingsPage } from '../SecuritySettingsPage'
|
|
6
|
+
|
|
7
|
+
const mocks = vi.hoisted(() => ({
|
|
8
|
+
post: vi.fn(),
|
|
9
|
+
refresh: vi.fn(),
|
|
10
|
+
logout: vi.fn(),
|
|
11
|
+
confirm: vi.fn(),
|
|
12
|
+
toastError: vi.fn(),
|
|
13
|
+
toastSuccess: vi.fn(),
|
|
14
|
+
sessions: [] as Array<Record<string, unknown>>,
|
|
15
|
+
loading: false,
|
|
16
|
+
revoke: vi.fn(),
|
|
17
|
+
revokeAll: vi.fn(),
|
|
18
|
+
}))
|
|
19
|
+
vi.mock('../../../../../hooks/src/hooks/useApi', () => ({
|
|
20
|
+
useApi: () => ({ post: mocks.post, get: vi.fn(), put: vi.fn(), patch: vi.fn(), delete: vi.fn() }),
|
|
21
|
+
}))
|
|
22
|
+
vi.mock('../../../../../hooks/src/hooks/useAuth', () => ({
|
|
23
|
+
useAuth: () => ({ user: null, loading: false, refresh: mocks.refresh, logout: mocks.logout, workspaces: [] }),
|
|
24
|
+
}))
|
|
25
|
+
vi.mock('../../../components/toast', () => ({
|
|
26
|
+
toast: { success: mocks.toastSuccess, error: mocks.toastError, info: vi.fn() },
|
|
27
|
+
}))
|
|
28
|
+
vi.mock('../../../components/ConfirmDialog', () => ({
|
|
29
|
+
useConfirm: () => mocks.confirm,
|
|
30
|
+
}))
|
|
31
|
+
vi.mock('../../../../../hooks/src/hooks/useSessions', () => ({
|
|
32
|
+
useSessions: () => ({ sessions: mocks.sessions, loading: mocks.loading, error: null, refetch: vi.fn() }),
|
|
33
|
+
useRevokeSession: () => ({ revoke: mocks.revoke, loading: false, error: null }),
|
|
34
|
+
useRevokeAllSessions: () => ({ revokeAll: mocks.revokeAll, loading: false, error: null }),
|
|
35
|
+
}))
|
|
36
|
+
|
|
37
|
+
const NOW = '2026-10-05T10:00:00Z'
|
|
38
|
+
function session(over: Record<string, unknown> = {}) {
|
|
39
|
+
return {
|
|
40
|
+
id: 's-1', ip_hash: 'a1b2c3d4e5f6', user_agent: 'Mozilla/5.0 Chrome/130',
|
|
41
|
+
last_seen_at: NOW, expires_at: '2026-11-05T10:00:00Z', created_at: NOW,
|
|
42
|
+
...over,
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
beforeEach(() => {
|
|
47
|
+
mocks.post.mockReset().mockResolvedValue({ expires_at: NOW })
|
|
48
|
+
mocks.refresh.mockReset().mockResolvedValue(undefined)
|
|
49
|
+
mocks.logout.mockReset().mockResolvedValue(undefined)
|
|
50
|
+
mocks.confirm.mockReset().mockResolvedValue(true)
|
|
51
|
+
mocks.revoke.mockReset().mockResolvedValue(undefined)
|
|
52
|
+
mocks.revokeAll.mockReset().mockResolvedValue(undefined)
|
|
53
|
+
mocks.toastError.mockReset()
|
|
54
|
+
mocks.toastSuccess.mockReset()
|
|
55
|
+
mocks.loading = false
|
|
56
|
+
mocks.sessions = []
|
|
57
|
+
})
|
|
58
|
+
|
|
59
|
+
describe('SecuritySettingsPage', () => {
|
|
60
|
+
it('会话加载中渲染 Skeleton 行', () => {
|
|
61
|
+
mocks.loading = true
|
|
62
|
+
render(<SecuritySettingsPage />)
|
|
63
|
+
expect(document.querySelectorAll('[data-slot="skeleton"]').length).toBeGreaterThan(0)
|
|
64
|
+
})
|
|
65
|
+
|
|
66
|
+
it('渲染会话行:current=true 显示当前设备徽标,current 缺失显示 —', () => {
|
|
67
|
+
mocks.sessions = [
|
|
68
|
+
session({ id: 's-cur', user_agent: 'MacBook Chrome/130', current: true }),
|
|
69
|
+
session({ id: 's-old', user_agent: 'iPhone Safari' }), // 后端 current 并行落地前的形态
|
|
70
|
+
]
|
|
71
|
+
render(<SecuritySettingsPage />)
|
|
72
|
+
expect(screen.getByText('当前设备')).toBeInTheDocument()
|
|
73
|
+
expect(screen.getByText('MacBook Chrome/130')).toBeInTheDocument()
|
|
74
|
+
expect(screen.getByText('iPhone Safari')).toBeInTheDocument()
|
|
75
|
+
})
|
|
76
|
+
|
|
77
|
+
it('修改密码 → POST /auth/change-password 携带 old/new', async () => {
|
|
78
|
+
render(<SecuritySettingsPage />)
|
|
79
|
+
fireEvent.change(screen.getByLabelText('当前密码'), { target: { value: 'old-password' } })
|
|
80
|
+
fireEvent.change(screen.getByLabelText('新密码'), { target: { value: 'Abcdef1234!' } })
|
|
81
|
+
fireEvent.click(screen.getByRole('button', { name: '修改密码' }))
|
|
82
|
+
|
|
83
|
+
await waitFor(() => expect(mocks.post).toHaveBeenCalledTimes(1))
|
|
84
|
+
expect(mocks.post).toHaveBeenCalledWith('/auth/change-password', {
|
|
85
|
+
old_password: 'old-password', new_password: 'Abcdef1234!',
|
|
86
|
+
})
|
|
87
|
+
})
|
|
88
|
+
|
|
89
|
+
it('弱新密码被 zod 拦截,不发请求', async () => {
|
|
90
|
+
render(<SecuritySettingsPage />)
|
|
91
|
+
fireEvent.change(screen.getByLabelText('当前密码'), { target: { value: 'old-password' } })
|
|
92
|
+
fireEvent.change(screen.getByLabelText('新密码'), { target: { value: 'abcdefgh' } })
|
|
93
|
+
fireEvent.click(screen.getByRole('button', { name: '修改密码' }))
|
|
94
|
+
|
|
95
|
+
expect(await screen.findByText('密码至少 10 位')).toBeInTheDocument()
|
|
96
|
+
expect(mocks.post).not.toHaveBeenCalled()
|
|
97
|
+
})
|
|
98
|
+
|
|
99
|
+
|
|
100
|
+
|
|
101
|
+
it('B4:新密码与当前密码相同 → 内联报错且不发请求', async () => {
|
|
102
|
+
render(<SecuritySettingsPage />)
|
|
103
|
+
fireEvent.change(screen.getByLabelText('当前密码'), { target: { value: 'Abcdef1234!' } })
|
|
104
|
+
fireEvent.change(screen.getByLabelText('新密码'), { target: { value: 'Abcdef1234!' } })
|
|
105
|
+
fireEvent.click(screen.getByRole('button', { name: '修改密码' }))
|
|
106
|
+
|
|
107
|
+
expect(await screen.findByText('新密码不能与当前密码相同')).toBeInTheDocument()
|
|
108
|
+
expect(mocks.post).not.toHaveBeenCalled()
|
|
109
|
+
})
|
|
110
|
+
|
|
111
|
+
it('B4 边界:当前密码为空时不触发 new==old 跨字段报错(仍报必填)', async () => {
|
|
112
|
+
render(<SecuritySettingsPage />)
|
|
113
|
+
fireEvent.change(screen.getByLabelText('新密码'), { target: { value: 'Abcdef1234!' } })
|
|
114
|
+
fireEvent.click(screen.getByRole('button', { name: '修改密码' }))
|
|
115
|
+
|
|
116
|
+
expect(await screen.findByText('请输入当前密码')).toBeInTheDocument()
|
|
117
|
+
expect(screen.queryByText('新密码不能与当前密码相同')).not.toBeInTheDocument()
|
|
118
|
+
expect(mocks.post).not.toHaveBeenCalled()
|
|
119
|
+
})
|
|
120
|
+
|
|
121
|
+
it('单行吊销:确认后调用 revoke(sessionId)', async () => {
|
|
122
|
+
mocks.confirm.mockResolvedValueOnce(true)
|
|
123
|
+
mocks.sessions = [session({ id: 's-9', user_agent: 'iPad Safari', current: false })]
|
|
124
|
+
render(<SecuritySettingsPage />)
|
|
125
|
+
|
|
126
|
+
fireEvent.click(screen.getByRole('button', { name: '吊销' }))
|
|
127
|
+
await waitFor(() => expect(mocks.revoke).toHaveBeenCalledWith('s-9'))
|
|
128
|
+
expect(mocks.confirm).toHaveBeenCalledWith(
|
|
129
|
+
expect.objectContaining({ title: '吊销此会话?', danger: true }),
|
|
130
|
+
)
|
|
131
|
+
})
|
|
132
|
+
|
|
133
|
+
it('单行吊销:取消确认则不调用 revoke', async () => {
|
|
134
|
+
mocks.confirm.mockResolvedValueOnce(false)
|
|
135
|
+
mocks.sessions = [session({ id: 's-9' })]
|
|
136
|
+
render(<SecuritySettingsPage />)
|
|
137
|
+
|
|
138
|
+
fireEvent.click(screen.getByRole('button', { name: '吊销' }))
|
|
139
|
+
await waitFor(() => expect(mocks.confirm).toHaveBeenCalled())
|
|
140
|
+
expect(mocks.revoke).not.toHaveBeenCalled()
|
|
141
|
+
})
|
|
142
|
+
|
|
143
|
+
it('P1-3:吊销当前会话(current=true)→ 调 logout() 并跳 /login,不困在失效会话页', async () => {
|
|
144
|
+
mocks.sessions = [session({ id: 's-cur', current: true })]
|
|
145
|
+
render(<SecuritySettingsPage />)
|
|
146
|
+
|
|
147
|
+
fireEvent.click(screen.getByRole('button', { name: '吊销' }))
|
|
148
|
+
await waitFor(() => expect(mocks.revoke).toHaveBeenCalledWith('s-cur'))
|
|
149
|
+
await waitFor(() => expect(mocks.logout).toHaveBeenCalledTimes(1))
|
|
150
|
+
})
|
|
151
|
+
|
|
152
|
+
it('P1-3:吊销非当前会话 → 不调 logout,留在本页', async () => {
|
|
153
|
+
mocks.sessions = [session({ id: 's-other', current: false })]
|
|
154
|
+
render(<SecuritySettingsPage />)
|
|
155
|
+
|
|
156
|
+
fireEvent.click(screen.getByRole('button', { name: '吊销' }))
|
|
157
|
+
await waitFor(() => expect(mocks.revoke).toHaveBeenCalledWith('s-other'))
|
|
158
|
+
expect(mocks.logout).not.toHaveBeenCalled()
|
|
159
|
+
})
|
|
160
|
+
|
|
161
|
+
it('P2-24(最危险操作):全部吊销 → ImpactConfirmation 勾选后 revokeAll', async () => {
|
|
162
|
+
mocks.sessions = [session({ id: 's-1' }), session({ id: 's-2', current: true })]
|
|
163
|
+
render(<SecuritySettingsPage />)
|
|
164
|
+
|
|
165
|
+
fireEvent.click(screen.getByRole('button', { name: '全部吊销' }))
|
|
166
|
+
|
|
167
|
+
expect(await screen.findByText('吊销全部会话?')).toBeInTheDocument()
|
|
168
|
+
expect(screen.getByText(/个人访问令牌(PAT)不受影响/)).toBeInTheDocument()
|
|
169
|
+
|
|
170
|
+
fireEvent.click(screen.getByLabelText(/我理解并接受以上影响/))
|
|
171
|
+
fireEvent.click(screen.getByRole('button', { name: '全部吊销', hidden: false }))
|
|
172
|
+
await waitFor(() => expect(mocks.revokeAll).toHaveBeenCalledTimes(1))
|
|
173
|
+
})
|
|
174
|
+
|
|
175
|
+
it('P2-24:全部吊销失败 → 错误 toast(服务端语义透出)', async () => {
|
|
176
|
+
mocks.revokeAll.mockRejectedValueOnce(new Error('网络连接失败'))
|
|
177
|
+
render(<SecuritySettingsPage />)
|
|
178
|
+
|
|
179
|
+
fireEvent.click(screen.getByRole('button', { name: '全部吊销' }))
|
|
180
|
+
fireEvent.click(await screen.findByLabelText(/我理解并接受以上影响/))
|
|
181
|
+
fireEvent.click(screen.getByRole('button', { name: '全部吊销', hidden: false }))
|
|
182
|
+
|
|
183
|
+
await waitFor(() => expect(mocks.toastError).toHaveBeenCalledWith('网络连接失败'))
|
|
184
|
+
})
|
|
185
|
+
|
|
186
|
+
it('P2-24:修改密码失败 → 错误 toast(服务端语义透出)', async () => {
|
|
187
|
+
mocks.post.mockRejectedValueOnce(new Error('当前密码不正确'))
|
|
188
|
+
render(<SecuritySettingsPage />)
|
|
189
|
+
fireEvent.change(screen.getByLabelText('当前密码'), { target: { value: 'wrong-old' } })
|
|
190
|
+
fireEvent.change(screen.getByLabelText('新密码'), { target: { value: 'Abcdef1234!' } })
|
|
191
|
+
fireEvent.click(screen.getByRole('button', { name: '修改密码' }))
|
|
192
|
+
|
|
193
|
+
await waitFor(() => expect(mocks.post).toHaveBeenCalledTimes(1))
|
|
194
|
+
await waitFor(() => expect(mocks.toastError).toHaveBeenCalledWith('当前密码不正确'))
|
|
195
|
+
})
|
|
196
|
+
|
|
197
|
+
|
|
198
|
+
|
|
199
|
+
|
|
200
|
+
it('B3:旧密码错 401 信封(英文 message)→ toast 中文域文案,不直出英文行话', async () => {
|
|
201
|
+
mocks.post.mockRejectedValueOnce(
|
|
202
|
+
new ApiError(401, 'E_UNAUTHENTICATED', 'current password incorrect'),
|
|
203
|
+
)
|
|
204
|
+
render(<SecuritySettingsPage />)
|
|
205
|
+
fireEvent.change(screen.getByLabelText('当前密码'), { target: { value: 'wrong-old' } })
|
|
206
|
+
fireEvent.change(screen.getByLabelText('新密码'), { target: { value: 'Abcdef1234!' } })
|
|
207
|
+
fireEvent.click(screen.getByRole('button', { name: '修改密码' }))
|
|
208
|
+
|
|
209
|
+
await waitFor(() => expect(mocks.post).toHaveBeenCalledTimes(1))
|
|
210
|
+
await waitFor(() => expect(mocks.toastError).toHaveBeenCalledWith('当前密码不正确,请确认后重新输入'))
|
|
211
|
+
})
|
|
212
|
+
})
|