@@ -16,10 +16,16 @@ vi.hoisted(() => {
1616
1717import type { IToken } from '../store/authtoken.ts'
1818
19+ // Mock @nextcloud /dialogs so the wipe action's showConfirmation call resolves
20+ // synchronously in tests. Hoisted so it's installed before AuthToken.vue imports.
21+ const showConfirmationMock = vi . hoisted ( ( ) => vi . fn ( ) )
22+ vi . mock ( '@nextcloud/dialogs' , ( ) => ( {
23+ showConfirmation : showConfirmationMock ,
24+ } ) )
25+
1926import NcNoteCard from '@nextcloud/vue/components/NcNoteCard'
2027import AuthToken from './AuthToken.vue'
2128import AuthTokenDeleteDialog from './AuthTokenDeleteDialog.vue'
22- import AuthTokenWipeDialog from './AuthTokenWipeDialog.vue'
2329import { TokenType , useAuthTokenStore } from '../store/authtoken.ts'
2430import { detect } from '../utils/userAgentDetect.ts'
2531
@@ -143,33 +149,27 @@ describe('AuthToken wipe flow', () => {
143149 vi . clearAllMocks ( )
144150 } )
145151
146- it ( 'does not call wipeToken when the wipe action is triggered (dialog opens first)' , async ( ) => {
152+ it ( 'does not call wipeToken when the user rejects the confirmation' , async ( ) => {
153+ showConfirmationMock . mockResolvedValueOnce ( false )
147154 const token = makeToken ( )
148155 const wrapper = mountAuthToken ( token )
149156 const store = useAuthTokenStore ( )
150157
151- ; ( wrapper . vm as unknown as { wipe : ( ) => void } ) . wipe ( )
152- await wrapper . vm . $nextTick ( )
158+ await ( wrapper . vm as unknown as { wipe : ( ) => Promise < void > } ) . wipe ( )
153159
154- const dialog = wrapper . findComponent ( AuthTokenWipeDialog )
155- expect ( dialog . exists ( ) ) . toBe ( true )
156- expect ( dialog . props ( 'open' ) ) . toBe ( true )
160+ expect ( showConfirmationMock ) . toHaveBeenCalledTimes ( 1 )
157161 expect ( store . wipeToken ) . not . toHaveBeenCalled ( )
158162 } )
159163
160- it ( 'calls wipeToken only after the dialog emits confirm' , async ( ) => {
164+ it ( 'calls wipeToken when the user accepts the confirmation' , async ( ) => {
165+ showConfirmationMock . mockResolvedValueOnce ( true )
161166 const token = makeToken ( )
162167 const wrapper = mountAuthToken ( token )
163168 const store = useAuthTokenStore ( )
164169
165- ; ( wrapper . vm as unknown as { wipe : ( ) => void } ) . wipe ( )
166- await wrapper . vm . $nextTick ( )
167-
168- const dialog = wrapper . findComponent ( AuthTokenWipeDialog )
169- dialog . vm . $emit ( 'confirm' )
170- dialog . vm . $emit ( 'update:open' , false )
171- await wrapper . vm . $nextTick ( )
170+ await ( wrapper . vm as unknown as { wipe : ( ) => Promise < void > } ) . wipe ( )
172171
172+ expect ( showConfirmationMock ) . toHaveBeenCalledTimes ( 1 )
173173 expect ( store . wipeToken ) . toHaveBeenCalledTimes ( 1 )
174174 expect ( store . wipeToken ) . toHaveBeenCalledWith ( token )
175175 } )
0 commit comments