Skip to content

Commit

Permalink
Merge pull request #2153 from CartoDB/2089-interactivity-cartodbid
Browse files Browse the repository at this point in the history
Fix interactivity when only 'cartodb_id' is selected
  • Loading branch information
rubenmoya authored Jul 5, 2018
2 parents a87594d + 0a260ce commit 80dca10
Show file tree
Hide file tree
Showing 3 changed files with 52 additions and 2 deletions.
3 changes: 1 addition & 2 deletions src/geo/map/cartodb-layer.js
Original file line number Diff line number Diff line change
Expand Up @@ -74,8 +74,7 @@ var CartoDBLayer = LayerModelBase.extend({
},

isInteractive: function () {
// By default it has one field (cartodb_id)
return this.getInteractiveColumnNames().length > 1;
return this._hasInfowindowFields() || this._hasTooltipFields();
},

_hasInfowindowFields: function () {
Expand Down
24 changes: 24 additions & 0 deletions test/spec/api/v4/layer/layer.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -625,6 +625,30 @@ describe('api/v4/layer', function () {
});
});

describe('.isInteractive', function () {
it('returns true if layer has featureClickColumns', function () {
const layer = new carto.layer.Layer(source, style, {
featureClickColumns: ['cartodb_id']
});

expect(layer.isInteractive()).toBe(true);
});

it('returns true if layer has featureOverColumns', function () {
const layer = new carto.layer.Layer(source, style, {
featureOverColumns: ['cartodb_id']
});

expect(layer.isInteractive()).toBe(true);
});

it('returns false if layer doesn\'t have getFeatureClickColumns or getFeatureHoverColumns', function () {
const layer = new carto.layer.Layer(source, style);

expect(layer.isInteractive()).toBe(false);
});
});

xit('should update "internalmodel.cartocss" when the style is updated', function (done) {
var client = new carto.Client({
apiKey: '84fdbd587e4a942510270a48e843b4c1baa11e18',
Expand Down
27 changes: 27 additions & 0 deletions test/spec/geo/map/cartodb-layer.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,33 @@ describe('geo/map/cartodb-layer', function () {
});
});

describe('.isInteractive', function () {
var layer, infowindowSpy, tooltipSpy;

beforeEach(function () {
layer = new CartoDBLayer({}, { engine: engineMock });

infowindowSpy = spyOn(layer, '_hasInfowindowFields');
tooltipSpy = spyOn(layer, '_hasTooltipFields');
});

it('returns true if there are selected fields', function () {
infowindowSpy.and.returnValue(true);
tooltipSpy.and.returnValue(false);
expect(layer.isInteractive()).toBe(true);

infowindowSpy.and.returnValue(false);
tooltipSpy.and.returnValue(true);
expect(layer.isInteractive()).toBe(true);
});

it('returns true if there are selected fields', function () {
infowindowSpy.and.returnValue(false);
tooltipSpy.and.returnValue(false);
expect(layer.isInteractive()).toBe(false);
});
});

describe('.getInteractiveColumnNames', function () {
it("should return 'cartodb_id' and the names of the fields for infowindows and tooltips with no duplicates", function () {
this.layer = new CartoDBLayer({
Expand Down

0 comments on commit 80dca10

Please sign in to comment.