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

changed to use testUtils / added a test

parent 06ccdacc
No related branches found
No related tags found
1 merge request!128Merge improve testing
...@@ -4,6 +4,7 @@ import DataExport from '@/components/export/DataExport.vue' ...@@ -4,6 +4,7 @@ import DataExport from '@/components/export/DataExport.vue'
import sinon from 'sinon' import sinon from 'sinon'
import chai from 'chai' import chai from 'chai'
import VueRouter from 'vue-router' import VueRouter from 'vue-router'
import testUtils from '@/../tests/utils/testUtils'
import * as api from '@/api' import * as api from '@/api'
chai.should() chai.should()
...@@ -23,17 +24,6 @@ describe('DataExport Component Unit Tests', () => { ...@@ -23,17 +24,6 @@ describe('DataExport Component Unit Tests', () => {
error: console.error 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 () { before(function () {
console.warn = function () {} console.warn = function () {}
console.error = function () {} console.error = function () {}
...@@ -63,7 +53,7 @@ describe('DataExport Component Unit Tests', () => { ...@@ -63,7 +53,7 @@ describe('DataExport Component Unit Tests', () => {
// @ts-ignore // @ts-ignore
sinon.replace(wrapper.vm, 'createDownloadPopup', sinon.spy()) sinon.replace(wrapper.vm, 'createDownloadPopup', sinon.spy())
// @ts-ignore // @ts-ignore
wrapper.vm.optionalConvertAndCreatePopup(students) wrapper.vm.optionalConvertAndCreatePopup(testUtils.studentExports)
spy.called.should.equal(true) spy.called.should.equal(true)
}) })
it('should download JSON when selected', () => { it('should download JSON when selected', () => {
...@@ -75,12 +65,12 @@ describe('DataExport Component Unit Tests', () => { ...@@ -75,12 +65,12 @@ describe('DataExport Component Unit Tests', () => {
// @ts-ignore // @ts-ignore
sinon.replace(wrapper.vm, 'createDownloadPopup', sinon.spy()) sinon.replace(wrapper.vm, 'createDownloadPopup', sinon.spy())
// @ts-ignore // @ts-ignore
wrapper.vm.optionalConvertAndCreatePopup(students) wrapper.vm.optionalConvertAndCreatePopup(testUtils.studentExports)
spy.called.should.equal(false) spy.called.should.equal(false)
}) })
it('should download obfuscated data when no mapping was selected', async () => { it('should download obfuscated data when no mapping was selected', async () => {
let wrapper = mount(DataExport, { localVue: localVue, store }) let wrapper = mount(DataExport, { localVue: localVue, store })
let stub = sinon.stub().returns(Promise.resolve({ data: students })) let stub = sinon.stub().returns(Promise.resolve({ data: testUtils.studentExports }))
let spy = sinon.spy() let spy = sinon.spy()
// @ts-ignore replace ax.post because of fetch in getExportFile // @ts-ignore replace ax.post because of fetch in getExportFile
sinon.replace(api.default, 'post', stub) sinon.replace(api.default, 'post', stub)
...@@ -88,10 +78,20 @@ describe('DataExport Component Unit Tests', () => { ...@@ -88,10 +78,20 @@ describe('DataExport Component Unit Tests', () => {
sinon.replace(wrapper.vm, 'optionalConvertAndCreatePopup', spy) sinon.replace(wrapper.vm, 'optionalConvertAndCreatePopup', spy)
// @ts-ignore // @ts-ignore
await wrapper.vm.getExportFile('data') await wrapper.vm.getExportFile('data')
spy.called.should.equal(true) spy.calledWithExactly(testUtils.studentExports).should.equal(true)
spy.calledWithExactly(students).should.equal(true)
}) })
it('should download deobfuscated data when no mapping was selected', async () => { it('should download deobfuscated data when mapping was selected', async () => {
let wrapper = mount(DataExport, { localVue: localVue, store })
let stub = sinon.stub().returns(Promise.resolve({ data: testUtils.studentExports }))
let spy = sinon.spy()
// @ts-ignore
wrapper.vm.mapFile = testUtils.fakeFile
// @ts-ignore replace ax.post because of fetch in getExportFile
sinon.replace(api.default, 'post', stub)
// @ts-ignore
sinon.replace(wrapper.vm, 'getMappedExportFile', spy)
// @ts-ignore
await wrapper.vm.getExportFile('data')
spy.calledWithExactly(testUtils.studentExports).should.equal(true)
}) })
}) })
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