From 4ae2c76022b5b7e7ce075bac25deca67f6dbbb4c Mon Sep 17 00:00:00 2001 From: Pol Selles Climent <81540683+Pokesi@users.noreply.github.com> Date: Sun, 29 Jan 2023 15:51:59 +1100 Subject: [PATCH 1/6] Add tests for clicks --- src/App.test.tsx | 50 +++++++++++++++++++++++++++++++++++++++++++++ src/App.tsx | 52 ++++++++++++++++++++++++----------------------- tests.txt | Bin 0 -> 31800 bytes 3 files changed, 77 insertions(+), 25 deletions(-) create mode 100644 tests.txt diff --git a/src/App.test.tsx b/src/App.test.tsx index 64ec6ac..f95f6d7 100644 --- a/src/App.test.tsx +++ b/src/App.test.tsx @@ -1,9 +1,59 @@ import React from "react"; import { render, screen } from "@testing-library/react"; import App from "./App"; +import Button from "@mui/material/Button"; +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(); + + const radio = container.getElementsByTagName("label"); + act(() => { radio[0].click(); }); + let pieceDisplay = container.getElementsByClassName("coneOrCube")[0]; + let style = getComputedStyle(pieceDisplay).backgroundColor; + + expect(style).toEqual("yellow"); + + act(() => { radio[1].click(); }); + pieceDisplay = container.getElementsByClassName("coneOrCube")[0]; + style = getComputedStyle(pieceDisplay).backgroundColor; + + expect(style).toEqual("violet"); + + act(() => { radio[2].click(); }); + pieceDisplay = container.getElementsByClassName("coneOrCube")[0]; + style = getComputedStyle(pieceDisplay).backgroundColor; + + expect(style).toEqual("grey"); +}); + +test("Clicking on a node should change it", () => { + const { container } = render(); + + const table = container.getElementsByTagName("button"); + + for (let i = 0; i < table.length; i++) { + + const item = table[i]; + + let style = getComputedStyle(item).backgroundColor; + + console.log(item.children[1], item.children.length) + + expect(style).toEqual("red"); + + act(() => { + item.click(); + }) + + style = getComputedStyle(item).backgroundColor; + + expect(style).toEqual("green"); + } +}); \ No newline at end of file diff --git a/src/App.tsx b/src/App.tsx index 5c613ab..c0dada5 100644 --- a/src/App.tsx +++ b/src/App.tsx @@ -42,31 +42,33 @@ function Table(props: { return ( - {[0, 1, 2].map(function (key, row) { - return ( - - {table[row].map(function (item, key) { - return ( - - ); - })} - - ); - })} + + {[0, 1, 2].map(function (key, row) { + return ( + + {table[row].map(function (item, key) { + return ( + + ); + })} + + ); + })} +
-

Node ID #{row * 9 + key}

- -
+

Node ID #{row * 9 + key}

+ +
); } diff --git a/tests.txt b/tests.txt new file mode 100644 index 0000000000000000000000000000000000000000..8c3ef256bae186e417686fa9aef4a20efdb29300 GIT binary patch literal 31800 zcmeI5ZF3v95y$U!XZjsDnNFo-BFd6w*>ci0iefjO`XTj0{lZB#k|@clX-O4nJ8I&u z-uC~)3IXm8IPz#pd6*jxMd}DF7Q2hx1$F`a@4vq^mpKX+i|}euD#-&>VVO) zYK-;yPSAH$>r`b27j=7jLO<6|ax=_E>{c{QY_HQZ>QI)59?RR8Q!k;V@PyaOK&K za384-SUlFJwbj%AV^@a$#J!{3NcB(jbm(y0RjoAUMu#f)w@Vnu*!z-;>SM3?ljHgi zrPB0wx%fnX4@6OT+|&E5-pGaV*7q&Oy4;^n1S4+uz1sV%^u*eLH_+zH(F)mvu28t= z`ac$*-nieY5M$_1RpZFv29_h$0Pixc=MLV&MUTq73vEJadiPfFPERD7&kgCn{$>>+6^MDrIurD_%Ru)G`Tqss7Q=k)(ZDuQ0CurDuIt`cTh@u9a8% z=4E(E^-Ru38iVijJG5I8T%CC=39w;HXCt-jhH72gZ`MsZz#uNOBZ0bo?cYDM~GL$vr&Z~xj? zjd-l|g(qA=BkUJ#jtqcWY7IQ(?PTyb^UzMOh?)|NG)4^zvFB z$}Q>@u!mpAD)ZV=l~DrDJQ?a$)iqTtY#f}5E{vmb#Red!Xm2#@wi`VI2N%hYN6V5* zoapyuVa&)${nmF-&}Ku|J1-}FSL1eZt5|o^dhJ45V=fq$!D?M4Uh9&<+dqw=I#yUY ztmZw9%xB`7x0Iveq526$W2^UEbVgHbic({Z{y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M0+G|Aq&KO~88%cLCfMY|}Al zW&Dy=Nml&^50978h|@@*%94B-bos4}E~jm;^%oL6OL2jgM$%2(Z9q1FA46#ls(xzgNp}r$BsL2Fak=tc zOHjz}hluYzsowsBH%h5>efrx`uoPHO)A=SJWxKX0T6xb7nw5Wz{YhXxmmb~DmdQ&I zJ@7br$%;SgCu7r-o0VG3CD7&Em%tdn+d(s%-K={-e^E)s&zU6A=78MLa^R%h?s+=U z{{bqnw@Q$)0Ne}3>$4>9Z#f)OQc=CZ=SVFx5(B;af(~c6oeK{P`DK=Y&drqi(%I8N zgR?;wLox0jTXrLg8Ibww++~ATha_O}xc7;@pv(w3@rU1*^~C08Jll2u2fX<;{MUE& z(T0qmc(xYHsnMlAZ|ZAQyi=>(2Nc7kFTu)Obzl5_9yisi+^sCBzSKE@{ztFZ?;66> zv3t0nZ;(j%fd(`!?(Y)fq$6(a0ka%NoI%B1JV6FFMMYMg{9G@#XOl2WafQ1XxYr0z zs+rTY>7~i6FsE7B>^{FDFfFz6xN#TIs&Mn?Ao}rXdJh?69QGx1(D=BdnV#u?KT`cE z)@6O^pFS2Gd{aBe*SF#2-A<)S>uv62>s{QVgkEE>dpz>+XW*HwzL`cF>Obrr7?0I1 z-|8m_(`r@kdyImnjx$Be8arnT(BfqcZg-TeNeOmhc69{je_`wcz4Wc@R}AAw5^t@QUIvr+jEoUk0lxMzf|vU^LQBl?@M+V3vd}4 zmF=P|wS@bD1pj~dKyIR`-XSm~v+oW>ZE2mF`%(T&7llAHK3u~3vrzwoQ zj-3swyx!srXtSPqi{snA3jIFGlGFcRn|{X*mB$ Date: Sun, 29 Jan 2023 15:57:13 +1100 Subject: [PATCH 2/6] fix linter errors --- src/App.test.tsx | 25 +++++++++++++++---------- 1 file changed, 15 insertions(+), 10 deletions(-) diff --git a/src/App.test.tsx b/src/App.test.tsx index f95f6d7..ca98b20 100644 --- a/src/App.test.tsx +++ b/src/App.test.tsx @@ -14,23 +14,29 @@ test("Clicking on an option changes the displayed piece", () => { const { container } = render(); const radio = container.getElementsByTagName("label"); - act(() => { radio[0].click(); }); + act(() => { + radio[0].click(); + }); let pieceDisplay = container.getElementsByClassName("coneOrCube")[0]; let style = getComputedStyle(pieceDisplay).backgroundColor; expect(style).toEqual("yellow"); - act(() => { radio[1].click(); }); + act(() => { + radio[1].click(); + }); pieceDisplay = container.getElementsByClassName("coneOrCube")[0]; style = getComputedStyle(pieceDisplay).backgroundColor; - expect(style).toEqual("violet"); + expect(style).toEqual("violet"); - act(() => { radio[2].click(); }); + act(() => { + radio[2].click(); + }); pieceDisplay = container.getElementsByClassName("coneOrCube")[0]; style = getComputedStyle(pieceDisplay).backgroundColor; - expect(style).toEqual("grey"); + expect(style).toEqual("grey"); }); test("Clicking on a node should change it", () => { @@ -39,21 +45,20 @@ test("Clicking on a node should change it", () => { const table = container.getElementsByTagName("button"); for (let i = 0; i < table.length; i++) { - const item = table[i]; let style = getComputedStyle(item).backgroundColor; - console.log(item.children[1], item.children.length) + console.log(item.children[1], item.children.length); expect(style).toEqual("red"); act(() => { item.click(); - }) - + }); + style = getComputedStyle(item).backgroundColor; expect(style).toEqual("green"); } -}); \ No newline at end of file +}); From 349cc875fb92f39ef3de5cf2756c3fa174342757 Mon Sep 17 00:00:00 2001 From: Pol Selles Climent <81540683+Pokesi@users.noreply.github.com> Date: Sun, 29 Jan 2023 16:28:48 +1100 Subject: [PATCH 3/6] fix eslint warnings --- src/App.test.tsx | 23 +++++++++++------------ src/App.tsx | 2 ++ 2 files changed, 13 insertions(+), 12 deletions(-) diff --git a/src/App.test.tsx b/src/App.test.tsx index ca98b20..11d24a8 100644 --- a/src/App.test.tsx +++ b/src/App.test.tsx @@ -1,7 +1,6 @@ import React from "react"; import { render, screen } from "@testing-library/react"; import App from "./App"; -import Button from "@mui/material/Button"; import { act } from "react-dom/test-utils"; test("Renders", () => { @@ -11,13 +10,17 @@ test("Renders", () => { }); test("Clicking on an option changes the displayed piece", () => { - const { container } = render(); + // const { container } = render(); + render(); + + const radio = screen.getAllByRole('radio'); + + console.log(radio) - const radio = container.getElementsByTagName("label"); act(() => { radio[0].click(); }); - let pieceDisplay = container.getElementsByClassName("coneOrCube")[0]; + let pieceDisplay = screen.getByRole("none"); let style = getComputedStyle(pieceDisplay).backgroundColor; expect(style).toEqual("yellow"); @@ -25,32 +28,28 @@ test("Clicking on an option changes the displayed piece", () => { act(() => { radio[1].click(); }); - pieceDisplay = container.getElementsByClassName("coneOrCube")[0]; + pieceDisplay = screen.getByRole("none"); style = getComputedStyle(pieceDisplay).backgroundColor; - expect(style).toEqual("violet"); act(() => { radio[2].click(); }); - pieceDisplay = container.getElementsByClassName("coneOrCube")[0]; + pieceDisplay = screen.getByRole("none"); style = getComputedStyle(pieceDisplay).backgroundColor; - expect(style).toEqual("grey"); }); test("Clicking on a node should change it", () => { - const { container } = render(); + render(); - const table = container.getElementsByTagName("button"); + const table = screen.getAllByRole("btn"); for (let i = 0; i < table.length; i++) { const item = table[i]; let style = getComputedStyle(item).backgroundColor; - console.log(item.children[1], item.children.length); - expect(style).toEqual("red"); act(() => { diff --git a/src/App.tsx b/src/App.tsx index c0dada5..1dcc872 100644 --- a/src/App.tsx +++ b/src/App.tsx @@ -18,6 +18,7 @@ function ConeOrCube(props: { piece: cubeOrCone }): JSX.Element { return (
{ handleButtonClick(key, row); }} + role="btn" variant="contained" className="gridButton" style={{ From 5775c5c064f7c950f9b696c715af1d3fabf47eba Mon Sep 17 00:00:00 2001 From: Pol Selles Climent <81540683+Pokesi@users.noreply.github.com> Date: Sun, 29 Jan 2023 16:30:23 +1100 Subject: [PATCH 4/6] im going to kill myself if this doesnt pass the ci --- src/App.test.tsx | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/App.test.tsx b/src/App.test.tsx index 11d24a8..81ecbc1 100644 --- a/src/App.test.tsx +++ b/src/App.test.tsx @@ -13,9 +13,9 @@ test("Clicking on an option changes the displayed piece", () => { // const { container } = render(); render(); - const radio = screen.getAllByRole('radio'); + const radio = screen.getAllByRole("radio"); - console.log(radio) + console.log(radio); act(() => { radio[0].click(); From f8734e55640dea84d6475b943496220c95173b61 Mon Sep 17 00:00:00 2001 From: Pol Selles Climent <81540683+Pokesi@users.noreply.github.com> Date: Sun, 29 Jan 2023 16:41:49 +1100 Subject: [PATCH 5/6] PLEASE --- src/App.test.tsx | 2 +- src/App.tsx | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/App.test.tsx b/src/App.test.tsx index 81ecbc1..4072e4e 100644 --- a/src/App.test.tsx +++ b/src/App.test.tsx @@ -43,7 +43,7 @@ test("Clicking on an option changes the displayed piece", () => { test("Clicking on a node should change it", () => { render(); - const table = screen.getAllByRole("btn"); + const table = screen.getAllByRole("button"); for (let i = 0; i < table.length; i++) { const item = table[i]; diff --git a/src/App.tsx b/src/App.tsx index 1dcc872..f06ea8c 100644 --- a/src/App.tsx +++ b/src/App.tsx @@ -55,7 +55,7 @@ function Table(props: { onClick={() => { handleButtonClick(key, row); }} - role="btn" + type="button" variant="contained" className="gridButton" style={{ From 18d76ee3ac63a791892ec4d5b5b15e02903aaaf1 Mon Sep 17 00:00:00 2001 From: Pol Selles Climent <81540683+Pokesi@users.noreply.github.com> Date: Sun, 29 Jan 2023 17:01:08 +1100 Subject: [PATCH 6/6] remove the button type --- src/App.test.tsx | 2 -- src/App.tsx | 1 - 2 files changed, 3 deletions(-) diff --git a/src/App.test.tsx b/src/App.test.tsx index 4072e4e..3c697da 100644 --- a/src/App.test.tsx +++ b/src/App.test.tsx @@ -15,8 +15,6 @@ test("Clicking on an option changes the displayed piece", () => { const radio = screen.getAllByRole("radio"); - console.log(radio); - act(() => { radio[0].click(); }); diff --git a/src/App.tsx b/src/App.tsx index f06ea8c..c548070 100644 --- a/src/App.tsx +++ b/src/App.tsx @@ -55,7 +55,6 @@ function Table(props: { onClick={() => { handleButtonClick(key, row); }} - type="button" variant="contained" className="gridButton" style={{