import { Page, expect } from '@playwright/test'; import type { metricsEntries } from '../../../src/config/entries'; export async function testEntryCards(page: Page, entries: typeof metricsEntries, checkLinkNavigation = false) { for (const entry of entries) { // 卡片文本可见 const card = page.locator(`text=${entry.label}`); await expect(card).toBeVisible(); // 卡片链接正确 const link = card.locator('..').locator('a'); await expect(link).toHaveAttribute('href', entry.href); // 图标存在 const img = card.locator('..').locator('img'); await expect(img).toBeVisible(); await expect(img).toHaveAttribute('src', /\/assets\/.+/); if (checkLinkNavigation) { const [newPage] = await Promise.all([ page.context().waitForEvent('page'), link.click(), ]); await expect(newPage).toHaveURL(entry.href); await newPage.close(); } } }