From 07a3817591ab64ecbd1c528cc60b799fc43cf411 Mon Sep 17 00:00:00 2001 From: QiuSW <105186638@qq.com> Date: Fri, 18 Sep 2026 09:30:20 +0800 Subject: [PATCH] test: verify optional order amount in purchase detail (#306) --- web/tests/e2e/purchase-task-module.spec.ts | 41 +++++++++++++++++++--- 1 file changed, 37 insertions(+), 4 deletions(-) diff --git a/web/tests/e2e/purchase-task-module.spec.ts b/web/tests/e2e/purchase-task-module.spec.ts index 87930a3..bfa940e 100644 --- a/web/tests/e2e/purchase-task-module.spec.ts +++ b/web/tests/e2e/purchase-task-module.spec.ts @@ -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();