import { expect } from "e2e";
import { readFileSync } from "node:fs";
import { test, IOS } from "./t3-mobile.ts";

test("Activity orders an offset commit and a later UTC comment chronologically", { ...IOS, video: "off" }, async ({ t3, app, screen }) => {
  const fixture = JSON.parse(readFileSync(process.env.SCENARIO_FIXTURE_FILE!, "utf8"));
  await t3.project("Chronological activity", {
    ".git/config": `[remote "origin"]\n  url = ${fixture.remote}\n  fetch = +refs/heads/*:refs/remotes/origin/*\n`,
  });
  await t3.open();
  await screen.getByTestId("workspace-tab-pullRequests").tap();
  await screen.getByText("Repro 28391 chronological activity", { exact: false }).first().tap();
  await screen.getByText("Activity", { exact: true }).tap();
  const commit = screen.getByRole("button", /View commit .*Older commit \(UTC\+14\)/);
  const comment = screen.getByText("Newer comment (UTC, two hours later)", { exact: true });
  const newestCommit = await commit.boundingBox();
  const newestComment = await comment.boundingBox();
  await app.startRecording({ name: "activity-sort" });
  await app.screenshot("newest-first");
  await screen.getByRole("button", "Newest first").tap();
  const oldestCommit = await commit.boundingBox();
  const oldestComment = await comment.boundingBox();
  await app.screenshot("oldest-first");
  await app.stopRecording();
  expect(newestComment!.y < newestCommit!.y && oldestCommit!.y < oldestComment!.y).toBe(true);
});
