@@ -7,7 +7,7 @@ import { basename } from 'path'
77import { expect } from '@jest/globals'
88import { Folder , Navigation , getNavigation } from '@nextcloud/files'
99import { CancelablePromise } from 'cancelable-promise'
10- import eventBus from '@nextcloud/event-bus'
10+ import eventBus , { emit } from '@nextcloud/event-bus'
1111import * as initialState from '@nextcloud/initial-state'
1212
1313import { action } from '../actions/favoriteAction'
@@ -47,9 +47,10 @@ describe('Favorites view definition', () => {
4747 const favoritesView = Navigation . views . find ( view => view . id === 'favorites' )
4848 const favoriteFoldersViews = Navigation . views . filter ( view => view . parent === 'favorites' )
4949
50- expect ( eventBus . subscribe ) . toHaveBeenCalledTimes ( 2 )
50+ expect ( eventBus . subscribe ) . toHaveBeenCalledTimes ( 3 )
5151 expect ( eventBus . subscribe ) . toHaveBeenNthCalledWith ( 1 , 'files:favorites:added' , expect . anything ( ) )
5252 expect ( eventBus . subscribe ) . toHaveBeenNthCalledWith ( 2 , 'files:favorites:removed' , expect . anything ( ) )
53+ expect ( eventBus . subscribe ) . toHaveBeenNthCalledWith ( 3 , 'files:node:renamed' , expect . anything ( ) )
5354
5455 // one main view and no children
5556 expect ( Navigation . views . length ) . toBe ( 1 )
@@ -180,4 +181,43 @@ describe('Dynamic update of favourite folders', () => {
180181 expect ( favoritesView ) . toBeDefined ( )
181182 expect ( favoriteFoldersViews . length ) . toBe ( 0 )
182183 } )
184+
185+ test ( 'Renaming a favorite folder updates the navigation' , async ( ) => {
186+ jest . spyOn ( eventBus , 'emit' )
187+ jest . spyOn ( initialState , 'loadState' ) . mockReturnValue ( [ ] )
188+ jest . spyOn ( favoritesService , 'getContents' ) . mockReturnValue ( CancelablePromise . resolve ( { folder : { } as Folder , contents : [ ] } ) )
189+
190+ registerFavoritesView ( )
191+ const favoritesView = Navigation . views . find ( view => view . id === 'favorites' )
192+ const favoriteFoldersViews = Navigation . views . filter ( view => view . parent === 'favorites' )
193+
194+ // one main view and no children
195+ expect ( Navigation . views . length ) . toBe ( 1 )
196+ expect ( favoritesView ) . toBeDefined ( )
197+ expect ( favoriteFoldersViews . length ) . toBe ( 0 )
198+
199+ // expect(eventBus.emit).toHaveBeenCalledTimes(2)
200+
201+ // Create new folder to favorite
202+ const folder = new Folder ( {
203+ id : 1 ,
204+ source : 'http://localhost/remote.php/dav/files/admin/Foo/Bar' ,
205+ owner : 'admin' ,
206+ } )
207+
208+ // Exec the action
209+ await action . exec ( folder , favoritesView , '/' )
210+ expect ( eventBus . emit ) . toHaveBeenNthCalledWith ( 1 , 'files:favorites:added' , folder )
211+
212+ // Create a folder with the same id but renamed
213+ const renamedFolder = new Folder ( {
214+ id : 1 ,
215+ source : 'http://localhost/remote.php/dav/files/admin/Foo/Bar.renamed' ,
216+ owner : 'admin' ,
217+ } )
218+
219+ // Exec the rename action
220+ emit ( 'files:node:renamed' , renamedFolder )
221+ expect ( eventBus . emit ) . toHaveBeenNthCalledWith ( 2 , 'files:node:renamed' , renamedFolder )
222+ } )
183223} )
0 commit comments