forked from AkkomaGang/admin-fe
Add test for running on mounted actions in Statuses
This commit is contained in:
parent
744872d64a
commit
6ec7d89a91
4 changed files with 70 additions and 0 deletions
4
src/api/__mocks__/peers.js
Normal file
4
src/api/__mocks__/peers.js
Normal file
|
@ -0,0 +1,4 @@
|
||||||
|
export async function fetchPeers(authHost, token) {
|
||||||
|
const data = ['lain.com', 'heaven.com']
|
||||||
|
return Promise.resolve({ data })
|
||||||
|
}
|
|
@ -5,3 +5,11 @@ export async function changeStatusScope(id, sensitive, visibility, authHost, tok
|
||||||
export async function deleteStatus(id, authHost, token) {
|
export async function deleteStatus(id, authHost, token) {
|
||||||
return Promise.resolve()
|
return Promise.resolve()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export async function fetchStatusesCount(instance, authHost, token) {
|
||||||
|
const data = {
|
||||||
|
'status_visibility':
|
||||||
|
{ 'direct': 4, 'private': 10, 'public': 4, 'unlisted': 10 }
|
||||||
|
}
|
||||||
|
return Promise.resolve({ data })
|
||||||
|
}
|
||||||
|
|
41
test/views/statuses/index.test.js
Normal file
41
test/views/statuses/index.test.js
Normal file
|
@ -0,0 +1,41 @@
|
||||||
|
import Vuex from 'vuex'
|
||||||
|
import { mount, createLocalVue, config } from '@vue/test-utils'
|
||||||
|
import flushPromises from 'flush-promises'
|
||||||
|
import Element from 'element-ui'
|
||||||
|
import Statuses from '@/views/statuses/index'
|
||||||
|
import storeConfig from './store.conf'
|
||||||
|
import { cloneDeep } from 'lodash'
|
||||||
|
|
||||||
|
config.mocks["$t"] = () => {}
|
||||||
|
|
||||||
|
const localVue = createLocalVue()
|
||||||
|
localVue.use(Vuex)
|
||||||
|
localVue.use(Element)
|
||||||
|
|
||||||
|
jest.mock('@/api/app')
|
||||||
|
jest.mock('@/api/status')
|
||||||
|
jest.mock('@/api/peers')
|
||||||
|
jest.mock('@/api/nodeInfo')
|
||||||
|
|
||||||
|
describe('Statuses', () => {
|
||||||
|
let store
|
||||||
|
|
||||||
|
beforeEach(() => {
|
||||||
|
store = new Vuex.Store(cloneDeep(storeConfig))
|
||||||
|
})
|
||||||
|
|
||||||
|
it('fetches peers and statuses count', async (done) => {
|
||||||
|
mount(Statuses, {
|
||||||
|
store,
|
||||||
|
localVue
|
||||||
|
})
|
||||||
|
|
||||||
|
await flushPromises()
|
||||||
|
const statusVisibilityCount = store.state.status.statusVisibility
|
||||||
|
expect(statusVisibilityCount.direct).toEqual(4)
|
||||||
|
expect(statusVisibilityCount.private).toEqual(10)
|
||||||
|
expect(statusVisibilityCount.public).toEqual(4)
|
||||||
|
expect(statusVisibilityCount.unlisted).toEqual(10)
|
||||||
|
done()
|
||||||
|
})
|
||||||
|
})
|
17
test/views/statuses/store.conf.js
Normal file
17
test/views/statuses/store.conf.js
Normal file
|
@ -0,0 +1,17 @@
|
||||||
|
import app from '@/store/modules/app'
|
||||||
|
import peers from '@/store/modules/peers'
|
||||||
|
import user from '@/store/modules/user'
|
||||||
|
import settings from '@/store/modules/settings'
|
||||||
|
import status from '@/store/modules/status'
|
||||||
|
import getters from '@/store/getters'
|
||||||
|
|
||||||
|
export default {
|
||||||
|
modules: {
|
||||||
|
app,
|
||||||
|
peers,
|
||||||
|
settings,
|
||||||
|
status,
|
||||||
|
user
|
||||||
|
},
|
||||||
|
getters
|
||||||
|
}
|
Loading…
Reference in a new issue