/** * ================================================================ * 场景:供应商入驻全流程 E2E 测试 * ================================================================ * 用户故事:供应商申请入驻,管理员审核 * * 流程步骤: * 1. 供应商提交入驻申请 * 2. 供应商查看入驻状态 * 3. 管理员审核供应商 * * 关键里程碑: * - [Milestone-1] 申请提交成功 * - [Milestone-2] 审核完成 * ================================================================ * * 运行:npx playwright test tests/e2e/vendor-onboarding.spec.js */ const { test, expect } = require('@playwright/test'); test.describe('【场景流程】供应商入驻全流程', () => { // ===== 场景1:供应商提交入驻申请 ===== test('[场景1] 供应商提交入驻申请 - 期望申请成功', async ({ page }) => { // ========== Given:供应商进入入驻申请页 ========== await page.goto('/#/pages/profile/vendor-apply'); await page.waitForLoadState('networkidle'); // ========== When:填写并提交申请 ========== await page.waitForSelector('.apply-form, .vendor-form', { timeout: 5000 }); // 选择服务商类型 const typeSelect = page.locator('.type-picker, select[name="vendorType"]'); if (await typeSelect.isVisible()) { await typeSelect.selectOption('product_supplier'); } // 填写资质说明 const infoInput = page.locator('textarea[name="vendorInfo"], .info-input'); if (await infoInput.isVisible()) { await infoInput.fill('我们是专业的商品供应商,提供优质的家庭用品。'); } // 提交申请 await page.click('.submit-btn, .apply-btn'); // ========== Then:Milestone-1 - 申请成功 ======== await page.waitForSelector('.success-tip, .apply-success, .toast-success', { timeout: 10000 }); expect(await page.locator('.success-tip, .apply-success').isVisible()).toBeTruthy(); }); // ===== 场景2:供应商查看入驻状态 ===== test('[场景2] 供应商查看入驻状态 - 期望返回当前状态', async ({ page }) => { // ========== Given:供应商进入状态查询页 ========== await page.goto('/#/pages/profile/vendor-status'); await page.waitForLoadState('networkidle'); // ========== When:查看状态 ========== await page.waitForSelector('.status-card, .vendor-status', { timeout: 10000 }); // ========== Then:返回状态信息 ======== const statusCard = page.locator('.status-card, .status-info'); if (await statusCard.isVisible()) { const statusText = await statusCard.textContent(); expect(statusText).toBeTruthy(); } }); // ===== 场景3:管理员审核供应商 ===== test('[场景3] 管理员审核供应商 - 期望审核成功', async ({ page }) => { // ========== Given:管理员进入供应商审核页 ========== await page.goto('/#/pages/admin/vendor-review'); await page.waitForLoadState('networkidle'); // ========== When:审核供应商 ========== await page.waitForSelector('.vendor-item, .vendor-row', { timeout: 10000 }); const pendingItem = page.locator('.vendor-item').first(); const approveBtn = pendingItem.locator('.approve-btn, .pass-btn'); if (await approveBtn.isVisible()) { await approveBtn.click(); } // ========== Then:Milestone-2 - 审核成功 ======== await page.waitForTimeout(500); // 验证状态变化 const statusTag = pendingItem.locator('.status-tag'); if (await statusTag.isVisible()) { const statusText = await statusTag.textContent(); expect(statusText).toMatch(/已通过|approved/i); } }); });