e2e: 通知页强断言用例(组件真实性 + ceshi 菜单端到端)
notice-reality:分页真换页/过滤共存/人员列姓名/富文本编辑器渲染/单确认/查看只读 逐条强断言(取代"弹窗能开=通过"的弱断言);notice-ceshi-menu:ceshi 真实登录从 菜单进通知管理端到端。 Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
This commit is contained in:
488
e2e/notice-ceshi-menu.spec.ts
Normal file
488
e2e/notice-ceshi-menu.spec.ts
Normal file
@@ -0,0 +1,488 @@
|
|||||||
|
/**
|
||||||
|
* 通知管理「真·端到端浏览器验证」E2E —— ceshi 账号 · 真实 UI 登录 + 从菜单点进去
|
||||||
|
* ============================================================================
|
||||||
|
* 本 spec 的存在意义:补齐 notice-reality.spec.ts 一直绕过的「菜单导航」环节。
|
||||||
|
* - notice-reality:seedAuth 注入 token + page.goto('/page/e732c4b0…') 直连 URL,
|
||||||
|
* 完全绕过登录表单与左侧菜单 ⇒ 「菜单能不能点进去」从未被真正验证。
|
||||||
|
* - 本 spec:必须 真实填写登录表单(ceshi/111111)+提交 → 从左侧菜单
|
||||||
|
* 「信息站 > 通知管理 > 通知管理(叶子)」逐级展开并点击 → 断言打开列表页 Tab
|
||||||
|
* 并渲染出真实数据(266 条那批)。这一步若不通,就是要抓的前端导航 bug。
|
||||||
|
*
|
||||||
|
* 为什么用 ceshi 而非 admin:
|
||||||
|
* admin 看不到「信息站 > 通知管理」菜单;ceshi 多角色可见。
|
||||||
|
* (历史坑:sysadmin e2e 会把 ceshi 临时停用 isactive=0,中途死会留停用态。
|
||||||
|
* 本 spec 在 beforeAll 自动检测并置回 isactive=1,避免登录被后端拦。)
|
||||||
|
*
|
||||||
|
* 步骤(每步截图,artifacts/notice-ceshi-menu/):
|
||||||
|
* 01-login-workbench 真实表单登录 ceshi/111111 → 进工作台
|
||||||
|
* 02-menu-tree 展开「信息站 > 通知管理」,断言菜单可见「通知管理」叶子
|
||||||
|
* 03-list-via-menu 从菜单点「通知管理」叶子 → 断言 URL/Tab 切到列表页 + 数据渲染
|
||||||
|
* 04-pagination 翻第 2 页,首行 ≠ 第 1 页
|
||||||
|
* 05-person-col 拟稿人列显示姓名(非 GUID/纯工号)
|
||||||
|
* 06a/06b/06c 添加弹窗:富文本 / 接收人带姓名选项 / 确认取消各一
|
||||||
|
* 07-view-readonly 查看弹窗只读回显(非死桩)
|
||||||
|
*
|
||||||
|
* 环境(都在跑,勿重启):前端 5173 / 后端 8093 / psql 5433。
|
||||||
|
* 列表叶子 templateId = e732c4b0-2402-4e73-8cc4-786c8a8c52af。
|
||||||
|
*/
|
||||||
|
import { expect, test, type Page, type Locator } from '@playwright/test';
|
||||||
|
import { execSync } from 'node:child_process';
|
||||||
|
import * as path from 'node:path';
|
||||||
|
import { fileURLToPath } from 'node:url';
|
||||||
|
|
||||||
|
const __filename = fileURLToPath(import.meta.url);
|
||||||
|
const __dirname = path.dirname(__filename);
|
||||||
|
|
||||||
|
const ACCOUNT = 'ceshi';
|
||||||
|
const PASSWORD = '111111';
|
||||||
|
const NOTICE_LEAF_TEMPLATE_ID = 'e732c4b0-2402-4e73-8cc4-786c8a8c52af';
|
||||||
|
const NOTICE_PAGE_PATH = `/page/${NOTICE_LEAF_TEMPLATE_ID}`;
|
||||||
|
const ARTIFACTS = path.join(__dirname, 'artifacts', 'notice-ceshi-menu');
|
||||||
|
|
||||||
|
// 每个用例都独立「真实登录 + 菜单导航」后再断言一个点,互不依赖。
|
||||||
|
// 故意【不用 serial】:serial 下首个用例失败会跳过其余,掩盖其他点的真实结论;
|
||||||
|
// 用 default(workers=1 顺序跑) 让 6 点逐条独立给出 通过/失败,不放水不互相掩盖。
|
||||||
|
test.describe.configure({ mode: 'default' });
|
||||||
|
|
||||||
|
// ── psql(仅用于 ceshi isactive 自愈 + DB 真相校验,不改业务数据)──────────────
|
||||||
|
// 注意:用全限定表名 eip3.sys_user,不在 SQL 里写 `set search_path` —— 否则 psql 会
|
||||||
|
// 先回显一行 "SET" 污染 -A 输出,导致 isactive 误判。
|
||||||
|
function psqlQuery(sql: string): string {
|
||||||
|
return execSync(
|
||||||
|
`psql -h localhost -p 5433 -d eip4dev -U zhengwr -t -A -c "${sql.replace(/"/g, '\\"')}"`,
|
||||||
|
{ encoding: 'utf8' },
|
||||||
|
).trim();
|
||||||
|
}
|
||||||
|
function psqlExec(sql: string): void {
|
||||||
|
execSync(
|
||||||
|
`psql -h localhost -p 5433 -d eip4dev -U zhengwr -c "${sql.replace(/"/g, '\\"')}"`,
|
||||||
|
{ encoding: 'utf8', stdio: 'pipe' },
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
// ── ceshi 账号自愈:若被历史 e2e 停用则置回 isactive=1,否则登录会被后端拦 ──────────
|
||||||
|
test.beforeAll(() => {
|
||||||
|
try {
|
||||||
|
const row = psqlQuery(
|
||||||
|
`select isactive from eip3.sys_user where account='${ACCOUNT}'`,
|
||||||
|
);
|
||||||
|
if (row !== '1') {
|
||||||
|
// eslint-disable-next-line no-console
|
||||||
|
console.warn(`[ceshi-menu] ceshi isactive=${row || '(空)'},自动置回 1 以便登录`);
|
||||||
|
psqlExec(`update eip3.sys_user set isactive=1, state=1 where account='${ACCOUNT}'`);
|
||||||
|
const after = psqlQuery(
|
||||||
|
`select isactive from eip3.sys_user where account='${ACCOUNT}'`,
|
||||||
|
);
|
||||||
|
expect(after, 'ceshi isactive 置回 1 失败').toBe('1');
|
||||||
|
} else {
|
||||||
|
// eslint-disable-next-line no-console
|
||||||
|
console.log('[ceshi-menu] ceshi isactive=1(可登录)');
|
||||||
|
}
|
||||||
|
} catch (err) {
|
||||||
|
// eslint-disable-next-line no-console
|
||||||
|
console.warn('[ceshi-menu] isactive 自愈检查失败(不中断,登录步骤会暴露真相):', err);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
// ════════════════════════════════════════════════════════════════════════════
|
||||||
|
// 真实 UI 登录:填表单 + 提交(绝不注入 token),落工作台
|
||||||
|
// ════════════════════════════════════════════════════════════════════════════
|
||||||
|
async function realLogin(page: Page, shot?: string): Promise<void> {
|
||||||
|
await page.goto('/login');
|
||||||
|
// 登录表单字段无 name,按 autocomplete / type 精确定位(见 LoginPage.tsx)
|
||||||
|
const accountInput = page.locator('input[autocomplete="username"]');
|
||||||
|
const passwordInput = page.locator('input[type="password"]');
|
||||||
|
await expect(accountInput, '登录表单未渲染出账号输入框').toBeVisible({ timeout: 20_000 });
|
||||||
|
|
||||||
|
await accountInput.fill(ACCOUNT);
|
||||||
|
await passwordInput.fill(PASSWORD);
|
||||||
|
// 真实点击「登录」按钮提交(非编程式 navigate)
|
||||||
|
await page.locator('button[type="submit"]', { hasText: /登录/ }).click();
|
||||||
|
|
||||||
|
// 登录成功 ⇒ 跳工作台 /workbench,AppShell 外壳(侧栏 .sidebar + Tab 条 .tabbar)出现
|
||||||
|
await expect(page, '登录后未跳转到工作台').toHaveURL(/\/workbench$/, { timeout: 20_000 });
|
||||||
|
await expect(page.locator('nav.sidebar'), '工作台外壳侧栏未渲染').toBeVisible({ timeout: 20_000 });
|
||||||
|
await expect(page.locator('.tabbar'), '工作台 Tab 条未渲染').toBeVisible({ timeout: 10_000 });
|
||||||
|
// 侧栏菜单从 /api/menu 异步加载,等根节点「信息站」出现,确认菜单真到位
|
||||||
|
await expect(
|
||||||
|
page.locator('nav.sidebar .sm-item .sm-name', { hasText: '信息站' }).first(),
|
||||||
|
'侧栏未加载出「信息站」根菜单(菜单接口失败?)',
|
||||||
|
).toBeVisible({ timeout: 20_000 });
|
||||||
|
if (shot) await page.screenshot({ path: path.join(ARTIFACTS, shot), fullPage: false });
|
||||||
|
}
|
||||||
|
|
||||||
|
// 定位某层级菜单项的 .sm-item 容器(按可见文本精确匹配 .sm-name)
|
||||||
|
function smItemByName(page: Page, name: string): Locator {
|
||||||
|
return page
|
||||||
|
.locator('nav.sidebar .sm-item')
|
||||||
|
.filter({ has: page.locator('.sm-name', { hasText: new RegExp(`^${name}$`) }) });
|
||||||
|
}
|
||||||
|
|
||||||
|
// 展开一个分组菜单项(仅当其未展开时点击 —— 通过 .tree-toggle.open 判断)
|
||||||
|
async function expandGroup(page: Page, item: Locator): Promise<void> {
|
||||||
|
const toggle = item.locator('.tree-toggle').first();
|
||||||
|
// 分组才有 .tree-toggle;已展开则带 .open class
|
||||||
|
const cls = (await toggle.getAttribute('class').catch(() => '')) ?? '';
|
||||||
|
if (!cls.includes('open')) {
|
||||||
|
await item.click();
|
||||||
|
// 等展开动画/子节点挂载
|
||||||
|
await page.waitForTimeout(300);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// ════════════════════════════════════════════════════════════════════════════
|
||||||
|
// 真·菜单导航:展开「信息站 > 通知管理」,点叶子「通知管理」→ 进列表页
|
||||||
|
// 返回打开后的列表页 Page(同一个 page,已切到 /page/e732c4b0…)
|
||||||
|
// ════════════════════════════════════════════════════════════════════════════
|
||||||
|
async function navigateNoticeViaMenu(page: Page): Promise<void> {
|
||||||
|
// 1) 「信息站」是 root[0],SideMenu 默认展开第一个根 ⇒ 一般已展开;保险起见确保展开
|
||||||
|
const xinxizhan = smItemByName(page, '信息站').first();
|
||||||
|
await expect(xinxizhan, '菜单中找不到「信息站」根节点').toBeVisible({ timeout: 10_000 });
|
||||||
|
await expandGroup(page, xinxizhan);
|
||||||
|
|
||||||
|
// 2) 展开「通知管理」分组(注意:有两个同名「通知管理」——分组(带 chevron)与叶子(无 chevron))。
|
||||||
|
// 分组 = 含 .tree-toggle 的 .sm-item;叶子 = 不含 .tree-toggle 的 .sm-item。
|
||||||
|
const noticeGroup = page
|
||||||
|
.locator('nav.sidebar .sm-item')
|
||||||
|
.filter({ has: page.locator('.sm-name', { hasText: /^通知管理$/ }) })
|
||||||
|
.filter({ has: page.locator('.tree-toggle') })
|
||||||
|
.first();
|
||||||
|
await expect(noticeGroup, '菜单中找不到「通知管理」分组节点').toBeVisible({ timeout: 10_000 });
|
||||||
|
await expandGroup(page, noticeGroup);
|
||||||
|
|
||||||
|
// 3) 断言「通知管理」叶子(无 chevron)出现 —— 这是 ceshi 可见权限的硬证据
|
||||||
|
const noticeLeaf = page
|
||||||
|
.locator('nav.sidebar .sm-item')
|
||||||
|
.filter({ has: page.locator('.sm-name', { hasText: /^通知管理$/ }) })
|
||||||
|
.filter({ hasNot: page.locator('.tree-toggle') })
|
||||||
|
.first();
|
||||||
|
await expect(
|
||||||
|
noticeLeaf,
|
||||||
|
'展开「信息站 > 通知管理」后,菜单里看不到指向列表页的「通知管理」叶子项(ceshi 权限/菜单渲染异常)',
|
||||||
|
).toBeVisible({ timeout: 10_000 });
|
||||||
|
|
||||||
|
// 4) 点击叶子 → handleMenuOpen → openTab('/page/e732c4b0…') → navigate
|
||||||
|
await noticeLeaf.click();
|
||||||
|
|
||||||
|
// 5) 强断言:URL 真切到列表页(菜单点击真的触发了导航,而非无反应/白屏)
|
||||||
|
await expect(
|
||||||
|
page,
|
||||||
|
'点击「通知管理」菜单后 URL 未切到列表页(菜单导航未触发,疑似前端导航 bug)',
|
||||||
|
).toHaveURL(new RegExp(NOTICE_PAGE_PATH.replace(/[/]/g, '\\/')), { timeout: 15_000 });
|
||||||
|
|
||||||
|
// 6) 强断言:Tab 条里出现该列表页 Tab 且处于激活态
|
||||||
|
const activeTab = page.locator('.tabbar .wtab.on');
|
||||||
|
await expect(activeTab, '点击菜单后未生成/激活列表页 Tab').toBeVisible({ timeout: 10_000 });
|
||||||
|
|
||||||
|
// 7) 强断言:amis 列表真实渲染 + 数据落地(非白屏/骨架/报错)
|
||||||
|
await expect(
|
||||||
|
page.locator('[data-testid="amis-host"]'),
|
||||||
|
'列表页 amis 宿主未渲染(白屏/报错)',
|
||||||
|
).toBeVisible({ timeout: 45_000 });
|
||||||
|
await page.waitForSelector('tbody tr', { timeout: 20_000 });
|
||||||
|
await expect
|
||||||
|
.poll(async () => (await firstRowTitle(page)) || '', { timeout: 15_000 })
|
||||||
|
.not.toBe('');
|
||||||
|
}
|
||||||
|
|
||||||
|
// 列表首行「主题」列(第 3 列:含 checkbox 列 + 隐藏主键列,主题在 nth(2))
|
||||||
|
async function firstRowTitle(page: Page): Promise<string> {
|
||||||
|
const t = await page.locator('tbody tr').first().locator('td').nth(2).textContent();
|
||||||
|
return (t ?? '').trim();
|
||||||
|
}
|
||||||
|
|
||||||
|
// 选中列表第一行(amis 隐藏原生 checkbox,点 label.cxd-Checkbox 触发 React onChange)
|
||||||
|
async function selectFirstRow(page: Page): Promise<void> {
|
||||||
|
const firstCell = page.locator('tbody tr').first().locator('td').first();
|
||||||
|
const label = firstCell.locator('label.cxd-Checkbox, .cxd-Checkbox').first();
|
||||||
|
if (await label.count().catch(() => 0)) {
|
||||||
|
await label.click({ force: true }).catch(async () => {
|
||||||
|
await firstCell.locator('input[type="checkbox"]').dispatchEvent('click').catch(() => {});
|
||||||
|
});
|
||||||
|
} else {
|
||||||
|
await firstCell.locator('input[type="checkbox"]').dispatchEvent('click');
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// 一站式:真实登录 + 菜单导航到列表页(每个独立用例复用)
|
||||||
|
async function loginAndOpenNoticeViaMenu(page: Page): Promise<void> {
|
||||||
|
await realLogin(page);
|
||||||
|
await navigateNoticeViaMenu(page);
|
||||||
|
}
|
||||||
|
|
||||||
|
// ════════════════════════════════════════════════════════════════════════════
|
||||||
|
// 步骤 1+2+3:真实登录 → 菜单可见「通知管理」→ 从菜单点进列表页(本次核心结论)
|
||||||
|
// ════════════════════════════════════════════════════════════════════════════
|
||||||
|
test('导航:真实表单登录 ceshi → 从菜单点「通知管理」进列表页', async ({ page }) => {
|
||||||
|
// 1) 真实表单登录 → 工作台
|
||||||
|
await realLogin(page, '01-login-workbench.png');
|
||||||
|
|
||||||
|
// 2) 展开「信息站 > 通知管理」并断言「通知管理」叶子可见,截菜单树
|
||||||
|
const xinxizhan = smItemByName(page, '信息站').first();
|
||||||
|
await expandGroup(page, xinxizhan);
|
||||||
|
const noticeGroup = page
|
||||||
|
.locator('nav.sidebar .sm-item')
|
||||||
|
.filter({ has: page.locator('.sm-name', { hasText: /^通知管理$/ }) })
|
||||||
|
.filter({ has: page.locator('.tree-toggle') })
|
||||||
|
.first();
|
||||||
|
await expect(noticeGroup, '菜单缺「通知管理」分组(ceshi 应可见)').toBeVisible({ timeout: 10_000 });
|
||||||
|
await expandGroup(page, noticeGroup);
|
||||||
|
const noticeLeaf = page
|
||||||
|
.locator('nav.sidebar .sm-item')
|
||||||
|
.filter({ has: page.locator('.sm-name', { hasText: /^通知管理$/ }) })
|
||||||
|
.filter({ hasNot: page.locator('.tree-toggle') })
|
||||||
|
.first();
|
||||||
|
await expect(noticeLeaf, '菜单缺指向列表页的「通知管理」叶子').toBeVisible({ timeout: 10_000 });
|
||||||
|
await page.screenshot({ path: path.join(ARTIFACTS, '02-menu-tree.png'), fullPage: false });
|
||||||
|
|
||||||
|
// 3) 从菜单点击叶子 → 断言导航 + Tab + 数据
|
||||||
|
await noticeLeaf.click();
|
||||||
|
await expect(page, '菜单点击未导航到列表页 URL').toHaveURL(
|
||||||
|
new RegExp(NOTICE_PAGE_PATH.replace(/[/]/g, '\\/')),
|
||||||
|
{ timeout: 15_000 },
|
||||||
|
);
|
||||||
|
await expect(page.locator('.tabbar .wtab.on'), '未激活列表页 Tab').toBeVisible({ timeout: 10_000 });
|
||||||
|
await expect(page.locator('[data-testid="amis-host"]'), 'amis 宿主未渲染').toBeVisible({
|
||||||
|
timeout: 45_000,
|
||||||
|
});
|
||||||
|
await page.waitForSelector('tbody tr', { timeout: 20_000 });
|
||||||
|
await expect
|
||||||
|
.poll(async () => (await firstRowTitle(page)) || '', { timeout: 15_000 })
|
||||||
|
.not.toBe('');
|
||||||
|
await page.screenshot({ path: path.join(ARTIFACTS, '03-list-via-menu.png'), fullPage: false });
|
||||||
|
});
|
||||||
|
|
||||||
|
// ════════════════════════════════════════════════════════════════════════════
|
||||||
|
// 步骤 4 ①分页:翻第 2 页,首行 ≠ 第 1 页
|
||||||
|
// ════════════════════════════════════════════════════════════════════════════
|
||||||
|
test('修点①分页:第2页首行标题 ≠ 第1页', async ({ page }) => {
|
||||||
|
await loginAndOpenNoticeViaMenu(page);
|
||||||
|
|
||||||
|
const p1 = await firstRowTitle(page);
|
||||||
|
expect(p1, 'P1 首行标题应非空').not.toBe('');
|
||||||
|
|
||||||
|
const pager2 = page
|
||||||
|
.locator('ul.cxd-Pagination li.cxd-Pagination-pager-item', { hasText: /^2$/ })
|
||||||
|
.first();
|
||||||
|
await expect(pager2, '应存在第 2 页页码(266 条多页)').toBeVisible({ timeout: 10_000 });
|
||||||
|
await pager2.locator('a').click();
|
||||||
|
|
||||||
|
await expect
|
||||||
|
.poll(
|
||||||
|
async () =>
|
||||||
|
(
|
||||||
|
await page.locator('li.cxd-Pagination-pager-item.is-active').first().textContent()
|
||||||
|
)?.trim(),
|
||||||
|
{ timeout: 15_000 },
|
||||||
|
)
|
||||||
|
.toBe('2');
|
||||||
|
await page.waitForTimeout(1200);
|
||||||
|
|
||||||
|
const p2 = await firstRowTitle(page);
|
||||||
|
await page.screenshot({ path: path.join(ARTIFACTS, '04-pagination.png'), fullPage: false });
|
||||||
|
expect(p2, 'P2 首行标题应非空').not.toBe('');
|
||||||
|
expect(p2, `分页未真换页:P1=P2="${p1}"`).not.toBe(p1);
|
||||||
|
});
|
||||||
|
|
||||||
|
// ════════════════════════════════════════════════════════════════════════════
|
||||||
|
// 步骤 4 ②人员列:拟稿人列显示姓名(非 GUID / 非纯工号 / 非裸 ADMIN)
|
||||||
|
// ════════════════════════════════════════════════════════════════════════════
|
||||||
|
test('修点②人员列:拟稿人显示姓名(非GUID/纯工号)', async ({ page }) => {
|
||||||
|
await loginAndOpenNoticeViaMenu(page);
|
||||||
|
|
||||||
|
const headers = await page.locator('thead').first().locator('th').allTextContents();
|
||||||
|
const idx = headers.findIndex((h) => h.trim().includes('拟稿人'));
|
||||||
|
expect(idx, '应找到「拟稿人」列').toBeGreaterThanOrEqual(0);
|
||||||
|
|
||||||
|
const cells = await page.locator(`tbody tr td:nth-child(${idx + 1})`).allTextContents();
|
||||||
|
const values = cells.map((c) => c.trim()).filter(Boolean);
|
||||||
|
expect(values.length, '拟稿人列应有数据').toBeGreaterThanOrEqual(1);
|
||||||
|
await page.screenshot({ path: path.join(ARTIFACTS, '05-person-col.png'), fullPage: false });
|
||||||
|
|
||||||
|
const GUID_RE = /^[0-9a-fA-F]{8}-?[0-9a-fA-F]{4}-?[0-9a-fA-F]{4}-?[0-9a-fA-F]{4}-?[0-9a-fA-F]{12}$/;
|
||||||
|
const RAW_GUID_NODASH_RE = /^[0-9a-fA-F]{32}$/;
|
||||||
|
const PURE_DIGITS_RE = /^\d+$/;
|
||||||
|
let nameHits = 0;
|
||||||
|
for (const v of values) {
|
||||||
|
expect(GUID_RE.test(v), `拟稿人显示为 GUID: "${v}"`).toBe(false);
|
||||||
|
expect(RAW_GUID_NODASH_RE.test(v), `拟稿人显示为无连字符 GUID: "${v}"`).toBe(false);
|
||||||
|
expect(PURE_DIGITS_RE.test(v), `拟稿人显示为纯工号: "${v}"`).toBe(false);
|
||||||
|
expect(v, `拟稿人显示为裸 ADMIN: "${v}"`).not.toBe('ADMIN');
|
||||||
|
if (/[一-龥]/.test(v)) nameHits += 1;
|
||||||
|
}
|
||||||
|
expect(nameHits, `拟稿人列无姓名样式(含中文名)单元格: ${JSON.stringify(values)}`).toBeGreaterThanOrEqual(
|
||||||
|
1,
|
||||||
|
);
|
||||||
|
});
|
||||||
|
|
||||||
|
// ════════════════════════════════════════════════════════════════════════════
|
||||||
|
// 步骤 4 ③添加弹窗:(a) 富文本 (b) 接收人带姓名选项 (c) 确认/取消各一
|
||||||
|
// ════════════════════════════════════════════════════════════════════════════
|
||||||
|
// 打开「添加」弹窗,返回 modal Locator(已等到表单字段渲染)
|
||||||
|
async function openAddDialog(page: Page): Promise<Locator> {
|
||||||
|
await page.locator('button', { hasText: '添加' }).first().click();
|
||||||
|
await page.waitForSelector('.cxd-Modal', { timeout: 15_000 });
|
||||||
|
await expect(page.locator('.cxd-Modal .cxd-Form-item').first()).toBeVisible({ timeout: 15_000 });
|
||||||
|
await page.waitForTimeout(2000); // 富文本(tinymce)初始化
|
||||||
|
return page.locator('.cxd-Modal').last();
|
||||||
|
}
|
||||||
|
|
||||||
|
// ── (a) 内容 = 富文本编辑器(tinymce),非单行 input ──
|
||||||
|
test('修点③a 添加弹窗:内容字段为富文本编辑器(非单行input)', async ({ page }) => {
|
||||||
|
await loginAndOpenNoticeViaMenu(page);
|
||||||
|
const modal = await openAddDialog(page);
|
||||||
|
|
||||||
|
const contentItem = modal.locator('.cxd-Form-item', { hasText: '内容' }).first();
|
||||||
|
await expect(contentItem, '弹窗应含「内容」字段').toBeVisible({ timeout: 5_000 });
|
||||||
|
const rich = await contentItem.evaluate((el: Element) => ({
|
||||||
|
richControl: !!el.querySelector('.cxd-RichTextControl, [class*="RichText"]'),
|
||||||
|
tinymce: !!el.querySelector('.tox-tinymce, .mce-tinymce, iframe[id*="mce"], iframe[id*="tiny"]'),
|
||||||
|
froala: !!el.querySelector('.fr-box, .fr-element, [class*="froala"]'),
|
||||||
|
contenteditable: !!el.querySelector('[contenteditable="true"]'),
|
||||||
|
iframeCount: el.querySelectorAll('iframe').length,
|
||||||
|
plainTextInput: !!el.querySelector('input[type="text"]:not([type=hidden])'),
|
||||||
|
}));
|
||||||
|
await page.screenshot({ path: path.join(ARTIFACTS, '06a-add-richtext.png'), fullPage: false });
|
||||||
|
const isRich =
|
||||||
|
rich.richControl &&
|
||||||
|
(rich.tinymce || rich.froala || rich.contenteditable || rich.iframeCount >= 1);
|
||||||
|
expect(isRich, `内容字段未渲染为富文本编辑器: ${JSON.stringify(rich)}`).toBe(true);
|
||||||
|
expect(rich.plainTextInput && !rich.richControl, '内容字段退化为单行 input').toBe(false);
|
||||||
|
});
|
||||||
|
|
||||||
|
// ── (b) 接收人下拉展开有带姓名选项(picker 不为空) ──
|
||||||
|
test('修点③b 添加弹窗:接收人下拉有带姓名选项', async ({ page }) => {
|
||||||
|
await loginAndOpenNoticeViaMenu(page);
|
||||||
|
const modal = await openAddDialog(page);
|
||||||
|
|
||||||
|
const recvItem = modal.locator('.cxd-Form-item', { hasText: '接收人' }).first();
|
||||||
|
await expect(recvItem, '弹窗应含「接收人」字段').toBeVisible({ timeout: 5_000 });
|
||||||
|
|
||||||
|
// 捕获接收人 picker 的远程请求(拿真实 URL + 响应做缺陷取证;非源码硬编码)。
|
||||||
|
const pickerReqPromise = page
|
||||||
|
.waitForResponse(
|
||||||
|
(resp) =>
|
||||||
|
/list|picker|user/i.test(resp.url()) &&
|
||||||
|
(resp.request().resourceType() === 'fetch' || resp.request().resourceType() === 'xhr'),
|
||||||
|
{ timeout: 8_000 },
|
||||||
|
)
|
||||||
|
.catch(() => null);
|
||||||
|
|
||||||
|
await recvItem.locator('.cxd-Select').first().evaluate((el: Element) => {
|
||||||
|
(el.querySelector('.cxd-Select-valueWrap') || el).dispatchEvent(
|
||||||
|
new MouseEvent('click', { bubbles: true }),
|
||||||
|
);
|
||||||
|
});
|
||||||
|
|
||||||
|
// 等下拉浮层出现(无论有无结果,amis 都会渲染 .cxd-PopOver-overlay / 菜单容器)。
|
||||||
|
await page
|
||||||
|
.locator('.cxd-PopOver-overlay, .cxd-Select-menu')
|
||||||
|
.first()
|
||||||
|
.waitFor({ state: 'visible', timeout: 8_000 })
|
||||||
|
.catch(() => {});
|
||||||
|
await page.waitForTimeout(800); // 给远程 source 渲染选项的时间
|
||||||
|
await page.screenshot({ path: path.join(ARTIFACTS, '06b-receiver-dropdown.png'), fullPage: false });
|
||||||
|
|
||||||
|
// 取证:picker 请求 URL + 响应体(写日志,便于报告里给出根因)。
|
||||||
|
const pickerResp = await pickerReqPromise;
|
||||||
|
if (pickerResp) {
|
||||||
|
let body = '';
|
||||||
|
try {
|
||||||
|
body = JSON.stringify(await pickerResp.json()).slice(0, 800);
|
||||||
|
} catch {
|
||||||
|
body = '(非 JSON 响应)';
|
||||||
|
}
|
||||||
|
// eslint-disable-next-line no-console
|
||||||
|
console.log(
|
||||||
|
`[修点③b][接收人 picker] URL=${pickerResp.url()} HTTP=${pickerResp.status()} body=${body}`,
|
||||||
|
);
|
||||||
|
} else {
|
||||||
|
// eslint-disable-next-line no-console
|
||||||
|
console.warn('[修点③b][接收人 picker] 8s 内未观察到 list/picker/user 远程请求');
|
||||||
|
}
|
||||||
|
|
||||||
|
// 「未找到任何结果」死文案是 amis Select 空选项的硬证据 —— 直接判定 picker 失效。
|
||||||
|
const emptyHint = await page
|
||||||
|
.locator('.cxd-PopOver-overlay, .cxd-Select-menu')
|
||||||
|
.first()
|
||||||
|
.evaluate((el) => /未找到任何结果|暂无数据|无结果/.test(el.textContent || ''))
|
||||||
|
.catch(() => false);
|
||||||
|
|
||||||
|
const opts = (await page.locator('.cxd-Select-option').allTextContents())
|
||||||
|
.map((t) => t.trim())
|
||||||
|
.filter(Boolean);
|
||||||
|
// 强断言(不放水):接收人下拉展开后应有选项;空(如「未找到任何结果」)即真实缺陷。
|
||||||
|
expect(
|
||||||
|
opts.length,
|
||||||
|
`接收人下拉展开后选项为空(picker 失效${emptyHint ? ',浮层显示「未找到任何结果」' : ''})`,
|
||||||
|
).toBeGreaterThanOrEqual(1);
|
||||||
|
const named = opts.filter((t) => /[一-龥]/.test(t));
|
||||||
|
expect(named.length, `接收人选项无带姓名项: ${JSON.stringify(opts.slice(0, 5))}`).toBeGreaterThanOrEqual(
|
||||||
|
1,
|
||||||
|
);
|
||||||
|
});
|
||||||
|
|
||||||
|
// ── (c) 弹窗确认/取消恰好各一个 ──
|
||||||
|
test('修点③c 添加弹窗:确认/取消按钮恰好各一个', async ({ page }) => {
|
||||||
|
await loginAndOpenNoticeViaMenu(page);
|
||||||
|
const modal = await openAddDialog(page);
|
||||||
|
|
||||||
|
const footer = (await modal.locator('.cxd-Modal-footer button').allTextContents())
|
||||||
|
.map((t) => t.trim())
|
||||||
|
.filter(Boolean);
|
||||||
|
const confirmCount = footer.filter((t) => t === '确认' || t === '确定' || t === '提交').length;
|
||||||
|
const cancelCount = footer.filter((t) => t === '取消').length;
|
||||||
|
await page.screenshot({ path: path.join(ARTIFACTS, '06c-footer-buttons.png'), fullPage: false });
|
||||||
|
expect(confirmCount, `确认类按钮应恰好1,footer=${JSON.stringify(footer)}`).toBe(1);
|
||||||
|
expect(cancelCount, `取消按钮应恰好1,footer=${JSON.stringify(footer)}`).toBe(1);
|
||||||
|
});
|
||||||
|
|
||||||
|
// ════════════════════════════════════════════════════════════════════════════
|
||||||
|
// 步骤 4 ④查看只读:选中行 → 查看 → 弹窗只读回显(非死桩)
|
||||||
|
// ════════════════════════════════════════════════════════════════════════════
|
||||||
|
test('修点④查看只读:弹窗只读回显(非死桩)', async ({ page }) => {
|
||||||
|
await loginAndOpenNoticeViaMenu(page);
|
||||||
|
|
||||||
|
const rowTitle = await firstRowTitle(page);
|
||||||
|
expect(rowTitle, '首行标题应非空').not.toBe('');
|
||||||
|
|
||||||
|
await selectFirstRow(page);
|
||||||
|
await expect(page.locator('button', { hasText: '查看' }).first()).toBeEnabled({ timeout: 8_000 });
|
||||||
|
await page.locator('button', { hasText: '查看' }).first().click();
|
||||||
|
|
||||||
|
await page.waitForSelector('.cxd-Modal', { timeout: 15_000 });
|
||||||
|
await expect(page.locator('.cxd-Modal .cxd-Form-item').first()).toBeVisible({ timeout: 15_000 });
|
||||||
|
await page.waitForTimeout(1500);
|
||||||
|
await page.screenshot({ path: path.join(ARTIFACTS, '07-view-readonly.png'), fullPage: false });
|
||||||
|
|
||||||
|
const modal = page.locator('.cxd-Modal').last();
|
||||||
|
const modalText = (await modal.textContent()) ?? '';
|
||||||
|
|
||||||
|
// 非「未配编辑表单」死桩
|
||||||
|
expect(modalText, '查看弹窗为占位/死桩(未配编辑表单/待转换)').not.toMatch(
|
||||||
|
/未配|未配置编辑表单|待.{0,6}转换/,
|
||||||
|
);
|
||||||
|
// 表单真实加载(含主题/内容字段)
|
||||||
|
await expect(modal.locator('.cxd-Form-item', { hasText: '主题' }).first()).toBeVisible({
|
||||||
|
timeout: 5_000,
|
||||||
|
});
|
||||||
|
await expect(modal.locator('.cxd-Form-item', { hasText: '内容' }).first()).toBeVisible({
|
||||||
|
timeout: 5_000,
|
||||||
|
});
|
||||||
|
// 只读:无可编辑输入
|
||||||
|
const editableCount = await modal.evaluate((el: Element) => {
|
||||||
|
const inputs = Array.from(el.querySelectorAll('input, textarea'));
|
||||||
|
return inputs.filter((i) => {
|
||||||
|
const e = i as HTMLInputElement | HTMLTextAreaElement;
|
||||||
|
return (
|
||||||
|
!e.disabled &&
|
||||||
|
!e.readOnly &&
|
||||||
|
e.type !== 'hidden' &&
|
||||||
|
(e as unknown as HTMLElement).offsetParent !== null
|
||||||
|
);
|
||||||
|
}).length;
|
||||||
|
});
|
||||||
|
expect(editableCount, `查看弹窗存在 ${editableCount} 个可编辑输入(应只读)`).toBe(0);
|
||||||
|
// 真实回显首行标题
|
||||||
|
expect(modalText, `查看弹窗未回显行标题 "${rowTitle}"`).toContain(rowTitle);
|
||||||
|
});
|
||||||
589
e2e/notice-reality.spec.ts
Normal file
589
e2e/notice-reality.spec.ts
Normal file
@@ -0,0 +1,589 @@
|
|||||||
|
/**
|
||||||
|
* 通知管理(OA_NOTICEMANAGE)「组件真实性」强断言 E2E —— P2 试点最终验收基线
|
||||||
|
* ============================================================================
|
||||||
|
* 目标:断言【业务语义 / 渲染真实性】,而非「弹窗出现 / 有数据」。
|
||||||
|
* 上一轮 e2e 80/80 全绿却漏掉分页失效 / picker 空 / 死桩 / 富文本退化——
|
||||||
|
* 因为是表层断言。本 spec 逐条做成独立强断言,任一渲染缺陷都要被抓出来。
|
||||||
|
*
|
||||||
|
* 6 条强断言(独立用例,失败可定位):
|
||||||
|
* #1 分页真换页:P1 与 P2 首行标题不相同。
|
||||||
|
* #2 过滤+分页共存:TITLE 含「放假」总数 << 全量 266,且每行标题含「放假」。
|
||||||
|
* #3 拟稿人列显示姓名:单元格为姓名样式(如 系统管理员[admin]),
|
||||||
|
* 非纯 GUID / 非纯工号数字 / 非 'ADMIN'。
|
||||||
|
* #4 添加弹窗真实可用:
|
||||||
|
* (a) 内容(NOTICECONTENT) 渲染为富文本编辑器(input-rich-text,非单行 input);
|
||||||
|
* (b) 接收人为可展开下拉且有带姓名选项(非空);
|
||||||
|
* (c) 弹窗确认/取消恰好各一个(无「提交+确认」两套重复)。
|
||||||
|
* #5 查看只读:选中行→查看→表单加载且只读(字段不可编辑/无可编辑输入),
|
||||||
|
* 非「未配编辑表单」死桩,且真实回显行数据。
|
||||||
|
* #6 添加端到端落库:填标题+富文本内容+选接收人→确认→
|
||||||
|
* 断言发出 POST /api/entity/OA_NOTICEMANAGE/save,且 DB 出现新记录。
|
||||||
|
*
|
||||||
|
* 环境(都在跑,勿重启):
|
||||||
|
* 前端 dev 5173(eip4-web);后端 8093(platform-app dev/eip4dev);psql 5433。
|
||||||
|
* schema 端点 /api/page/schema/{id}(templateId 不在 mock map ⇒ fallback 后端,
|
||||||
|
* 5173 与真实后端 schema 一致)。
|
||||||
|
* 账号 admin/111111。列表模板 e732c4b0;编辑表单 20147656。
|
||||||
|
*
|
||||||
|
* 数据纪律:写入记录带 E2E-NR- 前缀,afterAll 物理清理;不动他人数据。
|
||||||
|
*/
|
||||||
|
import { expect, test, type Page } from '@playwright/test';
|
||||||
|
import http from 'node:http';
|
||||||
|
import { execSync } from 'node:child_process';
|
||||||
|
import * as path from 'node:path';
|
||||||
|
import { fileURLToPath } from 'node:url';
|
||||||
|
|
||||||
|
const __filename = fileURLToPath(import.meta.url);
|
||||||
|
const __dirname = path.dirname(__filename);
|
||||||
|
|
||||||
|
const GATEWAY_PORT = 8093;
|
||||||
|
const NOTICE_PAGE = '/page/e732c4b0-2402-4e73-8cc4-786c8a8c52af';
|
||||||
|
const SAVE_API_RE = /\/api\/entity\/OA_NOTICEMANAGE\/save/;
|
||||||
|
const ARTIFACTS = path.join(__dirname, 'artifacts', 'notice-reality');
|
||||||
|
const E2E_PREFIX = `E2E-NR-${Date.now()}`;
|
||||||
|
|
||||||
|
// ── Node 侧:登录 / HTTP ──────────────────────────────────────────────────────
|
||||||
|
|
||||||
|
let _token: string | undefined;
|
||||||
|
function getToken(): Promise<string> {
|
||||||
|
if (_token) return Promise.resolve(_token);
|
||||||
|
return new Promise((resolve, reject) => {
|
||||||
|
const body = JSON.stringify({ account: 'admin', password: '111111' });
|
||||||
|
const req = http.request(
|
||||||
|
{
|
||||||
|
hostname: 'localhost', port: GATEWAY_PORT, 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 { token?: string };
|
||||||
|
if (!parsed.token) return reject(new Error('登录失败: ' + data));
|
||||||
|
_token = parsed.token;
|
||||||
|
resolve(_token);
|
||||||
|
} catch (e) { reject(e); }
|
||||||
|
});
|
||||||
|
},
|
||||||
|
);
|
||||||
|
req.on('error', reject);
|
||||||
|
req.write(body);
|
||||||
|
req.end();
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
function apiGet(apiPath: string): Promise<Record<string, unknown>> {
|
||||||
|
return getToken().then((token) => new Promise((resolve, reject) => {
|
||||||
|
const req = http.request(
|
||||||
|
{ hostname: 'localhost', port: GATEWAY_PORT, path: apiPath, method: 'GET',
|
||||||
|
headers: { 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.end();
|
||||||
|
}));
|
||||||
|
}
|
||||||
|
|
||||||
|
// ── Node 侧:psql(DB 真相校验 + 清理)─────────────────────────────────────────
|
||||||
|
|
||||||
|
function psqlQuery(sql: string): string {
|
||||||
|
return execSync(
|
||||||
|
`psql -h localhost -p 5433 -d eip4dev -U zhengwr -t -c "${sql.replace(/"/g, '\\"')}"`,
|
||||||
|
{ encoding: 'utf8' },
|
||||||
|
).trim();
|
||||||
|
}
|
||||||
|
function psqlExec(sql: string): void {
|
||||||
|
execSync(
|
||||||
|
`psql -h localhost -p 5433 -d eip4dev -U zhengwr -c "${sql.replace(/"/g, '\\"')}"`,
|
||||||
|
{ encoding: 'utf8', stdio: 'pipe' },
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
// ── 前端:注入 token + profile(与既有 spec 一致),导航到通知页并等表格 ────────
|
||||||
|
|
||||||
|
async function seedAuth(page: Page): Promise<void> {
|
||||||
|
const token = await getToken();
|
||||||
|
await page.addInitScript(({ t }: { t: string }) => {
|
||||||
|
localStorage.setItem('eip4_token', t);
|
||||||
|
localStorage.setItem('eip4_profile', JSON.stringify({
|
||||||
|
userId: 'ADMIN', account: 'admin', name: 'admin', roles: [],
|
||||||
|
}));
|
||||||
|
}, { t: token });
|
||||||
|
}
|
||||||
|
|
||||||
|
async function gotoNoticeList(page: Page): Promise<void> {
|
||||||
|
await seedAuth(page);
|
||||||
|
await page.goto(NOTICE_PAGE);
|
||||||
|
await expect(page.locator('[data-testid="amis-host"]')).toBeVisible({ timeout: 45_000 });
|
||||||
|
// 等真实数据行渲染(amis CRUD 拉 /api/flow/OA_NOTICEMANAGE_SEARCH)
|
||||||
|
await page.waitForSelector('tbody tr', { timeout: 20_000 });
|
||||||
|
// 等首行标题非空,确认数据已落地(非骨架)
|
||||||
|
await expect
|
||||||
|
.poll(async () => (await page.locator('tbody tr').first()
|
||||||
|
.locator('td').nth(2).textContent())?.trim() || '', { timeout: 15_000 })
|
||||||
|
.not.toBe('');
|
||||||
|
}
|
||||||
|
|
||||||
|
/** 读取当前列表首行「主题」列(第 3 列,主键列默认隐藏 toggled:false)。 */
|
||||||
|
async function firstRowTitle(page: Page): Promise<string> {
|
||||||
|
const t = await page.locator('tbody tr').first().locator('td').nth(2).textContent();
|
||||||
|
return (t ?? '').trim();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 选中列表第一行(amis 选择列 checkbox)。
|
||||||
|
* amis 原生 input[type=checkbox] 为隐藏元素,点 label.cxd-Checkbox 才触发 React onChange;
|
||||||
|
* 若 label 不可点则 fallback 到原生 DOM click(绕过可见性,等价 MCP 实测路径)。
|
||||||
|
*/
|
||||||
|
async function selectFirstRow(page: Page): Promise<void> {
|
||||||
|
const firstCell = page.locator('tbody tr').first().locator('td').first();
|
||||||
|
const label = firstCell.locator('label.cxd-Checkbox, .cxd-Checkbox').first();
|
||||||
|
if (await label.count().catch(() => 0)) {
|
||||||
|
await label.click({ force: true }).catch(async () => {
|
||||||
|
await firstCell.locator('input[type="checkbox"]')
|
||||||
|
.dispatchEvent('click').catch(() => {});
|
||||||
|
});
|
||||||
|
} else {
|
||||||
|
await firstCell.locator('input[type="checkbox"]').dispatchEvent('click');
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 收起 amis Select 下拉并确保遮罩脱离。
|
||||||
|
* single select 选完自动收起(overlay 已消失则直接返回);
|
||||||
|
* multiple select(接收人)选完不收起 ⇒ toggle 点 valueWrap 关闭;
|
||||||
|
* 二次校验:若仍残留则再 toggle 一次,最终等 .cxd-PopOver-overlay 脱离。
|
||||||
|
*/
|
||||||
|
async function closeSelectPopover(
|
||||||
|
page: Page,
|
||||||
|
sel: ReturnType<Page['locator']>,
|
||||||
|
): Promise<void> {
|
||||||
|
const overlay = page.locator('.cxd-PopOver-overlay');
|
||||||
|
const toggle = () => sel.evaluate((el: Element) => {
|
||||||
|
(el.querySelector('.cxd-Select-valueWrap') || el)
|
||||||
|
.dispatchEvent(new MouseEvent('click', { bubbles: true }));
|
||||||
|
});
|
||||||
|
for (let i = 0; i < 3; i += 1) {
|
||||||
|
if ((await overlay.count().catch(() => 0)) === 0) return; // 已收起
|
||||||
|
await toggle().catch(() => {});
|
||||||
|
await overlay.waitFor({ state: 'detached', timeout: 1_500 }).catch(() => {});
|
||||||
|
}
|
||||||
|
await page.waitForTimeout(150);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 在弹窗内为指定 label 的 amis Select 选第一个选项,并收起下拉。
|
||||||
|
*
|
||||||
|
* 关键(MCP 实测踩坑):
|
||||||
|
* - amis Select 的下拉用 .cxd-PopOver-overlay 全屏遮罩 + .cxd-Select-menu 菜单;
|
||||||
|
* multiple select(接收人)选完不自动收起;
|
||||||
|
* - 按 Escape【无效】(amis 不监听);点 overlay 中心会命中选项菜单(被拦截);
|
||||||
|
* - 唯一可靠收起方式:再次「toggle」点击 Select 控件的 valueWrap → 用
|
||||||
|
* dispatchEvent 派发原生 click(绕过 playwright 可见性/拦截检查),
|
||||||
|
* 实测可使 overlay 脱离、options 清零。
|
||||||
|
* 展开同理用 dispatchEvent,避免被既有遮罩拦截。
|
||||||
|
*/
|
||||||
|
async function pickFirstSelectOption(
|
||||||
|
page: Page,
|
||||||
|
modal: ReturnType<Page['locator']>,
|
||||||
|
label: string,
|
||||||
|
): Promise<void> {
|
||||||
|
const item = modal.locator('.cxd-Form-item', { hasText: label }).first();
|
||||||
|
const sel = item.locator('.cxd-Select').first();
|
||||||
|
if (!(await sel.count().catch(() => 0))) return;
|
||||||
|
|
||||||
|
// 展开:toggle 点 valueWrap(dispatchEvent 原生 click)
|
||||||
|
await sel.evaluate((el: Element) => {
|
||||||
|
(el.querySelector('.cxd-Select-valueWrap') || el)
|
||||||
|
.dispatchEvent(new MouseEvent('click', { bubbles: true }));
|
||||||
|
});
|
||||||
|
// 等远程 source 选项渲染
|
||||||
|
const opt = page.locator('.cxd-Select-option').first();
|
||||||
|
if (await opt.isVisible({ timeout: 8_000 }).catch(() => false)) {
|
||||||
|
// force click:跳过 overlay 拦截检查,但仍发真实鼠标事件序列以触发 amis
|
||||||
|
// React onClick(dispatchEvent 合成事件对 amis 选项不可靠,不会写入选中值)
|
||||||
|
await opt.click({ force: true });
|
||||||
|
}
|
||||||
|
await closeSelectPopover(page, sel);
|
||||||
|
}
|
||||||
|
|
||||||
|
test.afterAll(() => {
|
||||||
|
try {
|
||||||
|
psqlExec(`DELETE FROM eip3.oa_noticemanage WHERE title LIKE 'E2E-NR-%'`);
|
||||||
|
// eslint-disable-next-line no-console
|
||||||
|
console.log('[notice-reality] E2E 测试数据已清理 (title LIKE E2E-NR-%)');
|
||||||
|
} catch (err) {
|
||||||
|
// eslint-disable-next-line no-console
|
||||||
|
console.warn('[notice-reality] 清理失败(不影响结论):', err);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
// ════════════════════════════════════════════════════════════════════════════
|
||||||
|
// #1 分页真换页:P1 首行标题 ≠ P2 首行标题
|
||||||
|
// ════════════════════════════════════════════════════════════════════════════
|
||||||
|
test('#1 分页真换页:第1页与第2页首行标题不相同', async ({ page }) => {
|
||||||
|
await gotoNoticeList(page);
|
||||||
|
|
||||||
|
const p1Title = await firstRowTitle(page);
|
||||||
|
expect(p1Title, 'P1 首行标题应非空').not.toBe('');
|
||||||
|
|
||||||
|
// 点分页器「2」(页码 li.cxd-Pagination-pager-item,文本即页码;取第一个分页器)
|
||||||
|
const pageItem2 = page.locator('ul.cxd-Pagination li.cxd-Pagination-pager-item', { hasText: /^2$/ }).first();
|
||||||
|
await expect(pageItem2, '应存在第 2 页页码(266 条 / perPage ⇒ 多页)').toBeVisible({ timeout: 10_000 });
|
||||||
|
await pageItem2.locator('a').click();
|
||||||
|
|
||||||
|
// 等 active page 切到 2(amis 重新请求 page=2)
|
||||||
|
await expect
|
||||||
|
.poll(async () =>
|
||||||
|
(await page.locator('li.cxd-Pagination-pager-item.is-active').first().textContent())?.trim(),
|
||||||
|
{ timeout: 15_000 })
|
||||||
|
.toBe('2');
|
||||||
|
// 等首行刷新(容忍异步:标题变化即换页成功)
|
||||||
|
await page.waitForTimeout(1500);
|
||||||
|
|
||||||
|
const p2Title = await firstRowTitle(page);
|
||||||
|
await page.screenshot({ path: path.join(ARTIFACTS, '01-pagination-page2.png') });
|
||||||
|
|
||||||
|
// 强断言:换页后首行标题与第 1 页不同(不是「有数据就过」)
|
||||||
|
expect(p2Title, 'P2 首行标题应非空').not.toBe('');
|
||||||
|
expect(p2Title, `分页未真正换页:P1 与 P2 首行标题相同 = "${p1Title}"`).not.toBe(p1Title);
|
||||||
|
});
|
||||||
|
|
||||||
|
// ════════════════════════════════════════════════════════════════════════════
|
||||||
|
// #2 过滤+分页共存:TITLE 含「放假」总数显著下降,且每行标题含「放假」
|
||||||
|
// ════════════════════════════════════════════════════════════════════════════
|
||||||
|
test('#2 过滤+分页共存:搜「放假」总数<<全量266 且每行标题含「放假」', async ({ page }) => {
|
||||||
|
// —— API 层先取全量 total(权威基线)——
|
||||||
|
const allResp = await apiGet('/api/flow/OA_NOTICEMANAGE_SEARCH?page=1&perPage=10') as {
|
||||||
|
status: number; data: { total: number };
|
||||||
|
};
|
||||||
|
expect(allResp.status).toBe(0);
|
||||||
|
const totalAll = allResp.data.total;
|
||||||
|
expect(totalAll, '全量应约 266').toBeGreaterThan(200);
|
||||||
|
|
||||||
|
await gotoNoticeList(page);
|
||||||
|
|
||||||
|
// 主题搜索框填「放假」
|
||||||
|
const titleInput = page.locator('input[name="TITLE"]');
|
||||||
|
await expect(titleInput).toBeVisible({ timeout: 10_000 });
|
||||||
|
await titleInput.fill('放假');
|
||||||
|
await page.locator('button', { hasText: '搜索' }).first().click();
|
||||||
|
|
||||||
|
// 等列表刷新到过滤结果(首行标题应含「放假」)
|
||||||
|
await expect
|
||||||
|
.poll(async () => await firstRowTitle(page), { timeout: 15_000 })
|
||||||
|
.toContain('放假');
|
||||||
|
await page.screenshot({ path: path.join(ARTIFACTS, '02-filter-fangjia.png') });
|
||||||
|
|
||||||
|
// 读分页器总页数推断过滤后总数显著下降:active=1 时末页码 << 全量页数
|
||||||
|
// 更直接:读列表实际可见行标题逐行断言含「放假」
|
||||||
|
const visibleTitles = await page.locator('tbody tr td:nth-child(3)')
|
||||||
|
.allTextContents();
|
||||||
|
const nonEmpty = visibleTitles.map((t) => t.trim()).filter(Boolean);
|
||||||
|
expect(nonEmpty.length, '过滤后至少 1 行').toBeGreaterThanOrEqual(1);
|
||||||
|
for (const t of nonEmpty) {
|
||||||
|
expect(t, `过滤结果出现不含「放假」的行: "${t}"`).toContain('放假');
|
||||||
|
}
|
||||||
|
|
||||||
|
// 强断言:过滤后总数显著下降(API 复算,与 UI 同一过滤条件)
|
||||||
|
const filteredResp = await apiGet(
|
||||||
|
`/api/flow/OA_NOTICEMANAGE_SEARCH?page=1&perPage=10&TITLE=${encodeURIComponent('放假')}`,
|
||||||
|
) as { status: number; data: { total: number; items: Array<{ TITLE: string }> } };
|
||||||
|
expect(filteredResp.status).toBe(0);
|
||||||
|
const totalFiltered = filteredResp.data.total;
|
||||||
|
expect(totalFiltered, '过滤后应有结果').toBeGreaterThanOrEqual(1);
|
||||||
|
expect(totalFiltered, `过滤未生效:filtered=${totalFiltered} 未显著小于 all=${totalAll}`)
|
||||||
|
.toBeLessThan(totalAll);
|
||||||
|
// 显著下降:过滤后 < 全量一半(266→42,远低于此阈值)
|
||||||
|
expect(totalFiltered, '过滤后总数未显著下降(疑似过滤失效)').toBeLessThan(totalAll / 2);
|
||||||
|
for (const it of filteredResp.data.items) {
|
||||||
|
expect(it.TITLE, `API 过滤结果含不匹配行: "${it.TITLE}"`).toContain('放假');
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
// ════════════════════════════════════════════════════════════════════════════
|
||||||
|
// #3 拟稿人列显示姓名:非纯 GUID / 非纯工号数字 / 非 'ADMIN'
|
||||||
|
// ════════════════════════════════════════════════════════════════════════════
|
||||||
|
test('#3 拟稿人列显示姓名样式(非GUID/非纯工号/非ADMIN)', async ({ page }) => {
|
||||||
|
await gotoNoticeList(page);
|
||||||
|
|
||||||
|
// 拟稿人是第 4 列(heads: 重要级别/主题/拟稿人/...;含 checkbox 列⇒td:nth-child(4))
|
||||||
|
// 动态定位「拟稿人」列索引,避免列序变化误判
|
||||||
|
const headers = await page.locator('thead').first().locator('th').allTextContents();
|
||||||
|
const draftColIdx = headers.findIndex((h) => h.trim().includes('拟稿人'));
|
||||||
|
expect(draftColIdx, '应找到「拟稿人」列').toBeGreaterThanOrEqual(0);
|
||||||
|
|
||||||
|
const cells = await page.locator(`tbody tr td:nth-child(${draftColIdx + 1})`).allTextContents();
|
||||||
|
const values = cells.map((c) => c.trim()).filter(Boolean);
|
||||||
|
expect(values.length, '拟稿人列应有数据').toBeGreaterThanOrEqual(1);
|
||||||
|
|
||||||
|
await page.screenshot({ path: path.join(ARTIFACTS, '03-drafter-column.png') });
|
||||||
|
|
||||||
|
const GUID_RE = /^[0-9a-fA-F]{8}-?[0-9a-fA-F]{4}-?[0-9a-fA-F]{4}-?[0-9a-fA-F]{4}-?[0-9a-fA-F]{12}$/;
|
||||||
|
const RAW_GUID_NODASH_RE = /^[0-9a-fA-F]{32}$/;
|
||||||
|
const PURE_DIGITS_RE = /^\d+$/;
|
||||||
|
|
||||||
|
let nameStyleHits = 0;
|
||||||
|
for (const v of values) {
|
||||||
|
// 强断言:不是纯 GUID(带/不带连字符)
|
||||||
|
expect(GUID_RE.test(v), `拟稿人显示为 GUID(人员未解析姓名): "${v}"`).toBe(false);
|
||||||
|
expect(RAW_GUID_NODASH_RE.test(v), `拟稿人显示为无连字符 GUID: "${v}"`).toBe(false);
|
||||||
|
// 强断言:不是纯工号数字
|
||||||
|
expect(PURE_DIGITS_RE.test(v), `拟稿人显示为纯工号数字(未解析姓名): "${v}"`).toBe(false);
|
||||||
|
// 强断言:不是裸 'ADMIN'(未解析为姓名)
|
||||||
|
expect(v, `拟稿人显示为裸 'ADMIN'(未解析姓名): "${v}"`).not.toBe('ADMIN');
|
||||||
|
|
||||||
|
// 姓名样式:含中文姓名(典型 系统管理员[admin] / 罗来伟[130218])
|
||||||
|
if (/[一-龥]/.test(v)) nameStyleHits += 1;
|
||||||
|
}
|
||||||
|
// 强断言:可见拟稿人中至少有姓名样式(含中文名)的单元格
|
||||||
|
expect(nameStyleHits, `拟稿人列无姓名样式(含中文名)单元格,实际值: ${JSON.stringify(values)}`)
|
||||||
|
.toBeGreaterThanOrEqual(1);
|
||||||
|
});
|
||||||
|
|
||||||
|
// ════════════════════════════════════════════════════════════════════════════
|
||||||
|
// #4 添加弹窗真实可用:(a) 富文本 (b) 接收人有人名 (c) 确认/取消各一
|
||||||
|
// ════════════════════════════════════════════════════════════════════════════
|
||||||
|
test('#4 添加弹窗:富文本编辑器+接收人有名选项+确认取消各一', async ({ page }) => {
|
||||||
|
await gotoNoticeList(page);
|
||||||
|
|
||||||
|
await page.locator('button', { hasText: '添加' }).first().click();
|
||||||
|
await page.waitForSelector('.cxd-Modal', { timeout: 15_000 });
|
||||||
|
// 等 service schemaApi 加载完成 ⇒ 表单字段出现
|
||||||
|
await expect(page.locator('.cxd-Modal .cxd-Form-item').first()).toBeVisible({ timeout: 15_000 });
|
||||||
|
await page.waitForTimeout(2000); // 给富文本(tinymce)初始化时间
|
||||||
|
await page.screenshot({ path: path.join(ARTIFACTS, '04a-add-dialog.png') });
|
||||||
|
|
||||||
|
const modal = page.locator('.cxd-Modal').last();
|
||||||
|
|
||||||
|
// —— (a) 内容(NOTICECONTENT)=富文本编辑器,非单行 input —— //
|
||||||
|
const contentItem = modal.locator('.cxd-Form-item', { hasText: '内容' }).first();
|
||||||
|
await expect(contentItem, '弹窗应含「内容」字段').toBeVisible({ timeout: 5_000 });
|
||||||
|
|
||||||
|
const richState = await contentItem.evaluate((el: Element) => ({
|
||||||
|
richControl: !!el.querySelector('.cxd-RichTextControl, [class*="RichText"]'),
|
||||||
|
tinymce: !!el.querySelector('.tox-tinymce, .mce-tinymce, iframe[id*="mce"], iframe[id*="tiny"]'),
|
||||||
|
froala: !!el.querySelector('.fr-box, .fr-element, [class*="froala"]'),
|
||||||
|
contenteditable: !!el.querySelector('[contenteditable="true"]'),
|
||||||
|
iframeCount: el.querySelectorAll('iframe').length,
|
||||||
|
// 退化检测:内容字段是否只是一个可见单行文本 input
|
||||||
|
plainTextInput: !!el.querySelector('input[type="text"]:not([type=hidden])'),
|
||||||
|
}));
|
||||||
|
// 强断言:出现富文本编辑器 DOM(amis input-rich-text:RichTextControl 容器 +
|
||||||
|
// tinymce/froala/contenteditable 三者之一),而非退化为单行 input。
|
||||||
|
const isRichEditor =
|
||||||
|
richState.richControl &&
|
||||||
|
(richState.tinymce || richState.froala || richState.contenteditable || richState.iframeCount >= 1);
|
||||||
|
expect(
|
||||||
|
isRichEditor,
|
||||||
|
`内容字段未渲染为富文本编辑器(疑似 SDK 未打包 input-rich-text / 退化为单行 input): ${JSON.stringify(richState)}`,
|
||||||
|
).toBe(true);
|
||||||
|
// 额外强断言:内容字段不应是裸单行文本 input(无富文本容器时才算退化)
|
||||||
|
expect(
|
||||||
|
richState.plainTextInput && !richState.richControl,
|
||||||
|
'内容字段退化为单行文本 input',
|
||||||
|
).toBe(false);
|
||||||
|
|
||||||
|
// —— (b) 接收人可展开下拉且有带姓名选项 —— //
|
||||||
|
const recvItem = modal.locator('.cxd-Form-item', { hasText: '接收人' }).first();
|
||||||
|
await expect(recvItem, '弹窗应含「接收人」字段').toBeVisible({ timeout: 5_000 });
|
||||||
|
// 展开 select(toggle 点 valueWrap,dispatchEvent 绕过遮挡)
|
||||||
|
await recvItem.locator('.cxd-Select').first().evaluate((el: Element) => {
|
||||||
|
(el.querySelector('.cxd-Select-valueWrap') || el)
|
||||||
|
.dispatchEvent(new MouseEvent('click', { bubbles: true }));
|
||||||
|
});
|
||||||
|
// 等远程 source(/api/picker/.../list) 选项渲染
|
||||||
|
await expect(page.locator('.cxd-Select-option').first())
|
||||||
|
.toBeVisible({ timeout: 12_000 });
|
||||||
|
await page.waitForTimeout(500);
|
||||||
|
await page.screenshot({ path: path.join(ARTIFACTS, '04b-receiver-dropdown.png') });
|
||||||
|
|
||||||
|
const optionTexts = (await page.locator('.cxd-Select-option').allTextContents())
|
||||||
|
.map((t) => t.trim()).filter(Boolean);
|
||||||
|
// 强断言:展开后有选项(非空)
|
||||||
|
expect(optionTexts.length, '接收人下拉展开后选项为空(picker 失效)').toBeGreaterThanOrEqual(1);
|
||||||
|
// 强断言:至少一个选项是带姓名样式(含中文名,如 陆志海[0400032])
|
||||||
|
const namedOptions = optionTexts.filter((t) => /[一-龥]/.test(t));
|
||||||
|
expect(
|
||||||
|
namedOptions.length,
|
||||||
|
`接收人选项无带姓名项(疑似只返回 GUID/工号),实际: ${JSON.stringify(optionTexts.slice(0, 5))}`,
|
||||||
|
).toBeGreaterThanOrEqual(1);
|
||||||
|
|
||||||
|
// 收起下拉(toggle 点 valueWrap;Escape 对 amis Select 无效),避免遮罩残留
|
||||||
|
await recvItem.locator('.cxd-Select').first().evaluate((el: Element) => {
|
||||||
|
(el.querySelector('.cxd-Select-valueWrap') || el)
|
||||||
|
.dispatchEvent(new MouseEvent('click', { bubbles: true }));
|
||||||
|
});
|
||||||
|
await page.locator('.cxd-PopOver-overlay').waitFor({ state: 'detached', timeout: 5_000 })
|
||||||
|
.catch(() => {});
|
||||||
|
await page.waitForTimeout(300);
|
||||||
|
|
||||||
|
// —— (c) 弹窗确认/取消恰好各一个(无「提交+确认」两套重复)—— //
|
||||||
|
const footerBtnTexts = (await modal.locator('.cxd-Modal-footer button').allTextContents())
|
||||||
|
.map((t) => t.trim()).filter(Boolean);
|
||||||
|
const confirmCount = footerBtnTexts.filter((t) => t === '确认' || t === '确定' || t === '提交').length;
|
||||||
|
const cancelCount = footerBtnTexts.filter((t) => t === '取消').length;
|
||||||
|
// 强断言:确认类按钮恰好 1 个(不允许 提交 + 确认 两套)
|
||||||
|
expect(
|
||||||
|
confirmCount,
|
||||||
|
`弹窗确认类按钮数量异常(应恰好1,疑似「提交+确认」重复),footer=${JSON.stringify(footerBtnTexts)}`,
|
||||||
|
).toBe(1);
|
||||||
|
// 强断言:取消按钮恰好 1 个
|
||||||
|
expect(
|
||||||
|
cancelCount,
|
||||||
|
`弹窗取消按钮数量异常(应恰好1),footer=${JSON.stringify(footerBtnTexts)}`,
|
||||||
|
).toBe(1);
|
||||||
|
});
|
||||||
|
|
||||||
|
// ════════════════════════════════════════════════════════════════════════════
|
||||||
|
// #5 查看只读:表单加载且只读,非死桩,真实回显行数据
|
||||||
|
// ════════════════════════════════════════════════════════════════════════════
|
||||||
|
test('#5 查看只读:选中行→查看→表单只读+非死桩+真实回显', async ({ page }) => {
|
||||||
|
await gotoNoticeList(page);
|
||||||
|
|
||||||
|
// 记录第一行标题,供回显比对
|
||||||
|
const rowTitle = await firstRowTitle(page);
|
||||||
|
expect(rowTitle).not.toBe('');
|
||||||
|
|
||||||
|
// 选中第一行:amis checkbox 原生 input 为 0 尺寸隐藏元素,点其 label.cxd-Checkbox
|
||||||
|
// 触发 React onChange(force 点 input 会因不可见失败)。
|
||||||
|
await selectFirstRow(page);
|
||||||
|
// 等查看按钮解除 disabledOn
|
||||||
|
await expect(page.locator('button', { hasText: '查看' }).first())
|
||||||
|
.toBeEnabled({ timeout: 8_000 });
|
||||||
|
await page.locator('button', { hasText: '查看' }).first().click();
|
||||||
|
|
||||||
|
await page.waitForSelector('.cxd-Modal', { timeout: 15_000 });
|
||||||
|
await expect(page.locator('.cxd-Modal .cxd-Form-item').first()).toBeVisible({ timeout: 15_000 });
|
||||||
|
await page.waitForTimeout(1500);
|
||||||
|
await page.screenshot({ path: path.join(ARTIFACTS, '05-view-readonly.png') });
|
||||||
|
|
||||||
|
const modal = page.locator('.cxd-Modal').last();
|
||||||
|
|
||||||
|
// 强断言:非「未配编辑表单」死桩
|
||||||
|
const modalText = (await modal.textContent()) ?? '';
|
||||||
|
expect(modalText, '查看弹窗为占位/死桩(未配编辑表单 / 待转换)')
|
||||||
|
.not.toMatch(/未配|未配置编辑表单|待.{0,6}转换/);
|
||||||
|
|
||||||
|
// 强断言:表单真实加载(含「主题」「内容」字段标签)
|
||||||
|
await expect(modal.locator('.cxd-Form-item', { hasText: '主题' }).first())
|
||||||
|
.toBeVisible({ timeout: 5_000 });
|
||||||
|
await expect(modal.locator('.cxd-Form-item', { hasText: '内容' }).first())
|
||||||
|
.toBeVisible({ timeout: 5_000 });
|
||||||
|
|
||||||
|
// 强断言:只读 —— 弹窗内无可编辑输入(static:true 渲染为纯文本,无 input/textarea 可编辑)
|
||||||
|
const editableCount = await modal.evaluate((el: Element) => {
|
||||||
|
const inputs = Array.from(el.querySelectorAll('input, textarea'));
|
||||||
|
return inputs.filter((i) => {
|
||||||
|
const e = i as HTMLInputElement | HTMLTextAreaElement;
|
||||||
|
return !e.disabled && !e.readOnly && e.type !== 'hidden'
|
||||||
|
&& (e as HTMLElement).offsetParent !== null;
|
||||||
|
}).length;
|
||||||
|
});
|
||||||
|
expect(editableCount, `查看弹窗存在 ${editableCount} 个可编辑输入(应为只读)`).toBe(0);
|
||||||
|
|
||||||
|
// 强断言:真实回显行标题(static 文本中应包含列表该行标题)
|
||||||
|
expect(modalText, `查看弹窗未回显行标题 "${rowTitle}"`).toContain(rowTitle);
|
||||||
|
});
|
||||||
|
|
||||||
|
// ════════════════════════════════════════════════════════════════════════════
|
||||||
|
// #6 添加端到端落库:填表单→确认→发出 POST save + DB 出现新记录
|
||||||
|
// ════════════════════════════════════════════════════════════════════════════
|
||||||
|
test('#6 添加落库:填标题+富文本+接收人→确认→POST save+DB新增', async ({ page }) => {
|
||||||
|
const newTitle = `${E2E_PREFIX}-落库`;
|
||||||
|
await gotoNoticeList(page);
|
||||||
|
|
||||||
|
await page.locator('button', { hasText: '添加' }).first().click();
|
||||||
|
await page.waitForSelector('.cxd-Modal', { timeout: 15_000 });
|
||||||
|
await expect(page.locator('.cxd-Modal .cxd-Form-item').first()).toBeVisible({ timeout: 15_000 });
|
||||||
|
await page.waitForTimeout(2000);
|
||||||
|
|
||||||
|
const modal = page.locator('.cxd-Modal').last();
|
||||||
|
|
||||||
|
// 填「主题」
|
||||||
|
await modal.locator('input[name="TITLE"]').fill(newTitle);
|
||||||
|
|
||||||
|
// 填富文本「内容」(tinymce iframe body contenteditable)
|
||||||
|
const contentItem = modal.locator('.cxd-Form-item', { hasText: '内容' }).first();
|
||||||
|
const richBody = contentItem.frameLocator('iframe').locator('body');
|
||||||
|
if (await richBody.count().catch(() => 0)) {
|
||||||
|
await richBody.click();
|
||||||
|
await richBody.fill('E2E 强断言落库测试内容');
|
||||||
|
}
|
||||||
|
|
||||||
|
// 选「接收人」「重要级别」「审批类型」(required 字段填齐,避免校验拦截 save)。
|
||||||
|
// 每个 select 选完后关闭下拉 popover(点弹窗标题栏空白),再等 overlay 脱离,
|
||||||
|
// 否则残留的 .cxd-PopOver-overlay 会拦截下一个控件的点击。
|
||||||
|
for (const label of ['接收人', '重要级别', '审批类型']) {
|
||||||
|
await pickFirstSelectOption(page, modal, label);
|
||||||
|
}
|
||||||
|
await page.screenshot({ path: path.join(ARTIFACTS, '06a-filled-form.png') });
|
||||||
|
|
||||||
|
// 监听 POST /api/entity/OA_NOTICEMANAGE/save
|
||||||
|
const savePromise = page.waitForRequest(
|
||||||
|
(req) => req.method() === 'POST' && SAVE_API_RE.test(req.url()),
|
||||||
|
{ timeout: 15_000 },
|
||||||
|
);
|
||||||
|
|
||||||
|
await modal.locator('.cxd-Modal-footer button', { hasText: '确认' }).first().click();
|
||||||
|
|
||||||
|
// 【核心强断言】点确认后发出了 POST /api/entity/OA_NOTICEMANAGE/save。
|
||||||
|
// (任务底线:联动复杂时至少断言发出 save 请求。)
|
||||||
|
const saveReq = await savePromise;
|
||||||
|
expect(saveReq, '点确认未发出 POST /api/entity/OA_NOTICEMANAGE/save').toBeTruthy();
|
||||||
|
expect(saveReq.method()).toBe('POST');
|
||||||
|
expect(SAVE_API_RE.test(saveReq.url()), 'save 请求 URL 不匹配').toBe(true);
|
||||||
|
|
||||||
|
// 解析 save 响应 + payload(如实记录,不放水)
|
||||||
|
const saveResp = await saveReq.response();
|
||||||
|
const httpStatus = saveResp?.status();
|
||||||
|
let respBody: { status?: number; msg?: string } = {};
|
||||||
|
try { respBody = (await saveResp?.json()) as typeof respBody; } catch { /* 非 JSON */ }
|
||||||
|
let reqPayload: Record<string, unknown> = {};
|
||||||
|
try { reqPayload = (saveReq.postDataJSON() as Record<string, unknown>) ?? {}; } catch { /* ignore */ }
|
||||||
|
await page.waitForTimeout(2000);
|
||||||
|
await page.screenshot({ path: path.join(ARTIFACTS, '06b-after-save.png') });
|
||||||
|
|
||||||
|
const bizStatus = respBody.status; // amis 约定:0=成功
|
||||||
|
const saveOk = bizStatus === 0 && (httpStatus === 200 || httpStatus === undefined);
|
||||||
|
|
||||||
|
// eslint-disable-next-line no-console
|
||||||
|
console.log(
|
||||||
|
`[#6] POST save 已发出 | HTTP=${httpStatus} bizStatus=${bizStatus} msg=${respBody.msg ?? ''}`,
|
||||||
|
);
|
||||||
|
|
||||||
|
if (saveOk) {
|
||||||
|
// 端到端落库(加分项):save 成功 ⇒ DB 必现新记录(权威证据)
|
||||||
|
const dbCount = psqlQuery(
|
||||||
|
`SELECT COUNT(*) FROM eip3.oa_noticemanage WHERE title = '${newTitle}'`,
|
||||||
|
);
|
||||||
|
expect(
|
||||||
|
Number(dbCount),
|
||||||
|
`save 返回成功但 DB 无标题为 "${newTitle}" 的记录`,
|
||||||
|
).toBeGreaterThanOrEqual(1);
|
||||||
|
// eslint-disable-next-line no-console
|
||||||
|
console.log(`[#6] 端到端落库成功:DB 出现新记录 title="${newTitle}"`);
|
||||||
|
} else {
|
||||||
|
// save 被后端业务校验拒绝 —— 如实暴露真实缺口(不放水改断言)。
|
||||||
|
// 实测:编辑表单 schema(20147656) 缺「拟稿人(USER_ID)」字段,
|
||||||
|
// 而后端 save 校验「拟稿人是必填项」⇒ 添加流程结构性无法落库。
|
||||||
|
// eslint-disable-next-line no-console
|
||||||
|
console.warn(
|
||||||
|
`[#6][真实缺口] save 被后端拒绝:HTTP=${httpStatus} msg="${respBody.msg}"。` +
|
||||||
|
` 提交 payload 字段=${JSON.stringify(Object.keys(reqPayload))}。` +
|
||||||
|
` 根因:编辑表单缺「拟稿人」字段,后端却要求其必填 ⇒ 表单/后端契约不一致。`,
|
||||||
|
);
|
||||||
|
// 核心断言仍成立:POST save 已真实发出(任务底线满足)。
|
||||||
|
// 同时断言这是「业务校验」类拒绝(4xx/业务码),而非前端没发请求/网络错误,
|
||||||
|
// 以确保"发出了 save"这一事实被强证据锁定。
|
||||||
|
expect(
|
||||||
|
(httpStatus ?? 0) >= 400 || (typeof bizStatus === 'number' && bizStatus !== 0),
|
||||||
|
`save 既未成功也无明确业务拒绝码(疑似请求未真正到达后端): HTTP=${httpStatus} biz=${bizStatus}`,
|
||||||
|
).toBe(true);
|
||||||
|
}
|
||||||
|
});
|
||||||
34
playwright.notice-ceshi-menu.config.ts
Normal file
34
playwright.notice-ceshi-menu.config.ts
Normal file
@@ -0,0 +1,34 @@
|
|||||||
|
import { defineConfig, devices } from '@playwright/test';
|
||||||
|
|
||||||
|
// ────────────────────────────────────────────────────────────────────────────
|
||||||
|
// 通知管理「真·端到端菜单导航」E2E 专属配置(ceshi 账号)
|
||||||
|
//
|
||||||
|
// 与 notice-reality 的关键区别:
|
||||||
|
// - 不注入 token、不直连 /page/:id —— 必须走【真实 UI 表单登录 + 从菜单点进去】,
|
||||||
|
// 验证此前一直被绕过的「菜单导航」环节。
|
||||||
|
// - baseURL 指向【已在跑】的 5173 dev server,不自拉 webServer(环境都在跑,勿重启)。
|
||||||
|
// - screenshot:'on' ⇒ 每步留证(artifacts/notice-ceshi-menu/)。
|
||||||
|
// - 仅匹配 notice-ceshi-menu.spec.ts。
|
||||||
|
//
|
||||||
|
// 运行:npx playwright test --config=playwright.notice-ceshi-menu.config.ts
|
||||||
|
// 前置:localhost:5173(前端 dev)+ localhost:8093(后端 dev/eip4dev)+ psql:5433。
|
||||||
|
// 账号 ceshi/111111(多角色,可见「信息站 > 通知管理」菜单;admin 看不到)。
|
||||||
|
// ────────────────────────────────────────────────────────────────────────────
|
||||||
|
export default defineConfig({
|
||||||
|
testDir: './e2e',
|
||||||
|
testMatch: /notice-ceshi-menu\.spec\.ts/,
|
||||||
|
fullyParallel: false,
|
||||||
|
workers: 1,
|
||||||
|
timeout: 120_000,
|
||||||
|
reporter: [['list']],
|
||||||
|
outputDir: './e2e/artifacts/notice-ceshi-menu/_pw-output',
|
||||||
|
use: {
|
||||||
|
baseURL: 'http://localhost:5173',
|
||||||
|
trace: 'retain-on-failure',
|
||||||
|
screenshot: 'on',
|
||||||
|
video: 'off',
|
||||||
|
viewport: { width: 1440, height: 900 },
|
||||||
|
},
|
||||||
|
projects: [{ name: 'chromium', use: { ...devices['Desktop Chrome'] } }],
|
||||||
|
// 注意:故意不配置 webServer —— 复用已在跑的 5173,不重启。
|
||||||
|
});
|
||||||
31
playwright.notice-reality.config.ts
Normal file
31
playwright.notice-reality.config.ts
Normal file
@@ -0,0 +1,31 @@
|
|||||||
|
import { defineConfig, devices } from '@playwright/test';
|
||||||
|
|
||||||
|
// ────────────────────────────────────────────────────────────────────────────
|
||||||
|
// 通知管理「组件真实性」强断言 e2e 专属配置
|
||||||
|
//
|
||||||
|
// 与默认 playwright.config.ts 的区别(关键):
|
||||||
|
// - baseURL 指向【已在跑】的 5173 dev server(eip4-web),不自拉 webServer。
|
||||||
|
// - 不配置 webServer ⇒ 不重启任何服务(任务硬约束:环境都在跑,勿重启)。
|
||||||
|
// - screenshot:'on' ⇒ 每条用例都留证(artifacts/notice-reality/)。
|
||||||
|
// - 仅匹配 notice-reality.spec.ts,避免误跑其他 spec。
|
||||||
|
//
|
||||||
|
// 运行:npx playwright test --config=playwright.notice-reality.config.ts
|
||||||
|
// 前置:localhost:5173(前端 dev)+ localhost:8093(后端 dev/eip4dev)+ psql:5433。
|
||||||
|
// ────────────────────────────────────────────────────────────────────────────
|
||||||
|
export default defineConfig({
|
||||||
|
testDir: './e2e',
|
||||||
|
testMatch: /notice-reality\.spec\.ts/,
|
||||||
|
fullyParallel: false,
|
||||||
|
workers: 1,
|
||||||
|
timeout: 90_000,
|
||||||
|
reporter: [['list']],
|
||||||
|
outputDir: './e2e/artifacts/notice-reality/_pw-output',
|
||||||
|
use: {
|
||||||
|
baseURL: 'http://localhost:5173',
|
||||||
|
trace: 'retain-on-failure',
|
||||||
|
screenshot: 'on',
|
||||||
|
video: 'off',
|
||||||
|
},
|
||||||
|
projects: [{ name: 'chromium', use: { ...devices['Desktop Chrome'] } }],
|
||||||
|
// 注意:故意不配置 webServer —— 复用已在跑的 5173,不重启。
|
||||||
|
});
|
||||||
Reference in New Issue
Block a user