150 lines
6.5 KiB
JavaScript
150 lines
6.5 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, 'salesman');
|
||
await context.close();
|
||
});
|
||
|
||
test('创建订单页面加载', async ({ salesmanPage }) => {
|
||
// 导航到创建订单页
|
||
await salesmanPage.goto('/orders/create');
|
||
|
||
// 等待页面加载
|
||
await salesmanPage.waitForSelector('.order-form, .create-order, [data-testid="order-form"]', { timeout: 10000 });
|
||
|
||
// 验证表单元素存在
|
||
const customerNameInput = salesmanPage.locator('input[name="customerName"], input[placeholder*="客户"], #customerName');
|
||
await expect(customerNameInput).toBeVisible();
|
||
});
|
||
|
||
test('填写订单基本信息', async ({ salesmanPage }) => {
|
||
await salesmanPage.goto('/orders/create');
|
||
await salesmanPage.waitForSelector('.order-form, .create-order', { timeout: 10000 });
|
||
|
||
// 填写客户信息
|
||
const customerNameInput = salesmanPage.locator('input[name="customerName"], input[placeholder*="客户"], #customerName').first();
|
||
const customerMobileInput = salesmanPage.locator('input[name="customerMobile"], input[placeholder*="手机"], #customerMobile').first();
|
||
|
||
await customerNameInput.fill('测试客户E2E');
|
||
await customerMobileInput.fill('13800001234');
|
||
|
||
// 验证输入成功
|
||
await expect(customerNameInput).toHaveValue('测试客户E2E');
|
||
await expect(customerMobileInput).toHaveValue('13800001234');
|
||
});
|
||
|
||
test('添加订单明细', async ({ salesmanPage }) => {
|
||
await salesmanPage.goto('/orders/create');
|
||
await salesmanPage.waitForSelector('.order-form, .create-order', { timeout: 10000 });
|
||
|
||
// 填写客户信息
|
||
await salesmanPage.fill('input[name="customerName"], input[placeholder*="客户"]', '明细测试客户');
|
||
await salesmanPage.fill('input[name="customerMobile"], input[placeholder*="手机"]', '13800005678');
|
||
|
||
// 添加明细行
|
||
const addBtn = salesmanPage.locator('button:has-text("添加"), button:has-text("新增明细"), .add-item-btn');
|
||
if (await addBtn.isVisible({ timeout: 3000 }).catch(() => false)) {
|
||
await addBtn.click();
|
||
|
||
// 填写明细信息
|
||
const productSelect = salesmanPage.locator('select[name*="product"], .product-select').first();
|
||
if (await productSelect.isVisible({ timeout: 2000 }).catch(() => false)) {
|
||
await productSelect.selectOption({ index: 1 });
|
||
}
|
||
|
||
const quantityInput = salesmanPage.locator('input[name*="quantity"], input[placeholder*="数量"]').first();
|
||
if (await quantityInput.isVisible({ timeout: 2000 }).catch(() => false)) {
|
||
await quantityInput.fill('10');
|
||
}
|
||
|
||
const salePriceInput = salesmanPage.locator('input[name*="salePrice"], input[placeholder*="售价"]').first();
|
||
if (await salePriceInput.isVisible({ timeout: 2000 }).catch(() => false)) {
|
||
await salePriceInput.fill('100');
|
||
}
|
||
|
||
const costPriceInput = salesmanPage.locator('input[name*="costPrice"], input[placeholder*="成本"]').first();
|
||
if (await costPriceInput.isVisible({ timeout: 2000 }).catch(() => false)) {
|
||
await costPriceInput.fill('60');
|
||
}
|
||
}
|
||
});
|
||
|
||
test('提交订单', async ({ salesmanPage }) => {
|
||
await salesmanPage.goto('/orders/create');
|
||
await salesmanPage.waitForSelector('.order-form, .create-order', { timeout: 10000 });
|
||
|
||
// 填写完整订单信息
|
||
await salesmanPage.fill('input[name="customerName"], input[placeholder*="客户"]', '提交测试客户');
|
||
await salesmanPage.fill('input[name="customerMobile"], input[placeholder*="手机"]', '13800009999');
|
||
|
||
// 添加明细
|
||
const addBtn = salesmanPage.locator('button:has-text("添加"), button:has-text("新增明细"), .add-item-btn');
|
||
if (await addBtn.isVisible({ timeout: 3000 }).catch(() => false)) {
|
||
await addBtn.click();
|
||
|
||
// 填写明细
|
||
await salesmanPage.fill('input[name*="quantity"], input[placeholder*="数量"]', '5');
|
||
await salesmanPage.fill('input[name*="salePrice"], input[placeholder*="售价"]', '100');
|
||
await salesmanPage.fill('input[name*="costPrice"], input[placeholder*="成本"]', '60');
|
||
}
|
||
|
||
// 点击保存按钮
|
||
const saveBtn = salesmanPage.locator('button:has-text("保存"), button:has-text("提交"), .save-btn');
|
||
if (await saveBtn.isVisible({ timeout: 3000 }).catch(() => false)) {
|
||
await saveBtn.click();
|
||
|
||
// 等待保存结果
|
||
await salesmanPage.waitForTimeout(2000);
|
||
|
||
// 验证成功提示或跳转
|
||
const successMsg = salesmanPage.locator('.success-message, .el-message--success, [data-testid="success"]');
|
||
const isRedirected = salesmanPage.url().includes('/orders') && !salesmanPage.url().includes('/create');
|
||
|
||
// 应该显示成功消息或跳转到订单列表
|
||
const isSuccess = await successMsg.isVisible({ timeout: 5000 }).catch(() => false) || isRedirected;
|
||
expect(isSuccess).toBeTruthy();
|
||
}
|
||
});
|
||
|
||
test('利润计算验证', async ({ salesmanPage }) => {
|
||
await salesmanPage.goto('/orders/create');
|
||
await salesmanPage.waitForSelector('.order-form, .create-order', { timeout: 10000 });
|
||
|
||
// 填写订单信息
|
||
await salesmanPage.fill('input[name="customerName"], input[placeholder*="客户"]', '利润测试客户');
|
||
await salesmanPage.fill('input[name="customerMobile"], input[placeholder*="手机"]', '13800007777');
|
||
|
||
// 添加明细
|
||
const addBtn = salesmanPage.locator('button:has-text("添加"), button:has-text("新增明细"), .add-item-btn');
|
||
if (await addBtn.isVisible({ timeout: 3000 }).catch(() => false)) {
|
||
await addBtn.click();
|
||
|
||
// 填写售价和成本
|
||
await salesmanPage.fill('input[name*="quantity"], input[placeholder*="数量"]', '1');
|
||
await salesmanPage.fill('input[name*="salePrice"], input[placeholder*="售价"]', '100');
|
||
await salesmanPage.fill('input[name*="costPrice"], input[placeholder*="成本"]', '60');
|
||
|
||
// 检查利润显示
|
||
const profitDisplay = salesmanPage.locator('.profit, [data-testid="profit"], text=/利润/');
|
||
if (await profitDisplay.isVisible({ timeout: 3000 }).catch(() => false)) {
|
||
const profitText = await profitDisplay.textContent();
|
||
// 利润应该约为 40(100-60)
|
||
expect(profitText).toMatch(/40|利润/);
|
||
}
|
||
}
|
||
});
|
||
});
|