merged tests

This commit is contained in:
counterweight 2025-12-24 23:52:52 +01:00
parent 4be45f8f7c
commit 67ffe6a823
Signed by: counterweight
GPG key ID: 883EDBAA726BD96C
7 changed files with 212 additions and 599 deletions

View file

@ -21,14 +21,12 @@ test.describe("Admin Invites Page", () => {
await loginAsAdmin(page);
});
test("admin can access invites page", async ({ page }) => {
test("admin can access invites page and UI elements are correct", async ({ page }) => {
await page.goto("/admin/invites");
// Check page headings
await expect(page.getByRole("heading", { name: "Create Invite" })).toBeVisible();
await expect(page.getByRole("heading", { name: "All Invites" })).toBeVisible();
});
test("godfather selection is a dropdown with users, not a number input", async ({ page }) => {
await page.goto("/admin/invites");
// The godfather selector should be a <select> element, not an <input type="number">
const selectElement = page.locator("select").first();
@ -49,28 +47,7 @@ test.describe("Admin Invites Page", () => {
await expect(numberInput).toHaveCount(0);
});
test("can create invite by selecting user from dropdown", async ({ page }) => {
await page.goto("/admin/invites");
// Wait for page to load
await page.waitForSelector("select");
// Select the regular user as godfather
const godfatherSelect = page.locator("select").first();
await godfatherSelect.selectOption({ label: REGULAR_USER_EMAIL });
// Click create invite
await page.click('button:has-text("Create Invite")');
// Wait for the invite to appear in the table
await expect(page.locator("table")).toContainText(REGULAR_USER_EMAIL);
// Verify an invite code appears (format: word-word-NN)
const inviteCodeCell = page.locator("td").first();
await expect(inviteCodeCell).toHaveText(/^[a-z]+-[a-z]+-\d{2}$/);
});
test("create button is disabled when no user selected", async ({ page }) => {
test("can create invite with proper button state management", async ({ page }) => {
await page.goto("/admin/invites");
// Wait for page to load
@ -86,9 +63,19 @@ test.describe("Admin Invites Page", () => {
// Now the button should be enabled
await expect(createButton).toBeEnabled();
// Click create invite
await page.click('button:has-text("Create Invite")');
// Wait for the invite to appear in the table
await expect(page.locator("table")).toContainText(REGULAR_USER_EMAIL);
// Verify an invite code appears (format: word-word-NN)
const inviteCodeCell = page.locator("td").first();
await expect(inviteCodeCell).toHaveText(/^[a-z]+-[a-z]+-\d{2}$/);
});
test("can revoke a ready invite", async ({ page }) => {
test("can revoke invite and filter by status", async ({ page }) => {
await page.goto("/admin/invites");
await page.waitForSelector("select");
@ -96,6 +83,7 @@ test.describe("Admin Invites Page", () => {
const godfatherSelect = page.locator("select").first();
await godfatherSelect.selectOption({ label: REGULAR_USER_EMAIL });
await page.click('button:has-text("Create Invite")');
await expect(page.locator("table")).toContainText("ready");
// Wait for the new invite to appear and capture its code
// The new invite should be the first row with godfather = REGULAR_USER_EMAIL and status = ready
@ -115,35 +103,30 @@ test.describe("Admin Invites Page", () => {
// Verify this specific invite now shows "revoked"
const revokedRow = page.locator("tr").filter({ hasText: inviteCode! });
await expect(revokedRow).toContainText("revoked");
});
test("status filter works", async ({ page }) => {
await page.goto("/admin/invites");
await page.waitForSelector("select");
// Create an invite
const godfatherSelect = page.locator("select").first();
await godfatherSelect.selectOption({ label: REGULAR_USER_EMAIL });
await page.click('button:has-text("Create Invite")');
await expect(page.locator("table")).toContainText("ready");
// Filter by "revoked" status - should show no ready invites
// Test status filter - filter by "revoked" status
const statusFilter = page.locator("select").nth(1); // Second select is the status filter
await statusFilter.selectOption("revoked");
// Wait for the filter to apply
await page.waitForResponse((resp) => resp.url().includes("status=revoked"));
// Filter by "ready" status - should show our invite
// Filter by "ready" status - should show our invite (if we create another one)
await statusFilter.selectOption("ready");
await page.waitForResponse((resp) => resp.url().includes("status=ready"));
await expect(page.locator("table")).toContainText("ready");
});
});
test.describe("Admin Invites Access Control", () => {
test("regular user cannot access admin invites page", async ({ page }) => {
// Login as regular user
test("regular user and unauthenticated user cannot access admin invites page", async ({
page,
}) => {
// Test unauthenticated access
await page.context().clearCookies();
await page.goto("/admin/invites");
await expect(page).toHaveURL("/login");
// Test regular user access
await page.goto("/login");
await page.fill('input[type="email"]', REGULAR_USER_EMAIL);
await page.fill('input[type="password"]', "user123");
@ -156,12 +139,4 @@ test.describe("Admin Invites Access Control", () => {
// Should be redirected away (to home page based on fallbackRedirect)
await expect(page).not.toHaveURL("/admin/invites");
});
test("unauthenticated user cannot access admin invites page", async ({ page }) => {
await page.context().clearCookies();
await page.goto("/admin/invites");
// Should be redirected to login
await expect(page).toHaveURL("/login");
});
});