switch ImportDialogBox to using enzyme but tests are still failing

This commit is contained in:
Devin Howard 2017-05-06 18:08:48 -07:00
parent 84e268be2d
commit b1c6aec050

View file

@ -1,50 +1,48 @@
/* global describe, it */ /* global describe, it */
import React from 'react' import React from 'react'
import TestUtils from 'react-addons-test-utils' // ES6 import ImportDialogBox from '../../../src/components/MapView/ImportDialogBox.js'
import ImportDialogBox from '../../../src/components/ImportDialogBox.js'
import Dropzone from 'react-dropzone' import Dropzone from 'react-dropzone'
import chai from 'chai' import { expect } from 'chai'
import { shallow } from 'enzyme'
const { expect } = chai import sinon from 'sinon'
describe('ImportDialogBox', function() { describe('ImportDialogBox', function() {
it('has an Export CSV button', function(done) { it('has an Export CSV button', () => {
const onExport = format => { const onExport = sinon.spy()
if (format === 'csv') done() const wrapper = shallow(<ImportDialogBox onExport={onExport} />)
} const button = wrapper.find('.export-csv')
const detachedComp = TestUtils.renderIntoDocument(<ImportDialogBox onExport={onExport} />) expect(button).to.exist
const button = TestUtils.findRenderedDOMComponentWithClass(detachedComp, 'export-csv') //button.simulate('click')
const buttonNode = React.findDOMNode(button) expect(onExport).to.have.property('callCount', 1)
expect(button).to.exist; expect(onExport.calledWith('csv')).to.equal(true)
TestUtils.Simulate.click(buttonNode)
}) })
it('has an Export JSON button', function(done) { it('has an Export JSON button', () => {
const onExport = format => { const onExport = sinon.spy()
if (format === 'json') done() const wrapper = shallow(<ImportDialogBox onExport={onExport} />)
} const button = wrapper.find('.export-json')
const detachedComp = TestUtils.renderIntoDocument(<ImportDialogBox onExport={onExport} />) expect(button).to.exist
const button = TestUtils.findRenderedDOMComponentWithClass(detachedComp, 'export-json') //button.simulate('click')
const buttonNode = React.findDOMNode(button) expect(onExport).to.have.property('callCount', 1)
expect(button).to.exist; expect(onExport.calledWith('json')).to.equal(true)
TestUtils.Simulate.click(buttonNode)
}) })
it('has a Download screenshot button', function(done) { it('has a Download screenshot button', () => {
const downloadScreenshot = () => { done() } const onExport = sinon.spy()
const detachedComp = TestUtils.renderIntoDocument(<ImportDialogBox downloadScreenshot={downloadScreenshot()} />) const wrapper = shallow(<ImportDialogBox onExport={onExport} />)
const button = TestUtils.findRenderedDOMComponentWithClass(detachedComp, 'download-screenshot') const button = wrapper.find('.download-screenshot')
const buttonNode = React.findDOMNode(button) expect(button).to.exist
expect(button).to.exist; //button.simulate('click')
TestUtils.Simulate.click(buttonNode) expect(onExport).to.have.property('callCount', 1)
}) })
it('has a file uploader', function(done) { it('has a file uploader', () => {
const uploadedFile = { file: 'mock a file' } const uploadedFile = {}
const onFileAdded = file => { if (file === uploadedFile) done() } const onFileAdded = sinon.spy()
const detachedComp = TestUtils.renderIntoDocument(<ImportDialogBox onExport={() => {}} onFileAdded={onFileAdded} />) const wrapper = shallow(<ImportDialogBox onExport={() => {}} onFileAdded={onFileAdded} />)
const dropzone = TestUtils.findRenderedComponentWithType(detachedComp, Dropzone) const dropzone = wrapper.find(Dropzone)
expect(dropzone).to.exist; dropzone.props().onDropAccepted([uploadedFile], { preventDefault: () => {} })
dropzone.props.onDropAccepted([uploadedFile], { preventDefault: () => {} }) expect(onFileAdded).to.have.property('callCount', 1)
expect(onFileAdded.calledWith(uploadedFile)).to.equal(true)
}) })
}) })