refs #209 Add integration/unit tests for TimelineSpace/HeaderMenu

This commit is contained in:
AkiraFukushima 2019-01-02 19:26:54 +09:00
parent 0411459f48
commit 71e36ec814
2 changed files with 88 additions and 0 deletions

View File

@ -0,0 +1,69 @@
import Mastodon from 'megalodon'
import { createLocalVue } from '@vue/test-utils'
import Vuex from 'vuex'
import HeaderMenu from '~/src/renderer/store/TimelineSpace/HeaderMenu'
jest.genMockFromModule('megalodon')
jest.mock('megalodon')
const state = {
title: 'Home',
reload: false
}
const initState = {
namespaced: true,
state: state,
actions: HeaderMenu.actions,
mutations: HeaderMenu.mutations
}
const timelineState = {
namespaced: true,
state: {
account: {
accessToken: 'token',
baseURL: 'http://localhost'
}
}
}
describe('HeaderMenu', () => {
let store
let localVue
beforeEach(() => {
localVue = createLocalVue()
localVue.use(Vuex)
store = new Vuex.Store({
modules: {
HeaderMenu: initState,
TimelineSpace: timelineState
}
})
Mastodon.mockClear()
})
describe('fetchLists', () => {
it('should be updated', async () => {
const mockClient = {
get: () => {
return new Promise((resolve, reject) => {
resolve({
data: {
title: 'list1'
}
})
})
}
}
Mastodon.mockImplementation(() => mockClient)
const list = await store.dispatch('HeaderMenu/fetchList', 1)
expect(list).toEqual({
title: 'list1'
})
expect(store.state.HeaderMenu.title).toEqual('#list1')
})
})
})

View File

@ -0,0 +1,19 @@
import HeaderMenu from '@/store/TimelineSpace/HeaderMenu'
describe('TimelineSpace/HeaderMenu', () => {
describe('mutations', () => {
let state
beforeEach(() => {
state = {
title: 'Home',
reload: false
}
})
describe('changeReload', () => {
it('should be changed', () => {
HeaderMenu.mutations.changeReload(state, true)
expect(state.reload).toEqual(true)
})
})
})
})