import { test, expect } from './fixtures';
import { gotoLeafPage, assertPageRendered, collectErrors, getRowCount } from './helpers';
/**
* Deployment/AppDeploy/Index 迁移 e2e(TDD)
*
* 自定义逻辑:
* - 列表含自定义操作列「部署节点 / 编译节点 / 版本 / 历史」跳转
* - 工具栏含「同步应用」(SyncApp) 自定义 Action(POST /Deployment/AppDeploy/SyncApp)
* - 后端 API:GET /api/Deployment/AppDeploy、POST /api/Deployment/AppDeploy/SyncApp(已验证可达)
*
* 任务要求还原的 MVC 跳转入口:
* - 部署节点 → /Deployment/AppDeployNode?deployId={Id}
* - 编译节点 → /Deployment/AppBuildNode?deployId={Id}
* - 版本 → /Deployment/AppDeployVersion?deployId={Id}
* - 历史 → /Deployment/AppDeployHistory?deployId={Id}
*
* 种子数据为空时列表 0 行属正常,仅校验:渲染 + 自定义操作列/跳转按钮存在 + 无 >=400 错误。
* 条件渲染按钮(如有)按 §2 对策:始终渲染 + :disabled,便于断言。
*/
test('Deployment/AppDeploy 页面渲染(列表 + 自定义操作列)', async ({ page }) => {
const errs = collectErrors(page);
await gotoLeafPage(page, 'Deployment/AppDeploy');
const rendered = await assertPageRendered(page);
expect(rendered).toBe('list');
// 列表主体:.list-page / .el-table
await expect(page.locator('main.cosmic-content .list-page')).toBeVisible();
await expect(page.locator('main.cosmic-content .el-table').first()).toBeVisible();
// 自定义跳转列(独立 el-table-column,不合并进操作列):部署节点 / 编译节点 / 版本 / 部署历史
for (const label of ['部署节点', '编译节点', '版本', '部署历史']) {
await expect(page.locator('main.cosmic-content').getByText(label, { exact: false }).first()).toBeVisible();
}
// 搜索栏(对齐 MVC _List_Search):类别 / 启用 / 时间
await expect(page.locator('main.cosmic-content').getByText('类别', { exact: false }).first()).toBeVisible();
await expect(page.locator('main.cosmic-content').getByText('启用', { exact: false }).first()).toBeVisible();
await expect(page.locator('main.cosmic-content').getByText('时间', { exact: false }).first()).toBeVisible();
// 工具栏:同步应用(SyncApp 自定义 Action)
await expect(page.locator('main.cosmic-content').getByText('同步应用', { exact: false }).first()).toBeVisible();
const captured = await errs;
if (captured.errors.length) {
console.log('NET_ERR=' + JSON.stringify(captured.errors));
throw new Error('存在接口/资源 >=400 错误: ' + JSON.stringify(captured.errors));
}
if (captured.consoleErrors.length) {
console.log('CONSOLE_ERR=' + JSON.stringify(captured.consoleErrors));
}
// 链接列(还原 MVC AddListField Url 跳转字段,自建为独立 el-table-column,渲染为 el-link=<a>):
// 部署节点 / 编译节点 / 版本 / 部署历史。断言表头含这些列,且数据行内该列为可点击链接。
const linkColumns = ['部署节点', '编译节点', '版本', '部署历史'];
for (const label of linkColumns) {
// 表头存在该列
await expect(
page.locator('main.cosmic-content .el-table__header').getByText(label, { exact: true }).first(),
).toBeVisible();
}
// 链接列单元格(el-link 渲染为 <a href>)仅在 row.Id 非空时渲染,row.Id 为空时降级为 <span>-</span>。
// 因此表头断言(上方 4 个链接列存在)是核心回归点;单元格侧仅做软断言:
// 若首行内有 <a>(即存在有 Id 的链接列),则证明链接列已生效,至少应有 1 个可点击链接。
const rowCount = await getRowCount(page);
if (rowCount > 0) {
const firstRow = page.locator('main.cosmic-content .el-table__body .el-table__row').first();
const linkCount = await firstRow.locator('a').count();
if (linkCount > 0) {
expect(linkCount).toBeGreaterThanOrEqual(1);
} else {
console.log('APPDEPLOY_LINKS_DEGRADED=首行 row.Id 为空,链接列降级为 -,跳过单元格 <a> 断言,表头断言已覆盖链接列存在');
}
} else {
console.log('APPDEPLOY_NO_ROWS=种子数据为空,跳过链接列单元格断言,仅保留表头/无400校验');
}
// 截图 1:列表态
await page.screenshot({
path: 'e2e/screenshots/Deployment/AppDeploy/list.png',
fullPage: true,
});
// 截图 2:触发 SyncApp(同步应用)关键 Action 后态
try {
await page
.locator('main.cosmic-content')
.getByRole('button', { name: '同步应用' })
.first()
.click({ timeout: 3000 });
await page.waitForTimeout(1200);
} catch (e) {
console.log('SYNCAPP_CLICK_SKIPPED=' + String(e));
}
await page.screenshot({
path: 'e2e/screenshots/Deployment/AppDeploy/after-syncapp.png',
fullPage: true,
});
expect(true).toBe(true);
});
|