|
| 1 | +import renderer from "react-test-renderer"; |
| 2 | +import { Footer } from "../footer"; |
| 3 | + |
| 4 | +describe("Footer", () => { |
| 5 | + it("renders when path is Game Board, News and not Chat", () => { |
| 6 | + const tree = renderer.create(<Footer path="/" />).toJSON(); |
| 7 | + expect(tree).not.toBeNull(); |
| 8 | + const tree2 = renderer.create(<Footer path="/news" />).toJSON(); |
| 9 | + expect(tree2).not.toBeNull(); |
| 10 | + const tree3 = renderer.create(<Footer path="/chat" />).toJSON(); |
| 11 | + expect(tree3).toBeNull(); |
| 12 | + }); |
| 13 | + it("applies active state styling for the selected page", () => { |
| 14 | + const homeTree = renderer.create(<Footer path="/" />).toJSON(); |
| 15 | + if (!homeTree || !("children" in homeTree)) { |
| 16 | + throw new Error("Game Board tree not rendered correctly"); |
| 17 | + } |
| 18 | + const homeChildren = homeTree.children as unknown as { |
| 19 | + type: string; |
| 20 | + props: { className: string }; |
| 21 | + children: { type: string; props: { className: string } }[]; |
| 22 | + }[]; |
| 23 | + const homeOpacities = homeChildren |
| 24 | + .map((child) => child.children?.[0]?.props?.className || "") |
| 25 | + .filter((className) => className.includes("opacity")); |
| 26 | + expect(homeOpacities[0]).toContain("opacity-100"); |
| 27 | + expect(homeOpacities[1]).toContain("opacity-70"); |
| 28 | + const newsTree = renderer.create(<Footer path="/news" />).toJSON(); |
| 29 | + if (!newsTree || !("children" in newsTree)) { |
| 30 | + throw new Error("News tree not rendered correctly"); |
| 31 | + } |
| 32 | + const newsChildren = newsTree.children as unknown as { |
| 33 | + type: string; |
| 34 | + props: { className: string }; |
| 35 | + children: { type: string; props: { className: string } }[]; |
| 36 | + }[]; |
| 37 | + const newsOpacities = newsChildren |
| 38 | + .map((child) => child.children?.[0]?.props?.className || "") |
| 39 | + .filter((className) => className.includes("opacity")); |
| 40 | + expect(newsOpacities[0]).toContain("opacity-70"); |
| 41 | + expect(newsOpacities[1]).toContain("opacity-100"); |
| 42 | + }); |
| 43 | + it("navigates to Game Board when the Game Board & News tabs are clicked", () => { |
| 44 | + const tree = renderer.create(<Footer path="/" />).toJSON(); |
| 45 | + if (!tree || !("children" in tree)) { |
| 46 | + throw new Error("Tree not rendered correctly"); |
| 47 | + } |
| 48 | + const treeChildren = tree.children as unknown as { |
| 49 | + type: string; |
| 50 | + props: { onClick: () => void }; |
| 51 | + }[]; |
| 52 | + treeChildren.forEach((child) => { |
| 53 | + if (child.props.onClick) { |
| 54 | + child.props.onClick(); |
| 55 | + } |
| 56 | + }); |
| 57 | + const newTree = renderer.create(<Footer path="/" />).toJSON(); |
| 58 | + if (!newTree || !("children" in newTree)) { |
| 59 | + throw new Error("Tree not rendered correctly"); |
| 60 | + } |
| 61 | + const newTreeChildren = newTree.children as unknown as { |
| 62 | + type: string; |
| 63 | + props: { className: string }; |
| 64 | + children: { type: string; props: { className: string } }[]; |
| 65 | + }[]; |
| 66 | + const newTreeOpacities = newTreeChildren |
| 67 | + .map((child) => child.children?.[0]?.props?.className || "") |
| 68 | + .filter((className) => className.includes("opacity")); |
| 69 | + expect(newTreeOpacities[0]).toContain("opacity-100"); |
| 70 | + expect(newTreeOpacities[1]).toContain("opacity-70"); |
| 71 | + }); |
| 72 | +}); |
0 commit comments