import { test, expect } from "./fixtures/console-gate";

// Schedule details page must render Angular's `<schedule-details-header>`
// summary block between the day-tabs strip and the per-leg cards:
//
//   • One `details-header-badge` per flight in the URL (so a connecting
//     itinerary like SU 6188 + SU 6341 shows BOTH badges, not just one).
//   • A right-side cluster with the share/buy/last-update controls.
//   • For multi-leg trips, a `flight-details-full-route` timeline that
//     spans every leg, with formatted times (`00:30`, not raw ISO).
//
// This test pins those guarantees so the page can't regress to "no
// summary header" or "first-leg-only badge / raw ISO timeline" again.

const URL =
  "/ru-ru/schedule/VKO/SU6188-20260426/LED/SU6341-20260427/MMK?request=schedule-route-MOW-MMK-20260427-20260503";

test("summary header — both badges + last-update + formatted full-route timeline", async ({ page, consoleMessages }) => {
  await page.goto(URL);

  const summary = page.locator(".schedule-details__summary");
  await expect(summary).toBeVisible({ timeout: 15000 });

  // Both flight-number badges present (SU 6188 + SU 6341).
  const badges = summary.locator(".details-header-badge");
  await expect(badges).toHaveCount(2);
  await expect(summary).toContainText("SU 6188");
  await expect(summary).toContainText("SU 6341");

  // Last-update line is rendered (right-side cluster).
  await expect(summary).toContainText(/Последнее обновление:\s*\d{2}:\d{2}/);

  // Full-route timeline is present and shows formatted clock times
  // (00:30 / 02:00 / 06:30 / 08:20) — NOT raw ISO timestamps with
  // T-separators or '+03:00' offsets, which was a regression from
  // using `.local` instead of `.localTime`.
  const timeline = summary.locator(".full-route-timeline");
  await expect(timeline).toBeVisible();
  const timelineText = (await timeline.innerText()).replace(/\s+/g, " ");
  expect(timelineText).toMatch(/\b00:30\b/);
  expect(timelineText).toMatch(/\b02:00\b/);
  expect(timelineText).toMatch(/\b08:20\b/);
  expect(timelineText).not.toMatch(/2026-04-\d{2}T/);
  expect(timelineText).not.toContain("+03:00");
});
