a2-ui-batch2.spec.ts 5.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114
  1. import { test, expect } from '../fixtures/auth';
  2. import type { Page, Response } from '@playwright/test';
  3. /**
  4. * A2 UI 回归 第二批:Material / Supplier
  5. * Material:通过 routing-op-details 反查找到必有引用的样本 → 实测删除拦截
  6. * Supplier:唯一下游 SRM 列表接口 S01999 不可用,无法稳妥定位"必有引用"样本,标 Block
  7. */
  8. async function token(page: Page) {
  9. return page.evaluate(() => {
  10. for (let i = 0; i < localStorage.length; i++) {
  11. const k = localStorage.key(i)!;
  12. if (/access-token$/i.test(k) && !/x-access-token$/i.test(k)) {
  13. const raw = localStorage.getItem(k)!;
  14. try { const v = JSON.parse(raw); return typeof v === 'string' ? v : v?.value ?? raw; } catch { return raw; }
  15. }
  16. }
  17. return null;
  18. });
  19. }
  20. async function pickMaterialReferencedByRouting(page: Page): Promise<{ id: number; itemNum: string } | null> {
  21. const tk = await token(page);
  22. const headers = { Authorization: `Bearer ${tk!}` };
  23. const base = new URL(page.url()).origin;
  24. const r = await page.request.get(
  25. `${base}/api/s0/manufacturing/routing-op-details?page=1&pageSize=200&tenantId=1&factoryId=1`,
  26. { headers },
  27. );
  28. if (!r.ok()) return null;
  29. const codes: string[] = [...new Set<string>(((await r.json()).list ?? []).map((x: any) => x.materialCode).filter(Boolean))];
  30. for (const c of codes) {
  31. const lookup = await page.request.get(
  32. `${base}/api/s0/sales/materials?ItemNum=${encodeURIComponent(c)}&page=1&pageSize=5&tenantId=1&factoryId=1`,
  33. { headers },
  34. );
  35. const j = await lookup.json().catch(() => null);
  36. const hits = j?.list ?? [];
  37. if (hits.length > 0) return { id: Number(hits[0].id), itemNum: hits[0].itemNum };
  38. }
  39. return null;
  40. }
  41. test('Material 删除被工艺引用 → 409 + 红色 toast + 行未消失', async ({ authedPage }) => {
  42. await authedPage.goto('/#/dashboard/home', { waitUntil: 'domcontentloaded' });
  43. const sample = await pickMaterialReferencedByRouting(authedPage);
  44. test.skip(!sample, '未找到被 routing-op-details 引用的物料样本');
  45. test.info().annotations.push({ type: 'sample', description: JSON.stringify(sample) });
  46. await authedPage.goto('/#/aidop/s0/sales/material', { waitUntil: 'domcontentloaded' });
  47. await authedPage.waitForLoadState('networkidle', { timeout: 10_000 }).catch(() => {});
  48. await expect(authedPage.locator('table tbody tr').first()).toBeVisible({ timeout: 15_000 });
  49. // 页面筛选栏有两个输入:placeholder="编码/名称" 的 keyword + 物料编码单独输入
  50. const kw = authedPage.locator('input[placeholder*="编码/名称"]').first();
  51. await kw.fill(sample!.itemNum);
  52. await authedPage.getByRole('button', { name: /查询/ }).first().click();
  53. await authedPage.waitForLoadState('networkidle', { timeout: 5_000 }).catch(() => {});
  54. const row = authedPage.locator('tr', { hasText: sample!.itemNum }).first();
  55. await expect(row, '应在列表中找到目标物料').toBeVisible({ timeout: 10_000 });
  56. let deleteResp: Response | null = null;
  57. authedPage.on('response', (r) => {
  58. if (/\/api\/s0\/sales\/materials\/\d+/.test(r.url()) && r.request().method() === 'DELETE') deleteResp = r;
  59. });
  60. await row.getByRole('button', { name: /删除/ }).click();
  61. const confirm = authedPage.locator('.el-message-box').getByRole('button', { name: /确\s*定/ });
  62. await expect(confirm).toBeVisible({ timeout: 5_000 });
  63. await confirm.click();
  64. await expect.poll(() => deleteResp?.status() ?? 0, { timeout: 10_000 }).toBe(409);
  65. const body = await deleteResp!.json().catch(() => null);
  66. test.info().annotations.push({
  67. type: 'api',
  68. description: `DELETE → ${deleteResp!.status()} body=${JSON.stringify(body).slice(0, 200)}`,
  69. });
  70. expect(body?.code).toBe('S01006');
  71. expect(String(body?.message ?? '')).toMatch(/引用该物料|RoutingOpDetail|工艺路线|物料替代/);
  72. const errToast = authedPage.locator('.el-message--error, .el-message.is-error').first();
  73. await expect(errToast).toBeVisible({ timeout: 5_000 });
  74. const toastText = (await errToast.innerText()).replace(/\s+/g, '');
  75. test.info().annotations.push({ type: 'toast', description: toastText });
  76. expect(toastText).toMatch(/引用该物料|工艺路线|物料替代/);
  77. const okToast = authedPage.locator('.el-message--success').first();
  78. expect(await okToast.isVisible().catch(() => false), '不应出现 success toast').toBeFalsy();
  79. await authedPage.waitForLoadState('networkidle', { timeout: 5_000 }).catch(() => {});
  80. await expect(authedPage.locator('tr', { hasText: sample!.itemNum }).first()).toBeVisible({ timeout: 3_000 });
  81. });
  82. test('Supplier UI 回归 → Block(样本不足)', async ({ authedPage }) => {
  83. // 唯一下游 SRM 接口 S01999 schema mismatch,Reference checker 走 SafeCount 兜底为 0
  84. // 任何 Supplier DELETE 都会被放行 → 盲删风险高,按要求标 Block,不执行删除
  85. await authedPage.goto('/#/dashboard/home', { waitUntil: 'domcontentloaded' });
  86. const tk = await token(authedPage);
  87. const r = await authedPage.request.get(
  88. `${new URL(authedPage.url()).origin}/api/s0/supply/srm-purchases?page=1&pageSize=1&tenantId=1&factoryId=1`,
  89. { headers: { Authorization: `Bearer ${tk!}` } },
  90. );
  91. const body = await r.json().catch(() => null);
  92. test.info().annotations.push({
  93. type: 'block-reason',
  94. description: `SRM 列表接口 HTTP ${r.status()} body=${JSON.stringify(body).slice(0, 200)}`,
  95. });
  96. test.info().annotations.push({
  97. type: 'impact',
  98. description: 'SRM SafeCount 兜底为 0 → Supplier DELETE 会被放行 → 任何运行态删除都不安全;BUG-S0-SRMPURCHASE-SCHEMA-MISMATCH 修复前不做 UI 回归',
  99. });
  100. test.skip(true, 'Supplier 下游 SRM 不可用,标 Block;详见 annotations');
  101. });