test: 新增新用户的创建逻辑用例

This commit is contained in:
肖应宇 2026-04-09 17:08:59 +08:00 committed by Titan
parent c9116e2fb2
commit 0c1a293fbd
1 changed files with 49 additions and 0 deletions

View File

@ -1,15 +1,22 @@
import { expect, test } from "@playwright/test";
import { v4 as uuid } from "uuid";
import {
THREAD_FOR_WELCOME,
newChatEntry,
openChat,
reuseThreadChatEntry,
sendMessage,
skipIfMissingThread,
waitForAnyMessages,
waitForMessageListReady,
} from "./support/chat-helpers";
test.use({
screenshot: "on",
video: "on",
});
test.describe("线程路由(无 isnew", () => {
test("/new 始终走欢迎态,发送后进入具体 thread 路由", async ({ page }, testInfo) => {
skipIfMissingThread(testInfo, THREAD_FOR_WELCOME, "FRONTEND_E2E_THREAD_ID");
@ -29,4 +36,46 @@ test.describe("线程路由(无 isnew", () => {
await expect(page).toHaveURL(new RegExp(`/workspace/chats/${THREAD_FOR_WELCOME!}`));
await expect(page.locator(".is-user, .is-assistant").first()).toBeVisible();
});
test("/new 使用 uuid thread_id 发送后触发 stream(cod=0) 并进入 thread 路由", async ({
page,
}) => {
const threadId = uuid();
const text = `e2e-${threadId.slice(0, 8)}`;
await openChat(page, newChatEntry(threadId));
await expect(page.getByTestId("welcome-suggestions")).toBeVisible();
const streamRequestPromise = page.waitForRequest(
(request) => {
const url = request.url();
if (!url.includes("/stream")) return false;
if (!url.includes(threadId)) return false;
try {
const parsed = new URL(url);
return parsed.searchParams.get("cancel_on_disconnect") === "0";
} catch {
return url.includes("cancel_on_disconnect=0");
}
},
{ timeout: 30_000 },
);
await sendMessage(page, text);
await expect(page.locator(".is-user").filter({ hasText: text })).toHaveCount(1);
await expect
.poll(
async () => await page.locator(".is-assistant").count(),
{ timeout: 30_000 },
)
.toBeGreaterThan(0);
const streamRequest = await streamRequestPromise;
expect(streamRequest.url()).toContain("cancel_on_disconnect=0");
await expect(page).toHaveURL(
new RegExp(`/workspace/chats/${threadId}\\?is_chatting=true`),
{ timeout: 30_000 },
);
});
});