mirror of
https://github.com/lana-k/sqliteviz.git
synced 2025-12-06 18:18:53 +08:00
Support all CSV media types #37
This commit is contained in:
@@ -139,6 +139,15 @@ import ChangeDbIcon from '@/components/svg/changeDb'
|
|||||||
import time from '@/time'
|
import time from '@/time'
|
||||||
import database from '@/database'
|
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 {
|
export default {
|
||||||
name: 'DbUploader',
|
name: 'DbUploader',
|
||||||
props: {
|
props: {
|
||||||
@@ -365,7 +374,7 @@ export default {
|
|||||||
|
|
||||||
async checkFile (file) {
|
async checkFile (file) {
|
||||||
this.state = 'drop'
|
this.state = 'drop'
|
||||||
if (file.type === 'text/csv') {
|
if (csvMimeTypes.includes(file.type)) {
|
||||||
this.file = file
|
this.file = file
|
||||||
this.header = true
|
this.header = true
|
||||||
this.quoteChar = '"'
|
this.quoteChar = '"'
|
||||||
|
|||||||
@@ -57,7 +57,7 @@ describe('file.utils.js', () => {
|
|||||||
expect(URL.revokeObjectURL.calledOnceWith(url)).to.equal(true)
|
expect(URL.revokeObjectURL.calledOnceWith(url)).to.equal(true)
|
||||||
})
|
})
|
||||||
|
|
||||||
it('importFile', () => {
|
it('importFile', async () => {
|
||||||
const spyInput = document.createElement('input')
|
const spyInput = document.createElement('input')
|
||||||
sinon.stub(spyInput, 'click')
|
sinon.stub(spyInput, 'click')
|
||||||
|
|
||||||
@@ -71,14 +71,12 @@ describe('file.utils.js', () => {
|
|||||||
|
|
||||||
setTimeout(() => { spyInput.dispatchEvent(new Event('change')) })
|
setTimeout(() => { spyInput.dispatchEvent(new Event('change')) })
|
||||||
|
|
||||||
return fu.importFile()
|
const data = await fu.importFile()
|
||||||
.then((data) => {
|
expect(data).to.equal('foo')
|
||||||
expect(data).to.equal('foo')
|
expect(document.createElement.calledOnceWith('input')).to.equal(true)
|
||||||
expect(document.createElement.calledOnceWith('input')).to.equal(true)
|
expect(spyInput.type).to.equal('file')
|
||||||
expect(spyInput.type).to.equal('file')
|
expect(spyInput.accept).to.equal('.json')
|
||||||
expect(spyInput.accept).to.equal('.json')
|
expect(spyInput.click.calledOnce).to.equal(true)
|
||||||
expect(spyInput.click.calledOnce).to.equal(true)
|
|
||||||
})
|
|
||||||
})
|
})
|
||||||
|
|
||||||
it('readFile', () => {
|
it('readFile', () => {
|
||||||
|
|||||||
Reference in New Issue
Block a user