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

test("Scheduled interval units follow count and UI language", WEB, async ({ t3, app, browser, screen }) => {
  const project = await t3.project("interval-demo");
  await t3.thread({ project, title: "Interval demo", messages: ["Start"] });
  const units: string[] = [];
  const capture = async (language: string, label: string, count: string) => {
    await screen.getByRole("spinbutton", language === "en" ? "Run every" : "Ausführen alle").fill(count);
    units.push(await browser.evaluate(() => document.querySelector('#scheduled-task-interval')?.parentElement?.nextElementSibling?.textContent ?? "missing"));
    await app.screenshot(label);
  };
  await t3.open("/settings/scheduled-tasks");
  await screen.getByRole("button", "New task", { exact: true }).tap();
  await screen.getByRole("button", "Every interval", { exact: true }).tap();
  await capture("en", "en-15", "15");
  await capture("en", "en-1", "1");
  await screen.getByRole("button", "Cancel", { exact: true }).tap();
  await t3.open("/settings/general");
  await screen.getByLabel("Language", { exact: true }).tap();
  await screen.getByText("Deutsch", { exact: true }).tap();
  await screen.getByLabel("Sprache", { exact: true }).waitFor();
  await t3.open("/settings/scheduled-tasks");
  await screen.getByRole("button", "Neue Aufgabe", { exact: true }).tap();
  await screen.getByRole("button", "In einem Intervall", { exact: true }).tap();
  await capture("de", "de-1", "1");
  await capture("de", "de-15", "15");
  await capture("de", "de-1-5", "1.5");
  expect(units).toEqual(["minutes", "minute", "Minute", "Minuten", "Minuten"]);
});
