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:
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);
|
||||
}
|
||||
});
|
||||
Reference in New Issue
Block a user