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

// On the schedule details page the left mini-list renders a SINGLE
// card for the currently-open flight — matching Angular's
// `schedule-flights-mini-list`, which only falls into the
// multi-day-accordion branch when `schedule.length > 1`. Previously
// the rail showed day-±1 siblings that read as visual duplicates of
// the open flight, and before that it dumped the whole route search.
//
// For a connecting itinerary the single card must surface BOTH
// flight numbers ("SU 6188, SU 6341") and the combined
// Moscow→Murmansk origin/destination, not just the first leg.

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

test("mini-list — one combined card for the open SU 6188+SU 6341 itinerary", async ({ page, consoleMessages }) => {
  await page.goto(URL);

  const miniList = page.locator(".schedule-mini-list");
  await expect(miniList).toBeVisible({ timeout: 15000 });

  // No day-grouping accordion headers, no day-siblings — just one row.
  await expect(miniList.locator("[data-testid^='mini-list-day-header-']")).toHaveCount(0);
  const items = miniList.locator("[data-testid^='mini-list-item-']");
  await expect(items).toHaveCount(1);

  const railText = (await miniList.innerText()).replace(/\s+/g, " ");
  // Both flight numbers present (Angular surfaces the whole chain).
  expect(railText).toContain("SU 6188");
  expect(railText).toContain("SU 6341");
  // Combined Moscow → Murmansk endpoints — NOT first-leg-only
  // Moscow → St Petersburg.
  expect(railText).toContain("Мурманск");
  expect(railText).not.toContain("Санкт-Петербург");
  // No unrelated route-mates from the parent search.
  expect(railText).not.toMatch(/SU\s*6190/);
  expect(railText).not.toMatch(/SU\s*6699/);
});
