test: verify optional order amount in purchase detail (#306)

This commit is contained in:
QiuSW
2026-09-18 09:30:20 +08:00
parent d35d7354d6
commit 07a3817591
+37 -4
View File
@@ -1,5 +1,7 @@
import { expect, test } from '@playwright/test';
const purchaseTaskRoute = [{ path: '/collection-purchase', component: 'Layout', menuName: 'GoAutoCollectionPurchase', title: '采集采购', visible: '0', children: [{ path: '/purchase-tasks/index', component: '/goauto/purchase-tasks/index', menuName: 'GoAutoPurchaseTasks', title: '采购管理', visible: '0' }] }];
const task = {
id: 11,
executionMode: 'live',
@@ -35,8 +37,8 @@ const task = {
createdAt: '2026-08-20T08:00:00Z',
};
async function mockAdmin(page: any, status = 'order_created') {
let current = { ...task, status };
async function mockAdmin(page: any, status = 'order_created', pddOrderAmountCent: number | null = 2298) {
let current = { ...task, status, pddOrderAmountCent };
let paymentPayload: any;
let listQuery: URLSearchParams | undefined;
await page.context().addCookies([{ name: 'Admin-Token', value: 'prototype-test-token', domain: 'localhost', path: '/' }]);
@@ -44,6 +46,7 @@ async function mockAdmin(page: any, status = 'order_created') {
const url = new URL(route.request().url());
if (url.pathname.startsWith('/src/api/')) return route.continue();
if (url.pathname.endsWith('/api/v1/getinfo')) return route.fulfill({ json: { code: 200, data: { roles: ['admin'], name: '管理员', avatar: '', introduction: '', permissions: [] } } });
if (url.pathname.endsWith('/api/v1/menurole')) return route.fulfill({ json: { code: 200, data: purchaseTaskRoute } });
if (url.pathname.endsWith('/api/admin/v1/purchase-tasks/11/payment-review')) {
paymentPayload = route.request().postDataJSON();
current = { ...current, paymentReviewStatus: paymentPayload.status, paymentReviewedAt: '2026-08-20T09:00:00Z' };
@@ -63,7 +66,7 @@ async function mockAdmin(page: any, status = 'order_created') {
test('采购管理只管理已有任务,并可复核支付状态', async ({ page }) => {
const state = await mockAdmin(page);
await page.goto('http://localhost:9527/#/purchase-tasks/index');
await page.goto('/#/purchase-tasks/index');
await expect(page.locator('.page-heading')).toHaveCount(0);
await expect(page.getByLabel('模式')).toHaveCount(0);
@@ -88,9 +91,39 @@ test('采购管理只管理已有任务,并可复核支付状态', async ({ pa
await expect(page.getByText('已支付', { exact: true }).first()).toBeVisible();
});
test('采购详情显示已获取的实付价格', async ({ page }) => {
await page.setViewportSize({ width: 1920, height: 1080 });
await mockAdmin(page, 'order_created', 2298);
await page.goto('/#/purchase-tasks/index');
await page.getByRole('button', { name: '详情' }).click();
const orderCard = page.locator('.state-card').filter({ hasText: '实付价格:CNY 22.98' });
await orderCard.evaluate(element => element.scrollIntoView({ block: 'center' }));
await expect(orderCard).toBeInViewport();
const amountText = page.getByText('实付价格:CNY 22.98');
await expect(amountText).toBeVisible();
await expect(amountText).toBeInViewport();
await page.waitForTimeout(1000);
await page.screenshot({ path: 'test-results/issue-306-paid-amount.png', fullPage: true });
});
test('采购详情明确显示尚未获取实付价格', async ({ page }) => {
await page.setViewportSize({ width: 1920, height: 1080 });
await mockAdmin(page, 'order_created', null);
await page.goto('/#/purchase-tasks/index');
await page.getByRole('button', { name: '详情' }).click();
const orderCard = page.locator('.state-card').filter({ hasText: '实付价格:尚未获取' });
await orderCard.evaluate(element => element.scrollIntoView({ block: 'center' }));
await expect(orderCard).toBeInViewport();
const amountText = page.getByText('实付价格:尚未获取');
await expect(amountText).toBeVisible();
await expect(amountText).toBeInViewport();
await page.waitForTimeout(1000);
await page.screenshot({ path: 'test-results/issue-306-paid-amount-missing.png', fullPage: true });
});
test('订单结果未知时明确禁止重复采购并可人工解除', async ({ page }) => {
await mockAdmin(page, 'order_result_unknown');
await page.goto('http://localhost:9527/#/purchase-tasks/index');
await page.goto('/#/purchase-tasks/index');
await page.getByRole('button', { name: '详情' }).click();
await expect(page.getByText('订单结果未知,禁止重复采购')).toBeVisible();