import { test, expect } from '@playwright/test'; /** * 协作流程测试 * 核心路径:采购商创建计划 → 纺织厂确认 → 入库 → 采购商看到库存 * * 注意:这些测试需要真实的数据库连接和测试账号 * 在实际运行前需要配置测试环境 */ test.describe('协作流程 - 采购商视角', () => { test.beforeEach(async ({ page }) => { // 登录采购商账号(需要配置测试账号) await page.goto('/login'); // await loginAsPurchaser(page); }); test('采购商创建新计划', async ({ page }) => { // 导航到新建计划页面 await page.goto('/purchaser/plans/new'); // 验证页面加载 await expect(page.locator('h1')).toContainText('新建纺织计划'); // 填写计划表单 await page.fill('[name="productName"]', '测试产品'); await page.fill('[name="color"]', '红色'); await page.fill('[name="targetQuantity"]', '1000'); // 添加纱线配比 await page.click('text=添加纱线'); await page.fill('[name="yarnName"]', '测试纱线'); await page.fill('[name="ratio"]', '100'); // 提交表单 // await page.click('button[type="submit"]'); // 验证创建成功 // await expect(page).toHaveURL(/.*purchaser\/plans/); }); test('采购商查看计划列表', async ({ page }) => { await page.goto('/purchaser/plans'); // 验证页面加载 await expect(page.locator('h1')).toContainText('计划总览'); // 验证计划列表存在 await expect(page.locator('[data-testid="plan-list"]')).toBeVisible(); }); test('采购商查看库存', async ({ page }) => { await page.goto('/purchaser/warehouse'); // 验证页面加载 await expect(page.locator('h1')).toContainText('仓库管理'); // 验证库存列表 await expect(page.locator('[data-testid="inventory-list"]')).toBeVisible(); }); }); test.describe('协作流程 - 纺织厂视角', () => { test.beforeEach(async ({ page }) => { // 登录纺织厂账号 await page.goto('/login'); // await loginAsTextileFactory(page); }); test('纺织厂查看计划', async ({ page }) => { await page.goto('/textile/plans'); // 验证页面加载 await expect(page.locator('h1')).toContainText('计划总览'); // 验证计划列表 await expect(page.locator('[data-testid="plan-list"]')).toBeVisible(); }); test('纺织厂确认流程节点', async ({ page }) => { await page.goto('/textile/plans'); // 找到待确认的计划 const pendingPlan = page.locator('[data-testid="plan-card"]').first(); await expect(pendingPlan).toBeVisible(); // 展开计划详情 await pendingPlan.click(); // 点击确认按钮 // await page.click('[data-testid="confirm-step-button"]'); // 验证确认成功 // await expect(page.locator('[data-testid="step-completed"]')).toBeVisible(); }); test('纺织厂坯布入库', async ({ page }) => { await page.goto('/textile/plans'); // 找到进行中的计划 const activePlan = page.locator('[data-testid="plan-card"]').first(); await expect(activePlan).toBeVisible(); // 展开计划 await activePlan.click(); // 填写入库信息 // await page.fill('[data-testid="inbound-quantity"]', '100'); // await page.fill('[data-testid="inbound-rolls"]', '10'); // 提交入库 // await page.click('[data-testid="submit-inbound"]'); // 验证入库成功 // await expect(page.locator('[data-testid="inbound-success"]')).toBeVisible(); }); test('纺织厂查看坯布仓库', async ({ page }) => { await page.goto('/textile/fabric-warehouse'); // 验证页面加载 await expect(page.locator('h1')).toContainText('原坯布仓库'); // 验证库存列表 await expect(page.locator('[data-testid="fabric-inventory"]')).toBeVisible(); }); }); test.describe('数据同步验证', () => { test('入库后采购商实时看到库存更新', async ({ page, browser }) => { // 这个测试需要两个浏览器上下文模拟两个角色 const purchaserContext = await browser.newContext(); const textileContext = await browser.newContext(); const purchaserPage = await purchaserContext.newPage(); const textilePage = await textileContext.newPage(); try { // 采购商查看初始库存 await purchaserPage.goto('/purchaser/warehouse'); // const initialInventory = await getInventoryCount(purchaserPage); // 纺织厂执行入库 await textilePage.goto('/textile/plans'); // await textilePage.click('[data-testid="inbound-button"]'); // await textilePage.fill('[data-testid="quantity"]', '100'); // await textilePage.click('[data-testid="submit"]'); // 等待实时同步 await purchaserPage.waitForTimeout(2000); // 验证采购商看到更新后的库存 // const updatedInventory = await getInventoryCount(purchaserPage); // expect(updatedInventory).toBe(initialInventory + 100); } finally { await purchaserContext.close(); await textileContext.close(); } }); }); test.describe('分享链接流程', () => { test('通过分享链接导入计划', async ({ page }) => { // 访问分享链接 const shareToken = 'test-token'; await page.goto(`/import?token=${shareToken}`); // 验证导入页面加载 await expect(page.locator('h1')).toContainText('导入计划'); // 验证计划信息展示(不包含敏感信息) await expect(page.locator('[data-testid="plan-code"]')).toBeVisible(); await expect(page.locator('[data-testid="fabric-code"]')).toBeVisible(); // 确认导入 // await page.click('[data-testid="confirm-import"]'); // 验证导入成功 // await expect(page).toHaveURL(/.*textile\/plans/); }); });