34 lines
2.5 KiB
TypeScript
34 lines
2.5 KiB
TypeScript
import { expect, test } from '@playwright/test'
|
|
|
|
const routes = [{ path: '/collection-purchase', component: 'Layout', menuName: 'GoAutoCollectionPurchase', title: '采集采购', visible: '0', children: [{ path: '/shopee-products', component: '/goauto/shopee-products/index', menuName: 'GoAutoShopeeProducts', title: '虾皮商品', visible: '0' }] }]
|
|
|
|
test('管理员可确认并手动启动规格自动匹配且查看摘要', async({ page, context }) => {
|
|
await context.addCookies([{ name: 'Admin-Token', value: 'prototype-test-token', domain: 'localhost', path: '/' }])
|
|
let started = false
|
|
let requestBody: Record<string, unknown> | null = null
|
|
await page.route('**/api/**', async route => {
|
|
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: routes }})
|
|
if (url.pathname.endsWith('/api/admin/v1/shopee-products')) return route.fulfill({ json: { code: 200, data: { items: [], total: 0, page: 1, pageSize: 20 }}})
|
|
if (url.pathname.endsWith('/api/admin/v1/shopee-spec-auto-match/runs/latest')) {
|
|
const run = started ? { id: 8, status: 'completed', processedCount: 12, confirmedCount: 9, unmatchedCount: 3 } : null
|
|
return route.fulfill({ json: { code: 200, data: { run }}})
|
|
}
|
|
if (url.pathname.endsWith('/api/admin/v1/shopee-spec-auto-match/runs')) {
|
|
requestBody = route.request().postDataJSON()
|
|
started = true
|
|
return route.fulfill({ status: 202, json: { code: 200, data: { run: { id: 8, status: 'running', processedCount: 0 }}}})
|
|
}
|
|
return route.fulfill({ json: { code: 200, data: [] }})
|
|
})
|
|
|
|
await page.goto('/#/shopee-products')
|
|
await page.getByRole('button', { name: '执行规格自动匹配', exact: true }).click()
|
|
await expect(page.getByText('将在后台处理最多 20 个符合条件的商品,并可能调用 AI。不会创建采购任务或订单。是否继续?', { exact: true })).toBeVisible()
|
|
await page.getByRole('button', { name: '开始执行', exact: true }).click()
|
|
await expect(page.getByText('最近一次:完成,处理 12,确认 9,未匹配 3', { exact: true })).toBeVisible()
|
|
expect(String(requestBody?.requestId || '')).toMatch(/^[0-9a-f-]{36}$/)
|
|
})
|