summaryrefslogtreecommitdiffstats
path: root/tests
diff options
context:
space:
mode:
authorDevlin Junker <devlin.junker@gmail.com>2022-12-03 16:39:00 -0800
committerBenjamin Brahmer <info@b-brahmer.de>2022-12-06 14:57:20 +0100
commite61fb48d64fe11c42c84b0a46d859c08b10a3fb8 (patch)
tree6d1e4fa5c745750510f91e241f30a4b878d308f2 /tests
parent2c32ea05f0a0f266e36075e702ee293d7834bf62 (diff)
basic tests for store
Signed-off-by: Devlin Junker <devlin.junker@gmail.com>
Diffstat (limited to 'tests')
-rw-r--r--tests/javascript/unit/setup.ts (renamed from tests/javascript/unit/setup.spec.ts)0
-rw-r--r--tests/javascript/unit/store/feed.spec.ts36
-rw-r--r--tests/javascript/unit/store/folder.spec.ts44
3 files changed, 67 insertions, 13 deletions
diff --git a/tests/javascript/unit/setup.spec.ts b/tests/javascript/unit/setup.ts
index 510e53baa..510e53baa 100644
--- a/tests/javascript/unit/setup.spec.ts
+++ b/tests/javascript/unit/setup.ts
diff --git a/tests/javascript/unit/store/feed.spec.ts b/tests/javascript/unit/store/feed.spec.ts
index 1a4fb0fee..94f45d42d 100644
--- a/tests/javascript/unit/store/feed.spec.ts
+++ b/tests/javascript/unit/store/feed.spec.ts
@@ -9,20 +9,48 @@ describe('feed.ts', () => {
'use strict'
describe('actions', () => {
- it('ADD_FEED', async () => {
+ it('ADD_FEED should call POST and commit feed to state', async () => {
(axios as any).post.mockResolvedValue()
const commit = jest.fn()
await actions[FEED_ACTION_TYPES.ADD_FEED]({ commit }, { feedReq: { url: '' } })
expect(axios.post).toBeCalled()
expect(commit).toBeCalled()
})
+
+ it('FETCH_FEEDS should call GET and commit returned feeds to state', async () => {
+ (axios as any).get.mockResolvedValue({ data: { feeds: [] } })
+ const commit = jest.fn()
+ await (actions[FEED_ACTION_TYPES.FETCH_FEEDS] as any)({ commit })
+ expect(axios.get).toBeCalled()
+ expect(commit).toBeCalled()
+ })
})
describe('mutations', () => {
- it('', () => {
- const state = { feeds: [] as Feed[] } as AppState
- const feeds = [] as Feed[]
+ it('SET_FEEDS should add feeds to state', () => {
+ const state = { feeds: [] as Feed[], folders: [] as any[] } as AppState
+ let feeds = [] as Feed[]
+ mutations[FEED_MUTATION_TYPES.SET_FEEDS](state, feeds)
+
+ expect(state.feeds.length).toEqual(0)
+
+ feeds = [{ title: 'test' }] as Feed[]
mutations[FEED_MUTATION_TYPES.SET_FEEDS](state, feeds)
+
+ expect(state.feeds.length).toEqual(1)
+ expect(state.feeds[0]).toEqual(feeds[0])
+ })
+
+ it('SET_FEEDS should add feeds and unreadCount to folder if exists and folder set', () => {
+ const state = { feeds: [] as Feed[], folders: [{ id: 1, feedCount: 3, feeds: [] as Feed[] }] } as AppState
+ const feeds = [{ title: 'test', folderId: 1, unreadCount: 2 }] as Feed[]
+
+ mutations[FEED_MUTATION_TYPES.SET_FEEDS](state, feeds)
+
+ expect(state.feeds.length).toEqual(1)
+ expect(state.feeds[0]).toEqual(feeds[0])
+ expect(state.folders[0].feeds[0]).toEqual(feeds[0])
+ expect(state.folders[0].feedCount).toEqual(5)
})
})
})
diff --git a/tests/javascript/unit/store/folder.spec.ts b/tests/javascript/unit/store/folder.spec.ts
index 1d7feafb0..0350bed34 100644
--- a/tests/javascript/unit/store/folder.spec.ts
+++ b/tests/javascript/unit/store/folder.spec.ts
@@ -1,19 +1,29 @@
import axios from '@nextcloud/axios'
+import { generateUrl } from '@nextcloud/router'
import { Folder } from '../../../../src/types/Folder'
import { AppState } from '../../../../src/store'
import { FOLDER_ACTION_TYPES, FOLDER_MUTATION_TYPES, mutations, actions } from '../../../../src/store/folder'
jest.mock('@nextcloud/axios')
+jest.mock('@nextcloud/router')
describe('folder.ts', () => {
'use strict'
describe('actions', () => {
- it('FETCH_FOLDERS', () => {
- // TODO
+ it('FETCH_FOLDERS should send GET and then commit folders returned to state', async () => {
+ (generateUrl as any).mockReturnValue('');
+ (axios.get as any).mockResolvedValue({ data: { folders: [] } })
+
+ const commit = jest.fn()
+
+ await (actions[FOLDER_ACTION_TYPES.FETCH_FOLDERS] as any)({ commit })
+
+ expect(axios.get).toBeCalled()
+ expect(commit).toBeCalled()
})
- it('ADD_FOLDERS should send POST and then commit the folders returned', async () => {
+ it('ADD_FOLDERS should send POST and then commit the folders returned to state', async () => {
(axios.post as any).mockResolvedValue({ data: { folders: [] } })
const folder = {} as Folder
@@ -23,22 +33,38 @@ describe('folder.ts', () => {
expect(commit).toBeCalled()
})
- it('DELETE_FOLDER', () => {
- // TODO
+ it('DELETE_FOLDER should send DELETE and then commit deleted folder to state', async () => {
+ (axios.delete as any).mockResolvedValue()
+
+ const folder = {} as Folder
+ const commit = jest.fn()
+ await actions[FOLDER_ACTION_TYPES.DELETE_FOLDER]({ commit }, { folder })
+ expect(axios.delete).toBeCalled()
+ expect(commit).toBeCalled()
})
})
describe('mutations', () => {
- it('SET_FOLDERS', () => {
+ it('SET_FOLDERS should add the passed in folders to the state', () => {
const state = { folders: [] as Folder[] } as AppState
- const folders = [] as Folder[]
+ let folders = [] as Folder[]
(mutations[FOLDER_MUTATION_TYPES.SET_FOLDERS] as any)(state, folders)
expect(state.folders.length).toEqual(0)
+
+ folders = [{ name: 'test' }] as Folder[]
+ (mutations[FOLDER_MUTATION_TYPES.SET_FOLDERS] as any)(state, folders)
+
+ expect(state.folders.length).toEqual(1)
+ expect(state.folders[0]).toEqual(folders[0])
})
- it('DELETE_FOLDER', () => {
- // TODO
+ it('DELETE_FOLDER should remove the passed in folder from the state', () => {
+ const state = { folders: [{ name: 'test' }] as Folder[] } as AppState
+ const folders = [state.folders[0]] as Folder[]
+ (mutations[FOLDER_MUTATION_TYPES.DELETE_FOLDER] as any)(state, folders)
+
+ expect(state.folders.length).toEqual(0)
})
})
})