import { test, expect } from "@playwright/test";
import { installOnboardingApiStubs } from "./fixtures/api-stubs";
import { loginAsDdAdmin } from "./fixtures/login";

test.describe("Onboarding — Dealership Requests", () => {
    test.beforeEach(async ({ page }) => {
        await installOnboardingApiStubs(page);
    });

    test("DD Admin logs in via quick-login and sees shortlisted application", async ({
        page,
    }) => {
        await loginAsDdAdmin(page);

        await page.getByRole("button", { name: /Dealership Requests/i }).click();
        await expect(page).toHaveURL(/\/applications$/);

        await expect(
            page.getByRole("heading", { name: /Dealership Requests/i })
        ).toBeVisible();

        await expect(page.getByText("E2E Visible Dealer")).toBeVisible();
    });

    test("deep link to applications with restored session loads list", async ({
        page,
    }) => {
        await page.addInitScript((token: string) => {
            localStorage.setItem("token", token);
        }, "e2e-session-token");

        await page.goto("/applications");

        await expect(page.getByText("E2E Visible Dealer")).toBeVisible();
    });
});
