Allow schedule weeks at date window edges
This commit is contained in:
@@ -0,0 +1,70 @@
|
||||
import { test, expect } from "./fixtures/console-gate";
|
||||
|
||||
function addDays(base: Date, days: number): Date {
|
||||
const d = new Date(base);
|
||||
d.setDate(d.getDate() + days);
|
||||
return d;
|
||||
}
|
||||
|
||||
function startOfWeekMonday(base: Date): Date {
|
||||
const d = new Date(base);
|
||||
d.setHours(0, 0, 0, 0);
|
||||
const offset = (d.getDay() + 6) % 7;
|
||||
d.setDate(d.getDate() - offset);
|
||||
return d;
|
||||
}
|
||||
|
||||
function yyyymmdd(date: Date): string {
|
||||
const y = date.getFullYear();
|
||||
const m = String(date.getMonth() + 1).padStart(2, "0");
|
||||
const d = String(date.getDate()).padStart(2, "0");
|
||||
return `${y}${m}${d}`;
|
||||
}
|
||||
|
||||
function currentScheduleWeekRange(): [string, string] {
|
||||
const scheduleMinDate = addDays(new Date(), -1);
|
||||
const monday = startOfWeekMonday(scheduleMinDate);
|
||||
return [yyyymmdd(monday), yyyymmdd(addDays(monday, 6))];
|
||||
}
|
||||
|
||||
function nextScheduleWeekRange(): [string, string] {
|
||||
const [currentWeekStart] = currentScheduleWeekRange();
|
||||
const monday = startOfWeekMonday(
|
||||
new Date(
|
||||
Number(currentWeekStart.slice(0, 4)),
|
||||
Number(currentWeekStart.slice(4, 6)) - 1,
|
||||
Number(currentWeekStart.slice(6, 8)),
|
||||
),
|
||||
);
|
||||
const nextMonday = addDays(monday, 7);
|
||||
return [yyyymmdd(nextMonday), yyyymmdd(addDays(nextMonday, 6))];
|
||||
}
|
||||
|
||||
test.describe("Schedule VVO-MJZ week route parity", () => {
|
||||
test("current schedule week route does not reset to the start page", async ({
|
||||
page,
|
||||
consoleMessages,
|
||||
}) => {
|
||||
const [dateFrom, dateTo] = currentScheduleWeekRange();
|
||||
await page.goto(`/ru-ru/schedule/route/VVO-MJZ-${dateFrom}-${dateTo}`);
|
||||
|
||||
await expect(page.locator("h1")).toContainText(/(Владивосток.*Мирный|VVO.*MJZ)/, {
|
||||
timeout: 30000,
|
||||
});
|
||||
await expect(page).toHaveURL(new RegExp(`/schedule/route/VVO-MJZ-${dateFrom}-${dateTo}`));
|
||||
});
|
||||
|
||||
test("next schedule week route renders without the search error page", async ({
|
||||
page,
|
||||
consoleMessages,
|
||||
}) => {
|
||||
const [dateFrom, dateTo] = nextScheduleWeekRange();
|
||||
await page.goto(`/ru-ru/schedule/route/VVO-MJZ-${dateFrom}-${dateTo}`);
|
||||
|
||||
await expect(page.locator("h1")).toContainText(/(Владивосток.*Мирный|VVO.*MJZ)/, {
|
||||
timeout: 30000,
|
||||
});
|
||||
await expect(page.getByText("Что-то пошло не так")).toBeHidden();
|
||||
await expect(page).toHaveURL(new RegExp(`/schedule/route/VVO-MJZ-${dateFrom}-${dateTo}`));
|
||||
});
|
||||
});
|
||||
Reference in New Issue
Block a user