import { expect, test } from "@playwright/test"; import { THREAD_WITH_ARTIFACTS, THREAD_WITH_HTML_ARTIFACT, THREAD_WITH_IMAGE_ARTIFACT, openChat, reuseThreadChatEntry, skipIfMissingThread, waitForAnyMessages, waitForMessageListReady, } from "./support/chat-helpers"; test.describe("聊天工作台 / Artifact 面板", () => { test("DF-ART-001 含 artifacts 的线程展示入口并可打开文件列表", async ({ page, }, testInfo) => { skipIfMissingThread( testInfo, THREAD_WITH_ARTIFACTS, "FRONTEND_E2E_ARTIFACTS_THREAD_ID", ); await openChat(page, reuseThreadChatEntry(THREAD_WITH_ARTIFACTS!)); await waitForMessageListReady(page, { requireMessages: false }); const messageCount = await waitForAnyMessages(page); testInfo.skip(messageCount === 0, "当前线程没有可见历史消息。"); testInfo.skip( (await page.getByTestId("artifacts-open-button").count()) === 0, "当前线程未展示 artifacts 入口。", ); await expect(page.getByTestId("artifacts-open-button")).toBeVisible(); await page.getByTestId("artifacts-open-button").click(); await expect(page.getByTestId("artifact-file-list").first()).toBeVisible(); }); test("DF-ART-002 可打开图片 artifact 详情", async ({ page }, testInfo) => { skipIfMissingThread( testInfo, THREAD_WITH_IMAGE_ARTIFACT, "FRONTEND_E2E_IMAGE_ARTIFACT_THREAD_ID", ); await openChat(page, reuseThreadChatEntry(THREAD_WITH_IMAGE_ARTIFACT!)); await waitForMessageListReady(page, { requireMessages: false }); const messageCount = await waitForAnyMessages(page); testInfo.skip(messageCount === 0, "当前线程没有可见历史消息。"); testInfo.skip( (await page.getByTestId("artifacts-open-button").count()) === 0, "当前线程未展示 artifacts 入口。", ); await page.getByTestId("artifacts-open-button").click(); const imageFile = page .locator("[data-testid='artifact-file-list'] [data-testid='artifact-file-card']") .filter({ hasText: /\.(png|jpe?g|gif|webp|svg)/i }) .first(); testInfo.skip( (await imageFile.count()) === 0, "当前线程没有可预览的图片 artifact。", ); await imageFile.click(); await expect(page.getByTitle(/Artifact preview(?::.*)?$/i)).toBeVisible(); }); test("DF-ART-003 可打开 HTML artifact 详情", async ({ page }, testInfo) => { skipIfMissingThread( testInfo, THREAD_WITH_HTML_ARTIFACT, "FRONTEND_E2E_HTML_ARTIFACT_THREAD_ID", ); await openChat(page, reuseThreadChatEntry(THREAD_WITH_HTML_ARTIFACT!)); await waitForMessageListReady(page, { requireMessages: false }); const messageCount = await waitForAnyMessages(page); testInfo.skip(messageCount === 0, "当前线程没有可见历史消息。"); testInfo.skip( (await page.getByTestId("artifacts-open-button").count()) === 0, "当前线程未展示 artifacts 入口。", ); await page.getByTestId("artifacts-open-button").click(); const htmlFile = page .locator("[data-testid='artifact-file-list'] [data-testid='artifact-file-card']") .filter({ hasText: /\.html?/i }) .first(); testInfo.skip( (await htmlFile.count()) === 0, "当前线程没有 HTML artifact。", ); await htmlFile.click(); await expect(page.getByTitle(/Artifact preview(?::.*)?$/i)).toBeVisible(); }); test("DF-ART-004 关闭 artifact 面板后恢复聊天主视图", async ({ page, }, testInfo) => { skipIfMissingThread( testInfo, THREAD_WITH_ARTIFACTS, "FRONTEND_E2E_ARTIFACTS_THREAD_ID", ); await openChat(page, reuseThreadChatEntry(THREAD_WITH_ARTIFACTS!)); await waitForMessageListReady(page, { requireMessages: false }); const messageCount = await waitForAnyMessages(page); testInfo.skip(messageCount === 0, "当前线程没有可见历史消息。"); testInfo.skip( (await page.getByTestId("artifacts-open-button").count()) === 0, "当前线程未展示 artifacts 入口。", ); await page.getByTestId("artifacts-open-button").click(); await expect(page.getByTestId("artifact-file-list").first()).toBeVisible(); await page.getByTestId("artifacts-panel-close").click(); await expect(page.getByTestId("artifacts-open-button")).toBeVisible(); await expect(page.getByRole("log").first()).toBeVisible(); }); });