// The Lucia project.
// Copyright 2026-2026 DSP, inc.  All rights reserved.
// Authors:
//   imacat.yang@dsp.im (imacat), 2026/03/22

import { test, expect } from "@playwright/test";
import { loginWithMSW } from "../helpers";

test.describe("Discover Conformance Page", () => {
  test.beforeEach(async ({ page, context }) => {
    await loginWithMSW(context);
    await page.goto("/discover/log/297310264/conformance");
    await expect(
      page.locator(".p-radiobutton, [class*=conformance]").first(),
    ).toBeVisible();
  });

  test("page loads and loading overlay disappears", async ({ page }) => {
    await expect(
      page.locator(".z-\\[9999\\]"),
    ).not.toBeVisible({ timeout: 10000 });
  });

  test("displays Rule Settings sidebar", async ({ page }) => {
    await expect(
      page.locator(".z-\\[9999\\]"),
    ).not.toBeVisible({ timeout: 10000 });
    await expect(page.getByText("Rule Settings")).toBeVisible();
  });

  test("displays Conformance Checking Results heading", async ({ page }) => {
    await expect(
      page.locator(".z-\\[9999\\]"),
    ).not.toBeVisible({ timeout: 10000 });
    await expect(
      page.getByText("Conformance Checking Results"),
    ).toBeVisible();
  });

  test("displays rule type radio options", async ({ page }) => {
    await expect(
      page.locator(".z-\\[9999\\]"),
    ).not.toBeVisible({ timeout: 10000 });
    await expect(page.getByText("Have activity")).toBeVisible();
    await expect(page.getByText("Activity sequence").first()).toBeVisible();
    await expect(page.getByText("Activity duration")).toBeVisible();
    await expect(page.getByText("Processing time")).toBeVisible();
    await expect(page.getByText("Waiting time")).toBeVisible();
    await expect(page.getByText("Cycle time")).toBeVisible();
  });

  test("displays Clear and Apply buttons", async ({ page }) => {
    await expect(
      page.locator(".z-\\[9999\\]"),
    ).not.toBeVisible({ timeout: 10000 });
    await expect(
      page.getByRole("button", { name: "Clear" }),
    ).toBeVisible();
    await expect(
      page.getByRole("button", { name: "Apply" }),
    ).toBeVisible();
  });

  test("displays Activity list area", async ({ page }) => {
    await expect(
      page.locator(".z-\\[9999\\]"),
    ).not.toBeVisible({ timeout: 10000 });
    await expect(page.getByText("Activity list")).toBeVisible();
  });

  test("displays default placeholder values in results", async ({
    page,
  }) => {
    await expect(
      page.locator(".z-\\[9999\\]"),
    ).not.toBeVisible({ timeout: 10000 });
    await expect(page.getByText("Conformance Rate")).toBeVisible();
    await expect(page.getByText("Cases").first()).toBeVisible();
  });
});
