feat: dynamic model discovery from vercel ai gateway (#1353)
This commit is contained in:
parent
2b0b42d144
commit
b1da86062e
74 changed files with 7426 additions and 2277 deletions
|
|
@ -1,77 +0,0 @@
|
|||
import { expect, test } from "../fixtures";
|
||||
import { ArtifactPage } from "../pages/artifact";
|
||||
import { ChatPage } from "../pages/chat";
|
||||
|
||||
test.describe("Artifacts activity", () => {
|
||||
let chatPage: ChatPage;
|
||||
let artifactPage: ArtifactPage;
|
||||
|
||||
test.beforeEach(async ({ page }) => {
|
||||
chatPage = new ChatPage(page);
|
||||
artifactPage = new ArtifactPage(page);
|
||||
|
||||
await chatPage.createNewChat();
|
||||
});
|
||||
|
||||
test("Create a text artifact", async () => {
|
||||
test.fixme();
|
||||
await chatPage.createNewChat();
|
||||
|
||||
await chatPage.sendUserMessage(
|
||||
"Help me write an essay about Silicon Valley"
|
||||
);
|
||||
await artifactPage.isGenerationComplete();
|
||||
|
||||
expect(artifactPage.artifact).toBeVisible();
|
||||
|
||||
const assistantMessage = await chatPage.getRecentAssistantMessage();
|
||||
expect(assistantMessage.content).toBe(
|
||||
"A document was created and is now visible to the user."
|
||||
);
|
||||
|
||||
await chatPage.hasChatIdInUrl();
|
||||
});
|
||||
|
||||
test("Toggle artifact visibility", async () => {
|
||||
test.fixme();
|
||||
await chatPage.createNewChat();
|
||||
|
||||
await chatPage.sendUserMessage(
|
||||
"Help me write an essay about Silicon Valley"
|
||||
);
|
||||
await artifactPage.isGenerationComplete();
|
||||
|
||||
expect(artifactPage.artifact).toBeVisible();
|
||||
|
||||
const assistantMessage = await chatPage.getRecentAssistantMessage();
|
||||
expect(assistantMessage.content).toBe(
|
||||
"A document was created and is now visible to the user."
|
||||
);
|
||||
|
||||
await artifactPage.closeArtifact();
|
||||
await chatPage.isElementNotVisible("artifact");
|
||||
});
|
||||
|
||||
test("Send follow up message after generation", async () => {
|
||||
test.fixme();
|
||||
await chatPage.createNewChat();
|
||||
|
||||
await chatPage.sendUserMessage(
|
||||
"Help me write an essay about Silicon Valley"
|
||||
);
|
||||
await artifactPage.isGenerationComplete();
|
||||
|
||||
expect(artifactPage.artifact).toBeVisible();
|
||||
|
||||
const assistantMessage = await artifactPage.getRecentAssistantMessage();
|
||||
expect(assistantMessage.content).toBe(
|
||||
"A document was created and is now visible to the user."
|
||||
);
|
||||
|
||||
await artifactPage.sendUserMessage("Thanks!");
|
||||
await artifactPage.isGenerationComplete();
|
||||
|
||||
const secondAssistantMessage = await chatPage.getRecentAssistantMessage();
|
||||
expect(secondAssistantMessage.content).toBe("You're welcome!");
|
||||
});
|
||||
});
|
||||
53
tests/e2e/auth.test.ts
Normal file
53
tests/e2e/auth.test.ts
Normal file
|
|
@ -0,0 +1,53 @@
|
|||
import { expect, test } from "@playwright/test";
|
||||
|
||||
test.describe("Authentication", () => {
|
||||
test("can register a new account", async ({ page }) => {
|
||||
const timestamp = Date.now();
|
||||
const email = `test-${timestamp}@example.com`;
|
||||
const password = "testpassword123";
|
||||
|
||||
await page.goto("/register");
|
||||
await page.getByPlaceholder("user@acme.com").fill(email);
|
||||
await page.getByLabel("Password").fill(password);
|
||||
await page.getByRole("button", { name: "Sign Up" }).click();
|
||||
|
||||
await expect(page.getByTestId("toast")).toContainText(
|
||||
"Account created successfully"
|
||||
);
|
||||
await expect(page).toHaveURL("/");
|
||||
});
|
||||
|
||||
test("can login with credentials", async ({ page }) => {
|
||||
const timestamp = Date.now();
|
||||
const email = `test-${timestamp}@example.com`;
|
||||
const password = "testpassword123";
|
||||
|
||||
await page.goto("/register");
|
||||
await page.getByPlaceholder("user@acme.com").fill(email);
|
||||
await page.getByLabel("Password").fill(password);
|
||||
await page.getByRole("button", { name: "Sign Up" }).click();
|
||||
await expect(page).toHaveURL("/");
|
||||
|
||||
await page.goto("/login");
|
||||
await page.getByPlaceholder("user@acme.com").fill(email);
|
||||
await page.getByLabel("Password").fill(password);
|
||||
await page.getByRole("button", { name: "Sign In" }).click();
|
||||
|
||||
await expect(page).toHaveURL("/");
|
||||
});
|
||||
|
||||
test("shows error for invalid credentials", async ({ page }) => {
|
||||
await page.goto("/login");
|
||||
await page.getByPlaceholder("user@acme.com").fill("invalid@example.com");
|
||||
await page.getByLabel("Password").fill("wrongpassword");
|
||||
await page.getByRole("button", { name: "Sign In" }).click();
|
||||
|
||||
await expect(page.getByTestId("toast")).toBeVisible();
|
||||
});
|
||||
|
||||
test("can continue as guest", async ({ page }) => {
|
||||
await page.goto("/");
|
||||
await expect(page.getByTestId("multimodal-input")).toBeVisible();
|
||||
});
|
||||
});
|
||||
|
||||
|
|
@ -1,7 +1,7 @@
|
|||
import { expect, test } from "../fixtures";
|
||||
import { expect, test } from "@playwright/test";
|
||||
import { ChatPage } from "../pages/chat";
|
||||
|
||||
test.describe("Chat activity", () => {
|
||||
test.describe("Chat", () => {
|
||||
let chatPage: ChatPage;
|
||||
|
||||
test.beforeEach(async ({ page }) => {
|
||||
|
|
@ -9,164 +9,60 @@ test.describe("Chat activity", () => {
|
|||
await chatPage.createNewChat();
|
||||
});
|
||||
|
||||
test("Send a user message and receive response", async () => {
|
||||
await chatPage.sendUserMessage("Why is grass green?");
|
||||
await chatPage.isGenerationComplete();
|
||||
|
||||
const assistantMessage = await chatPage.getRecentAssistantMessage();
|
||||
expect(assistantMessage.content).toContain("It's just green duh!");
|
||||
test("page loads with input ready", async () => {
|
||||
await chatPage.waitForInputToBeReady();
|
||||
});
|
||||
|
||||
test("Redirect to /chat/:id after submitting message", async () => {
|
||||
await chatPage.sendUserMessage("Why is grass green?");
|
||||
test("send button is disabled when input is empty", async () => {
|
||||
await expect(chatPage.sendButton).toBeDisabled();
|
||||
});
|
||||
|
||||
test("send button is enabled when input has text", async () => {
|
||||
await chatPage.multimodalInput.fill("Hello");
|
||||
await expect(chatPage.sendButton).toBeEnabled();
|
||||
});
|
||||
|
||||
test("can send a message and receive a response", async () => {
|
||||
await chatPage.sendUserMessage("Hello");
|
||||
await chatPage.isGenerationComplete();
|
||||
|
||||
const assistantMessage = await chatPage.getRecentAssistantMessage();
|
||||
expect(assistantMessage.content).toContain("It's just green duh!");
|
||||
const userContent = await chatPage.getLastUserMessageContent();
|
||||
expect(userContent).toBe("Hello");
|
||||
|
||||
const assistantContent = await chatPage.getLastAssistantMessageContent();
|
||||
expect(assistantContent).toBeTruthy();
|
||||
});
|
||||
|
||||
test("redirects to /chat/:id after sending message", async () => {
|
||||
await chatPage.sendUserMessage("Hello");
|
||||
await chatPage.isGenerationComplete();
|
||||
await chatPage.hasChatIdInUrl();
|
||||
});
|
||||
|
||||
test("Send a user message from suggestion", async () => {
|
||||
await chatPage.sendUserMessageFromSuggestion();
|
||||
await chatPage.isGenerationComplete();
|
||||
|
||||
const assistantMessage = await chatPage.getRecentAssistantMessage();
|
||||
expect(assistantMessage.content).toContain(
|
||||
"With Next.js, you can ship fast!"
|
||||
);
|
||||
test("shows stop button during generation", async () => {
|
||||
await chatPage.multimodalInput.fill("Hello");
|
||||
await chatPage.sendButton.click();
|
||||
await expect(chatPage.stopButton).toBeVisible({ timeout: 5000 });
|
||||
});
|
||||
|
||||
test("Toggle between send/stop button based on activity", async () => {
|
||||
await expect(chatPage.sendButton).toBeVisible();
|
||||
await expect(chatPage.sendButton).toBeDisabled();
|
||||
|
||||
await chatPage.sendUserMessage("Why is grass green?");
|
||||
|
||||
await expect(chatPage.sendButton).not.toBeVisible();
|
||||
await expect(chatPage.stopButton).toBeVisible();
|
||||
|
||||
await chatPage.isGenerationComplete();
|
||||
|
||||
await expect(chatPage.stopButton).not.toBeVisible();
|
||||
await expect(chatPage.sendButton).toBeVisible();
|
||||
});
|
||||
|
||||
test("Stop generation during submission", async () => {
|
||||
await chatPage.sendUserMessage("Why is grass green?");
|
||||
await expect(chatPage.stopButton).toBeVisible();
|
||||
test("can stop generation", async () => {
|
||||
await chatPage.multimodalInput.fill("Hello");
|
||||
await chatPage.sendButton.click();
|
||||
await expect(chatPage.stopButton).toBeVisible({ timeout: 5000 });
|
||||
await chatPage.stopButton.click();
|
||||
await expect(chatPage.sendButton).toBeVisible();
|
||||
});
|
||||
|
||||
test("Edit user message and resubmit", async () => {
|
||||
await chatPage.sendUserMessage("Why is grass green?");
|
||||
await chatPage.isGenerationComplete();
|
||||
|
||||
const assistantMessage = await chatPage.getRecentAssistantMessage();
|
||||
expect(assistantMessage.content).toContain("It's just green duh!");
|
||||
|
||||
const userMessage = await chatPage.getRecentUserMessage();
|
||||
await userMessage.edit("Why is the sky blue?");
|
||||
|
||||
await chatPage.isGenerationComplete();
|
||||
|
||||
const updatedAssistantMessage = await chatPage.getRecentAssistantMessage();
|
||||
expect(updatedAssistantMessage.content).toContain("It's just blue duh!");
|
||||
});
|
||||
|
||||
test("Hide suggested actions after sending message", async () => {
|
||||
await chatPage.isElementVisible("suggested-actions");
|
||||
await chatPage.sendUserMessageFromSuggestion();
|
||||
await chatPage.isElementNotVisible("suggested-actions");
|
||||
});
|
||||
|
||||
test("Upload file and send image attachment with message", async () => {
|
||||
await chatPage.addImageAttachment();
|
||||
|
||||
await chatPage.isElementVisible("attachments-preview");
|
||||
await chatPage.isElementVisible("input-attachment-loader");
|
||||
await chatPage.isElementNotVisible("input-attachment-loader");
|
||||
|
||||
await chatPage.sendUserMessage("Who painted this?");
|
||||
|
||||
const userMessage = await chatPage.getRecentUserMessage();
|
||||
expect(userMessage.attachments).toHaveLength(1);
|
||||
|
||||
await chatPage.isGenerationComplete();
|
||||
|
||||
const assistantMessage = await chatPage.getRecentAssistantMessage();
|
||||
expect(assistantMessage.content).toBe("This painting is by Monet!");
|
||||
});
|
||||
|
||||
test("Call weather tool", async () => {
|
||||
await chatPage.sendUserMessage("What's the weather in sf?");
|
||||
await chatPage.isGenerationComplete();
|
||||
|
||||
const assistantMessage = await chatPage.getRecentAssistantMessage();
|
||||
|
||||
expect(assistantMessage.content).toBe(
|
||||
"The current temperature in San Francisco is 17°C."
|
||||
);
|
||||
});
|
||||
|
||||
test("Upvote message", async () => {
|
||||
await chatPage.sendUserMessage("Why is the sky blue?");
|
||||
await chatPage.isGenerationComplete();
|
||||
|
||||
const assistantMessage = await chatPage.getRecentAssistantMessage();
|
||||
await assistantMessage.upvote();
|
||||
await chatPage.isVoteComplete();
|
||||
});
|
||||
|
||||
test("Downvote message", async () => {
|
||||
await chatPage.sendUserMessage("Why is the sky blue?");
|
||||
await chatPage.isGenerationComplete();
|
||||
|
||||
const assistantMessage = await chatPage.getRecentAssistantMessage();
|
||||
await assistantMessage.downvote();
|
||||
await chatPage.isVoteComplete();
|
||||
});
|
||||
|
||||
test("Update vote", async () => {
|
||||
await chatPage.sendUserMessage("Why is the sky blue?");
|
||||
await chatPage.isGenerationComplete();
|
||||
|
||||
const assistantMessage = await chatPage.getRecentAssistantMessage();
|
||||
await assistantMessage.upvote();
|
||||
await chatPage.isVoteComplete();
|
||||
|
||||
await assistantMessage.downvote();
|
||||
await chatPage.isVoteComplete();
|
||||
});
|
||||
|
||||
test("Create message from url query", async ({ page }) => {
|
||||
await page.goto("/?query=Why is the sky blue?");
|
||||
|
||||
await chatPage.isGenerationComplete();
|
||||
|
||||
const userMessage = await chatPage.getRecentUserMessage();
|
||||
expect(userMessage.content).toBe("Why is the sky blue?");
|
||||
|
||||
const assistantMessage = await chatPage.getRecentAssistantMessage();
|
||||
expect(assistantMessage.content).toContain("It's just blue duh!");
|
||||
});
|
||||
|
||||
test("auto-scrolls to bottom after submitting new messages", async () => {
|
||||
test.fixme();
|
||||
await chatPage.sendMultipleMessages(5, (i) => `filling message #${i}`);
|
||||
await chatPage.waitForScrollToBottom();
|
||||
});
|
||||
|
||||
test("scroll button appears when user scrolls up, hides on click", async () => {
|
||||
test.fixme();
|
||||
await chatPage.sendMultipleMessages(5, (i) => `filling message #${i}`);
|
||||
await expect(chatPage.scrollToBottomButton).not.toBeVisible();
|
||||
|
||||
await chatPage.scrollToTop();
|
||||
await expect(chatPage.scrollToBottomButton).toBeVisible();
|
||||
|
||||
await chatPage.scrollToBottomButton.click();
|
||||
await chatPage.waitForScrollToBottom();
|
||||
await expect(chatPage.scrollToBottomButton).not.toBeVisible();
|
||||
await expect(chatPage.sendButton).toBeVisible({ timeout: 5000 });
|
||||
});
|
||||
});
|
||||
|
||||
test.describe("Chat - Guest User", () => {
|
||||
test("can use chat as guest", async ({ page }) => {
|
||||
const chatPage = new ChatPage(page);
|
||||
await chatPage.createNewChat();
|
||||
await chatPage.waitForInputToBeReady();
|
||||
await chatPage.sendUserMessage("Hello");
|
||||
await chatPage.isGenerationComplete();
|
||||
|
||||
const content = await chatPage.getLastAssistantMessageContent();
|
||||
expect(content).toBeTruthy();
|
||||
});
|
||||
});
|
||||
|
|
|
|||
54
tests/e2e/message-actions.test.ts
Normal file
54
tests/e2e/message-actions.test.ts
Normal file
|
|
@ -0,0 +1,54 @@
|
|||
import { expect, test } from "@playwright/test";
|
||||
import { ChatPage } from "../pages/chat";
|
||||
|
||||
test.describe("Message Actions", () => {
|
||||
let chatPage: ChatPage;
|
||||
|
||||
test.beforeEach(async ({ page }) => {
|
||||
chatPage = new ChatPage(page);
|
||||
await chatPage.createNewChat();
|
||||
await chatPage.sendUserMessage("Hello");
|
||||
await chatPage.isGenerationComplete();
|
||||
});
|
||||
|
||||
test("can upvote a message", async ({ page }) => {
|
||||
const upvoteButton = page.getByTestId("message-upvote").first();
|
||||
await upvoteButton.click();
|
||||
await expect(upvoteButton).toHaveAttribute("data-state", "active");
|
||||
});
|
||||
|
||||
test("can downvote a message", async ({ page }) => {
|
||||
const downvoteButton = page.getByTestId("message-downvote").first();
|
||||
await downvoteButton.click();
|
||||
await expect(downvoteButton).toHaveAttribute("data-state", "active");
|
||||
});
|
||||
|
||||
test("can copy message content", async ({ page, context }) => {
|
||||
await context.grantPermissions(["clipboard-read", "clipboard-write"]);
|
||||
|
||||
const copyButton = page.getByTestId("message-copy").first();
|
||||
await copyButton.click();
|
||||
|
||||
const clipboardContent = await page.evaluate(() =>
|
||||
navigator.clipboard.readText()
|
||||
);
|
||||
expect(clipboardContent.length).toBeGreaterThan(0);
|
||||
});
|
||||
|
||||
test("can edit user message", async ({ page }) => {
|
||||
const editButton = page.getByTestId("message-edit-button").first();
|
||||
await editButton.click();
|
||||
|
||||
const editor = page.getByTestId("message-editor");
|
||||
await expect(editor).toBeVisible();
|
||||
await editor.fill("Updated message");
|
||||
|
||||
const sendButton = page.getByTestId("message-editor-send-button");
|
||||
await sendButton.click();
|
||||
|
||||
await chatPage.isGenerationComplete();
|
||||
const userContent = await chatPage.getLastUserMessageContent();
|
||||
expect(userContent).toBe("Updated message");
|
||||
});
|
||||
});
|
||||
|
||||
41
tests/e2e/model-selector.test.ts
Normal file
41
tests/e2e/model-selector.test.ts
Normal file
|
|
@ -0,0 +1,41 @@
|
|||
import { expect, test } from "@playwright/test";
|
||||
import { ChatPage } from "../pages/chat";
|
||||
|
||||
test.describe("Model Selector", () => {
|
||||
let chatPage: ChatPage;
|
||||
|
||||
test.beforeEach(async ({ page }) => {
|
||||
chatPage = new ChatPage(page);
|
||||
await chatPage.createNewChat();
|
||||
});
|
||||
|
||||
test("displays default model on load", async ({ page }) => {
|
||||
const modelButton = page.locator("button").filter({ hasText: /Gemini|Claude|GPT/i }).first();
|
||||
await expect(modelButton).toBeVisible();
|
||||
});
|
||||
|
||||
test("opens model selector on click", async ({ page }) => {
|
||||
const modelButton = page.locator("button").filter({ hasText: /Gemini|Claude|GPT/i }).first();
|
||||
await modelButton.click();
|
||||
await expect(page.getByPlaceholder("Search models...")).toBeVisible();
|
||||
});
|
||||
|
||||
test("can search for models", async ({ page }) => {
|
||||
const modelButton = page.locator("button").filter({ hasText: /Gemini|Claude|GPT/i }).first();
|
||||
await modelButton.click();
|
||||
await page.getByPlaceholder("Search models...").fill("Claude");
|
||||
await expect(page.getByText("Claude", { exact: false })).toBeVisible();
|
||||
});
|
||||
|
||||
test("can select a different model", async ({ page }) => {
|
||||
const modelButton = page.locator("button").filter({ hasText: /Gemini|Claude|GPT/i }).first();
|
||||
await modelButton.click();
|
||||
|
||||
const modelOption = page.getByRole("option").first();
|
||||
const modelName = await modelOption.innerText();
|
||||
await modelOption.click();
|
||||
|
||||
await expect(page.locator("button").filter({ hasText: modelName.split("\n")[0] })).toBeVisible();
|
||||
});
|
||||
});
|
||||
|
||||
|
|
@ -1,63 +0,0 @@
|
|||
import { expect, test } from "../fixtures";
|
||||
import { ChatPage } from "../pages/chat";
|
||||
|
||||
test.describe("chat activity with reasoning", () => {
|
||||
let chatPage: ChatPage;
|
||||
|
||||
test.beforeEach(async ({ curieContext }) => {
|
||||
chatPage = new ChatPage(curieContext.page);
|
||||
await chatPage.createNewChat();
|
||||
});
|
||||
|
||||
test("Curie can send message and generate response with reasoning", async () => {
|
||||
await chatPage.sendUserMessage("Why is the sky blue?");
|
||||
await chatPage.isGenerationComplete();
|
||||
|
||||
const assistantMessage = await chatPage.getRecentAssistantMessage();
|
||||
expect(assistantMessage.content).toBe("It's just blue duh!");
|
||||
|
||||
expect(assistantMessage.reasoning).toBe(
|
||||
"The sky is blue because of rayleigh scattering!"
|
||||
);
|
||||
});
|
||||
|
||||
test("Curie can toggle reasoning visibility", async () => {
|
||||
await chatPage.sendUserMessage("Why is the sky blue?");
|
||||
await chatPage.isGenerationComplete();
|
||||
|
||||
const assistantMessage = await chatPage.getRecentAssistantMessage();
|
||||
const reasoningElement =
|
||||
assistantMessage.element.getByTestId("message-reasoning");
|
||||
expect(reasoningElement).toBeVisible();
|
||||
|
||||
await assistantMessage.toggleReasoningVisibility();
|
||||
await expect(reasoningElement).not.toBeVisible();
|
||||
|
||||
await assistantMessage.toggleReasoningVisibility();
|
||||
await expect(reasoningElement).toBeVisible();
|
||||
});
|
||||
|
||||
test("Curie can edit message and resubmit", async () => {
|
||||
await chatPage.sendUserMessage("Why is the sky blue?");
|
||||
await chatPage.isGenerationComplete();
|
||||
|
||||
const assistantMessage = await chatPage.getRecentAssistantMessage();
|
||||
const reasoningElement =
|
||||
assistantMessage.element.getByTestId("message-reasoning");
|
||||
expect(reasoningElement).toBeVisible();
|
||||
|
||||
const userMessage = await chatPage.getRecentUserMessage();
|
||||
|
||||
const generationCompletePromise = chatPage.isGenerationComplete();
|
||||
await userMessage.edit("Why is grass green?");
|
||||
await generationCompletePromise;
|
||||
|
||||
const updatedAssistantMessage = await chatPage.getRecentAssistantMessage();
|
||||
|
||||
expect(updatedAssistantMessage.content).toBe("It's just green duh!");
|
||||
|
||||
expect(updatedAssistantMessage.reasoning).toBe(
|
||||
"Grass is green because of chlorophyll absorption!"
|
||||
);
|
||||
});
|
||||
});
|
||||
|
|
@ -1,209 +0,0 @@
|
|||
import { getMessageByErrorCode } from "@/lib/errors";
|
||||
import { expect, test } from "../fixtures";
|
||||
import { generateRandomTestUser } from "../helpers";
|
||||
import { AuthPage } from "../pages/auth";
|
||||
import { ChatPage } from "../pages/chat";
|
||||
|
||||
test.describe
|
||||
.serial("Guest Session", () => {
|
||||
test("Authenticate as guest user when a new session is loaded", async ({
|
||||
page,
|
||||
}) => {
|
||||
const response = await page.goto("/");
|
||||
|
||||
if (!response) {
|
||||
throw new Error("Failed to load page");
|
||||
}
|
||||
|
||||
let request = response.request();
|
||||
|
||||
const chain: string[] = [];
|
||||
|
||||
while (request) {
|
||||
chain.unshift(request.url());
|
||||
request = request.redirectedFrom();
|
||||
}
|
||||
|
||||
expect(chain).toEqual([
|
||||
"http://localhost:3000/",
|
||||
"http://localhost:3000/api/auth/guest?redirectUrl=http%3A%2F%2Flocalhost%3A3000%2F",
|
||||
"http://localhost:3000/",
|
||||
]);
|
||||
});
|
||||
|
||||
test("Log out is not available for guest users", async ({ page }) => {
|
||||
await page.goto("/");
|
||||
|
||||
const sidebarToggleButton = page.getByTestId("sidebar-toggle-button");
|
||||
await sidebarToggleButton.click();
|
||||
|
||||
const userNavButton = page.getByTestId("user-nav-button");
|
||||
await expect(userNavButton).toBeVisible();
|
||||
|
||||
await userNavButton.click();
|
||||
const userNavMenu = page.getByTestId("user-nav-menu");
|
||||
await expect(userNavMenu).toBeVisible();
|
||||
|
||||
const authMenuItem = page.getByTestId("user-nav-item-auth");
|
||||
await expect(authMenuItem).toContainText("Login to your account");
|
||||
});
|
||||
|
||||
test("Do not authenticate as guest user when an existing non-guest session is active", async ({
|
||||
adaContext,
|
||||
}) => {
|
||||
const response = await adaContext.page.goto("/");
|
||||
|
||||
if (!response) {
|
||||
throw new Error("Failed to load page");
|
||||
}
|
||||
|
||||
let request = response.request();
|
||||
|
||||
const chain: string[] = [];
|
||||
|
||||
while (request) {
|
||||
chain.unshift(request.url());
|
||||
request = request.redirectedFrom();
|
||||
}
|
||||
|
||||
expect(chain).toEqual(["http://localhost:3000/"]);
|
||||
});
|
||||
|
||||
test("Allow navigating to /login as guest user", async ({ page }) => {
|
||||
await page.goto("/login");
|
||||
await page.waitForURL("/login");
|
||||
await expect(page).toHaveURL("/login");
|
||||
});
|
||||
|
||||
test("Allow navigating to /register as guest user", async ({ page }) => {
|
||||
await page.goto("/register");
|
||||
await page.waitForURL("/register");
|
||||
await expect(page).toHaveURL("/register");
|
||||
});
|
||||
|
||||
test("Do not show email in user menu for guest user", async ({ page }) => {
|
||||
await page.goto("/");
|
||||
|
||||
const sidebarToggleButton = page.getByTestId("sidebar-toggle-button");
|
||||
await sidebarToggleButton.click();
|
||||
|
||||
const userEmail = page.getByTestId("user-email");
|
||||
await expect(userEmail).toContainText("Guest");
|
||||
});
|
||||
});
|
||||
|
||||
test.describe
|
||||
.serial("Login and Registration", () => {
|
||||
let authPage: AuthPage;
|
||||
|
||||
const testUser = generateRandomTestUser();
|
||||
|
||||
test.beforeEach(({ page }) => {
|
||||
authPage = new AuthPage(page);
|
||||
});
|
||||
|
||||
test("Register new account", async () => {
|
||||
await authPage.register(testUser.email, testUser.password);
|
||||
await authPage.expectToastToContain("Account created successfully!");
|
||||
});
|
||||
|
||||
test("Register new account with existing email", async () => {
|
||||
await authPage.register(testUser.email, testUser.password);
|
||||
await authPage.expectToastToContain("Account already exists!");
|
||||
});
|
||||
|
||||
test("Log into account that exists", async ({ page }) => {
|
||||
await authPage.login(testUser.email, testUser.password);
|
||||
|
||||
await page.waitForURL("/");
|
||||
await expect(page.getByPlaceholder("Send a message...")).toBeVisible();
|
||||
});
|
||||
|
||||
test("Display user email in user menu", async ({ page }) => {
|
||||
await authPage.login(testUser.email, testUser.password);
|
||||
|
||||
await page.waitForURL("/");
|
||||
await expect(page.getByPlaceholder("Send a message...")).toBeVisible();
|
||||
|
||||
const userEmail = await page.getByTestId("user-email");
|
||||
await expect(userEmail).toHaveText(testUser.email);
|
||||
});
|
||||
|
||||
test("Log out as non-guest user", async () => {
|
||||
await authPage.logout(testUser.email, testUser.password);
|
||||
});
|
||||
|
||||
test("Do not force create a guest session if non-guest session already exists", async ({
|
||||
page,
|
||||
}) => {
|
||||
await authPage.login(testUser.email, testUser.password);
|
||||
await page.waitForURL("/");
|
||||
|
||||
const userEmail = await page.getByTestId("user-email");
|
||||
await expect(userEmail).toHaveText(testUser.email);
|
||||
|
||||
await page.goto("/api/auth/guest");
|
||||
await page.waitForURL("/");
|
||||
|
||||
const updatedUserEmail = await page.getByTestId("user-email");
|
||||
await expect(updatedUserEmail).toHaveText(testUser.email);
|
||||
});
|
||||
|
||||
test("Log out is available for non-guest users", async ({ page }) => {
|
||||
await authPage.login(testUser.email, testUser.password);
|
||||
await page.waitForURL("/");
|
||||
|
||||
authPage.openSidebar();
|
||||
|
||||
const userNavButton = page.getByTestId("user-nav-button");
|
||||
await expect(userNavButton).toBeVisible();
|
||||
|
||||
await userNavButton.click();
|
||||
const userNavMenu = page.getByTestId("user-nav-menu");
|
||||
await expect(userNavMenu).toBeVisible();
|
||||
|
||||
const authMenuItem = page.getByTestId("user-nav-item-auth");
|
||||
await expect(authMenuItem).toContainText("Sign out");
|
||||
});
|
||||
|
||||
test("Do not navigate to /register for non-guest users", async ({
|
||||
page,
|
||||
}) => {
|
||||
await authPage.login(testUser.email, testUser.password);
|
||||
await page.waitForURL("/");
|
||||
|
||||
await page.goto("/register");
|
||||
await expect(page).toHaveURL("/");
|
||||
});
|
||||
|
||||
test("Do not navigate to /login for non-guest users", async ({ page }) => {
|
||||
await authPage.login(testUser.email, testUser.password);
|
||||
await page.waitForURL("/");
|
||||
|
||||
await page.goto("/login");
|
||||
await expect(page).toHaveURL("/");
|
||||
});
|
||||
});
|
||||
|
||||
test.describe("Entitlements", () => {
|
||||
let chatPage: ChatPage;
|
||||
|
||||
test.beforeEach(({ page }) => {
|
||||
chatPage = new ChatPage(page);
|
||||
});
|
||||
|
||||
test("Guest user cannot send more than 20 messages/day", async () => {
|
||||
test.fixme();
|
||||
await chatPage.createNewChat();
|
||||
|
||||
for (let i = 0; i <= 20; i++) {
|
||||
await chatPage.sendUserMessage("Why is the sky blue?");
|
||||
await chatPage.isGenerationComplete();
|
||||
}
|
||||
|
||||
await chatPage.sendUserMessage("Why is the sky blue?");
|
||||
await chatPage.expectToastToContain(
|
||||
getMessageByErrorCode("rate_limit:chat")
|
||||
);
|
||||
});
|
||||
});
|
||||
85
tests/e2e/sidebar.test.ts
Normal file
85
tests/e2e/sidebar.test.ts
Normal file
|
|
@ -0,0 +1,85 @@
|
|||
import { expect, test } from "@playwright/test";
|
||||
import { ChatPage } from "../pages/chat";
|
||||
|
||||
test.describe("Sidebar", () => {
|
||||
test("can toggle sidebar open and closed", async ({ page }) => {
|
||||
const chatPage = new ChatPage(page);
|
||||
await chatPage.createNewChat();
|
||||
|
||||
const toggleButton = page.getByTestId("sidebar-toggle-button");
|
||||
const sidebar = page.getByTestId("sidebar");
|
||||
|
||||
await toggleButton.click();
|
||||
await expect(sidebar).toBeVisible();
|
||||
|
||||
await toggleButton.click();
|
||||
await expect(sidebar).not.toBeVisible();
|
||||
});
|
||||
|
||||
test("shows chat in history after sending message", async ({ page }) => {
|
||||
const chatPage = new ChatPage(page);
|
||||
await chatPage.createNewChat();
|
||||
await chatPage.sendUserMessage("Test message for history");
|
||||
await chatPage.isGenerationComplete();
|
||||
|
||||
const toggleButton = page.getByTestId("sidebar-toggle-button");
|
||||
await toggleButton.click();
|
||||
|
||||
const historyItem = page.getByTestId("sidebar-chat-item").first();
|
||||
await expect(historyItem).toBeVisible();
|
||||
});
|
||||
|
||||
test("can navigate to chat from history", async ({ page }) => {
|
||||
const chatPage = new ChatPage(page);
|
||||
await chatPage.createNewChat();
|
||||
await chatPage.sendUserMessage("First chat message");
|
||||
await chatPage.isGenerationComplete();
|
||||
|
||||
const firstChatUrl = page.url();
|
||||
|
||||
await page.goto("/");
|
||||
|
||||
const toggleButton = page.getByTestId("sidebar-toggle-button");
|
||||
await toggleButton.click();
|
||||
|
||||
const historyItem = page.getByTestId("sidebar-chat-item").first();
|
||||
await historyItem.click();
|
||||
|
||||
await expect(page).toHaveURL(firstChatUrl);
|
||||
});
|
||||
|
||||
test("can delete chat from history", async ({ page }) => {
|
||||
const chatPage = new ChatPage(page);
|
||||
await chatPage.createNewChat();
|
||||
await chatPage.sendUserMessage("Chat to delete");
|
||||
await chatPage.isGenerationComplete();
|
||||
|
||||
const toggleButton = page.getByTestId("sidebar-toggle-button");
|
||||
await toggleButton.click();
|
||||
|
||||
const historyItem = page.getByTestId("sidebar-chat-item").first();
|
||||
await historyItem.hover();
|
||||
|
||||
const deleteButton = page.getByTestId("sidebar-chat-delete").first();
|
||||
await deleteButton.click();
|
||||
|
||||
const confirmButton = page.getByRole("button", { name: "Delete" });
|
||||
await confirmButton.click();
|
||||
|
||||
await expect(page.getByTestId("toast")).toContainText("deleted");
|
||||
});
|
||||
|
||||
test("can create new chat from sidebar", async ({ page }) => {
|
||||
const chatPage = new ChatPage(page);
|
||||
await chatPage.createNewChat();
|
||||
await chatPage.sendUserMessage("Initial message");
|
||||
await chatPage.isGenerationComplete();
|
||||
|
||||
const newChatButton = page.getByTestId("sidebar-new-chat");
|
||||
await newChatButton.click();
|
||||
|
||||
await expect(page).toHaveURL("/");
|
||||
await expect(page.getByTestId("multimodal-input")).toBeEmpty();
|
||||
});
|
||||
});
|
||||
|
||||
Loading…
Add table
Add a link
Reference in a new issue