|
| 1 | +/** |
| 2 | + * Route A through the pages. Sessions are minted, so CAS is not involved. |
| 3 | + * |
| 4 | + * student /rides/new fills the form Requested |
| 5 | + * student /rides ride is in this/next week |
| 6 | + * admin /admin?tab=Rides assigns driver + vehicle Scheduled |
| 7 | + * driver /rides Tomorrow tab shows it |
| 8 | + * student /rides/:id scheduled driver/vehicle |
| 9 | + * |
| 10 | + * Stops at Scheduled — the full lifecycle lives in routeB.ui.spec.ts. |
| 11 | + */ |
| 12 | +import type { Page } from "@playwright/test"; |
| 13 | +import { test, expect } from "./fixtures"; |
| 14 | +import { PERSONAS, LOCATIONS, VEHICLE } from "./seed"; |
| 15 | +import { estDateDaysFromNow } from "./routeTestHelpers"; |
| 16 | + |
| 17 | +const PICKUP = LOCATIONS.techSquare; |
| 18 | +const DROPOFF = LOCATIONS.studentCenter; |
| 19 | +const PICKUP_TIME = "2:00 PM"; |
| 20 | + |
| 21 | +/** TimeInput is a text box with a listbox; typing then Enter commits the first match. */ |
| 22 | +async function pickTime(input: ReturnType<Page["locator"]>, label: string) { |
| 23 | + await input.fill(label); |
| 24 | + await input.press("Enter"); |
| 25 | + await expect(input).toHaveValue(label); |
| 26 | +} |
| 27 | + |
| 28 | +function isEstSaturday(): boolean { |
| 29 | + return ( |
| 30 | + new Intl.DateTimeFormat("en-US", { |
| 31 | + timeZone: "America/New_York", |
| 32 | + weekday: "short", |
| 33 | + }).format(new Date()) === "Sat" |
| 34 | + ); |
| 35 | +} |
| 36 | + |
| 37 | +test("route A: student creates, admin schedules (UI)", async ({ |
| 38 | + pageAs, |
| 39 | + diag, |
| 40 | +}) => { |
| 41 | + test.setTimeout(90_000); |
| 42 | + |
| 43 | + const student = await pageAs("student"); |
| 44 | + |
| 45 | + // ── Student requests a ride ──────────────────────────────────────────── |
| 46 | + await student.goto("/rides/new"); |
| 47 | + await expect( |
| 48 | + student.getByRole("heading", { name: "Create Ride" }), |
| 49 | + ).toBeVisible(); |
| 50 | + |
| 51 | + const today = estDateDaysFromNow(0); |
| 52 | + const tomorrow = estDateDaysFromNow(1); |
| 53 | + if (tomorrow.getMonth() !== today.getMonth()) { |
| 54 | + await student.locator('button[type="button"]:has(svg)').nth(1).click(); |
| 55 | + } |
| 56 | + await student |
| 57 | + .getByRole("button", { name: String(tomorrow.getDate()), exact: true }) |
| 58 | + .click(); |
| 59 | + |
| 60 | + const times = student.getByPlaceholder("hh:mm"); |
| 61 | + await pickTime(times.nth(0), PICKUP_TIME); |
| 62 | + await pickTime(student.locator("#pickup-window-from"), "1:30 PM"); |
| 63 | + await pickTime(student.locator("#pickup-window-to"), "2:30 PM"); |
| 64 | + |
| 65 | + const selects = student.locator("select"); |
| 66 | + await selects.nth(0).selectOption({ label: PICKUP.name }); |
| 67 | + await selects.nth(1).selectOption({ label: DROPOFF.name }); |
| 68 | + |
| 69 | + const created = student.waitForResponse( |
| 70 | + (r) => r.url().endsWith("/api/routes") && r.request().method() === "POST", |
| 71 | + ); |
| 72 | + await student.getByRole("button", { name: "Submit" }).click(); |
| 73 | + const createRes = await created; |
| 74 | + expect(createRes.status(), await createRes.text()).toBe(201); |
| 75 | + const { _id: routeId } = (await createRes.json()) as { _id: string }; |
| 76 | + await expect(student).toHaveURL(/\/rides$/); |
| 77 | + |
| 78 | + // Tomorrow is next week when today is Saturday (weeks start Sunday EST). |
| 79 | + if (isEstSaturday()) { |
| 80 | + await student.getByText("Next Week", { exact: true }).click(); |
| 81 | + } |
| 82 | + |
| 83 | + const studentCard = student.getByTestId("ride-card").filter({ |
| 84 | + hasText: PICKUP_TIME, |
| 85 | + }); |
| 86 | + await expect(studentCard).toHaveCount(1); |
| 87 | + await expect( |
| 88 | + studentCard.getByText("Requested", { exact: true }), |
| 89 | + ).toBeVisible(); |
| 90 | + |
| 91 | + // ── Admin sees it and schedules ──────────────────────────────────────── |
| 92 | + const admin = await pageAs("admin"); |
| 93 | + await admin.goto("/admin?tab=Rides"); |
| 94 | + const row = admin |
| 95 | + .getByRole("row") |
| 96 | + .filter({ hasText: PERSONAS.student.lastName }) |
| 97 | + .filter({ hasText: PICKUP.name }) |
| 98 | + .filter({ hasText: DROPOFF.name }) |
| 99 | + .filter({ hasText: PICKUP_TIME }); |
| 100 | + await expect(row).toHaveCount(1); |
| 101 | + |
| 102 | + await row.getByText("Select driver").click(); |
| 103 | + await admin |
| 104 | + .getByRole("menuitem", { |
| 105 | + name: `${PERSONAS.driver.lastName}, ${PERSONAS.driver.firstName}`, |
| 106 | + }) |
| 107 | + .click(); |
| 108 | + await row.getByText("Select vehicle").click(); |
| 109 | + await admin |
| 110 | + .getByRole("menuitem", { |
| 111 | + name: `${VEHICLE.name} (${VEHICLE.licensePlate})`, |
| 112 | + }) |
| 113 | + .click(); |
| 114 | + |
| 115 | + const scheduled = admin.waitForResponse((r) => |
| 116 | + r.url().endsWith("/api/routes/schedule"), |
| 117 | + ); |
| 118 | + await row.getByRole("button", { name: "Assign" }).click(); |
| 119 | + const scheduleRes = await scheduled; |
| 120 | + expect(scheduleRes.status(), await scheduleRes.text()).toBe(200); |
| 121 | + await expect(row).toHaveCount(0); |
| 122 | + |
| 123 | + // ── Driver sees it on Tomorrow ───────────────────────────────────────── |
| 124 | + const driver = await pageAs("driver"); |
| 125 | + await driver.goto("/rides"); |
| 126 | + await driver.getByText("Tomorrow", { exact: true }).click(); |
| 127 | + const driverCard = driver |
| 128 | + .getByTestId("ride-card") |
| 129 | + .filter({ hasText: PICKUP.name }) |
| 130 | + .filter({ hasText: DROPOFF.name }); |
| 131 | + await expect(driverCard).toHaveCount(1); |
| 132 | + await expect( |
| 133 | + driverCard.getByText("Scheduled", { exact: true }), |
| 134 | + ).toBeVisible(); |
| 135 | + |
| 136 | + // ── Student sees scheduled assignment ────────────────────────────────── |
| 137 | + await student.goto(`/rides/${routeId}`); |
| 138 | + await expect( |
| 139 | + student |
| 140 | + .getByRole("heading", { name: "Ride Details" }) |
| 141 | + .locator("xpath=following-sibling::span[1]"), |
| 142 | + ).toHaveText("Scheduled"); |
| 143 | + await expect(student.getByText(PICKUP.name)).toBeVisible(); |
| 144 | + await expect(student.getByText(DROPOFF.name)).toBeVisible(); |
| 145 | + await expect(student.getByText(VEHICLE.name)).toBeVisible(); |
| 146 | + await expect(student.getByText(VEHICLE.licensePlate)).toBeVisible(); |
| 147 | + await expect( |
| 148 | + student.getByText( |
| 149 | + `${PERSONAS.driver.firstName} ${PERSONAS.driver.lastName}`, |
| 150 | + ), |
| 151 | + ).toBeVisible(); |
| 152 | + |
| 153 | + expect(diag.apiFailures, diag.summary()).toHaveLength(0); |
| 154 | +}); |
0 commit comments