Skip to content
Merged
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
Original file line number Diff line number Diff line change
Expand Up @@ -611,3 +611,25 @@ describe('MessageRow copy button', () => {
expect(await screen.findByRole('button', { name: 'Copy message failed' })).toBeInTheDocument()
})
})

describe('MessageRow copy placement', () => {
it('renders the copy affordance below the answer body and above the stats bar', () => {
render(
<MessageRow messageRole="assistant" body="The mesh has 3 nodes online." tokens="120 tok" timestamp="12:11" />
)
const copyRow = screen.getByTestId('message-copy-row')
expect(screen.getByText('The mesh has 3 nodes online.').compareDocumentPosition(copyRow)).toBe(
Node.DOCUMENT_POSITION_FOLLOWING
)
const stats = screen.getByText('120')
expect(copyRow.compareDocumentPosition(stats)).toBe(Node.DOCUMENT_POSITION_FOLLOWING)
})

it('renders the copy affordance below a user message body', () => {
render(<MessageRow messageRole="user" body="Summarize this mesh status" timestamp="12:10" />)
const copyRow = screen.getByTestId('message-copy-row')
expect(screen.getByText('Summarize this mesh status').compareDocumentPosition(copyRow)).toBe(
Node.DOCUMENT_POSITION_FOLLOWING
)
})
})
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ function CopyMessageButton({ text }: { text: string }) {
type="button"
aria-label={label}
title={label}
className="ml-auto inline-flex shrink-0 items-center justify-center rounded-[var(--radius-sm)] p-0.5 text-fg-faint opacity-0 outline-none transition-[opacity,color] hover:text-fg-dim focus-visible:opacity-100 focus-visible:outline focus-visible:outline-2 focus-visible:outline-offset-1 focus-visible:outline-accent group-hover:opacity-100 [@media(hover:none)]:opacity-100"
className="inline-flex shrink-0 items-center justify-center rounded-[var(--radius-sm)] p-0.5 text-fg-faint opacity-0 outline-none transition-[opacity,color] hover:text-fg-dim focus-visible:opacity-100 focus-visible:outline focus-visible:outline-2 focus-visible:outline-offset-1 focus-visible:outline-accent group-hover:opacity-100 [@media(hover:none)]:opacity-100"
onClick={(event) => {
event.stopPropagation()
void copyText(text)
Expand Down Expand Up @@ -342,7 +342,6 @@ export function MessageRow({
<span>Inspect</span>
</button>
) : null}
{copyableText ? <CopyMessageButton text={copyableText} /> : null}
</div>
<div
className="block select-text text-[length:var(--density-type-body-lg)] leading-[1.55]"
Expand Down Expand Up @@ -384,6 +383,11 @@ export function MessageRow({
</span>
) : null}
</div>
{copyableText ? (
<div className="flex justify-end" data-testid="message-copy-row">
<CopyMessageButton text={copyableText} />
</div>
) : null}
{isResponse && !isError ? (
<ResponseStatsBar
tokens={tokens}
Expand Down
Loading