all files / lib/ feature-group.directive.spec.js

100% Statements 110/110
100% Branches 4/4
100% Functions 35/35
100% Lines 110/110
2 statements, 2 branches Ignored     
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154  14× 14× 14× 14×                                                                                      
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
var chai_1 = require("chai");
var leaflet_1 = require("leaflet");
var index_1 = require("./index");
describe("Feature-Group Directive", function () {
    var map;
    var layer;
    beforeEach(function () {
        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.FeatureGroupDirective({ ref: map }, {}, {});
    });
    describe("[(display)]", function () {
        it("should remove layer when not displaying", function () {
            layer.display = false;
            chai_1.expect(layer._map).to.equal(null);
        });
        it("should re-add layer when display is true again", function () {
            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", function (done) {
            setTimeout(function () {
                layer.displayChange.subscribe(function (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", function (done) {
            map.removeLayer(layer);
            layer.displayChange.subscribe(function (val) {
                chai_1.expect(val).to.equal(true);
                chai_1.expect(layer.display).to.equal(true);
                done();
            });
            map.addLayer(layer);
        });
    });
    // Events
    describe("(add)", function () {
        it("should fire event in Angular when firing event in Leaflet", function (done) {
            var testHandle = {};
            var testEvent = { testHandle: testHandle };
            layer.addEvent.subscribe(function (event) {
                chai_1.expect(event.testHandle).to.equal(testEvent.testHandle);
                return done();
            });
            layer.fire("add", testEvent);
        });
    });
    describe("(remove)", function () {
        it("should fire event in Angular when firing event in Leaflet", function (done) {
            var testHandle = {};
            var testEvent = { testHandle: testHandle };
            layer.removeEvent.subscribe(function (event) {
                chai_1.expect(event.testHandle).to.equal(testEvent.testHandle);
                return done();
            });
            layer.fire("remove", testEvent);
        });
    });
    describe("(popupopen)", function () {
        it("should fire event in Angular when firing event in Leaflet", function (done) {
            var testHandle = {};
            var testEvent = { testHandle: testHandle };
            layer.popupopenEvent.subscribe(function (event) {
                chai_1.expect(event.testHandle).to.equal(testEvent.testHandle);
                return done();
            });
            layer.fire("popupopen", testEvent);
        });
    });
    describe("(popupclose)", function () {
        it("should fire event in Angular when firing event in Leaflet", function (done) {
            var testHandle = {};
            var testEvent = { testHandle: testHandle };
            layer.popupcloseEvent.subscribe(function (event) {
                chai_1.expect(event.testHandle).to.equal(testEvent.testHandle);
                return done();
            });
            layer.fire("popupclose", testEvent);
        });
    });
    describe("(tooltipopen)", function () {
        it("should fire event in Angular when firing event in Leaflet", function (done) {
            var testHandle = {};
            var testEvent = { testHandle: testHandle };
            layer.tooltipopenEvent.subscribe(function (event) {
                chai_1.expect(event.testHandle).to.equal(testEvent.testHandle);
                return done();
            });
            layer.fire("tooltipopen", testEvent);
        });
    });
    describe("(tooltipclose)", function () {
        it("should fire event in Angular when firing event in Leaflet", function (done) {
            var testHandle = {};
            var testEvent = { testHandle: testHandle };
            layer.tooltipcloseEvent.subscribe(function (event) {
                chai_1.expect(event.testHandle).to.equal(testEvent.testHandle);
                return done();
            });
            layer.fire("tooltipclose", testEvent);
        });
    });
    // Inputs
    describe("[attribution]", function () {
        var attributionControl;
        beforeEach(function () {
            attributionControl = new index_1.AttributionControlDirective({ ref: map });
        });
        it("should be changed in Leaflet when changing in Angular", function () {
            var 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", function () {
            var 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", function () {
            var oldVal = "Old test attribution";
            var 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 Feature-Group Directive", function () {
        it("should remove Feature Directive from map on destroy", function () {
            /* istanbul ignore if */
            Iif (!map.hasLayer(layer)) {
                throw new Error("The layer is not part of the map before destroying");
            }
            layer.ngOnDestroy();
            /* istanbul ignore if */
            Iif (map.hasLayer(layer)) {
                throw new Error("The layer is still part of the map after destroying");
            }
        });
    });
});
//# sourceMappingURL=feature-group.directive.spec.js.map