Skip to content

Commit

Permalink
#2006 Use React Testing Library for icons tests (#2002)
Browse files Browse the repository at this point in the history
Signed-off-by: Michael Pavlik <[email protected]>
  • Loading branch information
mikieyx authored Jun 5, 2024
1 parent e809d7c commit 36755ee
Showing 1 changed file with 10 additions and 10 deletions.
20 changes: 10 additions & 10 deletions canvas_modules/common-canvas/__tests__/icons/icon-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,31 +15,31 @@
*/

import React from "react";
import { mount, shallow } from "enzyme";
import { render } from "@testing-library/react";
import Icon from "../../src/icons/icon.jsx";
import { expect } from "chai";


describe("Icon renders correctly", () => {

it("should render a div when type unknown", () => {
const icon = shallow(<Icon type="unknown" />);
expect(icon.find("div")).to.have.length(1);
const icon = render(<Icon type="unknown" />);
// divs have generic roles, thus when icon is set to unknown, there is supposed to be 2 elements with generic roles
expect(icon.getAllByRole("generic")).to.have.length(2);
});

it("should render a svg when type known", () => {
const icon = mount(<Icon type="double" />);

expect(icon.find("svg")).to.have.length(1);
const { container } = render(<Icon type="double" />);
expect(container.getElementsByClassName("canvas-icon")).to.have.length(1);
});

it("should render a svg with class name", () => {
const icon = mount(<Icon type="integer" className="svg-test-class" />);
expect(icon.find("svg.svg-test-class")).to.have.length(1);
const { container } = render(<Icon type="integer" className="svg-test-class" />);
expect(container.getElementsByClassName("svg-test-class")).to.have.length(1);
});

it("should render a svg with class 'properties-icon'", () => {
const icon = mount(<Icon type="measurement-empty" />);
expect(icon.find("svg.properties-icon")).to.have.length(1);
const { container } = render(<Icon type="measurement-empty" />);
expect(container.getElementsByClassName("properties-icon")).to.have.length(1);
});
});

0 comments on commit 36755ee

Please sign in to comment.