import { expect } from "e2e";
import { test, WEB } from "./t3.ts";

test("Skipped usage warnings follow the selected dates", WEB, async ({ t3, app, screen, browser }) => {
  await t3.project("Usage demo");
  await t3.open();
  await browser.evaluate(() => localStorage.setItem("t3code:usage-page-preferences:v1", JSON.stringify({metric:"tokens",windowDays:90,hiddenProviders:["claude","grok","cursor","opencode","antigravity","pi","muse"]})));
  await t3.open("/usage");
  await screen.getByText("4.40K", {exact:true}).first().waitFor();
  const warning = screen.getByText("1 malformed or inconsistent usage record(s) were skipped; usage may be incomplete.", {exact:false});
  await warning.waitFor();
  await app.screenshot("90-days-includes-old-rejection");
  const observed: boolean[] = [];
  for (const [period,total] of [["7 days","3.30K"],["30 days","3.30K"],["Past 24h","0"]]) {
    await screen.getByRole("button", period, {exact:true}).tap();
    await screen.getByRole("button", "Refresh usage").waitFor();
    await browser.locator('button[aria-label="Refresh usage"]:not([disabled]):visible').waitFor();
    await screen.getByText(total, {exact:true}).first().waitFor();
    await app.screenshot(period.replaceAll(" ","-").toLowerCase());
    observed.push(await browser.evaluate(() => document.body.innerText.includes("1 malformed or inconsistent")));
  }
  await screen.getByRole("button", "90 days", {exact:true}).tap();
  await warning.waitFor();
  await app.screenshot("90-days-warning-restored");
  await expect(observed).toEqual([false,false,false]);
});
