Files
goauto/web/tests/e2e/purchase-order-writeback.spec.ts
T

79 lines
5.6 KiB
TypeScript
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
import { expect, test } from '@playwright/test'
async function setup(page: any, state = 'not_started') {
await page.setViewportSize({ width: 1920, height: 1080 })
await page.context().addCookies([{ name: 'Admin-Token', value: 'test-only', domain: 'localhost', path: '/' }])
const requests: { path: string, body: any }[] = []
const items = [
{ id: 11, taskType: 'syb_order', executionMode: 'live', status: 'order_created', pddOrderNo: 'EXAMPLE-11', paymentReviewStatus: 'unpaid', orderWriteback: { status: state, canSubmit: ['not_started', 'failed', 'unknown'].includes(state), reason: state === 'conflict' ? 'SYB 已有不同单号,未覆盖' : '' } },
{ id: 12, taskType: 'syb_order', executionMode: 'live', status: 'failed', retryable: true, orderWriteback: { status: 'not_applicable', canSubmit: false, reason: '' } },
{ id: 13, taskType: 'stock', executionMode: 'live', status: 'order_created', orderWriteback: { status: 'not_applicable', canSubmit: false, reason: '' } }
]
await page.route('**/api/**', async route => {
const path = new URL(route.request().url()).pathname
if (path.endsWith('/getinfo')) return route.fulfill({ json: { code: 200, data: { roles: ['admin'], name: '测试采购员', avatar: '', introduction: '', permissions: [] } } })
if (path.endsWith('/menurole')) return route.fulfill({ json: { code: 200, data: [{ 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' }] }] } })
if (route.request().method() === 'POST') {
const body = route.request().postDataJSON()
requests.push({ path, body })
if (path.endsWith('/syb-order-writeback')) {
items[0].orderWriteback = { status: 'pending', canSubmit: false, reason: '' }
return route.fulfill({ json: { code: 200, data: { items: body.purchaseTaskIds.map((taskId: number) => ({ taskId, result: 'pending', reason: '已受理' })) } } })
}
if (path.endsWith('/batch-retry')) return route.fulfill({ json: { code: 200, data: { items: [], createdCount: 1, failedCount: 0 } } })
throw new Error('unexpected write: ' + path)
}
if (path.endsWith('/purchase-tasks/11')) return route.fulfill({ json: { code: 200, data: { task: items[0], attempts: [] } } })
if (path.endsWith('/purchase-tasks')) return route.fulfill({ json: { code: 200, data: { items, total: items.length } } })
return route.fulfill({ json: { code: 200, data: [] } })
})
await page.goto('/#/purchase-tasks/index')
await expect(page.getByText('CG-11', { exact: true })).toBeVisible()
return requests
}
test('混选任务分别回填与重试,不把已下单任务交给采购重试', async ({ page }) => {
const requests = await setup(page)
await page.locator('.el-table__header-wrapper .el-checkbox').click()
await expect(page.getByRole('button', { name: '重试(1)', exact: true })).toBeEnabled()
await expect(page.getByRole('button', { name: '批量回填 SYB(1)', exact: true })).toBeEnabled()
await page.getByRole('button', { name: '重试(1)', exact: true }).click()
const retry = page.getByRole('dialog', { name: '确认重试失败任务' })
await expect(retry.getByText('CG-12', { exact: true })).toBeVisible()
await expect(retry.getByText('CG-11', { exact: true })).toHaveCount(0)
await retry.getByRole('button', { name: '确认重试', exact: true }).click()
await expect.poll(() => requests.length).toBe(1)
expect(requests[0].body.taskIds).toEqual([12])
await page.getByRole('dialog', { name: '批量重试结果' }).getByRole('button', { name: '留在当前页' }).click()
await page.locator('.el-table__header-wrapper .el-checkbox').first().click()
await page.getByRole('button', { name: '批量回填 SYB(1)', exact: true }).click()
const result = page.getByRole('dialog', { name: 'SYB 单号回填提交结果' })
await expect(result.getByText('待回填', { exact: true })).toBeVisible()
expect(requests[1].body.purchaseTaskIds).toEqual([11])
expect(requests[1].body.requestId).toMatch(/^[0-9a-f-]{36}$/)
await result.getByRole('button', { name: '关闭', exact: true }).click()
await expect(result).toBeHidden()
await expect(page.getByRole('button', { name: '批量回填 SYB(0)', exact: true })).toBeDisabled()
})
test('未支付订单可从详情补偿回填,旧物流流程保持独立', async ({ page }) => {
const requests = await setup(page, 'failed')
await page.getByRole('button', { name: '详情', exact: true }).first().click()
const drawer = page.getByRole('dialog', { name: '采购任务详情' })
await expect(drawer.getByText('SYB 物流回填', { exact: true })).toBeVisible()
await drawer.getByRole('button', { name: '重试回填 SYB 单号', exact: true }).click()
await expect(page.getByRole('dialog', { name: 'SYB 单号回填提交结果' })).toBeVisible()
expect(requests).toHaveLength(1)
expect(requests[0].path).toContain('/syb-order-writeback')
expect(requests[0].body.purchaseTaskIds).toEqual([11])
})
test('冲突显示原因且没有覆盖按钮', async ({ page }) => {
await setup(page, 'conflict')
await page.getByRole('button', { name: '详情', exact: true }).first().click()
const drawer = page.getByRole('dialog', { name: '采购任务详情' })
await expect(drawer.getByText('单号冲突', { exact: true })).toBeVisible()
await expect(drawer.getByText('SYB 已有不同单号,未覆盖', { exact: true })).toBeVisible()
await expect(drawer.getByRole('button', { name: /回填 SYB 单号/ })).toHaveCount(0)
})