2022-04-25 15:33:49 +02:00
|
|
|
import { RootState } from '@/store'
|
2020-03-15 09:48:02 +01:00
|
|
|
import { Response, Entity } from 'megalodon'
|
2022-04-25 15:33:49 +02:00
|
|
|
import { createStore, Store } from 'vuex'
|
2019-04-08 18:09:12 +02:00
|
|
|
import HeaderMenu, { HeaderMenuState } from '~/src/renderer/store/TimelineSpace/HeaderMenu'
|
2019-01-02 11:26:54 +01:00
|
|
|
|
2020-03-15 09:48:02 +01:00
|
|
|
const list: Entity.List = {
|
2019-05-27 16:04:53 +02:00
|
|
|
id: '1',
|
2019-04-03 15:15:46 +02:00
|
|
|
title: 'example'
|
2019-04-02 16:24:06 +02:00
|
|
|
}
|
|
|
|
|
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
|
|
|
|
}))
|
|
|
|
|
2019-04-08 18:09:12 +02:00
|
|
|
const state = (): HeaderMenuState => {
|
2019-02-16 11:41:58 +01:00
|
|
|
return {
|
|
|
|
title: 'Home',
|
2019-05-07 15:40:46 +02:00
|
|
|
reload: false,
|
|
|
|
loading: false
|
2019-02-16 11:41:58 +01:00
|
|
|
}
|
2019-01-02 11:26:54 +01:00
|
|
|
}
|
|
|
|
|
2019-02-16 11:41:58 +01:00
|
|
|
const initStore = () => {
|
|
|
|
return {
|
|
|
|
namespaced: true,
|
|
|
|
state: state(),
|
|
|
|
actions: HeaderMenu.actions,
|
|
|
|
mutations: HeaderMenu.mutations
|
|
|
|
}
|
2019-01-02 11:26:54 +01:00
|
|
|
}
|
|
|
|
|
2022-04-25 15:33:49 +02:00
|
|
|
const timelineStore = () => ({
|
2019-01-02 11:26:54 +01:00
|
|
|
namespaced: true,
|
|
|
|
state: {
|
|
|
|
account: {
|
2023-01-01 17:12:53 +01:00
|
|
|
accessToken: 'token'
|
2020-03-15 09:48:02 +01:00
|
|
|
},
|
2023-01-01 17:12:53 +01:00
|
|
|
server: {
|
|
|
|
sns: 'mastodon',
|
|
|
|
baseURL: 'http://localhost'
|
|
|
|
}
|
2022-04-25 15:33:49 +02:00
|
|
|
},
|
|
|
|
modules: {
|
|
|
|
HeaderMenu: initStore()
|
2019-01-02 11:26:54 +01:00
|
|
|
}
|
2022-04-25 15:33:49 +02:00
|
|
|
})
|
2019-01-02 11:26:54 +01:00
|
|
|
|
2019-10-27 10:37:43 +01:00
|
|
|
const appState = {
|
|
|
|
namespaced: true,
|
|
|
|
state: {
|
|
|
|
proxyConfiguration: false
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-01-02 11:26:54 +01:00
|
|
|
describe('HeaderMenu', () => {
|
2022-04-25 15:33:49 +02:00
|
|
|
let store: Store<RootState>
|
2019-01-02 11:26:54 +01:00
|
|
|
|
|
|
|
beforeEach(() => {
|
2022-04-25 15:33:49 +02:00
|
|
|
store = createStore({
|
2019-01-02 11:26:54 +01:00
|
|
|
modules: {
|
2022-04-25 15:33:49 +02:00
|
|
|
TimelineSpace: timelineStore(),
|
2019-10-27 10:37:43 +01:00
|
|
|
App: appState
|
2019-01-02 11:26:54 +01:00
|
|
|
}
|
|
|
|
})
|
|
|
|
})
|
|
|
|
|
|
|
|
describe('fetchLists', () => {
|
|
|
|
it('should be updated', async () => {
|
2022-04-25 15:33:49 +02:00
|
|
|
const l = await store.dispatch('TimelineSpace/HeaderMenu/fetchList', list.id)
|
2019-04-02 16:24:06 +02:00
|
|
|
expect(l).toEqual(list)
|
2022-04-25 15:33:49 +02:00
|
|
|
expect(store.state.TimelineSpace.HeaderMenu.title).toEqual(`#${list.title}`)
|
2019-01-02 11:26:54 +01:00
|
|
|
})
|
|
|
|
})
|
|
|
|
})
|