-
Notifications
You must be signed in to change notification settings - Fork 887
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
104 changed files
with
3,330 additions
and
2,230 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,36 +1,37 @@ | ||
/* global describe, expect, it */ | ||
|
||
import Leaflet from 'leaflet' | ||
import React, { Component } from 'react' | ||
import { renderIntoDocument } from 'react-addons-test-utils' | ||
import Leaflet from 'leaflet'; | ||
import PropTypes from 'prop-types'; | ||
import React, { Component } from 'react'; | ||
import { renderIntoDocument } from 'react-dom/test-utils'; | ||
|
||
import LayersControl from '../src/LayersControl' | ||
import Map from '../src/Map' | ||
import LayersControl from '../src/LayersControl'; | ||
import Map from '../src/Map'; | ||
|
||
describe('LayersControl', () => { | ||
it('passes its `map` context to its children', () => { | ||
class ChildComponent extends Component { | ||
static contextTypes = { | ||
map: React.PropTypes.instanceOf(Leaflet.Map), | ||
} | ||
map: PropTypes.instanceOf(Leaflet.Map), | ||
}; | ||
|
||
componentWillMount () { | ||
expect(this.context.map).toBeDefined() | ||
componentWillMount() { | ||
expect(this.context.map).toBeDefined(); | ||
} | ||
|
||
render () { | ||
return null | ||
render() { | ||
return null; | ||
} | ||
} | ||
|
||
renderIntoDocument( | ||
<Map> | ||
<LayersControl> | ||
<LayersControl.Overlay checked name='test'> | ||
<LayersControl.Overlay checked name="test"> | ||
<ChildComponent /> | ||
</LayersControl.Overlay> | ||
</LayersControl> | ||
</Map> | ||
) | ||
}) | ||
}) | ||
</Map>, | ||
); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,108 +1,110 @@ | ||
/* global describe, expect, it */ | ||
|
||
import React, { Component } from 'react' | ||
import { renderIntoDocument } from 'react-addons-test-utils' | ||
import { renderToStaticMarkup } from 'react-dom/server' | ||
import React, { Component } from 'react'; | ||
import { renderToStaticMarkup } from 'react-dom/server'; | ||
import { renderIntoDocument } from 'react-dom/test-utils'; | ||
|
||
import Map from '../src/Map' | ||
import Map from '../src/Map'; | ||
|
||
describe('Map', () => { | ||
it('only renders the container div server-side', () => { | ||
class TestComponent extends Component { | ||
render () { | ||
return <span>test</span> | ||
render() { | ||
return <span>test</span>; | ||
} | ||
} | ||
const component = <Map><TestComponent /></Map> | ||
const html = renderToStaticMarkup(component) | ||
const component = <Map><TestComponent /></Map>; | ||
const html = renderToStaticMarkup(component); | ||
|
||
expect(html).toBe('<div></div>') | ||
}) | ||
expect(html).toBe('<div></div>'); | ||
}); | ||
|
||
it('sets center and zoom props', () => { | ||
const center = [1.2, 3.4] | ||
const zoom = 10 | ||
const center = [1.2, 3.4]; | ||
const zoom = 10; | ||
|
||
const map = renderIntoDocument(<Map center={center} zoom={zoom} />) | ||
const mapLeaflet = map.leafletElement | ||
const map = renderIntoDocument(<Map center={center} zoom={zoom} />); | ||
const mapLeaflet = map.leafletElement; | ||
|
||
expect(mapLeaflet.getCenter().lat).toBe(center[0]) | ||
expect(mapLeaflet.getCenter().lng).toBe(center[1]) | ||
expect(mapLeaflet.getZoom()).toBe(zoom) | ||
}) | ||
expect(mapLeaflet.getCenter().lat).toBe(center[0]); | ||
expect(mapLeaflet.getCenter().lng).toBe(center[1]); | ||
expect(mapLeaflet.getZoom()).toBe(zoom); | ||
}); | ||
|
||
it('sets bounds', () => { | ||
const bounds = [[0, 0], [2, 2]] | ||
const map = renderIntoDocument(<Map bounds={bounds} />) | ||
const mapBounds = map.leafletElement.getBounds() | ||
expect(mapBounds).toEqual(bounds) | ||
}) | ||
const bounds = [[0, 0], [2, 2]]; | ||
const map = renderIntoDocument(<Map bounds={bounds} />); | ||
const mapBounds = map.leafletElement.getBounds(); | ||
expect(mapBounds).toEqual(bounds); | ||
}); | ||
|
||
it('updates center and zoom props', () => { | ||
class TestComponent extends Component { | ||
constructor () { | ||
super() | ||
constructor() { | ||
super(); | ||
this.state = { | ||
center: [1.2, 3.4], | ||
zoom: 10, | ||
} | ||
}; | ||
} | ||
getLeafletMap () { | ||
return this.refs.map.leafletElement | ||
getLeafletMap() { | ||
return this.refs.map.leafletElement; | ||
} | ||
updatePosition () { | ||
updatePosition() { | ||
this.setState({ | ||
center: [2.3, 4.5], | ||
zoom: 12, | ||
}) | ||
}); | ||
} | ||
render () { | ||
return <Map center={this.state.center} ref='map' zoom={this.state.zoom} /> | ||
render() { | ||
return ( | ||
<Map center={this.state.center} ref="map" zoom={this.state.zoom} /> | ||
); | ||
} | ||
} | ||
|
||
const component = renderIntoDocument(<TestComponent />) | ||
const mapLeaflet = component.getLeafletMap() | ||
const component = renderIntoDocument(<TestComponent />); | ||
const mapLeaflet = component.getLeafletMap(); | ||
|
||
expect(mapLeaflet.getCenter().lat).toBe(1.2) | ||
expect(mapLeaflet.getCenter().lng).toBe(3.4) | ||
expect(mapLeaflet.getZoom()).toBe(10) | ||
expect(mapLeaflet.getCenter().lat).toBe(1.2); | ||
expect(mapLeaflet.getCenter().lng).toBe(3.4); | ||
expect(mapLeaflet.getZoom()).toBe(10); | ||
|
||
component.updatePosition() | ||
expect(mapLeaflet.getCenter().lat).toBe(2.3) | ||
expect(mapLeaflet.getCenter().lng).toBe(4.5) | ||
expect(mapLeaflet.getZoom()).toBe(12) | ||
}) | ||
component.updatePosition(); | ||
expect(mapLeaflet.getCenter().lat).toBe(2.3); | ||
expect(mapLeaflet.getCenter().lng).toBe(4.5); | ||
expect(mapLeaflet.getZoom()).toBe(12); | ||
}); | ||
|
||
it('updates bounds props', () => { | ||
const firstBounds = [[0, 0], [2, 2]] | ||
const secondBounds = [[0, 0], [-2, -2]] | ||
const firstBounds = [[0, 0], [2, 2]]; | ||
const secondBounds = [[0, 0], [-2, -2]]; | ||
|
||
class TestComponent extends Component { | ||
constructor () { | ||
super() | ||
constructor() { | ||
super(); | ||
this.state = { | ||
bounds: firstBounds, | ||
} | ||
}; | ||
} | ||
getLeafletMap () { | ||
return this.refs.map.leafletElement | ||
getLeafletMap() { | ||
return this.refs.map.leafletElement; | ||
} | ||
updatePosition () { | ||
updatePosition() { | ||
this.setState({ | ||
bounds: secondBounds, | ||
}) | ||
}); | ||
} | ||
render () { | ||
return <Map bounds={this.state.bounds} ref='map' /> | ||
render() { | ||
return <Map bounds={this.state.bounds} ref="map" />; | ||
} | ||
} | ||
|
||
const component = renderIntoDocument(<TestComponent />) | ||
const mapLeaflet = component.getLeafletMap() | ||
const component = renderIntoDocument(<TestComponent />); | ||
const mapLeaflet = component.getLeafletMap(); | ||
|
||
expect(mapLeaflet.getBounds()).toEqual(firstBounds) | ||
component.updatePosition() | ||
expect(mapLeaflet.getBounds()).toEqual(secondBounds) | ||
}) | ||
}) | ||
expect(mapLeaflet.getBounds()).toEqual(firstBounds); | ||
component.updatePosition(); | ||
expect(mapLeaflet.getBounds()).toEqual(secondBounds); | ||
}); | ||
}); |
Oops, something went wrong.