|
23 | 23 | import { basename } from 'path' |
24 | 24 | import { expect } from '@jest/globals' |
25 | 25 | import { Folder, Navigation, getNavigation } from '@nextcloud/files' |
26 | | -import eventBus from '@nextcloud/event-bus' |
| 26 | +import eventBus, { emit } from '@nextcloud/event-bus' |
27 | 27 | import * as initialState from '@nextcloud/initial-state' |
28 | 28 |
|
29 | 29 | import { action } from '../actions/favoriteAction' |
@@ -63,9 +63,10 @@ describe('Favorites view definition', () => { |
63 | 63 | const favoritesView = Navigation.views.find(view => view.id === 'favorites') |
64 | 64 | const favoriteFoldersViews = Navigation.views.filter(view => view.parent === 'favorites') |
65 | 65 |
|
66 | | - expect(eventBus.subscribe).toHaveBeenCalledTimes(2) |
| 66 | + expect(eventBus.subscribe).toHaveBeenCalledTimes(3) |
67 | 67 | expect(eventBus.subscribe).toHaveBeenNthCalledWith(1, 'files:favorites:added', expect.anything()) |
68 | 68 | expect(eventBus.subscribe).toHaveBeenNthCalledWith(2, 'files:favorites:removed', expect.anything()) |
| 69 | + expect(eventBus.subscribe).toHaveBeenNthCalledWith(3, 'files:node:renamed', expect.anything()) |
69 | 70 |
|
70 | 71 | // one main view and no children |
71 | 72 | expect(Navigation.views.length).toBe(1) |
@@ -196,4 +197,43 @@ describe('Dynamic update of favourite folders', () => { |
196 | 197 | expect(favoritesView).toBeDefined() |
197 | 198 | expect(favoriteFoldersViews.length).toBe(0) |
198 | 199 | }) |
| 200 | + |
| 201 | + test('Renaming a favorite folder updates the navigation', async () => { |
| 202 | + jest.spyOn(eventBus, 'emit') |
| 203 | + jest.spyOn(initialState, 'loadState').mockReturnValue([]) |
| 204 | + jest.spyOn(favoritesService, 'getContents').mockReturnValue(Promise.resolve({ folder: {} as Folder, contents: [] })) |
| 205 | + |
| 206 | + registerFavoritesView() |
| 207 | + const favoritesView = Navigation.views.find(view => view.id === 'favorites') |
| 208 | + const favoriteFoldersViews = Navigation.views.filter(view => view.parent === 'favorites') |
| 209 | + |
| 210 | + // one main view and no children |
| 211 | + expect(Navigation.views.length).toBe(1) |
| 212 | + expect(favoritesView).toBeDefined() |
| 213 | + expect(favoriteFoldersViews.length).toBe(0) |
| 214 | + |
| 215 | + // expect(eventBus.emit).toHaveBeenCalledTimes(2) |
| 216 | + |
| 217 | + // Create new folder to favorite |
| 218 | + const folder = new Folder({ |
| 219 | + id: 1, |
| 220 | + source: 'http://localhost/remote.php/dav/files/admin/Foo/Bar', |
| 221 | + owner: 'admin', |
| 222 | + }) |
| 223 | + |
| 224 | + // Exec the action |
| 225 | + await action.exec(folder, favoritesView, '/') |
| 226 | + expect(eventBus.emit).toHaveBeenNthCalledWith(1, 'files:favorites:added', folder) |
| 227 | + |
| 228 | + // Create a folder with the same id but renamed |
| 229 | + const renamedFolder = new Folder({ |
| 230 | + id: 1, |
| 231 | + source: 'http://localhost/remote.php/dav/files/admin/Foo/Bar.renamed', |
| 232 | + owner: 'admin', |
| 233 | + }) |
| 234 | + |
| 235 | + // Exec the rename action |
| 236 | + emit('files:node:renamed', renamedFolder) |
| 237 | + expect(eventBus.emit).toHaveBeenNthCalledWith(2, 'files:node:renamed', renamedFolder) |
| 238 | + }) |
199 | 239 | }) |
0 commit comments