Skip to content

Commit

Permalink
PLT-5551 test review comment changes
Browse files Browse the repository at this point in the history
  • Loading branch information
amnambiar committed Aug 14, 2023
1 parent e52a37c commit 29f90e1
Show file tree
Hide file tree
Showing 7 changed files with 50 additions and 38 deletions.
37 changes: 9 additions & 28 deletions react-web/src/components/Button/Button.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,34 +2,15 @@ import { fireEvent, render, screen } from "@testing-library/react";
import Button from "./Button";

describe("renders the Button component with defaults", () => {
it("renders without a class name", () => {
it("renders with default properties", () => {
render(<Button />);
expect(screen.getAllByRole("button")[0]).toHaveClass("btn");
});

it("renders without a type", () => {
render(<Button />);
expect(screen.getAllByRole("button")[0]).toHaveAttribute("type", "submit");
});

it("renders without a size", () => {
render(<Button />);
expect(screen.getAllByRole("button")[0]).toHaveClass("btn-medium");
});

it("renders without a displayStyle", () => {
render(<Button />);
expect(screen.getAllByRole("button")[0]).toHaveClass("btn-primary");
});

it("renders without a label", () => {
render(<Button />);
expect(screen.getAllByRole("button")[0]).toHaveTextContent("Submit");
});

it("renders without class is-loading", () => {
render(<Button />);
expect(screen.getAllByRole("button")[0]).not.toHaveClass("is-loading");
const button = screen.getAllByRole("button")[0];
expect(button).toHaveClass("btn");
expect(button).toHaveAttribute("type", "submit");
expect(button).toHaveClass("btn-medium");
expect(button).toHaveClass("btn-primary");
expect(button).toHaveTextContent("Submit");
expect(button).not.toHaveClass("is-loading");
});
});

Expand Down Expand Up @@ -63,7 +44,7 @@ describe("renders the Button component", () => {

it("successful button click", () => {
const mockOnClick = jest.fn();
render(<Button onClick={mockOnClick()} />);
render(<Button onClick={mockOnClick} />);
const clickIndicator = screen.getByRole("button");
fireEvent.click(clickIndicator);
expect(mockOnClick).toHaveBeenCalledTimes(1);
Expand Down
10 changes: 5 additions & 5 deletions react-web/src/components/HelperText/HelperText.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,28 +4,28 @@ import HelperText, { fetchHelperTextColor } from "./HelperText";

describe("HelperText", () => {
test("renders the text with correct class name when type=info", () => {
const value = "This is an info message";
const value = "This is a info message";
render(<HelperText value={value} type="info" />);
const textElement = screen.getByText(value);
expect(textElement).toHaveClass(fetchHelperTextColor("info"));
});

test("renders the text with correct class name when type=warning", () => {
const value = "This is an warning message";
const value = "This is a warning message";
render(<HelperText value={value} type="warning" />);
const textElement = screen.getByText(value);
expect(textElement).toHaveClass(fetchHelperTextColor("warning"));
});

test("renders the text with correct class name when type=success", () => {
const value = "This is an success message";
const value = "This is a success message";
render(<HelperText value={value} type="success" />);
const textElement = screen.getByText(value);
expect(textElement).toHaveClass(fetchHelperTextColor("success"));
});

test("renders the text with correct class name when type=error", () => {
const value = "This is an error message";
const value = "This is a error message";
render(<HelperText value={value} type="error" />);
const textElement = screen.getByText(value);
expect(textElement).toHaveClass(fetchHelperTextColor("error"));
Expand All @@ -42,7 +42,7 @@ describe("HelperText", () => {
});

test("renders the text with an info icon when showInfoIcon is true", () => {
const value = "This is an info message";
const value = "This is a info message";
render(
<HelperText value={value} showInfoIcon={true} />
);
Expand Down
8 changes: 4 additions & 4 deletions react-web/src/components/Icons/Icons.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,20 +4,20 @@ import Icons, { IconTypes } from "./Icons";

describe("Icons", () => {
test("renders the correct icon based on the provided type", () => {
Object.keys(IconTypes).map((type) => {
Object.keys(IconTypes).forEach((type) => {
const { container } = render(<Icons type={type} />);
expect(container.querySelector(".MuiSvgIcon-root")).toBeInTheDocument();
});
});

test("renders the info icon based when type is not provided", () => {
render(<Icons />);
expect(screen.queryByTestId("InfoIcon")).toBeInTheDocument();
expect(screen.getByTestId("InfoIcon")).toBeInTheDocument();
});

test("renders default icon when type is not from mapping", () => {
render(<Icons type="invalid-type" />);
expect(screen.queryByTestId("default-icon")).toBeInTheDocument();
expect(screen.queryByTestId(".MuiSvgIcon-root")).not.toBeInTheDocument();
});

test("renders icon with provided fontsize", () => {
Expand Down Expand Up @@ -51,4 +51,4 @@ describe("Icons", () => {
fireEvent.click(iconElement!);
expect(onClick).toHaveBeenCalled();
});
});
});
2 changes: 2 additions & 0 deletions react-web/src/compositions/Form/Form.test.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
import { screen, render } from "@testing-library/react";
import userEvent from "@testing-library/user-event";

import { Form } from "./Form";
import { useForm } from "react-hook-form";
import { Input } from "./components/Input";
Expand Down
4 changes: 4 additions & 0 deletions react-web/src/compositions/Timeline/Timeline.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,10 @@ describe("Timeline", () => {

const timelineItems = screen.getAllByRole("listitem");
expect(timelineItems).toHaveLength(statusConfig.length);
statusConfig.forEach((config, index) => {
expect(timelineItems[index]).toHaveTextContent(config.status);
expect(timelineItems[index]).toHaveTextContent(String(config.runTimeTaken));
});
});

test("sets runTimeTaken property based on the buildInfo runState", () => {
Expand Down
25 changes: 25 additions & 0 deletions react-web/src/pages/certification/Certification.helper.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,31 @@ import {

expect(filteredKeys).toEqual(expectedKeys);
});

describe("filterCertificationTaskKeys", () => {
it("should return an empty array when an invalid type is passed", () => {
const type = "invalid";
const filteredKeys = filterCertificationTaskKeys(type);
expect(filteredKeys).toEqual([]);
});
});

describe("isAnyTaskFailure", () => {
it("should return false if the result object is empty", () => {
const result = {};
const hasFailure = isAnyTaskFailure(result);
expect(hasFailure).toBe(false);
});

it("should return false if the result object contains unexpected values", () => {
const result = {
_certRes_standardPropertyResult: { tag: "Unexpected" },
_certRes_doubleSatisfactionResult: { tag: "Unexpected" },
};
const hasFailure = isAnyTaskFailure(result);
expect(hasFailure).toBe(false);
});
});
});

describe("isAnyTaskFailure", () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -153,4 +153,4 @@ describe("ResultContainer component", () => {
queryByText(/InstanceErr (GenericError "failed to create currency")/i)
).not.toBeInTheDocument();
});
});
});

0 comments on commit 29f90e1

Please sign in to comment.