Status: ready-for-dev
作为测试开发者, 我想要编写编辑订单的 E2E 测试, 以便验证订单编辑功能。
Given 创建订单测试已通过 When 编写编辑订单测试用例 Then 包含以下测试场景:
编辑订单基本信息
编辑订单关联信息
编辑后验证列表更新
测试文件: web/tests/e2e/specs/admin/order-edit.spec.ts
web/tests/e2e/specs/admin/order-edit.spec.tsselectRadixOption 工具Epic 10: 订单管理 E2E 测试 (Epic C - 业务测试 Epic)
依赖:
Page Object 已有的编辑功能:
web/tests/e2e/pages/admin/order-management.page.ts 包含以下编辑相关方法:
打开编辑对话框:
async openEditDialog(orderName: string): Promise<void>
填写订单表单:
async fillOrderForm(data: OrderData): Promise<void>
selectRadixOption 工具选择下拉选项提交表单:
async submitForm(): Promise<FormSubmitResult>
编辑订单完整流程:
async editOrder(orderName: string, data: OrderData): Promise<FormSubmitResult>
创建测试订单: 编辑测试需要先有可编辑的订单。参考 Story 10.3 的测试数据策略:
// 使用时间戳创建唯一订单名称
const timestamp = Date.now();
const testOrderName = `编辑测试订单_${timestamp}`;
// 先创建订单
await orderManagementPage.createOrder({
name: testOrderName,
expectedStartDate: '2025-01-15',
platformName: '58同城', // 可选
companyName: '测试公司', // 可选
channelName: '网络招聘', // 可选
});
参考 Story 10.2(订单列表查看测试)和 Story 10.3(订单筛选测试)的测试结构:
import { test, expect } from '../../utils/test-setup';
import { OrderManagementPage } from '../../pages/admin/order-management.page';
import { selectRadixOption } from '@d8d/e2e-test-utils';
test.describe.serial('编辑订单测试', () => {
let testOrderName: string;
test.beforeEach(async ({ adminLoginPage, orderManagementPage }) => {
await adminLoginPage.goto();
await adminLoginPage.login('admin', 'admin123');
await orderManagementPage.goto();
// 创建测试订单
const timestamp = Date.now();
testOrderName = `编辑测试_${timestamp}`;
await orderManagementPage.createOrder({
name: testOrderName,
expectedStartDate: '2025-01-15',
});
});
test.describe('编辑订单基本信息', () => {
test('应该能修改订单名称', async ({ orderManagementPage }) => {
// 编辑订单名称
const newName = `${testOrderName}_已修改`;
await orderManagementPage.editOrder(testOrderName, {
name: newName,
});
// 验证列表中显示新名称
expect(await orderManagementPage.orderExists(newName)).toBe(true);
});
// 更多测试...
});
});
导入依赖:
import { test, expect } from '../../utils/test-setup';
import { OrderManagementPage, ORDER_STATUS, WORK_STATUS } from '../../pages/admin/order-management.page';
import { selectRadixOption } from '@d8d/e2e-test-utils';
测试 Fixtures:
adminLoginPage fixture 进行登录orderManagementPage fixture 操作页面test.describe.serial() 确保测试按顺序执行断言策略:
Select 工具使用(来自 Epic 1, 2):
import { selectRadixOption } from '@d8d/e2e-test-utils';
// 选择平台
await selectRadixOption(page, '平台', '58同城');
// 选择公司
await selectRadixOption(page, '公司', '新公司');
// 选择渠道
await selectRadixOption(page, '渠道', '现场招聘');
遵循以下测试标准文档:
docs/standards/testing-standards.md - 测试规范docs/standards/web-ui-testing-standards.md - Web UI 测试规范docs/standards/e2e-radix-testing.md - Radix UI E2E 测试标准选择器优先级:
data-testid - 最高优先级aria-label + roletext content + role - 兜底文件位置:
web/tests/e2e/specs/admin/order-edit.spec.tsweb/tests/e2e/pages/admin/order-management.page.tsweb/tests/e2e/fixtures/对齐统一项目结构:
project-context.md 中的 TypeScript 严格模式规则any 类型# 在 web 目录下运行单个测试文件
cd web
pnpm test:e2e:chromium order-edit
# 快速失败模式(推荐调试时使用)
timeout 60 pnpm test:e2e:chromium order-edit
编辑对话框交互:
表单预填充:
测试数据清理:
断言策略:
编辑订单基本信息:
编辑订单关联信息:
编辑后列表更新验证:
边界条件测试(可选):
从 Story 10.2(订单列表测试)学到的经验:
table tbody tr 选择器定位行getByText 精确匹配getByText 精确匹配从 Story 10.3(订单筛选测试)学到的经验:
locator('label').filter({ hasText: ... }) 避免与表头冲突waitForLoadState 超时处理(可能不触发网络请求)selectRadixOption 工具选择下拉选项表单数据接口:
interface OrderData {
name: string;
expectedStartDate?: string;
platformId?: number;
platformName?: string;
companyId?: number;
companyName?: string;
channelId?: number;
channelName?: string;
status?: OrderStatus;
workStatus?: WorkStatus;
}
表单提交结果接口:
interface FormSubmitResult {
success: boolean;
hasError: boolean;
hasSuccess: boolean;
errorMessage?: string;
successMessage?: string;
responses?: NetworkResponse[];
}
claude-opus-4-5-20251101