Skip to content

Commit

Permalink
Merge pull request #21 from sprocketc/labels
Browse files Browse the repository at this point in the history
Marker label support
  • Loading branch information
asennikov committed Jan 23, 2016
2 parents 068cfe6 + 709a2b4 commit 1bdb12f
Show file tree
Hide file tree
Showing 3 changed files with 55 additions and 2 deletions.
14 changes: 14 additions & 0 deletions addon/components/g-map-marker.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ const GMapMarkerComponent = Ember.Component.extend({
}
this.setPosition();
this.setIcon();
this.setLabel();
this.setTitle();
this.setMap();
this.setOnClick();
Expand Down Expand Up @@ -104,6 +105,19 @@ const GMapMarkerComponent = Ember.Component.extend({
}
},

labelChanged: observer('label', function() {
run.once(this, 'setLabel');
}),

setLabel() {
const marker = this.get('marker');
const label = this.get('label');

if (isPresent(marker) && isPresent(label)) {
marker.setLabel(label);
}
},

titleChanged: observer('title', function() {
run.once(this, 'setTitle');
}),
Expand Down
4 changes: 2 additions & 2 deletions addon/templates/components/g-map-address-marker.hbs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{{#if hasBlock}}
{{#g-map-marker mapContext lat=lat lng=lng icon=icon group=group title=title as |markerContext|}}
{{#g-map-marker mapContext lat=lat lng=lng icon=icon label=label group=group title=title as |markerContext|}}
{{yield markerContext}}
{{/g-map-marker}}
{{else}}
{{g-map-marker mapContext lat=lat lng=lng icon=icon title=title group=group}}
{{g-map-marker mapContext lat=lat lng=lng icon=icon label=label title=title group=group}}
{{/if}}
39 changes: 39 additions & 0 deletions tests/unit/components/g-map-marker-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ moduleForComponent('g-map-marker', 'Unit | Component | g map marker', {
fakeMarkerObject = {
setPosition: sinon.stub(),
setIcon: sinon.stub(),
setLabel: sinon.stub(),
setTitle: sinon.stub(),
setMap: sinon.stub(),
addListener: sinon.stub()
Expand Down Expand Up @@ -215,6 +216,44 @@ test('it doesn\'t call `setIcon` of google marker on `setIcon` when no icon pres
sinon.assert.notCalled(fakeMarkerObject.setIcon);
});

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

test('it triggers `setLabel` on `label` change', function() {
component.setLabel = sinon.stub();
run(() => component.set('label', 'A'));
sinon.assert.calledOnce(component.setLabel);
});

test('it calls `setLabel` of google marker on `setLabel` with label present', function() {
run(() => component.setProperties({
label: 'A',
marker: fakeMarkerObject
}));

fakeMarkerObject.setLabel = sinon.stub();

run(() => component.setLabel());

sinon.assert.calledOnce(fakeMarkerObject.setLabel);
sinon.assert.calledWith(fakeMarkerObject.setLabel, 'A');
});

test('it doesn\'t call `setLabel` of google marker on `setLabel` when no label present', function() {
fakeMarkerObject.setLabel = sinon.stub();

run(() => component.setProperties({
label: undefined,
marker: fakeMarkerObject
}));
run(() => component.setLabel());

sinon.assert.notCalled(fakeMarkerObject.setLabel);
});

test('it triggers `setTitle` on `didInsertElement` event', function() {
component.setTitle = sinon.stub();
component.trigger('didInsertElement');
Expand Down

0 comments on commit 1bdb12f

Please sign in to comment.