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

test("LST: 'event rates' page shows error if 'Make Plot' button is clicked without selecting parameters first", async ({
  page,
}) => {
  await page.goto("/LSTs/event_rates");

  // Take a debug snapshot before hovering the sidebar
  await page.screenshot({
    path: "playwright-snapshot/1_event_rates_before_hovering_sidebar.png",
    fullPage: false,
  });

  // Simulates mouse movement over the sidebar to trigger sidebar expansion hover effects
  await page.hover("#sidebar-wrapper");

  // Wait 1 second to allow animation/effect
  await page.waitForTimeout(1000);

  // Take a debug snapshot after hovering the sidebar
  await page.screenshot({
    path: "playwright-snapshot/2_event_rates_after_hovering_sidebar.png",
    fullPage: false,
  });

  // Verify button existence
  const makePlotButton = await page.$("#makePlot");
  expect(makePlotButton).not.toBeNull();

  // Click on the button without selecting parameterss first
  await makePlotButton.click();

  // Wait for the error messageto appear in id="missingInfo")
  const errorMessage = await page.waitForSelector("#missingInfo", {
    timeout: 2000,
  });

  // Verify that the error message is visible and contains the expected text
  expect(await errorMessage.isVisible()).toBeTruthy();
  expect(await errorMessage.textContent()).toContain(
    "Please select a 'date' from the dropdown menu."
  );

  // Take a debug snapshot
  await page.screenshot({
    path: "playwright-snapshot/3_event_rates_error.png",
    fullPage: false,
  });
  await page.screenshot({
    path: "playwright-snapshot/3_event_rates_error_FULLPAGE.png",
    fullPage: true,
  });
});
