@yaga/leaflet-ng2
Version:
Angular2 module for Leaflet
154 lines • 6.44 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
const chai_1 = require("chai");
const leaflet_1 = require("leaflet");
const index_1 = require("./index");
describe("Layer-Group Directive", () => {
let map;
let layer;
beforeEach(() => {
map = new index_1.MapComponent({ nativeElement: document.createElement("div") }, new index_1.LayerGroupProvider(), new index_1.MapProvider());
map._size = leaflet_1.point(100, 100);
map._pixelOrigin = leaflet_1.point(50, 50);
layer = new index_1.LayerGroupDirective({ ref: map }, {}, {});
});
describe("[(display)]", () => {
it("should remove layer when not displaying", () => {
layer.display = false;
chai_1.expect(layer._map).to.equal(null);
});
it("should re-add layer when display is true again", () => {
layer.display = false;
layer.display = true;
chai_1.expect(layer._map).to.equal(layer.parentLayerGroupProvider.ref);
});
it("should set to false by removing from map", (done) => {
setTimeout(() => {
layer.displayChange.subscribe((val) => {
chai_1.expect(val).to.equal(false);
chai_1.expect(layer.display).to.equal(false);
done();
});
map.removeLayer(layer);
}, 0);
});
it("should set to true when adding to map again", (done) => {
map.removeLayer(layer);
layer.displayChange.subscribe((val) => {
chai_1.expect(val).to.equal(true);
chai_1.expect(layer.display).to.equal(true);
done();
});
map.addLayer(layer);
});
});
// Events
describe("(add)", () => {
it("should fire event in Angular when firing event in Leaflet", (done) => {
const testHandle = {};
const testEvent = { testHandle };
layer.addEvent.subscribe((event) => {
chai_1.expect(event.testHandle).to.equal(testEvent.testHandle);
return done();
});
layer.fire("add", testEvent);
});
});
describe("(remove)", () => {
it("should fire event in Angular when firing event in Leaflet", (done) => {
const testHandle = {};
const testEvent = { testHandle };
layer.removeEvent.subscribe((event) => {
chai_1.expect(event.testHandle).to.equal(testEvent.testHandle);
return done();
});
layer.fire("remove", testEvent);
});
});
describe("(popupopen)", () => {
it("should fire event in Angular when firing event in Leaflet", (done) => {
const testHandle = {};
const testEvent = { testHandle };
layer.popupopenEvent.subscribe((event) => {
chai_1.expect(event.testHandle).to.equal(testEvent.testHandle);
return done();
});
layer.fire("popupopen", testEvent);
});
});
describe("(popupclose)", () => {
it("should fire event in Angular when firing event in Leaflet", (done) => {
const testHandle = {};
const testEvent = { testHandle };
layer.popupcloseEvent.subscribe((event) => {
chai_1.expect(event.testHandle).to.equal(testEvent.testHandle);
return done();
});
layer.fire("popupclose", testEvent);
});
});
describe("(tooltipopen)", () => {
it("should fire event in Angular when firing event in Leaflet", (done) => {
const testHandle = {};
const testEvent = { testHandle };
layer.tooltipopenEvent.subscribe((event) => {
chai_1.expect(event.testHandle).to.equal(testEvent.testHandle);
return done();
});
layer.fire("tooltipopen", testEvent);
});
});
describe("(tooltipclose)", () => {
it("should fire event in Angular when firing event in Leaflet", (done) => {
const testHandle = {};
const testEvent = { testHandle };
layer.tooltipcloseEvent.subscribe((event) => {
chai_1.expect(event.testHandle).to.equal(testEvent.testHandle);
return done();
});
layer.fire("tooltipclose", testEvent);
});
});
// Inputs
describe("[attribution]", () => {
let attributionControl;
beforeEach(() => {
attributionControl = new index_1.AttributionControlDirective({ ref: map });
});
it("should be changed in Leaflet when changing in Angular", () => {
const val = "Test attribution";
layer.attribution = val;
// TODO: fix in official type definition
chai_1.expect(layer.options.attribution).to.equal(val);
chai_1.expect(attributionControl.attributions).to.contain(val);
});
it("should be changed in Angular when changing in Angular", () => {
const val = "Test attribution";
layer.attribution = val;
chai_1.expect(layer.attribution).to.equal(val);
chai_1.expect(attributionControl.attributions).to.contain(val);
});
it("should remove old attribution when changing in Angular", () => {
const oldVal = "Old test attribution";
const newVal = "Test attribution";
layer.attribution = oldVal;
layer.attribution = newVal;
chai_1.expect(attributionControl.attributions).to.contain(newVal);
chai_1.expect(attributionControl.attributions).to.not.contain(oldVal);
});
});
describe("Destroying a Layer-Group Directive", () => {
it("should remove Tile-Layer Directive from map on destroy", () => {
/* istanbul ignore if */
if (!map.hasLayer(layer)) {
throw new Error("The layer is not part of the map before destroying");
}
layer.ngOnDestroy();
/* istanbul ignore if */
if (map.hasLayer(layer)) {
throw new Error("The layer is still part of the map after destroying");
}
});
});
});
//# sourceMappingURL=layer-group.directive.spec.js.map