|
1 |
| -import {geolocated} from '../src/index'; |
| 1 | +import React, {Component} from 'react'; |
| 2 | +import ReactDOM from 'react-dom'; |
| 3 | +import TestUtils from 'react-addons-test-utils'; |
| 4 | +import {geolocated, geoPropTypes} from '../src/index'; |
2 | 5 |
|
3 |
| -describe('Geolocated', function() { |
4 |
| - it('should export a function', function() { |
| 6 | +class SimpleComponent extends Component { |
| 7 | + render() { |
| 8 | + const {coords} = this.props; |
| 9 | + return (<div> |
| 10 | + {coords && coords.latitude}, {coords && coords.longitude} |
| 11 | + </div>); |
| 12 | + } |
| 13 | +} |
| 14 | + |
| 15 | +SimpleComponent.propTypes = {...SimpleComponent.propTypes, ...geoPropTypes }; |
| 16 | + |
| 17 | +describe('Geolocated', () => { |
| 18 | + it('should export a function', () => { |
5 | 19 | expect(geolocated).to.exist;
|
6 | 20 | expect(geolocated).to.be.instanceof(Function);
|
7 | 21 | });
|
| 22 | + |
| 23 | + it('should inject the location', () => { |
| 24 | + const mockGeolocationProvider = { |
| 25 | + getCurrentPosition(onSuccess) { |
| 26 | + return onSuccess({ |
| 27 | + coords: { |
| 28 | + latitude: 50, |
| 29 | + longitude: 20, |
| 30 | + }, |
| 31 | + }) |
| 32 | + }, |
| 33 | + }; |
| 34 | + |
| 35 | + const Wrapped = geolocated({ |
| 36 | + geolocationProvider: mockGeolocationProvider, |
| 37 | + })(SimpleComponent); |
| 38 | + |
| 39 | + const rendered = TestUtils.renderIntoDocument(<Wrapped />); |
| 40 | + const renderedNode = ReactDOM.findDOMNode(rendered); |
| 41 | + |
| 42 | + expect(renderedNode.textContent).to.equal('50, 20'); |
| 43 | + }); |
| 44 | + |
| 45 | + it('should throw on invalid geolocation provider', () => { |
| 46 | + const Wrapped = geolocated({ |
| 47 | + geolocationProvider: {}, |
| 48 | + })(SimpleComponent); |
| 49 | + |
| 50 | + expect(() => TestUtils.renderIntoDocument(<Wrapped />)).to.throw(); |
| 51 | + }); |
8 | 52 | });
|
0 commit comments