1- import { act , render , waitFor } from '@testing-library/react' ;
1+ import { render , waitFor } from '@testing-library/react' ;
2+ import userEvent from '@testing-library/user-event' ;
23import { Mock , MockedFunction , vi } from 'vitest' ;
34
45import { useProcessorTooltips } from '../../hooks/use-processor-tooltips.hook' ;
@@ -60,35 +61,34 @@ describe('ComponentMode', () => {
6061 } ) ;
6162
6263 it ( 'should not call updateSourceCodeFromEntities if we are switching to the same EIP' , async ( ) => {
64+ const user = userEvent . setup ( ) ;
6365 const vizNode = getMockVizNode ( 'to' ) ;
6466 const wrapper = render ( < ComponentMode vizNode = { vizNode } /> ) ;
6567
6668 const toButton = wrapper . getByText ( 'Static' ) ;
6769 expect ( toButton ) . toBeInTheDocument ( ) ;
6870
69- await act ( async ( ) => {
70- toButton . click ( ) ;
71- } ) ;
71+ await user . click ( toButton ) ;
7272
7373 expect ( mockUpdateSourceCodeFromEntities ) . not . toHaveBeenCalled ( ) ;
7474 } ) ;
7575
7676 it ( 'should not call updateSourceCodeFromEntities if the vizNode does not contain a path' , async ( ) => {
77+ const user = userEvent . setup ( ) ;
7778 const vizNode = getMockVizNode ( 'to' ) ;
7879 vizNode . data . path = undefined ;
7980 const wrapper = render ( < ComponentMode vizNode = { vizNode } /> ) ;
8081
8182 const toButton = wrapper . getByText ( 'Static' ) ;
8283 expect ( toButton ) . toBeInTheDocument ( ) ;
8384
84- await act ( async ( ) => {
85- toButton . click ( ) ;
86- } ) ;
85+ await user . click ( toButton ) ;
8786
8887 expect ( mockUpdateSourceCodeFromEntities ) . not . toHaveBeenCalled ( ) ;
8988 } ) ;
9089
9190 it ( 'calls updateModel when switching from "to" to "poll"' , async ( ) => {
91+ const user = userEvent . setup ( ) ;
9292 const vizNode = getMockVizNode ( 'to' ) ;
9393 const wrapper = render ( < ComponentMode vizNode = { vizNode } /> ) ;
9494
@@ -100,16 +100,15 @@ describe('ComponentMode', () => {
100100 expect ( vizNode . getParsedDefinition as ReturnType < typeof vi . fn > ) . toHaveBeenCalled ( ) ;
101101 } ) ;
102102
103- await act ( async ( ) => {
104- pollButton . click ( ) ;
105- } ) ;
103+ await user . click ( pollButton ) ;
106104
107105 expect ( vizNode . updateModel ) . toHaveBeenCalledWith ( undefined ) ;
108106 expect ( vizNode . data . path ) . toBe ( 'route.from.steps.0.poll' ) ;
109107 expect ( vizNode . updateModel ) . toHaveBeenCalledTimes ( 2 ) ;
110108 } ) ;
111109
112110 it ( 'calls updateModel when switching from "to" to "toD"' , async ( ) => {
111+ const user = userEvent . setup ( ) ;
113112 const vizNode = getMockVizNode ( 'to' ) ;
114113 const wrapper = render ( < ComponentMode vizNode = { vizNode } /> ) ;
115114
@@ -121,16 +120,15 @@ describe('ComponentMode', () => {
121120 expect ( vizNode . getParsedDefinition as ReturnType < typeof vi . fn > ) . toHaveBeenCalled ( ) ;
122121 } ) ;
123122
124- await act ( async ( ) => {
125- toDButton . click ( ) ;
126- } ) ;
123+ await user . click ( toDButton ) ;
127124
128125 expect ( vizNode . updateModel ) . toHaveBeenCalledWith ( undefined ) ;
129126 expect ( vizNode . data . path ) . toBe ( 'route.from.steps.0.toD' ) ;
130127 expect ( vizNode . updateModel ) . toHaveBeenCalledTimes ( 2 ) ;
131128 } ) ;
132129
133130 it ( 'calls updateModel when switching from "poll" to "to"' , async ( ) => {
131+ const user = userEvent . setup ( ) ;
134132 const vizNode = getMockVizNode ( 'poll' ) ;
135133 const wrapper = render ( < ComponentMode vizNode = { vizNode } /> ) ;
136134
@@ -141,20 +139,16 @@ describe('ComponentMode', () => {
141139 await waitFor ( ( ) => {
142140 expect ( vizNode . getParsedDefinition as ReturnType < typeof vi . fn > ) . toHaveBeenCalled ( ) ;
143141 } ) ;
144- await act ( async ( ) => {
145- await Promise . resolve ( ) ;
146- } ) ;
147142
148- await act ( async ( ) => {
149- toButton . click ( ) ;
150- } ) ;
143+ await user . click ( toButton ) ;
151144
152145 expect ( vizNode . updateModel ) . toHaveBeenCalledWith ( undefined ) ;
153146 expect ( vizNode . data . path ) . toBe ( 'route.from.steps.0.to' ) ;
154147 expect ( vizNode . updateModel ) . toHaveBeenCalledTimes ( 2 ) ;
155148 } ) ;
156149
157150 it ( 'calls updateSourceCodeFromEntities when switching from "poll" to "to"' , async ( ) => {
151+ const user = userEvent . setup ( ) ;
158152 const vizNode = getMockVizNode ( 'poll' ) ;
159153 const wrapper = render ( < ComponentMode vizNode = { vizNode } /> ) ;
160154
@@ -165,13 +159,8 @@ describe('ComponentMode', () => {
165159 await waitFor ( ( ) => {
166160 expect ( vizNode . getParsedDefinition as ReturnType < typeof vi . fn > ) . toHaveBeenCalled ( ) ;
167161 } ) ;
168- await act ( async ( ) => {
169- await Promise . resolve ( ) ;
170- } ) ;
171162
172- await act ( async ( ) => {
173- toButton . click ( ) ;
174- } ) ;
163+ await user . click ( toButton ) ;
175164
176165 expect ( mockUpdateSourceCodeFromEntities ) . toHaveBeenCalled ( ) ;
177166 } ) ;
0 commit comments