2019-04-03 15:29:33 +00:00
|
|
|
import Vuex from 'vuex'
|
|
|
|
import { mount, createLocalVue, config } from '@vue/test-utils'
|
|
|
|
import Element from 'element-ui'
|
|
|
|
import Reports from '@/views/reports/index'
|
|
|
|
import storeConfig from './store.conf'
|
|
|
|
import { cloneDeep } from 'lodash'
|
2019-05-25 12:20:13 +00:00
|
|
|
import flushPromises from 'flush-promises'
|
2019-04-03 15:29:33 +00:00
|
|
|
|
|
|
|
config.mocks["$t"] = () => {}
|
2019-05-25 12:20:13 +00:00
|
|
|
config.stubs['reports-filter'] = '<div />'
|
|
|
|
config.stubs['timeline-item'] = '<div />'
|
2019-04-03 15:29:33 +00:00
|
|
|
|
|
|
|
const localVue = createLocalVue()
|
|
|
|
localVue.use(Vuex)
|
|
|
|
localVue.use(Element)
|
|
|
|
|
2019-05-25 12:20:13 +00:00
|
|
|
jest.mock('@/api/reports')
|
2019-04-03 15:29:33 +00:00
|
|
|
|
|
|
|
describe('Reports', () => {
|
|
|
|
let store
|
|
|
|
|
|
|
|
beforeEach(() => {
|
|
|
|
store = new Vuex.Store(cloneDeep(storeConfig))
|
|
|
|
})
|
|
|
|
|
|
|
|
it('initially fetches reports', async (done) => {
|
|
|
|
const wrapper = mount(Reports, {
|
|
|
|
store,
|
|
|
|
localVue
|
|
|
|
})
|
|
|
|
|
2019-05-25 12:20:13 +00:00
|
|
|
await flushPromises()
|
2019-04-03 15:29:33 +00:00
|
|
|
const initialReports = store.state.reports.fetchedReports.length
|
2019-05-25 12:20:13 +00:00
|
|
|
expect(initialReports).toEqual(5)
|
2019-04-03 15:29:33 +00:00
|
|
|
done()
|
|
|
|
})
|
2019-04-03 15:42:44 +00:00
|
|
|
|
2019-05-25 12:20:13 +00:00
|
|
|
it('loads more reports on scroll', async (done) => {
|
2019-04-03 15:42:44 +00:00
|
|
|
const wrapper = mount(Reports, {
|
|
|
|
store,
|
|
|
|
localVue
|
|
|
|
})
|
|
|
|
|
2019-05-25 12:20:13 +00:00
|
|
|
await flushPromises()
|
|
|
|
expect(store.state.reports.fetchedReports.length).toEqual(5)
|
2019-04-03 19:26:39 +00:00
|
|
|
|
|
|
|
window.dispatchEvent(new CustomEvent('scroll', { detail: 2000 }))
|
2019-05-25 12:20:13 +00:00
|
|
|
await flushPromises()
|
|
|
|
expect(store.state.reports.fetchedReports.length).toEqual(7)
|
|
|
|
done()
|
2019-04-03 19:26:39 +00:00
|
|
|
})
|
2019-04-03 15:29:33 +00:00
|
|
|
})
|