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

test("Invalid scheduled task URL parameters do not show a missing task", WEB, async ({ t3, app, screen }) => {
  const project = await t3.project("Scheduled tasks demo");
  await t3.thread({ project, title: "Demo", messages: ["Hello"], model: "multi-turn" });
  const observations: boolean[] = [];
  for (const [label, query] of [
    ["control-no-params", ""],
    ["invalid-number", "?taskId=123"],
    ["invalid-boolean", "?taskId=true"],
    ["invalid-blank", "?taskId=%20"],
    ["invalid-environment-number", "?environmentId=123"],
    ["invalid-environment-blank", "?environmentId=%20"],
    ["valid-missing-task", "?taskId=abc"],
  ]) {
    await t3.open(`/settings/scheduled-tasks${query}`);
    await screen.getByText("No scheduled tasks", { exact: true }).waitFor();
    await app.screenshot(label!);
    const missing = await screen.getByText("Task unavailable", { exact: true }).count();
    observations.push(label === "valid-missing-task" ? missing === 1 : missing === 0);
  }
  expect(observations).toEqual([true, true, true, true, true, true, true]);
});
