vendor-onboarding.spec.js 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100
  1. /**
  2. * ================================================================
  3. * 场景:供应商入驻全流程 E2E 测试
  4. * ================================================================
  5. * 用户故事:供应商申请入驻,管理员审核
  6. *
  7. * 流程步骤:
  8. * 1. 供应商提交入驻申请
  9. * 2. 供应商查看入驻状态
  10. * 3. 管理员审核供应商
  11. *
  12. * 关键里程碑:
  13. * - [Milestone-1] 申请提交成功
  14. * - [Milestone-2] 审核完成
  15. * ================================================================
  16. *
  17. * 运行:npx playwright test tests/e2e/vendor-onboarding.spec.js
  18. */
  19. const { test, expect } = require('@playwright/test');
  20. test.describe('【场景流程】供应商入驻全流程', () => {
  21. // ===== 场景1:供应商提交入驻申请 =====
  22. test('[场景1] 供应商提交入驻申请 - 期望申请成功', async ({ page }) => {
  23. // ========== Given:供应商进入入驻申请页 ==========
  24. await page.goto('/#/pages/profile/vendor-apply');
  25. await page.waitForLoadState('networkidle');
  26. // ========== When:填写并提交申请 ==========
  27. await page.waitForSelector('.apply-form, .vendor-form', { timeout: 5000 });
  28. // 选择服务商类型
  29. const typeSelect = page.locator('.type-picker, select[name="vendorType"]');
  30. if (await typeSelect.isVisible()) {
  31. await typeSelect.selectOption('product_supplier');
  32. }
  33. // 填写资质说明
  34. const infoInput = page.locator('textarea[name="vendorInfo"], .info-input');
  35. if (await infoInput.isVisible()) {
  36. await infoInput.fill('我们是专业的商品供应商,提供优质的家庭用品。');
  37. }
  38. // 提交申请
  39. await page.click('.submit-btn, .apply-btn');
  40. // ========== Then:Milestone-1 - 申请成功 ========
  41. await page.waitForSelector('.success-tip, .apply-success, .toast-success', { timeout: 10000 });
  42. expect(await page.locator('.success-tip, .apply-success').isVisible()).toBeTruthy();
  43. });
  44. // ===== 场景2:供应商查看入驻状态 =====
  45. test('[场景2] 供应商查看入驻状态 - 期望返回当前状态', async ({ page }) => {
  46. // ========== Given:供应商进入状态查询页 ==========
  47. await page.goto('/#/pages/profile/vendor-status');
  48. await page.waitForLoadState('networkidle');
  49. // ========== When:查看状态 ==========
  50. await page.waitForSelector('.status-card, .vendor-status', { timeout: 10000 });
  51. // ========== Then:返回状态信息 ========
  52. const statusCard = page.locator('.status-card, .status-info');
  53. if (await statusCard.isVisible()) {
  54. const statusText = await statusCard.textContent();
  55. expect(statusText).toBeTruthy();
  56. }
  57. });
  58. // ===== 场景3:管理员审核供应商 =====
  59. test('[场景3] 管理员审核供应商 - 期望审核成功', async ({ page }) => {
  60. // ========== Given:管理员进入供应商审核页 ==========
  61. await page.goto('/#/pages/admin/vendor-review');
  62. await page.waitForLoadState('networkidle');
  63. // ========== When:审核供应商 ==========
  64. await page.waitForSelector('.vendor-item, .vendor-row', { timeout: 10000 });
  65. const pendingItem = page.locator('.vendor-item').first();
  66. const approveBtn = pendingItem.locator('.approve-btn, .pass-btn');
  67. if (await approveBtn.isVisible()) {
  68. await approveBtn.click();
  69. }
  70. // ========== Then:Milestone-2 - 审核成功 ========
  71. await page.waitForTimeout(500);
  72. // 验证状态变化
  73. const statusTag = pendingItem.locator('.status-tag');
  74. if (await statusTag.isVisible()) {
  75. const statusText = await statusTag.textContent();
  76. expect(statusText).toMatch(/已通过|approved/i);
  77. }
  78. });
  79. });