Skip to content
Snippets Groups Projects
Commit f15d6b21 authored by Dominik Seeger's avatar Dominik Seeger Committed by robinwilliam.hundt
Browse files

added tests for DataExport component

parent c535b6b0
No related branches found
No related tags found
1 merge request!128Merge improve testing
import Vuex from 'vuex'
import { mount, createLocalVue } from '@vue/test-utils'
import DataExport from '@/components/export/DataExport.vue'
import sinon from 'sinon'
import chai from 'chai'
import VueRouter from 'vue-router'
import * as api from '@/api'
chai.should()
let localVue = createLocalVue()
localVue.use(Vuex)
localVue.use(VueRouter)
let router = new VueRouter()
// @ts-ignore
global.requestAnimationFrame = cb => cb()
describe('DataExport Component Unit Tests', () => {
let store: any = null
let consoleTemp = {
warn: console.warn,
error: console.error
}
// for creating test data
let students = [{
Matrikel: 1000000,
Name: 'test',
Username: 'test',
Sum: 100,
Exam: 'test',
Password: 'test',
Scores: { type: 'test', score: 100 }
}]
before(function () {
console.warn = function () {}
console.error = function () {}
})
after(function () {
console.warn = consoleTemp.warn
console.error = consoleTemp.error
})
beforeEach(() => {
store = new Vuex.Store({
state: {}
})
})
afterEach(() => {
sinon.restore()
})
it('should download CSV when selected', () => {
let wrapper = mount(DataExport, { localVue: localVue, store })
wrapper.vm.$data.exportType = 'CSV'
let spy = sinon.spy()
// @ts-ignore
sinon.replace(wrapper.vm, 'jsonToCSV', spy)
// @ts-ignore
sinon.replace(wrapper.vm, 'createDownloadPopup', sinon.spy())
// @ts-ignore
wrapper.vm.optionalConvertAndCreatePopup(students)
spy.called.should.equal(true)
})
it('should download JSON when selected', () => {
let wrapper = mount(DataExport, { localVue: localVue, store })
wrapper.vm.$data.exportType = 'JSON'
let spy = sinon.spy()
// @ts-ignore
sinon.replace(wrapper.vm, 'jsonToCSV', spy)
// @ts-ignore
sinon.replace(wrapper.vm, 'createDownloadPopup', sinon.spy())
// @ts-ignore
wrapper.vm.optionalConvertAndCreatePopup(students)
spy.called.should.equal(false)
})
it('should download obfuscated data when no mapping was selected', async () => {
let wrapper = mount(DataExport, { localVue: localVue, store })
let stub = sinon.stub().returns(Promise.resolve({ data: students }))
let spy = sinon.spy()
// @ts-ignore replace ax.post because of fetch in getExportFile
sinon.replace(api.default, 'post', stub)
// @ts-ignore
sinon.replace(wrapper.vm, 'optionalConvertAndCreatePopup', spy)
// @ts-ignore
await wrapper.vm.getExportFile('data')
spy.called.should.equal(true)
spy.calledWithExactly(students).should.equal(true)
})
it('should download deobfuscated data when no mapping was selected', async () => {
})
})
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment