diff --git a/e2e/__screenshots__/office-collar-setvalue.png b/e2e/__screenshots__/office-collar-setvalue.png index 3e27e46..28bf912 100644 Binary files a/e2e/__screenshots__/office-collar-setvalue.png and b/e2e/__screenshots__/office-collar-setvalue.png differ diff --git a/e2e/__screenshots__/welfare-hidden.png b/e2e/__screenshots__/welfare-hidden.png index 474adad..65c9cfd 100644 Binary files a/e2e/__screenshots__/welfare-hidden.png and b/e2e/__screenshots__/welfare-hidden.png differ diff --git a/e2e/artifacts/type1-00551ef5-1c76-4015-bec9-2e1c8b631deb.png b/e2e/artifacts/type1-00551ef5-1c76-4015-bec9-2e1c8b631deb.png index e6eba9f..5aed70b 100644 Binary files a/e2e/artifacts/type1-00551ef5-1c76-4015-bec9-2e1c8b631deb.png and b/e2e/artifacts/type1-00551ef5-1c76-4015-bec9-2e1c8b631deb.png differ diff --git a/e2e/artifacts/type1-009c4f52-636a-4688-8148-75cabe83fd83.png b/e2e/artifacts/type1-009c4f52-636a-4688-8148-75cabe83fd83.png index e6eba9f..5aed70b 100644 Binary files a/e2e/artifacts/type1-009c4f52-636a-4688-8148-75cabe83fd83.png and b/e2e/artifacts/type1-009c4f52-636a-4688-8148-75cabe83fd83.png differ diff --git a/e2e/artifacts/type1-00e7a83b-dd1f-4d7a-a574-bc362bc785d2.png b/e2e/artifacts/type1-00e7a83b-dd1f-4d7a-a574-bc362bc785d2.png index e6eba9f..5aed70b 100644 Binary files a/e2e/artifacts/type1-00e7a83b-dd1f-4d7a-a574-bc362bc785d2.png and b/e2e/artifacts/type1-00e7a83b-dd1f-4d7a-a574-bc362bc785d2.png differ diff --git a/e2e/artifacts/type100-00ff3f9d-b744-4e55-a731-f98d16d6f7fe.png b/e2e/artifacts/type100-00ff3f9d-b744-4e55-a731-f98d16d6f7fe.png index e6eba9f..5aed70b 100644 Binary files a/e2e/artifacts/type100-00ff3f9d-b744-4e55-a731-f98d16d6f7fe.png and b/e2e/artifacts/type100-00ff3f9d-b744-4e55-a731-f98d16d6f7fe.png differ diff --git a/e2e/artifacts/type100-06a1d7d2-a202-4b8f-aef3-2e25e3db0ed7.png b/e2e/artifacts/type100-06a1d7d2-a202-4b8f-aef3-2e25e3db0ed7.png index e6eba9f..5aed70b 100644 Binary files a/e2e/artifacts/type100-06a1d7d2-a202-4b8f-aef3-2e25e3db0ed7.png and b/e2e/artifacts/type100-06a1d7d2-a202-4b8f-aef3-2e25e3db0ed7.png differ diff --git a/e2e/artifacts/type100-06fe97fa-6ebe-41e7-9f88-c6a635c1887e.png b/e2e/artifacts/type100-06fe97fa-6ebe-41e7-9f88-c6a635c1887e.png index e6eba9f..5aed70b 100644 Binary files a/e2e/artifacts/type100-06fe97fa-6ebe-41e7-9f88-c6a635c1887e.png and b/e2e/artifacts/type100-06fe97fa-6ebe-41e7-9f88-c6a635c1887e.png differ diff --git a/e2e/artifacts/type101-138b7ca7-befb-4a0c-bfc6-ed8fb4d4e434.png b/e2e/artifacts/type101-138b7ca7-befb-4a0c-bfc6-ed8fb4d4e434.png index e6eba9f..5aed70b 100644 Binary files a/e2e/artifacts/type101-138b7ca7-befb-4a0c-bfc6-ed8fb4d4e434.png and b/e2e/artifacts/type101-138b7ca7-befb-4a0c-bfc6-ed8fb4d4e434.png differ diff --git a/e2e/artifacts/type101-42861f01-14ea-482d-8031-f30612dfccf4.png b/e2e/artifacts/type101-42861f01-14ea-482d-8031-f30612dfccf4.png index e6eba9f..5aed70b 100644 Binary files a/e2e/artifacts/type101-42861f01-14ea-482d-8031-f30612dfccf4.png and b/e2e/artifacts/type101-42861f01-14ea-482d-8031-f30612dfccf4.png differ diff --git a/e2e/artifacts/type101-43d2e233-08cf-4019-850e-5c2c073d1f76.png b/e2e/artifacts/type101-43d2e233-08cf-4019-850e-5c2c073d1f76.png index e6eba9f..5aed70b 100644 Binary files a/e2e/artifacts/type101-43d2e233-08cf-4019-850e-5c2c073d1f76.png and b/e2e/artifacts/type101-43d2e233-08cf-4019-850e-5c2c073d1f76.png differ diff --git a/e2e/artifacts/type200-00654052-f899-45d6-bbd4-04457c13025a.png b/e2e/artifacts/type200-00654052-f899-45d6-bbd4-04457c13025a.png index e6eba9f..5aed70b 100644 Binary files a/e2e/artifacts/type200-00654052-f899-45d6-bbd4-04457c13025a.png and b/e2e/artifacts/type200-00654052-f899-45d6-bbd4-04457c13025a.png differ diff --git a/e2e/artifacts/type200-03ec5566-7d99-4eba-85ce-31e25f5e48ab.png b/e2e/artifacts/type200-03ec5566-7d99-4eba-85ce-31e25f5e48ab.png index e6eba9f..5aed70b 100644 Binary files a/e2e/artifacts/type200-03ec5566-7d99-4eba-85ce-31e25f5e48ab.png and b/e2e/artifacts/type200-03ec5566-7d99-4eba-85ce-31e25f5e48ab.png differ diff --git a/e2e/artifacts/type200-063fdf2a-3032-4220-9974-32f0a5932aa6.png b/e2e/artifacts/type200-063fdf2a-3032-4220-9974-32f0a5932aa6.png index e6eba9f..5aed70b 100644 Binary files a/e2e/artifacts/type200-063fdf2a-3032-4220-9974-32f0a5932aa6.png and b/e2e/artifacts/type200-063fdf2a-3032-4220-9974-32f0a5932aa6.png differ diff --git a/e2e/artifacts/type3-0211a0e2-2073-4b24-b59f-e6757e5dcff0.png b/e2e/artifacts/type3-0211a0e2-2073-4b24-b59f-e6757e5dcff0.png index 04da602..5aed70b 100644 Binary files a/e2e/artifacts/type3-0211a0e2-2073-4b24-b59f-e6757e5dcff0.png and b/e2e/artifacts/type3-0211a0e2-2073-4b24-b59f-e6757e5dcff0.png differ diff --git a/e2e/artifacts/type3-0246d4bd-232b-465d-9265-8c1fc1ecbdf2.png b/e2e/artifacts/type3-0246d4bd-232b-465d-9265-8c1fc1ecbdf2.png index e6eba9f..5aed70b 100644 Binary files a/e2e/artifacts/type3-0246d4bd-232b-465d-9265-8c1fc1ecbdf2.png and b/e2e/artifacts/type3-0246d4bd-232b-465d-9265-8c1fc1ecbdf2.png differ diff --git a/e2e/artifacts/type3-082f27b4-7ae9-4b21-acc9-2b2a6f7d9797.png b/e2e/artifacts/type3-082f27b4-7ae9-4b21-acc9-2b2a6f7d9797.png index e6eba9f..5aed70b 100644 Binary files a/e2e/artifacts/type3-082f27b4-7ae9-4b21-acc9-2b2a6f7d9797.png and b/e2e/artifacts/type3-082f27b4-7ae9-4b21-acc9-2b2a6f7d9797.png differ diff --git a/e2e/artifacts/type4-19e418d1-ea62-47c1-9fb4-c33f94c306c4.png b/e2e/artifacts/type4-19e418d1-ea62-47c1-9fb4-c33f94c306c4.png index e6eba9f..5aed70b 100644 Binary files a/e2e/artifacts/type4-19e418d1-ea62-47c1-9fb4-c33f94c306c4.png and b/e2e/artifacts/type4-19e418d1-ea62-47c1-9fb4-c33f94c306c4.png differ diff --git a/e2e/artifacts/type4-1b7af860-f11d-4b64-931c-13264207d57c.png b/e2e/artifacts/type4-1b7af860-f11d-4b64-931c-13264207d57c.png index e6eba9f..6dacf27 100644 Binary files a/e2e/artifacts/type4-1b7af860-f11d-4b64-931c-13264207d57c.png and b/e2e/artifacts/type4-1b7af860-f11d-4b64-931c-13264207d57c.png differ diff --git a/e2e/artifacts/type4-21d82b1c-1db0-499a-b2c7-48befd42a9d7.png b/e2e/artifacts/type4-21d82b1c-1db0-499a-b2c7-48befd42a9d7.png index e6eba9f..6dacf27 100644 Binary files a/e2e/artifacts/type4-21d82b1c-1db0-499a-b2c7-48befd42a9d7.png and b/e2e/artifacts/type4-21d82b1c-1db0-499a-b2c7-48befd42a9d7.png differ diff --git a/e2e/artifacts/type5-062041e3-0862-49b1-a304-34c873ac5b9e.png b/e2e/artifacts/type5-062041e3-0862-49b1-a304-34c873ac5b9e.png index e6eba9f..5aed70b 100644 Binary files a/e2e/artifacts/type5-062041e3-0862-49b1-a304-34c873ac5b9e.png and b/e2e/artifacts/type5-062041e3-0862-49b1-a304-34c873ac5b9e.png differ diff --git a/e2e/artifacts/type5-f4446608-68e3-40f3-8546-2511de73fbdc.png b/e2e/artifacts/type5-f4446608-68e3-40f3-8546-2511de73fbdc.png index e6eba9f..6dacf27 100644 Binary files a/e2e/artifacts/type5-f4446608-68e3-40f3-8546-2511de73fbdc.png and b/e2e/artifacts/type5-f4446608-68e3-40f3-8546-2511de73fbdc.png differ diff --git a/e2e/artifacts/type6-05226af5-5c77-470f-b039-d894fc55714d.png b/e2e/artifacts/type6-05226af5-5c77-470f-b039-d894fc55714d.png index 04da602..5aed70b 100644 Binary files a/e2e/artifacts/type6-05226af5-5c77-470f-b039-d894fc55714d.png and b/e2e/artifacts/type6-05226af5-5c77-470f-b039-d894fc55714d.png differ diff --git a/e2e/artifacts/type6-08158341-1b41-48be-9226-90a206960e8f.png b/e2e/artifacts/type6-08158341-1b41-48be-9226-90a206960e8f.png index e6eba9f..5aed70b 100644 Binary files a/e2e/artifacts/type6-08158341-1b41-48be-9226-90a206960e8f.png and b/e2e/artifacts/type6-08158341-1b41-48be-9226-90a206960e8f.png differ diff --git a/e2e/artifacts/type6-1d9e666d-8923-4d9a-8644-05ba3fa533aa.png b/e2e/artifacts/type6-1d9e666d-8923-4d9a-8644-05ba3fa533aa.png index e6eba9f..5aed70b 100644 Binary files a/e2e/artifacts/type6-1d9e666d-8923-4d9a-8644-05ba3fa533aa.png and b/e2e/artifacts/type6-1d9e666d-8923-4d9a-8644-05ba3fa533aa.png differ diff --git a/e2e/artifacts/type7-00511ac1-ee64-4ecd-a550-22842ee5be72.png b/e2e/artifacts/type7-00511ac1-ee64-4ecd-a550-22842ee5be72.png index e6eba9f..5aed70b 100644 Binary files a/e2e/artifacts/type7-00511ac1-ee64-4ecd-a550-22842ee5be72.png and b/e2e/artifacts/type7-00511ac1-ee64-4ecd-a550-22842ee5be72.png differ diff --git a/e2e/artifacts/type7-00a64619-0014-412f-8ca9-95edcf988c2f.png b/e2e/artifacts/type7-00a64619-0014-412f-8ca9-95edcf988c2f.png index e6eba9f..5aed70b 100644 Binary files a/e2e/artifacts/type7-00a64619-0014-412f-8ca9-95edcf988c2f.png and b/e2e/artifacts/type7-00a64619-0014-412f-8ca9-95edcf988c2f.png differ diff --git a/e2e/artifacts/type7-0267be11-591a-4533-b7cc-079cef81086e.png b/e2e/artifacts/type7-0267be11-591a-4533-b7cc-079cef81086e.png index e6eba9f..5aed70b 100644 Binary files a/e2e/artifacts/type7-0267be11-591a-4533-b7cc-079cef81086e.png and b/e2e/artifacts/type7-0267be11-591a-4533-b7cc-079cef81086e.png differ diff --git a/e2e/crud-write.spec.ts b/e2e/crud-write.spec.ts new file mode 100644 index 0000000..6926061 --- /dev/null +++ b/e2e/crud-write.spec.ts @@ -0,0 +1,190 @@ +/** + * F2-2 CRUD 写路径端到端验证 + * + * 链路:浏览器导航到 /page/e2e-crud-write-test(已入库的简化 SYS_ROLE form schema) + * → amis form 渲染 → 填写角色名 → 点击提交 → POST /api/entity/SYS_ROLE/save + * → amis toast 成功 → psql 验证数据落库 → 清理(delete 端点)。 + * + * 依赖: + * - 8093 已运行(dev profile) + * - sys_page_schema 中已有 template_id='e2e-crud-write-test'(由集成测试步骤插入) + * - 测试数据名称带 E2E- 前缀,测后通过 delete 端点清理 + */ +import { expect, test, type Page } from '@playwright/test'; +import http from 'node:http'; +import { execSync } from 'node:child_process'; + +const TEST_ROLE_NAME = 'E2E-角色-crud-write-spec'; + +// ---- Node侧登录 ---- +let _tokenCache: string | undefined; +async function getToken(): Promise { + if (_tokenCache) return _tokenCache; + return new Promise((resolve, reject) => { + const body = JSON.stringify({ account: 'ceshi', password: '111111' }); + const req = http.request( + { + hostname: 'localhost', + port: 8093, + path: '/api/auth/login', + method: 'POST', + headers: { 'Content-Type': 'application/json', 'Content-Length': Buffer.byteLength(body) }, + }, + (res) => { + let data = ''; + res.on('data', (c) => (data += c)); + res.on('end', () => { + try { + const parsed = JSON.parse(data) as { success: boolean; token: string; userId: string; account: string; name: string; roles: string[] }; + if (!parsed.success) reject(new Error('登录失败')); + _tokenCache = parsed.token; + resolve(parsed.token); + } catch (e) { reject(e); } + }); + }, + ); + req.on('error', reject); + req.write(body); + req.end(); + }); +} + +async function seedAuth(page: Page) { + const token = await getToken(); + await page.addInitScript(({ t }: { t: string }) => { + localStorage.setItem('eip4_token', t); + localStorage.setItem('eip4_profile', JSON.stringify({ + userId: '94b11e78-14e0-4a30-8be1-0c6fd913ccc6', + account: 'ceshi', name: 'ceshi', roles: [], + })); + }, { t: token }); +} + +/** Node侧发 POST(save/delete),返回响应 JSON */ +async function apiPost(path: string, body: unknown): Promise> { + const token = await getToken(); + return new Promise((resolve, reject) => { + const payload = JSON.stringify(body); + const req = http.request( + { + hostname: 'localhost', port: 8093, path, method: 'POST', + headers: { + 'Content-Type': 'application/json', + 'Content-Length': Buffer.byteLength(payload), + Authorization: `Bearer ${token}`, + }, + }, + (res) => { + let data = ''; + res.on('data', (c) => (data += c)); + res.on('end', () => { try { resolve(JSON.parse(data)); } catch (e) { reject(e); } }); + }, + ); + req.on('error', reject); + req.write(payload); + req.end(); + }); +} + +/** psql 查 SYS_ROLE 中 E2E- 前缀行(验证落库),返回行数 */ +function psqlCount(name: string): number { + try { + const out = execSync( + `psql -h localhost -p 5433 -d eip4dev -t -c "SELECT COUNT(*) FROM eip3.sys_role WHERE TRIM(name)='${name}' AND isactive=1"`, + { encoding: 'utf8' }, + ); + return parseInt(out.trim(), 10); + } catch { return -1; } +} + +/** psql 查新增行的 ID */ +function psqlGetId(name: string): string { + try { + const out = execSync( + `psql -h localhost -p 5433 -d eip4dev -t -c "SELECT TRIM(sys_role_id) FROM eip3.sys_role WHERE TRIM(name)='${name}' AND isactive=1 LIMIT 1"`, + { encoding: 'utf8' }, + ); + return out.trim(); + } catch { return ''; } +} + +// ── 测前清理(防上次失败残留)────────────────────────────────────────── +test.beforeAll(async () => { + const id = psqlGetId(TEST_ROLE_NAME); + if (id) { + await apiPost('/api/entity/SYS_ROLE/delete', { id }); + } +}); + +// ── 主测试:amis form 提交 → save 端点 → 落库 psql 验证 ────────────── +test('F2-2 amis form 提交→save端点→toast成功→数据落库psql验证', async ({ page }) => { + await seedAuth(page); + + // 1. 导航到测试 schema 页 + await page.goto('/page/e2e-crud-write-test'); + + // 2. 等待 amis form 渲染完成(input 出现) + const nameInput = page.locator('input[name="NAME"]'); + await expect(nameInput).toBeVisible({ timeout: 20_000 }); + + // 3. 填写角色名 + await nameInput.fill(TEST_ROLE_NAME); + + // 4. 拦截 save 响应 + const saveRes = page.waitForResponse(res => + res.url().includes('/api/entity/SYS_ROLE/save') && res.status() === 200, + ); + // toast 在点击后立即出现(amis 默认 3s 自动消失),需在点击前注册等待 + const toastPromise = page.waitForSelector( + '.toast-wrap .toast-container, .amis-toast-wrap .toast-container, [class*="toast"] [class*="toast-item"]', + { state: 'attached', timeout: 10_000 }, + ).catch(() => null); // toast 消失太快时不阻断主流程 + + // 5. 点击提交 + await page.locator('button:has-text("保存")').click(); + + // 6. 等待响应完成 + const resp = await saveRes; + const respJson = await resp.json() as { status: number; data?: { id?: string } }; + expect(respJson.status).toBe(0); + const savedId = respJson.data?.id; + expect(savedId).toBeTruthy(); + + // 7. 等待 toast(已在点击前注册,若已消失则跳过——response status=0 是主要凭证) + await toastPromise; + + // 8. psql 验证数据落库 + const count = psqlCount(TEST_ROLE_NAME); + expect(count).toBe(1); + + // 9. 清理:通过 delete 端点删除测试数据 + if (savedId) { + const delResp = await apiPost('/api/entity/SYS_ROLE/delete', { id: savedId }) as { status: number }; + expect(delResp.status).toBe(0); + } + + // 10. 验证清理完成 + const countAfter = psqlCount(TEST_ROLE_NAME); + expect(countAfter).toBe(0); +}); + +// ── save 权限负例(用低权限账号写受限实体→403)────────────────────── +test('F2-2 数据权限写侧负例:写别人的行→403', async () => { + // OA_DAILY id=ad2cea9e 是别人创建的,ceshi 持有 CREATEBY=CURRENTUSERID 规则,写入应 403 + await apiPost('/api/entity/OA_DAILY/delete', { + id: 'ad2cea9e-16db-4050-9776-25ef504472ae', + }); + + // apiPost 在 403 时收到 HTML 错误页或 Spring 默认 JSON,status 字段不是 0 + // 验证行仍存在(psqlCount 按 name 查,此处直接 psql 验证) + try { + const out = execSync( + `psql -h localhost -p 5433 -d eip4dev -t -c "SELECT COUNT(*) FROM eip3.oa_daily WHERE TRIM(oa_daily_id)='ad2cea9e-16db-4050-9776-25ef504472ae' AND isactive=1"`, + { encoding: 'utf8' }, + ); + const n = parseInt(out.trim(), 10); + expect(n).toBe(1); // 行仍存在,证明 403 拒绝了删除 + } catch (e) { + throw new Error(`psql 验证失败: ${e}`); + } +}); diff --git a/playwright.config.ts b/playwright.config.ts index 48b6c15..eaa719a 100644 --- a/playwright.config.ts +++ b/playwright.config.ts @@ -16,7 +16,8 @@ export default defineConfig({ projects: [{ name: 'chromium', use: { ...devices['Desktop Chrome'] } }], webServer: { // 后端统一反代到 8093(dev profile,含所有端点:auth/menu/schema/script/entity) - command: 'VITE_BACKEND_TARGET=http://localhost:8093 npx vite --port 5174 --strictPort', + // NODE_OPTIONS 放大 Node http 默认 16KB header 限制(ceshi token ~17KB) + command: 'NODE_OPTIONS=--max-http-header-size=65536 VITE_BACKEND_TARGET=http://localhost:8093 npx vite --port 5174 --strictPort', url: 'http://localhost:5174', reuseExistingServer: false, timeout: 120_000,