From 453098b41022a920478266a027a86d28446cdfc1 Mon Sep 17 00:00:00 2001 From: lana-k Date: Tue, 27 Apr 2021 13:42:58 +0200 Subject: [PATCH] Support all CSV media types #37 --- src/components/DbUploader.vue | 11 ++++++++++- tests/file.utils.spec.js | 16 +++++++--------- 2 files changed, 17 insertions(+), 10 deletions(-) diff --git a/src/components/DbUploader.vue b/src/components/DbUploader.vue index 346ad1e..774a38e 100644 --- a/src/components/DbUploader.vue +++ b/src/components/DbUploader.vue @@ -139,6 +139,15 @@ import ChangeDbIcon from '@/components/svg/changeDb' import time from '@/time' import database from '@/database' +const csvMimeTypes = [ + 'text/csv', + 'text/x-csv', + 'application/x-csv', + 'application/csv', + 'text/x-comma-separated-values', + 'text/comma-separated-values' +] + export default { name: 'DbUploader', props: { @@ -365,7 +374,7 @@ export default { async checkFile (file) { this.state = 'drop' - if (file.type === 'text/csv') { + if (csvMimeTypes.includes(file.type)) { this.file = file this.header = true this.quoteChar = '"' diff --git a/tests/file.utils.spec.js b/tests/file.utils.spec.js index fa02173..d46071d 100644 --- a/tests/file.utils.spec.js +++ b/tests/file.utils.spec.js @@ -57,7 +57,7 @@ describe('file.utils.js', () => { expect(URL.revokeObjectURL.calledOnceWith(url)).to.equal(true) }) - it('importFile', () => { + it('importFile', async () => { const spyInput = document.createElement('input') sinon.stub(spyInput, 'click') @@ -71,14 +71,12 @@ describe('file.utils.js', () => { setTimeout(() => { spyInput.dispatchEvent(new Event('change')) }) - return fu.importFile() - .then((data) => { - expect(data).to.equal('foo') - expect(document.createElement.calledOnceWith('input')).to.equal(true) - expect(spyInput.type).to.equal('file') - expect(spyInput.accept).to.equal('.json') - expect(spyInput.click.calledOnce).to.equal(true) - }) + const data = await fu.importFile() + expect(data).to.equal('foo') + expect(document.createElement.calledOnceWith('input')).to.equal(true) + expect(spyInput.type).to.equal('file') + expect(spyInput.accept).to.equal('.json') + expect(spyInput.click.calledOnce).to.equal(true) }) it('readFile', () => {