118 lines
4.2 KiB
JavaScript
118 lines
4.2 KiB
JavaScript
/**
|
|
* 管理后台订单管理测试
|
|
*
|
|
* 测试用例:
|
|
* - 订单列表查看
|
|
* - 订单详情查看
|
|
* - 订单审批
|
|
* - 订单筛选
|
|
*/
|
|
|
|
const { test, expect, login } = require('../fixtures/auth');
|
|
|
|
test.describe('订单管理', () => {
|
|
test.beforeAll(async ({ browser }) => {
|
|
// 确保已登录
|
|
const context = await browser.newContext();
|
|
const page = await context.newPage();
|
|
await login(page, 'admin');
|
|
await context.close();
|
|
});
|
|
|
|
test('查看订单列表', async ({ adminPage }) => {
|
|
// 导航到订单列表页
|
|
await adminPage.goto('/orders');
|
|
|
|
// 等待页面加载
|
|
await adminPage.waitForSelector('.order-list, .el-table, [data-testid="order-list"]', { timeout: 10000 });
|
|
|
|
// 验证订单列表存在
|
|
const orderList = adminPage.locator('.order-list, .el-table, [data-testid="order-list"]');
|
|
await expect(orderList).toBeVisible();
|
|
|
|
// 验证有订单数据(或空状态提示)
|
|
const hasOrders = await adminPage.locator('.order-item, .el-table__row, tr').count() > 0;
|
|
const hasEmptyState = await adminPage.locator('.empty-state, .el-empty, [data-testid="empty"]').isVisible().catch(() => false);
|
|
|
|
// 应该有订单或显示空状态
|
|
expect(hasOrders || hasEmptyState).toBeTruthy();
|
|
});
|
|
|
|
test('订单状态筛选', async ({ adminPage }) => {
|
|
await adminPage.goto('/orders');
|
|
|
|
// 等待页面加载
|
|
await adminPage.waitForSelector('.order-list, .el-table', { timeout: 10000 });
|
|
|
|
// 查找状态筛选器
|
|
const statusFilter = adminPage.locator('select[name="status"], .status-filter, [data-testid="status-filter"]');
|
|
|
|
if (await statusFilter.isVisible({ timeout: 3000 }).catch(() => false)) {
|
|
// 选择"待审核"状态
|
|
await statusFilter.selectOption('pending_approve');
|
|
|
|
// 点击搜索/筛选按钮
|
|
const searchBtn = adminPage.locator('button:has-text("搜索"), button:has-text("查询"), .search-btn');
|
|
if (await searchBtn.isVisible({ timeout: 2000 }).catch(() => false)) {
|
|
await searchBtn.click();
|
|
}
|
|
|
|
// 等待筛选结果
|
|
await adminPage.waitForTimeout(1000);
|
|
}
|
|
});
|
|
|
|
test('查看订单详情', async ({ adminPage }) => {
|
|
await adminPage.goto('/orders');
|
|
|
|
// 等待订单列表加载
|
|
await adminPage.waitForSelector('.order-list, .el-table', { timeout: 10000 });
|
|
|
|
// 点击第一个订单的详情按钮
|
|
const detailBtn = adminPage.locator('button:has-text("详情"), a:has-text("详情"), .detail-btn').first();
|
|
|
|
if (await detailBtn.isVisible({ timeout: 3000 }).catch(() => false)) {
|
|
await detailBtn.click();
|
|
|
|
// 等待详情页加载
|
|
await adminPage.waitForSelector('.order-detail, .detail-page, [data-testid="order-detail"]', { timeout: 10000 });
|
|
|
|
// 验证详情页显示
|
|
const detailPage = adminPage.locator('.order-detail, .detail-page, [data-testid="order-detail"]');
|
|
await expect(detailPage).toBeVisible();
|
|
}
|
|
});
|
|
|
|
test('审批订单', async ({ adminPage }) => {
|
|
// 导航到审批列表
|
|
await adminPage.goto('/approvals');
|
|
|
|
// 等待页面加载
|
|
await adminPage.waitForSelector('.approval-list, .el-table, [data-testid="approval-list"]', { timeout: 10000 });
|
|
|
|
// 查找待审批订单
|
|
const approveBtn = adminPage.locator('button:has-text("审批"), button:has-text("通过")').first();
|
|
|
|
if (await approveBtn.isVisible({ timeout: 3000 }).catch(() => false)) {
|
|
// 点击审批按钮
|
|
await approveBtn.click();
|
|
|
|
// 填写审批意见
|
|
const opinionInput = adminPage.locator('textarea[name="opinion"], .opinion-input, [data-testid="opinion"]');
|
|
if (await opinionInput.isVisible({ timeout: 2000 }).catch(() => false)) {
|
|
await opinionInput.fill('测试审批通过');
|
|
}
|
|
|
|
// 确认审批
|
|
const confirmBtn = adminPage.locator('button:has-text("确认"), button:has-text("提交")');
|
|
if (await confirmBtn.isVisible({ timeout: 2000 }).catch(() => false)) {
|
|
await confirmBtn.click();
|
|
|
|
// 验证审批成功提示
|
|
const successMsg = adminPage.locator('.success-message, .el-message--success, [data-testid="success"]');
|
|
await expect(successMsg).toBeVisible({ timeout: 5000 });
|
|
}
|
|
}
|
|
});
|
|
});
|