2019-04-02 23:24:06 +09:00
|
|
|
import { Response, List } from 'megalodon'
|
|
|
|
import mockedMegalodon from '~/spec/mock/megalodon'
|
2019-01-02 19:26:54 +09:00
|
|
|
import { createLocalVue } from '@vue/test-utils'
|
|
|
|
import Vuex from 'vuex'
|
2019-04-09 01:09:12 +09:00
|
|
|
import HeaderMenu, { HeaderMenuState } from '~/src/renderer/store/TimelineSpace/HeaderMenu'
|
2019-01-02 19:26:54 +09:00
|
|
|
|
|
|
|
jest.mock('megalodon')
|
|
|
|
|
2019-04-02 23:24:06 +09:00
|
|
|
const list: List = {
|
2019-05-27 23:04:53 +09:00
|
|
|
id: '1',
|
2019-04-03 22:15:46 +09:00
|
|
|
title: 'example'
|
2019-04-02 23:24:06 +09:00
|
|
|
}
|
|
|
|
|
2019-04-09 01:09:12 +09:00
|
|
|
const state = (): HeaderMenuState => {
|
2019-02-16 19:41:58 +09:00
|
|
|
return {
|
|
|
|
title: 'Home',
|
2019-05-07 22:40:46 +09:00
|
|
|
reload: false,
|
|
|
|
loading: false
|
2019-02-16 19:41:58 +09:00
|
|
|
}
|
2019-01-02 19:26:54 +09:00
|
|
|
}
|
|
|
|
|
2019-02-16 19:41:58 +09:00
|
|
|
const initStore = () => {
|
|
|
|
return {
|
|
|
|
namespaced: true,
|
|
|
|
state: state(),
|
|
|
|
actions: HeaderMenu.actions,
|
|
|
|
mutations: HeaderMenu.mutations
|
|
|
|
}
|
2019-01-02 19:26:54 +09:00
|
|
|
}
|
|
|
|
|
|
|
|
const timelineState = {
|
|
|
|
namespaced: true,
|
|
|
|
state: {
|
|
|
|
account: {
|
|
|
|
accessToken: 'token',
|
|
|
|
baseURL: 'http://localhost'
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-10-27 18:37:43 +09:00
|
|
|
const appState = {
|
|
|
|
namespaced: true,
|
|
|
|
state: {
|
|
|
|
proxyConfiguration: false
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-01-02 19:26:54 +09:00
|
|
|
describe('HeaderMenu', () => {
|
|
|
|
let store
|
|
|
|
let localVue
|
|
|
|
|
|
|
|
beforeEach(() => {
|
|
|
|
localVue = createLocalVue()
|
|
|
|
localVue.use(Vuex)
|
|
|
|
store = new Vuex.Store({
|
|
|
|
modules: {
|
2019-02-16 19:41:58 +09:00
|
|
|
HeaderMenu: initStore(),
|
2019-10-27 18:37:43 +09:00
|
|
|
TimelineSpace: timelineState,
|
|
|
|
App: appState
|
2019-01-02 19:26:54 +09:00
|
|
|
}
|
|
|
|
})
|
2019-04-02 23:24:06 +09:00
|
|
|
mockedMegalodon.mockClear()
|
2019-01-02 19:26:54 +09:00
|
|
|
})
|
|
|
|
|
|
|
|
describe('fetchLists', () => {
|
|
|
|
it('should be updated', async () => {
|
|
|
|
const mockClient = {
|
2019-04-02 23:24:06 +09:00
|
|
|
get: (_path: string, _params: object) => {
|
2019-04-03 22:15:46 +09:00
|
|
|
return new Promise<Response<List>>(resolve => {
|
2019-04-02 23:24:06 +09:00
|
|
|
const res: Response<List> = {
|
|
|
|
data: list,
|
|
|
|
status: 200,
|
2019-04-03 22:15:46 +09:00
|
|
|
statusText: 'OK',
|
2019-04-02 23:24:06 +09:00
|
|
|
headers: {}
|
|
|
|
}
|
|
|
|
resolve(res)
|
2019-01-02 19:26:54 +09:00
|
|
|
})
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-04-02 23:24:06 +09:00
|
|
|
mockedMegalodon.mockImplementation(() => mockClient)
|
|
|
|
const l = await store.dispatch('HeaderMenu/fetchList', list.id)
|
|
|
|
expect(l).toEqual(list)
|
|
|
|
expect(store.state.HeaderMenu.title).toEqual(`#${list.title}`)
|
2019-01-02 19:26:54 +09:00
|
|
|
})
|
|
|
|
})
|
|
|
|
})
|