@@ -9,8 +9,13 @@ import { createPinia, setActivePinia } from 'pinia'
99
1010import FilesList from '../../../views/FilesList/FilesList.vue'
1111import { useFilesStore } from '../../../store/files.js'
12+ import { useSidebarStore } from '../../../store/sidebar.js'
1213import { useUserConfigStore } from '../../../store/userconfig.js'
1314
15+ vi . mock ( 'vue-router' , ( ) => ( {
16+ useRoute : vi . fn ( ( ) => routeMock ) ,
17+ } ) )
18+
1419vi . mock ( '@nextcloud/logger' , ( ) => ( {
1520 getLogger : vi . fn ( ( ) => ( {
1621 error : vi . fn ( ) ,
@@ -132,6 +137,7 @@ describe('FilesList.vue rendering rules', () => {
132137 beforeEach ( ( ) => {
133138 setActivePinia ( createPinia ( ) )
134139 vi . clearAllMocks ( )
140+ routeMock . query = { }
135141 } )
136142
137143 function mountComponent ( ) {
@@ -277,4 +283,34 @@ describe('FilesList.vue rendering rules', () => {
277283 const iconWithPath = gridButton . findAll ( '.nc-icon' ) . find ( ( node ) => ! ! node . attributes ( 'data-path' ) )
278284 expect ( iconWithPath ?. attributes ( 'data-path' ) ) . toBe ( wrapper . vm . mdiFormatListBulletedSquare )
279285 } )
286+
287+ it ( 'preserves the selected file while the sign sidebar is open' , async ( ) => {
288+ const filesStore = useFilesStore ( )
289+ const sidebarStore = useSidebarStore ( )
290+ vi . spyOn ( filesStore , 'getAllFiles' ) . mockResolvedValue ( { } )
291+ const selectSpy = vi . spyOn ( filesStore , 'selectFile' )
292+
293+ const wrapper = mountComponent ( )
294+ await flushPromises ( )
295+ selectSpy . mockClear ( )
296+
297+ sidebarStore . activeSignTab ( )
298+ wrapper . unmount ( )
299+
300+ expect ( selectSpy ) . not . toHaveBeenCalled ( )
301+ } )
302+
303+ it ( 'clears the selected file when the sign sidebar is not active' , async ( ) => {
304+ const filesStore = useFilesStore ( )
305+ vi . spyOn ( filesStore , 'getAllFiles' ) . mockResolvedValue ( { } )
306+ const selectSpy = vi . spyOn ( filesStore , 'selectFile' )
307+
308+ const wrapper = mountComponent ( )
309+ await flushPromises ( )
310+ selectSpy . mockClear ( )
311+
312+ wrapper . unmount ( )
313+
314+ expect ( selectSpy ) . toHaveBeenCalledWith ( )
315+ } )
280316} )
0 commit comments