more merging

This commit is contained in:
counterweight 2025-12-25 00:06:32 +01:00
parent 67ffe6a823
commit d6f955d2d9
Signed by: counterweight
GPG key ID: 883EDBAA726BD96C
5 changed files with 107 additions and 251 deletions

View file

@ -45,44 +45,7 @@ test.describe("Availability Page - Admin Access", () => {
await expect(page.getByRole("button", { name: "Cancel" })).toBeVisible();
});
test("can add availability slot", async ({ page }) => {
await page.goto("/admin/availability");
// Wait for initial data load to complete
await page.waitForLoadState("networkidle");
// Find a day card with "No availability" and click on it
// This ensures we're clicking on a day without existing slots
const dayCardWithNoAvailability = page
.locator('[data-testid^="day-card-"]')
.filter({
has: page.getByText("No availability"),
})
.first();
await dayCardWithNoAvailability.click();
// Wait for modal
await expect(page.getByRole("heading", { name: /Edit Availability/ })).toBeVisible();
// Set up listeners for both PUT and GET before clicking Save to avoid race condition
const putPromise = page.waitForResponse(
(resp) => resp.url().includes("/api/admin/availability") && resp.request().method() === "PUT"
);
const getPromise = page.waitForResponse(
(resp) => resp.url().includes("/api/admin/availability") && resp.request().method() === "GET"
);
await page.getByRole("button", { name: "Save" }).click();
await putPromise;
await getPromise;
// Wait for modal to close
await expect(page.getByRole("heading", { name: /Edit Availability/ })).not.toBeVisible();
// Should now show the slot (the card we clicked should now have this slot)
await expect(page.getByText("09:00 - 17:00")).toBeVisible();
});
test("can clear availability", async ({ page }) => {
test("can add, clear, and add multiple availability slots", async ({ page }) => {
await page.goto("/admin/availability");
// Wait for initial data load to complete
@ -139,39 +102,31 @@ test.describe("Availability Page - Admin Access", () => {
// Slot should be gone from this specific card
await expect(targetCard.getByText("09:00 - 17:00")).not.toBeVisible();
});
test("can add multiple slots", async ({ page }) => {
await page.goto("/admin/availability");
// Wait for initial data load to complete
// Now test adding multiple slots - find another day card
await page.waitForLoadState("networkidle");
// Find a day card with "No availability" and click on it (to avoid conflicts with booking tests)
const dayCardWithNoAvailability = page
const anotherDayCard = page
.locator('[data-testid^="day-card-"]')
.filter({
has: page.getByText("No availability"),
})
.first();
const testId = await dayCardWithNoAvailability.getAttribute("data-testid");
const targetCard = page.locator(`[data-testid="${testId}"]`);
await dayCardWithNoAvailability.click();
const anotherTestId = await anotherDayCard.getAttribute("data-testid");
const anotherTargetCard = page.locator(`[data-testid="${anotherTestId}"]`);
await anotherDayCard.click();
await expect(page.getByRole("heading", { name: /Edit Availability/ })).toBeVisible();
// First slot is 09:00-17:00 by default - change it to morning only
const timeSelects = page.locator("select");
await timeSelects.nth(1).selectOption("12:00"); // Change first slot end to 12:00
await timeSelects.nth(1).selectOption("12:00");
// Add another slot for afternoon
await page.getByText("+ Add Time Range").click();
await timeSelects.nth(2).selectOption("14:00");
await timeSelects.nth(3).selectOption("17:00");
// Change second slot times to avoid overlap
await timeSelects.nth(2).selectOption("14:00"); // Second slot start
await timeSelects.nth(3).selectOption("17:00"); // Second slot end
// Set up listeners for both PUT and GET before clicking Save to avoid race condition
// Save multiple slots
const putPromise = page.waitForResponse(
(resp) => resp.url().includes("/api/admin/availability") && resp.request().method() === "PUT"
);
@ -183,9 +138,9 @@ test.describe("Availability Page - Admin Access", () => {
await getPromise;
await expect(page.getByRole("heading", { name: /Edit Availability/ })).not.toBeVisible();
// Should see both slots in the card we clicked
await expect(targetCard.getByText("09:00 - 12:00")).toBeVisible();
await expect(targetCard.getByText("14:00 - 17:00")).toBeVisible();
// Should see both slots
await expect(anotherTargetCard.getByText("09:00 - 12:00")).toBeVisible();
await expect(anotherTargetCard.getByText("14:00 - 17:00")).toBeVisible();
});
});