98 lines
8.7 KiB
TypeScript
98 lines
8.7 KiB
TypeScript
import { expect, test } from '@playwright/test'
|
|
|
|
const routes = [{ path: '/goauto-order-workbench', component: 'Layout', menuName: 'GoAutoOrderWorkbench', title: '订单工作台', visible: '0', children: [{ path: '/shopee-products', component: '/goauto/shopee-products/index', menuName: 'GoAutoShopeeProducts', title: '虾皮商品', visible: '0' }] }]
|
|
|
|
test('PDD 选择器默认最近五条并支持搜索与清空回退', async({ page, context }) => {
|
|
await context.addCookies([{ name: 'Admin-Token', value: 'prototype-test-token', domain: 'localhost', path: '/' }])
|
|
await page.route('**/static/**', route => route.fulfill({ status: 200, contentType: 'image/png', body: Buffer.from('iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAQAAAC1HAwCAAAAC0lEQVR42mNk+A8AAQUBAScY42YAAAAASUVORK5CYII=', 'base64') }))
|
|
const listURLs: URL[] = []
|
|
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: ['purchaser'], 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: [{ id: 9, shopeeItemId: 'S9', title: '待关联商品', shopName: '测试店', specs: [] }], total: 1, page: 1, pageSize: 20 }}})
|
|
if (url.pathname.endsWith('/api/admin/v1/pdd-products')) {
|
|
listURLs.push(url)
|
|
const keyword = url.searchParams.get('keyword')
|
|
const item = keyword ? { id: 2, goodsId: '222222', title: '搜索商品', shopName: '搜索店', status: 'disabled', updatedAt: '2026-08-30T10:00:00Z' } : { id: 1, goodsId: '111111', title: '最近商品', shopName: '最近店', status: 'active', updatedAt: '2026-08-31T10:00:00Z', colorImages: [{ color: '黑色', imagePath: '/static/uploadfile/goauto-color/test.jpg' }] }
|
|
return route.fulfill({ json: { code: 200, data: { items: [item, ...(keyword ? [] : [{ id: 3, goodsId: '333333', title: '无图商品', shopName: '', status: 'active', updatedAt: '2026-08-29T10:00:00Z' }])], total: keyword ? 1 : 2, page: 1, pageSize: Number(url.searchParams.get('pageSize')) }}})
|
|
}
|
|
return route.fulfill({ json: { code: 200, data: [] }})
|
|
})
|
|
await page.goto('/#/shopee-products')
|
|
await page.getByRole('button', { name: '添加', exact: true }).click()
|
|
await page.getByRole('button', { name: '搜索并选择', exact: true }).click()
|
|
await expect(page.getByText('最近商品', { exact: true })).toBeVisible()
|
|
await expect(page.getByText('暂无图片', { exact: true }).first()).toBeVisible()
|
|
const pickerImage = page.getByRole('img', { name: '黑色颜色图,单击或双击查看大图' })
|
|
await pickerImage.click()
|
|
await expect(page.locator('.el-image-viewer__wrapper')).toBeVisible()
|
|
await page.locator('.el-image-viewer__close').click()
|
|
await expect(page.getByText('最近商品', { exact: true })).toBeVisible()
|
|
await pickerImage.dblclick()
|
|
await expect(page.locator('.el-image-viewer__wrapper')).toBeVisible()
|
|
await page.locator('.el-image-viewer__close').click()
|
|
await expect(page.getByText('已选择 PDD-1', { exact: true })).toHaveCount(0)
|
|
expect(listURLs[0].searchParams.get('pageSize')).toBe('5')
|
|
expect(listURLs[0].searchParams.get('status')).toBe('active')
|
|
expect(listURLs[0].searchParams.has('keyword')).toBe(false)
|
|
await page.getByPlaceholder('goods_id、标题或店铺').fill('222222')
|
|
await page.getByRole('button', { name: '搜索', exact: true }).click()
|
|
await expect(page.getByText('搜索商品', { exact: true })).toBeVisible()
|
|
expect(listURLs.at(-1)?.searchParams.get('pageSize')).toBe('20')
|
|
expect(listURLs.at(-1)?.searchParams.get('keyword')).toBe('222222')
|
|
expect(listURLs.at(-1)?.searchParams.has('status')).toBe(false)
|
|
await expect(page.getByRole('button', { name: '选择', exact: true })).toBeDisabled()
|
|
await page.getByPlaceholder('goods_id、标题或店铺').fill('')
|
|
await page.getByPlaceholder('goods_id、标题或店铺').press('Enter')
|
|
await expect(page.getByText('最近商品', { exact: true })).toBeVisible()
|
|
expect(listURLs.at(-1)?.searchParams.get('pageSize')).toBe('5')
|
|
expect(listURLs.at(-1)?.searchParams.get('status')).toBe('active')
|
|
})
|
|
|
|
test('虾皮详情一键匹配颜色尺码后直接使用并可原地叠加 PDD 抽屉', async({ page, context }) => {
|
|
await context.addCookies([{ name: 'Admin-Token', value: 'prototype-test-token', domain: 'localhost', path: '/' }])
|
|
let autoMatched = false
|
|
let autoMatchBody: 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: ['purchaser'], 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: [{ id: 9, shopeeItemId: 'S9', title: '叠加抽屉商品', shopName: '测试店', pddProductId: 17, specs: [{ name: '颜色', role: 'color', values: [{ name: '藏青色', source: 'syb', mapping: null }] }] }], total: 1, page: 1, pageSize: 20 }}})
|
|
if (url.pathname.endsWith('/api/admin/v1/shopee-products/9/specs/mapping/auto-match')) {
|
|
autoMatchBody = route.request().postDataJSON()
|
|
autoMatched = true
|
|
return route.fulfill({ json: { code: 200, data: { confirmedCount: 2, preservedCount: 0, unmatchedCount: 0, items: [] }}})
|
|
}
|
|
if (url.pathname.endsWith('/api/admin/v1/shopee-products/9')) {
|
|
return route.fulfill({ json: { code: 200, data: { product: { id: 9, shopeeItemId: 'S9', title: '叠加抽屉商品', shopName: '测试店', pddProductId: 17, specContextVersion: 'context-3', specs: [{ name: '颜色', role: 'color', values: [{ name: '藏青色', source: 'import', mapping: autoMatched ? { pddValue: '黑色', source: 'ai_match', status: 'confirmed', confidence: 0.96, reason: '颜色含义唯一一致' } : null }] }, { name: '尺码', role: 'size', values: [{ name: 'XL', source: 'import', mapping: autoMatched ? { pddValue: 'XL', source: 'exact_match', status: 'confirmed', reason: '格式统一后唯一匹配' } : null }] }] }}}})
|
|
}
|
|
if (url.pathname.endsWith('/api/admin/v1/pdd-products/17/related-syb-products')) return route.fulfill({ json: { code: 200, data: { items: [], total: 0 }}})
|
|
if (url.pathname.endsWith('/api/admin/v1/pdd-products/17')) return route.fulfill({ json: { code: 200, data: { product: { id: 17, goodsId: 'P17', title: 'PDD 叠加详情', shopName: 'PDD 店', status: 'active', url: 'https://mobile.yangkeduo.com/goods.html?goods_id=17', specs: [{ name: '颜色分类', role: 'color', values: [{ name: '黑色', selectable: true, priceCent: 1299 }] }, { name: '尺码', role: 'size', values: [{ name: 'XL', selectable: true }] }], colorImages: [] }, relatedShopeeProducts: [] }}})
|
|
return route.fulfill({ json: { code: 200, data: [] }})
|
|
})
|
|
|
|
await page.goto('/#/shopee-products')
|
|
let popupCount = 0
|
|
page.on('popup', () => { popupCount += 1 })
|
|
await page.getByRole('button', { name: '详情', exact: true }).click()
|
|
await expect(page.getByText('虾皮商品详情', { exact: true })).toBeVisible()
|
|
await expect(page.getByRole('button', { name: '一键匹配颜色和尺码', exact: true })).toHaveCount(1)
|
|
await expect(page.getByRole('button', { name: 'AI 匹配', exact: true })).toHaveCount(0)
|
|
await page.getByRole('button', { name: '一键匹配颜色和尺码', exact: true }).click()
|
|
await expect(page.locator('.el-drawer:visible').getByText('黑色 · ¥12.99', { exact: true })).toBeVisible()
|
|
await expect(page.getByText('可采购', { exact: true })).toBeVisible()
|
|
expect(autoMatchBody?.specContextVersion).toBe('context-3')
|
|
expect(String(autoMatchBody?.requestId || '')).toMatch(/^[0-9a-f-]{36}$/)
|
|
await page.getByLabel('虾皮商品详情').getByText('PDD-17 ↗', { exact: true }).click()
|
|
await expect(page.locator('.el-drawer:visible').getByText('PDD 商品详情', { exact: true })).toBeVisible()
|
|
await expect(page.getByText('PDD 叠加详情', { exact: true })).toBeVisible()
|
|
await page.keyboard.press('Escape')
|
|
await expect(page.getByText('PDD 叠加详情', { exact: true })).toBeHidden()
|
|
await expect(page.getByText('虾皮商品详情', { exact: true })).toBeVisible()
|
|
await expect(page.locator('.el-drawer:visible').getByText('黑色 · ¥12.99', { exact: true })).toBeVisible()
|
|
expect(popupCount).toBe(0)
|
|
})
|