diff --git a/.travis.yml b/.travis.yml new file mode 100644 index 0000000..caab5e0 --- /dev/null +++ b/.travis.yml @@ -0,0 +1,6 @@ +language: node_js +node_js: + - "iojs-2" +script: + - npm run lint + - npm test diff --git a/package.json b/package.json index 3bf9326..11185a4 100644 --- a/package.json +++ b/package.json @@ -7,10 +7,11 @@ "build:lib": "babel ./src -d lib --ignore '__tests__'", "build:umd": "webpack src/index.js dist/GoogleMapReact.js --config webpack.config.dev.js", "build:umd:min": "webpack src/index.js dist/GoogleMapReact.min.js --config webpack.config.prod.js", + "build": "npm run build:lib && npm run build:umd && npm run build:umd:min", "clean": "rimraf lib dist", - "prepublish": "npm run clean && npm run build:lib && npm run build:umd && npm run build:umd:min", - "eyetest": "babel-node ./src/__tests__/eye_test.js", - "es5eyetest": "node ./lib/__tests__/eye_test.js" + "prepublish": "npm run clean && npm run build", + "lint": "eslint src", + "test": "NODE_ENV=eee mocha --compilers js:babel/register --recursive" }, "repository": { "type": "git", @@ -35,10 +36,6 @@ }, "homepage": "https://github.com/istarkov/google-map-react#readme", "dependencies": { - "babel-eslint": "^4.1.3", - "eslint": "^1.6.0", - "eslint-config-airbnb": "^0.1.0", - "eslint-plugin-react": "^3.5.1", "eventemitter3": "^1.1.0", "lodash.assign": "^3.2.0", "lodash.isfunction": "^3.0.5", @@ -52,8 +49,16 @@ "devDependencies": { "babel": "^5.8.23", "babel-core": "^5.8.25", + "babel-eslint": "^4.1.3", "babel-loader": "^5.3.2", + "eslint": "^1.6.0", + "eslint-config-airbnb": "^0.1.0", + "eslint-plugin-react": "^3.5.1", + "expect": "^1.11.1", + "jsdom": "^6.5.1", + "mocha": "^2.3.3", "react": "^0.14.0-rc1", + "react-addons-test-utils": "^0.14.0-rc1", "react-dom": "^0.14.0-rc1", "rimraf": "^2.4.3", "webpack": "^1.12.2" diff --git a/src/google_map.js b/src/google_map.js index ac10424..7e3453b 100644 --- a/src/google_map.js +++ b/src/google_map.js @@ -115,13 +115,12 @@ export default class GoogleMap extends Component { componentDidMount() { this.mounted_ = true; window.addEventListener('resize', this._onWindowResize); + this.props.googleMapLoader(this.props.apiKey); // we can start load immediatly setTimeout(() => { // to detect size this._setViewSize(); if (this._isCenterDefined(this.props.center)) { this._initMap(); - } else { - this.props.googleMapLoader(this.props.apiKey); // начать подгружать можно уже сейчас } }, 0, this); } diff --git a/test/components/GoogleMap.spec.js b/test/components/GoogleMap.spec.js new file mode 100644 index 0000000..809d993 --- /dev/null +++ b/test/components/GoogleMap.spec.js @@ -0,0 +1,74 @@ +import './utils/jsdomInit.js'; + +const React = require('react'); +const { PropTypes, Component } = React; +const expect = require('expect'); + +const TestUtils = require('react-addons-test-utils'); +const GoogleMap = require('../../src/index'); + +describe('Components', () => { + it('Should work', () => { + const mapMarkerClassName = 'mapMarkerClassName'; + + class MapMarker extends Component { + render() { + return ( +
Marker
+ ); + } + } + + class MapHolder extends Component { // eslint-disable-line react/no-multi-comp + static propTypes = { + center: PropTypes.array, + zoom: PropTypes.number, + greatPlaceCoords: PropTypes.any, + }; + + static defaultProps = { + center: [59.938043, 30.337157], + zoom: 9, + }; + + constructor(props) { + super(props); + } + + render() { + return ( + + + + ); + } + } + + const mapHolder = TestUtils.renderIntoDocument( + + ); + + const marker = TestUtils.findRenderedDOMComponentWithClass(mapHolder, 'mapMarkerClassName'); + expect(marker.parentNode.style.left).toEqual('0.250129066669615px'); + expect(marker.parentNode.style.top).toEqual('-12.62811732746195px'); + }); + + it('Should call custom loader', () => { + const API_KEY = 'API_KEY'; + const spy = expect.createSpy(() => {}); + const asyncSpy = async (a) => spy(a); + + TestUtils.renderIntoDocument( + + ); + + expect(spy.calls.length).toEqual(1); + expect(spy.calls[0].arguments[0]).toEqual(API_KEY); + }); +}); diff --git a/test/components/utils/jsdomInit.js b/test/components/utils/jsdomInit.js new file mode 100644 index 0000000..de22db5 --- /dev/null +++ b/test/components/utils/jsdomInit.js @@ -0,0 +1,17 @@ +import jsdom from 'jsdom'; + +const doc = jsdom.jsdom(''); +const win = doc.defaultView; +global.document = doc; +global.window = win; + +function propagateToGlobal(window) { + for (const key in window) { + if (!window.hasOwnProperty(key)) continue; + if (key in global) continue; + + global[key] = window[key]; + } +} + +propagateToGlobal(win);