|
| 1 | +import { render } from "@testing-library/react"; |
| 2 | +import { describe, expect, it, vi } from "vitest"; |
| 3 | +import { Streamdown } from "../index"; |
| 4 | + |
| 5 | +// Mock the dependencies |
| 6 | +vi.mock("harden-react-markdown", () => ({ |
| 7 | + default: (Component: any) => Component, |
| 8 | +})); |
| 9 | + |
| 10 | +describe("HTML Block Elements with Multiline Content - #164", () => { |
| 11 | + it("should render multiline content inside details element", () => { |
| 12 | + const content = `<details> |
| 13 | +<summary>Summary</summary> |
| 14 | +
|
| 15 | +Paragraph inside details. |
| 16 | +</details>`; |
| 17 | + |
| 18 | + const { container } = render(<Streamdown>{content}</Streamdown>); |
| 19 | + const details = container.querySelector("details"); |
| 20 | + const paragraph = container.querySelector("p"); |
| 21 | + |
| 22 | + expect(details).toBeTruthy(); |
| 23 | + expect(paragraph).toBeTruthy(); |
| 24 | + // The paragraph should be inside the details element |
| 25 | + expect(details?.contains(paragraph as Node)).toBe(true); |
| 26 | + }); |
| 27 | + |
| 28 | + it("should render multiline content inside div element", () => { |
| 29 | + const content = `<div> |
| 30 | +
|
| 31 | +Paragraph inside div. |
| 32 | +</div>`; |
| 33 | + |
| 34 | + const { container } = render(<Streamdown>{content}</Streamdown>); |
| 35 | + const div = container.querySelectorAll("div"); |
| 36 | + const paragraph = container.querySelector("p"); |
| 37 | + |
| 38 | + expect(div.length).toBeGreaterThan(0); |
| 39 | + expect(paragraph).toBeTruthy(); |
| 40 | + // The paragraph should be inside a div element |
| 41 | + const containingDiv = paragraph?.closest("div"); |
| 42 | + expect(containingDiv).toBeTruthy(); |
| 43 | + }); |
| 44 | + |
| 45 | + it("should handle multiple paragraphs inside details", () => { |
| 46 | + const content = `<details> |
| 47 | +<summary>Summary</summary> |
| 48 | +
|
| 49 | +First paragraph. |
| 50 | +
|
| 51 | +Second paragraph. |
| 52 | +</details>`; |
| 53 | + |
| 54 | + const { container } = render(<Streamdown>{content}</Streamdown>); |
| 55 | + const details = container.querySelector("details"); |
| 56 | + const paragraphs = container.querySelectorAll("p"); |
| 57 | + |
| 58 | + expect(details).toBeTruthy(); |
| 59 | + expect(paragraphs.length).toBeGreaterThan(0); |
| 60 | + // All paragraphs should be inside the details element |
| 61 | + for (const p of paragraphs) { |
| 62 | + expect(details?.contains(p)).toBe(true); |
| 63 | + } |
| 64 | + }); |
| 65 | + |
| 66 | + it("should preserve nested structure in complex HTML blocks", () => { |
| 67 | + const content = `<div> |
| 68 | +<details> |
| 69 | +<summary>Nested Summary</summary> |
| 70 | +
|
| 71 | +Content in nested structure. |
| 72 | +</details> |
| 73 | +</div>`; |
| 74 | + |
| 75 | + const { container } = render(<Streamdown>{content}</Streamdown>); |
| 76 | + const details = container.querySelector("details"); |
| 77 | + const paragraph = container.querySelector("p"); |
| 78 | + |
| 79 | + expect(details).toBeTruthy(); |
| 80 | + expect(paragraph).toBeTruthy(); |
| 81 | + // The paragraph should be inside the details element |
| 82 | + expect(details?.contains(paragraph as Node)).toBe(true); |
| 83 | + }); |
| 84 | +}); |
0 commit comments