all files / lib/ geojson.directive.spec.js

100% Statements 141/141
100% Branches 6/6
100% Functions 57/57
100% Lines 141/141
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 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221  22× 22× 22× 22× 22×                                                                                                                                                              
"use strict";
var index_1 = require("./index");
var chai_1 = require("chai");
var leaflet_1 = require("leaflet");
describe('GeoJSON Directive', function () {
    var map, layer;
    beforeEach(function () {
        map = new index_1.MapComponent({ nativeElement: document.createElement('div') });
        map._size = leaflet_1.point(100, 100);
        map._pixelOrigin = leaflet_1.point(50, 50);
        map._renderer = map._renderer || new leaflet_1.SVG();
        layer = new index_1.GeoJSONDirective(map);
    });
    var TEST_VALUE = {
        features: [
            {
                geometry: {
                    coordinates: [7, 51],
                    type: 'Point'
                },
                properties: {
                    test: 'OK'
                },
                type: 'Feature'
            }
        ],
        type: 'FeatureCollection'
    };
    describe('[(data)]', function () {
        it('should be changed in Leaflet when changing in Angular', function () {
            layer.data = TEST_VALUE;
            chai_1.expect(layer.toGeoJSON()).to.deep.equal(TEST_VALUE);
        });
        it('should be changed in Angular when changing in Angular', function () {
            layer.data = TEST_VALUE;
            chai_1.expect(layer.data).to.deep.equal(TEST_VALUE);
        });
        it('should be changed data in Angular when changing in Leaflet', function () {
            layer.setData(TEST_VALUE);
            chai_1.expect(layer.data).to.deep.equal(TEST_VALUE);
        });
        it('should be changed geoJSON in Angular when adding in latlngs Leaflet', function () {
            layer.addData(TEST_VALUE.features[0]);
            chai_1.expect(layer.data).to.deep.equal(TEST_VALUE);
        });
        it('should fire an event when changing in Angular', function (done) {
            layer.dataChange.subscribe(function (eventVal) {
                chai_1.expect(eventVal).to.deep.equal(TEST_VALUE);
                return done();
            });
            layer.data = TEST_VALUE;
        });
        it('should fire an event when changing in Leaflet', function (done) {
            layer.dataChange.subscribe(function (eventVal) {
                chai_1.expect(eventVal).to.deep.equal(TEST_VALUE);
                return done();
            });
            layer.setData(TEST_VALUE);
        });
        it('should fire an event when adding in Leaflet', function (done) {
            layer.ngAfterViewInit();
            layer.dataChange.subscribe(function (eventVal) {
                chai_1.expect(eventVal).to.deep.equal(TEST_VALUE);
                return done();
            });
            layer.addData(TEST_VALUE.features[0]);
        });
    });
    var testHandle = {};
    var testEvent = { testHandle: testHandle };
    describe('(add)', function () {
        it('should fire event in Angular when firing event in Leaflet', function (done) {
            layer.addEvent.subscribe(function (event) {
                chai_1.expect(event.testHandle).to.equal(testHandle);
                chai_1.expect(event.testHandle).to.equal(testHandle);
                return done();
            });
            layer.fire('add', testEvent);
        });
    });
    describe('(remove)', function () {
        it('should fire event in Angular when firing event in Leaflet', function (done) {
            layer.removeEvent.subscribe(function (event) {
                chai_1.expect(event.testHandle).to.equal(testHandle);
                return done();
            });
            layer.fire('remove', testEvent);
        });
    });
    describe('(popupopen)', function () {
        it('should fire event in Angular when firing event in Leaflet', function (done) {
            layer.popupopenEvent.subscribe(function (event) {
                chai_1.expect(event.testHandle).to.equal(testHandle);
                return done();
            });
            layer.fire('popupopen', testEvent);
        });
    });
    describe('(popupclose)', function () {
        it('should fire event in Angular when firing event in Leaflet', function (done) {
            layer.popupcloseEvent.subscribe(function (event) {
                chai_1.expect(event.testHandle).to.equal(testHandle);
                return done();
            });
            layer.fire('popupclose', testEvent);
        });
    });
    describe('(tooltipopen)', function () {
        it('should fire event in Angular when firing event in Leaflet', function (done) {
            layer.tooltipopenEvent.subscribe(function (event) {
                chai_1.expect(event.testHandle).to.equal(testHandle);
                return done();
            });
            layer.fire('tooltipopen', testEvent);
        });
    });
    describe('(tooltipclose)', function () {
        it('should fire event in Angular when firing event in Leaflet', function (done) {
            layer.tooltipcloseEvent.subscribe(function (event) {
                chai_1.expect(event.testHandle).to.equal(testHandle);
                return done();
            });
            layer.fire('tooltipclose', testEvent);
        });
    });
    describe('(click)', function () {
        it('should fire event in Angular when firing event in Leaflet', function (done) {
            layer.clickEvent.subscribe(function (event) {
                chai_1.expect(event.testHandle).to.equal(testHandle);
                return done();
            });
            layer.fire('click', testEvent);
        });
    });
    describe('(dbclick)', function () {
        it('should fire event in Angular when firing event in Leaflet', function (done) {
            layer.dbclickEvent.subscribe(function (event) {
                chai_1.expect(event.testHandle).to.equal(testHandle);
                return done();
            });
            layer.fire('dbclick', testEvent);
        });
    });
    describe('(mousedown)', function () {
        it('should fire event in Angular when firing event in Leaflet', function (done) {
            layer.mousedownEvent.subscribe(function (event) {
                chai_1.expect(event.testHandle).to.equal(testHandle);
                return done();
            });
            layer.fire('mousedown', testEvent);
        });
    });
    describe('(mouseover)', function () {
        it('should fire event in Angular when firing event in Leaflet', function (done) {
            layer.mouseoverEvent.subscribe(function (event) {
                chai_1.expect(event.testHandle).to.equal(testHandle);
                return done();
            });
            layer.fire('mouseover', testEvent);
        });
    });
    describe('(mouseout)', function () {
        it('should fire event in Angular when firing event in Leaflet', function (done) {
            layer.mouseoutEvent.subscribe(function (event) {
                chai_1.expect(event.testHandle).to.equal(testHandle);
                return done();
            });
            layer.fire('mouseout', testEvent);
        });
    });
    describe('(contextmenu)', function () {
        it('should fire event in Angular when firing event in Leaflet', function (done) {
            layer.contextmenuEvent.subscribe(function (event) {
                chai_1.expect(event.testHandle).to.equal(testHandle);
                return done();
            });
            layer.fire('contextmenu', testEvent);
        });
    });
    describe('Popup in GeoJSON Directive', function () {
        var popup, testDiv, puLayer;
        before(function () {
            testDiv = document.createElement('div');
            popup = new index_1.PopupDirective(map, { nativeElement: testDiv });
            // Hack to get write-access to readonly property
            puLayer = Object.create(new index_1.GeoJSONDirective(map), { popupDirective: { value: popup } });
        });
        it('should bind popup', function () {
            puLayer.ngAfterViewInit();
            chai_1.expect(puLayer._popup).to.equal(popup);
        });
    });
    describe('Tooltip in GeoJSON Directive', function () {
        var tooltip, testDiv, ttLayer;
        before(function () {
            testDiv = document.createElement('div');
            tooltip = new index_1.TooltipDirective(map, { nativeElement: testDiv });
            // Hack to get write-access to readonly property
            ttLayer = Object.create(new index_1.GeoJSONDirective(map), { tooltipDirective: { value: tooltip } });
        });
        it('should bind tooltip', function () {
            ttLayer.ngAfterViewInit();
            chai_1.expect(ttLayer.tooltipDirective).to.equal(tooltip);
            // expect((<any>layer)._tooltip).to.equal(tooltip);
        });
    });
    describe('Destroying a GeoJSON Directive', function () {
        it('should remove Polyline 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=geojson.directive.spec.js.map