diff --git a/src/App.test.tsx b/src/App.test.tsx index 64ec6ac..3c697da 100644 --- a/src/App.test.tsx +++ b/src/App.test.tsx @@ -1,9 +1,61 @@ import React from "react"; import { render, screen } from "@testing-library/react"; import App from "./App"; +import { act } from "react-dom/test-utils"; test("Renders", () => { render(); const linkElement = screen.getAllByText(/None/i); expect(linkElement[0]).toBeInTheDocument(); }); + +test("Clicking on an option changes the displayed piece", () => { + // const { container } = render(); + render(); + + const radio = screen.getAllByRole("radio"); + + act(() => { + radio[0].click(); + }); + let pieceDisplay = screen.getByRole("none"); + let style = getComputedStyle(pieceDisplay).backgroundColor; + + expect(style).toEqual("yellow"); + + act(() => { + radio[1].click(); + }); + pieceDisplay = screen.getByRole("none"); + style = getComputedStyle(pieceDisplay).backgroundColor; + expect(style).toEqual("violet"); + + act(() => { + radio[2].click(); + }); + pieceDisplay = screen.getByRole("none"); + style = getComputedStyle(pieceDisplay).backgroundColor; + expect(style).toEqual("grey"); +}); + +test("Clicking on a node should change it", () => { + render(); + + const table = screen.getAllByRole("button"); + + for (let i = 0; i < table.length; i++) { + const item = table[i]; + + let style = getComputedStyle(item).backgroundColor; + + expect(style).toEqual("red"); + + act(() => { + item.click(); + }); + + style = getComputedStyle(item).backgroundColor; + + expect(style).toEqual("green"); + } +}); diff --git a/src/App.tsx b/src/App.tsx index 5c613ab..c548070 100644 --- a/src/App.tsx +++ b/src/App.tsx @@ -18,6 +18,7 @@ function ConeOrCube(props: { piece: cubeOrCone }): JSX.Element { return (
- {[0, 1, 2].map(function (key, row) { - return ( - - {table[row].map(function (item, key) { - return ( - -

Node ID #{row * 9 + key}

- - - ); - })} - - ); - })} + + {[0, 1, 2].map(function (key, row) { + return ( + + {table[row].map(function (item, key) { + return ( + +

Node ID #{row * 9 + key}

+ + + ); + })} + + ); + })} + ); } diff --git a/tests.txt b/tests.txt new file mode 100644 index 0000000..8c3ef25 Binary files /dev/null and b/tests.txt differ