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 = {
accounts: [],
changing: false,
hide: false
const state = () => {
return {
accounts: [],
changing: false,
hide: false
}
}
const initState = {
namespaced: true,
state: state,
actions: GlobalHeader.actions,
mutations: GlobalHeader.mutations
const initStore = () => {
return {
namespaced: true,
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,23 +8,27 @@ import DefaultFonts from '@/utils/fonts'
import Appearance from '@/store/Preferences/Appearance'
import { ipcMain } from '~/spec/mock/electron'
const state = {
appearance: {
theme: Theme.Light.key,
fontSize: 14,
displayNameStyle: DisplayStyle.DisplayNameAndUsername.value,
timeFormat: TimeFormat.Absolute.value,
customThemeColor: LightTheme,
font: DefaultFonts[0]
},
fonts: []
const state = () => {
return {
appearance: {
theme: Theme.Light.key,
fontSize: 14,
displayNameStyle: DisplayStyle.DisplayNameAndUsername.value,
timeFormat: TimeFormat.Absolute.value,
customThemeColor: LightTheme,
font: DefaultFonts[0]
},
fonts: []
}
}
const Preferences = {
namespaced: true,
state: state,
actions: Appearance.actions,
mutations: Appearance.mutations
const initStore = () => {
return {
namespaced: true,
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 = {
language: {
language: DefaultLanguage.en.key
const state = () => {
return {
language: {
language: DefaultLanguage.en.key
}
}
}
const initState = {
namespaced: true,
state: state,
actions: Language.actions,
mutations: Language.mutations
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,22 +3,26 @@ import Vuex from 'vuex'
import { ipcMain } from '~/spec/mock/electron'
import Notification from '@/store/Preferences/Notification'
const state = {
notification: {
notify: {
reply: true,
reblog: true,
favourite: true,
follow: true
const state = () => {
return {
notification: {
notify: {
reply: true,
reblog: true,
favourite: true,
follow: true
}
}
}
}
const initState = {
namespaced: true,
state: state,
actions: Notification.actions,
mutations: Notification.mutations
const initStore = () => {
return {
namespaced: true,
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,21 +6,25 @@ import Home from '~/src/renderer/store/TimelineSpace/Contents/Home'
jest.genMockFromModule('megalodon')
jest.mock('megalodon')
const state = {
lazyLoading: false,
heading: true,
timeline: [],
unreadTimeline: [],
filter: '',
showReblogs: true,
showReplies: true
const state = () => {
return {
lazyLoading: false,
heading: true,
timeline: [],
unreadTimeline: [],
filter: '',
showReblogs: true,
showReplies: true
}
}
const initState = {
namespaced: true,
state: state,
actions: Home.actions,
mutations: Home.mutations
const initStore = () => {
return {
namespaced: true,
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 = {
title: 'Home',
reload: false
const state = () => {
return {
title: 'Home',
reload: false
}
}
const initState = {
namespaced: true,
state: state,
actions: HeaderMenu.actions,
mutations: HeaderMenu.mutations
const initStore = () => {
return {
namespaced: true,
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,56 +4,59 @@ import i18n from '~/src/config/i18n'
import router from '@/router'
import Jump from '~/src/renderer/store/TimelineSpace/Modals/Jump'
const state = {
modalOpen: true,
channel: '',
defaultChannelList: [
{
const state = () => {
return {
modalOpen: true,
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'),
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 initState = {
namespaced: true,
state: state,
actions: Jump.actions,
mutations: Jump.mutations
const initStore = () => {
return {
namespaced: true,
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,22 +7,26 @@ import SideMenu from '~/src/renderer/store/TimelineSpace/SideMenu'
jest.genMockFromModule('megalodon')
jest.mock('megalodon')
const state = {
unreadHomeTimeline: false,
unreadNotifications: false,
unreadLocalTimeline: false,
unreadDirectMessagesTimeline: false,
unreadPublicTimeline: false,
lists: [],
tags: [],
collapse: false
const state = () => {
return {
unreadHomeTimeline: false,
unreadNotifications: false,
unreadLocalTimeline: false,
unreadDirectMessagesTimeline: false,
unreadPublicTimeline: false,
lists: [],
tags: [],
collapse: false
}
}
const initState = {
namespaced: true,
state: state,
actions: SideMenu.actions,
mutations: SideMenu.mutations
const initStore = () => {
return {
namespaced: true,
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()