Skip to content

Commit

Permalink
v1.1.6
Browse files Browse the repository at this point in the history
  • Loading branch information
PaulLeCam committed Apr 10, 2017
1 parent be838c6 commit 5ced368
Show file tree
Hide file tree
Showing 104 changed files with 3,330 additions and 2,230 deletions.
21 changes: 15 additions & 6 deletions .eslintrc.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,22 +5,31 @@
},
"extends": [
"plugin:flowtype/recommended",
"standard",
"standard-react"
"plugin:react/recommended",
"prettier",
"prettier/flowtype",
"prettier/react"
],
"parser": "babel-eslint",
"parserOptions": {
"ecmaVersion": 7,
"ecmaVersion": 2016,
"jsx": true,
"sourceType": "module"
},
"plugins": [
"flowtype",
"prettier",
"react"
],
"rules": {
"comma-dangle": [1, "always-multiline"],
"jsx-quotes": [2, "prefer-single"],
"no-unused-vars": [2, { "varsIgnorePattern": "^_" }]
"no-unused-vars": ["error", {"varsIgnorePattern": "^_"}],
"prettier/prettier": [
"error",
{
"jsxBracketSameLine": true,
"singleQuote": true,
"trailingComma": "all"
}
]
}
}
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
## v1.1.6 (2017-04-10)

- Added support for React v15.5, fixes PropTypes warning.
- [internal] Use Prettier code formatting.

## v1.1.5 (2017-04-05)

Filter falsy values as event handlers, [PR #308](https://github.com/PaulLeCam/react-leaflet/pull/308) by *awinograd*.
Expand Down
33 changes: 17 additions & 16 deletions __tests__/LayersControl.js
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>,
);
});
});
122 changes: 62 additions & 60 deletions __tests__/Map.js
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);
});
});
Loading

0 comments on commit 5ced368

Please sign in to comment.