Files
flights_web/tests/e2e/schedule-date-picker.spec.ts
T

94 lines
3.4 KiB
TypeScript

import { test, expect } from "./fixtures/console-gate";
import {
addDays,
formatRuDate,
formatRuWeekRange,
} from "./helpers/dates";
// Schedule date picker — Angular parity (TZ §4.1.9.4):
// • Single click on any day commits the **whole Mon-Sun week** that
// contains it (the schedule list is week-granular).
// • The panel auto-closes on selection.
// • The text input shows the snapped range as `DD.MM.YYYY - DD.MM.YYYY`.
// • Days bleeding into the previous / next month are clickable too
// (PrimeReact `selectOtherMonths`).
//
// The test derives dates from the real browser date. Schedule dates are
// valid only inside Angular's same rolling -1/+330 day window.
test.describe("Schedule date-range picker (week-snap)", () => {
test("single click snaps to Mon-Sun, closes panel, fills input", async ({
page,
consoleMessages,
}) => {
await page.goto("/ru-ru/schedule");
await expect(page.getByTestId("date-range-input")).toBeVisible({
timeout: 15000,
});
// Open the calendar via its trigger button.
await page.locator("button.p-datepicker-trigger").first().click();
const panel = page.locator(".p-datepicker-panel, .p-datepicker").first();
await expect(panel).toBeVisible();
const target = addDays(new Date(), 7);
await panel.locator(`td[aria-label="${formatRuDate(target)}"] span`).click();
// Panel auto-dismissed.
await expect(panel).toBeHidden({ timeout: 5000 });
// Input now holds the full week range.
const input = page.locator("#schedule-date-from");
await expect(input).toHaveValue(formatRuWeekRange(target));
});
test("clicking an enabled other-month bleed-in day snaps to its Mon-Sun week", async ({
page,
consoleMessages,
}) => {
await page.goto("/ru-ru/schedule");
await expect(page.getByTestId("date-range-input")).toBeVisible({
timeout: 15000,
});
await page.locator("button.p-datepicker-trigger").first().click();
const panel = page.locator(".p-datepicker-panel, .p-datepicker").first();
await expect(panel).toBeVisible();
// Move to a month whose first week contains prior-month bleed-in cells,
// then click one of those enabled other-month days.
let targetMonthOffset = 1;
while (targetMonthOffset < 6) {
const displayedMonth = new Date();
displayedMonth.setHours(0, 0, 0, 0);
displayedMonth.setMonth(displayedMonth.getMonth() + targetMonthOffset, 1);
const mondayBasedDay = (displayedMonth.getDay() + 6) % 7;
if (mondayBasedDay > 0) break;
targetMonthOffset += 1;
}
for (let i = 0; i < targetMonthOffset; i++) {
await page.locator(".p-datepicker-next").first().click();
}
const displayedMonth = new Date();
displayedMonth.setHours(0, 0, 0, 0);
displayedMonth.setMonth(displayedMonth.getMonth() + targetMonthOffset, 1);
const bleedTarget = addDays(displayedMonth, -1);
await panel.locator(`td[aria-label="${formatRuDate(bleedTarget)}"] span`).click();
await expect(panel).toBeHidden({ timeout: 5000 });
await expect(page.locator("#schedule-date-from")).toHaveValue(
formatRuWeekRange(bleedTarget),
);
});
test("input renders as range placeholder when empty", async ({ page, consoleMessages }) => {
await page.goto("/ru-ru/schedule");
const input = page.locator("#schedule-date-from");
await expect(input).toHaveAttribute(
"placeholder",
"ДД.ММ.ГГГГ - ДД.ММ.ГГГГ",
);
});
});