33 * SPDX-License-Identifier: AGPL-3.0-or-later
44 */
55
6- import { cleanup , findByRole , fireEvent , getByLabelText , getByRole } from '@testing-library/vue'
7- import { afterEach , expect , test } from 'vitest'
6+ import { findByRole , fireEvent , getByLabelText , getByRole } from '@testing-library/vue'
7+ import { expect , test } from 'vitest'
88import { showConfirmation } from './dialogs.ts'
99
10- afterEach ( cleanup )
10+ async function waitForTransition ( ) {
11+ await new Promise ( ( r ) => window . setTimeout ( r , 250 ) )
12+ }
1113
1214test ( 'Show confirmation dialog' , async ( ) => {
1315 const promise = showConfirmation ( {
@@ -16,6 +18,8 @@ test('Show confirmation dialog', async () => {
1618 } )
1719
1820 const dialog = await findByRole ( document . documentElement , 'dialog' )
21+ await waitForTransition ( )
22+
1923 expect ( dialog ) . toBeInstanceOf ( HTMLElement )
2024
2125 expect ( getByLabelText ( document . documentElement , 'Dialog name' ) ) . toBe ( dialog )
@@ -38,8 +42,10 @@ test('show confirmation dialog with reject', async () => {
3842 } )
3943
4044 const dialog = await findByRole ( document . documentElement , 'dialog' )
41- const confirm = getByRole ( dialog , 'button' , { name : 'My confirm' } )
42- const reject = getByRole ( dialog , 'button' , { name : 'My reject' } )
45+ await waitForTransition ( )
46+
47+ const confirm = await findByRole ( dialog , 'button' , { name : 'My confirm' } )
48+ const reject = await findByRole ( dialog , 'button' , { name : 'My reject' } )
4349 expect ( confirm ) . toBeInstanceOf ( HTMLElement )
4450 expect ( reject ) . toBeInstanceOf ( HTMLElement )
4551 await fireEvent ( reject , new MouseEvent ( 'click' , { bubbles : true } ) )
@@ -53,8 +59,9 @@ test('show confirmation dialog and close', async () => {
5359 } )
5460
5561 const dialog = await findByRole ( document . documentElement , 'dialog' )
56- const close = getByRole ( dialog , 'button' , { name : 'Close' } )
57- expect ( close ) . toBeInstanceOf ( HTMLElement )
62+ await waitForTransition ( )
63+
64+ const close = await findByRole ( dialog , 'button' , { name : 'Close' } )
5865 await fireEvent ( close , new MouseEvent ( 'click' , { bubbles : true } ) )
5966 await expect ( promise ) . rejects . toThrowError ( 'Dialog closed' )
6067} )
0 commit comments