1
0
mirror of https://github.com/h3poteto/whalebird-desktop synced 2025-02-03 18:57:43 +01:00
2019-03-19 09:07:13 +09:00

134 lines
2.9 KiB
JavaScript

import Mastodon from 'megalodon'
import { createLocalVue } from '@vue/test-utils'
import Vuex from 'vuex'
import Home from '~/src/renderer/store/TimelineSpace/Contents/Home'
jest.genMockFromModule('megalodon')
jest.mock('megalodon')
let state = () => {
return {
lazyLoading: false,
heading: true,
timeline: [],
unreadTimeline: [],
filter: '',
showReblogs: true,
showReplies: true
}
}
const initStore = () => {
return {
namespaced: true,
state: state(),
actions: Home.actions,
mutations: Home.mutations
}
}
const timelineState = {
namespaced: true,
state: {
account: {
accessToken: 'token',
baseURL: 'http://localhost'
}
}
}
describe('Home', () => {
let store
let localVue
beforeEach(() => {
localVue = createLocalVue()
localVue.use(Vuex)
store = new Vuex.Store({
modules: {
Home: initStore(),
TimelineSpace: timelineState
}
})
Mastodon.mockClear()
})
describe('fetchTimeline', () => {
it('should be updated', async () => {
const mockClient = {
get: () => {
return new Promise((resolve, reject) => {
resolve({
data: [
{ id: 1 },
{ id: 2 }
]
})
})
}
}
Mastodon.mockImplementation(() => mockClient)
const statuses = await store.dispatch('Home/fetchTimeline')
expect(statuses).toEqual([
{ id: 1 },
{ id: 2 }
])
expect(store.state.Home.timeline).toEqual([
{ id: 1 },
{ id: 2 }
])
})
})
describe('lazyFetchTimeline', () => {
describe('last is null', () => {
it('should not be updated', async () => {
const result = await store.dispatch('Home/lazyFetchTimeline', null)
expect(result).toEqual(null)
})
})
describe('success', () => {
beforeAll(() => {
state = () => {
return {
lazyLoading: false,
heading: true,
timeline: [
{ id: 3 },
{ id: 4 }
],
unreadTimeline: [],
filter: '',
showReblogs: true,
showReplies: true
}
}
})
it('should be updated', async () => {
const mockClient = {
get: () => {
return new Promise((resolve, reject) => {
resolve({
data: [
{ id: 19 },
{ id: 18 }
]
})
})
}
}
Mastodon.mockImplementation(() => mockClient)
await store.dispatch('Home/lazyFetchTimeline', { id: 20 })
expect(store.state.Home.lazyLoading).toEqual(false)
expect(store.state.Home.timeline).toEqual([
{ id: 3 },
{ id: 4 },
{ id: 19 },
{ id: 18 }
])
})
})
})
})