import { expect } from "e2e";
import { IOS, test } from "./t3-mobile.ts";
import { runPromise } from "./t3.ts";
import { run } from "./shell.ts";

test("Feature branch push finds an unused name beyond 100 local refs", IOS, async ({t3, app, screen}) => {
 const project = await t3.project("branch-pagination");
 const git = (args: string[]) => runPromise(run("git", args, {cwd: project}));
 await git(["init", "--bare", `${project}-origin.git`]);
 await git(["remote", "add", "origin", `${project}-origin.git`]);
 await git(["push", "-u", "origin", "main"]);
 await git(["remote", "set-head", "origin", "main"]);
 for(let i=0;i<99;i++) await git(["branch", `bugfix/${String(i).padStart(3,"0")}`]);
 await git(["branch", "feature/update"]);
 await git(["-c","user.name=Scenario","-c","user.email=scenario@example.invalid","commit","--allow-empty","-m","Local change"]);
 await t3.thread({project,title:"Branch pagination proof",messages:["Look around"]});
 await t3.open();
 await screen.getByText("Branch pagination proof", {exact:false}).first().tap();
 await screen.getByRole("button", "Git controls").tap();
 await screen.getByText("Push", {exact:true}).tap();
 await app.screenshot("push-confirmation");
 await screen.getByText("Feature branch & continue", {exact:true}).tap();
 await app.screenshot("feature-branch-result");
 await expect(screen.getByText("Pushed to origin/feature/update-2", {exact:false})).toBeVisible();
 await app.screenshot("push-complete");
});
