Skip to content
Merged
Show file tree
Hide file tree
Changes from 2 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
5 changes: 4 additions & 1 deletion webview-ui/src/components/history/CopyButton.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,10 @@ export const CopyButton = ({ itemTask }: CopyButtonProps) => {
const onCopy = useCallback(
(e: React.MouseEvent) => {
e.stopPropagation()
!isCopied && copy(itemTask)
const tempDiv = document.createElement('div');
tempDiv.innerHTML = itemTask;
const text = tempDiv.textContent || tempDiv.innerText || "";
!isCopied && copy(text)
},
[isCopied, copy, itemTask],
)
Expand Down
6 changes: 4 additions & 2 deletions webview-ui/src/components/history/HistoryView.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,7 @@ const HistoryView = ({ onDone }: HistoryViewProps) => {
}}
data={tasks}
data-testid="virtuoso-container"
initialTopMostItemIndex={0}
components={{
List: React.forwardRef((props, ref) => (
<div {...props} ref={ref} data-testid="virtuoso-item-list" />
Expand Down Expand Up @@ -161,6 +162,7 @@ const HistoryView = ({ onDone }: HistoryViewProps) => {
wordBreak: "break-word",
overflowWrap: "anywhere",
}}
data-testid="task-content"
dangerouslySetInnerHTML={{ __html: item.task }}
/>
<div style={{ display: "flex", flexDirection: "column", gap: "4px" }}>
Expand Down Expand Up @@ -306,8 +308,8 @@ const HistoryView = ({ onDone }: HistoryViewProps) => {
</span>
</div>
<div className="flex flex-row gap-1">
<CopyButton itemTask={item.task} />
<ExportButton itemId={item.id} />
<CopyButton itemTask={item.task} />
<ExportButton itemId={item.id} />
</div>
</div>
)}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ import { vscode } from "../../../utils/vscode"
jest.mock("../../../context/ExtensionStateContext")
jest.mock("../../../utils/vscode")
jest.mock("../../../i18n/TranslationContext")

jest.mock("react-virtuoso", () => ({
Virtuoso: ({ data, itemContent }: any) => (
<div data-testid="virtuoso-container">
Expand Down Expand Up @@ -71,6 +70,12 @@ describe("HistoryView", () => {
})

it("handles search functionality", () => {
// Setup clipboard mock that resolves immediately
const mockClipboard = {
writeText: jest.fn().mockResolvedValue(undefined),
}
Object.assign(navigator, { clipboard: mockClipboard })

const onDone = jest.fn()
render(<HistoryView onDone={onDone} />)

Expand All @@ -97,6 +102,14 @@ describe("HistoryView", () => {
// Verify radio button is checked
const updatedRadio = within(radioGroup).getByRole("radio", { name: "Most Relevant", checked: true })
expect(updatedRadio).toBeInTheDocument()

// Verify copy the plain text content of the task when the copy button is clicked
const taskContainer = screen.getByTestId("virtuoso-item-1")
fireEvent.mouseEnter(taskContainer)
const copyButton = within(taskContainer).getByTitle("Copy Prompt");
fireEvent.click(copyButton);
const taskContent = within(taskContainer).getByTestId("task-content");
expect(navigator.clipboard.writeText).toHaveBeenCalledWith(taskContent.textContent);
})

it("handles sort options correctly", async () => {
Expand Down