105 lines
5.8 KiB
TypeScript
105 lines
5.8 KiB
TypeScript
import { expect, test } from '@playwright/test';
|
|
|
|
const product = {
|
|
id: 1,
|
|
goodsId: '972800403573',
|
|
url: 'https://mobile.yangkeduo.com/goods.html?goods_id=972800403573',
|
|
title: '夏季防晒冰丝袖套',
|
|
shopName: '清凉优选店',
|
|
salesCount: 1200,
|
|
reviewCount: 36,
|
|
status: 'active',
|
|
collectionSelectable: true,
|
|
specs: [
|
|
{ name: '颜色分类', role: 'color', values: [{ name: '黑色', selectable: true, priceCent: 2590 }] },
|
|
{ name: '尺码', role: 'size', values: [{ name: 'XL', selectable: true }] },
|
|
],
|
|
updatedAt: '2026-08-17T08:00:00Z',
|
|
};
|
|
|
|
test('PDD 商品列表、详情和编辑流程符合已确认原型', async ({ page, context }) => {
|
|
let updatePayload: any;
|
|
await context.addCookies([{ name: 'Admin-Token', value: 'prototype-test-token', domain: 'localhost', path: '/' }]);
|
|
await page.route('**/api/**', async route => {
|
|
const url = new URL(route.request().url());
|
|
if (url.pathname.startsWith('/src/api/')) {
|
|
await route.continue();
|
|
return;
|
|
}
|
|
if (url.pathname.endsWith('/api/v1/getinfo')) {
|
|
await route.fulfill({ json: { code: 200, data: { roles: ['admin'], name: '管理员', avatar: '', introduction: '', permissions: [] } } });
|
|
return;
|
|
}
|
|
if (url.pathname.endsWith('/api/admin/v1/pdd-products/1') && route.request().method() === 'PATCH') {
|
|
updatePayload = route.request().postDataJSON();
|
|
await route.fulfill({ json: { code: 200, data: { product: { ...product, ...updatePayload } } } });
|
|
return;
|
|
}
|
|
if (url.pathname.endsWith('/api/admin/v1/pdd-products/1')) {
|
|
await route.fulfill({ json: { code: 200, data: { product } } });
|
|
return;
|
|
}
|
|
if (url.pathname.endsWith('/api/admin/v1/pdd-products')) {
|
|
await route.fulfill({ json: { code: 200, data: { items: [product], total: 1, page: 1, pageSize: 20 } } });
|
|
return;
|
|
}
|
|
await route.fulfill({ json: { code: 200, data: [] } });
|
|
});
|
|
|
|
await page.goto('http://localhost:9527/#/pdd-products/index');
|
|
await expect(page.getByRole('heading', { name: 'PDD 商品' })).toBeVisible();
|
|
await expect(page.getByText('夏季防晒冰丝袖套')).toBeVisible();
|
|
await expect(page.getByText('¥25.90')).toBeVisible();
|
|
|
|
await page.getByRole('button', { name: '查看' }).click();
|
|
await expect(page.getByText('PDD 商品详情')).toBeVisible();
|
|
await expect(page.locator('.spec-title').filter({ hasText: '颜色分类' })).toBeVisible();
|
|
await expect(page.getByText('XL')).toBeVisible();
|
|
|
|
await page.getByRole('button', { name: '编辑商品' }).click();
|
|
await expect(page.getByText('编辑 PDD 商品')).toBeVisible();
|
|
await page.getByLabel('商品标题').fill('夏季防晒袖套(人工确认)');
|
|
await page.getByRole('button', { name: '保存修改' }).click();
|
|
await expect.poll(() => updatePayload?.title).toBe('夏季防晒袖套(人工确认)');
|
|
expect(updatePayload.specs[0].values[0].priceCent).toBe(2590);
|
|
});
|
|
|
|
test('PDD 商品当前页多选并批量创建独立采集任务', async ({ page, context }) => {
|
|
const second = { ...product, id: 2, goodsId: '719834019024', title: '第二件商品' };
|
|
const disabled = { ...product, id: 3, goodsId: '731370706977', title: '已停用商品', status: 'disabled', collectionSelectable: false, collectionDisabledReason: '商品已停用' };
|
|
let batchPayload: any;
|
|
await context.addCookies([{ name: 'Admin-Token', value: 'prototype-test-token', domain: 'localhost', path: '/' }]);
|
|
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/admin/v1/pdd-products')) return route.fulfill({ json: { code: 200, data: { items: [product, second, disabled], total: 3, page: 1, pageSize: 20 } } });
|
|
if (url.pathname.endsWith('/api/admin/v1/collection-rules')) return route.fulfill({ json: { code: 200, data: { items: [{ id: 9, name: 'PDD 商品详情采集' }], total: 1 } } });
|
|
if (url.pathname.endsWith('/api/admin/v1/devices')) return route.fulfill({ json: { code: 200, data: { items: [{ id: 4, name: 'samsung-SM-G9700', selectable: true }], total: 1 } } });
|
|
if (url.pathname.endsWith('/api/admin/v1/collection-tasks/batch')) {
|
|
batchPayload = route.request().postDataJSON();
|
|
return route.fulfill({ json: { code: 200, data: { successCount: 1, failureCount: 1, items: [{ pddProductId: 1, success: true, taskId: 101 }, { pddProductId: 2, success: false, code: 'PDD_PRODUCT_TASK_ACTIVE', message: '该商品已有待执行或执行中的任务' }] } } });
|
|
}
|
|
return route.fulfill({ json: { code: 200, data: [] } });
|
|
});
|
|
|
|
await page.goto('http://localhost:9527/#/pdd-products/index');
|
|
const rows = page.locator('.el-table__body-wrapper tbody tr');
|
|
await rows.nth(0).locator('.el-checkbox').click();
|
|
await rows.nth(1).locator('.el-checkbox').click();
|
|
await expect(rows.nth(2).getByRole('checkbox')).toBeDisabled();
|
|
await expect(page.getByText('已选择 2 条')).toBeVisible();
|
|
|
|
await page.getByRole('button', { name: '批量创建采集任务' }).click();
|
|
await page.getByLabel('采集规则').click();
|
|
await page.getByRole('option', { name: 'PDD 商品详情采集' }).click();
|
|
await page.getByRole('button', { name: '创建 2 个采集任务' }).click();
|
|
|
|
await expect.poll(() => batchPayload?.pddProductIds).toEqual([1, 2]);
|
|
expect(batchPayload.ruleId).toBe(9);
|
|
expect(batchPayload.deviceId).toBeNull();
|
|
await expect(page.getByText('创建完成:成功 1 个,失败 1 个')).toBeVisible();
|
|
await expect(page.getByText('采集任务 #101')).toBeVisible();
|
|
await expect(page.getByText('该商品已有待执行或执行中的任务')).toBeVisible();
|
|
});
|