summaryrefslogtreecommitdiffstats
path: root/tests
diff options
context:
space:
mode:
authorDevlin Junker <devlin.junker@gmail.com>2023-09-16 14:00:27 -0700
committerBenjamin Brahmer <info@b-brahmer.de>2023-09-20 17:32:33 +0200
commit6aa282d2af464e9ee76dd0264d66ac54ef2fedea (patch)
tree521ccb1c4e9fbc96ec0eb35f62d4734d9c6c95a8 /tests
parentb234f334412d6e68a7adcd70e25707730c4808e7 (diff)
store tests
Signed-off-by: Devlin Junker <devlin.junker@gmail.com>
Diffstat (limited to 'tests')
-rw-r--r--tests/javascript/unit/store/feed.spec.ts150
-rw-r--r--tests/javascript/unit/store/folder.spec.ts36
2 files changed, 183 insertions, 3 deletions
diff --git a/tests/javascript/unit/store/feed.spec.ts b/tests/javascript/unit/store/feed.spec.ts
index db4431b20..ede4307d1 100644
--- a/tests/javascript/unit/store/feed.spec.ts
+++ b/tests/javascript/unit/store/feed.spec.ts
@@ -1,9 +1,10 @@
import { Feed } from '../../../../src/types/Feed'
import { AppState } from '../../../../src/store'
import { FEED_ACTION_TYPES, mutations, actions } from '../../../../src/store/feed'
-import { FeedService } from '../../../../src/dataservices/feed.service'
+import { FEED_ORDER, FEED_UPDATE_MODE, FeedService } from '../../../../src/dataservices/feed.service'
-import { FEED_ITEM_MUTATION_TYPES, FEED_MUTATION_TYPES } from '../../../../src/types/MutationTypes'
+import { FEED_ITEM_MUTATION_TYPES, FEED_MUTATION_TYPES, FOLDER_MUTATION_TYPES } from '../../../../src/types/MutationTypes'
+import { ItemService } from '../../../../src/dataservices/item.service'
describe('feed.ts', () => {
'use strict'
@@ -42,6 +43,113 @@ describe('feed.ts', () => {
})
})
+ describe('FEED_MARK_READ', () => {
+ it('should call FeedService.markRead and commit all items read to state', async () => {
+ ItemService.fetchFeedItems = jest.fn();
+ (ItemService.fetchFeedItems as any).mockResolvedValue({ data: { items: [{ id: 123 }] } })
+ FeedService.markRead = jest.fn()
+ const commit = jest.fn()
+ const feed = { id: 1, title: 'feed' }
+
+ await (actions[FEED_ACTION_TYPES.FEED_MARK_READ] as any)({ commit }, { feed })
+ expect(FeedService.markRead).toBeCalled()
+ expect(commit).toBeCalledWith(FEED_MUTATION_TYPES.SET_FEED_ALL_READ, feed)
+ })
+
+ it('should commit MODIFY_FOLDER_UNREAD_COUNT with feed unreadCount if folderId exists on feed ', async () => {
+ ItemService.fetchFeedItems = jest.fn();
+ (ItemService.fetchFeedItems as any).mockResolvedValue({ data: { items: [{ id: 123 }] } })
+ FeedService.markRead = jest.fn()
+ const commit = jest.fn()
+ const feed = { id: 1, title: 'feed', folderId: 234, unreadCount: 2 }
+
+ await (actions[FEED_ACTION_TYPES.FEED_MARK_READ] as any)({ commit }, { feed })
+ expect(FeedService.markRead).toBeCalled()
+ expect(commit).toBeCalledWith(FEED_MUTATION_TYPES.SET_FEED_ALL_READ, feed)
+ expect(commit).toBeCalledWith(FOLDER_MUTATION_TYPES.MODIFY_FOLDER_UNREAD_COUNT, { folderId: 234, delta: -2 })
+ })
+ })
+
+ describe('FEED_SET_PINNED', () => {
+ it('should call FeedService.updateFeed and commit updated `pinned` property to state', async () => {
+ FeedService.updateFeed = jest.fn()
+ const commit = jest.fn()
+ await (actions[FEED_ACTION_TYPES.FEED_SET_PINNED] as any)({ commit }, { feed: { id: 1 }, pinned: true })
+ expect(FeedService.updateFeed).toBeCalledWith({ feedId: 1, pinned: true })
+ expect(commit).toBeCalledWith(FEED_MUTATION_TYPES.UPDATE_FEED, { id: 1, pinned: true })
+ })
+ })
+
+ describe('FEED_SET_ORDERING', () => {
+ it('should call FeedService.updateFeed and commit updated `ordering` property to state', async () => {
+ FeedService.updateFeed = jest.fn()
+ const commit = jest.fn()
+ await (actions[FEED_ACTION_TYPES.FEED_SET_ORDERING] as any)({ commit }, { feed: { id: 1 }, ordering: FEED_ORDER.DEFAULT })
+ expect(FeedService.updateFeed).toBeCalledWith({ feedId: 1, ordering: FEED_ORDER.DEFAULT })
+ expect(commit).toBeCalledWith(FEED_MUTATION_TYPES.UPDATE_FEED, { id: 1, ordering: FEED_ORDER.DEFAULT })
+ })
+ })
+
+ describe('FEED_SET_FULL_TEXT', () => {
+ it('should call FeedService.updateFeed and commit updated `fullTextEnabled` property to state', async () => {
+ FeedService.updateFeed = jest.fn()
+ const commit = jest.fn()
+ await (actions[FEED_ACTION_TYPES.FEED_SET_FULL_TEXT] as any)({ commit }, { feed: { id: 1 }, fullTextEnabled: true })
+ expect(FeedService.updateFeed).toBeCalledWith({ feedId: 1, fullTextEnabled: true })
+ expect(commit).toBeCalledWith(FEED_MUTATION_TYPES.UPDATE_FEED, { id: 1, fullTextEnabled: true })
+ })
+ })
+
+ describe('FEED_SET_UPDATE_MODE', () => {
+ it('should call FeedService.updateFeed and commit updated `updateMode` property to state', async () => {
+ FeedService.updateFeed = jest.fn()
+ const commit = jest.fn()
+ await (actions[FEED_ACTION_TYPES.FEED_SET_UPDATE_MODE] as any)({ commit }, { feed: { id: 1 }, updateMode: FEED_UPDATE_MODE.IGNORE })
+ expect(FeedService.updateFeed).toBeCalledWith({ feedId: 1, updateMode: FEED_UPDATE_MODE.IGNORE })
+ expect(commit).toBeCalledWith(FEED_MUTATION_TYPES.UPDATE_FEED, { id: 1, updateMode: FEED_UPDATE_MODE.IGNORE })
+ })
+ })
+
+ describe('FEED_SET_TITLE', () => {
+ it('should call FeedService.updateFeed and commit updated `title` property to state', async () => {
+ FeedService.updateFeed = jest.fn()
+ const commit = jest.fn()
+ await (actions[FEED_ACTION_TYPES.FEED_SET_TITLE] as any)({ commit }, { feed: { id: 1 }, title: 'newTitle' })
+ expect(FeedService.updateFeed).toBeCalledWith({ feedId: 1, title: 'newTitle' })
+ expect(commit).toBeCalledWith(FEED_MUTATION_TYPES.UPDATE_FEED, { id: 1, title: 'newTitle' })
+ })
+ })
+
+ describe('FEED_DELETE', () => {
+ it('should call FeedService.deleteFeed and commit to state', async () => {
+ FeedService.deleteFeed = jest.fn()
+ const commit = jest.fn()
+ await (actions[FEED_ACTION_TYPES.FEED_DELETE] as any)({ commit }, { feed: { id: 1 } })
+ expect(FeedService.deleteFeed).toBeCalledWith({ feedId: 1 })
+ expect(commit).toBeCalledWith(FEED_MUTATION_TYPES.FEED_DELETE, 1)
+ })
+ })
+
+ describe('MODIFY_FEED_UNREAD_COUNT', () => {
+ const state = {
+ feeds: [{ id: 1 }],
+ }
+ it('should commit to state', async () => {
+ const commit = jest.fn()
+ await (actions[FEED_ACTION_TYPES.MODIFY_FEED_UNREAD_COUNT] as any)({ commit, state }, { feedId: 1, delta: -2 })
+ expect(commit).toBeCalledWith(FEED_MUTATION_TYPES.MODIFY_FEED_UNREAD_COUNT, { feedId: 1, delta: -2 })
+ })
+
+ it('should commit folder to state if feed has folderId', async () => {
+ const state = {
+ feeds: [{ id: 1, folderId: 234 }],
+ }
+ const commit = jest.fn()
+ await (actions[FEED_ACTION_TYPES.MODIFY_FEED_UNREAD_COUNT] as any)({ commit, state }, { feedId: 1, delta: -2 })
+ expect(commit).toBeCalledWith(FEED_MUTATION_TYPES.MODIFY_FEED_UNREAD_COUNT, { feedId: 1, delta: -2 })
+ expect(commit).toBeCalledWith(FOLDER_MUTATION_TYPES.MODIFY_FOLDER_UNREAD_COUNT, { folderId: 234, delta: -2 })
+ })
+ })
})
describe('mutations', () => {
@@ -71,5 +179,43 @@ describe('feed.ts', () => {
expect(state.feeds[0]).toEqual(feed)
})
})
+
+ describe('UPDATE_FEED', () => {
+ it('should update a feed in the state', () => {
+ const state = { feeds: [{ title: 'oldName', id: 1 }] as Feed[], folders: [] as any[] } as AppState
+ const feed = { title: 'test', id: 1 } as any
+
+ mutations[FEED_MUTATION_TYPES.UPDATE_FEED](state, feed)
+ expect(state.feeds[0].title).toEqual('test')
+ })
+ })
+
+ describe('SET_FEED_ALL_READ', () => {
+ it('should update a feed unreadCount to 0 in the state', () => {
+ const state = { feeds: [{ title: 'oldName', id: 1, unreadCount: 4 }] as Feed[], folders: [] as any[] } as AppState
+ const feed = { title: 'test', id: 1 } as any
+
+ mutations[FEED_MUTATION_TYPES.SET_FEED_ALL_READ](state, feed)
+ expect(state.feeds[0].unreadCount).toEqual(0)
+ })
+ })
+
+ describe('MODIFY_FEED_UNREAD_COUNT', () => {
+ it('should update a feed unreadCount to 0 in the state', () => {
+ const state = { feeds: [{ title: 'oldName', id: 1, unreadCount: 4 }] as Feed[], folders: [] as any[] } as AppState
+
+ mutations[FEED_MUTATION_TYPES.MODIFY_FEED_UNREAD_COUNT](state, { feedId: 1, delta: -1 } as any)
+ expect(state.feeds[0].unreadCount).toEqual(3)
+ })
+ })
+
+ describe('FEED_DELETE', () => {
+ it('should update a feed unreadCount to 0 in the state', () => {
+ const state = { feeds: [{ title: 'oldName', id: 1, unreadCount: 4 }] as Feed[], folders: [] as any[] } as AppState
+
+ mutations[FEED_MUTATION_TYPES.FEED_DELETE](state, 1 as any)
+ expect(state.feeds.length).toEqual(0)
+ })
+ })
})
})
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)
+ })
})
})