@@ -24,6 +24,9 @@ const DEFAULT_FORM_BUILDER_OPTIONS = {
24
24
describe ( 'NavFormBuilder' , ( ) => {
25
25
beforeAll ( ( ) => {
26
26
new NavFormioJs . Formio ( DEFAULT_PROJECT_URL ) ;
27
+ } ) ;
28
+
29
+ beforeEach ( ( ) => {
27
30
vi . spyOn ( NavFormioJs . Formio , 'fetch' ) . mockImplementation ( createMockImplementation ( ) ) ;
28
31
} ) ;
29
32
@@ -149,6 +152,7 @@ describe('NavFormBuilder', () => {
149
152
150
153
it ( 'prompts user when removing attachment panel' , async ( ) => {
151
154
window . confirm = vi . fn ( ) . mockImplementation ( ( ) => true ) ;
155
+ onReadyMock . mockReset ( ) ;
152
156
rerender (
153
157
< NavFormBuilder
154
158
form = { { ...testform , display : 'skjema' } }
@@ -159,11 +163,6 @@ describe('NavFormBuilder', () => {
159
163
) ;
160
164
await waitFor ( ( ) => expect ( onReadyMock . mock . calls ) . toHaveLength ( 1 ) ) ;
161
165
162
- // Bruker getByRole, siden findByRole finner element, men feiler på toBeInTheDocument()
163
- const attachmentPanelLink = screen . getByRole ( 'link' , { name : 'Vedlegg' } ) ;
164
- expect ( attachmentPanelLink ) . toBeInTheDocument ( ) ;
165
- await userEvent . click ( attachmentPanelLink ) ;
166
-
167
166
const attachmentPanel = await screen . findByRole ( 'button' , { name : 'Vedlegg' } ) ;
168
167
expect ( attachmentPanel ) . toBeInTheDocument ( ) ;
169
168
const builderComponent = findClosestWithAttribute ( attachmentPanel , BUILDER_COMP_TESTID_ATTR ) ;
@@ -181,6 +180,7 @@ describe('NavFormBuilder', () => {
181
180
182
181
it ( 'does not remove attachment panel if user declines prompt' , async ( ) => {
183
182
window . confirm = vi . fn ( ) . mockImplementation ( ( ) => false ) ;
183
+ onReadyMock . mockReset ( ) ;
184
184
rerender (
185
185
< NavFormBuilder
186
186
form = { { ...testform , display : 'skjema' } }
@@ -191,11 +191,6 @@ describe('NavFormBuilder', () => {
191
191
) ;
192
192
await waitFor ( ( ) => expect ( onReadyMock . mock . calls ) . toHaveLength ( 1 ) ) ;
193
193
194
- // Bruker getByRole, siden findByRole finner element, men feiler på toBeInTheDocument()
195
- const attachmentPanelLink = screen . getByRole ( 'link' , { name : 'Vedlegg' } ) ;
196
- expect ( attachmentPanelLink ) . toBeInTheDocument ( ) ;
197
- await userEvent . click ( attachmentPanelLink ) ;
198
-
199
194
const attachmentPanel = await screen . findByRole ( 'button' , { name : 'Vedlegg' } ) ;
200
195
expect ( attachmentPanel ) . toBeInTheDocument ( ) ;
201
196
const builderComponent = findClosestWithAttribute ( attachmentPanel , BUILDER_COMP_TESTID_ATTR ) ;
0 commit comments