chore: Remove no-longer maintained Enzyme

This commit is contained in:
Tom Moor
2024-01-30 09:12:45 -05:00
parent 56d05a2595
commit b52b12fcfd
4 changed files with 168 additions and 342 deletions

View File

@@ -1,15 +1,12 @@
import "../stores";
import { shallow } from "enzyme";
import { render } from "@testing-library/react";
import { TFunction } from "i18next";
import * as React from "react";
import { getI18n } from "react-i18next";
import { Pagination } from "@shared/constants";
import { runAllPromises } from "~/test/support";
import { Component as PaginatedList } from "./PaginatedList";
describe("PaginatedList", () => {
const render = () => null;
const i18n = getI18n();
const props = {
@@ -19,14 +16,14 @@ describe("PaginatedList", () => {
} as any;
it("with no items renders nothing", () => {
const list = shallow(
const result = render(
<PaginatedList items={[]} renderItem={render} {...props} />
);
expect(list).toEqual({});
expect(result.container.innerHTML).toEqual("");
});
it("with no items renders empty prop", () => {
const list = shallow(
it("with no items renders empty prop", async () => {
const result = render(
<PaginatedList
items={[]}
empty={<p>Sorry, no results</p>}
@@ -34,7 +31,9 @@ describe("PaginatedList", () => {
{...props}
/>
);
expect(list.text()).toEqual("Sorry, no results");
await expect(
result.findAllByText("Sorry, no results")
).resolves.toHaveLength(1);
});
it("calls fetch with options + pagination on mount", () => {
@@ -42,7 +41,7 @@ describe("PaginatedList", () => {
const options = {
id: "one",
};
shallow(
render(
<PaginatedList
items={[]}
fetch={fetch}
@@ -57,40 +56,4 @@ describe("PaginatedList", () => {
offset: 0,
});
});
it("calls fetch when options prop changes", async () => {
const fetchedItems = Array(Pagination.defaultLimit).fill(undefined);
const fetch = jest.fn().mockReturnValue(Promise.resolve(fetchedItems));
const list = shallow(
<PaginatedList
items={[]}
fetch={fetch}
options={{
id: "one",
}}
renderItem={render}
{...props}
/>
);
await runAllPromises();
expect(fetch).toHaveBeenCalledWith({
id: "one",
limit: Pagination.defaultLimit,
offset: 0,
});
fetch.mockReset();
list.setProps({
fetch,
items: [],
options: {
id: "two",
},
});
await runAllPromises();
expect(fetch).toHaveBeenCalledWith({
id: "two",
limit: Pagination.defaultLimit,
offset: 0,
});
});
});