Spaces:
Running
Running
Download frontend-react/src/components/__tests__/VerifyForm.test.jsx from manan77709/clearvoice-api: direct link, hf CLI and curl.
- Browser
- Download file 1.85 kB
-
https://huggingface.co/spaces/manan77709/clearvoice-api/resolve/main/frontend-react/src/components/__tests__/VerifyForm.test.jsx
- Command line
-
hf download hf://spaces/manan77709/clearvoice-api/frontend-react/src/components/__tests__/VerifyForm.test.jsx
-
curl -L -o VerifyForm.test.jsx https://huggingface.co/spaces/manan77709/clearvoice-api/resolve/main/frontend-react/src/components/__tests__/VerifyForm.test.jsx
1.85 kB
| import { useState } from "react" | |
| import { render, screen } from "@testing-library/react" | |
| import userEvent from "@testing-library/user-event" | |
| import { describe, it, expect, vi } from "vitest" | |
| import VerifyForm from "../VerifyForm" | |
| import { SAMPLE_CLAIMS } from "../../constants" | |
| function ControlledVerifyForm({ initialClaim = "", onVerify = vi.fn(), onClear = vi.fn(), loading = false }) { | |
| const [claim, setClaim] = useState(initialClaim) | |
| return ( | |
| <VerifyForm | |
| claim={claim} | |
| loading={loading} | |
| onClaimChange={setClaim} | |
| onVerify={onVerify} | |
| onClear={onClear} | |
| /> | |
| ) | |
| } | |
| describe("VerifyForm", () => { | |
| it("submits when Enter is pressed", async () => { | |
| const user = userEvent.setup() | |
| const onVerify = vi.fn() | |
| render(<ControlledVerifyForm initialClaim="Exercise lowers heart risk" onVerify={onVerify} />) | |
| const textarea = screen.getByLabelText(/health claim/i) | |
| await user.click(textarea) | |
| await user.keyboard("{Enter}") | |
| expect(onVerify).toHaveBeenCalledTimes(1) | |
| }) | |
| it("inserts a newline without submitting on Shift+Enter", async () => { | |
| const user = userEvent.setup() | |
| const onVerify = vi.fn() | |
| render(<ControlledVerifyForm initialClaim="Line one" onVerify={onVerify} />) | |
| const textarea = screen.getByLabelText(/health claim/i) | |
| await user.click(textarea) | |
| await user.keyboard("{Shift>}{Enter}{/Shift}Line two") | |
| expect(onVerify).not.toHaveBeenCalled() | |
| expect(textarea).toHaveValue("Line one\nLine two") | |
| }) | |
| it("fills the textarea when a sample chip is clicked", async () => { | |
| const user = userEvent.setup() | |
| render(<ControlledVerifyForm />) | |
| const firstSample = SAMPLE_CLAIMS[0] | |
| await user.click(screen.getByRole("button", { name: firstSample })) | |
| expect(screen.getByLabelText(/health claim/i)).toHaveValue(firstSample) | |
| }) | |
| }) | |