improve web testing (#3162)

* shared admin level test dependency

* change to on - push (recommended by chromatic)

* change playwright reporter to list, name test jobs

* use test tags ... much cleaner

* test vs prod

* try copying templates

* run with localhost?

* revert to dev

* new tests and a bit of refactoring

* add additional checks so that page snapshots reflect loaded state

* more admin tests

* User Management tests

* remaining admin pages

* test search and chat

* await fix and exclude UI that changes with dates.
This commit is contained in:
rkuo-danswer
2024-11-20 20:01:15 -08:00
committed by GitHub
parent 50826b6bef
commit 70207b4b39
32 changed files with 500 additions and 30 deletions

View File

@@ -0,0 +1,14 @@
import { test, expect } from "@chromatic-com/playwright";
test(
"Admin - Connectors - Add Connector",
{
tag: "@admin",
},
async ({ page }, testInfo) => {
// Test simple loading
await page.goto("http://localhost:3000/admin/add-connector");
await expect(page.locator("h1.text-3xl")).toHaveText("Add Connector");
await expect(page.locator("h1.text-lg").nth(0)).toHaveText(/^Storage/);
}
);

View File

@@ -0,0 +1,19 @@
import { test, expect } from "@chromatic-com/playwright";
test(
"Admin - User Management - API Keys",
{
tag: "@admin",
},
async ({ page }, testInfo) => {
// Test simple loading
await page.goto("http://localhost:3000/admin/api-key");
await expect(page.locator("h1.text-3xl")).toHaveText("API Keys");
await expect(page.locator("p.text-sm")).toHaveText(
/^API Keys allow you to access Danswer APIs programmatically/
);
await expect(
page.getByRole("button", { name: "Create API Key" })
).toHaveCount(1);
}
);

View File

@@ -0,0 +1,16 @@
import { test, expect } from "@chromatic-com/playwright";
test(
"Admin - Custom Assistants - Assistants",
{
tag: "@admin",
},
async ({ page }, testInfo) => {
// Test simple loading
await page.goto("http://localhost:3000/admin/assistants");
await expect(page.locator("h1.text-3xl")).toHaveText("Assistants");
await expect(page.locator("p.text-sm").nth(0)).toHaveText(
/^Assistants are a way to build/
);
}
);

View File

@@ -0,0 +1,24 @@
// dependency for all admin user tests
import { test as setup, expect } from "@playwright/test";
import { TEST_CREDENTIALS } from "./constants";
setup("authenticate", async ({ page }) => {
const { email, password } = TEST_CREDENTIALS;
await page.goto("http://localhost:3000/search");
await page.waitForURL("http://localhost:3000/auth/login?next=%2Fsearch");
await expect(page).toHaveTitle("Danswer");
await page.fill("#email", email);
await page.fill("#password", password);
// Click the login button
await page.click('button[type="submit"]');
await page.waitForURL("http://localhost:3000/search");
await page.context().storageState({ path: "admin_auth.json" });
});

View File

@@ -0,0 +1,16 @@
import { test, expect } from "@chromatic-com/playwright";
test(
"Admin - Custom Assistants - Slack Bots",
{
tag: "@admin",
},
async ({ page }, testInfo) => {
// Test simple loading
await page.goto("http://localhost:3000/admin/bots");
await expect(page.locator("h1.text-3xl")).toHaveText("Slack Bots");
await expect(page.locator("p.text-sm").nth(0)).toHaveText(
/^Setup Slack bots that connect to Danswer./
);
}
);

View File

@@ -0,0 +1,18 @@
import { test, expect } from "@chromatic-com/playwright";
test(
"Admin - Configuration - Document Processing",
{
tag: "@admin",
},
async ({ page }, testInfo) => {
// Test simple loading
await page.goto(
"http://localhost:3000/admin/configuration/document-processing"
);
await expect(page.locator("h1.text-3xl")).toHaveText("Document Processing");
await expect(page.locator("h3.text-2xl")).toHaveText(
"Process with Unstructured API"
);
}
);

View File

@@ -0,0 +1,16 @@
import { test, expect } from "@chromatic-com/playwright";
test(
"Admin - Configuration - LLM",
{
tag: "@admin",
},
async ({ page }, testInfo) => {
// Test simple loading
await page.goto("http://localhost:3000/admin/configuration/llm");
await expect(page.locator("h1.text-3xl")).toHaveText("LLM Setup");
await expect(page.locator("h1.text-lg").nth(0)).toHaveText(
"Enabled LLM Providers"
);
}
);

View File

@@ -0,0 +1,16 @@
import { test, expect } from "@chromatic-com/playwright";
test(
"Admin - Configuration - Search Settings",
{
tag: "@admin",
},
async ({ page }, testInfo) => {
// Test simple loading
await page.goto("http://localhost:3000/admin/configuration/search");
await expect(page.locator("h1.text-3xl")).toHaveText("Search Settings");
await expect(page.locator("h1.text-lg").nth(0)).toHaveText(
"Embedding Model"
);
}
);

View File

@@ -0,0 +1,16 @@
import { test, expect } from "@chromatic-com/playwright";
test(
"Admin - Document Management - Feedback",
{
tag: "@admin",
},
async ({ page }, testInfo) => {
// Test simple loading
await page.goto("http://localhost:3000/admin/documents/explorer");
await expect(page.locator("h1.text-3xl")).toHaveText("Document Explorer");
await expect(page.locator("div.flex.text-emphasis.mt-3")).toHaveText(
"Search for a document above to modify its boost or hide it from searches."
);
}
);

View File

@@ -0,0 +1,19 @@
import { test, expect } from "@chromatic-com/playwright";
test(
"Admin - Document Management - Feedback",
{
tag: "@admin",
},
async ({ page }, testInfo) => {
// Test simple loading
await page.goto("http://localhost:3000/admin/documents/feedback");
await expect(page.locator("h1.text-3xl")).toHaveText("Document Feedback");
await expect(page.locator("h1.text-lg").nth(0)).toHaveText(
"Most Liked Documents"
);
await expect(page.locator("h1.text-lg").nth(1)).toHaveText(
"Most Disliked Documents"
);
}
);

View File

@@ -0,0 +1,16 @@
import { test, expect } from "@chromatic-com/playwright";
test(
"Admin - Document Management - Document Sets",
{
tag: "@admin",
},
async ({ page }, testInfo) => {
// Test simple loading
await page.goto("http://localhost:3000/admin/documents/sets");
await expect(page.locator("h1.text-3xl")).toHaveText("Document Sets");
await expect(page.locator("p.text-sm")).toHaveText(
/^Document Sets allow you to group logically connected documents into a single bundle./
);
}
);

View File

@@ -0,0 +1,16 @@
import { test, expect } from "@chromatic-com/playwright";
test(
"Admin - User Management - Groups",
{
tag: "@admin",
},
async ({ page }, testInfo) => {
// Test simple loading
await page.goto("http://localhost:3000/admin/groups");
await expect(page.locator("h1.text-3xl")).toHaveText("Manage User Groups");
await expect(
page.getByRole("button", { name: "Create New User Group" })
).toHaveCount(1);
}
);

View File

@@ -0,0 +1,16 @@
import { test, expect } from "@chromatic-com/playwright";
test(
"Admin - Connectors - Existing Connectors",
{
tag: "@admin",
},
async ({ page }, testInfo) => {
// Test simple loading
await page.goto("http://localhost:3000/admin/indexing/status");
await expect(page.locator("h1.text-3xl")).toHaveText("Existing Connectors");
await expect(page.locator("p.text-sm")).toHaveText(
/^It looks like you don't have any connectors setup yet./
);
}
);

View File

@@ -0,0 +1,16 @@
import { test, expect } from "@chromatic-com/playwright";
test(
"Admin - Performance - Custom Analytics",
{
tag: "@admin",
},
async ({ page }, testInfo) => {
// Test simple loading
await page.goto("http://localhost:3000/admin/performance/custom-analytics");
await expect(page.locator("h1.text-3xl")).toHaveText("Custom Analytics");
await expect(page.locator("div.font-medium").nth(0)).toHaveText(
"Custom Analytics is not enabled."
);
}
);

View File

@@ -0,0 +1,14 @@
import { test, expect } from "@chromatic-com/playwright";
test(
"Admin - Performance - Query History",
{
tag: "@admin",
},
async ({ page }, testInfo) => {
// Test simple loading
await page.goto("http://localhost:3000/admin/performance/query-history");
await expect(page.locator("h1.text-3xl")).toHaveText("Query History");
await expect(page.locator("p.text-sm").nth(0)).toHaveText("Feedback Type");
}
);

View File

@@ -0,0 +1,19 @@
import { test, expect } from "@chromatic-com/playwright";
test.describe("Admin Performance Usage", () => {
// Ignores the diff for elements targeted by the specified list of selectors
test.use({ ignoreSelectors: ["button", "svg"] });
test(
"Admin - Performance - Usage Statistics",
{
tag: "@admin",
},
async ({ page }, testInfo) => {
await page.goto("http://localhost:3000/admin/performance/usage");
await expect(page.locator("h1.text-3xl")).toHaveText("Usage Statistics");
await expect(page.locator("h1.text-lg").nth(0)).toHaveText("Usage");
await expect(page.locator("h1.text-lg").nth(1)).toHaveText("Feedback");
}
);
});

View File

@@ -0,0 +1,16 @@
import { test, expect } from "@chromatic-com/playwright";
test(
"Admin - Custom Assistants - Prompt Library",
{
tag: "@admin",
},
async ({ page }, testInfo) => {
// Test simple loading
await page.goto("http://localhost:3000/admin/prompt-library");
await expect(page.locator("h1.text-3xl")).toHaveText("Prompt Library");
await expect(page.locator("p.text-sm")).toHaveText(
/^Create prompts that can be accessed/
);
}
);

View File

@@ -0,0 +1,19 @@
import { test, expect } from "@chromatic-com/playwright";
test(
"Admin - Settings - Workspace Settings",
{
tag: "@admin",
},
async ({ page }, testInfo) => {
// Test simple loading
await page.goto("http://localhost:3000/admin/settings");
await expect(page.locator("h1.text-3xl")).toHaveText("Workspace Settings");
await expect(page.locator("p.text-sm").nth(0)).toHaveText(
/^Manage general Danswer settings applicable to all users in the workspace./
);
await expect(
page.getByRole("button", { name: "Set Retention Limit" })
).toHaveCount(1);
}
);

View File

@@ -0,0 +1,16 @@
import { test, expect } from "@chromatic-com/playwright";
test(
"Admin - Custom Assistants - Standard Answers",
{
tag: "@admin",
},
async ({ page }, testInfo) => {
// Test simple loading
await page.goto("http://localhost:3000/admin/standard-answer");
await expect(page.locator("h1.text-3xl")).toHaveText("Standard Answers");
await expect(page.locator("p.text-sm").nth(0)).toHaveText(
/^Manage the standard answers for pre-defined questions./
);
}
);

View File

@@ -0,0 +1,22 @@
import { test, expect } from "@chromatic-com/playwright";
test(
"Admin - User Management - Token Rate Limits",
{
tag: "@admin",
},
async ({ page }, testInfo) => {
// Test simple loading
await page.goto("http://localhost:3000/admin/token-rate-limits");
await expect(page.locator("h1.text-3xl")).toHaveText("Token Rate Limits");
await expect(page.locator("p.text-sm").nth(0)).toHaveText(
/^Token rate limits enable you control how many tokens can be spent in a given time period./
);
await expect(
page.getByRole("button", { name: "Create a Token Rate Limit" })
).toHaveCount(1);
await expect(page.locator("h1.text-lg")).toHaveText(
"Global Token Rate Limits"
);
}
);

View File

@@ -0,0 +1,16 @@
import { test, expect } from "@chromatic-com/playwright";
test(
"Admin - Custom Assistants - Tools",
{
tag: "@admin",
},
async ({ page }, testInfo) => {
// Test simple loading
await page.goto("http://localhost:3000/admin/tools");
await expect(page.locator("h1.text-3xl")).toHaveText("Tools");
await expect(page.locator("p.text-sm")).toHaveText(
"Tools allow assistants to retrieve information or take actions."
);
}
);

View File

@@ -0,0 +1,19 @@
import { test, expect } from "@chromatic-com/playwright";
test(
"Admin - User Management - Groups",
{
tag: "@admin",
},
async ({ page }, testInfo) => {
// Test simple loading
await page.goto("http://localhost:3000/admin/users");
await expect(page.locator("h1.text-3xl")).toHaveText("Manage Users");
await expect(page.locator("div.font-bold").nth(0)).toHaveText(
"Invited Users"
);
await expect(page.locator("div.font-bold").nth(1)).toHaveText(
"Current Users"
);
}
);

View File

@@ -0,0 +1,18 @@
import { test, expect } from "@chromatic-com/playwright";
test(
"Admin - Performance - Whitelabeling",
{
tag: "@admin",
},
async ({ page }, testInfo) => {
// Test simple loading
await page.goto("http://localhost:3000/admin/whitelabeling");
await expect(page.locator("h1.text-3xl")).toHaveText("Whitelabeling");
await expect(page.locator("div.block").nth(0)).toHaveText(
"Application Name"
);
await expect(page.locator("div.block").nth(1)).toHaveText("Custom Logo");
await expect(page.getByRole("button", { name: "Update" })).toHaveCount(1);
}
);

View File

@@ -0,0 +1,19 @@
import { test, expect } from "@chromatic-com/playwright";
test(
"Chat",
{
tag: "@admin",
},
async ({ page }, testInfo) => {
// Test simple loading
await page.goto("http://localhost:3000/chat");
await expect(page.locator("div.text-2xl").nth(0)).toHaveText("General");
await expect(page.getByRole("button", { name: "Search S" })).toHaveClass(
/text-text-application-untoggled/
);
await expect(page.getByRole("button", { name: "Chat D" })).toHaveClass(
/text-text-application-toggled/
);
}
);

View File

@@ -0,0 +1,5 @@
// constants.js
export const TEST_CREDENTIALS = {
email: "admin_user@test.com",
password: "test",
};

View File

@@ -1,27 +1,31 @@
// Add this line
import { test, expect, takeSnapshot } from "@chromatic-com/playwright";
import { TEST_CREDENTIALS } from "./constants";
// Then use as normal 👇
test("Homepage", async ({ page }, testInfo) => {
// Test redirect to login, and redirect to search after login
test(
"Homepage",
{
tag: "@guest",
},
async ({ page }, testInfo) => {
// Test redirect to login, and redirect to search after login
const { email, password } = TEST_CREDENTIALS;
// move these into a constants file or test fixture soon
let email = "admin_user@test.com";
let password = "test";
await page.goto("http://localhost:3000/search");
await page.goto("http://localhost:3000/search");
await page.waitForURL("http://localhost:3000/auth/login?next=%2Fsearch");
await page.waitForURL("http://localhost:3000/auth/login?next=%2Fsearch");
await expect(page).toHaveTitle("Danswer");
await expect(page).toHaveTitle("Danswer");
await takeSnapshot(page, "Before login", testInfo);
await takeSnapshot(page, "Before login", testInfo);
await page.fill("#email", email);
await page.fill("#password", password);
await page.fill("#email", email);
await page.fill("#password", password);
// Click the login button
await page.click('button[type="submit"]');
// Click the login button
await page.click('button[type="submit"]');
await page.waitForURL("http://localhost:3000/search");
});
await page.waitForURL("http://localhost:3000/search");
}
);

View File

@@ -0,0 +1,19 @@
import { test, expect } from "@chromatic-com/playwright";
test(
"Search",
{
tag: "@admin",
},
async ({ page }, testInfo) => {
// Test simple loading
await page.goto("http://localhost:3000/search");
await expect(page.locator("div.text-3xl")).toHaveText("Unlock Knowledge");
await expect(page.getByRole("button", { name: "Search S" })).toHaveClass(
/text-text-application-toggled/
);
await expect(page.getByRole("button", { name: "Chat D" })).toHaveClass(
/text-text-application-untoggled/
);
}
);