test(qa): 加入目录规则浏览器回归和暂存门禁
build / build (push) Failing after 7m7s

在 QA 虚拟机通过 Chromium 复跑和本地提交检查,并验证必填校验失效会触发失败。Gitea 将浏览器回归纳入必需检查。
This commit is contained in:
姚章浩
2026-11-22 19:57:24 +08:00
parent d7d636792d
commit 5d00715c3a
18 changed files with 407 additions and 8 deletions
+2
View File
@@ -1,4 +1,6 @@
node_modules/
dist/
test-results/
playwright-report/
*.tsbuildinfo
package-lock.json
+11
View File
@@ -0,0 +1,11 @@
<!doctype html>
<html lang="zh-CN">
<head>
<meta charset="utf-8" />
<title>目录范围规则测试</title>
</head>
<body>
<div id="root"></div>
<script type="module" src="./scope-rules.tsx"></script>
</body>
</html>
+128
View File
@@ -0,0 +1,128 @@
import { expect, test, type Page } from '@playwright/test'
import { document as sample } from '../src/documentFixture'
import type { ScopeRule, ScopeRuleDecision } from '../src/scopeRules'
const cases = [
{ id: 'parent', directory_path: '产品', title: '总览.pdf' },
{ id: 'child', directory_path: '产品/手册', title: '手册.pdf' },
{ id: 'sibling', directory_path: '产品/固件', title: '固件.pdf' },
]
const existing: ScopeRule = {
target_type: 'directory',
connection_id: 'pp-1',
directory_path: '产品',
visibility: 'external',
reason: '父目录已公开',
updated_by: 'QA工程师',
updated_at: sample.updated_at,
}
async function scopeFixture(page: Page, canWrite = true) {
const rules = new Map<string, ScopeRule>([['产品', existing]])
const changes: ScopeRuleDecision[] = []
await page.route('**/*', async (route) => {
const request = route.request()
const url = new URL(request.url())
if (url.hostname !== '127.0.0.1' || url.port !== '4175') return route.abort()
if (url.pathname === '/api/v1/scope-rules') {
if (request.method() === 'GET' && url.searchParams.get('connection_id') === 'pp-1') {
return route.fulfill({ json: { data: [...rules.values()] } })
}
if (request.method() === 'PUT') {
const input = request.postDataJSON() as ScopeRuleDecision
changes.push(input)
if (!canWrite) return route.fulfill({ status: 403, json: { error: 'forbidden' } })
if (
input.target_type !== 'directory' ||
input.connection_id !== 'pp-1' ||
!cases.some((item) => item.directory_path === input.directory_path) ||
!request.headers()['idempotency-key'] ||
!input.reason.trim()
) {
return route.fulfill({ status: 400, json: { error: 'invalid fixture input' } })
}
const rule = { ...existing, ...input }
rules.set(input.directory_path, rule)
return route.fulfill({ json: { data: rule } })
}
}
if (url.pathname === '/api/v1/source-items' && request.method() === 'GET') {
const items = cases.map((item) => {
const rule = rules.get(item.directory_path) ?? rules.get('产品')!
return {
...sample,
...item,
visibility: rule.visibility,
visibility_origin: 'directory_rule',
scope_rule_path: rule.directory_path,
}
})
return route.fulfill({ json: { data: items, summary: { total: items.length }, offset: 0, limit: 100 } })
}
if (url.pathname.startsWith('/api/'))
return route.fulfill({ status: 404, json: { error: 'unexpected fixture request' } })
return route.continue()
})
await page.goto('/e2e/scope-rules.html')
return changes
}
function openDirectory(page: Page, name: string) {
return page
.getByRole('complementary', { name: '来源目录' })
.getByRole('button', { name: new RegExp(`^▸ ${name} \\d+$`) })
.click()
}
async function saveInternal(page: Page) {
const editor = page.getByRole('region', { name: '对内对外范围设置' })
await editor.getByLabel('拟修改为').selectOption('internal')
await expect(editor.getByRole('button', { name: '保存范围' })).toBeDisabled()
await editor.getByLabel('判断原因').fill(' 仅供内部使用 ')
await editor.getByRole('button', { name: '保存范围' }).click()
}
test('编辑器保存目录范围并在刷新后读回', async ({ page }) => {
const changes = await scopeFixture(page)
await openDirectory(page, '产品/手册')
await saveInternal(page)
await expect(page.getByText('当前设置:对内')).toBeVisible()
expect(changes).toEqual([
{
target_type: 'directory',
connection_id: 'pp-1',
directory_path: '产品/手册',
source_item_id: '',
visibility: 'internal',
reason: '仅供内部使用',
},
])
await page.reload()
await openDirectory(page, '产品/手册')
await expect(page.getByText('当前设置:对内')).toBeVisible()
await expect(page.getByRole('row', { name: /手册.pdf/ })).toContainText('继承目录设置:产品/手册')
})
test('编辑器显示只读拒绝并保留原规则', async ({ page }) => {
const changes = await scopeFixture(page, false)
await openDirectory(page, '产品/手册')
await saveInternal(page)
await expect(page.getByRole('alert')).toHaveText('保存范围规则失败(HTTP 403)')
expect(changes).toHaveLength(1)
await page.reload()
await openDirectory(page, '产品/手册')
await expect(page.getByText('当前没有本级设置')).toBeVisible()
await expect(page.getByRole('row', { name: /手册.pdf/ })).toContainText('继承目录设置:产品')
})
test('编辑器刷新并显示子目录规则和兄弟目录的继承来源', async ({ page }) => {
await scopeFixture(page)
await openDirectory(page, '产品/手册')
await saveInternal(page)
await expect(page.getByRole('row', { name: /手册.pdf/ })).toContainText('继承目录设置:产品/手册')
await openDirectory(page, '产品/固件')
const sibling = page.getByRole('row', { name: /固件.pdf/ })
await expect(sibling).toContainText('对外')
await expect(sibling).toContainText('继承目录设置:产品')
})
+4
View File
@@ -0,0 +1,4 @@
import { createRoot } from 'react-dom/client'
import { DocumentWorkbench } from '../src/DocumentWorkbench'
createRoot(document.getElementById('root')!).render(<DocumentWorkbench mode="directory" connections={[]} />)
+4
View File
@@ -0,0 +1,4 @@
import { defineConfig } from 'vite'
import react from '@vitejs/plugin-react'
export default defineConfig({ plugins: [react()], publicDir: false })
+46
View File
@@ -14,6 +14,7 @@
"remark-gfm": "4.0.1"
},
"devDependencies": {
"@playwright/test": "1.65.1",
"@types/react": "19.1.10",
"@types/react-dom": "19.1.7",
"@vitejs/plugin-react": "5.0.1",
@@ -814,6 +815,22 @@
"node": "^22.20 || ^24.12 || >=25"
}
},
"node_modules/@playwright/test": {
"version": "1.65.1",
"resolved": "https://registry.npmjs.org/@playwright/test/-/test-1.65.1.tgz",
"integrity": "sha512-y+NCIRm2LvY4slUVWvGh1nujJ8RF/hEisIsq2mtUPgdQC4L701bq5hZGMhrpeXjACvwvO9tj5dJqhvM6TP9lbw==",
"dev": true,
"license": "Apache-2.0",
"dependencies": {
"playwright": "1.65.1"
},
"bin": {
"playwright": "cli.js"
},
"engines": {
"node": ">=20"
}
},
"node_modules/@rolldown/pluginutils": {
"version": "1.0.0-beta.32",
"resolved": "https://registry.npmjs.org/@rolldown/pluginutils/-/pluginutils-1.0.0-beta.32.tgz",
@@ -2887,6 +2904,35 @@
"url": "https://github.com/sponsors/jonschlinkert"
}
},
"node_modules/playwright": {
"version": "1.65.1",
"resolved": "https://registry.npmjs.org/playwright/-/playwright-1.65.1.tgz",
"integrity": "sha512-vJ1FuoOrNwOKHUIVEvSt3jT1L+wjjDpwhwIstKtfvTh8XIG4FG4bIFuvNdMxi81LGfAhUgUZleVFaOLY4RIUUw==",
"dev": true,
"license": "Apache-2.0",
"dependencies": {
"playwright-core": "1.65.1"
},
"bin": {
"playwright": "cli.js"
},
"engines": {
"node": ">=20"
}
},
"node_modules/playwright-core": {
"version": "1.65.1",
"resolved": "https://registry.npmjs.org/playwright-core/-/playwright-core-1.65.1.tgz",
"integrity": "sha512-hqPpz7blSMPxWVdoeE1yiBSzXsKiVOd2k+kjCvmUywD2GPO2Dd9HfcWnq9NN0GHbNZDFgZ9JfBFr+X5/BLo0qw==",
"dev": true,
"license": "Apache-2.0",
"bin": {
"playwright-core": "cli.js"
},
"engines": {
"node": ">=20"
}
},
"node_modules/postcss": {
"version": "8.5.26",
"resolved": "https://registry.npmjs.org/postcss/-/postcss-8.5.26.tgz",
+3 -1
View File
@@ -5,7 +5,8 @@
"type": "module",
"scripts": {
"dev": "vite --host 0.0.0.0",
"test": "vitest run",
"test": "vitest run --exclude 'e2e/**'",
"test:e2e": "playwright test",
"build": "tsc -b && vite build",
"typecheck": "tsc -b --pretty false",
"format": "prettier --write .",
@@ -18,6 +19,7 @@
"remark-gfm": "4.0.1"
},
"devDependencies": {
"@playwright/test": "1.65.1",
"@types/react": "19.1.10",
"@types/react-dom": "19.1.7",
"@vitejs/plugin-react": "5.0.1",
+23
View File
@@ -0,0 +1,23 @@
import { defineConfig } from '@playwright/test'
export default defineConfig({
testDir: './e2e',
workers: 1,
retries: 0,
forbidOnly: true,
timeout: 15000,
expect: { timeout: 5000 },
use: {
browserName: 'chromium',
baseURL: 'http://127.0.0.1:4175',
serviceWorkers: 'block',
trace: 'retain-on-failure',
screenshot: 'only-on-failure',
},
webServer: {
command: 'vite --config e2e/vite.config.ts --host 127.0.0.1 --port 4175 --strictPort',
url: 'http://127.0.0.1:4175/e2e/scope-rules.html',
reuseExistingServer: false,
timeout: 20000,
},
})
+1 -1
View File
@@ -17,5 +17,5 @@
"jsx": "react-jsx",
"types": ["vitest/globals", "vite/client"]
},
"include": ["src", "vite.config.ts"]
"include": ["src", "e2e", "vite.config.ts", "playwright.config.ts"]
}