From 942203d173b6fab3f5c081d9e08bc338598b9ba9 Mon Sep 17 00:00:00 2001 From: Jakob Dieterle <jakob.dieterle@stud.uni-goettingen.de> Date: Tue, 14 Jan 2020 17:54:40 +0100 Subject: [PATCH 1/5] Removed option to export student scores in csv format. --- frontend/src/components/export/DataExport.vue | 9 +++------ frontend/src/components/mixins/exportMixin.ts | 15 +++++++++++---- frontend/tests/unit/mixins/exportMixin.spec.ts | 7 ++++++- functional_tests/test_export_modal.py | 4 ---- 4 files changed, 20 insertions(+), 15 deletions(-) diff --git a/frontend/src/components/export/DataExport.vue b/frontend/src/components/export/DataExport.vue index ec734f82..1ba556ba 100644 --- a/frontend/src/components/export/DataExport.vue +++ b/frontend/src/components/export/DataExport.vue @@ -46,11 +46,8 @@ xs3 offset-xs1 > - <v-select - v-model="exportType" - label="Export file format" - :items="availableExportTypes" - /> + <span>Export as <b>json</b> + </span> </v-flex> </v-layout> <v-card-actions> @@ -96,7 +93,7 @@ export default class DataExport extends mixins(exportMixin) { exportDialog = true mapFile: File | null = null setPasswords = false - exportType = ExportType.CSV + exportType = ExportType.JSON loading = false get studentMap () { return getters.state.studentMap } diff --git a/frontend/src/components/mixins/exportMixin.ts b/frontend/src/components/mixins/exportMixin.ts index dc536992..1d24bd03 100644 --- a/frontend/src/components/mixins/exportMixin.ts +++ b/frontend/src/components/mixins/exportMixin.ts @@ -10,7 +10,7 @@ let download = saveAs export enum ExportType { JSON = 'application/json', - CSV = 'text/csv' + //CSV = 'text/csv' } export function mock(mockedDownload?: () => boolean) { @@ -22,16 +22,18 @@ export class exportMixin extends mixins(Vue, parseCSVMapMixin) { exportDialog = true mapFile: File | null = null setPasswords = false - exportType = ExportType.CSV + exportType = ExportType.JSON loading = false get mapFileLoaded () { return Object.keys(getters.state.studentMap).length > 0 } + /* get availableExportTypes (): ExportType[] { return Object.values(ExportType) } + */ async getExportFile (type: string) { this.loading = true @@ -52,6 +54,7 @@ export class exportMixin extends mixins(Vue, parseCSVMapMixin) { } } + /* jsonToCSV (studentExport: StudentExportItem[], delimeter = ';') { let headerLine = Object.keys(studentExport[0]).reduce((acc: string, curr) => { if (curr === 'Scores') { @@ -83,12 +86,16 @@ export class exportMixin extends mixins(Vue, parseCSVMapMixin) { return `${acc}\n${curr}` }, '') + '\n' // add trailing newline } + */ optionalConvertAndCreatePopup (studentData: StudentExportItem[] | InstanceExportData) { - const convertedData = this.exportType === ExportType.CSV + /*const convertedData = this.exportType === ExportType.CSV ? this.jsonToCSV(studentData as StudentExportItem[]) : JSON.stringify(studentData) // we have a cast here because only student export may be converted to csv - const filename = this.exportType === ExportType.CSV ? 'export.csv' : 'export.json' + const filename = this.exportType === ExportType.CSV ? 'export.csv' : 'export.json' + */ + const convertedData = JSON.stringify(studentData) + const filename = 'export.json' download(new Blob([convertedData], { type: this.exportType }), filename) this.loading = false } diff --git a/frontend/tests/unit/mixins/exportMixin.spec.ts b/frontend/tests/unit/mixins/exportMixin.spec.ts index 099f880d..72148022 100644 --- a/frontend/tests/unit/mixins/exportMixin.spec.ts +++ b/frontend/tests/unit/mixins/exportMixin.spec.ts @@ -47,13 +47,14 @@ describe('Export Mixin Unit Tests', () => { spy.calledWith(testUtils.studentExports).should.equal(true) }) }) + /* describe('optionalConvertAndCreatePopup()', () => { let e = new exportMixin() afterEach(() => { sinon.restore() }) - + it('should convert data to csv when csv is selected in dropdown', () => { let stub = sinon.stub().returns('students as csv') let spy = sinon.spy() @@ -65,7 +66,9 @@ describe('Export Mixin Unit Tests', () => { spy.calledWith(new Blob(), 'export.csv').should.equal(true) mock() }) + }) + */ describe('readMapFileAndCommit', () => { let e = new exportMixin() // @ts-ignore @@ -141,6 +144,7 @@ describe('Export Mixin Unit Tests', () => { popupSpy.calledWithExactly(testUtils.instanceExports).should.equal(true) }) }) + /* describe('jsonToCSV()', () => { let e = new exportMixin @@ -151,4 +155,5 @@ describe('Export Mixin Unit Tests', () => { csv.should.equal(expected) }) }) + */ }) diff --git a/functional_tests/test_export_modal.py b/functional_tests/test_export_modal.py index a6e61cd3..beb5c7b8 100644 --- a/functional_tests/test_export_modal.py +++ b/functional_tests/test_export_modal.py @@ -97,10 +97,6 @@ class ExportTestModal(GradyTestCase): export_scores = self.browser.find_element_by_id('export-list0') export_scores.click() data_export_modal = self.browser.find_element_by_id('data-export-modal') - export_type_select = data_export_modal.find_element_by_id('type-select') - export_type_select.click() - export_type_json = data_export_modal.find_element_by_xpath("//*[contains(text(), 'json')]") - export_type_json.click() data_export_btn = data_export_modal.find_element_by_id('export-data-download-btn') data_export_btn.click() WebDriverWait(self.browser, 10).until(expect_file_to_be_downloaded(JSON_EXPORT_FILE)) -- GitLab From 1bcc19ade2feee084ccee62e56c88aa6a74341c5 Mon Sep 17 00:00:00 2001 From: Jakob Dieterle <jakob.dieterle@stud.uni-goettingen.de> Date: Tue, 28 Jan 2020 16:56:00 +0100 Subject: [PATCH 2/5] Removed commented code --- frontend/src/components/mixins/exportMixin.ts | 46 ------------------- .../tests/unit/mixins/exportMixin.spec.ts | 35 +------------- 2 files changed, 1 insertion(+), 80 deletions(-) diff --git a/frontend/src/components/mixins/exportMixin.ts b/frontend/src/components/mixins/exportMixin.ts index 1d24bd03..eb7c4aec 100644 --- a/frontend/src/components/mixins/exportMixin.ts +++ b/frontend/src/components/mixins/exportMixin.ts @@ -10,7 +10,6 @@ let download = saveAs export enum ExportType { JSON = 'application/json', - //CSV = 'text/csv' } export function mock(mockedDownload?: () => boolean) { @@ -29,12 +28,6 @@ export class exportMixin extends mixins(Vue, parseCSVMapMixin) { return Object.keys(getters.state.studentMap).length > 0 } - /* - get availableExportTypes (): ExportType[] { - return Object.values(ExportType) - } - */ - async getExportFile (type: string) { this.loading = true @@ -54,46 +47,7 @@ export class exportMixin extends mixins(Vue, parseCSVMapMixin) { } } - /* - jsonToCSV (studentExport: StudentExportItem[], delimeter = ';') { - let headerLine = Object.keys(studentExport[0]).reduce((acc: string, curr) => { - if (curr === 'Scores') { - return acc - } - return acc ? `${acc};${curr}` : `${curr}` - }, '') - headerLine += Object.values(studentExport[0].Scores) - .reduce((acc: string, curr) => { - return `${acc};${curr.type}` - }, '') - - const lines = studentExport.map(student => { - const normalFields = Object.values(student).reduce((acc: string, curr): string => { - // skip the Scores field - if (typeof curr === 'object') { - return acc - } - return acc ? `${acc};${curr}` : `${curr}` - }, '') - - const scoreFields = Object.values(student.Scores).reduce((acc: string, curr) => { - return `${acc};${curr.score}` - }, '') - return normalFields + scoreFields - }) - - return headerLine + lines.reduce((acc, curr) => { - return `${acc}\n${curr}` - }, '') + '\n' // add trailing newline - } - */ - optionalConvertAndCreatePopup (studentData: StudentExportItem[] | InstanceExportData) { - /*const convertedData = this.exportType === ExportType.CSV - ? this.jsonToCSV(studentData as StudentExportItem[]) : JSON.stringify(studentData) - // we have a cast here because only student export may be converted to csv - const filename = this.exportType === ExportType.CSV ? 'export.csv' : 'export.json' - */ const convertedData = JSON.stringify(studentData) const filename = 'export.json' download(new Blob([convertedData], { type: this.exportType }), filename) diff --git a/frontend/tests/unit/mixins/exportMixin.spec.ts b/frontend/tests/unit/mixins/exportMixin.spec.ts index 72148022..a2f747c7 100644 --- a/frontend/tests/unit/mixins/exportMixin.spec.ts +++ b/frontend/tests/unit/mixins/exportMixin.spec.ts @@ -47,28 +47,7 @@ describe('Export Mixin Unit Tests', () => { spy.calledWith(testUtils.studentExports).should.equal(true) }) }) - /* - describe('optionalConvertAndCreatePopup()', () => { - let e = new exportMixin() - - afterEach(() => { - sinon.restore() - }) - - it('should convert data to csv when csv is selected in dropdown', () => { - let stub = sinon.stub().returns('students as csv') - let spy = sinon.spy() - e.exportType = ExportType.CSV - sinon.replace(e, 'jsonToCSV', stub) - mock(spy) - e.optionalConvertAndCreatePopup(testUtils.studentExports) - stub.calledWith(testUtils.studentExports).should.equal(true) - spy.calledWith(new Blob(), 'export.csv').should.equal(true) - mock() - }) - - }) - */ + describe('readMapFileAndCommit', () => { let e = new exportMixin() // @ts-ignore @@ -144,16 +123,4 @@ describe('Export Mixin Unit Tests', () => { popupSpy.calledWithExactly(testUtils.instanceExports).should.equal(true) }) }) - /* - describe('jsonToCSV()', () => { - let e = new exportMixin - - it('should correctly parse JSON input to CSV with ; delimiter', () => { - let csv = e.jsonToCSV(testUtils.studentExports) - let expected = 'Matrikel;Name;Username;Sum;Exam;Password;test01\n' + - '1000000;name;username;100;exam;pwd;100\n' - csv.should.equal(expected) - }) - }) - */ }) -- GitLab From 09da753ab02aa150afefbf571fd5961aa5ef20ca Mon Sep 17 00:00:00 2001 From: Jakob Dieterle <jakob.dieterle@stud.uni-goettingen.de> Date: Tue, 28 Jan 2020 17:17:30 +0100 Subject: [PATCH 3/5] Removed CSV download test. --- frontend/tests/unit/components/DataExport.spec.ts | 13 ------------- 1 file changed, 13 deletions(-) diff --git a/frontend/tests/unit/components/DataExport.spec.ts b/frontend/tests/unit/components/DataExport.spec.ts index 3ed0ed38..739ec42e 100644 --- a/frontend/tests/unit/components/DataExport.spec.ts +++ b/frontend/tests/unit/components/DataExport.spec.ts @@ -46,24 +46,11 @@ describe('DataExport Component Unit Tests', () => { 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) - mock(spy) - // @ts-ignore - wrapper.vm.optionalConvertAndCreatePopup(testUtils.studentExports) - spy.called.should.equal(true) - mock() - }) 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) mock(() => { return true }) // @ts-ignore wrapper.vm.optionalConvertAndCreatePopup(testUtils.studentExports) -- GitLab From ef5b85959aef5d3bce853be0167a280ba40506a2 Mon Sep 17 00:00:00 2001 From: Jakob Dieterle <jakob.dieterle@stud.uni-goettingen.de> Date: Tue, 4 Feb 2020 16:03:38 +0100 Subject: [PATCH 4/5] Changed tooltip position so it doesnt obscure buttons in test --- frontend/src/components/export/ExportDialog.vue | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/frontend/src/components/export/ExportDialog.vue b/frontend/src/components/export/ExportDialog.vue index 86bb10b3..3a4800e5 100644 --- a/frontend/src/components/export/ExportDialog.vue +++ b/frontend/src/components/export/ExportDialog.vue @@ -3,7 +3,7 @@ <v-menu offset-y> <v-tooltip slot="activator" - bottom + left > <v-btn id="export-btn" -- GitLab From e97e9e263a7c5750bf226bbe4162828450d445a6 Mon Sep 17 00:00:00 2001 From: Dominik Seeger <dominik.seeger@stud.uni-goettingen.de> Date: Tue, 11 Feb 2020 16:43:15 +0100 Subject: [PATCH 5/5] removed duplicate initialization of values --- frontend/src/components/export/DataExport.vue | 5 ----- 1 file changed, 5 deletions(-) diff --git a/frontend/src/components/export/DataExport.vue b/frontend/src/components/export/DataExport.vue index 1ba556ba..3a1a5f51 100644 --- a/frontend/src/components/export/DataExport.vue +++ b/frontend/src/components/export/DataExport.vue @@ -90,11 +90,6 @@ import { ExportType, exportMixin } from '@/components/mixins/exportMixin.ts' components: { FileSelect } }) export default class DataExport extends mixins(exportMixin) { - exportDialog = true - mapFile: File | null = null - setPasswords = false - exportType = ExportType.JSON - loading = false get studentMap () { return getters.state.studentMap } -- GitLab