Skip to content

[WC-2954]: Migrate tests from enzyme to react-testing-library #1527

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 18 commits into from
May 20, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
18 commits
Select commit Hold shift + click to select a range
c37911e
chore: add Jest configuration and update test script
samuelreichert Apr 8, 2025
75069e5
fix: handle space key for toggling accordion collapse
samuelreichert Apr 8, 2025
708f801
test(accordion-web): update test cases to use only react-testing-library
samuelreichert Apr 8, 2025
e6f10e0
test(area-chart-web): migrate tests to use react-testing-library and …
samuelreichert Apr 8, 2025
abd15a3
test(badge-button-web): migrate tests to use react-testing-library an…
samuelreichert Apr 8, 2025
9f9f27b
test(badge-web): migrate tests to use react-testing-library and updat…
samuelreichert Apr 9, 2025
565951a
test(accordion-web): refactor tests to improve setup for default props
samuelreichert May 6, 2025
06e1c28
test(badge-web): refactor defaultBadgeProps initialization to beforeE…
samuelreichert May 6, 2025
2002d81
chore: create setupBasicSeries function to reuse throughout chart wid…
samuelreichert May 6, 2025
a2f0e33
test(bar-chart-web): update tests to use react-testing-library and re…
samuelreichert May 6, 2025
c42d1b2
test(bubble-chart-web): update tests to use react-testing-library and…
samuelreichert May 6, 2025
4d63b13
test(widgets): refactor tests to use asFragment for snapshot matching
samuelreichert May 6, 2025
e5fd7b3
test(color-picker-web): migrate tests to react-testing-library and im…
samuelreichert May 6, 2025
2de26cb
test(widgets): wrap rerender calls in act for proper state updates
samuelreichert May 14, 2025
7dd5967
test(color-picker-web): mock SketchPicker for better snapshot readabi…
samuelreichert May 16, 2025
53b0e08
test(color-picker-web): refactor tests to improve snapshot readability
samuelreichert May 16, 2025
8d73183
test(color-picker-web): refactor snapshots and tests for improved str…
samuelreichert May 20, 2025
3395f62
test(accordion-web): update focus handling in tests
samuelreichert May 20, 2025
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions packages/pluggableWidgets/accordion-web/jest.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
module.exports = {
...require("@mendix/pluggable-widgets-tools/test-config/jest.enzyme-free.config.js")
};
2 changes: 1 addition & 1 deletion packages/pluggableWidgets/accordion-web/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@
"publish-marketplace": "rui-publish-marketplace",
"release": "pluggable-widgets-tools release:web",
"start": "pluggable-widgets-tools start:server",
"test": "pluggable-widgets-tools test:unit:web",
"test": "jest --projects jest.config.js",
"update-changelog": "rui-update-changelog-widget",
"verify": "rui-verify-package-format"
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,7 @@ export function AccordionGroup(props: AccordionGroupProps): ReactElement | null
switch (event.key) {
case "Enter":
case " ":
case "Space":
event.preventDefault();
toggleCollapsed?.();
break;
Expand Down

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import "@testing-library/jest-dom";
import { render, RenderResult } from "@testing-library/react";
import { createElement, PropsWithChildren } from "react";
import { shallow } from "enzyme";

import { Header, HeaderProps } from "../Header";

describe("Header", () => {
Expand All @@ -13,39 +13,43 @@ describe("Header", () => {
};
});

function renderHeader(props: Partial<HeaderProps> = {}): RenderResult {
return render(<Header {...defaultHeaderProps} {...props} />);
}

it("renders h1", () => {
const headerWrapper = shallow(<Header {...defaultHeaderProps} heading="headingOne" />);
const header = renderHeader({ heading: "headingOne" });

expect(headerWrapper).toMatchSnapshot();
expect(header.asFragment()).toMatchSnapshot();
});

it("renders h2", () => {
const headerWrapper = shallow(<Header {...defaultHeaderProps} heading="headingTwo" />);
const header = renderHeader({ heading: "headingTwo" });

expect(headerWrapper).toMatchSnapshot();
expect(header.asFragment()).toMatchSnapshot();
});

it("renders h3", () => {
const headerWrapper = shallow(<Header {...defaultHeaderProps} />);
const header = renderHeader();

expect(headerWrapper).toMatchSnapshot();
expect(header.asFragment()).toMatchSnapshot();
});

it("renders h4", () => {
const headerWrapper = shallow(<Header {...defaultHeaderProps} heading="headingFour" />);
const header = renderHeader({ heading: "headingFour" });

expect(headerWrapper).toMatchSnapshot();
expect(header.asFragment()).toMatchSnapshot();
});

it("renders h5", () => {
const headerWrapper = shallow(<Header {...defaultHeaderProps} heading="headingFive" />);
const header = renderHeader({ heading: "headingFive" });

expect(headerWrapper).toMatchSnapshot();
expect(header.asFragment()).toMatchSnapshot();
});

it("renders h6", () => {
const headerWrapper = shallow(<Header {...defaultHeaderProps} heading="headingSix" />);
const header = renderHeader({ heading: "headingSix" });

expect(headerWrapper).toMatchSnapshot();
expect(header.asFragment()).toMatchSnapshot();
});
});
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import "@testing-library/jest-dom";
import { render, RenderResult } from "@testing-library/react";
import { createElement } from "react";
import { mount, render } from "enzyme";
import { Icon, IconProps } from "../Icon";

