Clamp schedule API dates at window edges
This commit is contained in:
@@ -21,6 +21,13 @@ function yyyymmdd(date: Date): string {
|
||||
return `${y}${m}${d}`;
|
||||
}
|
||||
|
||||
function apiDate(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);
|
||||
@@ -46,12 +53,25 @@ test.describe("Schedule VVO-MJZ week route parity", () => {
|
||||
consoleMessages,
|
||||
}) => {
|
||||
const [dateFrom, dateTo] = currentScheduleWeekRange();
|
||||
const minApiDate = apiDate(addDays(new Date(), -1));
|
||||
const scheduleSearch = page.waitForResponse(
|
||||
(response) =>
|
||||
response.url().includes("/api/flights/1/ru/schedule") &&
|
||||
response.url().includes("departure=VVO") &&
|
||||
response.url().includes("arrival=MJZ"),
|
||||
);
|
||||
|
||||
await page.goto(`/ru-ru/schedule/route/VVO-MJZ-${dateFrom}-${dateTo}`);
|
||||
|
||||
await expect(page.locator("h1")).toContainText(/(Владивосток.*Мирный|VVO.*MJZ)/, {
|
||||
timeout: 30000,
|
||||
});
|
||||
await expect(page.getByTestId("loader-bar")).toBeHidden({ timeout: 30000 });
|
||||
await expect(page.getByText("Неверные параметры поиска")).toBeHidden();
|
||||
await expect(page).toHaveURL(new RegExp(`/schedule/route/VVO-MJZ-${dateFrom}-${dateTo}`));
|
||||
|
||||
const requestUrl = new URL((await scheduleSearch).url());
|
||||
expect(requestUrl.searchParams.get("dateFrom")).toBe(minApiDate);
|
||||
});
|
||||
|
||||
test("next schedule week route renders without the search error page", async ({
|
||||
@@ -64,6 +84,8 @@ test.describe("Schedule VVO-MJZ week route parity", () => {
|
||||
await expect(page.locator("h1")).toContainText(/(Владивосток.*Мирный|VVO.*MJZ)/, {
|
||||
timeout: 30000,
|
||||
});
|
||||
await expect(page.getByTestId("loader-bar")).toBeHidden({ timeout: 30000 });
|
||||
await expect(page.getByText("Неверные параметры поиска")).toBeHidden();
|
||||
await expect(page.getByText("Что-то пошло не так")).toBeHidden();
|
||||
await expect(page).toHaveURL(new RegExp(`/schedule/route/VVO-MJZ-${dateFrom}-${dateTo}`));
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user