Files
PaperClipAI/ui/src/components/StarToggle.test.tsx
T
DottaandPaperclip 53d6297f75 fix(ui): simplify external object labels and star controls (#9929)
## Thinking Path

> - Paperclip is the open source control plane people use to manage AI
agents and their work
> - Operators rely on task detail properties and header actions to scan
linked resources and make quick decisions
> - External GitHub objects used a long pull-request label and repeated
mention counts that added visual noise without adding state
> - The task-detail star action also rendered as a labelled outline
button, unlike the compact star controls used elsewhere
> - These inconsistencies made dense task-detail surfaces slower to scan
and broke Paperclip's content-first visual language
> - This pull request shortens the GitHub pull-request label, removes
duplicate mention-count decoration, and aligns the detail star action
with the icon-only control pattern
> - The benefit is a calmer, more consistent task-detail experience with
accessible labels preserved for assistive technology

## Linked Issues or Issue Description

No matching public GitHub issue or open pull request was found.

**What happened?**

On the task detail surface, linked GitHub pull requests were labelled
`Github Pull Request` and could show a repeated `×N` mention count. The
detail-header star control used a labelled outline button rather than
the compact icon-only star pattern.

**Expected behavior**

Linked pull requests should use the concise `Github PR` label without
duplicate mention-count decoration, and the detail star action should
render as an accessible icon-only ghost button consistent with
neighboring controls.

**Steps to reproduce**

1. Open a task with a linked GitHub pull request mentioned more than
once.
2. Inspect the external-object property label and value row.
3. Inspect the star action in the task detail header.

**Paperclip version or commit:** `230126d80b` (`master` at preparation
time)

**Deployment / installation:** Local development, built from source.

**Scope:** Core UI; not adapter-specific, database-related, or
configuration-related.

## What Changed

- Render GitHub pull-request property labels as `Github PR`.
- Remove repeated external-object mention-count decoration from property
values.
- Render detail-header star controls as icon-only ghost buttons while
preserving `aria-label`, pressed, busy, error, and tooltip states.
- Expand component coverage for concise labels, duplicate-count
suppression, visual variants, and accessible star actions.

## Verification

- `pnpm --filter @paperclipai/ui exec vitest run
src/components/IssueProperties.test.tsx
src/components/StarToggle.test.tsx` — 54 tests passed.
- `pnpm --filter @paperclipai/ui typecheck` — passed.
- Visual review (before/after plus normal, starred, pending, and error
states):
https://htmlpreview.github.io/?https://gist.githubusercontent.com/cryppadotta/9688862a8826c1134aa2b2e8c16509d8/raw/45cb4921851f8968b21e7490e0d705161a9e165d/star-toggle-review.html
- `pnpm check:token-gates` — reports five existing `#9627` violations in
files unchanged by this PR; the same values are present on `master`.

## Risks

- Low risk: changes are limited to task-detail presentation and tests.
- The star action remains fully accessible through its existing ARIA
label and tooltip, but it no longer displays visible text.
- External-object mention counts remain available in data; only the
redundant property-row decoration is removed.

> For core feature work, check [`ROADMAP.md`](ROADMAP.md) first and
discuss it in `#dev` before opening the PR. Feature PRs that overlap
with planned core work may need to be redirected — check the roadmap
first. See `CONTRIBUTING.md`.

## Model Used

- OpenAI Codex, GPT-5.3 Codex, tool-enabled coding agent with repository
and shell access.

## Checklist

- [x] I have included a thinking path that traces from project context
to this change
- [x] I have specified the model used (with version and capability
details)
- [x] I have checked ROADMAP.md and confirmed this PR does not duplicate
planned core work
- [x] I have searched GitHub for duplicate or related PRs and linked
them above
- [x] I have either (a) linked existing issues with `Fixes: #` / `Closes
#` / `Refs #` OR (b) described the issue in-PR following the relevant
issue template
- [x] I have not referenced internal/instance-local Paperclip issues or
links (only public GitHub `#NNN` / `github.com/paperclipai/paperclip`
URLs)
- [x] My branch name describes the change (e.g. `docs/...`, `fix/...`)
and contains no internal Paperclip ticket id or instance-derived details
- [x] I have run tests locally and they pass
- [x] I have added or updated tests where applicable
- [x] I have updated relevant documentation to reflect my changes
- [x] I have considered and documented any risks above
- [x] All Paperclip CI gates are green
- [x] Greptile is 5/5 with no open P2s, recommendations, or follow-ups
- [x] I will address all Greptile and reviewer comments before
requesting merge

---------

Co-authored-by: Paperclip <noreply@paperclip.ing>
2026-07-21 09:14:29 -05:00

122 lines
4.6 KiB
TypeScript

// @vitest-environment jsdom
import { flushSync } from "react-dom";
import { createRoot } from "react-dom/client";
import { afterEach, beforeEach, describe, expect, it, vi } from "vitest";
import { StarToggle } from "./StarToggle";
// eslint-disable-next-line @typescript-eslint/no-explicit-any
(globalThis as any).IS_REACT_ACT_ENVIRONMENT = true;
async function act(callback: () => void | Promise<void>) {
let result: void | Promise<void> = undefined;
flushSync(() => {
result = callback();
});
await result;
}
describe("StarToggle", () => {
let container: HTMLDivElement;
let root: ReturnType<typeof createRoot> | null;
beforeEach(() => {
container = document.createElement("div");
document.body.appendChild(container);
root = null;
});
afterEach(async () => {
if (root) {
await act(async () => { root?.unmount(); });
}
container.remove();
document.body.innerHTML = "";
vi.clearAllMocks();
});
async function render(node: React.ReactElement) {
root = createRoot(container);
await act(async () => {
root?.render(node);
});
}
function button() {
return container.querySelector("button");
}
it("labels and announces the unstarred state and toggles toward starred", async () => {
const onToggle = vi.fn();
await render(<StarToggle starred={false} resourceName="Alpha" onToggle={onToggle} />);
const btn = button();
expect(btn?.getAttribute("aria-label")).toBe("Star Alpha");
expect(btn?.getAttribute("aria-pressed")).toBe("false");
await act(async () => { btn?.dispatchEvent(new MouseEvent("click", { bubbles: true })); });
expect(onToggle).toHaveBeenCalledWith(true);
});
it("labels and announces the starred state and toggles toward unstarred", async () => {
const onToggle = vi.fn();
await render(<StarToggle starred resourceName="Alpha" onToggle={onToggle} />);
const btn = button();
expect(btn?.getAttribute("aria-label")).toBe("Unstar Alpha");
expect(btn?.getAttribute("aria-pressed")).toBe("true");
// A starred (non-quiet) row control is visible at rest.
expect(btn?.className).toContain("opacity-100");
await act(async () => { btn?.dispatchEvent(new MouseEvent("click", { bubbles: true })); });
expect(onToggle).toHaveBeenCalledWith(false);
});
it("stays quiet (hidden at rest) for a starred sidebar row", async () => {
await render(
<StarToggle starred quiet resourceName="Alpha" onToggle={() => {}} revealClassName="reveal-me" />,
);
const btn = button();
// Quiet: even starred, hidden at rest and revealed via the passed class.
expect(btn?.className).toContain("reveal-me");
expect(btn?.className).not.toContain("opacity-100");
});
it("blocks input and spins while pending", async () => {
const onToggle = vi.fn();
await render(<StarToggle starred={false} pending resourceName="Alpha" onToggle={onToggle} />);
const btn = button();
expect(btn?.hasAttribute("disabled")).toBe(true);
expect(btn?.getAttribute("aria-busy")).toBe("true");
await act(async () => { btn?.dispatchEvent(new MouseEvent("click", { bubbles: true })); });
expect(onToggle).not.toHaveBeenCalled();
});
it("surfaces an icon-only retry affordance on error for the detail variant", async () => {
await render(<StarToggle starred size="button" error resourceName="Alpha" onToggle={() => {}} />);
const btn = button();
expect(btn?.textContent).toBe("");
expect(btn?.getAttribute("data-variant")).toBe("ghost");
expect(btn?.getAttribute("title")).toBe("Couldn't save — retry");
});
it("renders the unstarred detail variant as an unfilled icon without an outline", async () => {
await render(<StarToggle starred={false} size="button" resourceName="Alpha" onToggle={() => {}} />);
const btn = button();
expect(btn?.textContent).toBe("");
expect(btn?.getAttribute("data-variant")).toBe("ghost");
expect(btn?.getAttribute("aria-label")).toBe("Star Alpha");
expect(btn?.querySelector("svg")?.getAttribute("class")).not.toContain("fill-amber-500");
});
it("renders the detail variant as a filled, icon-only star without an outline", async () => {
await render(<StarToggle starred size="button" resourceName="Alpha" onToggle={() => {}} />);
const btn = button();
expect(btn?.textContent).toBe("");
expect(btn?.getAttribute("data-variant")).toBe("ghost");
expect(btn?.getAttribute("data-size")).toBe("icon-sm");
expect(btn?.getAttribute("aria-label")).toBe("Unstar Alpha");
expect(btn?.querySelector("svg")?.getAttribute("class")).toContain("fill-amber-500");
});
});