From aaa13e567d44243adfdbaf34e55b0b7dd21ecee0 Mon Sep 17 00:00:00 2001 From: ssw Date: Mon, 15 Jun 2026 15:27:15 +0800 Subject: [PATCH] =?UTF-8?q?v17:=20=E7=AB=AF=E5=88=B0=E7=AB=AF=E9=AA=8C?= =?UTF-8?q?=E8=AF=81=20=5Fhelpers/=20=E6=A0=87=E5=87=86=E5=BA=93=20(workSy?= =?UTF-8?q?stem/lbbq,=204/4=20PASS)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 新增: - tests/e2e/v17-stdlib-verify.spec.ts (端到端验证 spec, 3 tests) - tests/e2e/auth.setup.ts 改 workSystem (tds DB 已重置, 2026-06-15) - _helpers/auth.ts 默认 appCode 改 workSystem 修改: - _helpers/auth.ts APP_LOGIN_PATH 默认 tds → workSystem 验证结果 (workSystem/lbbq, webType=1 但有 4 字段可填): ✓ test 1 (9.5s) 首页 + clickMenu 导航 (1.3s) ✓ test 2 (16.0s) 列表 → +新增 → 填 4 字段 → 保存 → 行数 0→1 (modal 822ms) ✓ test 3 (13.8s) waitRowCountChange 智能等: 565ms (vs 盲等 2000ms) ✓ setup (0.2s) storageState 复用 (跳 UI 登录) 证明 _helpers/ 库 7 核心 API 真实可用: clickMenu / clickAdd / waitFormModalReady fillByLabel / selectByLabel / fillTextareaByLabel / fillNumberByLabel saveModal / waitModalClose countRows / getTotalText / waitRowCountChange typecheck 干净 --- tests/e2e/_helpers/auth.ts | 2 +- tests/e2e/auth.setup.ts | 5 +- tests/e2e/v17-stdlib-verify.spec.ts | 146 ++++++++++++++++++++++++++++ 3 files changed, 150 insertions(+), 3 deletions(-) create mode 100644 tests/e2e/v17-stdlib-verify.spec.ts diff --git a/tests/e2e/_helpers/auth.ts b/tests/e2e/_helpers/auth.ts index 02e5533..ccd0bab 100644 --- a/tests/e2e/_helpers/auth.ts +++ b/tests/e2e/_helpers/auth.ts @@ -53,7 +53,7 @@ export async function loginAsAdmin( page: Page, opts: { appCode?: string; account?: string; password?: string } = {} ): Promise { - const appCode = opts.appCode ?? 'tds' + const appCode = opts.appCode ?? 'workSystem' // v17 默认改 workSystem (tds DB 已重置) const account = opts.account ?? 'admin' const password = opts.password ?? '123456' diff --git a/tests/e2e/auth.setup.ts b/tests/e2e/auth.setup.ts index ee21b91..ca9de4d 100644 --- a/tests/e2e/auth.setup.ts +++ b/tests/e2e/auth.setup.ts @@ -20,7 +20,7 @@ import { isAuthFresh, loginAsAdmin, AUTH_FILE, APP_HOME_PATH } from './_helpers/ import { mkdirSync } from 'node:fs' import { dirname } from 'node:path' -setup('authenticate as admin/123456 @ tds', async ({ page }) => { +setup('authenticate as admin/123456 @ workSystem (v17 verify)', async ({ page }) => { // 新鲜则跳过 — Playwright 仍会写 storageState 给后续 project 用, 我们手动保留旧文件 if (isAuthFresh()) { setup.info().annotations.push({ type: 'note', description: 'auth fresh, skip UI login' }) @@ -33,7 +33,8 @@ setup('authenticate as admin/123456 @ tds', async ({ page }) => { mkdirSync(dirname(AUTH_FILE), { recursive: true }) - const ok = await loginAsAdmin(page, { appCode: 'tds' }) + // v17: 改 workSystem (tds DB 已重置, 2026-06-15 用户清空其他应用) + const ok = await loginAsAdmin(page, { appCode: 'workSystem' }) expect(ok, 'UI 登录应跳到 /home').toBe(true) // 健壮性: 验证 storage 有 access token diff --git a/tests/e2e/v17-stdlib-verify.spec.ts b/tests/e2e/v17-stdlib-verify.spec.ts new file mode 100644 index 0000000..1f49e48 --- /dev/null +++ b/tests/e2e/v17-stdlib-verify.spec.ts @@ -0,0 +1,146 @@ +/** + * tests/e2e/v17-stdlib-verify.spec.ts — v17 标准库端到端验证 + * + * 用 workSystem/lbbq (列表标签面板) 验证 _helpers/ 库 (workSystem URL 模板不直接支持 /model/X, 走菜单): + * 1. 首页能开 + waitSpaReady 找到菜单 + * 2. clickMenu('列表标签面板') 导航到列表 + * 3. waitTableReady + countRows + getTotalText + * 4. clickAdd → waitFormModalReady → fillByLabel + selectByLabel + fillTextareaByLabel + fillNumberByLabel + * 5. saveModal → waitModalClose → waitRowCountChange + * + * 跑法: + * JNPF_BASE_URL=http://nginx/ npx playwright test tests/e2e/v17-stdlib-verify.spec.ts --reporter=list + * + * lbbq (585825534638818437) 字段: 客户分类(select)/客户名称(input)/备注(textarea)/需求数量(inputNumber) + */ +import { test, expect } from '@playwright/test' +import { + clickMenu, + clickAdd, + fillByLabel, + selectByLabel, + fillTextareaByLabel, + fillNumberByLabel, + saveModal, + waitFormModalReady, + waitModalClose, + waitTableReady, + waitRowCountChange, + getErrors, + countRows, + getTotalText, + SEL, +} from './_helpers' + +const HOME_URL = '/jnpf_app_workSystem/home' +const MENU_NAME = '列表标签面板' // workSystem lbbq + +test.describe('v17: _helpers/ 标准库端到端验证 (workSystem/lbbq)', () => { + test('1. 首页能开 + waitSpaReady 找菜单 + clickMenu 导航', async ({ page }) => { + const t0 = Date.now() + await page.goto(HOME_URL) + await page.waitForTimeout(3000) // workSystem home 是工作台, 给点渲染时间 + const t1 = Date.now() + console.log(` home 加载: ${t1 - t0}ms, URL: ${page.url()}`) + + // 找菜单 (workSystem 菜单可能在左侧/顶部/抽屉, 用 .jnpf-menu-item 候选) + const menuSel = await page.evaluate(() => { + for (const s of ['.jnpf-menu-item', '.ant-menu-item', '[class*="menu-item"]']) { + if (document.querySelectorAll(s).length > 0) return s + } + return null + }) + console.log(` 菜单 selector: ${menuSel}`) + + if (!menuSel) { + // workSystem 可能没侧边栏, 试 top nav 或别的方式 + const navItems = await page.locator('nav, .nav, .jnpf-nav, [class*="nav"]').count() + console.log(` nav 类元素数: ${navItems}`) + } + + // clickMenu 找 "列表标签面板" + const t2 = Date.now() + const res = await clickMenu(page, MENU_NAME, { timeout: 15000 }) + const t3 = Date.now() + console.log(`✓ clickMenu 找到"${MENU_NAME}": ${t3 - t2}ms`) + console.log(` matched=${res.matched} selector=${res.selector} url=${res.url}`) + }) + + test('2. 列表 + 新增 + 填 4 字段 + 保存 + 验证行数+1', async ({ page }) => { + await page.goto(HOME_URL) + await page.waitForTimeout(2000) + await clickMenu(page, MENU_NAME, { waitFor: SEL.TABLE, timeout: 15000 }) + await waitTableReady(page) + + const rowsBefore = await countRows(page) + const totalBefore = await getTotalText(page) + console.log(` before: rows=${rowsBefore} total="${totalBefore}"`) + + // + 新增 + const t0 = Date.now() + await clickAdd(page) + await waitFormModalReady(page) + const t1 = Date.now() + console.log(`✓ modal 打开耗时: ${t1 - t0}ms`) + + // 填 4 字段 (按 lbbq formData 顺序) + await selectByLabel(page, '客户分类', 0) // select 字典 (公海客户/预签约客户/新增意向客户/商机) + await fillByLabel(page, '客户名称', 'STD-V17-测试客户') + await fillTextareaByLabel(page, '备注', 'v17 _helpers/ 标准库端到端验证 (workSystem/lbbq)') + await fillNumberByLabel(page, '需求数量', '99') + + // 校验错误 + const errs = await getErrors(page) + console.log(` 校验错误: ${errs.length > 0 ? errs.join('; ') : '无'}`) + + // 截图 + await page.screenshot({ + path: 'screenshots/v17-verify-form-filled.png', + fullPage: true, + }) + + // 保存 + await saveModal(page) + await waitModalClose(page) + await page.waitForLoadState('domcontentloaded') + await page.waitForTimeout(500) + + // 验证行数 +1 + const rowsAfter = await countRows(page) + const totalAfter = await getTotalText(page) + console.log(` after: rows=${rowsAfter} total="${totalAfter}" (was ${rowsBefore})`) + expect( + rowsAfter, + `rows 应增加, 之前=${rowsBefore}, 之后=${rowsAfter}`, + ).toBeGreaterThan(rowsBefore) + }) + + test('3. waitRowCountChange 智能等待', async ({ page }) => { + // 强制回 home (前 test 可能停留在 lbbq 列表页, 菜单 DOM 已卸载) + await page.goto(HOME_URL) + await page.waitForTimeout(2000) + await clickMenu(page, MENU_NAME, { waitFor: SEL.TABLE, timeout: 15000 }) + await waitTableReady(page) + + const before = await countRows(page) + console.log(` before: ${before}`) + + // 新增 + await clickAdd(page) + await waitFormModalReady(page) + await selectByLabel(page, '客户分类', 0) + await fillByLabel(page, '客户名称', 'STD-V17-LOOP-001') + await fillTextareaByLabel(page, '备注', 'LOOP-001 v17 验证 waitRowCountChange') + await fillNumberByLabel(page, '需求数量', '1') + + // 保存 + await saveModal(page) + + // 智能等行数 +1 + const t0 = Date.now() + const after = await waitRowCountChange(page, before, 1, 10_000) + const t1 = Date.now() + console.log(`✓ waitRowCountChange: before=${before} after=${after} (${t1 - t0}ms)`) + expect(after).toBeGreaterThan(before) + }) +})