Skip to content
This repository has been archived by the owner on Feb 15, 2025. It is now read-only.

Commit

Permalink
chore: show copy/edit btns for non last message during regen (#444)
Browse files Browse the repository at this point in the history
* chore: show copy/edit btns for non last message during regen

* fix: display newlines
  • Loading branch information
andrewrisse authored Apr 29, 2024
1 parent 857f583 commit 7c67a4f
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 3 deletions.
3 changes: 2 additions & 1 deletion src/leapfrogai_ui/src/lib/components/Message.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@
<span on:click={() => (editMode = true)}><Edit aria-label="edit prompt" /></span>
</div>
{/if}
{#if message.role !== 'user' && !isLoading}
{#if message.role !== 'user' && (isLastMessage ? !isLoading : true)}
<div data-testid="copy btn" class="highlight-icon" class:hide={!messageIsHovered}>
<span on:click={handleCopy}><Copy aria-label="copy message" /></span>
</div>
Expand Down Expand Up @@ -120,6 +120,7 @@
}
.message {
display: flex;
white-space: pre-line;
}
.transparent {
Expand Down
24 changes: 22 additions & 2 deletions src/leapfrogai_ui/src/lib/components/Message.test.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { render, screen } from '@testing-library/svelte';
import { afterAll, afterEach, vi } from 'vitest';
import {afterAll, afterEach, type MockInstance, vi} from 'vitest';
import { Message } from '$components/index';
import userEvent from '@testing-library/user-event';
import { getFakeMessage } from '../../testUtils/fakeData';
Expand Down Expand Up @@ -66,7 +66,7 @@ describe('Message component', () => {
});

describe('util functions', () => {
let clipboardSpy;
let clipboardSpy: MockInstance;

afterAll(() => {
clipboardSpy.mockRestore();
Expand Down Expand Up @@ -165,5 +165,25 @@ describe('Message component', () => {
expect(screen.queryByLabelText('copy message')).not.toBeInTheDocument();
expect(screen.queryByLabelText('regenerate message')).not.toBeInTheDocument();
});
it('leaves the copy button for messages when it is loading if not the latest message', () => {
render(MessageWithToast, {
...defaultMessageProps,
message: getFakeMessage({ role: 'assistant' }),
isLastMessage: false,
isLoading: true
});
expect(screen.getByLabelText('copy message')).toBeInTheDocument();

});
it('leaves the edit button for messages when it is loading if not the latest message', () => {
render(MessageWithToast, {
...defaultMessageProps,
message: getFakeMessage({ role: 'user' }),
isLastMessage: false,
isLoading: true
});
expect(screen.getByRole('img', { name: /edit prompt/i })).toBeInTheDocument();

});
});
});

0 comments on commit 7c67a4f

Please sign in to comment.