@yaga/leaflet-ng2
Version:
Angular2 module for Leaflet
254 lines • 10.6 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
const chai_1 = require("chai");
const leaflet_1 = require("leaflet");
const index_1 = require("./index");
const spec_1 = require("./spec");
describe("Zoom-Control Directive", () => {
let map;
let control;
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);
control = new index_1.ZoomControlDirective({ ref: map });
});
describe("[(display)]", () => {
it("should set DOM container style to display:none when not displaying", () => {
control.display = false;
chai_1.expect(control.getContainer().style.display).to.equal("none");
});
it("should reset DOM container style when display is true again", () => {
control.display = false;
control.display = true;
chai_1.expect(control.getContainer().style.display).to.not.equal("none");
});
it("should set to false by removing from map", (done) => {
control.displayChange.subscribe((val) => {
chai_1.expect(val).to.equal(false);
chai_1.expect(control.display).to.equal(false);
done();
});
map.removeControl(control);
});
// it.skip("should set to true when adding to map again", (done: Mocha.Done) => {
// /* tslint:disable */
// control.displayChange.subscribe((x) => { console.log("aslkdnasnldknaskldnlkd ", x); });
// map.removeControl(control);
// setTimeout(() => {
// control.displayChange.subscribe((val: boolean) => {
// expect(val).to.equal(true);
// expect(control.display).to.equal(true);
// done();
// });
// map.addControl(control);
// }, 0);
// });
});
describe("[(position)]", () => {
it("should be changed in Leaflet when changing in Angular", () => {
const val = "topright";
control.position = val;
chai_1.expect(control.getPosition()).to.equal(val);
});
it("should be changed in Angular when changing in Angular", () => {
const val = "topright";
control.position = val;
chai_1.expect(control.position).to.equal(val);
});
it("should be changed in Angular when changing in Leaflet", () => {
const val = "topright";
control.setPosition(val);
chai_1.expect(control.position).to.equal(val);
});
it("should fire an event when changing in Angular", (done) => {
const val = "topleft";
control.positionChange.subscribe((eventVal) => {
chai_1.expect(eventVal).to.equal(val);
return done();
});
control.position = val;
});
it("should fire an event when changing in Leaflet", (done) => {
const val = "topleft";
control.positionChange.subscribe((eventVal) => {
chai_1.expect(eventVal).to.equal(val);
return done();
});
control.setPosition(val);
});
});
describe("[opacity]", () => {
it("should be changed in Leaflet when changing in Angular", () => {
const val = spec_1.randomNumber();
control.opacity = val;
chai_1.expect(control.getContainer().style.opacity).to.equal(val.toString());
});
it("should be changed in Angular when changing in Angular", () => {
const val = spec_1.randomNumber();
control.opacity = val;
chai_1.expect(control.opacity).to.equal(val);
});
});
describe("[zIndex]", () => {
it("should be changed in Leaflet when changing in Angular", () => {
const val = spec_1.randomNumber(255, 1, 0);
control.zIndex = val;
chai_1.expect(control.getContainer().style.zIndex).to.equal(val.toString());
});
it("should be changed in Angular when changing in Angular", () => {
const val = spec_1.randomNumber(255, 1, 0);
control.zIndex = val;
chai_1.expect(control.zIndex).to.equal(val);
});
});
describe("[zoomInText]", () => {
const TEST_VALUE = "test-caption";
it("should be changed in Leaflet when changing in Angular", () => {
control.zoomInText = TEST_VALUE;
chai_1.expect(control.options.zoomInText).to.equal(TEST_VALUE);
chai_1.expect(control._zoomInButton.textContent).to.equal(TEST_VALUE);
});
it("should be changed in Angular when changing in Angular", () => {
control.zoomInText = TEST_VALUE;
chai_1.expect(control.zoomInText).to.equal(TEST_VALUE);
});
});
describe("[zoomOutText]", () => {
const TEST_VALUE = "test-caption";
it("should be changed in Leaflet when changing in Angular", () => {
control.zoomOutText = TEST_VALUE;
chai_1.expect(control.options.zoomOutText).to.equal(TEST_VALUE);
chai_1.expect(control._zoomOutButton.textContent).to.equal(TEST_VALUE);
});
it("should be changed in Angular when changing in Angular", () => {
control.zoomOutText = TEST_VALUE;
chai_1.expect(control.zoomOutText).to.equal(TEST_VALUE);
});
});
describe("[zoomInTitle]", () => {
const TEST_VALUE = "test-caption";
it("should be changed in Leaflet when changing in Angular", () => {
control.zoomInTitle = TEST_VALUE;
chai_1.expect(control.options.zoomInTitle).to.equal(TEST_VALUE);
chai_1.expect(control._zoomInButton.getAttribute("title")).to.equal(TEST_VALUE);
});
it("should be changed in Angular when changing in Angular", () => {
control.zoomInTitle = TEST_VALUE;
chai_1.expect(control.zoomInTitle).to.equal(TEST_VALUE);
});
});
describe("[zoomOutTitle]", () => {
const TEST_VALUE = "test-caption";
it("should be changed in Leaflet when changing in Angular", () => {
control.zoomOutTitle = TEST_VALUE;
chai_1.expect(control.options.zoomOutTitle).to.equal(TEST_VALUE);
chai_1.expect(control._zoomOutButton.getAttribute("title")).to.equal(TEST_VALUE);
});
it("should be changed in Angular when changing in Angular", () => {
control.zoomOutTitle = TEST_VALUE;
chai_1.expect(control.zoomOutTitle).to.equal(TEST_VALUE);
});
});
// Events
describe("(add)", () => {
it("should fire an event when adding to map", (done) => {
map.removeControl(control);
control.addEvent.subscribe(() => {
done();
});
map.addControl(control);
});
});
describe("(remove)", () => {
it("should fire an event when removing from map", (done) => {
control.removeEvent.subscribe(() => {
done();
});
map.removeControl(control);
});
});
describe("(click)", () => {
it("should fire an event when firing event from DOM", (done) => {
control.clickEvent.subscribe(() => {
done();
});
control.getContainer().dispatchEvent(new MouseEvent("click", {
clientX: 3,
clientY: 4,
screenX: 1,
screenY: 2,
}));
});
});
describe("(dblclick)", () => {
it("should fire an event when firing event from DOM", (done) => {
control.dblclickEvent.subscribe(() => {
done();
});
control.getContainer().dispatchEvent(new MouseEvent("dblclick", {
clientX: 3,
clientY: 4,
screenX: 1,
screenY: 2,
}));
});
});
describe("(mousedown)", () => {
it("should fire an event when firing event from DOM", (done) => {
control.mousedownEvent.subscribe(() => {
done();
});
control.getContainer().dispatchEvent(new MouseEvent("mousedown", {
clientX: 3,
clientY: 4,
screenX: 1,
screenY: 2,
}));
});
});
describe("(mouseover)", () => {
it("should fire an event when firing event from DOM", (done) => {
control.mouseoverEvent.subscribe(() => {
done();
});
control.getContainer().dispatchEvent(new MouseEvent("mouseover", {
clientX: 3,
clientY: 4,
screenX: 1,
screenY: 2,
}));
});
});
describe("(mouseout)", () => {
it("should fire an event when firing event from DOM", (done) => {
control.mouseoutEvent.subscribe(() => {
done();
});
control.getContainer().dispatchEvent(new MouseEvent("mouseout", {
clientX: 3,
clientY: 4,
screenX: 1,
screenY: 2,
}));
});
});
describe("Destroying a Zoom Control Directive", () => {
it("should remove Tile-Layer Directive from map on destroy", () => {
/* istanbul ignore if */
if (control.getContainer().parentElement.parentElement.parentElement !== map.getContainer()) {
throw new Error("The control is not part of the map before destroying");
}
control.ngOnDestroy();
/* istanbul ignore if */
if (control.getContainer() &&
control.getContainer().parentElement &&
control.getContainer().parentElement.parentElement &&
control.getContainer().parentElement.parentElement.parentElement &&
control.getContainer().parentElement.parentElement.parentElement === map.getContainer()) {
throw new Error("The layer is still part of the map after destroying");
}
});
});
});
//# sourceMappingURL=zoom-control.directive.spec.js.map