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

test("Missing npm is explained when updating both device tools", WEB, async ({ t3, app, screen, browser }) => {
  await t3.project("Device update demo");
  await t3.open("/settings/devices");
  const errors: string[] = [];
  for (const [tool, label] of [["Device hub", "hub"], ["Agent device", "agent-device"]]) {
    await t3.open("/settings/devices");
    await screen.getByRole("button", `${tool}: not installed. Show details`).tap();
    await screen.getByRole("button", "Update", { exact: true }).tap();
    const alert = screen.getByRole("alert");
    await alert.waitFor({ state: "visible" });
    errors.push(await alert.textContent());
    // Hold the visible result so the interaction recording is readable.
    await new Promise((resolve) => setTimeout(resolve, 2500));
    await app.screenshot(`${label}-update-error`);
    await browser.keyboard.press("Escape");
  }
  for (const message of errors) {
    expect(message).toContain("Device support needs npm");
    expect(message).toContain("restart T3 Code");
  }
});
