Skip to content

Commit

Permalink
getEntity method
Browse files Browse the repository at this point in the history
  • Loading branch information
MicheleBertoli committed Aug 13, 2015
1 parent 035287b commit bc32d37
Show file tree
Hide file tree
Showing 9 changed files with 50 additions and 23 deletions.
3 changes: 2 additions & 1 deletion .eslintrc
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,8 @@
"react/jsx-uses-vars": 2,
"react/react-in-jsx-scope": 2,
"no-var": 2,
"max-len": [2, 80]
"max-len": [2, 80],
"semi": 2
},
"plugins": [
"react"
Expand Down
15 changes: 11 additions & 4 deletions dist/components/__tests__/entity-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ describe('Entity', function () {
onClick: 'click'
});

var entity = undefined;

beforeEach(function () {
window.google = {
maps: {
Expand All @@ -26,8 +28,6 @@ describe('Entity', function () {

describe('mounting', function () {

var entity = undefined;

beforeEach(function () {
window.google.maps.Entity = jest.genMockFunction();
entity = TestUtils.renderIntoDocument(React.createElement(Entity, { onClick: jest.genMockFunction() }));
Expand All @@ -49,8 +49,6 @@ describe('Entity', function () {

describe('unmounting', function () {

var entity = undefined;

beforeEach(function () {
window.google.maps.Entity = function () {
return {
Expand Down Expand Up @@ -99,4 +97,13 @@ describe('Entity', function () {
expect(parent.refs.child.entity.setOptions).toBeCalled();
});
});

describe('getEntity', function () {

it('calls `setOptions` when receive new props', function () {
window.google.maps.Entity = jest.genMockFunction();
entity = TestUtils.renderIntoDocument(React.createElement(Entity, null));
expect(entity.getEntity()).toBeDefined();
});
});
});
4 changes: 3 additions & 1 deletion dist/components/__tests__/gmaps-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,9 @@ describe('Gmaps', function () {
});

it('clones children with map', function () {
expect(gmaps.getChildren()['.0'].props.map).toBeDefined();
React.Children.forEach(gmaps.getChildren(), function (child) {
expect(child.props.map).toBeDefined();
});
});

it('binds events', function () {
Expand Down
4 changes: 4 additions & 0 deletions dist/components/entity.js
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,10 @@ exports['default'] = function (name, latLngProp, events) {
this.entity = null;
},

getEntity: function getEntity() {
return this.entity;
},

getOptions: function getOptions(props) {
return _extends({}, props, _defineProperty({}, latLngProp, new google.maps.LatLng(props.lat, props.lng)));
},
Expand Down
7 changes: 2 additions & 5 deletions dist/components/gmaps.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,6 @@ var _react = require('react');

var _react2 = _interopRequireDefault(_react);

var _reactLibCloneWithProps = require('react/lib/cloneWithProps');

var _reactLibCloneWithProps2 = _interopRequireDefault(_reactLibCloneWithProps);

var _reactLibObjectAssign = require('react/lib/Object.assign');

var _reactLibObjectAssign2 = _interopRequireDefault(_reactLibObjectAssign);
Expand Down Expand Up @@ -91,7 +87,8 @@ var Gmaps = _react2['default'].createClass({
if (!_react2['default'].isValidElement(child)) {
return child;
}
return (0, _reactLibCloneWithProps2['default'])(child, {
return _react2['default'].cloneElement(child, {
ref: child.ref,
map: _this.map
});
});
Expand Down
24 changes: 17 additions & 7 deletions src/components/__tests__/entity-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ describe('Entity', () => {
onClick: 'click'
});

let entity;

beforeEach(() => {
window.google = {
maps: {
Expand All @@ -24,8 +26,6 @@ describe('Entity', () => {

describe('mounting', () => {

let entity;

beforeEach(() => {
window.google.maps.Entity = jest.genMockFunction();
entity = TestUtils.renderIntoDocument(
Expand All @@ -50,13 +50,11 @@ describe('Entity', () => {

describe('unmounting', () => {

let entity;

beforeEach(() => {
window.google.maps.Entity = () => {
return {
setMap: jest.genMockFunction()
}
};
};
entity = TestUtils.renderIntoDocument(
<Entity onClick={jest.genMockFunction()} />
Expand All @@ -82,7 +80,7 @@ describe('Entity', () => {
window.google.maps.Entity = () => {
return {
setOptions: jest.genMockFunction()
}
};
};
const Parent = React.createClass({
getInitialState() {
Expand All @@ -91,7 +89,7 @@ describe('Entity', () => {
};
},
render() {
return <Entity ref="child" />
return <Entity ref="child" />;
}
});
const parent = TestUtils.renderIntoDocument(<Parent />);
Expand All @@ -103,5 +101,17 @@ describe('Entity', () => {

});

describe('getEntity', () => {

it('calls `setOptions` when receive new props', () => {
window.google.maps.Entity = jest.genMockFunction();
entity = TestUtils.renderIntoDocument(
<Entity />
);
expect(entity.getEntity()).toBeDefined();
});

});

});

4 changes: 3 additions & 1 deletion src/components/__tests__/gmaps-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,9 @@ describe('Gmaps', () => {
});

it('clones children with map', () => {
expect(gmaps.getChildren()['.0'].props.map).toBeDefined();
React.Children.forEach(gmaps.getChildren(), (child) => {
expect(child.props.map).toBeDefined();
});
});

it('binds events', () => {
Expand Down
6 changes: 5 additions & 1 deletion src/components/entity.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,10 @@ export default (name, latLngProp, events) => {
this.entity = null;
},

getEntity() {
return this.entity;
},

getOptions(props) {
return {
...props,
Expand All @@ -37,4 +41,4 @@ export default (name, latLngProp, events) => {
}

});
}
};
6 changes: 3 additions & 3 deletions src/components/gmaps.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import React from 'react';
import cloneWithProps from 'react/lib/cloneWithProps';
import assign from 'react/lib/Object.assign';
import MapEvents from '../events/map';
import Listener from '../mixins/listener';
Expand All @@ -13,7 +12,7 @@ const Gmaps = React.createClass({
getInitialState() {
return {
isMapCreated: false
}
};
},

componentDidMount() {
Expand Down Expand Up @@ -66,7 +65,8 @@ const Gmaps = React.createClass({
if (!React.isValidElement(child)) {
return child;
}
return cloneWithProps(child, {
return React.cloneElement(child, {
ref: child.ref,
map: this.map
});
});
Expand Down

0 comments on commit bc32d37

Please sign in to comment.