remove duplicated code

This commit is contained in:
Devin Howard 2017-05-06 18:53:36 -07:00
parent e37079c079
commit 4abdc74750
2 changed files with 38 additions and 40 deletions

View file

@ -17,21 +17,17 @@ describe('ImportDialogBox', function() {
} }
} }
it('has an Export CSV button', () => { const testExportButton = ({ description, cssClass, exporter }) => {
const wrapper = shallow(<ImportDialogBox onExport={onExport} />) it(description, () => {
const button = wrapper.find('.export-csv') const wrapper = shallow(<ImportDialogBox onExport={onExport} />)
expect(button).to.exist const button = wrapper.find(cssClass)
button.simulate('click') expect(button).to.exist
expect(csvExport).to.have.property('callCount', 1) button.simulate('click')
}) expect(exporter).to.have.property('callCount', 1)
})
it('has an Export JSON button', () => { }
const wrapper = shallow(<ImportDialogBox onExport={onExport} />) testExportButton('has an Export CSV button', '.export-csv', csvExport)
const button = wrapper.find('.export-json') testExportButton('has an Export JSON button', '.export-json', jsonExport)
expect(button).to.exist
button.simulate('click')
expect(jsonExport).to.have.property('callCount', 1)
})
it('has a Download screenshot button', () => { it('has a Download screenshot button', () => {
const downloadScreenshot = sinon.spy() const downloadScreenshot = sinon.spy()

View file

@ -7,6 +7,15 @@ import sinon from 'sinon'
import InfoAndHelp from '../../../src/components/common/InfoAndHelp.js' import InfoAndHelp from '../../../src/components/common/InfoAndHelp.js'
import MapInfoBox from '../../../src/components/MapView/MapInfoBox.js' import MapInfoBox from '../../../src/components/MapView/MapInfoBox.js'
function assertTooltip({ wrapper, description, cssClass, tooltipText, callback }) {
it(description, function() {
expect(wrapper.find(cssClass)).to.exist
expect(wrapper.find(`${cssClass} .tooltipsAbove`).text()).to.equal(tooltipText)
wrapper.find(cssClass).simulate('click')
expect(callback).to.have.property('callCount', 1)
})
}
function assertContent({ currentUser, map }) { function assertContent({ currentUser, map }) {
const onInfoClick = sinon.spy() const onInfoClick = sinon.spy()
const onHelpClick = sinon.spy() const onHelpClick = sinon.spy()
@ -21,11 +30,12 @@ function assertContent({ currentUser, map }) {
if (map) { if (map) {
it('renders MapInfoBox', () => expect(wrapper.find(MapInfoBox)).to.exist) it('renders MapInfoBox', () => expect(wrapper.find(MapInfoBox)).to.exist)
it('renders Map Info icon', () => { assertTooltip({
expect(wrapper.find('.mapInfoIcon')).to.exist wrapper,
expect(wrapper.find('.mapInfoIcon .tooltipsAbove').text()).to.equal('Map Info') description: 'renders Map Info icon',
wrapper.find('.mapInfoIcon').simulate('click') cssClass: '.mapInfoIcon',
expect(onInfoClick).to.have.property('callCount', 1) tooltipText: 'Map Info',
callback: onInfoClick
}) })
} else { } else {
it('does not render MapInfoBox', () => expect(wrapper.find(MapInfoBox).length).to.equal(0)) it('does not render MapInfoBox', () => expect(wrapper.find(MapInfoBox).length).to.equal(0))
@ -43,11 +53,12 @@ function assertContent({ currentUser, map }) {
} }
// common content // common content
it('renders Help icon', function() { assertTooltip({
expect(wrapper.find('.openCheatsheet')).to.exist wrapper,
expect(wrapper.find('.openCheatsheet .tooltipsAbove').text()).to.equal('Help') description: 'renders Help icon',
wrapper.find('.openCheatsheet').simulate('click') cssClass: '.openCheatsheet',
expect(onHelpClick).to.have.property('callCount', 1) tooltipText: 'Help',
callback: onHelpClick
}) })
it('renders clearfloat at the end', function() { it('renders clearfloat at the end', function() {
const clearfloat = wrapper.find('.clearfloat') const clearfloat = wrapper.find('.clearfloat')
@ -67,21 +78,12 @@ function assertStarLogic({ mapIsStarred }) {
/>) />)
const starWrapper = wrapper.find('.starMap') const starWrapper = wrapper.find('.starMap')
starWrapper.simulate('click') starWrapper.simulate('click')
if (mapIsStarred) { it(mapIsStarred ? 'has unstar content' : 'has star content', () => {
it('has unstar content', () => { expect(starWrapper.hasClass('starred')).to.equal(mapIsStarred)
expect(starWrapper.hasClass('starred')).to.equal(true) expect(starWrapper.find('.tooltipsAbove').text()).to.equal(mapIsStarred ? 'Unstar' : 'Star')
expect(starWrapper.find('.tooltipsAbove').text()).to.equal('Unstar') expect(onMapStar).to.have.property('callCount', mapIsStarred ? 0 : 1)
expect(onMapStar).to.have.property('callCount', 0) expect(onMapUnstar).to.have.property('callCount', mapIsStarred ? 1 : 0)
expect(onMapUnstar).to.have.property('callCount', 1) })
})
} else {
it('has star content', () => {
expect(starWrapper.hasClass('starred')).to.equal(false)
expect(starWrapper.find('.tooltipsAbove').text()).to.equal('Star')
expect(onMapStar).to.have.property('callCount', 1)
expect(onMapUnstar).to.have.property('callCount', 0)
})
}
} }
describe('InfoAndHelp', function() { describe('InfoAndHelp', function() {