1
- import { shallow } from "enzyme" ;
1
+ import { render , fireEvent } from "@testing-library/react" ;
2
+ import "@testing-library/jest-dom" ;
2
3
import { createElement } from "react" ;
3
4
import { actionValue } from "@mendix/widget-plugin-test-utils" ;
4
5
import TimelineComponent from "../TimelineComponent" ;
@@ -51,16 +52,16 @@ describe("Timeline", () => {
51
52
} ;
52
53
53
54
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 ( ) ;
56
57
} ) ;
57
58
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 ( ) ;
60
61
} ) ;
61
62
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 ( ) ;
64
65
} ) ;
65
66
66
67
describe ( "with action set" , ( ) => {
@@ -74,12 +75,10 @@ describe("Timeline", () => {
74
75
basicData . set ( secondDate . toDateString ( ) , [ basicItemWithAction ] ) ;
75
76
76
77
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 ( ) ;
83
82
} ) ;
84
83
it ( "triggers actions when clicked" , ( ) => {
85
84
const action = actionValue ( true , false ) ;
@@ -91,11 +90,9 @@ describe("Timeline", () => {
91
90
basicData . set ( secondDate . toDateString ( ) , [ basicItemWithAction ] ) ;
92
91
93
92
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 ! ) ;
99
96
expect ( action . execute ) . toHaveBeenCalled ( ) ;
100
97
} ) ;
101
98
it ( "change style when hovered" , ( ) => {
@@ -108,12 +105,10 @@ describe("Timeline", () => {
108
105
basicData . set ( secondDate . toDateString ( ) , [ basicItemWithAction ] ) ;
109
106
110
107
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 ( ) ;
117
112
} ) ;
118
113
} ) ;
119
114
} ) ;
0 commit comments