summaryrefslogtreecommitdiffstats
path: root/tests/javascript/unit/store/folder.spec.ts
diff options
context:
space:
mode:
Diffstat (limited to 'tests/javascript/unit/store/folder.spec.ts')
-rw-r--r--tests/javascript/unit/store/folder.spec.ts36
1 files changed, 35 insertions, 1 deletions
diff --git a/tests/javascript/unit/store/folder.spec.ts b/tests/javascript/unit/store/folder.spec.ts
index 796908587..8150ed28f 100644
--- a/tests/javascript/unit/store/folder.spec.ts
+++ b/tests/javascript/unit/store/folder.spec.ts
@@ -1,7 +1,7 @@
import { Folder } from '../../../../src/types/Folder'
import { AppState } from '../../../../src/store'
import { FOLDER_ACTION_TYPES, mutations, actions } from '../../../../src/store/folder'
-import { FOLDER_MUTATION_TYPES } from '../../../../src/types/MutationTypes'
+import { FEED_MUTATION_TYPES, FOLDER_MUTATION_TYPES } from '../../../../src/types/MutationTypes'
import { FolderService } from '../../../../src/dataservices/folder.service'
jest.mock('@nextcloud/router')
@@ -44,6 +44,18 @@ describe('folder.ts', () => {
expect(FolderService.deleteFolder).toBeCalled()
expect(commit).toBeCalled()
})
+
+ it('FOLDER_SET_NAME should call FolderService.renameFolder and then commit deleted folder to state', async () => {
+ FolderService.renameFolder = jest.fn();
+ (FolderService.renameFolder as any).mockResolvedValue()
+
+ const folder = {} as Folder
+ const commit = jest.fn()
+
+ await actions[FOLDER_ACTION_TYPES.FOLDER_SET_NAME]({ commit } as any, { folder, name: 'newName' } as any)
+ expect(FolderService.renameFolder).toBeCalledWith({ id: folder.id, name: 'newName' })
+ expect(commit).toBeCalled()
+ })
})
describe('mutations', () => {
@@ -68,5 +80,27 @@ describe('folder.ts', () => {
(mutations[FOLDER_MUTATION_TYPES.DELETE_FOLDER] as any)(state, folders)
expect(state.folders.length).toEqual(0)
})
+
+ it('UPDATE_FOLDER should update the folder properties in the state', () => {
+ const state = { folders: [{ name: 'test', id: 123 }] as Folder[] } as AppState
+ const newFolder = { id: 123, name: 'newName' };
+
+ (mutations[FOLDER_MUTATION_TYPES.UPDATE_FOLDER] as any)(state, newFolder)
+ expect(state.folders[0].name).toEqual('newName')
+ })
+
+ it('MODIFY_FOLDER_UNREAD_COUNT should update the folder feedCount in the state based on the delta', () => {
+ const state = { folders: [{ name: 'test', id: 123, feedCount: 10 }] as Folder[] } as AppState
+
+ (mutations[FOLDER_MUTATION_TYPES.MODIFY_FOLDER_UNREAD_COUNT] as any)(state, { folderId: 123, delta: -3 })
+ expect(state.folders[0].feedCount).toEqual(7)
+ })
+
+ it('SET_FEED_ALL_READ should update the folder feedCount in the state based on the feed unreadCount', () => {
+ const state = { folders: [{ name: 'test', id: 123, feedCount: 10 }] as Folder[] } as AppState
+
+ (mutations[FEED_MUTATION_TYPES.SET_FEED_ALL_READ] as any)(state, { id: 1, folderId: 123, unreadCount: 2 })
+ expect(state.folders[0].feedCount).toEqual(8)
+ })
})
})