diff --git a/frontend/tests/unit/components/DataExport.spec.ts b/frontend/tests/unit/components/DataExport.spec.ts index f41c8bf8a6769f5be275503cef28c96a2c72e772..617670fbc848841e2dbb7a1e9b0489f6f881f49e 100644 --- a/frontend/tests/unit/components/DataExport.spec.ts +++ b/frontend/tests/unit/components/DataExport.spec.ts @@ -94,4 +94,18 @@ describe('DataExport Component Unit Tests', () => { await wrapper.vm.getExportFile('data') spy.calledWithExactly(testUtils.studentExports).should.equal(true) }) + it('should correctly apply the student-map file', () => { + let wrapper = mount(DataExport, { localVue: localVue, store }) + let mapStub = sinon.stub().returns(testUtils.studentMap) + let spy = sinon.spy() + // @ts-ignore + sinon.replaceGetter(wrapper.vm, 'studentMap', mapStub) + // @ts-ignore + sinon.replaceGetter(wrapper.vm, 'mapFileLoaded', sinon.stub().returns(true)) + // @ts-ignore + sinon.replace(wrapper.vm, 'optionalConvertAndCreatePopup', spy) + // @ts-ignore + wrapper.vm.getMappedExportFile(testUtils.studentExportsObfuscated) + spy.firstCall.args[0][0].Matrikel.should.equal(testUtils.studentMap['username'].matrikelNo) + }) }) diff --git a/frontend/tests/unit/components/InstanceExport.spec.ts b/frontend/tests/unit/components/InstanceExport.spec.ts new file mode 100644 index 0000000000000000000000000000000000000000..9f9a6de914e7e9c577de56f37110481ac1959e59 --- /dev/null +++ b/frontend/tests/unit/components/InstanceExport.spec.ts @@ -0,0 +1,61 @@ +import Vuex from 'vuex' +import { mount, createLocalVue, createWrapper } from '@vue/test-utils' +import InstanceExport from '@/components/export/InstanceExport.vue' +import sinon from 'sinon' +import chai from 'chai' +import VueRouter from 'vue-router' +import testUtils from '@/../tests/utils/testUtils' + +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('InstanceExport Component Unit Tests', () => { + let store: any = null + let consoleTemp = { + warn: console.warn, + error: console.error + } + + 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 correctly apply the student-map file', () => { + let wrp = mount(InstanceExport, { localVue: localVue, store }) + let mapStub = sinon.stub().returns(testUtils.studentMap) + let spy = sinon.spy() + // @ts-ignore + sinon.replaceGetter(wrp.vm, 'studentMap', mapStub) + // @ts-ignore + sinon.replaceGetter(wrp.vm, 'mapFileLoaded', sinon.stub().returns(true)) + // @ts-ignore + sinon.replace(wrp.vm, 'optionalConvertAndCreatePopup', spy) + // @ts-ignore + wrp.vm.getMappedExportFile(testUtils.instanceExportsObfuscated) + spy.firstCall.args[0].students[0].matrikelNo.should.equal(testUtils.studentMap['username'].matrikelNo) + }) +}) \ No newline at end of file diff --git a/frontend/tests/utils/testUtils.ts b/frontend/tests/utils/testUtils.ts index 599cb750c818286d2d087ec554b6456d16dcec9e..7009a2553f4328570dc061f36f43c890135234e4 100644 --- a/frontend/tests/utils/testUtils.ts +++ b/frontend/tests/utils/testUtils.ts @@ -19,12 +19,27 @@ export default { Password: 'pwd', Scores: [{ type: 'test01', score: 100 }] }], + studentExportsObfuscated: <StudentExportItem[]> [{ + Matrikel: 'username', + Name: 'name', + Username: 'username', + Sum: 100, + Exam: 'exam', + Password: 'pwd', + Scores: [{ type: 'test01', score: 100 }] + }], instanceExports: <InstanceExportData> { students: [{ - name: 'test', + name: 'name', matrikelNo: '1000000' }] }, + instanceExportsObfuscated: <InstanceExportData> { + students: [{ + name: 'name', + matrikelNo: 'username' + }] + }, fakeFile: <File> { lastModified: 1, name: 'Grady testUtils fake file', @@ -33,8 +48,8 @@ export default { type: 'fake file' }, studentMap: { - '1000000': { - matrikelNo: '1000000', name: 'test' + 'username': { + matrikelNo: '1000000', name: 'name' } - } + }, }