From c7bb072eb532027627f814884e248a04691e16f6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?R=C5=ABdolfs=20O=C5=A1i=C5=86=C5=A1?= Date: Wed, 30 Sep 2026 17:15:05 +0200 Subject: [PATCH] Test editing, permissions, seeding and the inbox end to end Every write path gets a happy path and the contributor gets the permission cases the ADR asks for: labels, assignees, state, titles, comments, deleting, seeding by bare RID and clearing notifications. --- tests/e2e/inbox.spec.ts | 67 ++++++++++++ tests/e2e/repo/issueEditing.spec.ts | 155 ++++++++++++++++++++++++++++ tests/e2e/repo/patchEditing.spec.ts | 75 ++++++++++++++ tests/e2e/repo/permissions.spec.ts | 88 ++++++++++++++++ tests/e2e/seeding.spec.ts | 37 +++++++ 5 files changed, 422 insertions(+) create mode 100644 tests/e2e/inbox.spec.ts create mode 100644 tests/e2e/repo/issueEditing.spec.ts create mode 100644 tests/e2e/repo/patchEditing.spec.ts create mode 100644 tests/e2e/repo/permissions.spec.ts create mode 100644 tests/e2e/seeding.spec.ts diff --git a/tests/e2e/inbox.spec.ts b/tests/e2e/inbox.spec.ts new file mode 100644 index 000000000..70e01bb9a --- /dev/null +++ b/tests/e2e/inbox.spec.ts @@ -0,0 +1,67 @@ +import type { Page } from "@playwright/test"; +import type { PeerManager } from "@tests/support/peerManager.js"; + +import * as Path from "node:path"; + +import { + clone, + createCollaborators, + createProject, + waitForCobFrom, +} from "@tests/support/collaboration.js"; +import { + expect, + reload, + test, + useBackend, + waitForCommand, +} from "@tests/support/fixtures.js"; + +// Eve comments on bob's issue; the app runs as bob, who gets notified. +async function withNotification(page: Page, peerManager: PeerManager) { + const { bob, eve } = await createCollaborators(peerManager); + const { rid, issueId } = await createProject(bob); + await clone(eve, rid); + await eve.rad( + ["issue", "comment", issueId, "--message", "They are fine by me"], + { cwd: Path.join(eve.checkoutPath, "project") }, + ); + await waitForCobFrom(bob, eve, rid, issueId); + await bob.startHttpd(); + await useBackend(page, bob); + await page.goto("/inbox"); + const teaser = page.getByText("The notes are too quiet"); + await expect(teaser).toBeVisible(); + return teaser; +} + +test("a notification can be deleted", async ({ page, peerManager }) => { + const teaser = await withNotification(page, peerManager); + + await teaser.hover(); + await waitForCommand(page, "clear_notifications", () => + page.getByTitle("Delete", { exact: true }).click(), + ); + await expect(teaser).toBeHidden(); + await reload(page); + await expect(teaser).toBeHidden(); +}); + +test("all notifications can be cleared", async ({ page, peerManager }) => { + const teaser = await withNotification(page, peerManager); + + // The clear button only shows while the header is hovered. + await page + .getByRole("button", { name: "icon-search", exact: true }) + .last() + .hover(); + await page + .getByRole("button", { name: "icon-clear-all", exact: true }) + .click(); + await waitForCommand(page, "clear_notifications", () => + page.getByRole("button", { name: /^icon-clear-all Delete \d+$/ }).click(), + ); + await expect(teaser).toBeHidden(); + await reload(page); + await expect(teaser).toBeHidden(); +}); diff --git a/tests/e2e/repo/issueEditing.spec.ts b/tests/e2e/repo/issueEditing.spec.ts new file mode 100644 index 000000000..5e6ffa27a --- /dev/null +++ b/tests/e2e/repo/issueEditing.spec.ts @@ -0,0 +1,155 @@ +import type { Page } from "@playwright/test"; +import type { RadiclePeer } from "@tests/support/peerManager.js"; + +import { createProject } from "@tests/support/collaboration.js"; +import { + expect, + reload, + test, + waitForCommand, +} from "@tests/support/fixtures.js"; + +// Items in the menu behind a comment's "Comment actions" button. +async function commentAction(page: Page, body: string, action: string) { + await page.getByText(body).hover(); + const toggle = page.getByTitle("Comment actions").last(); + await toggle.click(); + await toggle + .locator( + `xpath=following::*[@role="button"][normalize-space()="${action}"][1]`, + ) + .click(); +} + +async function openIssue(page: Page, peer: RadiclePeer) { + const { rid, issueId } = await createProject(peer); + await page.goto(`/repos/${rid}/issues/${issueId}`); + await expect( + page.getByRole("button", { name: "The notes are too quiet" }), + ).toBeVisible(); + return { rid, issueId }; +} + +test("labels can be added and removed", async ({ page, peer }) => { + await openIssue(page, peer); + + await page.getByRole("button", { name: "Add labels" }).click(); + await page.getByPlaceholder("Add label").fill("documentation"); + await waitForCommand(page, "edit_issue", () => + page.getByPlaceholder("Add label").press("Enter"), + ); + const label = page.getByRole("button", { name: "documentation" }); + await expect(label).toBeVisible(); + + await page.getByRole("button", { name: "Add labels" }).click(); + await page.getByPlaceholder("Add label").fill("documentation"); + await expect(page.getByText("This label is already assigned")).toBeVisible(); + await page.getByPlaceholder("Add label").fill(""); + + await reload(page); + await expect(label).toBeVisible(); + + await label.click(); + await waitForCommand(page, "edit_issue", () => + label.getByRole("img", { name: "icon-close" }).click(), + ); + await expect(label).toBeHidden(); + await reload(page); + await expect(label).toBeHidden(); +}); + +test("an assignee can be added by DID", async ({ page, peer }) => { + await openIssue(page, peer); + + await page.getByRole("button", { name: "Add assignees" }).click(); + const input = page.getByPlaceholder(/^Assignee DID/); + await input.fill("alice"); + await expect(page.getByText("This is not a valid DID")).toBeVisible(); + + await input.fill(`did:key:${peer.nodeId}`); + await waitForCommand(page, "edit_issue", () => input.press("Enter")); + await expect(input).toBeHidden(); + + const assignees = page.getByRole("button", { + name: "icon-avatar-incognito Assignees", + exact: true, + }); + await expect(assignees).toBeVisible(); + await reload(page); + await assignees.click(); + await page.getByPlaceholder(/^Assignee DID/).fill(peer.nodeId); + await expect(page.getByText("This assignee is already added")).toBeVisible(); +}); + +test("an issue can be closed and reopened", async ({ page, peer }) => { + await openIssue(page, peer); + + await page.getByRole("button", { name: /^icon-issue Open/ }).click(); + await page.getByRole("button", { name: /Closed as solved$/ }).click(); + const closed = page.getByRole("button", { name: /Closed as solved/ }); + await expect(closed).toBeVisible(); + + await reload(page); + await expect(closed).toBeVisible(); + + await closed.click(); + await page + .getByRole("button", { name: "icon-issue Open", exact: true }) + .click(); + await expect(closed).toBeHidden(); +}); + +test("the title can be edited", async ({ page, peer }) => { + await openIssue(page, peer); + + await page.getByRole("button", { name: "The notes are too quiet" }).click(); + const input = page.locator("input:focus"); + await input.fill("The notes are much too quiet"); + await input.press("Enter"); + + const title = page.getByRole("button", { + name: "The notes are much too quiet", + }); + await expect(title).toBeVisible(); + await reload(page); + await expect(title).toBeVisible(); +}); + +test("a comment can be edited and deleted", async ({ page, peer }) => { + await openIssue(page, peer); + + await page.getByPlaceholder("Leave a comment").fill("I read them daily"); + await page.getByRole("button", { name: /^Comment/ }).click(); + await expect(page.getByText("I read them daily")).toBeVisible(); + + await commentAction(page, "I read them daily", "Edit"); + await page + .getByPlaceholder("Leave a comment") + .first() + .fill("I read them weekly"); + await page.getByRole("button", { name: /^Save/ }).click(); + await expect(page.getByText("I read them weekly")).toBeVisible(); + + await reload(page); + await expect(page.getByText("I read them weekly")).toBeVisible(); + + await commentAction(page, "I read them weekly", "Delete"); + await expect(page.getByText("I read them weekly")).toBeHidden(); + await reload(page); + await expect(page.getByText("I read them weekly")).toBeHidden(); +}); + +test("an issue can be deleted", async ({ page, peer }) => { + const { rid } = await openIssue(page, peer); + + await page.getByTitle("Delete issue from your node").click(); + await page + .getByRole("button", { name: "icon-trash Delete", exact: true }) + .last() + .click(); + + await expect(page).toHaveURL(new RegExp(`/repos/${rid}/issues`)); + // The list renders with its items, so once its filters show it's loaded. + await expect(page.getByRole("link", { name: /Closed/ })).toBeVisible(); + await expect(page.getByText("The notes are too quiet")).toBeHidden(); +}); diff --git a/tests/e2e/repo/patchEditing.spec.ts b/tests/e2e/repo/patchEditing.spec.ts new file mode 100644 index 000000000..1f06afe92 --- /dev/null +++ b/tests/e2e/repo/patchEditing.spec.ts @@ -0,0 +1,75 @@ +import type { Page } from "@playwright/test"; +import type { RadiclePeer } from "@tests/support/peerManager.js"; + +import { createProject } from "@tests/support/collaboration.js"; +import { + expect, + reload, + test, + waitForCommand, +} from "@tests/support/fixtures.js"; + +async function openPatch(page: Page, peer: RadiclePeer) { + const { rid, patchId } = await createProject(peer); + await page.goto(`/repos/${rid}/patches/${patchId}`); + await expect( + page.getByRole("button", { name: "Shout the third line" }), + ).toBeVisible(); + return { rid, patchId }; +} + +test("a patch can be labelled", async ({ page, peer }) => { + await openPatch(page, peer); + + await page.getByRole("button", { name: "Add labels" }).click(); + await page.getByPlaceholder("Add label").fill("needs-review"); + await waitForCommand(page, "edit_patch", () => + page.getByPlaceholder("Add label").press("Enter"), + ); + const label = page.getByRole("button", { name: "needs-review" }); + await expect(label).toBeVisible(); + + await reload(page); + await expect(label).toBeVisible(); +}); + +test("a patch can be archived, drafted and reopened", async ({ + page, + peer, +}) => { + await openPatch(page, peer); + + const state = (name: string) => + page.getByRole("button", { name: new RegExp(`${name} icon-chevron`) }); + + await state("Open").click(); + await page.getByRole("button", { name: /Archived$/ }).click(); + await expect(state("Archived")).toBeVisible(); + await reload(page); + await expect(state("Archived")).toBeVisible(); + + await state("Archived").click(); + await page.getByRole("button", { name: /Draft$/ }).click(); + await expect(state("Draft")).toBeVisible(); + + await state("Draft").click(); + await page.getByRole("button", { name: /Open$/ }).click(); + await expect(state("Open")).toBeVisible(); + await reload(page); + await expect(state("Open")).toBeVisible(); +}); + +test("a patch can be deleted", async ({ page, peer }) => { + const { rid } = await openPatch(page, peer); + + await page.getByTitle("Delete patch from your node").click(); + await page + .getByRole("button", { name: "icon-trash Delete", exact: true }) + .last() + .click(); + + await expect(page).toHaveURL(new RegExp(`/repos/${rid}/patches`)); + // The list renders with its items, so once its filters show it's loaded. + await expect(page.getByRole("link", { name: /Merged/ })).toBeVisible(); + await expect(page.getByText("Shout the third line")).toBeHidden(); +}); diff --git a/tests/e2e/repo/permissions.spec.ts b/tests/e2e/repo/permissions.spec.ts new file mode 100644 index 000000000..6f3bb3de3 --- /dev/null +++ b/tests/e2e/repo/permissions.spec.ts @@ -0,0 +1,88 @@ +import type { Page } from "@playwright/test"; +import type { PeerManager } from "@tests/support/peerManager.js"; + +import { + clone, + createCollaborators, + createProject, +} from "@tests/support/collaboration.js"; +import { expect, test, useBackend } from "@tests/support/fixtures.js"; + +// Opens bob's project as eve, who cloned it but isn't a delegate. +async function asContributor(page: Page, peerManager: PeerManager) { + const { bob, eve } = await createCollaborators(peerManager); + const project = await createProject(bob); + await bob.rad( + [ + "issue", + "comment", + project.issueId, + "--message", + "Bob's own comment", + "--quiet", + ], + { cwd: project.repoFolder }, + ); + await clone(eve, project.rid); + await eve.startHttpd(); + await useBackend(page, eve); + return project; +} + +test("a contributor can't edit an issue's metadata or delete it", async ({ + page, + peerManager, +}) => { + const { rid, issueId } = await asContributor(page, peerManager); + await page.goto(`/repos/${rid}/issues/${issueId}`); + await expect(page.getByText("Nobody reads them.")).toBeVisible(); + + await expect(page.getByRole("button", { name: "Add labels" })).toBeDisabled(); + await expect( + page.getByRole("button", { name: "Add assignees" }), + ).toBeDisabled(); + await expect( + page.getByTitle( + "Only the issue author and delegates can change the issue state", + ), + ).toBeVisible(); + await expect(page.getByTitle("Delete issue from your node")).toBeHidden(); +}); + +test("a contributor can't edit or delete someone else's comment", async ({ + page, + peerManager, +}) => { + const { rid, issueId } = await asContributor(page, peerManager); + await page.goto(`/repos/${rid}/issues/${issueId}`); + + await page.getByText("Bob's own comment").hover(); + const toggle = page.getByTitle("Comment actions").last(); + await toggle.click(); + const menuItem = (action: string) => + toggle.locator( + `xpath=following::*[@role="button"][normalize-space()="${action}"][1]`, + ); + await expect(menuItem("Copy ID")).toBeVisible(); + await expect(menuItem("Edit")).toHaveCount(0); + await expect(menuItem("Delete")).toHaveCount(0); +}); + +test("a contributor can't change a patch's state or delete it", async ({ + page, + peerManager, +}) => { + const { rid, patchId } = await asContributor(page, peerManager); + await page.goto(`/repos/${rid}/patches/${patchId}`); + await expect( + page.getByRole("button", { name: "Shout the third line" }), + ).toBeVisible(); + + await expect( + page.getByTitle( + "Only delegates and the patch author can change the patch state", + ), + ).toBeVisible(); + await expect(page.getByRole("button", { name: "Add labels" })).toBeDisabled(); + await expect(page.getByTitle("Delete patch from your node")).toBeHidden(); +}); diff --git a/tests/e2e/seeding.spec.ts b/tests/e2e/seeding.spec.ts new file mode 100644 index 000000000..389fd1cf8 --- /dev/null +++ b/tests/e2e/seeding.spec.ts @@ -0,0 +1,37 @@ +import { createCollaborators } from "@tests/support/collaboration.js"; +import { + expect, + test, + useBackend, + waitForCommand, +} from "@tests/support/fixtures.js"; +import { createRepo } from "@tests/support/repo.js"; + +test("seeds a repo from the network by its bare RID", async ({ + page, + peerManager, +}) => { + const { bob, eve } = await createCollaborators(peerManager); + const { rid } = await createRepo(eve, { name: "garden" }); + await bob.startHttpd(); + await useBackend(page, bob); + + await page.goto("/inbox"); + await page.getByRole("button", { name: "icon-plus", exact: true }).click(); + const input = page.getByPlaceholder(/^RID, e\.g\./); + await input.fill(rid.replace(/^rad:/, "")); + await waitForCommand(page, "seed", () => + page.getByRole("button", { name: "icon-seed Seed", exact: true }).click(), + ); + + await expect(page.getByRole("link", { name: /garden/ })).toBeVisible({ + timeout: 20_000, + }); + + await page.getByRole("button", { name: "icon-plus", exact: true }).click(); + await input.fill(rid); + await input.press("Enter"); + await expect( + page.getByText(/This repo is already (seeded|queued for fetching)/), + ).toBeVisible(); +});