mirror of
https://github.com/lana-k/sqliteviz.git
synced 2025-12-07 02:28:54 +08:00
add test for exportToFile
This commit is contained in:
@@ -126,7 +126,7 @@ module.exports = function (config) {
|
|||||||
{
|
{
|
||||||
test: /\.js$/,
|
test: /\.js$/,
|
||||||
include: /src/,
|
include: /src/,
|
||||||
exclude: /(node_modules|bower_components|\.spec\.js$|\/file)/,
|
exclude: /(node_modules|bower_components|\.spec\.js$)/,
|
||||||
use: [
|
use: [
|
||||||
{
|
{
|
||||||
loader: 'istanbul-instrumenter-loader',
|
loader: 'istanbul-instrumenter-loader',
|
||||||
|
|||||||
@@ -157,7 +157,7 @@ import TextField from '@/components/TextField'
|
|||||||
import CheckBox from '@/components/CheckBox'
|
import CheckBox from '@/components/CheckBox'
|
||||||
import tooltipMixin from '@/mixins/tooltips'
|
import tooltipMixin from '@/mixins/tooltips'
|
||||||
import storedQueries from '@/storedQueries'
|
import storedQueries from '@/storedQueries'
|
||||||
import fu from '@/fileUtilities'
|
import fu from '@/fileUtils'
|
||||||
|
|
||||||
export default {
|
export default {
|
||||||
name: 'MyQueries',
|
name: 'MyQueries',
|
||||||
|
|||||||
70
tests/unit/fileUtils.spec.js
Normal file
70
tests/unit/fileUtils.spec.js
Normal file
@@ -0,0 +1,70 @@
|
|||||||
|
import { expect } from 'chai'
|
||||||
|
import fu from '@/fileUtils.js'
|
||||||
|
import sinon from 'sinon'
|
||||||
|
|
||||||
|
describe('fileUtils.js', () => {
|
||||||
|
afterEach(()=> {
|
||||||
|
document.createElement.restore()
|
||||||
|
URL.revokeObjectURL.restore()
|
||||||
|
URL.createObjectURL.restore()
|
||||||
|
window.Blob.restore()
|
||||||
|
})
|
||||||
|
|
||||||
|
it('exportToFile (octet/stream by default)', () => {
|
||||||
|
const spyAnchor = document.createElement('a')
|
||||||
|
sinon.spy(spyAnchor, 'click')
|
||||||
|
sinon.spy(spyAnchor, 'remove')
|
||||||
|
sinon.stub(document, 'createElement').returns(spyAnchor)
|
||||||
|
sinon.spy(URL, 'createObjectURL')
|
||||||
|
sinon.spy(URL, 'revokeObjectURL')
|
||||||
|
sinon.spy(window, 'Blob')
|
||||||
|
|
||||||
|
const str = 'foo'
|
||||||
|
fu.exportToFile('foo','foo.txt')
|
||||||
|
|
||||||
|
expect(document.createElement.calledOnceWith('a')).to.equal(true)
|
||||||
|
|
||||||
|
expect(window.Blob.calledOnceWith(['foo'], { type: 'octet/stream' })).to.equal(true)
|
||||||
|
const blob = window.Blob.returnValues[0]
|
||||||
|
expect(URL.createObjectURL.calledOnceWith(blob)).to.equal(true)
|
||||||
|
|
||||||
|
const url = URL.createObjectURL.returnValues[0]
|
||||||
|
expect(spyAnchor.href).to.equal(url)
|
||||||
|
|
||||||
|
expect(spyAnchor.download).to.equal('foo.txt')
|
||||||
|
|
||||||
|
expect(spyAnchor.click.calledOnce).to.equal(true)
|
||||||
|
|
||||||
|
expect(spyAnchor.remove.calledOnce).to.equal(true)
|
||||||
|
expect(URL.revokeObjectURL.calledOnceWith(url)).to.equal(true)
|
||||||
|
}),
|
||||||
|
|
||||||
|
it('exportToFile', () => {
|
||||||
|
const spyAnchor = document.createElement('a')
|
||||||
|
sinon.spy(spyAnchor, 'click')
|
||||||
|
sinon.spy(spyAnchor, 'remove')
|
||||||
|
sinon.stub(document, 'createElement').returns(spyAnchor)
|
||||||
|
sinon.spy(URL, 'createObjectURL')
|
||||||
|
sinon.spy(URL, 'revokeObjectURL')
|
||||||
|
sinon.spy(window, 'Blob')
|
||||||
|
|
||||||
|
const str = 'foo'
|
||||||
|
fu.exportToFile('foo','foo.html', 'text/html')
|
||||||
|
|
||||||
|
expect(document.createElement.calledOnceWith('a')).to.equal(true)
|
||||||
|
|
||||||
|
expect(window.Blob.calledOnceWith(['foo'], { type: 'text/html' })).to.equal(true)
|
||||||
|
const blob = window.Blob.returnValues[0]
|
||||||
|
expect(URL.createObjectURL.calledOnceWith(blob)).to.equal(true)
|
||||||
|
|
||||||
|
const url = URL.createObjectURL.returnValues[0]
|
||||||
|
expect(spyAnchor.href).to.equal(url)
|
||||||
|
|
||||||
|
expect(spyAnchor.download).to.equal('foo.html')
|
||||||
|
|
||||||
|
expect(spyAnchor.click.calledOnce).to.equal(true)
|
||||||
|
|
||||||
|
expect(spyAnchor.remove.calledOnce).to.equal(true)
|
||||||
|
expect(URL.revokeObjectURL.calledOnceWith(url)).to.equal(true)
|
||||||
|
})
|
||||||
|
})
|
||||||
Reference in New Issue
Block a user