/// <reference lib="dom" />
import { expect } from "e2e";
import { test, WEB } from "./t3.ts";

test("Link an existing model from a folder whose name ends in a space", WEB, async ({ t3, app, browser, screen }) => {
  await t3.project("demo");
  await browser.setViewport({ width: 1440, height: 1100 });
  await t3.open("/settings/voice");
  await screen.getByRole("combobox", "Transcribe with").tap();
  await screen.getByRole("option").nth(1).tap();
  await browser.locator('[placeholder="Search models"]').fill("Moonshine Tiny");
  const input = browser.locator('[aria-label="Path to a model file or folder already on this environment"]');
  await browser.evaluate(() => { document.querySelector('[aria-label="Path to a model file or folder already on this environment"]')?.scrollIntoView({ block: "center" }); });
  await input.fill("/tmp/factory-pr-47814-evidence-2/models ");
  await screen.getByRole("button", "Use existing", { exact: true }).tap();
  await screen.getByText(/Could not use a model from that path|Using your file at/).waitFor();
  await browser.evaluate(async () => { await Promise.all(document.getAnimations().filter(a => a.effect?.getComputedTiming().iterations !== Infinity).map(a => a.finished.catch(() => {}))); });
  await app.screenshot("literal-folder-path-result");
  await expect(screen.getByText("Using your file at /tmp/factory-pr-47814-evidence-2/models /moonshine-tiny-Q8_0.gguf", { exact: true })).toBeVisible();
});
