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

test("Fixed-time schedules identify the server timezone for a remote client", WEB, async ({ t3, app, screen, browser }) => {
  await t3.project("Timezone demo");
  await t3.open();
  await screen.getByRole("button", "Settings", { exact: true }).tap();
  await app.open("/settings/scheduled-tasks");
  await screen.getByRole("button", "New task").tap();
  await screen.getByRole("textbox", "Name").fill("Daily timezone check");
  await screen.getByRole("textbox", "Prompt").fill("Check the synthetic demo project.");
  await browser.locator("#scheduled-task-workspace").tap();
  await screen.getByRole("option", "Use the project checkout").tap();
  await screen.getByRole("button", "At a time", { exact: true }).tap();
  await browser.locator("#scheduled-task-time").fill("16:31");
  await screen.getByRole("button", "Sat", { exact: true }).tap();
  await screen.getByRole("button", "Sun", { exact: true }).tap();
  await screen.getByRole("button", "Create task", { exact: true }).tap();
  await screen.getByRole("button", "Actions for Daily timezone check").tap();
  await browser.keyboard.press("Escape");
  await app.screenshot("saved-row");
  const rowText = await browser.evaluate(() => document.body.innerText);
  await screen.getByRole("button", "Actions for Daily timezone check").tap();
  await screen.getByRole("menuitem", "Edit", { exact: true }).tap();
  await browser.locator("#scheduled-task-time").tap();
  await app.screenshot("reopened-editor");
  const zone = await browser.evaluate(() => document.getElementById("scheduled-task-time-zone")?.textContent ?? "");
  await expect(rowText).toContain("16:31 UTC");
  await expect(zone).toBe("UTC");
});
