Skip to content

Commit ebabecd

Browse files
committed
tests: correct weekend handling and add better labels for UI
1 parent 54f800f commit ebabecd

4 files changed

Lines changed: 48 additions & 40 deletions

File tree

‎src/app/rides/new/page.tsx‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -586,6 +586,7 @@ export default function CreateRidePage() {
586586
<div className={styles.calendarHeader}>
587587
<button
588588
type="button"
589+
aria-label="Previous month"
589590
onClick={prevMonth}
590591
className={styles.calendarNav}
591592
>
@@ -612,6 +613,7 @@ export default function CreateRidePage() {
612613
</div>
613614
<button
614615
type="button"
616+
aria-label="Next month"
615617
onClick={nextMonth}
616618
className={styles.calendarNav}
617619
>

‎tests/e2e/routeA.ui.spec.ts‎

Lines changed: 34 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -4,15 +4,15 @@
44
* student /rides/new fills the form Requested
55
* student /rides ride is in this/next week
66
* admin /admin?tab=Rides assigns driver + vehicle Scheduled
7-
* driver /rides Tomorrow tab shows it
7+
* driver /rides/:id scheduled ride is visible
88
* student /rides/:id scheduled driver/vehicle
99
*
1010
* Stops at Scheduled — the full lifecycle lives in routeB.ui.spec.ts.
1111
*/
1212
import type { Page } from "@playwright/test";
1313
import { test, expect } from "./fixtures";
1414
import { PERSONAS, LOCATIONS, VEHICLE } from "./seed";
15-
import { estDateDaysFromNow } from "./routeTestHelpers";
15+
import { estDateDaysFromNow, nextServiceDate } from "./routeTestHelpers";
1616

1717
const PICKUP = LOCATIONS.techSquare;
1818
const DROPOFF = LOCATIONS.studentCenter;
@@ -25,15 +25,6 @@ async function pickTime(input: ReturnType<Page["locator"]>, label: string) {
2525
await expect(input).toHaveValue(label);
2626
}
2727

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-
3728
test("route A: student creates, admin schedules (UI)", async ({
3829
pageAs,
3930
diag,
@@ -45,26 +36,29 @@ test("route A: student creates, admin schedules (UI)", async ({
4536
// ── Student requests a ride ────────────────────────────────────────────
4637
await student.goto("/rides/new");
4738
await expect(
48-
student.getByRole("heading", { name: "Create Ride" }),
39+
student.getByRole("heading", { name: "Request Ride" }),
4940
).toBeVisible();
5041

5142
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();
43+
const rideDate = nextServiceDate();
44+
if (rideDate.getMonth() !== today.getMonth()) {
45+
await student.getByRole("button", { name: "Next month" }).click();
5546
}
5647
await student
57-
.getByRole("button", { name: String(tomorrow.getDate()), exact: true })
48+
.getByRole("button", { name: String(rideDate.getDate()), exact: true })
5849
.click();
5950

6051
const times = student.getByPlaceholder("hh:mm");
6152
await pickTime(times.nth(0), PICKUP_TIME);
6253
await pickTime(student.locator("#pickup-window-from"), "1:30 PM");
6354
await pickTime(student.locator("#pickup-window-to"), "2:30 PM");
6455

65-
const selects = student.locator("select");
66-
await selects.nth(0).selectOption({ label: PICKUP.name });
67-
await selects.nth(1).selectOption({ label: DROPOFF.name });
56+
await student
57+
.getByRole("combobox", { name: "Pickup location" })
58+
.selectOption({ label: PICKUP.name });
59+
await student
60+
.getByRole("combobox", { name: "Dropoff location" })
61+
.selectOption({ label: DROPOFF.name });
6862

6963
const created = student.waitForResponse(
7064
(r) => r.url().endsWith("/api/routes") && r.request().method() === "POST",
@@ -75,8 +69,8 @@ test("route A: student creates, admin schedules (UI)", async ({
7569
const { _id: routeId } = (await createRes.json()) as { _id: string };
7670
await expect(student).toHaveURL(/\/rides$/);
7771

78-
// Tomorrow is next week when today is Saturday (weeks start Sunday EST).
79-
if (isEstSaturday()) {
72+
// Weeks start Sunday; a lower weekday means the ride is in next week.
73+
if (rideDate.getDay() <= today.getDay()) {
8074
await student.getByText("Next Week", { exact: true }).click();
8175
}
8276

@@ -120,18 +114,27 @@ test("route A: student creates, admin schedules (UI)", async ({
120114
expect(scheduleRes.status(), await scheduleRes.text()).toBe(200);
121115
await expect(row).toHaveCount(0);
122116

123-
// ── Driver sees it on Tomorrow ─────────────────────────────────────────
117+
// ── Driver sees the scheduled ride ─────────────────────────────────────
124118
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);
119+
// The driver list only covers today and tomorrow, not Monday after a weekend.
120+
if (rideDate.toDateString() === estDateDaysFromNow(1).toDateString()) {
121+
await driver.goto("/rides");
122+
await driver.getByText("Tomorrow", { exact: true }).click();
123+
const driverCard = driver
124+
.getByTestId("ride-card")
125+
.filter({ hasText: PICKUP.name })
126+
.filter({ hasText: DROPOFF.name });
127+
await expect(driverCard).toHaveCount(1);
128+
await expect(
129+
driverCard.getByText("Scheduled", { exact: true }),
130+
).toBeVisible();
131+
}
132+
await driver.goto(`/rides/${routeId}`);
132133
await expect(
133-
driverCard.getByText("Scheduled", { exact: true }),
134-
).toBeVisible();
134+
driver
135+
.getByRole("heading", { name: "Ride Details" })
136+
.locator("xpath=following-sibling::span[1]"),
137+
).toHaveText("Scheduled");
135138

136139
// ── Student sees scheduled assignment ──────────────────────────────────
137140
await student.goto(`/rides/${routeId}`);

‎tests/e2e/routeB.ui.spec.ts‎

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
import type { Page } from "@playwright/test";
1414
import { test, expect } from "./fixtures";
1515
import { PERSONAS, LOCATIONS, VEHICLE } from "./seed";
16-
import { estDateDaysFromNow } from "./routeTestHelpers";
16+
import { estDateDaysFromNow, nextServiceDate } from "./routeTestHelpers";
1717

1818
/** TimeInput is a text box with a listbox; typing then Enter commits the first match. */
1919
async function pickTime(input: ReturnType<Page["locator"]>, label: string) {
@@ -37,15 +37,9 @@ test("route B: driver start → pickup → dropoff (UI)", async ({
3737
).toBeVisible();
3838

3939
const today = estDateDaysFromNow(0);
40-
let offset = 1;
41-
let rideDate = estDateDaysFromNow(offset);
42-
while (rideDate.getDay() === 0 || rideDate.getDay() === 6) {
43-
offset += 1;
44-
rideDate = estDateDaysFromNow(offset);
45-
}
40+
const rideDate = nextServiceDate();
4641
if (rideDate.getMonth() !== today.getMonth()) {
47-
// Calendar header: [prev][month/year][next]; the nav buttons are the only icon buttons.
48-
await student.locator('button[type="button"]:has(svg)').nth(1).click();
42+
await student.getByRole("button", { name: "Next month" }).click();
4943
}
5044
await student
5145
.getByRole("button", { name: String(rideDate.getDate()), exact: true })

‎tests/e2e/routeTestHelpers.ts‎

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,15 @@ export function estDateDaysFromNow(days: number): Date {
1919
return addDays(toZonedTime(new Date(), "America/New_York"), days);
2020
}
2121

22+
export function nextServiceDate(): Date {
23+
let offset = 1;
24+
let date = estDateDaysFromNow(offset);
25+
while (date.getDay() === 0 || date.getDay() === 6) {
26+
date = estDateDaysFromNow(++offset);
27+
}
28+
return date;
29+
}
30+
2231
export function formatEstTime(iso: string): string {
2332
return new Date(iso).toLocaleTimeString("en-US", {
2433
timeZone: "America/New_York",

0 commit comments

Comments
 (0)