|
| 1 | +import { render, screen } from "@testing-library/svelte"; |
| 2 | +import RecursiveListHierarchyTest from "./RecursiveList.hierarchy.test.svelte"; |
| 3 | +import RecursiveListTest from "./RecursiveList.test.svelte"; |
| 4 | + |
| 5 | +const testCases = [ |
| 6 | + { name: "RecursiveList", component: RecursiveListTest }, |
| 7 | + { name: "RecursiveList hierarchy", component: RecursiveListHierarchyTest }, |
| 8 | +]; |
| 9 | + |
| 10 | +describe.each(testCases)("$name", ({ component }) => { |
| 11 | + it("renders all top-level items", () => { |
| 12 | + render(component); |
| 13 | + |
| 14 | + expect(screen.getByText("Item 1")).toBeInTheDocument(); |
| 15 | + expect(screen.getByText("Item 2")).toBeInTheDocument(); |
| 16 | + expect(screen.getByText("Item 3")).toBeInTheDocument(); |
| 17 | + |
| 18 | + expect(screen.getAllByRole("list")).toHaveLength(4); |
| 19 | + |
| 20 | + // Nested items |
| 21 | + expect(screen.getByText("Item 1a")).toBeInTheDocument(); |
| 22 | + }); |
| 23 | + |
| 24 | + it("renders HTML content", () => { |
| 25 | + render(component); |
| 26 | + |
| 27 | + const htmlContent = screen.getByText("HTML content"); |
| 28 | + expect(htmlContent.tagName).toBe("H5"); |
| 29 | + }); |
| 30 | + |
| 31 | + it("renders links correctly", () => { |
| 32 | + render(component); |
| 33 | + |
| 34 | + const links = screen.getAllByRole("link"); |
| 35 | + expect(links).toHaveLength(2); |
| 36 | + |
| 37 | + // Link with custom text |
| 38 | + const customLink = screen.getByText("Link with custom text"); |
| 39 | + expect(customLink).toHaveAttribute("href", "https://svelte.dev/"); |
| 40 | + |
| 41 | + // Plain link |
| 42 | + const plainLink = links.find( |
| 43 | + (link) => link.textContent === "https://svelte.dev/", |
| 44 | + ); |
| 45 | + expect(plainLink).toHaveAttribute("href", "https://svelte.dev/"); |
| 46 | + }); |
| 47 | +}); |
0 commit comments