Skip to content
Snippets Groups Projects
Unverified Commit d5c438ac authored by Nemanja Glumac's avatar Nemanja Glumac Committed by GitHub
Browse files

Migrate `EntityMenuItem` test from enzyme to react-testing-library (#13265)

parent 8a6ef93d
No related branches found
No related tags found
No related merge requests found
import React from "react";
import { shallow, mount } from "enzyme";
import { Link } from "react-router";
import "@testing-library/jest-dom/extend-expect";
import { fireEvent, render, screen } from "@testing-library/react";
import Icon from "metabase/components/Icon";
import EntityMenuItem from "metabase/components/EntityMenuItem";
describe("EntityMenuItem", () => {
it("should display the proper title and icon", () => {
const wrapper = shallow(
render(
<EntityMenuItem
title="A pencil icon"
icon="pencil"
action={() => ({})}
/>,
);
const icon = wrapper.find(Icon);
expect(icon.length).toBe(1);
expect(icon.props().name).toEqual("pencil");
screen.getByRole("img", { name: /pencil icon/i });
screen.getByText("A pencil icon");
});
describe("actions and links", () => {
......@@ -26,22 +22,22 @@ describe("EntityMenuItem", () => {
it("should call an action function if an action is provided", () => {
const spy = jest.fn();
const wrapper = mount(
render(
<EntityMenuItem title="A pencil icon" icon="pencil" action={spy} />,
);
wrapper.simulate("click");
expect(spy).toHaveBeenCalled();
fireEvent.click(screen.getByRole("img", { name: /pencil icon/i }));
expect(spy).toHaveBeenCalledTimes(1);
});
});
describe("links", () => {
it("should be a link if a link is provided", () => {
const wrapper = mount(
const { container } = render(
<EntityMenuItem title="A pencil icon" icon="pencil" link="/derp" />,
);
expect(wrapper.find(Link).length).toBe(1);
expect(container.querySelector("a")).toBeInTheDocument();
});
});
});
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment