import { test, expect } from '@playwright/test';
import { collectErrors, expectNoErrors } from './helpers';
/** 分类列表页走查:7 个分类 /{code} 与分页 */
const CATS = ['core', 'xcode', 'cube', 'blood', 'iot', 'tech', 'events'];
test.describe('分类列表页', () => {
test.beforeEach(async () => { await new Promise((r) => setTimeout(r, 300)); });
for (const code of CATS) {
test(`/${code} åŠ è½½ï¼šé¢åŒ…屑/分类头/æ–‡ç« å¡ç‰‡/æ— é”™è¯¯`, async ({ page }) => {
const errors = collectErrors(page);
const resp = await page.goto(`/${code}`);
expect(resp!.status(), `/${code} 返回 ${resp!.status()}`).toBe(200);
await expect(page.locator('.crumb')).toBeVisible();
await expect(page.locator('.page-head h1')).not.toBeEmpty();
// åˆ—è¡¨æœ‰æ•°æ®æˆ–空æ€å‹å¥½æç¤ºï¼ˆäºŒé€‰ä¸€ï¼‰
const hasCard = await page.locator('.article-card').count();
expect(hasCard, `/${code} æ—¢æ— æ–‡ç« å¡ç‰‡ä¹Ÿæ— ç©ºæ€æç¤º`).toBeGreaterThan(0);
// å¡ç‰‡é“¾æŽ¥æœ‰æ•ˆ
const bad = await page.locator('.article-card').evaluateAll((as) =>
as.map((a) => a.getAttribute('href')).filter((h) => !h || h === '#'),
);
expect(bad, `/${code} å˜åœ¨æ— 效å¡ç‰‡é“¾æŽ¥`).toEqual([]);
expectNoErrors(errors);
});
}
test('åˆ—è¡¨é¡µæ— å‰ç«¯é”™è¯¯ + 分类头统计文案', async ({ page }) => {
await page.goto('/core');
await expect(page.locator('.page-head .desc, .page-head h1').first()).toBeVisible();
expectNoErrors(collectErrors(page));
});
test('多页分类:分页控件å¯ç”¨ä¸”第 2 页å¯è¾¾', async ({ page }) => {
await page.goto('/core');
const pager = page.locator('.pagination');
if ((await pager.count()) > 0) {
const next = page.locator('.pagination a[aria-label="下一页"], .pagination .next a');
if ((await next.count()) > 0) {
await next.first().click();
await page.waitForLoadState('load');
expect(page.url()).toContain('-2');
await expect(page.locator('.article-card').first()).toBeVisible();
}
}
});
});
|