// @vitest-environment jsdom
import { test, expect, afterEach } from "vitest";
import { render, screen, cleanup } from "@testing-library/react";
import userEvent from "@testing-library/user-event";
import { MemoryRouter } from "react-router-dom";
import { Screens } from "./App";
afterEach(cleanup);
test("direct URL resolves the record and back navigation", async () => {
  render(
    <MemoryRouter initialEntries={["/vehicles/car"]}>
      <Screens />
    </MemoryRouter>,
  );
  expect(screen.getByRole("heading").textContent).toBe("Family car");
  await userEvent.click(screen.getByRole("link", { name: "All vehicles" }));
  expect(screen.getByRole("heading").textContent).toBe("Vehicles");
});
test("unknown record is explicit", () => {
  render(
    <MemoryRouter initialEntries={["/vehicles/missing"]}>
      <Screens />
    </MemoryRouter>,
  );
  expect(screen.getByRole("heading").textContent).toBe("Vehicle not found");
});

test("unknown route", () => {
  render(
    <MemoryRouter initialEntries={["/missing"]}>
      <Screens />
    </MemoryRouter>,
  );
  expect(screen.getByRole("heading").textContent).toBe("Page not found");
});
