test(e2e): 前后台联调 Playwright 与 admin 冒烟
ci / h5 (push) Canceled after 0s
ci / api (push) Canceled after 0s
ci / ess-docs (push) Canceled after 0s

新增 e2e-live 真 API 一致性全路径,并为 admin-h5 增加 mock 浏览器冒烟。

Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
jackyu66git
2026-08-06 22:41:43 +08:00
co-authored by Cursor
parent 879bf70cb7
commit 7e9023f0a8
12 changed files with 400 additions and 1 deletions
+104
View File
@@ -0,0 +1,104 @@
import { test, expect } from '@playwright/test'
/** Admin Phase A: login → users → detail grant → audit (API mocked). */
test('admin login users grant and audit with mocked API', async ({ page }) => {
const userId = '11111111-1111-1111-1111-111111111111'
let granted = false
await page.route('**/api/v1/admin/**', async (route) => {
const req = route.request()
const url = req.url()
const method = req.method()
const ok = (data: unknown) =>
route.fulfill({
status: 200,
contentType: 'application/json',
body: JSON.stringify({ code: 0, message: 'success', data }),
})
if (url.includes('/auth/login') && method === 'POST') {
await ok({
token: 'adm_e2e_token',
expires_at: new Date(Date.now() + 3600_000).toISOString(),
admin: { id: 'aaaaaaaa-aaaa-aaaa-aaaa-aaaaaaaaaaaa', username: 'admin' },
})
return
}
if (url.includes('/auth/logout') && method === 'POST') {
await ok({ ok: true })
return
}
if (url.endsWith('/me') || url.includes('/me?')) {
await ok({ id: 'aaaaaaaa-aaaa-aaaa-aaaa-aaaaaaaaaaaa', username: 'admin' })
return
}
if (url.includes(`/users/${userId}/membership/grant`) && method === 'POST') {
granted = true
await ok({ ok: true })
return
}
if (url.includes(`/users/${userId}`) && method === 'GET') {
await ok({
id: userId,
status: 'active',
created_at: '2026-08-01T00:00:00Z',
profiles: [{ id: 'p1', relation: 'self', display_name: '我' }],
membership: {
active: granted,
plan: granted ? 'month' : undefined,
status: granted ? 'active' : 'none',
expires_at: granted ? '2026-09-01T00:00:00Z' : undefined,
},
recent_orders: [],
})
return
}
if (url.includes('/users') && method === 'GET') {
await ok({
items: [{ id: userId, status: 'active', created_at: '2026-08-01T00:00:00Z' }],
})
return
}
if (url.includes('/orders')) {
await ok({ items: [] })
return
}
if (url.includes('/audit-logs')) {
await ok({
items: granted
? [
{
id: 'aud1',
admin_id: 'aaaaaaaa-aaaa-aaaa-aaaa-aaaaaaaaaaaa',
action: 'membership.grant',
target_type: 'user',
target_id: userId,
meta: { plan: 'month' },
created_at: '2026-08-06T00:00:00Z',
},
]
: [],
})
return
}
await ok({})
})
await page.goto('/login')
await expect(page.getByRole('heading', { name: '运营后台' })).toBeVisible()
await page.locator('input[type="password"]').fill('change-me')
await page.getByRole('button', { name: '登录' }).click()
await expect(page.getByRole('heading', { name: '用户' })).toBeVisible()
await expect(page.getByText(userId)).toBeVisible()
await page.getByRole('link', { name: userId }).click()
await expect(page.getByRole('heading', { name: '用户详情' })).toBeVisible()
await page.getByRole('button', { name: '授予 / 延长' }).click()
await expect(page.getByText('已授予')).toBeVisible()
await page.getByRole('link', { name: '审计' }).click()
await expect(page.getByRole('heading', { name: '审计' })).toBeVisible()
await expect(page.getByText('membership.grant')).toBeVisible()
})
+3 -1
View File
@@ -8,7 +8,8 @@
"dev": "vite",
"build": "vue-tsc --noEmit && vite build",
"typecheck": "vue-tsc --noEmit",
"preview": "vite preview"
"preview": "vite preview",
"test:e2e": "playwright test"
},
"dependencies": {
"pinia": "^2.3.0",
@@ -16,6 +17,7 @@
"vue-router": "^4.5.0"
},
"devDependencies": {
"@playwright/test": "^1.50.1",
"@vitejs/plugin-vue": "^5.2.1",
"typescript": "~5.7.2",
"vite": "^6.0.7",
+31
View File
@@ -0,0 +1,31 @@
import { defineConfig, devices } from '@playwright/test'
/**
* Ops admin L3 smoke: Vite preview + mocked /api/v1/admin (no Go required).
* Run: npm run test:e2e -w @yuxingu/admin-h5
*/
export default defineConfig({
testDir: './e2e',
fullyParallel: true,
forbidOnly: !!process.env.CI,
retries: process.env.CI ? 1 : 0,
use: {
baseURL: 'http://127.0.0.1:4174',
trace: 'on-first-retry',
},
projects: [
{
name: 'chromium',
use: {
...devices['Desktop Chrome'],
...(process.env.PW_CHANNEL ? { channel: process.env.PW_CHANNEL } : {}),
},
},
],
webServer: {
command: 'npm run build && npm run preview -- --host 127.0.0.1 --port 4174',
url: 'http://127.0.0.1:4174',
reuseExistingServer: false,
timeout: 120_000,
},
})