diff --git a/dist/components/__tests__/entity-test.js b/dist/components/__tests__/entity-test.js deleted file mode 100644 index 407f5b5..0000000 --- a/dist/components/__tests__/entity-test.js +++ /dev/null @@ -1,158 +0,0 @@ -'use strict'; - -jest.dontMock('../../mixins/listener'); -jest.dontMock('../../utils/compare-props'); -jest.dontMock('../entity'); - -describe('Entity', function () { - - var React = require('react'); - var TestUtils = require('react-addons-test-utils'); - var createEntity = require('../entity'); - var Entity = createEntity('Entity', 'prop', { - onClick: 'click' - }); - - var entity = undefined; - - beforeEach(function () { - window.google = { - maps: { - LatLng: jest.genMockFunction(), - event: { - addListener: jest.genMockFunction(), - removeListener: jest.genMockFunction() - } - } - }; - }); - - describe('mounting', function () { - - beforeEach(function () { - window.google.maps.Entity = jest.genMockFunction(); - entity = TestUtils.renderIntoDocument(React.createElement(Entity, { onClick: jest.genMockFunction() })); - }); - - it('creates the entity', function () { - expect(window.google.maps.Entity).toBeCalled(); - }); - - it('creates the entity once', function () { - entity.render(); - expect(window.google.maps.Entity.mock.calls.length).toBe(1); - }); - - it('binds events', function () { - expect(window.google.maps.event.addListener).toBeCalled(); - }); - }); - - describe('unmounting', function () { - - beforeEach(function () { - window.google.maps.Entity = function () { - return { - setMap: jest.genMockFunction() - }; - }; - entity = TestUtils.renderIntoDocument(React.createElement(Entity, { onClick: jest.genMockFunction() })); - }); - - it('unbinds events', function () { - entity.componentWillUnmount(); - expect(window.google.maps.event.removeListener).toBeCalled(); - }); - - it('removes the entity', function () { - var setMap = entity.entity.setMap; - entity.componentWillUnmount(); - expect(setMap).toBeCalledWith(null); - }); - }); - - describe('updating', function () { - - var parent = undefined; - - beforeEach(function () { - window.google.maps.Entity = function () { - return { - setOptions: jest.genMockFunction() - }; - }; - var Parent = React.createClass({ - displayName: 'Parent', - - getInitialState: function getInitialState() { - return { - prop: '1' - }; - }, - render: function render() { - var prop = this.state.prop; - - return React.createElement(Entity, { ref: 'child', prop: prop }); - } - }); - parent = TestUtils.renderIntoDocument(React.createElement(Parent, null)); - }); - - it('calls `setOptions` when receive new props', function () { - parent.setState({ - prop: '2' - }); - expect(parent.refs.child.entity.setOptions).toBeCalled(); - }); - - it('does not call `setOptions` when props are the same', function () { - parent.setState({ - prop: '1' - }); - expect(parent.refs.child.entity.setOptions).not.toBeCalled(); - }); - }); - - describe('getEntity', function () { - - it('returns the entity', function () { - window.google.maps.Entity = jest.genMockFunction(); - entity = TestUtils.renderIntoDocument(React.createElement(Entity, null)); - expect(entity.getEntity()).toBeDefined(); - }); - }); - - describe('binding', function () { - - it('keeps the listeners separated', function () { - window.google.maps.Entity = function () { - return { - setMap: jest.genMockFunction(), - setOptions: jest.genMockFunction() - }; - }; - var Parent = React.createClass({ - displayName: 'Parent', - - getInitialState: function getInitialState() { - return { - show: true - }; - }, - render: function render() { - return React.createElement( - 'div', - null, - React.createElement(Entity, { ref: 'child', onClick: jest.genMockFunction() }), - this.state.show && React.createElement(Entity, { onClick: jest.genMockFunction() }) - ); - } - }); - var parent = TestUtils.renderIntoDocument(React.createElement(Parent, null)); - parent.setState({ - show: false - }); - expect(parent.refs.child.listeners.length).toBe(1); - }); - }); -}); \ No newline at end of file diff --git a/dist/components/__tests__/gmaps-test.js b/dist/components/__tests__/gmaps-test.js deleted file mode 100644 index 9905dd3..0000000 --- a/dist/components/__tests__/gmaps-test.js +++ /dev/null @@ -1,181 +0,0 @@ -'use strict'; - -jest.dontMock('object-assign'); -jest.dontMock('../../mixins/listener'); -jest.dontMock('../../utils/google-maps'); -jest.dontMock('../../utils/compare-props'); -jest.dontMock('../gmaps'); - -describe('Gmaps', function () { - - var React = require('react'); - var ReactDOM = require('react-dom'); - var TestUtils = require('react-addons-test-utils'); - var GoogleMaps = require('../../utils/google-maps'); - GoogleMaps.appendScript = function () {}; - var Gmaps = require('../gmaps'); - - beforeEach(function () { - window.google = undefined; - }); - - describe('rendering', function () { - - var gmaps = undefined; - var width = '100%'; - var height = '100%'; - var style = { - backgroundColor: 'black' - }; - var className = 'className'; - var loadingMessage = 'loadingMessage'; - var onMapCreated = jest.genMockFunction(); - - beforeEach(function () { - var Child = React.createClass({ - displayName: 'Child', - - render: function render() { - return null; - } - }); - gmaps = TestUtils.renderIntoDocument(React.createElement( - Gmaps, - { - width: width, - height: height, - style: style, - className: className, - loadingMessage: loadingMessage, - onMapCreated: onMapCreated, - onClick: jest.genMockFunction() }, - React.createElement(Child, null) - )); - window.google = { - maps: { - Map: jest.genMockFunction(), - LatLng: jest.genMockFunction(), - event: { - addListener: jest.genMockFunction(), - removeListener: jest.genMockFunction() - } - } - }; - window.mapsCallback(); - }); - - it('applies the style', function () { - var node = ReactDOM.findDOMNode(gmaps); - expect(node.style.width).toBe(width); - expect(node.style.height).toBe(height); - expect(node.style.backgroundColor).toBe(style.backgroundColor); - }); - - it('applies the class name', function () { - var node = ReactDOM.findDOMNode(gmaps); - expect(node.className).toBe(className); - }); - - it('show the loading message', function () { - var node = ReactDOM.findDOMNode(gmaps); - expect(node.textContent).toBe(loadingMessage); - }); - - it('loads maps once', function () { - gmaps.componentDidMount(); - expect(window.mapsCallback).not.toBeDefined(); - }); - - it('creates a map', function () { - expect(gmaps.getMap()).not.toBe(null); - }); - - it('calls `onMapCreated`', function () { - expect(onMapCreated).toBeCalled(); - }); - - it('clones children with map', function () { - React.Children.forEach(gmaps.getChildren(), function (child) { - expect(child.props.map).toBeDefined(); - }); - }); - - it('binds events', function () { - expect(window.google.maps.event.addListener).toBeCalled(); - }); - - it('unbinds events', function () { - gmaps.componentWillUnmount(); - expect(window.google.maps.event.removeListener).toBeCalled(); - }); - }); - - describe('updating', function () { - - it('does not call `setOptions` if maps are not loaded', function () { - var gmaps = TestUtils.renderIntoDocument(React.createElement(Gmaps, null)); - expect(function () { - gmaps.componentWillReceiveProps({}); - }).not.toThrow(); - }); - - it('calls `setOptions` when receive new props', function () { - var Parent = React.createClass({ - displayName: 'Parent', - - getInitialState: function getInitialState() { - return { - prop: '1' - }; - }, - render: function render() { - var prop = this.state.prop; - - return React.createElement(Gmaps, { ref: 'gmaps', prop: prop }); - } - }); - var parent = TestUtils.renderIntoDocument(React.createElement(Parent, null)); - window.google = { - maps: { - Map: function Map() { - return { - setOptions: jest.genMockFunction() - }; - }, - LatLng: jest.genMockFunction() - } - }; - window.mapsCallback(); - parent.setState({ - prop: '2' - }); - expect(parent.refs.gmaps.getMap().setOptions).toBeCalled(); - }); - }); - - describe('unmounted', function () { - - beforeEach(function () { - GoogleMaps.fireCallbacks = jest.genMockFunction(); - }); - - it('does not fire the callback (unloaded)', function () { - var gmaps = TestUtils.renderIntoDocument(React.createElement(Gmaps, null)); - ReactDOM.unmountComponentAtNode(ReactDOM.findDOMNode(gmaps).parentNode); - expect(GoogleMaps.fireCallbacks).not.toBeCalled(); - }); - - it('does not fire the callback (loaded)', function () { - window.google = { - maps: { - event: { - removeListener: jest.genMockFunction() - } - } - }; - var gmaps = TestUtils.renderIntoDocument(React.createElement(Gmaps, null)); - ReactDOM.unmountComponentAtNode(ReactDOM.findDOMNode(gmaps).parentNode); - expect(GoogleMaps.fireCallbacks).not.toBeCalled(); - }); - }); -}); \ No newline at end of file diff --git a/dist/components/events.js b/dist/components/events.js deleted file mode 100644 index 8af17fb..0000000 --- a/dist/components/events.js +++ /dev/null @@ -1,62 +0,0 @@ -'use strict'; - -Object.defineProperty(exports, '__esModule', { - value: true -}); -var MapEvents = { - onBoundsChanged: 'bounds_changed', - onCenterChanged: 'center_changed', - onClick: 'click', - onDblClick: 'dblclick', - onDrag: 'drag', - onDragEnd: 'dragend', - onDragStart: 'dragstart', - onHeadingChanged: 'heading_changed', - onIdle: 'idle', - onMapTypeIdChanged: 'maptypeid_changed', - onMouseMove: 'mousemove', - onMouseOut: 'mouseout', - onMouseOver: 'mouseover', - onProjectionChanged: 'projection_changed', - onResize: 'resize', - onRightClick: 'rightclick', - onTilesLoaded: 'tilesloaded', - onTiltChanged: 'tilt_changed', - onZoomChanged: 'zoom_changed' -}; - -var MarkerEvents = { - onAnimationChanged: 'animation_changed', - onClick: 'click', - onClickableChanged: 'clickable_changed', - onCursorChanged: 'cursor_changed', - onDblClick: 'dblclick', - onDrag: 'drag', - onDragEnd: 'dragend', - onDraggableChanged: 'draggable_changed', - onDragStart: 'dragstart', - onFlatChanged: 'flat_changed', - onIconChanged: 'icon_changed', - onMouseDown: 'mousedown', - onMouseOut: 'mouseout', - onMouseOver: 'mouseover', - onMouseUp: 'mouseup', - onPositionChanged: 'position_changed', - onRightClick: 'rightclick', - onShapeChanged: 'shape_changed', - onTitleChanged: 'title_changed', - onVisibleChanged: 'visible_changed', - onZindexChanged: 'zindex_changed' -}; - -var InfoWindowEvents = { - onCloseClick: 'closeclick', - onContentChanged: 'content_changed', - onDOMReady: 'domready', - onPositionChanged: 'position_changed', - onZindexChanged: 'zindex_changed' -}; - -exports.MapEvents = MapEvents; -exports.MarkerEvents = MarkerEvents; -exports.InfoWindowEvents = InfoWindowEvents; \ No newline at end of file diff --git a/dist/components/infoWindow.js b/dist/components/infoWindow.js deleted file mode 100644 index 5714805..0000000 --- a/dist/components/infoWindow.js +++ /dev/null @@ -1,16 +0,0 @@ -'use strict'; - -Object.defineProperty(exports, '__esModule', { - value: true -}); - -function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { 'default': obj }; } - -var _entity = require('./entity'); - -var _entity2 = _interopRequireDefault(_entity); - -var _events = require('./events'); - -exports['default'] = (0, _entity2['default'])('InfoWindow', _events.InfoWindowEvents); -module.exports = exports['default']; \ No newline at end of file diff --git a/dist/components/listener.js b/dist/components/listener.js deleted file mode 100644 index e530321..0000000 --- a/dist/components/listener.js +++ /dev/null @@ -1,30 +0,0 @@ -"use strict"; - -Object.defineProperty(exports, "__esModule", { - value: true -}); - -var Listener = { - - listeners: [], - - addListeners: function addListeners(entity, events) { - for (var prop in this.props) { - if (this.props.hasOwnProperty(prop) && events[prop]) { - var addListener = google.maps.event.addListener; - var listener = addListener(entity, events[prop], this.props[prop]); - this.listeners.push(listener); - } - } - }, - - removeListeners: function removeListeners() { - this.listeners.forEach(function (listener) { - google.maps.event.removeListener(listener); - }); - } - -}; - -exports["default"] = Listener; -module.exports = exports["default"]; \ No newline at end of file diff --git a/dist/utils/__tests__/compare-props-test.js b/dist/utils/__tests__/compare-props-test.js deleted file mode 100644 index cb190ee..0000000 --- a/dist/utils/__tests__/compare-props-test.js +++ /dev/null @@ -1,33 +0,0 @@ -'use strict'; - -jest.dontMock('../../utils/compare-props'); - -describe('compareProps', function () { - - var compareProps = require('../../utils/compare-props'); - - it('returns false if the objects have a different number of keys', function () { - var result = compareProps({ a: 1 }, { a: 1, b: 2 }); - expect(result).toBe(false); - }); - - it('returns false if the objects have different keys', function () { - var result = compareProps({ a: 1 }, { b: 2 }); - expect(result).toBe(false); - }); - - it('returns false if the objects have different values', function () { - var result = compareProps({ a: 1 }, { a: 2 }); - expect(result).toBe(false); - }); - - it('returns true if the objects have the same keys/values', function () { - var result = compareProps({ a: 1 }, { a: 1 }); - expect(result).toBe(true); - }); - - it('ignores the `children` property', function () { - var result = compareProps({ a: 1, children: 1 }, { a: 1, children: 2 }); - expect(result).toBe(true); - }); -}); \ No newline at end of file diff --git a/dist/utils/__tests__/google-maps-test.js b/dist/utils/__tests__/google-maps-test.js deleted file mode 100644 index 9950b48..0000000 --- a/dist/utils/__tests__/google-maps-test.js +++ /dev/null @@ -1,59 +0,0 @@ -'use strict'; - -jest.dontMock('querystring'); -jest.dontMock('../../utils/google-maps'); - -describe('GoogleMaps', function () { - - var GoogleMaps = undefined; - - beforeEach(function () { - window.google = undefined; - window.mapsCallback = undefined; - GoogleMaps = require('../../utils/google-maps'); - }); - - it('registers the callbacks if google does not exist', function () { - expect(GoogleMaps.callbacks.length).toBe(0); - GoogleMaps.load(null, function () {}); - expect(GoogleMaps.callbacks.length).toBe(1); - }); - - it('appends the script if not appended', function () { - expect(GoogleMaps.appended).toBe(false); - GoogleMaps.load(null, function () {}); - expect(GoogleMaps.appended).toBe(true); - }); - - it('fires the callback if google exists', function () { - window.google = {}; - var callback = jest.genMockFunction(); - GoogleMaps.load(null, callback); - jest.runAllTimers(); - expect(callback).toBeCalled(); - }); - - it('fires the callbacks on mapsCallback', function () { - var callback = jest.genMockFunction(); - GoogleMaps.load(null, callback); - window.mapsCallback(); - expect(callback).toBeCalled(); - }); - - it('returns the src', function () { - var expected = GoogleMaps.getSrc({ - param0: 'param0', - param1: 'param1' - }); - var actual = 'https://maps.googleapis.com/maps/api/js'; - actual += '?callback=mapsCallback&'; - actual += 'param0=param0¶m1=param1'; - expect(expected).toBe(actual); - }); - - it('deletes the global mapsCallback', function () { - window.mapsCallback = {}; - GoogleMaps.mapsCallback(); - expect(window.mapsCallback).toBeUndefined(); - }); -}); \ No newline at end of file diff --git a/dist/utils/__tests__/google-maps.js b/dist/utils/__tests__/google-maps.js deleted file mode 100644 index 679c8e9..0000000 --- a/dist/utils/__tests__/google-maps.js +++ /dev/null @@ -1,59 +0,0 @@ -'use strict'; - -jest.dontMock('querystring'); -jest.dontMock('../../utils/google-maps'); - -describe('GoogleMaps', function () { - - var GoogleMaps = undefined; - - beforeEach(function () { - window.google = undefined; - window.mapsCallback = undefined; - GoogleMaps = require('../../utils/google-maps'); - }); - - it('registers the callbacks if google does not exist', function () { - expect(GoogleMaps.callbacks.length).toBe(0); - GoogleMaps.load(null, function () {}); - expect(GoogleMaps.callbacks.length).toBe(1); - }); - - it('adds the script if not added', function () { - expect(GoogleMaps.added).toBe(false); - GoogleMaps.load(null, function () {}); - expect(GoogleMaps.added).toBe(true); - }); - - it('fires the callback if google exists', function () { - window.google = {}; - var callback = jest.genMockFunction(); - GoogleMaps.load(null, callback); - jest.runAllTimers(); - expect(callback).toBeCalled(); - }); - - it('fires the callbacks on mapsCallback', function () { - var callback = jest.genMockFunction(); - GoogleMaps.load(null, callback); - window.mapsCallback(); - expect(callback).toBeCalled(); - }); - - it('returns the src', function () { - var expected = GoogleMaps.getSrc({ - param0: 'param0', - param1: 'param1' - }); - var actual = 'https://maps.googleapis.com/maps/api/js'; - actual += '?callback=mapsCallback&'; - actual += 'param0=param0¶m1=param1'; - expect(expected).toBe(actual); - }); - - it('deletes the global mapsCallback', function () { - window.mapsCallback = {}; - GoogleMaps.mapsCallback(); - expect(window.mapsCallback).toBeUndefined(); - }); -}); \ No newline at end of file diff --git a/dist/utils/__tests__/index.js b/dist/utils/__tests__/index.js deleted file mode 100644 index 95919e7..0000000 --- a/dist/utils/__tests__/index.js +++ /dev/null @@ -1,59 +0,0 @@ -'use strict'; - -jest.dontMock('querystring'); -jest.dontMock('../../utils'); - -describe('Utils', function () { - - var Utils = undefined; - - beforeEach(function () { - window.google = undefined; - window.mapsCallback = undefined; - Utils = require('../../utils'); - }); - - it('registers the callbacks if google does not exist', function () { - expect(Utils.callbacks.length).toBe(0); - Utils.loadMaps(null, function () {}); - expect(Utils.callbacks.length).toBe(1); - }); - - it('adds the script if not added', function () { - expect(Utils.added).toBe(false); - Utils.loadMaps(null, function () {}); - expect(Utils.added).toBe(true); - }); - - it('fires the callback if google exists', function () { - window.google = {}; - var callback = jest.genMockFunction(); - Utils.loadMaps(null, callback); - jest.runAllTimers(); - expect(callback).toBeCalled(); - }); - - it('fires the callbacks on mapsCallback', function () { - var callback = jest.genMockFunction(); - Utils.loadMaps(null, callback); - window.mapsCallback(); - expect(callback).toBeCalled(); - }); - - it('returns the src', function () { - var expected = Utils.getSrc({ - param0: 'param0', - param1: 'param1' - }); - var actual = 'https://maps.googleapis.com/maps/api/js'; - actual += '?callback=mapsCallback&'; - actual += 'param0=param0¶m1=param1'; - expect(expected).toBe(actual); - }); - - it('deletes the global mapsCallback', function () { - window.mapsCallback = {}; - Utils.mapsCallback(); - expect(window.mapsCallback).toBeUndefined(); - }); -}); \ No newline at end of file diff --git a/dist/utils/index.js b/dist/utils/index.js deleted file mode 100644 index 11f54a3..0000000 --- a/dist/utils/index.js +++ /dev/null @@ -1,55 +0,0 @@ -'use strict'; - -Object.defineProperty(exports, '__esModule', { - value: true -}); - -function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { 'default': obj }; } - -var _querystring = require('querystring'); - -var _querystring2 = _interopRequireDefault(_querystring); - -exports['default'] = { - - callbacks: [], - - added: false, - - loadMaps: function loadMaps(params, callback) { - if (!window.google) { - this.callbacks.push(callback); - if (!this.added) { - window.mapsCallback = this.mapsCallback.bind(this); - this.addScript(params); - } - } else { - setTimeout(callback); - } - }, - - getSrc: function getSrc(params) { - var src = 'https://maps.googleapis.com/maps/api/js'; - src += '?callback=mapsCallback&'; - src += _querystring2['default'].stringify(params); - return src; - }, - - addScript: function addScript(params) { - var src = this.getSrc(params); - var script = document.createElement('script'); - script.setAttribute('src', src); - document.head.appendChild(script); - this.added = true; - }, - - mapsCallback: function mapsCallback() { - window.mapsCallback = undefined;; - this.callbacks.forEach(function (callback) { - return callback(); - }); - this.callbacks = []; - } - -}; -module.exports = exports['default']; \ No newline at end of file diff --git a/package.json b/package.json index 7abb141..e6c7f82 100644 --- a/package.json +++ b/package.json @@ -5,7 +5,7 @@ "main": "dist/index.js", "scripts": { "prepublish": "npm run build", - "build": "babel ./src --out-dir ./dist", + "build": "babel ./src --out-dir ./dist --ignore __tests__", "pretest": "eslint ./src", "test": "jest", "demo": "browserify -t babelify ./demo/index.js -o ./demo/build.js",