Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
38 changes: 35 additions & 3 deletions frontend/src/pages/Findings.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -468,7 +468,21 @@ export default function Findings() {
setCopiedFindingId(null)
}
}
async function copyFindingId(findingId: string) {
try {
await navigator.clipboard.writeText(findingId)

setCopiedFindingId(findingId)

window.setTimeout(() => {
setCopiedFindingId((current) =>
current === findingId ? null : current
)
}, 1600)
} catch {
setCopiedFindingId(null)
}
}
// ─── Keyboard navigation ────────────────────────────────────────────────────
const listRef = useRef<HTMLDivElement>(null)

Expand Down Expand Up @@ -940,9 +954,20 @@ export default function Findings() {
</div>

<div>
<p className="mb-2 text-[10px] font-black uppercase tracking-[0.2em] text-silver/35">Selected Finding</p>
<h2 className="text-3xl font-black uppercase italic tracking-tight text-silver-bright">{selectedFinding.title}</h2>
</div>
<p className="mb-2 text-[10px] font-black uppercase tracking-[0.2em] text-silver/35">
Selected Finding
</p>

<h2 className="text-3xl font-black uppercase italic tracking-tight text-silver-bright">
{selectedFinding.title}
</h2>

<div className="mt-3 flex items-center gap-2">
<span className="text-xs font-mono text-silver/60">
ID: {selectedFinding.id}
</span>
</div>
</div>

<div className="grid gap-3 sm:grid-cols-2">
<div className="border border-silver-bright/8 bg-charcoal-dark p-3">
Expand Down Expand Up @@ -1133,6 +1158,13 @@ export default function Findings() {
>
{copiedFindingId === selectedFinding.id ? 'Copied' : 'Copy Brief'}
</button>
<button
type="button"
onClick={() => copyFindingId(selectedFinding.id)}
className="border border-rag-green/25 bg-rag-green/10 px-4 py-3 text-[10px] font-black uppercase tracking-[0.18em] text-rag-green"
>
{copiedFindingId === selectedFinding.id ? 'Copied' : 'Copy ID'}
</button>
</div>
</div>
</div>
Expand Down
36 changes: 36 additions & 0 deletions frontend/testing/unit/pages/Findings.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -231,6 +231,42 @@ describe('Findings — virtualized list', () => {
})
})

it('copies finding id and shows success feedback', async () => {
const findings = [makeFinding({ id: 'f1', title: 'ID Copy Test' })]
vi.mocked(getFindings).mockResolvedValue({ findings })
Object.defineProperty(navigator, 'clipboard', {
configurable: true,
value: { writeText: vi.fn().mockResolvedValue(undefined) },
})

render(<Findings />)
await waitFor(() => expect(screen.queryByText('Synchronizing findings feed...')).not.toBeInTheDocument())

const copyButton = screen.getByRole('button', { name: /Copy ID/i })
await userEvent.click(copyButton)

await waitFor(() => expect(navigator.clipboard.writeText).toHaveBeenCalledWith('f1'))
expect(copyButton).toHaveTextContent('Copied')
})

it('keeps copy state idle when finding id copy fails', async () => {
const findings = [makeFinding({ id: 'f2', title: 'ID Copy Failure Test' })]
vi.mocked(getFindings).mockResolvedValue({ findings })
Object.defineProperty(navigator, 'clipboard', {
configurable: true,
value: { writeText: vi.fn().mockRejectedValue(new Error('clipboard unavailable')) },
})

render(<Findings />)
await waitFor(() => expect(screen.queryByText('Synchronizing findings feed...')).not.toBeInTheDocument())

const copyButton = screen.getByRole('button', { name: /Copy ID/i })
await userEvent.click(copyButton)

await waitFor(() => expect(navigator.clipboard.writeText).toHaveBeenCalledWith('f2'))
expect(copyButton).toHaveTextContent('Copy ID')
})

it('persists review state to localStorage', async () => {
const findings = [makeFinding({ id: 'f1', title: 'Persist Test', severity: 'high' })]
vi.mocked(getFindings).mockResolvedValue({ findings })
Expand Down