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'
|
|
|
|
|
|
|
|
config.mocks["$t"] = () => {}
|
|
|
|
|
|
|
|
const localVue = createLocalVue()
|
|
|
|
localVue.use(Vuex)
|
|
|
|
localVue.use(Element)
|
|
|
|
|
|
|
|
// jest.mock('@/api/reports')
|
|
|
|
|
|
|
|
describe('Reports', () => {
|
|
|
|
let store
|
|
|
|
|
|
|
|
beforeEach(() => {
|
|
|
|
store = new Vuex.Store(cloneDeep(storeConfig))
|
|
|
|
})
|
|
|
|
|
|
|
|
it('initially fetches reports', async (done) => {
|
|
|
|
const wrapper = mount(Reports, {
|
|
|
|
store,
|
|
|
|
localVue
|
|
|
|
})
|
|
|
|
|
|
|
|
await wrapper.vm.$nextTick()
|
|
|
|
const initialReports = store.state.reports.fetchedReports.length
|
|
|
|
expect(initialReports).toEqual(3)
|
|
|
|
done()
|
|
|
|
})
|
2019-04-03 15:42:44 +00:00
|
|
|
|
|
|
|
it('shows notes', () => {
|
|
|
|
const wrapper = mount(Reports, {
|
|
|
|
store,
|
|
|
|
localVue
|
|
|
|
})
|
|
|
|
|
|
|
|
const note = wrapper.find('.el-collapse-item__content')
|
|
|
|
expect(note.isVisible()).toBe(false)
|
|
|
|
|
|
|
|
const button = wrapper.find('.el-collapse-item__header')
|
|
|
|
button.trigger('click')
|
|
|
|
expect(note.isVisible()).toBe(true)
|
|
|
|
|
|
|
|
button.trigger('click')
|
|
|
|
expect(note.isVisible()).toBe(false)
|
|
|
|
})
|
2019-04-03 18:34:05 +00:00
|
|
|
|
|
|
|
it('creates a note', () => {
|
|
|
|
const wrapper = mount(Reports, {
|
|
|
|
store,
|
|
|
|
localVue
|
|
|
|
})
|
|
|
|
const noteTextArea = wrapper.find('textarea')
|
|
|
|
const notes = store.state.reports.fetchedReports[0].notes
|
|
|
|
|
|
|
|
expect(noteTextArea.isVisible()).toBe(false)
|
|
|
|
|
|
|
|
wrapper.find('.el-button--default').trigger('click')
|
|
|
|
expect(noteTextArea.isVisible()).toBe(true)
|
|
|
|
expect(notes.length).toBe(2)
|
|
|
|
|
|
|
|
noteTextArea.setValue('new note')
|
|
|
|
wrapper.find('.submit-button').trigger('click')
|
|
|
|
const updatedNotes = store.state.reports.fetchedReports[0].notes
|
|
|
|
expect(updatedNotes.length).toBe(3)
|
|
|
|
|
|
|
|
wrapper.find('.new-note .el-icon-close').trigger('click')
|
|
|
|
expect(noteTextArea.isVisible()).toBe(false)
|
|
|
|
})
|
2019-04-03 19:26:39 +00:00
|
|
|
|
2019-04-03 20:12:01 +00:00
|
|
|
it('deletes a note', () => {
|
2019-04-03 21:30:53 +00:00
|
|
|
store.dispatch('FetchReports')
|
|
|
|
expect(store.state.reports.fetchedReports[0].notes.length).toBe(3)
|
2019-04-03 20:12:01 +00:00
|
|
|
|
2019-04-03 21:30:53 +00:00
|
|
|
store.dispatch('DeleteNote', { reportId: '1', noteId: '2' })
|
|
|
|
expect(store.state.reports.fetchedReports[0].notes.length).toBe(2)
|
2019-04-03 20:12:01 +00:00
|
|
|
})
|
|
|
|
|
2019-04-03 19:26:39 +00:00
|
|
|
it('loads more reports on scroll', () => {
|
|
|
|
const wrapper = mount(Reports, {
|
|
|
|
store,
|
|
|
|
localVue
|
|
|
|
})
|
|
|
|
expect(store.state.reports.fetchedReports.length).toEqual(3)
|
|
|
|
|
|
|
|
window.dispatchEvent(new CustomEvent('scroll', { detail: 2000 }))
|
|
|
|
expect(store.state.reports.fetchedReports.length).toEqual(6)
|
|
|
|
})
|
2019-04-03 15:29:33 +00:00
|
|
|
})
|