Skip to content

Commit

Permalink
Merge e0069e6 into 1381162
Browse files Browse the repository at this point in the history
  • Loading branch information
sprocketc committed Jan 25, 2016
2 parents 1381162 + e0069e6 commit 78f1008
Show file tree
Hide file tree
Showing 2 changed files with 99 additions and 2 deletions.
25 changes: 23 additions & 2 deletions addon/components/g-map-infowindow.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ const GMapInfowindowComponent = Ember.Component.extend({
this.setPosition();
this.setMap();
this.setMarker();
this.setOptions();
},

willDestroyElement() {
Expand All @@ -43,10 +44,30 @@ const GMapInfowindowComponent = Ember.Component.extend({
}
},

optionsChanged: observer('disableAutoPan', 'maxWidth', 'pixelOffset', function() {
run.once(this, 'setOptions');
}),

setOptions() {
const infowindow = this.get('infowindow');
const options = ['disableAutoPan', 'maxWidth', 'pixelOffset'];
const infoWindowOptions = {};

for (let i = 0; i < options.length; i++) {
const value = this.get(options[i]);
if (isPresent(value)) {
infoWindowOptions[options[i]] = value;
}
}

if (isPresent(infowindow) && Object.keys(infoWindowOptions).length !== 0) {
infowindow.setOptions(infoWindowOptions);
}
},

buildInfowindow() {
const infowindow = new google.maps.InfoWindow({
content: this.get('element'),
disableAutoPan: true
content: this.get('element')
});

if (isPresent(this.get('attrs.onClose'))) {
Expand Down
76 changes: 76 additions & 0 deletions tests/unit/components/g-map-infowindow-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ moduleForComponent('g-map-infowindow', 'Unit | Component | g map infowindow', {
beforeEach() {
fakeInfowindowObject = {
setPosition: sinon.stub(),
setOptions: sinon.stub(),
open: sinon.stub(),
close: sinon.stub(),
addListener: sinon.stub()
Expand Down Expand Up @@ -66,6 +67,12 @@ test('it triggers `setMarker` on `didInsertElement` event', function() {
sinon.assert.calledOnce(component.setMarker);
});

test('it triggers `setOptions` on `didInsertElement` event', function() {
component.setOptions = sinon.stub();
component.trigger('didInsertElement');
sinon.assert.calledOnce(component.setOptions);
});

test('it triggers `close` on `willDestroyElement` event', function() {
component.close = sinon.stub();
component.trigger('willDestroyElement');
Expand Down Expand Up @@ -168,6 +175,75 @@ test('it triggers `setMarker` on `mapContext.marker` change', function() {
sinon.assert.calledOnce(component.setMarker);
});

test('it triggers `setOptions` on `disableAutoPan` change', function() {
component.setOptions = sinon.spy();
run(() => component.set('disableAutoPan', true));
sinon.assert.calledOnce(component.setOptions);
});

test('it triggers `setOptions` on `maxWidth` change', function() {
component.setOptions = sinon.spy();
run(() => component.set('maxWidth', 200));
sinon.assert.calledOnce(component.setOptions);
});

test('it triggers `setOptions` on `pixelOffset` change', function() {
component.setOptions = sinon.spy();
run(() => component.set('pixelOffset', { width: 10, height: 10 }));
sinon.assert.calledOnce(component.setOptions);
});

test('it doesn\'t call `setOptions` of InfoWindow on `setOptions` when no option present', function() {
fakeInfowindowObject.setOptions = sinon.stub();

run(() => component.setProperties({
infowindow: fakeInfowindowObject
}));
run(() => component.setOptions());
sinon.assert.notCalled(fakeInfowindowObject.setOptions);
});

test('it calls `setOptions` of InfoWindow on `setOptions` with `disableAutoPan` present', function() {
fakeInfowindowObject.setOptions = sinon.stub();

run(() => component.setProperties({
disableAutoPan: true,
infowindow: fakeInfowindowObject
}));
sinon.assert.calledOnce(fakeInfowindowObject.setOptions);
});

test('it calls `setOptions` of InfoWindow on `setOptions` with `maxWidth` present', function() {
fakeInfowindowObject.setOptions = sinon.stub();

run(() => component.setProperties({
maxWidth: 200,
infowindow: fakeInfowindowObject
}));
sinon.assert.calledOnce(fakeInfowindowObject.setOptions);
});

test('it calls `setOptions` of InfoWindow on `setOptions` with `pixelOffset` present', function() {
fakeInfowindowObject.setOptions = sinon.stub();

run(() => component.setProperties({
pixelOffset: { width: 10, height: 10 },
infowindow: fakeInfowindowObject
}));
sinon.assert.calledOnce(fakeInfowindowObject.setOptions);
});

test('it calls `setOptions` of InfoWindow on `setOptions` once with more than one option present', function() {
fakeInfowindowObject.setOptions = sinon.stub();

run(() => component.setProperties({
disableAutoPan: true,
maxWidth: 200,
infowindow: fakeInfowindowObject
}));
sinon.assert.calledOnce(fakeInfowindowObject.setOptions);
});

test('it triggers `setPosition` on `lat` change', function() {
component.setPosition = sinon.stub();
run(() => component.set('lat', 14));
Expand Down

0 comments on commit 78f1008

Please sign in to comment.