diff options
author | Devlin Junker <devlin.junker@gmail.com> | 2022-11-28 23:52:31 -1000 |
---|---|---|
committer | Benjamin Brahmer <info@b-brahmer.de> | 2022-12-06 14:57:20 +0100 |
commit | 28ead9da95449ad220b137c98e6e19a62e83f184 (patch) | |
tree | 33cda9f1d9dae008073059d6ebbeb558c44469c1 /tests | |
parent | c0bc5ecd51f2a9538f30122554319fe47e0c4eaa (diff) |
modularize store files and fix unit tests
Signed-off-by: Devlin Junker <devlin.junker@gmail.com>
Diffstat (limited to 'tests')
-rw-r--r-- | tests/javascript/unit/components/AddFeed.spec.ts | 15 | ||||
-rw-r--r-- | tests/javascript/unit/components/Explore.spec.ts | 26 | ||||
-rw-r--r-- | tests/javascript/unit/components/Sidebar.spec.ts | 29 | ||||
-rw-r--r-- | tests/javascript/unit/setupStore.ts | 12 |
4 files changed, 56 insertions, 26 deletions
diff --git a/tests/javascript/unit/components/AddFeed.spec.ts b/tests/javascript/unit/components/AddFeed.spec.ts index a549ffb30..a426f2785 100644 --- a/tests/javascript/unit/components/AddFeed.spec.ts +++ b/tests/javascript/unit/components/AddFeed.spec.ts @@ -1,5 +1,4 @@ -import { shallowMount } from '@vue/test-utils' -import { store, localVue } from '../setupStore' +import { shallowMount, createLocalVue } from '@vue/test-utils' import AddFeed from 'Components/AddFeed.vue' @@ -7,7 +6,17 @@ describe('AddFeed.vue', () => { 'use strict' it('should initialize without showing createNewFolder', () => { - const wrapper = shallowMount(AddFeed, { localVue, store }) + const localVue = createLocalVue() + const wrapper = shallowMount(AddFeed, { + localVue, + mocks: { + $store: { + state: { + folders: [] + } + } + } + }) expect(wrapper.vm.$data.createNewFolder).toBeFalsy }); diff --git a/tests/javascript/unit/components/Explore.spec.ts b/tests/javascript/unit/components/Explore.spec.ts index fe547792e..3e24f2890 100644 --- a/tests/javascript/unit/components/Explore.spec.ts +++ b/tests/javascript/unit/components/Explore.spec.ts @@ -1,6 +1,5 @@ -import axios from '@nextcloud/axios'; -import { shallowMount } from '@vue/test-utils'; -import { store, localVue } from '../setupStore'; +import axios from '@nextcloud/axios' +import { shallowMount, createLocalVue } from '@vue/test-utils' import * as router from '@nextcloud/router'; @@ -9,11 +8,26 @@ import Explore from 'Components/Explore.vue'; jest.mock('@nextcloud/axios'); describe('Explore.vue', () => { - 'use strict'; + 'use strict' + const localVue = createLocalVue() + + it('should initialize without showing AddFeed Component', () => { - (axios as any).get.mockResolvedValue({ data: {} }); - (router as any).generateUrl = jest.fn().mockReturnValue(''); + (axios as any).get.mockResolvedValue({ data: { } }) + (router as any).generateUrl = jest.fn().mockReturnValue(''); + + const wrapper = shallowMount(Explore, { + localVue, + mocks: { + $store: { + state: { + feeds: [], + folders: [] + } + } + } + }) const wrapper = shallowMount(Explore, { localVue, store }); diff --git a/tests/javascript/unit/components/Sidebar.spec.ts b/tests/javascript/unit/components/Sidebar.spec.ts index 63b490f0e..5690aac08 100644 --- a/tests/javascript/unit/components/Sidebar.spec.ts +++ b/tests/javascript/unit/components/Sidebar.spec.ts @@ -1,5 +1,5 @@ -import { Wrapper, shallowMount } from '@vue/test-utils' -import { store, localVue } from '../setupStore' +import { ACTIONS } from '@/store'; +import { Wrapper, shallowMount, createLocalVue } from '@vue/test-utils' import AppSidebar from 'Components/Sidebar.vue' @@ -9,7 +9,18 @@ describe('Sidebar.vue', () => { let wrapper: Wrapper<AppSidebar>; beforeAll(() => { - wrapper = shallowMount(AppSidebar, { localVue, store }) + const localVue = createLocalVue() + wrapper = shallowMount(AppSidebar, { + localVue, + mocks: { + $store: { + state: { + feeds: [], + folders: [] + } + } + } + }) wrapper.vm.$store.dispatch = jest.fn(); }) @@ -20,14 +31,14 @@ describe('Sidebar.vue', () => { it('should dispatch message to store with folder name to create new folder', () => { (wrapper.vm as any).newFolder('abc') - expect(wrapper.vm.$store.dispatch).toHaveBeenCalledWith('addFolder', { folder: { name: 'abc'} }) + expect(wrapper.vm.$store.dispatch).toHaveBeenCalledWith(ACTIONS.ADD_FOLDERS, { folder: { name: 'abc'} }) }); it('should dispatch message to store with folder object on delete folder', () => { const folder = {}; (wrapper.vm as any).deleteFolder(folder) - expect(wrapper.vm.$store.dispatch).toHaveBeenCalledWith('deleteFolder', { folder }) + expect(wrapper.vm.$store.dispatch).toHaveBeenCalledWith(ACTIONS.DELETE_FOLDER, { folder }) }) it('should set showAddFeed to true', () => { @@ -43,4 +54,12 @@ describe('Sidebar.vue', () => { afterEach(() => { jest.clearAllMocks(); }); + + describe('SideBar State', () => { + // it('should return top level nav (folders and feeds without folders)', () => { + // const navItems = (wrapper.vm.$options?.computed?.topLevelNav as any)({ feeds: [], folders: [] }); + + // console.log(navItems) + // }) + }) }) diff --git a/tests/javascript/unit/setupStore.ts b/tests/javascript/unit/setupStore.ts deleted file mode 100644 index 074d591ef..000000000 --- a/tests/javascript/unit/setupStore.ts +++ /dev/null @@ -1,12 +0,0 @@ -// NOTE: This was copied from nextcloud/tasks repo -import { createLocalVue } from '@vue/test-utils' -import Vuex from 'vuex' - -const localVue = createLocalVue() -localVue.use(Vuex) - -const store = new Vuex.Store({ - modules: { - }, -}) -export { store, localVue } |