From b1c6aec0506c62535737978c4c4d27f6fdafedff Mon Sep 17 00:00:00 2001 From: Devin Howard Date: Sat, 6 May 2017 18:08:48 -0700 Subject: [PATCH] switch ImportDialogBox to using enzyme but tests are still failing --- .../MapView/ImportDialogBox.spec.js | 72 +++++++++---------- 1 file changed, 35 insertions(+), 37 deletions(-) diff --git a/frontend/test/components/MapView/ImportDialogBox.spec.js b/frontend/test/components/MapView/ImportDialogBox.spec.js index aa4fd8c6..ad42b5b1 100644 --- a/frontend/test/components/MapView/ImportDialogBox.spec.js +++ b/frontend/test/components/MapView/ImportDialogBox.spec.js @@ -1,50 +1,48 @@ /* global describe, it */ import React from 'react' -import TestUtils from 'react-addons-test-utils' // ES6 -import ImportDialogBox from '../../../src/components/ImportDialogBox.js' +import ImportDialogBox from '../../../src/components/MapView/ImportDialogBox.js' import Dropzone from 'react-dropzone' -import chai from 'chai' - -const { expect } = chai +import { expect } from 'chai' +import { shallow } from 'enzyme' +import sinon from 'sinon' describe('ImportDialogBox', function() { - it('has an Export CSV button', function(done) { - const onExport = format => { - if (format === 'csv') done() - } - const detachedComp = TestUtils.renderIntoDocument() - const button = TestUtils.findRenderedDOMComponentWithClass(detachedComp, 'export-csv') - const buttonNode = React.findDOMNode(button) - expect(button).to.exist; - TestUtils.Simulate.click(buttonNode) + it('has an Export CSV button', () => { + const onExport = sinon.spy() + const wrapper = shallow() + const button = wrapper.find('.export-csv') + expect(button).to.exist + //button.simulate('click') + expect(onExport).to.have.property('callCount', 1) + expect(onExport.calledWith('csv')).to.equal(true) }) - it('has an Export JSON button', function(done) { - const onExport = format => { - if (format === 'json') done() - } - const detachedComp = TestUtils.renderIntoDocument() - const button = TestUtils.findRenderedDOMComponentWithClass(detachedComp, 'export-json') - const buttonNode = React.findDOMNode(button) - expect(button).to.exist; - TestUtils.Simulate.click(buttonNode) + it('has an Export JSON button', () => { + const onExport = sinon.spy() + const wrapper = shallow() + const button = wrapper.find('.export-json') + expect(button).to.exist + //button.simulate('click') + expect(onExport).to.have.property('callCount', 1) + expect(onExport.calledWith('json')).to.equal(true) }) - it('has a Download screenshot button', function(done) { - const downloadScreenshot = () => { done() } - const detachedComp = TestUtils.renderIntoDocument() - const button = TestUtils.findRenderedDOMComponentWithClass(detachedComp, 'download-screenshot') - const buttonNode = React.findDOMNode(button) - expect(button).to.exist; - TestUtils.Simulate.click(buttonNode) + it('has a Download screenshot button', () => { + const onExport = sinon.spy() + const wrapper = shallow() + const button = wrapper.find('.download-screenshot') + expect(button).to.exist + //button.simulate('click') + expect(onExport).to.have.property('callCount', 1) }) - it('has a file uploader', function(done) { - const uploadedFile = { file: 'mock a file' } - const onFileAdded = file => { if (file === uploadedFile) done() } - const detachedComp = TestUtils.renderIntoDocument( {}} onFileAdded={onFileAdded} />) - const dropzone = TestUtils.findRenderedComponentWithType(detachedComp, Dropzone) - expect(dropzone).to.exist; - dropzone.props.onDropAccepted([uploadedFile], { preventDefault: () => {} }) + it('has a file uploader', () => { + const uploadedFile = {} + const onFileAdded = sinon.spy() + const wrapper = shallow( {}} onFileAdded={onFileAdded} />) + const dropzone = wrapper.find(Dropzone) + dropzone.props().onDropAccepted([uploadedFile], { preventDefault: () => {} }) + expect(onFileAdded).to.have.property('callCount', 1) + expect(onFileAdded.calledWith(uploadedFile)).to.equal(true) }) })