describe("Icon", () => {
Expand All @@ -13,53 +14,64 @@ describe("Icon", () => {
};
});

it("renders glyph icons", () => {
const iconWrapper = render(<Icon {...defaultIconProps} />);
function renderIcon(props: Partial<IconProps> = {}): RenderResult {
return render(<Icon {...defaultIconProps} {...props} />);
}

expect(iconWrapper).toMatchSnapshot();
});

it("renders image icons", () => {
const iconWrapper = render(<Icon {...defaultIconProps} data={{ type: "image", iconUrl: "icon.url" }} />);

expect(iconWrapper).toMatchSnapshot();
});

it("renders a default icon", () => {
const iconWrapper = render(<Icon {...defaultIconProps} data={undefined} />);
describe("Rendering", () => {
it("renders glyph icons", () => {
const icon = renderIcon();

expect(iconWrapper).toMatchSnapshot();
});
expect(icon.asFragment()).toMatchSnapshot();
});

it("doesn't render a default icon while loading", () => {
const iconWrapper = render(<Icon {...defaultIconProps} data={undefined} loading />);
it("renders image icons", () => {
const icon = renderIcon({ data: { type: "image", iconUrl: "icon.url" } });

expect(iconWrapper).toMatchSnapshot();
});
expect(icon.asFragment()).toMatchSnapshot();
});

it("doesn't render an icon with an unknown icon data type", () => {
const iconWrapper = render(<Icon {...defaultIconProps} data={{ type: "unknown" } as any} />);
it("renders a default icon", () => {
const icon = renderIcon({ data: undefined });

expect(iconWrapper).toMatchSnapshot();
});
expect(icon.asFragment()).toMatchSnapshot();
});

it("doesn't apply an animate class to a glyph icon when animate is false", () => {
const iconWrapper = mount(<Icon {...defaultIconProps} animate={false} />);
it("doesn't render a default icon while loading", () => {
const icon = renderIcon({ data: undefined, loading: true });

expect(iconWrapper.find("span").prop("className")).not.toContain("widget-accordion-group-header-icon-animate");
});
expect(icon.asFragment()).toMatchSnapshot();
});

it("doesn't apply an animate class to an image icon when animate is false", () => {
const iconWrapper = mount(
<Icon {...defaultIconProps} data={{ type: "image", iconUrl: "icon.url" }} animate={false} />
);
it("doesn't render an icon with an unknown icon data type", () => {
const icon = renderIcon({ data: { type: "unknown" } as any });

expect(iconWrapper.find("img").prop("className")).not.toContain("widget-accordion-group-header-icon-animate");
expect(icon.asFragment()).toMatchSnapshot();
});
});

it("doesn't apply an animate class to a default icon when animate is false", () => {
const iconWrapper = mount(<Icon {...defaultIconProps} data={undefined} animate={false} />);

expect(iconWrapper.find("svg").prop("className")).not.toContain("widget-accordion-group-header-icon-animate");
describe("Animation Behaviour", () => {
it("doesn't apply an animate class to a glyph icon when animate is false", () => {
const icon = renderIcon({ animate: false });
const spanElement = icon.container.querySelector("span");

expect(spanElement).not.toHaveClass("widget-accordion-group-header-icon-animate");
});

it("doesn't apply an animate class to an image icon when animate is false", () => {
const icon = renderIcon({
data: { type: "image", iconUrl: "icon.url" },
animate: false
});
const imgElement = icon.container.querySelector("img");

expect(imgElement).not.toHaveClass("widget-accordion-group-header-icon-animate");
});

it("doesn't apply an animate class to a default icon when animate is false", () => {
const icon = renderIcon({ data: undefined, animate: false });
const svgElement = icon.container.querySelector("svg");
expect(svgElement).not.toHaveClass("widget-accordion-group-header-icon-animate");
});
});
});
Loading
Loading