From 846daf0b168e35404c0fe9cdb713ec125f7dc090 Mon Sep 17 00:00:00 2001 From: Sebastian Martinez Date: Mon, 21 Oct 2024 18:22:32 +0200 Subject: [PATCH] Fix mutation of commit listing in place The commit listing on each patch revision started to be flaky when using browser navigation. It seems like the `Array.sort()` call started to reverse the order of the commit listing back to HEAD on top which isn't what we wanted. `Array.toReversed()` returns a fresh copy of the reversed array which is less error prone. --- src/views/repos/Cob/Revision.svelte | 2 +- tests/e2e/repo/patch.spec.ts | 29 +++++++++++++++++++++++++++++ tsconfig.json | 2 +- 3 files changed, 31 insertions(+), 2 deletions(-) diff --git a/src/views/repos/Cob/Revision.svelte b/src/views/repos/Cob/Revision.svelte index 22bfdd5ab..2f24124f7 100644 --- a/src/views/repos/Cob/Revision.svelte +++ b/src/views/repos/Cob/Revision.svelte @@ -437,7 +437,7 @@ {/if} {#if response?.commits}
- {#each response.commits.reverse() as commit} + {#each response.commits.toReversed() as commit}
diff --git a/tests/e2e/repo/patch.spec.ts b/tests/e2e/repo/patch.spec.ts index b0078679d..446a84d43 100644 --- a/tests/e2e/repo/patch.spec.ts +++ b/tests/e2e/repo/patch.spec.ts @@ -117,3 +117,32 @@ test("view file navigation from changes tab", async ({ page }) => { `${cobUrl}/tree/8c900d6cb38811e099efb3cbbdbfaba817bcf970/README.md`, ); }); + +test("commit listing ordering keeping stable on browser navigation", async ({ + page, +}) => { + await page.goto(`${cobUrl}/patches`); + await page + .getByRole("link", { name: "Taking another stab at the README" }) + .click(); + await page + .getByRole("heading", { name: "Taking another stab at the README" }) + .waitFor(); + + async function expectCorrectCommitListing() { + const commits = await page.locator(".commit").all(); + expect(commits).toHaveLength(2); + await expect( + commits[0].getByText("Rewrite subtitle to README"), + ).toBeVisible(); + await expect(commits[1].getByText("Add more text")).toBeVisible(); + } + + await expectCorrectCommitListing(); + await page.getByRole("link", { name: "Rewrite subtitle to README" }).click(); + await page.goBack(); + await page + .getByRole("heading", { name: "Taking another stab at the README" }) + .waitFor(); + await expectCorrectCommitListing(); +}); diff --git a/tsconfig.json b/tsconfig.json index f6b360862..f2f51ad23 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -4,7 +4,7 @@ "exclude": ["node_modules/*", "radicle-httpd/*"], "compilerOptions": { "noEmit": true, - "target": "es2021", + "target": "es2023", "module": "es2022", "types": ["vite/client"], "sourceMap": true,