Skip to content

Commit c98550d

Browse files
test: update TimelineComponent tests to use Testing Library and improve structure
1 parent a7a2ea7 commit c98550d

File tree

3 files changed

+461
-517
lines changed

3 files changed

+461
-517
lines changed

packages/pluggableWidgets/timeline-web/jest.config.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
const { join } = require("path");
2-
const base = require("@mendix/pluggable-widgets-tools/test-config/jest.config");
2+
const base = require("@mendix/pluggable-widgets-tools/test-config/jest.enzyme-free.config.js");
33

44
module.exports = {
55
...base,

packages/pluggableWidgets/timeline-web/src/components/__tests__/TimelineComponent.spec.tsx

Lines changed: 19 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
import { shallow } from "enzyme";
1+
import { render, fireEvent } from "@testing-library/react";
2+
import "@testing-library/jest-dom";
23
import { createElement } from "react";
34
import { actionValue } from "@mendix/widget-plugin-test-utils";
45
import TimelineComponent from "../TimelineComponent";
@@ -51,16 +52,16 @@ describe("Timeline", () => {
5152
};
5253

5354
it("renders timeline with basic configuration", () => {
54-
const component = shallow(<TimelineComponent {...basicRenderProps} />);
55-
expect(component).toMatchSnapshot();
55+
const { container } = render(<TimelineComponent {...basicRenderProps} />);
56+
expect(container).toMatchSnapshot();
5657
});
5758
it("renders timeline with custom configuration", () => {
58-
const component = shallow(<TimelineComponent {...customRenderProps} />);
59-
expect(component).toMatchSnapshot();
59+
const { container } = render(<TimelineComponent {...customRenderProps} />);
60+
expect(container).toMatchSnapshot();
6061
});
6162
it("hides the timeline header", () => {
62-
const component = shallow(<TimelineComponent {...basicRenderProps} groupEvents={false} />);
63-
expect(component).toMatchSnapshot();
63+
const { container } = render(<TimelineComponent {...basicRenderProps} groupEvents={false} />);
64+
expect(container).toMatchSnapshot();
6465
});
6566

6667
describe("with action set", () => {
@@ -74,12 +75,10 @@ describe("Timeline", () => {
7475
basicData.set(secondDate.toDateString(), [basicItemWithAction]);
7576

7677
const basicPropsWithAction = { ...basicRenderProps, data: basicData };
77-
const component = shallow(<TimelineComponent {...basicPropsWithAction} />);
78-
79-
const clickableItem = component.find(".clickable");
80-
81-
expect(clickableItem).toHaveLength(1);
82-
expect(component).toMatchSnapshot();
78+
const { container } = render(<TimelineComponent {...basicPropsWithAction} />);
79+
const clickableItem = container.querySelector(".clickable");
80+
expect(clickableItem).toBeInTheDocument();
81+
expect(container).toMatchSnapshot();
8382
});
8483
it("triggers actions when clicked", () => {
8584
const action = actionValue(true, false);
@@ -91,11 +90,9 @@ describe("Timeline", () => {
9190
basicData.set(secondDate.toDateString(), [basicItemWithAction]);
9291

9392
const basicPropsWithAction = { ...basicRenderProps, data: basicData };
94-
const component = shallow(<TimelineComponent {...basicPropsWithAction} />);
95-
96-
const clickableItem = component.find(".clickable");
97-
clickableItem.simulate("click");
98-
93+
const { container } = render(<TimelineComponent {...basicPropsWithAction} />);
94+
const clickableItem = container.querySelector(".clickable");
95+
fireEvent.click(clickableItem!);
9996
expect(action.execute).toHaveBeenCalled();
10097
});
10198
it("change style when hovered", () => {
@@ -108,12 +105,10 @@ describe("Timeline", () => {
108105
basicData.set(secondDate.toDateString(), [basicItemWithAction]);
109106

110107
const basicPropsWithAction = { ...basicRenderProps, data: basicData };
111-
const component = shallow(<TimelineComponent {...basicPropsWithAction} />);
112-
113-
const clickableItem = component.find(".clickable");
114-
clickableItem.simulate("mouseover");
115-
116-
expect(component).toMatchSnapshot();
108+
const { container } = render(<TimelineComponent {...basicPropsWithAction} />);
109+
const clickableItem = container.querySelector(".clickable");
110+
fireEvent.mouseOver(clickableItem!);
111+
expect(container).toMatchSnapshot();
117112
});
118113
});
119114
});

0 commit comments

Comments
 (0)