hezarfen_frontend
Clone
https://git.tahinli.com/archive/hezarfen_frontend.git
0 watching0 forksTypeScript5.5 MiB5fcd955Burak Boduroğlu2 months ago730 commits
| 1 | import { cleanup, fireEvent, render, screen, waitFor } from "@solidjs/testing-library"; |
| 2 | import { afterEach, describe, expect, it, vi } from "vitest"; |
| 3 | import type { RagMessage } from "@/api/client"; |
| 4 | import { RagMessageRow } from "@/components/rag/rag-message-row"; |
| 5 | import { ragCopy } from "@/components/rag/rag-copy"; |
| 6 | |
| 7 | const labels = ragCopy("tr"); |
| 8 | |
| 9 | function message(over: Partial<RagMessage>): RagMessage { |
| 10 | return { |
| 11 | id: "m1", |
| 12 | thread_id: "t1", |
| 13 | role: "assistant", |
| 14 | status: "complete", |
| 15 | content: "Hücre zarı seçici geçirgendir.", |
| 16 | abstained: false, |
| 17 | reason: "", |
| 18 | citations: [], |
| 19 | created_at: Date.UTC(2026, 0, 2), |
| 20 | ...over, |
| 21 | }; |
| 22 | } |
| 23 | |
| 24 | describe("RagMessageRow", () => { |
| 25 | afterEach(() => { |
| 26 | cleanup(); |
| 27 | vi.restoreAllMocks(); |
| 28 | }); |
| 29 | |
| 30 | it("copies a finished answer and says so", async () => { |
| 31 | const writeText = vi.fn().mockResolvedValue(undefined); |
| 32 | Object.assign(navigator, { clipboard: { writeText } }); |
| 33 | |
| 34 | render(() => <RagMessageRow message={message({})} labels={labels} />); |
| 35 | |
| 36 | fireEvent.click(screen.getByRole("button", { name: labels.copy })); |
| 37 | |
| 38 | await waitFor(() => expect(writeText).toHaveBeenCalledWith("Hücre zarı seçici geçirgendir.")); |
| 39 | await waitFor(() => expect(screen.getByText(labels.copied)).toBeTruthy()); |
| 40 | }); |
| 41 | |
| 42 | it("offers no copy on the user's own turn", () => { |
| 43 | render(() => <RagMessageRow message={message({ role: "user" })} labels={labels} />); |
| 44 | |
| 45 | expect(screen.queryByRole("button", { name: labels.copy })).toBeNull(); |
| 46 | }); |
| 47 | |
| 48 | it("re-asks through the handler the panel supplies", () => { |
| 49 | const onRetry = vi.fn(); |
| 50 | render(() => <RagMessageRow message={message({ status: "failed" })} labels={labels} onRetry={onRetry} />); |
| 51 | |
| 52 | fireEvent.click(screen.getByRole("button", { name: labels.retry })); |
| 53 | |
| 54 | expect(onRetry).toHaveBeenCalledTimes(1); |
| 55 | }); |
| 56 | |
| 57 | it("shows no action row while the answer is still pending", () => { |
| 58 | render(() => <RagMessageRow message={message({ status: "pending", content: "" })} labels={labels} onRetry={vi.fn()} />); |
| 59 | |
| 60 | expect(screen.queryByRole("button", { name: labels.retry })).toBeNull(); |
| 61 | expect(screen.queryByRole("button", { name: labels.copy })).toBeNull(); |
| 62 | }); |
| 63 | }); |