2020-05-11 18:20:52 +00:00
|
|
|
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"] = () => {}
|
2020-09-18 22:46:37 +00:00
|
|
|
config.stubs.transition = false
|
2020-05-11 18:20:52 +00:00
|
|
|
|
|
|
|
const localVue = createLocalVue()
|
|
|
|
localVue.use(Vuex)
|
|
|
|
localVue.use(Element)
|
|
|
|
|
|
|
|
jest.mock('@/api/app')
|
|
|
|
jest.mock('@/api/nodeInfo')
|
2020-10-12 20:39:12 +00:00
|
|
|
jest.mock('@/api/peers')
|
|
|
|
jest.mock('@/api/settings')
|
|
|
|
jest.mock('@/api/status')
|
2020-05-11 18:20:52 +00:00
|
|
|
|
|
|
|
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()
|
|
|
|
})
|
2020-05-12 19:43:15 +00:00
|
|
|
|
|
|
|
it('fetches statuses from selected instance and updates the count', async (done) => {
|
|
|
|
const wrapper = mount(Statuses, {
|
|
|
|
store,
|
|
|
|
localVue
|
|
|
|
})
|
|
|
|
await flushPromises()
|
|
|
|
|
|
|
|
store.dispatch('HandleFilterChange', 'heaven.com')
|
|
|
|
wrapper.vm.handleFilterChange()
|
|
|
|
await flushPromises()
|
|
|
|
const statusVisibilityCount = store.state.status.statusVisibility
|
|
|
|
|
|
|
|
expect(statusVisibilityCount.direct).toEqual(1)
|
|
|
|
expect(statusVisibilityCount.private).toEqual(2)
|
|
|
|
expect(statusVisibilityCount.public).toEqual(3)
|
|
|
|
expect(statusVisibilityCount.unlisted).toEqual(0)
|
|
|
|
expect(store.state.status.fetchedStatuses.length).toEqual(2)
|
|
|
|
done()
|
|
|
|
})
|
2020-05-13 17:34:47 +00:00
|
|
|
|
|
|
|
it('handles status select', async (done) => {
|
|
|
|
const wrapper = mount(Statuses, {
|
|
|
|
store: store,
|
|
|
|
localVue
|
|
|
|
})
|
|
|
|
await flushPromises()
|
|
|
|
|
|
|
|
store.dispatch('HandleFilterChange', 'heaven.com')
|
|
|
|
wrapper.vm.handleFilterChange()
|
|
|
|
await flushPromises()
|
|
|
|
wrapper.find('.status-checkbox input').setChecked()
|
|
|
|
await flushPromises()
|
|
|
|
|
|
|
|
expect(wrapper.vm.selectedUsers.length).toEqual(1)
|
2020-06-06 19:33:08 +00:00
|
|
|
expect(wrapper.vm.selectedUsers[0].nickname).toBe('sky')
|
2020-05-13 17:34:47 +00:00
|
|
|
done()
|
|
|
|
})
|
|
|
|
|
|
|
|
it('clear state after component was destroyed', async (done) => {
|
|
|
|
const wrapper = mount(Statuses, {
|
|
|
|
store: store,
|
|
|
|
localVue
|
|
|
|
})
|
|
|
|
await flushPromises()
|
|
|
|
|
|
|
|
store.dispatch('HandleFilterChange', 'heaven.com')
|
|
|
|
wrapper.vm.handleFilterChange()
|
|
|
|
await flushPromises()
|
|
|
|
wrapper.find('.status-checkbox input').setChecked()
|
|
|
|
await flushPromises()
|
|
|
|
|
|
|
|
expect(wrapper.vm.selectedUsers.length).toEqual(1)
|
|
|
|
expect(store.state.status.statusesByInstance.selectedInstance).toBe('heaven.com')
|
|
|
|
expect(store.state.status.fetchedStatuses.length).toEqual(2)
|
|
|
|
wrapper.destroy()
|
|
|
|
|
|
|
|
expect(wrapper.vm.selectedUsers.length).toEqual(0)
|
|
|
|
expect(store.state.status.statusesByInstance.selectedInstance).toBe('')
|
|
|
|
expect(store.state.status.fetchedStatuses.length).toEqual(0)
|
|
|
|
done()
|
|
|
|
})
|
2020-05-11 18:20:52 +00:00
|
|
|
})
|