| 1 | import { ApprovalRequestId, EnvironmentId } from "@t3tools/contracts"; |
| 2 | import type { ReactNode } from "react"; |
| 3 | import { renderToStaticMarkup } from "react-dom/server"; |
| 4 | import { describe, expect, it, vi } from "vite-plus/test"; |
| 5 | |
| 6 | vi.mock("react-native", () => ({ |
| 7 | View: "div", |
| 8 | Pressable: ({ children }: { children: ReactNode }) => <button>{children}</button>, |
| 9 | Linking: { openURL: vi.fn() }, |
| 10 | })); |
| 11 | vi.mock("expo-image", () => ({ Image: "img" })); |
| 12 | vi.mock("../../components/AppText", () => ({ AppText: "span" })); |
| 13 | vi.mock("../../state/assets", () => ({ useAssetUrl: () => null })); |
| 14 | |
| 15 | import { QuestionAnswerHistory } from "./QuestionAnswerHistory"; |
| 16 | |
| 17 | describe("QuestionAnswerHistory", () => { |
| 18 | it.each([{}, { text: "Text-only answer", file: "Answer with a file" }])( |
| 19 | "renders attachment-only questions alongside text answers: %j", |
| 20 | (answers) => { |
| 21 | const markup = renderToStaticMarkup( |
| 22 | <QuestionAnswerHistory |
| 23 | environmentId={EnvironmentId.make("environment-local")} |
| 24 | answer={{ |
| 25 | requestId: ApprovalRequestId.make("question-request"), |
| 26 | answers, |
| 27 | questionTextById: { file: "Provide a spec", image: "Provide a screenshot" }, |
| 28 | attachmentsByQuestionId: { |
| 29 | file: [ |
| 30 | { |
| 31 | type: "file", |
| 32 | id: "spec", |
| 33 | name: "spec.txt", |
| 34 | mimeType: "text/plain", |
| 35 | sizeBytes: 4, |
| 36 | }, |
| 37 | ], |
| 38 | image: [ |
| 39 | { |
| 40 | type: "image", |
| 41 | id: "shot", |
| 42 | name: "shot.png", |
| 43 | mimeType: "image/png", |
| 44 | sizeBytes: 4, |
| 45 | }, |
| 46 | ], |
| 47 | }, |
| 48 | }} |
| 49 | />, |
| 50 | ); |
| 51 | expect(markup.match(/Provide a spec/g)).toHaveLength(1); |
| 52 | expect(markup.match(/spec\.txt/g)).toHaveLength(1); |
| 53 | expect(markup).toContain("Provide a screenshot"); |
| 54 | expect(markup).toContain("shot.png"); |
| 55 | for (const answer of Object.values(answers)) expect(markup).toContain(answer); |
| 56 | }, |
| 57 | ); |
| 58 | }); |