refs #843 Add integration spec for mentions

This commit is contained in:
AkiraFukushima 2019-03-19 09:07:13 +09:00
parent 89ddb4c4d3
commit dfd705b9d3
3 changed files with 180 additions and 2 deletions

View File

@ -63,6 +63,13 @@ const PublicStore = {
}
}
const MentionStore = {
namespaced: true,
actions: {
fetchMentions: jest.fn()
}
}
const contentsStore = {
namespaced: true,
modules: {
@ -70,7 +77,8 @@ const contentsStore = {
Notifications: notificationStore,
DirectMessages: DMStore,
Local: LocalStore,
Public: PublicStore
Public: PublicStore,
Mentions: MentionStore
}
}

View File

@ -6,7 +6,7 @@ import Home from '~/src/renderer/store/TimelineSpace/Contents/Home'
jest.genMockFromModule('megalodon')
jest.mock('megalodon')
const state = () => {
let state = () => {
return {
lazyLoading: false,
heading: true,
@ -89,6 +89,22 @@ describe('Home', () => {
})
})
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: () => {
@ -106,6 +122,8 @@ describe('Home', () => {
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 }
])

View File

@ -0,0 +1,152 @@
import Mastodon from 'megalodon'
import { createLocalVue } from '@vue/test-utils'
import Vuex from 'vuex'
import Mentions from '~/src/renderer/store/TimelineSpace/Contents/Mentions'
jest.genMockFromModule('megalodon')
jest.mock('megalodon')
let state = () => {
return {
lazyLoading: false,
heading: true,
mentions: [],
unreadMentions: [],
filter: ''
}
}
const initStore =() => {
return {
namespaced: true,
state: state(),
actions: Mentions.actions,
mutations: Mentions.mutations
}
}
const timelineState = {
namespaced: true,
state: {
account: {
accessToken: 'token',
baseURL: 'http://localhost'
}
}
}
describe('Mentions', () => {
let store
let localVue
beforeEach(() => {
localVue = createLocalVue()
localVue.use(Vuex)
store = new Vuex.Store({
modules: {
Mentions: initStore(),
TimelineSpace: timelineState
}
})
Mastodon.mockClear()
})
describe('fetchMentions', () => {
it('should be updated', async () => {
const mockClient = {
get: () => {
return new Promise((resolve, reject) => {
resolve({
data: [
{ id: 1, type: 'mention' },
{ id: 2, type: 'favourite' },
{ id: 3, type: 'reblog' },
{ id: 4, type: 'follow' }
]
})
})
}
}
Mastodon.mockImplementation(() => mockClient)
const mentions = await store.dispatch('Mentions/fetchMentions')
expect(store.state.Mentions.mentions).toEqual([
{ id: 1, type: 'mention' },
{ id: 2, type: 'favourite' },
{ id: 3, type: 'reblog' },
{ id: 4, type: 'follow' }
])
})
})
describe('lazyFetchMentions', () => {
describe('last is null', () => {
it('should not be updated', async () => {
const result = await store.dispatch('Mentions/lazyFetchMentions', null)
expect(result).toEqual(null)
})
})
describe('loading', () => {
beforeAll(() => {
state = () => {
return {
lazyLoading: true,
heading: true,
mentions: [],
unreadMentions: [],
filter: ''
}
}
})
it('should not be updated', async () => {
const result = await store.dispatch('Mentions/lazyFetchMentions', {})
expect(result).toEqual(null)
})
})
describe('success', () => {
beforeAll(() => {
state = () => {
return {
lazyLoading: false,
heading: true,
mentions: [
{ id: 1, type: 'mention' },
{ id: 2, type: 'favourite' },
{ id: 3, type: 'reblog' },
{ id: 4, type: 'follow' }
],
unreadMentions: [],
filter: ''
}
}
})
it('should be updated', async () => {
const mockClient = {
get: () => {
return new Promise((resolve, reject) => {
resolve({
data: [
{ id: 5, type: 'mention' },
{ id: 6, type: 'favourite' }
]
})
})
}
}
Mastodon.mockImplementation(() => mockClient)
const mentions = await store.dispatch('Mentions/lazyFetchMentions', { id: 1 })
expect(store.state.Mentions.mentions).toEqual([
{ id: 1, type: 'mention' },
{ id: 2, type: 'favourite' },
{ id: 3, type: 'reblog' },
{ id: 4, type: 'follow' },
{ id: 5, type: 'mention' },
{ id: 6, type: 'favourite' }
])
expect(store.state.Mentions.lazyLoading).toEqual(false)
})
})
})
})