refs #209 Fix state definition in integration spec

This commit is contained in:
AkiraFukushima 2019-02-16 19:41:58 +09:00
parent d3574a4619
commit f95fa11aa7
8 changed files with 166 additions and 137 deletions

View File

@ -3,17 +3,21 @@ import Vuex from 'vuex'
import { ipcMain } from '~/spec/mock/electron'
import GlobalHeader from '~/src/renderer/store/GlobalHeader'
const state = {
const state = () => {
return {
accounts: [],
changing: false,
hide: false
}
}
const initState = {
const initStore = () => {
return {
namespaced: true,
state: state,
state: state(),
actions: GlobalHeader.actions,
mutations: GlobalHeader.mutations
}
}
const routerState = {
@ -34,7 +38,7 @@ describe('GlobalHeader', () => {
localVue.use(Vuex)
store = new Vuex.Store({
modules: {
GlobalHeader: initState,
GlobalHeader: initStore(),
route: routerState
}
})
@ -90,8 +94,8 @@ describe('GlobalHeader', () => {
})
})
it('should be switched', async () => {
await store.dispatch('GlobalHeader/switchHide', true)
expect(store.state.GlobalHeader.hide).toEqual(true)
const hide = await store.dispatch('GlobalHeader/switchHide', true)
expect(hide).toEqual(true)
})
})
})

View File

@ -8,7 +8,8 @@ import DefaultFonts from '@/utils/fonts'
import Appearance from '@/store/Preferences/Appearance'
import { ipcMain } from '~/spec/mock/electron'
const state = {
const state = () => {
return {
appearance: {
theme: Theme.Light.key,
fontSize: 14,
@ -18,13 +19,16 @@ const state = {
font: DefaultFonts[0]
},
fonts: []
}
}
const Preferences = {
const initStore = () => {
return {
namespaced: true,
state: state,
state: state(),
actions: Appearance.actions,
mutations: Appearance.mutations
}
}
const App = {
@ -43,8 +47,8 @@ describe('Preferences/Appearance', () => {
localVue.use(Vuex)
store = new Vuex.Store({
modules: {
Preferences,
App
Preferences: initStore(),
App: App
}
})
ipcMain.once('update-preferences', (event, config) => {

View File

@ -4,17 +4,21 @@ import { ipcMain } from '~/spec/mock/electron'
import Language from '@/store/Preferences/Language'
import DefaultLanguage from '~/src/constants/language'
const state = {
const state = () => {
return {
language: {
language: DefaultLanguage.en.key
}
}
}
const initState = {
const initStore = () => {
return {
namespaced: true,
state: state,
actions: Language.actions,
mutations: Language.mutations
}
}
describe('Preferences/Language', () => {
@ -26,7 +30,7 @@ describe('Preferences/Language', () => {
localVue.use(Vuex)
store = new Vuex.Store({
modules: {
Language: initState
Language: initStore()
}
})
})

View File

@ -3,7 +3,8 @@ import Vuex from 'vuex'
import { ipcMain } from '~/spec/mock/electron'
import Notification from '@/store/Preferences/Notification'
const state = {
const state = () => {
return {
notification: {
notify: {
reply: true,
@ -12,13 +13,16 @@ const state = {
follow: true
}
}
}
}
const initState = {
const initStore = () => {
return {
namespaced: true,
state: state,
state: state(),
actions: Notification.actions,
mutations: Notification.mutations
}
}
const App = {
@ -37,7 +41,7 @@ describe('Preferences/Notification', () => {
localVue.use(Vuex)
store = new Vuex.Store({
modules: {
Notification: initState,
Notification: initStore(),
App: App
}
})

View File

@ -6,7 +6,8 @@ import Home from '~/src/renderer/store/TimelineSpace/Contents/Home'
jest.genMockFromModule('megalodon')
jest.mock('megalodon')
const state = {
const state = () => {
return {
lazyLoading: false,
heading: true,
timeline: [],
@ -14,13 +15,16 @@ const state = {
filter: '',
showReblogs: true,
showReplies: true
}
}
const initState = {
const initStore = () => {
return {
namespaced: true,
state: state,
state: state(),
actions: Home.actions,
mutations: Home.mutations
}
}
const timelineState = {
@ -42,7 +46,7 @@ describe('Home', () => {
localVue.use(Vuex)
store = new Vuex.Store({
modules: {
Home: initState,
Home: initStore(),
TimelineSpace: timelineState
}
})
@ -102,8 +106,6 @@ describe('Home', () => {
await store.dispatch('Home/lazyFetchTimeline', { id: 20 })
expect(store.state.Home.lazyLoading).toEqual(false)
expect(store.state.Home.timeline).toEqual([
{ id: 1 },
{ id: 2 },
{ id: 19 },
{ id: 18 }
])

View File

@ -6,16 +6,20 @@ import HeaderMenu from '~/src/renderer/store/TimelineSpace/HeaderMenu'
jest.genMockFromModule('megalodon')
jest.mock('megalodon')
const state = {
const state = () => {
return {
title: 'Home',
reload: false
}
}
const initState = {
const initStore = () => {
return {
namespaced: true,
state: state,
state: state(),
actions: HeaderMenu.actions,
mutations: HeaderMenu.mutations
}
}
const timelineState = {
@ -37,7 +41,7 @@ describe('HeaderMenu', () => {
localVue.use(Vuex)
store = new Vuex.Store({
modules: {
HeaderMenu: initState,
HeaderMenu: initStore(),
TimelineSpace: timelineState
}
})

View File

@ -4,7 +4,8 @@ import i18n from '~/src/config/i18n'
import router from '@/router'
import Jump from '~/src/renderer/store/TimelineSpace/Modals/Jump'
const state = {
const state = () => {
return {
modalOpen: true,
channel: '',
defaultChannelList: [
@ -47,13 +48,15 @@ const state = {
name: i18n.t('side_menu.home'),
path: 'home'
}
}
}
const initState = {
const initStore = () => {
return {
namespaced: true,
state: state,
state: state(),
actions: Jump.actions,
mutations: Jump.mutations
}
}
const timelineState = {
@ -74,7 +77,7 @@ describe('Jump', () => {
localVue.use(Vuex)
store = new Vuex.Store({
modules: {
Jump: initState,
Jump: initStore(),
TimelineSpace: timelineState
}
})

View File

@ -7,7 +7,8 @@ import SideMenu from '~/src/renderer/store/TimelineSpace/SideMenu'
jest.genMockFromModule('megalodon')
jest.mock('megalodon')
const state = {
const state = () => {
return {
unreadHomeTimeline: false,
unreadNotifications: false,
unreadLocalTimeline: false,
@ -16,13 +17,16 @@ const state = {
lists: [],
tags: [],
collapse: false
}
}
const initState = {
const initStore = () => {
return {
namespaced: true,
state: state,
state: state(),
actions: SideMenu.actions,
mutations: SideMenu.mutations
}
}
describe('SideMenu', () => {
@ -34,7 +38,7 @@ describe('SideMenu', () => {
localVue.use(Vuex)
store = new Vuex.Store({
modules: {
SideMenu: initState
SideMenu: initStore()
}
})
Mastodon.mockClear()