Whalebird-desktop-client-ma.../spec/renderer/integration/store/TimelineSpace/HeaderMenu.spec.ts

90 lines
1.7 KiB
TypeScript
Raw Normal View History

2020-03-15 09:48:02 +01:00
import { Response, Entity } from 'megalodon'
import { createLocalVue } from '@vue/test-utils'
import Vuex from 'vuex'
import HeaderMenu, { HeaderMenuState } from '~/src/renderer/store/TimelineSpace/HeaderMenu'
2020-03-15 09:48:02 +01:00
const list: Entity.List = {
2019-05-27 16:04:53 +02:00
id: '1',
title: 'example'
}
2020-03-15 09:48:02 +01:00
const mockClient = {
getList: (_listID: string) => {
return new Promise<Response<Entity.List>>(resolve => {
const res: Response<Entity.List> = {
data: list,
status: 200,
statusText: 'OK',
headers: {}
}
resolve(res)
})
}
}
jest.mock('megalodon', () => ({
2020-09-13 10:24:36 +02:00
...jest.requireActual<object>('megalodon'),
2020-03-15 09:48:02 +01:00
default: jest.fn(() => mockClient),
__esModule: true
}))
const state = (): HeaderMenuState => {
return {
title: 'Home',
reload: false,
loading: false
}
}
const initStore = () => {
return {
namespaced: true,
state: state(),
actions: HeaderMenu.actions,
mutations: HeaderMenu.mutations
}
}
const timelineState = {
namespaced: true,
state: {
account: {
accessToken: 'token',
baseURL: 'http://localhost'
2020-03-15 09:48:02 +01:00
},
sns: 'mastodon'
}
}
const appState = {
namespaced: true,
state: {
proxyConfiguration: false
}
}
describe('HeaderMenu', () => {
let store
let localVue
beforeEach(() => {
localVue = createLocalVue()
localVue.use(Vuex)
store = new Vuex.Store({
modules: {
HeaderMenu: initStore(),
TimelineSpace: timelineState,
App: appState
}
})
})
describe('fetchLists', () => {
it('should be updated', async () => {
const l = await store.dispatch('HeaderMenu/fetchList', list.id)
expect(l).toEqual(list)
expect(store.state.HeaderMenu.title).toEqual(`#${list.title}`)
})
})
})