-
Notifications
You must be signed in to change notification settings - Fork 55
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
enzyme to RTL shallow tests migration (#4840)
- Loading branch information
1 parent
8fe1ed7
commit 385d217
Showing
11 changed files
with
58 additions
and
155 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
16 changes: 0 additions & 16 deletions
16
src/app/base/components/Placeholder/__snapshots__/Placeholder.test.tsx.snap
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,27 +1,28 @@ | ||
import { shallow } from "enzyme"; | ||
/* eslint-disable testing-library/no-container */ | ||
/* eslint-disable testing-library/no-node-access */ | ||
import { render } from "@testing-library/react"; | ||
|
||
import PowerIcon from "./PowerIcon"; | ||
|
||
import { PowerState } from "app/store/types/enum"; | ||
|
||
describe("PowerIcon", () => { | ||
it("renders", () => { | ||
const wrapper = shallow(<PowerIcon powerState={PowerState.ON} />); | ||
expect(wrapper).toMatchSnapshot(); | ||
const { container } = render(<PowerIcon powerState={PowerState.ON} />); | ||
expect(container.querySelector("i")).toBeInTheDocument(); | ||
}); | ||
|
||
it("can show a spinner regardless of the power state", () => { | ||
const wrapper = shallow( | ||
it("can show a spinner regardless of the power state", async () => { | ||
const { container } = render( | ||
<PowerIcon powerState={PowerState.ON} showSpinner /> | ||
); | ||
expect(wrapper.find("Icon").prop("name")).toBe("spinner"); | ||
expect(wrapper.find("Icon").prop("className")).toBe("u-animation--spin"); | ||
expect(container.querySelector("i")).toHaveClass("u-animation--spin"); | ||
}); | ||
|
||
it("makes the icon inline if children are provided", () => { | ||
const wrapper = shallow( | ||
const { container } = render( | ||
<PowerIcon powerState={PowerState.ON}>On</PowerIcon> | ||
); | ||
expect(wrapper.find("Icon").prop("className")).toBe("is-inline"); | ||
expect(container.querySelector("i")).toHaveClass("is-inline"); | ||
}); | ||
}); |
10 changes: 0 additions & 10 deletions
10
src/app/base/components/PowerIcon/__snapshots__/PowerIcon.test.tsx.snap
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
41 changes: 0 additions & 41 deletions
41
src/app/base/components/Stepper/__snapshots__/Stepper.test.tsx.snap
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,11 +1,11 @@ | ||
import { shallow } from "enzyme"; | ||
import { render, screen } from "@testing-library/react"; | ||
|
||
import Switch from "./Switch"; | ||
|
||
describe("Switch", () => { | ||
it("renders", () => { | ||
const wrapper = shallow(<Switch />); | ||
render(<Switch />); | ||
|
||
expect(wrapper).toMatchSnapshot(); | ||
expect(screen.getByRole("checkbox")).toBeInTheDocument(); | ||
}); | ||
}); |
15 changes: 0 additions & 15 deletions
15
src/app/base/components/Switch/__snapshots__/Switch.test.tsx.snap
This file was deleted.
Oops, something went wrong.
49 changes: 28 additions & 21 deletions
49
src/app/base/components/TableActions/TableActions.test.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,59 +1,66 @@ | ||
import { shallow } from "enzyme"; | ||
import { screen } from "@testing-library/react"; | ||
import userEvent from "@testing-library/user-event"; | ||
|
||
import TableActions from "./TableActions"; | ||
|
||
import { renderWithBrowserRouter } from "testing/utils"; | ||
|
||
describe("TableActions ", () => { | ||
it("renders a copy button if copy value provided", () => { | ||
const wrapper = shallow(<TableActions copyValue="foo" />); | ||
expect(wrapper.find("CopyButton").exists()).toBe(true); | ||
renderWithBrowserRouter(<TableActions copyValue="foo" />); | ||
expect(screen.getByText(/copy/i)).toBeInTheDocument(); | ||
}); | ||
|
||
it("renders an edit link if edit path provided", () => { | ||
const wrapper = shallow(<TableActions editPath="/bar" />); | ||
expect(wrapper.find("Button").props().to).toBe("/bar"); | ||
renderWithBrowserRouter(<TableActions editPath="/bar" />); | ||
expect(screen.getByRole("link", { name: /edit/i })).toHaveAttribute( | ||
"href", | ||
"/bar" | ||
); | ||
}); | ||
|
||
it("renders an edit button if edit on-click provided", () => { | ||
it("renders an edit button if edit on-click provided", async () => { | ||
const onEdit = jest.fn(); | ||
const wrapper = shallow(<TableActions onEdit={onEdit} />); | ||
wrapper.find("Button").simulate("click"); | ||
renderWithBrowserRouter(<TableActions onEdit={onEdit} />); | ||
await userEvent.click(screen.getByText(/edit/i)); | ||
expect(onEdit).toHaveBeenCalled(); | ||
expect(wrapper.find("Button").prop("element")).toBe(undefined); | ||
expect(screen.getByRole("button", { name: /edit/i })).toBeInTheDocument(); | ||
}); | ||
|
||
it("renders a delete button if delete function provided", () => { | ||
it("renders a delete button if delete function provided", async () => { | ||
const onDelete = jest.fn(); | ||
const wrapper = shallow(<TableActions onDelete={onDelete} />); | ||
expect(wrapper.find("Button .p-icon--delete").exists()).toBe(true); | ||
wrapper.find("Button").simulate("click"); | ||
renderWithBrowserRouter(<TableActions onDelete={onDelete} />); | ||
expect(screen.getByRole("button", { name: /delete/i })).toBeInTheDocument(); | ||
await userEvent.click(screen.getByRole("button", { name: /delete/i })); | ||
expect(onDelete).toHaveBeenCalled(); | ||
}); | ||
|
||
it("correctly renders tooltips", () => { | ||
const wrapper = shallow( | ||
renderWithBrowserRouter( | ||
<TableActions | ||
deleteTooltip="delete tooltip" | ||
editPath="/bar" | ||
editTooltip="edit tooltip" | ||
onDelete={jest.fn()} | ||
/> | ||
); | ||
expect(wrapper.find("Tooltip").at(0).prop("message")).toBe("edit tooltip"); | ||
expect(wrapper.find("Tooltip").at(1).prop("message")).toBe( | ||
"delete tooltip" | ||
); | ||
expect(screen.getByText(/edit tooltip/i)).toBeInTheDocument(); | ||
expect(screen.getByText(/delete tooltip/i)).toBeInTheDocument(); | ||
}); | ||
|
||
it("correctly disables buttons", () => { | ||
const wrapper = shallow( | ||
renderWithBrowserRouter( | ||
<TableActions | ||
deleteDisabled | ||
editDisabled | ||
editPath="/bar" | ||
onDelete={jest.fn()} | ||
/> | ||
); | ||
expect(wrapper.find("Button").at(0).props().disabled).toBe(true); | ||
expect(wrapper.find("Button").at(1).props().disabled).toBe(true); | ||
expect(screen.getByRole("link", { name: /edit/i })).toHaveAttribute( | ||
"aria-disabled", | ||
"true" | ||
); | ||
expect(screen.getByRole("button", { name: /delete/i })).toBeDisabled(); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
23 changes: 0 additions & 23 deletions
23
src/app/base/components/TableDeleteConfirm/__snapshots__/TableDeleteConfirm.test.tsx.snap
This file was deleted.
Oops, something went wrong.