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

View File

@ -8,23 +8,27 @@ import DefaultFonts from '@/utils/fonts'
import Appearance from '@/store/Preferences/Appearance' import Appearance from '@/store/Preferences/Appearance'
import { ipcMain } from '~/spec/mock/electron' import { ipcMain } from '~/spec/mock/electron'
const state = { const state = () => {
appearance: { return {
theme: Theme.Light.key, appearance: {
fontSize: 14, theme: Theme.Light.key,
displayNameStyle: DisplayStyle.DisplayNameAndUsername.value, fontSize: 14,
timeFormat: TimeFormat.Absolute.value, displayNameStyle: DisplayStyle.DisplayNameAndUsername.value,
customThemeColor: LightTheme, timeFormat: TimeFormat.Absolute.value,
font: DefaultFonts[0] customThemeColor: LightTheme,
}, font: DefaultFonts[0]
fonts: [] },
fonts: []
}
} }
const Preferences = { const initStore = () => {
namespaced: true, return {
state: state, namespaced: true,
actions: Appearance.actions, state: state(),
mutations: Appearance.mutations actions: Appearance.actions,
mutations: Appearance.mutations
}
} }
const App = { const App = {
@ -43,8 +47,8 @@ describe('Preferences/Appearance', () => {
localVue.use(Vuex) localVue.use(Vuex)
store = new Vuex.Store({ store = new Vuex.Store({
modules: { modules: {
Preferences, Preferences: initStore(),
App App: App
} }
}) })
ipcMain.once('update-preferences', (event, config) => { 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 Language from '@/store/Preferences/Language'
import DefaultLanguage from '~/src/constants/language' import DefaultLanguage from '~/src/constants/language'
const state = { const state = () => {
language: { return {
language: DefaultLanguage.en.key language: {
language: DefaultLanguage.en.key
}
} }
} }
const initState = { const initStore = () => {
namespaced: true, return {
state: state, namespaced: true,
actions: Language.actions, state: state,
mutations: Language.mutations actions: Language.actions,
mutations: Language.mutations
}
} }
describe('Preferences/Language', () => { describe('Preferences/Language', () => {
@ -26,7 +30,7 @@ describe('Preferences/Language', () => {
localVue.use(Vuex) localVue.use(Vuex)
store = new Vuex.Store({ store = new Vuex.Store({
modules: { modules: {
Language: initState Language: initStore()
} }
}) })
}) })

View File

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

View File

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

View File

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

View File

@ -4,56 +4,59 @@ import i18n from '~/src/config/i18n'
import router from '@/router' import router from '@/router'
import Jump from '~/src/renderer/store/TimelineSpace/Modals/Jump' import Jump from '~/src/renderer/store/TimelineSpace/Modals/Jump'
const state = { const state = () => {
modalOpen: true, return {
channel: '', modalOpen: true,
defaultChannelList: [ channel: '',
{ defaultChannelList: [
{
name: i18n.t('side_menu.home'),
path: 'home'
},
{
name: i18n.t('side_menu.notification'),
path: 'notifications'
},
{
name: i18n.t('side_menu.favourite'),
path: 'favourites'
},
{
name: i18n.t('side_menu.local'),
path: 'local'
},
{
name: i18n.t('side_menu.public'),
path: 'public'
},
{
name: i18n.t('side_menu.hashtag'),
path: 'hashtag'
},
{
name: i18n.t('side_menu.search'),
path: 'search'
},
{
name: i18n.t('side_menu.direct'),
path: 'direct-messages'
}
],
listChannelList: [],
tagChannelList: [],
selectedChannel: {
name: i18n.t('side_menu.home'), name: i18n.t('side_menu.home'),
path: 'home' path: 'home'
},
{
name: i18n.t('side_menu.notification'),
path: 'notifications'
},
{
name: i18n.t('side_menu.favourite'),
path: 'favourites'
},
{
name: i18n.t('side_menu.local'),
path: 'local'
},
{
name: i18n.t('side_menu.public'),
path: 'public'
},
{
name: i18n.t('side_menu.hashtag'),
path: 'hashtag'
},
{
name: i18n.t('side_menu.search'),
path: 'search'
},
{
name: i18n.t('side_menu.direct'),
path: 'direct-messages'
} }
],
listChannelList: [],
tagChannelList: [],
selectedChannel: {
name: i18n.t('side_menu.home'),
path: 'home'
} }
} }
const initStore = () => {
const initState = { return {
namespaced: true, namespaced: true,
state: state, state: state(),
actions: Jump.actions, actions: Jump.actions,
mutations: Jump.mutations mutations: Jump.mutations
}
} }
const timelineState = { const timelineState = {
@ -74,7 +77,7 @@ describe('Jump', () => {
localVue.use(Vuex) localVue.use(Vuex)
store = new Vuex.Store({ store = new Vuex.Store({
modules: { modules: {
Jump: initState, Jump: initStore(),
TimelineSpace: timelineState TimelineSpace: timelineState
} }
}) })

View File

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