82 lines
4.9 KiB
TypeScript
82 lines
4.9 KiB
TypeScript
import { expect, test } from '@playwright/test'
|
||
|
||
test('page-local 200 default, pagination, filters, selection and other-page isolation', async ({ page, context }) => {
|
||
await page.setViewportSize({ width: 1920, height: 1080 })
|
||
await context.addCookies([{ name: 'Admin-Token', value: 'isolated-test-token', domain: 'localhost', path: '/' }])
|
||
const lists: URL[] = []; const shopLists: URL[] = []; const previews: number[][] = []; const writes: string[] = []
|
||
const rows = Array.from({ length: 205 }, (_, i) => ({ id: i + 1, businessDate: '2026-10-07', orderNumber: `MOCK-${i + 1}`, status: 'ready', specRaw: '模拟规格', items: [{ ordinal: 1, code: `CODE-${i + 1}` }] }))
|
||
await page.route('**/api/**', async route => {
|
||
const request = route.request(); const url = new URL(request.url()); const path = url.pathname
|
||
if (path.startsWith('/src/api/')) return route.continue()
|
||
const reply = (data: unknown) => route.fulfill({ json: { code: 200, data } })
|
||
if (path.endsWith('/api/v1/getinfo')) return reply({ roles: ['purchaser'], name: '模拟采购员', avatar: '', permissions: [] })
|
||
if (path.endsWith('/api/v1/menurole')) return reply([{ path: '/workbench', component: 'Layout', menuName: 'Workbench', title: '工作台', visible: '0', children: [
|
||
{ path: '/syb-inner-codes', component: '/goauto/syb-inner-codes/index', menuName: 'GoAutoSybInnerCodes', title: '档口入库码', visible: '0' },
|
||
{ path: '/syb-shops', component: '/goauto/syb-shops/index', menuName: 'GoAutoSybShops', title: '店铺管理', visible: '0' }
|
||
] }])
|
||
if (path.endsWith('/syb-inner-codes') && request.method() === 'GET') {
|
||
lists.push(url)
|
||
const pageNo = Number(url.searchParams.get('page')); const size = Number(url.searchParams.get('pageSize'))
|
||
const filtered = url.searchParams.get('keyword') === 'empty' ? [] : rows
|
||
return reply({ items: filtered.slice((pageNo - 1) * size, pageNo * size), total: filtered.length, page: pageNo, pageSize: size })
|
||
}
|
||
if (path.endsWith('/apply-preview')) {
|
||
const ids = request.postDataJSON().ids; previews.push(ids)
|
||
return reply({ records: ids.length, inboundCodes: ids.length, placeholderDetails: 0, replaceOldCodes: 0, blocked: [] })
|
||
}
|
||
if (path.endsWith('/syb-shops') && request.method() === 'GET') { shopLists.push(url); return reply({ items: [], total: 0 }) }
|
||
if (request.method() !== 'GET') writes.push(path)
|
||
return reply({ items: [], total: 0 })
|
||
})
|
||
const tableRows = page.locator('.el-table__body-wrapper tbody tr')
|
||
const pagination = page.locator('.pagination-container')
|
||
const started = Date.now()
|
||
await page.goto('/#/syb-inner-codes')
|
||
await expect(tableRows).toHaveCount(200)
|
||
console.log(`mock 200-row initial navigation and render: ${Date.now() - started}ms`)
|
||
expect(lists[0].searchParams.get('page')).toBe('1')
|
||
expect(lists[0].searchParams.get('pageSize')).toBe('200')
|
||
await expect(pagination.locator('.el-select')).toContainText('200')
|
||
|
||
await page.locator('.el-table__header-wrapper .el-checkbox').first().click()
|
||
await page.getByRole('button', { name: '回写(200)', exact: true }).click()
|
||
await expect.poll(() => previews.length).toBe(1)
|
||
expect(previews[0]).toEqual(rows.slice(0, 200).map(row => row.id))
|
||
await page.getByRole('dialog').getByRole('button', { name: '取消', exact: true }).click()
|
||
expect(writes).toEqual([])
|
||
|
||
await pagination.locator('.btn-next').click()
|
||
await expect(tableRows).toHaveCount(5)
|
||
await expect(page.getByRole('cell', { name: 'MOCK-201', exact: true })).toBeVisible()
|
||
expect(lists.at(-1)!.searchParams.get('page')).toBe('2')
|
||
await expect(page.getByRole('button', { name: '回写(0)', exact: true })).toBeDisabled()
|
||
await page.getByRole('button', { name: '搜索', exact: true }).click()
|
||
await expect(tableRows).toHaveCount(200)
|
||
|
||
for (const size of [20, 50, 100, 200]) {
|
||
await pagination.locator('.el-select').click()
|
||
await page.getByRole('option', { name: new RegExp(`^${size}\\s*条/页$`) }).click()
|
||
await expect(tableRows).toHaveCount(size)
|
||
expect(lists.at(-1)!.searchParams.get('pageSize')).toBe(String(size))
|
||
for (const name of ['搜索', '清除']) {
|
||
const before = lists.length
|
||
await page.getByRole('button', { name, exact: true }).click()
|
||
await expect.poll(() => lists.length).toBeGreaterThan(before)
|
||
expect(lists.at(-1)!.searchParams.get('pageSize')).toBe(String(size))
|
||
}
|
||
}
|
||
|
||
await page.getByPlaceholder('订单号或入库码').fill('empty')
|
||
await page.getByRole('button', { name: '搜索', exact: true }).click()
|
||
await expect(tableRows).toHaveCount(0)
|
||
await expect(pagination).not.toBeVisible()
|
||
await page.reload()
|
||
await expect(tableRows).toHaveCount(200)
|
||
expect(lists.at(-1)!.searchParams.get('pageSize')).toBe('200')
|
||
|
||
await page.goto('/#/syb-shops')
|
||
await expect.poll(() => shopLists.length).toBeGreaterThan(0)
|
||
expect(shopLists[0].searchParams.get('pageSize')).toBe('20')
|
||
expect(writes).toEqual([])
|
||
})
|