@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,347 @@
|
|
|
1
|
+
import '@testing-library/jest-dom/vitest'
|
|
2
|
+
import { fireEvent, render, screen, waitFor } from '@testing-library/react'
|
|
3
|
+
import { QueryClient, QueryClientProvider } from '@tanstack/react-query'
|
|
4
|
+
import { MemoryRouter, useLocation } from 'react-router'
|
|
5
|
+
import { describe, it, expect, vi, beforeEach } from 'vitest'
|
|
6
|
+
import { ApiError } from '@ploykit/client'
|
|
7
|
+
import { MembersPage } from '../MembersPage'
|
|
8
|
+
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
const apiMocks = vi.hoisted(() => ({
|
|
12
|
+
get: vi.fn(),
|
|
13
|
+
post: vi.fn(),
|
|
14
|
+
put: vi.fn(),
|
|
15
|
+
patch: vi.fn(),
|
|
16
|
+
delete: vi.fn(),
|
|
17
|
+
}))
|
|
18
|
+
vi.mock('../../../../../hooks/src/hooks/useApi', () => ({ useApi: () => apiMocks }))
|
|
19
|
+
|
|
20
|
+
const wsMocks = vi.hoisted(() => ({ role: 'owner' as string }))
|
|
21
|
+
vi.mock('../../../../../hooks/src/hooks/useWorkspace', () => ({
|
|
22
|
+
useWorkspace: () => ({
|
|
23
|
+
current: { id: 'ws-1', name: 'Acme', slug: 'acme', plan_code: 'free', role: wsMocks.role },
|
|
24
|
+
switchTo: vi.fn(),
|
|
25
|
+
clear: vi.fn(),
|
|
26
|
+
}),
|
|
27
|
+
}))
|
|
28
|
+
|
|
29
|
+
const toastMocks = vi.hoisted(() => ({
|
|
30
|
+
success: vi.fn(), error: vi.fn(), info: vi.fn(),
|
|
31
|
+
}))
|
|
32
|
+
vi.mock('../../../components/toast', () => ({ toast: toastMocks }))
|
|
33
|
+
|
|
34
|
+
vi.mock('../../../components/ConfirmDialog', () => ({
|
|
35
|
+
useConfirm: () => async () => true,
|
|
36
|
+
}))
|
|
37
|
+
|
|
38
|
+
|
|
39
|
+
const locationLog: string[] = []
|
|
40
|
+
function LocationProbe() {
|
|
41
|
+
const loc = useLocation()
|
|
42
|
+
locationLog.push(`${loc.pathname}${loc.search}`)
|
|
43
|
+
return null
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
function renderPage(initialEntries?: string[]) {
|
|
47
|
+
const qc = new QueryClient({ defaultOptions: { queries: { retry: false } } })
|
|
48
|
+
return render(
|
|
49
|
+
<QueryClientProvider client={qc}>
|
|
50
|
+
<MemoryRouter initialEntries={initialEntries}>
|
|
51
|
+
<LocationProbe />
|
|
52
|
+
<MembersPage />
|
|
53
|
+
</MemoryRouter>
|
|
54
|
+
</QueryClientProvider>,
|
|
55
|
+
)
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
const member = {
|
|
59
|
+
user_id: 'u-1', email: 'owner@example.com', display_name: 'Owner',
|
|
60
|
+
role: 'owner', created_at: '2026-01-01T00:00:00Z',
|
|
61
|
+
}
|
|
62
|
+
const admin = {
|
|
63
|
+
user_id: 'u-2', email: 'admin@example.com', display_name: 'Admin',
|
|
64
|
+
role: 'admin', created_at: '2026-02-01T00:00:00Z',
|
|
65
|
+
}
|
|
66
|
+
const invitation = {
|
|
67
|
+
id: 'inv-1', workspace_id: 'ws-1', email: 'new@example.com', role: 'member',
|
|
68
|
+
status: 'pending', expires_at: '2026-12-01T00:00:00Z', created_at: '2026-06-01T00:00:00Z',
|
|
69
|
+
}
|
|
70
|
+
const shareLink = {
|
|
71
|
+
id: 'link-1', code_prefix: 'abcd', role: 'member', max_uses: 10, uses: 2,
|
|
72
|
+
expires_at: '2026-12-01T00:00:00Z', created_at: '2026-06-01T00:00:00Z',
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
beforeEach(() => {
|
|
76
|
+
vi.clearAllMocks()
|
|
77
|
+
locationLog.length = 0
|
|
78
|
+
wsMocks.role = 'owner'
|
|
79
|
+
|
|
80
|
+
apiMocks.get.mockImplementation(async (path: string) => {
|
|
81
|
+
if (path.startsWith('/api/workspaces/ws-1/members')) {
|
|
82
|
+
return { items: [member, admin], total: 2 }
|
|
83
|
+
}
|
|
84
|
+
if (path.startsWith('/api/workspaces/ws-1/invitations')) {
|
|
85
|
+
return { items: [invitation], total: 1 }
|
|
86
|
+
}
|
|
87
|
+
if (path.startsWith('/api/workspaces/ws-1/share-links')) {
|
|
88
|
+
return { items: [shareLink], total: 1 }
|
|
89
|
+
}
|
|
90
|
+
throw new Error('unexpected GET ' + path)
|
|
91
|
+
})
|
|
92
|
+
apiMocks.post.mockResolvedValue({})
|
|
93
|
+
apiMocks.patch.mockResolvedValue({})
|
|
94
|
+
apiMocks.delete.mockResolvedValue({})
|
|
95
|
+
})
|
|
96
|
+
|
|
97
|
+
describe('MembersPage', () => {
|
|
98
|
+
it('加载后渲染成员表(邮箱/角色 + 分页底栏总数来自信封 total)', async () => {
|
|
99
|
+
renderPage()
|
|
100
|
+
expect(await screen.findByText('owner@example.com')).toBeInTheDocument()
|
|
101
|
+
expect(screen.getByText('admin@example.com')).toBeInTheDocument()
|
|
102
|
+
expect(screen.getByText('所有者')).toBeInTheDocument()
|
|
103
|
+
|
|
104
|
+
expect(await screen.findByText('2')).toBeInTheDocument()
|
|
105
|
+
})
|
|
106
|
+
|
|
107
|
+
it('邀请成员:提交正确的 path 与 payload', async () => {
|
|
108
|
+
renderPage()
|
|
109
|
+
fireEvent.click(await screen.findByRole('button', { name: /邀请成员/ }))
|
|
110
|
+
|
|
111
|
+
const emailInput = await screen.findByLabelText('邮箱')
|
|
112
|
+
fireEvent.change(emailInput, { target: { value: 'new@example.com' } })
|
|
113
|
+
fireEvent.click(screen.getByRole('button', { name: '发送邀请' }))
|
|
114
|
+
|
|
115
|
+
await waitFor(() =>
|
|
116
|
+
expect(apiMocks.post).toHaveBeenCalledWith(
|
|
117
|
+
'/api/workspaces/ws-1/invitations',
|
|
118
|
+
{ email: 'new@example.com', role: 'member' },
|
|
119
|
+
),
|
|
120
|
+
)
|
|
121
|
+
await waitFor(() => expect(toastMocks.success).toHaveBeenCalled())
|
|
122
|
+
})
|
|
123
|
+
|
|
124
|
+
it('移除成员 409(last owner)→ 透出冲突文案', async () => {
|
|
125
|
+
apiMocks.delete.mockRejectedValue(
|
|
126
|
+
new ApiError(409, 'E_CONFLICT', 'cannot remove the last owner'),
|
|
127
|
+
)
|
|
128
|
+
renderPage()
|
|
129
|
+
await screen.findByText('admin@example.com')
|
|
130
|
+
|
|
131
|
+
fireEvent.click(screen.getByRole('button', { name: '移除' }))
|
|
132
|
+
await waitFor(() => expect(toastMocks.error).toHaveBeenCalled())
|
|
133
|
+
expect(toastMocks.error.mock.calls[0][0]).toContain('请先转移或删除工作区')
|
|
134
|
+
})
|
|
135
|
+
|
|
136
|
+
it('角色变更 Select 走 PATCH members/{userId} {role}', async () => {
|
|
137
|
+
renderPage()
|
|
138
|
+
const trigger = await screen.findByRole('combobox', { name: /admin@example.com 的角色/ })
|
|
139
|
+
fireEvent.click(trigger)
|
|
140
|
+
const option = await screen.findByRole('option', { name: '成员' })
|
|
141
|
+
|
|
142
|
+
|
|
143
|
+
fireEvent.pointerDown(option, { button: 0, pointerType: 'mouse' })
|
|
144
|
+
fireEvent.pointerUp(option, { button: 0, pointerType: 'mouse' })
|
|
145
|
+
fireEvent.click(option)
|
|
146
|
+
|
|
147
|
+
await waitFor(() =>
|
|
148
|
+
expect(apiMocks.patch).toHaveBeenCalledWith(
|
|
149
|
+
'/api/workspaces/ws-1/members/u-2',
|
|
150
|
+
{ role: 'member' },
|
|
151
|
+
),
|
|
152
|
+
)
|
|
153
|
+
})
|
|
154
|
+
|
|
155
|
+
|
|
156
|
+
it('owner:member/admin 行出现"转让所有权"→ ImpactConfirmation 勾选后 POST transfer-ownership', async () => {
|
|
157
|
+
renderPage()
|
|
158
|
+
await screen.findByText('admin@example.com')
|
|
159
|
+
|
|
160
|
+
|
|
161
|
+
const transferBtn = screen.getByRole('button', { name: '转让所有权' })
|
|
162
|
+
expect(screen.getAllByRole('button', { name: '转让所有权' })).toHaveLength(1)
|
|
163
|
+
fireEvent.click(transferBtn)
|
|
164
|
+
|
|
165
|
+
|
|
166
|
+
expect(await screen.findByText('转让所有权给 admin@example.com')).toBeInTheDocument()
|
|
167
|
+
fireEvent.click(screen.getByLabelText('我理解并接受以上影响'))
|
|
168
|
+
fireEvent.click(screen.getByRole('button', { name: '确认转让' }))
|
|
169
|
+
|
|
170
|
+
await waitFor(() =>
|
|
171
|
+
expect(apiMocks.post).toHaveBeenCalledWith(
|
|
172
|
+
'/api/workspaces/ws-1/transfer-ownership',
|
|
173
|
+
{ user_id: 'u-2' },
|
|
174
|
+
),
|
|
175
|
+
)
|
|
176
|
+
await waitFor(() => expect(toastMocks.success).toHaveBeenCalled())
|
|
177
|
+
})
|
|
178
|
+
|
|
179
|
+
it('转让所有权 409(目标已是 owner/钩子拦截)→ toast 透出本地化语义', async () => {
|
|
180
|
+
apiMocks.post.mockRejectedValue(
|
|
181
|
+
new ApiError(409, 'E_CONFLICT', 'target is already an owner'),
|
|
182
|
+
)
|
|
183
|
+
renderPage()
|
|
184
|
+
await screen.findByText('admin@example.com')
|
|
185
|
+
|
|
186
|
+
fireEvent.click(screen.getByRole('button', { name: '转让所有权' }))
|
|
187
|
+
fireEvent.click(await screen.findByLabelText('我理解并接受以上影响'))
|
|
188
|
+
fireEvent.click(screen.getByRole('button', { name: '确认转让' }))
|
|
189
|
+
|
|
190
|
+
await waitFor(() => expect(toastMocks.error).toHaveBeenCalled())
|
|
191
|
+
|
|
192
|
+
|
|
193
|
+
expect(toastMocks.error.mock.calls[0][0]).toContain('对方已是所有者')
|
|
194
|
+
})
|
|
195
|
+
})
|
|
196
|
+
|
|
197
|
+
describe('MembersPage 角色门控(member 只读)', () => {
|
|
198
|
+
beforeEach(() => {
|
|
199
|
+
wsMocks.role = 'member'
|
|
200
|
+
})
|
|
201
|
+
|
|
202
|
+
it('member:无邀请/分享链接/移除/撤销/角色变更控件,列表只读展示', async () => {
|
|
203
|
+
renderPage()
|
|
204
|
+
expect(await screen.findByText('owner@example.com')).toBeInTheDocument()
|
|
205
|
+
|
|
206
|
+
expect(screen.queryByRole('button', { name: /邀请成员/ })).not.toBeInTheDocument()
|
|
207
|
+
expect(screen.queryByRole('button', { name: /创建分享链接/ })).not.toBeInTheDocument()
|
|
208
|
+
expect(screen.queryByRole('button', { name: '移除' })).not.toBeInTheDocument()
|
|
209
|
+
|
|
210
|
+
expect(screen.queryByRole('button', { name: '转让所有权' })).not.toBeInTheDocument()
|
|
211
|
+
|
|
212
|
+
expect(screen.queryByRole('combobox', { name: /admin@example.com 的角色/ })).not.toBeInTheDocument()
|
|
213
|
+
expect(screen.getAllByText('管理员').length).toBeGreaterThan(0)
|
|
214
|
+
})
|
|
215
|
+
|
|
216
|
+
it('member:邀请/分享链接两个 tab 无撤销按钮(只读)', async () => {
|
|
217
|
+
renderPage()
|
|
218
|
+
await screen.findByText('owner@example.com')
|
|
219
|
+
fireEvent.click(screen.getByRole('tab', { name: /邀请/ }))
|
|
220
|
+
expect(await screen.findByText('new@example.com')).toBeInTheDocument()
|
|
221
|
+
expect(screen.queryByRole('button', { name: '撤销' })).not.toBeInTheDocument()
|
|
222
|
+
|
|
223
|
+
fireEvent.click(screen.getByRole('tab', { name: /分享链接/ }))
|
|
224
|
+
expect(await screen.findByText(/abcd/)).toBeInTheDocument()
|
|
225
|
+
expect(screen.queryByRole('button', { name: '撤销' })).not.toBeInTheDocument()
|
|
226
|
+
})
|
|
227
|
+
})
|
|
228
|
+
|
|
229
|
+
describe('MembersPage 角色门控(admin 可管理但不可转让所有权)', () => {
|
|
230
|
+
beforeEach(() => {
|
|
231
|
+
wsMocks.role = 'admin'
|
|
232
|
+
})
|
|
233
|
+
|
|
234
|
+
it('admin:可见移除但无转让所有权(发起方必须是 owner,守卫在 workspace 域)', async () => {
|
|
235
|
+
renderPage()
|
|
236
|
+
await screen.findByText('admin@example.com')
|
|
237
|
+
|
|
238
|
+
expect(screen.getByRole('button', { name: '移除' })).toBeInTheDocument()
|
|
239
|
+
expect(screen.queryByRole('button', { name: '转让所有权' })).not.toBeInTheDocument()
|
|
240
|
+
})
|
|
241
|
+
})
|
|
242
|
+
|
|
243
|
+
describe('MembersPage B7:邀请邮箱语义 type=email(zod 兜底保留)', () => {
|
|
244
|
+
it('输入框 type=email + autoComplete;非法邮箱仍由 zod 拦截(不发请求)', async () => {
|
|
245
|
+
renderPage()
|
|
246
|
+
fireEvent.click(await screen.findByRole('button', { name: /邀请成员/ }))
|
|
247
|
+
|
|
248
|
+
const emailInput = await screen.findByLabelText('邮箱')
|
|
249
|
+
expect(emailInput).toHaveAttribute('type', 'email')
|
|
250
|
+
expect(emailInput).toHaveAttribute('autocomplete', 'email')
|
|
251
|
+
|
|
252
|
+
expect(emailInput.closest('form')).toHaveAttribute('novalidate')
|
|
253
|
+
|
|
254
|
+
fireEvent.change(emailInput, { target: { value: 'not-an-email' } })
|
|
255
|
+
fireEvent.click(screen.getByRole('button', { name: '发送邀请' }))
|
|
256
|
+
expect(await screen.findByText('邮箱格式不正确')).toBeInTheDocument()
|
|
257
|
+
expect(apiMocks.post).not.toHaveBeenCalled()
|
|
258
|
+
})
|
|
259
|
+
})
|
|
260
|
+
|
|
261
|
+
describe('MembersPage B9:分享链接空态补 CTA(与邀请空态同构)', () => {
|
|
262
|
+
beforeEach(() => {
|
|
263
|
+
apiMocks.get.mockImplementation(async (path: string) => {
|
|
264
|
+
if (path.startsWith('/api/workspaces/ws-1/members')) {
|
|
265
|
+
return { items: [member], total: 1 }
|
|
266
|
+
}
|
|
267
|
+
if (path.startsWith('/api/workspaces/ws-1/invitations')) {
|
|
268
|
+
return { items: [], total: 0 }
|
|
269
|
+
}
|
|
270
|
+
if (path.startsWith('/api/workspaces/ws-1/share-links')) {
|
|
271
|
+
return { items: [], total: 0 }
|
|
272
|
+
}
|
|
273
|
+
throw new Error('unexpected GET ' + path)
|
|
274
|
+
})
|
|
275
|
+
})
|
|
276
|
+
|
|
277
|
+
it('分享链接空态 hint 指向页头主动作;邀请空态同构对照', async () => {
|
|
278
|
+
renderPage()
|
|
279
|
+
await screen.findByText('owner@example.com')
|
|
280
|
+
|
|
281
|
+
fireEvent.click(screen.getByRole('tab', { name: /分享链接/ }))
|
|
282
|
+
expect(
|
|
283
|
+
await screen.findByText(/点击右上角“创建分享链接”生成兑换码/),
|
|
284
|
+
).toBeInTheDocument()
|
|
285
|
+
|
|
286
|
+
|
|
287
|
+
fireEvent.click(screen.getByRole('tab', { name: /邀请/ }))
|
|
288
|
+
expect(
|
|
289
|
+
await screen.findByText(/点击右上角“邀请成员”发送新邀请/),
|
|
290
|
+
).toBeInTheDocument()
|
|
291
|
+
})
|
|
292
|
+
})
|
|
293
|
+
|
|
294
|
+
describe('MembersPage K5:tab/分页状态进 URL(searchParams)', () => {
|
|
295
|
+
it('默认无参数 → 成员 Tab;默认值不写入地址栏', async () => {
|
|
296
|
+
renderPage()
|
|
297
|
+
expect(await screen.findByText('owner@example.com')).toBeInTheDocument()
|
|
298
|
+
expect(locationLog.at(-1)).toBe('/')
|
|
299
|
+
})
|
|
300
|
+
|
|
301
|
+
it('URL ?tab=share-links 直达分享链接 Tab(刷新不回默认)', async () => {
|
|
302
|
+
renderPage(['/?tab=share-links'])
|
|
303
|
+
expect(await screen.findByText(/abcd/)).toBeInTheDocument()
|
|
304
|
+
})
|
|
305
|
+
|
|
306
|
+
it('非法 tab 参数回落成员 Tab;点击 Tab 写入地址栏', async () => {
|
|
307
|
+
renderPage(['/?tab=bogus'])
|
|
308
|
+
expect(await screen.findByText('owner@example.com')).toBeInTheDocument()
|
|
309
|
+
|
|
310
|
+
expect(screen.queryByText('new@example.com')).not.toBeInTheDocument()
|
|
311
|
+
|
|
312
|
+
fireEvent.click(screen.getByRole('tab', { name: /邀请/ }))
|
|
313
|
+
expect(await screen.findByText('new@example.com')).toBeInTheDocument()
|
|
314
|
+
|
|
315
|
+
expect(locationLog.at(-1)).toBe('/?tab=invitations')
|
|
316
|
+
})
|
|
317
|
+
|
|
318
|
+
it('翻页写入页码参数(total 120 > 50/页 → 下一页可用)', async () => {
|
|
319
|
+
apiMocks.get.mockImplementation(async (path: string) => {
|
|
320
|
+
if (path.startsWith('/api/workspaces/ws-1/members')) {
|
|
321
|
+
return { items: [member, admin], total: 120 }
|
|
322
|
+
}
|
|
323
|
+
if (path.startsWith('/api/workspaces/ws-1/invitations')) {
|
|
324
|
+
return { items: [invitation], total: 1 }
|
|
325
|
+
}
|
|
326
|
+
if (path.startsWith('/api/workspaces/ws-1/share-links')) {
|
|
327
|
+
return { items: [shareLink], total: 1 }
|
|
328
|
+
}
|
|
329
|
+
throw new Error('unexpected GET ' + path)
|
|
330
|
+
})
|
|
331
|
+
renderPage()
|
|
332
|
+
await screen.findByText('owner@example.com')
|
|
333
|
+
|
|
334
|
+
fireEvent.click(screen.getByRole('button', { name: '下一页' }))
|
|
335
|
+
await waitFor(() => expect(locationLog.at(-1)).toBe('/?mpage=2'))
|
|
336
|
+
})
|
|
337
|
+
|
|
338
|
+
it('URL 直达 ?mpage=2 → 请求带 page=2 且分页栏显示第 2 页', async () => {
|
|
339
|
+
renderPage(['/?mpage=2'])
|
|
340
|
+
await screen.findByText('owner@example.com')
|
|
341
|
+
await waitFor(() =>
|
|
342
|
+
expect(apiMocks.get).toHaveBeenCalledWith(
|
|
343
|
+
'/api/workspaces/ws-1/members?page=2&page_size=50',
|
|
344
|
+
),
|
|
345
|
+
)
|
|
346
|
+
})
|
|
347
|
+
})
|
|
@@ -0,0 +1,138 @@
|
|
|
1
|
+
import '@testing-library/jest-dom/vitest'
|
|
2
|
+
import { fireEvent, render, screen, waitFor } from '@testing-library/react'
|
|
3
|
+
import { QueryClient, QueryClientProvider } from '@tanstack/react-query'
|
|
4
|
+
import { MemoryRouter, Routes, Route } from 'react-router'
|
|
5
|
+
import { describe, it, expect, vi, beforeEach } from 'vitest'
|
|
6
|
+
import { ApiError } from '@ploykit/client'
|
|
7
|
+
import { RolePermissionsPage } from '../RolePermissionsPage'
|
|
8
|
+
|
|
9
|
+
const apiMocks = vi.hoisted(() => ({
|
|
10
|
+
get: vi.fn(), post: vi.fn(), put: vi.fn(), patch: vi.fn(), delete: vi.fn(),
|
|
11
|
+
}))
|
|
12
|
+
vi.mock('../../../../../hooks/src/hooks/useApi', () => ({ useApi: () => apiMocks }))
|
|
13
|
+
|
|
14
|
+
vi.mock('../../../../../hooks/src/hooks/useWorkspace', () => ({
|
|
15
|
+
useWorkspace: () => ({
|
|
16
|
+
current: { id: 'ws-1', name: 'Acme', slug: 'acme', plan_code: 'free', role: 'owner' },
|
|
17
|
+
switchTo: vi.fn(),
|
|
18
|
+
clear: vi.fn(),
|
|
19
|
+
}),
|
|
20
|
+
}))
|
|
21
|
+
|
|
22
|
+
const toastMocks = vi.hoisted(() => ({
|
|
23
|
+
success: vi.fn(), error: vi.fn(), info: vi.fn(),
|
|
24
|
+
}))
|
|
25
|
+
vi.mock('../../../components/toast', () => ({ toast: toastMocks }))
|
|
26
|
+
|
|
27
|
+
vi.mock('../../../components/ConfirmDialog', () => ({
|
|
28
|
+
useConfirm: () => async () => true,
|
|
29
|
+
}))
|
|
30
|
+
|
|
31
|
+
function renderPage() {
|
|
32
|
+
const qc = new QueryClient({ defaultOptions: { queries: { retry: false } } })
|
|
33
|
+
return render(
|
|
34
|
+
<QueryClientProvider client={qc}>
|
|
35
|
+
<MemoryRouter initialEntries={['/settings/workspace/roles']}>
|
|
36
|
+
<Routes>
|
|
37
|
+
<Route path="/settings/workspace/roles" element={<RolePermissionsPage />} />
|
|
38
|
+
</Routes>
|
|
39
|
+
</MemoryRouter>
|
|
40
|
+
</QueryClientProvider>,
|
|
41
|
+
)
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
const ROLES = {
|
|
45
|
+
items: [
|
|
46
|
+
{
|
|
47
|
+
role: 'admin',
|
|
48
|
+
perms: ['members:read', 'workspace:read'],
|
|
49
|
+
overridden: false,
|
|
50
|
+
defaults: ['members:read', 'workspace:read'],
|
|
51
|
+
},
|
|
52
|
+
{
|
|
53
|
+
role: 'member',
|
|
54
|
+
perms: ['workspace:read'],
|
|
55
|
+
overridden: true,
|
|
56
|
+
defaults: ['members:read', 'workspace:read'],
|
|
57
|
+
},
|
|
58
|
+
],
|
|
59
|
+
catalog: ['members:read', 'roles:manage', 'workspace:read'],
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
beforeEach(() => {
|
|
63
|
+
vi.clearAllMocks()
|
|
64
|
+
apiMocks.get.mockResolvedValue(ROLES)
|
|
65
|
+
apiMocks.put.mockResolvedValue(ROLES.items[1])
|
|
66
|
+
apiMocks.delete.mockResolvedValue(undefined)
|
|
67
|
+
apiMocks.post.mockResolvedValue({})
|
|
68
|
+
})
|
|
69
|
+
|
|
70
|
+
describe('RolePermissionsPage', () => {
|
|
71
|
+
it('渲染两个可配置角色与权限矩阵(member 标记已自定义)', async () => {
|
|
72
|
+
renderPage()
|
|
73
|
+
expect(await screen.findByRole('heading', { name: '管理员' })).toBeInTheDocument()
|
|
74
|
+
expect(screen.getByRole('heading', { name: /成员/ })).toBeInTheDocument()
|
|
75
|
+
expect(screen.getByText('已自定义')).toBeInTheDocument()
|
|
76
|
+
// catalog 权限逐项渲染(admin 卡内 + member 卡内各一份)
|
|
77
|
+
expect(screen.getAllByText('roles:manage').length).toBeGreaterThanOrEqual(2)
|
|
78
|
+
})
|
|
79
|
+
|
|
80
|
+
it('勾选并保存 → PUT /api/workspaces/{id}/roles/{role}', async () => {
|
|
81
|
+
renderPage()
|
|
82
|
+
await screen.findByText('管理员')
|
|
83
|
+
// admin 卡内勾选 roles:manage(第一份),保存(第一份按钮)
|
|
84
|
+
const boxes = screen.getAllByRole('checkbox', { name: 'roles:manage' })
|
|
85
|
+
fireEvent.click(boxes[0])
|
|
86
|
+
const save = screen.getAllByRole('button', { name: '保存修改' })[0]
|
|
87
|
+
expect(save).toBeEnabled()
|
|
88
|
+
fireEvent.click(save)
|
|
89
|
+
|
|
90
|
+
await waitFor(() => {
|
|
91
|
+
expect(apiMocks.put).toHaveBeenCalledWith('/api/workspaces/ws-1/roles/admin', {
|
|
92
|
+
perms: ['members:read', 'roles:manage', 'workspace:read'],
|
|
93
|
+
})
|
|
94
|
+
})
|
|
95
|
+
expect(toastMocks.success).toHaveBeenCalled()
|
|
96
|
+
})
|
|
97
|
+
|
|
98
|
+
it('E_REAUTH_REQUIRED → 弹验证对话框 → 确认密码后自动重试原请求', async () => {
|
|
99
|
+
apiMocks.put.mockRejectedValueOnce(
|
|
100
|
+
new ApiError(403, 'E_REAUTH_REQUIRED', 'password confirmation required', {
|
|
101
|
+
max_age_seconds: 900,
|
|
102
|
+
}),
|
|
103
|
+
)
|
|
104
|
+
renderPage()
|
|
105
|
+
await screen.findByText('管理员')
|
|
106
|
+
|
|
107
|
+
const boxes = screen.getAllByRole('checkbox', { name: 'members:read' })
|
|
108
|
+
// member 卡(第二个):取消勾选 members:read(已勾选)→ dirty
|
|
109
|
+
fireEvent.click(boxes[1])
|
|
110
|
+
fireEvent.click(screen.getAllByRole('button', { name: '保存修改' })[1])
|
|
111
|
+
|
|
112
|
+
expect(await screen.findByRole('dialog')).toBeInTheDocument()
|
|
113
|
+
fireEvent.change(await screen.findByLabelText('当前密码'), {
|
|
114
|
+
target: { value: 'correct horse' },
|
|
115
|
+
})
|
|
116
|
+
fireEvent.click(screen.getByRole('button', { name: '验证并继续' }))
|
|
117
|
+
|
|
118
|
+
await waitFor(() => {
|
|
119
|
+
expect(apiMocks.post).toHaveBeenCalledWith('/auth/confirm-password', {
|
|
120
|
+
password: 'correct horse',
|
|
121
|
+
})
|
|
122
|
+
})
|
|
123
|
+
await waitFor(() => {
|
|
124
|
+
expect(apiMocks.put).toHaveBeenCalledTimes(2)
|
|
125
|
+
})
|
|
126
|
+
expect(toastMocks.success).toHaveBeenCalledWith('已验证,操作已重试')
|
|
127
|
+
})
|
|
128
|
+
|
|
129
|
+
it('恢复默认(已自定义角色)→ DELETE 并提示', async () => {
|
|
130
|
+
renderPage()
|
|
131
|
+
await screen.findByText('已自定义')
|
|
132
|
+
fireEvent.click(screen.getByRole('button', { name: '恢复默认' }))
|
|
133
|
+
await waitFor(() => {
|
|
134
|
+
expect(apiMocks.delete).toHaveBeenCalledWith('/api/workspaces/ws-1/roles/member')
|
|
135
|
+
})
|
|
136
|
+
expect(toastMocks.success).toHaveBeenCalled()
|
|
137
|
+
})
|
|
138
|
+
})
|