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

// Schedule Details "Питание на борту" must render meal-class sub-icons
// (Эконом класс / Комфорт класс / Бизнес класс) ONLY when the API
// returns the matching `equipment.meal[].type` for that flight. Empty
// meal[] → just the cutlery icon + caption with no sub-icons. Mirrors
// Angular's `*ngIf="hasEconomyMeal"` etc. in
// flight-details-meal.component.html.
//
// Reference URL covers a connecting itinerary where
//   • SU 6188 returns meal=[] → no sub-icons
//   • SU 6341 returns meal=[Comfort, Economy, Business] → all three

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

test("Питание sub-icons appear only for legs whose API meal[] contains them", async ({
  page,
  consoleMessages,
}) => {
  await page.goto(URL);

  // Wait until both leg-details panels are mounted.
  await expect(page.locator(".schedule-leg-details")).toHaveCount(2, {
    timeout: 15000,
  });

  // ── Leg 1 (SU 6188, meal=[]) ─────────────────────────────────────
  const leg1 = page.locator(".schedule-leg-details").nth(0);
  await expect(leg1.getByText(/Sukhoi SuperJet/i)).toBeVisible();
  // Cutlery icon row + caption present.
  await expect(leg1.getByText("Питание на борту")).toBeVisible();
  // No sub-icons.
  await expect(leg1.getByText("Эконом класс")).toHaveCount(0);
  await expect(leg1.getByText("Комфорт класс")).toHaveCount(0);
  await expect(leg1.getByText("Бизнес класс")).toHaveCount(0);

  // ── Leg 2 (SU 6341, meal=[Comfort, Economy, Business]) ───────────
  const leg2 = page.locator(".schedule-leg-details").nth(1);
  await expect(leg2.getByText("Эконом класс")).toBeVisible();
  await expect(leg2.getByText("Комфорт класс")).toBeVisible();
  await expect(leg2.getByText("Бизнес класс")).toBeVisible();
});
