Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add tests for clicks #5

Open
wants to merge 6 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 11 additions & 12 deletions src/App.test.tsx
Original file line number Diff line number Diff line change
@@ -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", () => {
Expand All @@ -11,46 +10,46 @@ test("Renders", () => {
});

test("Clicking on an option changes the displayed piece", () => {
const { container } = render(<App />);
// const { container } = render(<App />);
render(<App />);

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");

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(<App />);
render(<App />);

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(() => {
Expand Down
2 changes: 2 additions & 0 deletions src/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ function ConeOrCube(props: { piece: cubeOrCone }): JSX.Element {
return (
<div
className="coneOrCube"
role="none"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Isn't none the default role for a <div>?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ESLint complained about it - but maybe i had something there before

Copy link
Contributor Author

@Pokesi Pokesi Jan 29, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the tests dont passif the role isnt defined as none

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Well, we shouldn't be setting the ARIA role to none anyway. It sounds like your tests are abusing the ARIA role to select this element. Maybe find a different selector? You have a class name on this after all...

style={{
backgroundColor:
piece === "None" ? "grey" : piece === "Cube" ? "violet" : "yellow",
Expand Down Expand Up @@ -54,6 +55,7 @@ function Table(props: {
onClick={() => {
handleButtonClick(key, row);
}}
role="btn"
auscompgeek marked this conversation as resolved.
Show resolved Hide resolved
variant="contained"
className="gridButton"
style={{
Expand Down