import { expect } from "e2e";

import { IOS, test } from "./t3-mobile.ts";

test(
  "The terminal font size uses the German decimal separator",
  IOS,
  async ({ t3, app, screen, device }) => {
    const project = await t3.project("demo");
    await t3.thread({ project, title: "Terminal work", messages: ["hello"] });
    // A local simulator keeps the last run's language and pairing.
    await app.clearState().catch(() => {});
    await t3.open();
    await screen.getByText("Terminal work", { exact: false }).first().waitFor({ timeout: 120_000 });

    const openSettings = async (page: string) => {
      await device.openLink(`t3code-dev://settings/${page}`, { app: "com.t3tools.t3code.dev" });
      await device.alert("accept").catch(() => {});
    };
    await openSettings("language");
    await screen.getByRole("radio", "Deutsch").check({ timeout: 60_000 });
    await screen.getByText("Sprache", { exact: true }).first().waitFor();

    await openSettings("appearance");
    // Terminal comes before Code, which has a switch with the same label.
    const custom = screen.getByRole("switch", "Eigene Schriftgröße").first();
    // A fling can carry the switch under the translucent header, where a tap misses it.
    await screen.scrollUntilVisible(custom, { momentum: "none" });
    await custom.check();
    // The default follows the base text size, so match the separator, not a value.
    const size = screen.getByText(/^\d+[.,]\d pt$/);
    await size.waitFor();
    await app.screenshot("german-terminal-font-size");
    await expect(size).toHaveText(/^\d+,\d pt$/);
  },
);
