a2-ui-batch2.spec.ts 4.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798
  1. import { test, expect } from '../fixtures/auth';
  2. import type { Page, Response } from '@playwright/test';
  3. /**
  4. * A2 UI 回归 第二批:Material
  5. * Material:通过 routing-op-details 反查找到必有引用的样本 → 实测删除拦截
  6. *
  7. * Supplier UI 回归已迁移至 srm-fix-regression.spec.ts:使用 Supp=10001875 + SRM 引用样本
  8. * 验证删除 409 / S01006 拦截。BUG-S0-SRMPURCHASE-SCHEMA-MISMATCH(commit 50359ac3)已修复,
  9. * 原"SRM 不可用"Block 标记已废弃。
  10. */
  11. async function token(page: Page) {
  12. return page.evaluate(() => {
  13. for (let i = 0; i < localStorage.length; i++) {
  14. const k = localStorage.key(i)!;
  15. if (/access-token$/i.test(k) && !/x-access-token$/i.test(k)) {
  16. const raw = localStorage.getItem(k)!;
  17. try { const v = JSON.parse(raw); return typeof v === 'string' ? v : v?.value ?? raw; } catch { return raw; }
  18. }
  19. }
  20. return null;
  21. });
  22. }
  23. async function pickMaterialReferencedByRouting(page: Page): Promise<{ id: number; itemNum: string } | null> {
  24. const tk = await token(page);
  25. const headers = { Authorization: `Bearer ${tk!}` };
  26. const base = new URL(page.url()).origin;
  27. const r = await page.request.get(
  28. `${base}/api/s0/manufacturing/routing-op-details?page=1&pageSize=200&tenantId=1&factoryId=1`,
  29. { headers },
  30. );
  31. if (!r.ok()) return null;
  32. const codes: string[] = [...new Set<string>(((await r.json()).list ?? []).map((x: any) => x.materialCode).filter(Boolean))];
  33. for (const c of codes) {
  34. const lookup = await page.request.get(
  35. `${base}/api/s0/sales/materials?ItemNum=${encodeURIComponent(c)}&page=1&pageSize=5&tenantId=1&factoryId=1`,
  36. { headers },
  37. );
  38. const j = await lookup.json().catch(() => null);
  39. const hits = j?.list ?? [];
  40. if (hits.length > 0) return { id: Number(hits[0].id), itemNum: hits[0].itemNum };
  41. }
  42. return null;
  43. }
  44. test('Material 删除被工艺引用 → 409 + 红色 toast + 行未消失', async ({ authedPage }) => {
  45. await authedPage.goto('/#/dashboard/home', { waitUntil: 'domcontentloaded' });
  46. const sample = await pickMaterialReferencedByRouting(authedPage);
  47. test.skip(!sample, '未找到被 routing-op-details 引用的物料样本');
  48. test.info().annotations.push({ type: 'sample', description: JSON.stringify(sample) });
  49. await authedPage.goto('/#/aidop/s0/sales/material', { waitUntil: 'domcontentloaded' });
  50. await authedPage.waitForLoadState('networkidle', { timeout: 10_000 }).catch(() => {});
  51. await expect(authedPage.locator('table tbody tr').first()).toBeVisible({ timeout: 15_000 });
  52. // 页面筛选栏有两个输入:placeholder="编码/名称" 的 keyword + 物料编码单独输入
  53. const kw = authedPage.locator('input[placeholder*="编码/名称"]').first();
  54. await kw.fill(sample!.itemNum);
  55. await authedPage.getByRole('button', { name: /查询/ }).first().click();
  56. await authedPage.waitForLoadState('networkidle', { timeout: 5_000 }).catch(() => {});
  57. const row = authedPage.locator('tr', { hasText: sample!.itemNum }).first();
  58. await expect(row, '应在列表中找到目标物料').toBeVisible({ timeout: 10_000 });
  59. let deleteResp: Response | null = null;
  60. authedPage.on('response', (r) => {
  61. if (/\/api\/s0\/sales\/materials\/\d+/.test(r.url()) && r.request().method() === 'DELETE') deleteResp = r;
  62. });
  63. await row.getByRole('button', { name: /删除/ }).click();
  64. const confirm = authedPage.locator('.el-message-box').getByRole('button', { name: /确\s*定/ });
  65. await expect(confirm).toBeVisible({ timeout: 5_000 });
  66. await confirm.click();
  67. await expect.poll(() => deleteResp?.status() ?? 0, { timeout: 10_000 }).toBe(409);
  68. const body = await deleteResp!.json().catch(() => null);
  69. test.info().annotations.push({
  70. type: 'api',
  71. description: `DELETE → ${deleteResp!.status()} body=${JSON.stringify(body).slice(0, 200)}`,
  72. });
  73. expect(body?.code).toBe('S01006');
  74. expect(String(body?.message ?? '')).toMatch(/引用该物料|RoutingOpDetail|工艺路线|物料替代/);
  75. const errToast = authedPage.locator('.el-message--error, .el-message.is-error').first();
  76. await expect(errToast).toBeVisible({ timeout: 5_000 });
  77. const toastText = (await errToast.innerText()).replace(/\s+/g, '');
  78. test.info().annotations.push({ type: 'toast', description: toastText });
  79. expect(toastText).toMatch(/引用该物料|工艺路线|物料替代/);
  80. const okToast = authedPage.locator('.el-message--success').first();
  81. expect(await okToast.isVisible().catch(() => false), '不应出现 success toast').toBeFalsy();
  82. await authedPage.waitForLoadState('networkidle', { timeout: 5_000 }).catch(() => {});
  83. await expect(authedPage.locator('tr', { hasText: sample!.itemNum }).first()).toBeVisible({ timeout: 3_000 });
  84. });
  85. // Supplier UI 回归不再放在本文件;见 srm-fix-regression.spec.ts。