diff options
author | Devlin Junker <devlin.junker@gmail.com> | 2022-12-03 15:40:06 -0800 |
---|---|---|
committer | Benjamin Brahmer <info@b-brahmer.de> | 2022-12-06 14:57:20 +0100 |
commit | 2c32ea05f0a0f266e36075e702ee293d7834bf62 (patch) | |
tree | 8cf87a4a051af892f76213182471df09de7674e9 | |
parent | 4899be32e3f6065297f95e0ccc42e97efbec545b (diff) |
start on state/store tests
Signed-off-by: Devlin Junker <devlin.junker@gmail.com>
-rw-r--r-- | .eslintrc.js | 8 | ||||
-rw-r--r-- | package-lock.json | 14 | ||||
-rw-r--r-- | package.json | 4 | ||||
-rw-r--r-- | src/components/AddFeed.vue | 4 | ||||
-rw-r--r-- | src/components/Explore.vue | 2 | ||||
-rw-r--r-- | src/components/Sidebar.vue | 16 | ||||
-rw-r--r-- | src/store/feed.ts | 19 | ||||
-rw-r--r-- | src/store/folder.ts | 19 | ||||
-rw-r--r-- | tests/javascript/unit/components/Explore.spec.ts | 1 | ||||
-rw-r--r-- | tests/javascript/unit/components/Sidebar.spec.ts | 4 | ||||
-rw-r--r-- | tests/javascript/unit/setup.spec.ts (renamed from tests/javascript/unit/setup.ts) | 4 | ||||
-rw-r--r-- | tests/javascript/unit/store/feed.spec.ts | 28 | ||||
-rw-r--r-- | tests/javascript/unit/store/folder.spec.ts | 44 |
13 files changed, 119 insertions, 48 deletions
diff --git a/.eslintrc.js b/.eslintrc.js index 6f719bc0e..33eef5695 100644 --- a/.eslintrc.js +++ b/.eslintrc.js @@ -35,4 +35,12 @@ module.exports = { }, }, }, + overrides: [ + { + files: ['*spec.ts'], + rules: { + '@typescript-eslint/no-explicit-any': 'off', + }, + }, + ], } diff --git a/package-lock.json b/package-lock.json index 44f4c681c..9279f9e1d 100644 --- a/package-lock.json +++ b/package-lock.json @@ -82,7 +82,7 @@ "vue-color": "^2.8.1", "vue-eslint-parser": "^9.0.2", "vue-jest": "^3.0.7", - "vue-loader": "^15.9.8", + "vue-loader": "^15.10.1", "vue-material-design-icons": "^5.1.2", "vue-multiselect": "^2.1.6", "vue-template-compiler": "^2.6.14", @@ -15661,9 +15661,9 @@ } }, "node_modules/vue-loader": { - "version": "15.10.0", - "resolved": "https://registry.npmjs.org/vue-loader/-/vue-loader-15.10.0.tgz", - "integrity": "sha512-VU6tuO8eKajrFeBzMssFUP9SvakEeeSi1BxdTH5o3+1yUyrldp8IERkSdXlMI2t4kxF2sqYUDsQY+WJBxzBmZg==", + "version": "15.10.1", + "resolved": "https://registry.npmjs.org/vue-loader/-/vue-loader-15.10.1.tgz", + "integrity": "sha512-SaPHK1A01VrNthlix6h1hq4uJu7S/z0kdLUb6klubo738NeQoLbS6V9/d8Pv19tU0XdQKju3D1HSKuI8wJ5wMA==", "dev": true, "dependencies": { "@vue/component-compiler-utils": "^3.1.0", @@ -27998,9 +27998,9 @@ } }, "vue-loader": { - "version": "15.10.0", - "resolved": "https://registry.npmjs.org/vue-loader/-/vue-loader-15.10.0.tgz", - "integrity": "sha512-VU6tuO8eKajrFeBzMssFUP9SvakEeeSi1BxdTH5o3+1yUyrldp8IERkSdXlMI2t4kxF2sqYUDsQY+WJBxzBmZg==", + "version": "15.10.1", + "resolved": "https://registry.npmjs.org/vue-loader/-/vue-loader-15.10.1.tgz", + "integrity": "sha512-SaPHK1A01VrNthlix6h1hq4uJu7S/z0kdLUb6klubo738NeQoLbS6V9/d8Pv19tU0XdQKju3D1HSKuI8wJ5wMA==", "dev": true, "requires": { "@vue/component-compiler-utils": "^3.1.0", diff --git a/package.json b/package.json index 85b941019..b4aa4643c 100644 --- a/package.json +++ b/package.json @@ -118,7 +118,7 @@ "vue-color": "^2.8.1", "vue-eslint-parser": "^9.0.2", "vue-jest": "^3.0.7", - "vue-loader": "^15.9.8", + "vue-loader": "^15.10.1", "vue-material-design-icons": "^5.1.2", "vue-multiselect": "^2.1.6", "vue-template-compiler": "^2.6.14", @@ -151,7 +151,7 @@ "jest-serializer-vue" ], "setupFilesAfterEnv": [ - "./tests/javascript/unit/setup.ts" + "./tests/javascript/unit/setup.spec.ts" ], "coverageDirectory": "./coverage/", "collectCoverage": false, diff --git a/src/components/AddFeed.vue b/src/components/AddFeed.vue index 462ab77d1..af5d75937 100644 --- a/src/components/AddFeed.vue +++ b/src/components/AddFeed.vue @@ -115,7 +115,7 @@ import NcMultiselect from '@nextcloud/vue/dist/Components/NcMultiselect.js' import { Folder } from '../types/Folder' import { Feed } from '../types/Feed' -import { ACTIONS, AppState } from '../store' +import { ACTIONS } from '../store' type AddFeedState = { folder: Folder; @@ -142,7 +142,7 @@ export default Vue.extend({ }, data: (): AddFeedState => { return { - folder: { name: '' } as any, + folder: { name: '' } as Folder, autoDiscover: true, createNewFolder: false, withBasicAuth: false, diff --git a/src/components/Explore.vue b/src/components/Explore.vue index e909101f7..067dd61b3 100644 --- a/src/components/Explore.vue +++ b/src/components/Explore.vue @@ -50,7 +50,7 @@ const ExploreComponent = Vue.extend({ }, data: () => { const exploreSites: ExploreSite[] = [] - const feed: Feed = {} as any + const feed: Feed = {} as Feed const showAddFeed = false return { diff --git a/src/components/Sidebar.vue b/src/components/Sidebar.vue index cd88369ee..c51ea16ac 100644 --- a/src/components/Sidebar.vue +++ b/src/components/Sidebar.vue @@ -129,7 +129,7 @@ <script lang="ts"> -import Vuex from 'vuex' +import { mapState } from 'vuex' import Vue from 'vue' import NcAppNavigation from '@nextcloud/vue/dist/Components/NcAppNavigation.js' @@ -148,9 +148,10 @@ import AddFeed from './AddFeed.vue' import { Folder } from '../types/Folder' import { Feed } from '../types/Feed' -const SideBarState: any = { - topLevelNav(localState: any, state: AppState): any[] { - let navItems: any[] = state.feeds.filter((feed: Feed) => { +const SideBarState = { + // eslint-disable-next-line @typescript-eslint/no-explicit-any + topLevelNav(localState: any, state: AppState): (Feed | Folder)[] { + let navItems: (Feed | Folder)[] = state.feeds.filter((feed: Feed) => { return feed.folderId === undefined || feed.folderId === null }) navItems = navItems.concat(state.folders) @@ -177,11 +178,11 @@ export default Vue.extend({ } }, computed: { - ...Vuex.mapState(['feeds', 'folders']), - ...Vuex.mapState(SideBarState), + ...mapState(['feeds', 'folders']), + ...mapState(SideBarState), }, created() { - // TODO: ? + // TODO: init? }, methods: { newFolder(value: string) { @@ -191,7 +192,6 @@ export default Vue.extend({ }, deleteFolder(folder: Folder) { this.$store.dispatch(ACTIONS.DELETE_FOLDER, { folder }) - // TODO: Reload }, showShowAddFeed() { this.showAddFeed = true diff --git a/src/store/feed.ts b/src/store/feed.ts index a74b7c9e4..e39907f38 100644 --- a/src/store/feed.ts +++ b/src/store/feed.ts @@ -4,15 +4,15 @@ import { generateUrl } from '@nextcloud/router' import { ActionParams, AppState } from '../store' import { Feed } from '../types/Feed' -export const FEED_MUTATION_TYPES = { - SET_FEEDS: 'SET_FEEDS', -} - export const FEED_ACTION_TYPES = { ADD_FEED: 'ADD_FEED', FETCH_FEEDS: 'FETCH_FEEDS', } +export const FEED_MUTATION_TYPES = { + SET_FEEDS: 'SET_FEEDS', +} + const state = { feeds: [], } @@ -33,8 +33,7 @@ export const actions = { commit(FEED_MUTATION_TYPES.SET_FEEDS, feeds.data.feeds) }, - [FEED_ACTION_TYPES.ADD_FEED]({ commit }: ActionParams, { feedReq }: { feedReq: { url: string; folder?: { id: number } } }) { - console.log(feedReq) + async [FEED_ACTION_TYPES.ADD_FEED]({ commit }: ActionParams, { feedReq }: { feedReq: { url: string; folder?: { id: number } } }) { let url = feedReq.url.trim() if (!url.startsWith('http')) { url = 'https://' + url @@ -51,22 +50,22 @@ export const actions = { folderId: feedReq.folder?.id || 0, title: undefined, unreadCount: 0, - autoDiscover: undefined, // TODO + autoDiscover: undefined, // TODO: autodiscover? } // this.add(feed); // this.updateFolderCache(); - axios.post(feedUrl, { + await axios.post(feedUrl, { url: feed.url, parentFolderId: feed.folderId, title: null, user: null, password: null, fullDiscover: feed.autoDiscover, - }).then(() => { - commit('addFeed', feed) }) + + commit('addFeed', feed) }, } diff --git a/src/store/folder.ts b/src/store/folder.ts index 3a46e755b..70a05c4ed 100644 --- a/src/store/folder.ts +++ b/src/store/folder.ts @@ -4,17 +4,17 @@ import { generateUrl } from '@nextcloud/router' import { AppState, ActionParams } from '../store' import { Folder } from '../types/Folder' -export const FOLDER_MUTATION_TYPES = { - SET_FOLDERS: 'SET_FOLDERS', - DELETE_FOLDER: 'DELETE_FOLDER', -} - export const FOLDER_ACTION_TYPES = { FETCH_FOLDERS: 'FETCH_FOLDERS', ADD_FOLDERS: 'ADD_FOLDER', DELETE_FOLDER: 'DELETE_FOLDER', } +export const FOLDER_MUTATION_TYPES = { + SET_FOLDERS: 'SET_FOLDERS', + DELETE_FOLDER: 'DELETE_FOLDER', +} + const state = { folders: [], } @@ -35,11 +35,9 @@ export const actions = { commit(FOLDER_MUTATION_TYPES.SET_FOLDERS, folders.data.folders) }, - [FOLDER_ACTION_TYPES.ADD_FOLDERS]({ commit }: ActionParams, { folder }: { folder: Folder}) { - console.log(folder) - axios.post(folderUrl, { folderName: folder.name }).then( - response => commit(FOLDER_MUTATION_TYPES.SET_FOLDERS, response.data.folders), - ) + async [FOLDER_ACTION_TYPES.ADD_FOLDERS]({ commit }: ActionParams, { folder }: { folder: Folder}) { + 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}) { /** @@ -65,7 +63,6 @@ export const actions = { export const mutations = { [FOLDER_MUTATION_TYPES.SET_FOLDERS](state: AppState, folders: Folder[]) { - console.log(folders) folders.forEach(it => { it.feedCount = 0 it.feeds = [] diff --git a/tests/javascript/unit/components/Explore.spec.ts b/tests/javascript/unit/components/Explore.spec.ts index f0a945821..1a952fac0 100644 --- a/tests/javascript/unit/components/Explore.spec.ts +++ b/tests/javascript/unit/components/Explore.spec.ts @@ -9,7 +9,6 @@ jest.mock('@nextcloud/axios'); describe('Explore.vue', () => { 'use strict' - const localVue = createLocalVue() it('should initialize without showing AddFeed Component', () => { diff --git a/tests/javascript/unit/components/Sidebar.spec.ts b/tests/javascript/unit/components/Sidebar.spec.ts index 16affbb3d..e70db7197 100644 --- a/tests/javascript/unit/components/Sidebar.spec.ts +++ b/tests/javascript/unit/components/Sidebar.spec.ts @@ -134,8 +134,4 @@ describe('Sidebar.vue', () => { afterEach(() => { jest.clearAllMocks() }) - - afterEach(() => { - jest.clearAllMocks() - }) }) diff --git a/tests/javascript/unit/setup.ts b/tests/javascript/unit/setup.spec.ts index 380436f8c..510e53baa 100644 --- a/tests/javascript/unit/setup.ts +++ b/tests/javascript/unit/setup.spec.ts @@ -10,11 +10,11 @@ config.mocks.$t = function(_app: any, string: any) { } config.mocks.t = config.mocks.$t -config.mocks.$n = function(app: any, singular: any, plural: any, count: any) { +config.mocks.$n = function(app: any, singular: any) { return singular } config.mocks.n = config.mocks.$n afterAll(() => { - // TODO: ? + // TODO: afterAll tests? }) diff --git a/tests/javascript/unit/store/feed.spec.ts b/tests/javascript/unit/store/feed.spec.ts new file mode 100644 index 000000000..1a4fb0fee --- /dev/null +++ b/tests/javascript/unit/store/feed.spec.ts @@ -0,0 +1,28 @@ +import axios from '@nextcloud/axios' +import { Feed } from '../../../../src/types/Feed' +import { AppState } from '../../../../src/store' +import { FEED_ACTION_TYPES, FEED_MUTATION_TYPES, mutations, actions } from '../../../../src/store/feed' + +jest.mock('@nextcloud/axios') + +describe('feed.ts', () => { + 'use strict' + + describe('actions', () => { + it('ADD_FEED', 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() + }) + }) + + describe('mutations', () => { + it('', () => { + const state = { feeds: [] as Feed[] } as AppState + const feeds = [] as Feed[] + mutations[FEED_MUTATION_TYPES.SET_FEEDS](state, feeds) + }) + }) +}) diff --git a/tests/javascript/unit/store/folder.spec.ts b/tests/javascript/unit/store/folder.spec.ts new file mode 100644 index 000000000..1d7feafb0 --- /dev/null +++ b/tests/javascript/unit/store/folder.spec.ts @@ -0,0 +1,44 @@ +import axios from '@nextcloud/axios' +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') + +describe('folder.ts', () => { + 'use strict' + + describe('actions', () => { + it('FETCH_FOLDERS', () => { + // TODO + }) + + it('ADD_FOLDERS should send POST and then commit the folders returned', async () => { + (axios.post as any).mockResolvedValue({ data: { folders: [] } }) + + const folder = {} as Folder + const commit = jest.fn() + await actions[FOLDER_ACTION_TYPES.ADD_FOLDERS]({ commit }, { folder }) + expect(axios.post).toBeCalled() + expect(commit).toBeCalled() + }) + + it('DELETE_FOLDER', () => { + // TODO + }) + }) + + describe('mutations', () => { + it('SET_FOLDERS', () => { + const state = { folders: [] as Folder[] } as AppState + const folders = [] as Folder[] + (mutations[FOLDER_MUTATION_TYPES.SET_FOLDERS] as any)(state, folders) + + expect(state.folders.length).toEqual(0) + }) + + it('DELETE_FOLDER', () => { + // TODO + }) + }) +}) |