@@ -2,7 +2,7 @@ import { useVerna, VernaForm, VernaProvider } from '@openfun/verna';
22import { VernaSchemaType } from '@openfun/verna/dist/types/rjsf' ;
33import { Maybe } from '@openfun/verna/dist/types/utils' ;
44import * as factories from '@openfun/verna/src/tests/mocks/factories' ;
5- import { act , render , screen , waitFor } from '@testing-library/react' ;
5+ import { render , screen , waitFor } from '@testing-library/react' ;
66import userEvent from '@testing-library/user-event' ;
77import { Suspense } from 'react' ;
88import { IntlProvider } from 'react-intl' ;
@@ -52,42 +52,36 @@ describe('AddQuestionModal', () => {
5252
5353 beforeEach ( ( ) => {
5454 useVernaValue = undefined ;
55+ document . body . innerHTML = '' ;
5556 } ) ;
5657
5758 it ( 'should be able to add a widget from the list with correct type and name' , async ( ) => {
5859 render ( < VernaSuspenseWrapper idParts = { [ 'root' , 'testSection' ] } /> ) ;
5960
6061 // Wait that the form is rendered...
61- await waitFor ( ( ) => {
62- expect ( screen . queryByTestId ( 'suspense-fallback' ) ) . toBeNull ( ) ;
62+ await waitFor ( async ( ) => {
63+ expect ( screen . queryByTestId ( 'suspense-fallback' ) ) . not . toBeInTheDocument ( ) ;
6364 } ) ;
64-
6565 // Check that the modal is rendered
66- expect ( screen . getByText ( 'Select a type of question to add' ) ) . toBeInTheDocument ( ) ;
66+ await waitFor ( async ( ) => {
67+ screen . getByText ( 'Select a type of question to add' ) ;
68+ } ) ;
6769
6870 // Add a Multiple choice question field
69- await act ( async ( ) => {
70- await userEvent . click ( screen . getByRole ( 'button' , { name : 'Open Drop' } ) ) ;
71- await userEvent . click ( screen . getByRole ( 'option' , { name : 'Single choice question' } ) ) ;
72- await userEvent . click ( screen . getByRole ( 'button' , { name : 'Add' } ) ) ;
73- } ) ;
71+ await userEvent . click ( screen . getByRole ( 'button' , { name : 'Open Drop' } ) ) ;
72+ await userEvent . click ( screen . getByRole ( 'option' , { name : 'Single choice question' } ) ) ;
73+ await userEvent . click ( screen . getByRole ( 'button' , { name : 'Add' } ) ) ;
7474
7575 // Open parameters of the newly created field and add an option
76- await act ( async ( ) => {
77- await userEvent . click ( screen . getAllByRole ( 'button' , { name : 'Parameters' } ) [ 3 ] ) ;
78- await userEvent . click ( screen . getAllByRole ( 'button' , { name : 'Add' } ) [ 0 ] ) ;
79- await userEvent . type ( screen . getAllByRole ( 'textbox' , { } ) [ 1 ] , 'test' ) ;
80- } ) ;
76+ await userEvent . click ( screen . getAllByRole ( 'button' , { name : 'Parameters' } ) [ 3 ] ) ;
77+ await userEvent . click ( screen . getAllByRole ( 'button' , { name : 'Add' } ) [ 0 ] ) ;
78+ await userEvent . type ( screen . getAllByRole ( 'textbox' , { } ) [ 1 ] , 'test' ) ;
8179
8280 // Save parameters
83- await act ( async ( ) => {
84- await userEvent . click ( screen . getByRole ( 'button' , { name : 'save' } ) ) ;
85- } ) ;
81+ await userEvent . click ( screen . getByRole ( 'button' , { name : 'save' } ) ) ;
8682
8783 // Reopen parameters
88- await act ( async ( ) => {
89- await userEvent . click ( screen . getAllByRole ( 'button' , { name : 'Parameters' } ) [ 3 ] ) ;
90- } ) ;
84+ await userEvent . click ( screen . getAllByRole ( 'button' , { name : 'Parameters' } ) [ 3 ] ) ;
9185
9286 expect ( screen . getAllByRole ( 'textbox' , { } ) [ 1 ] ) . toHaveValue ( 'test' ) ;
9387 } ) ;
@@ -101,11 +95,9 @@ describe('AddQuestionModal', () => {
10195 } ) ;
10296
10397 // Add a Multiple choice question field
104- await act ( async ( ) => {
105- await userEvent . click ( screen . getByRole ( 'button' , { name : 'Open Drop' } ) ) ;
106- await userEvent . click ( screen . getByRole ( 'option' , { name : 'Single choice question' } ) ) ;
107- await userEvent . click ( screen . getByRole ( 'button' , { name : 'Add' } ) ) ;
108- } ) ;
98+ await userEvent . click ( screen . getByRole ( 'button' , { name : 'Open Drop' } ) ) ;
99+ await userEvent . click ( screen . getByRole ( 'option' , { name : 'Single choice question' } ) ) ;
100+ await userEvent . click ( screen . getByRole ( 'button' , { name : 'Add' } ) ) ;
109101
110102 // Check that the newly created widget is well initialized
111103 const { formSchema, uiSchema } = useVernaValue ! ;
0 commit comments