summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--.eslintrc.js2
-rw-r--r--package.json2
-rw-r--r--src/store/folder.ts5
-rw-r--r--src/store/index.ts4
-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
7 files changed, 74 insertions, 19 deletions
diff --git a/.eslintrc.js b/.eslintrc.js
index 33eef5695..1021c7404 100644
--- a/.eslintrc.js
+++ b/.eslintrc.js
@@ -37,7 +37,7 @@ module.exports = {
},
overrides: [
{
- files: ['*spec.ts'],
+ files: ['*spec.ts', 'tests/javascript/unit/setup.ts'],
rules: {
'@typescript-eslint/no-explicit-any': 'off',
},
diff --git a/package.json b/package.json
index b4aa4643c..a181d2614 100644
--- a/package.json
+++ b/package.json
@@ -151,7 +151,7 @@
"jest-serializer-vue"
],
"setupFilesAfterEnv": [
- "./tests/javascript/unit/setup.spec.ts"
+ "./tests/javascript/unit/setup.ts"
],
"coverageDirectory": "./coverage/",
"collectCoverage": false,
diff --git a/src/store/folder.ts b/src/store/folder.ts
index 70a05c4ed..77d8a3b15 100644
--- a/src/store/folder.ts
+++ b/src/store/folder.ts
@@ -39,14 +39,15 @@ export const actions = {
const response = await axios.post(folderUrl, { folderName: folder.name })
commit(FOLDER_MUTATION_TYPES.SET_FOLDERS, response.data.folders)
},
- [FOLDER_ACTION_TYPES.DELETE_FOLDER]({ commit }: ActionParams, { folder }: { folder: Folder}) {
+ async [FOLDER_ACTION_TYPES.DELETE_FOLDER]({ commit }: ActionParams, { folder }: { folder: Folder}) {
/**
this.getByFolderId(folderId).forEach(function (feed) {
promises.push(self.reversiblyDelete(feed.id, false, true));
});
this.updateUnreadCache();
*/
- axios.delete(folderUrl + '/' + folder.id).then(() => commit(FOLDER_MUTATION_TYPES.DELETE_FOLDER, folder))
+ await axios.delete(folderUrl + '/' + folder.id)
+ commit(FOLDER_MUTATION_TYPES.DELETE_FOLDER, folder)
},
// loadFolder({commit}) {
// console.log('loading folders')
diff --git a/src/store/index.ts b/src/store/index.ts
index 277bbfc2a..1a6dfc1c9 100644
--- a/src/store/index.ts
+++ b/src/store/index.ts
@@ -13,12 +13,12 @@ export const ACTIONS = {
...FOLDER_ACTION_TYPES,
}
-export type ActionParams = { commit: any };
+type Func = (name: string, value: unknown) => void;
+export type ActionParams = { commit: Func };
export type AppState = {
feeds: Feed[];
folders: Folder[];
- items: any[];
}
export default {
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)
})
})
})