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

100% Statements 261/261
100% Branches 10/10
100% Functions 85/85
100% Lines 261/261
1 statement, 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 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362            44× 44× 44× 44×                                                                                                                                                                                              
"use strict";
var index_1 = require("./index");
var leaflet_1 = require("leaflet");
var chai_1 = require("chai");
function hasAsChild(root, child) {
    'use strict';
    var length = root.children.length;
    for (var i = 0; i < length; i += 1) {
        /* istanbul ignore else */
        Eif (root.children.item(i) === child) {
            return true;
        }
    }
    return false;
}
describe('Marker 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);
        layer = new index_1.MarkerDirective(map);
    });
    describe('[(display)]', function () {
        it('should remove DOM container when not displaying', function () {
            layer.display = false;
            chai_1.expect(hasAsChild(layer.getPane(), layer.getElement())).to.equal(false);
        });
        it('should re-add DOM container when display is true again', function () {
            layer.display = false;
            layer.display = true;
            chai_1.expect(hasAsChild(layer.getPane(), layer.getElement())).to.equal(true);
        });
        it('should remove EventListeners when not displaying', function (done) {
            var zoomEvents = map._events.zoom, length = zoomEvents.length, originalEventListener = layer.getEvents()['zoom'];
            layer.display = false;
            for (var i = 0; i < length; i += 1) {
                /* istanbul ignore if */
                Iif (zoomEvents[i] && zoomEvents[i].fn === originalEventListener) {
                    return done(new Error('There is still an event on listener'));
                }
            }
            done();
        });
        it('should re-add EventListeners when display is true again', function (done) {
            var zoomEvents = map._events.zoom, length = zoomEvents.length, originalEventListener = layer.getEvents()['zoom'];
            layer.display = false;
            layer.display = true;
            for (var i = 0; i < length; i += 1) {
                if (zoomEvents[i] && zoomEvents[i].fn === originalEventListener) {
                    return done();
                }
            }
        });
        it('should set to false by removing from map', function (done) {
            layer.displayChange.subscribe(function (val) {
                chai_1.expect(val).to.equal(false);
                chai_1.expect(layer.display).to.equal(false);
                done();
            });
            map.removeLayer(layer);
        });
        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);
        });
    });
    describe('[(opacity)]', function () {
        it('should be changed in Leaflet when changing in Angular', function () {
            var val = Math.random();
            layer.opacity = val;
            chai_1.expect(layer.options.opacity).to.equal(val);
        });
        it('should be changed in Angular when changing in Angular', function () {
            var val = Math.random();
            layer.opacity = val;
            chai_1.expect(layer.opacity).to.equal(val);
        });
        it('should be changed in Angular when changing in Leaflet', function () {
            var val = Math.random();
            layer.setOpacity(val);
            chai_1.expect(layer.opacity).to.equal(val);
        });
        it('should fire an event when changing in Angular', function (done) {
            var val = Math.random();
            layer.opacityChange.subscribe(function (eventVal) {
                chai_1.expect(eventVal).to.equal(val);
                return done();
            });
            layer.opacity = val;
        });
        it('should fire an event when changing in Leaflet', function (done) {
            var val = Math.random();
            layer.opacityChange.subscribe(function (eventVal) {
                chai_1.expect(eventVal).to.equal(val);
                return done();
            });
            layer.setOpacity(val);
        });
    });
    describe('[(lat)]', function () {
        beforeEach(function () {
            layer.ngAfterViewInit();
        });
        it('should be changed in Leaflet when changing in Angular', function () {
            var val = Math.random() * 100;
            layer.lat = val;
            chai_1.expect(layer.getLatLng().lat).to.equal(val);
        });
        it('should be changed in Angular when changing in Angular', function () {
            var val = Math.random() * 100;
            layer.lat = val;
            chai_1.expect(layer.lat).to.equal(val);
        });
        it('should be changed in Angular when changing in Leaflet', function () {
            var val = Math.random() * 100;
            layer.setLatLng([val, 0]);
            chai_1.expect(layer.lat).to.equal(val);
        });
        it('should fire an event when changing in Angular', function (done) {
            var val = Math.random() * 100;
            layer.latChange.subscribe(function (eventVal) {
                chai_1.expect(eventVal).to.equal(val);
                return done();
            });
            layer.lat = val;
        });
        it('should fire an event when changing in Leaflet', function (done) {
            var val = Math.random() * 100;
            layer.latChange.subscribe(function (eventVal) {
                chai_1.expect(eventVal).to.equal(val);
                return done();
            });
            layer.setLatLng([val, 0]);
        });
    });
    describe('[(lng)]', function () {
        beforeEach(function () {
            layer.ngAfterViewInit();
        });
        it('should be changed in Leaflet when changing in Angular', function () {
            var val = Math.random() * 100;
            layer.lng = val;
            chai_1.expect(layer.getLatLng().lng).to.equal(val);
        });
        it('should be changed in Angular when changing in Angular', function () {
            var val = Math.random() * 100;
            layer.lng = val;
            chai_1.expect(layer.lng).to.equal(val);
        });
        it('should be changed in Angular when changing in Leaflet', function () {
            var val = Math.random() * 100;
            layer.setLatLng([0, val]);
            chai_1.expect(layer.lng).to.equal(val);
        });
        it('should fire an event when changing in Angular', function (done) {
            var val = Math.random() * 100;
            layer.lngChange.subscribe(function (eventVal) {
                chai_1.expect(eventVal).to.equal(val);
                return done();
            });
            layer.lng = val;
        });
        it('should fire an event when changing in Leaflet', function (done) {
            var val = Math.random() * 100;
            layer.lngChange.subscribe(function (eventVal) {
                chai_1.expect(eventVal).to.equal(val);
                return done();
            });
            layer.setLatLng([0, val]);
        });
    });
    describe('[(position)]', function () {
        beforeEach(function () {
            layer.ngAfterViewInit();
        });
        it('should be changed in Leaflet when changing in Angular', function () {
            var val = leaflet_1.latLng(Math.random() * 100 - 50, Math.random() * 100 - 50);
            layer.position = val;
            chai_1.expect(layer.getLatLng()).to.deep.equal(val);
        });
        it('should be changed in Angular when changing in Angular', function () {
            var val = leaflet_1.latLng(Math.random() * 100 - 50, Math.random() * 100 - 50);
            layer.position = val;
            chai_1.expect(layer.position).to.equal(val);
        });
        it('should be changed in Angular when changing in Leaflet', function () {
            var val = leaflet_1.latLng(Math.random() * 100 - 50, Math.random() * 100 - 50);
            layer.setLatLng(val);
            chai_1.expect(layer.position).to.equal(val);
        });
        it('should fire an event when changing in Angular', function (done) {
            var val = leaflet_1.latLng(Math.random() * 100 - 50, Math.random() * 100 - 50);
            layer.positionChange.subscribe(function (eventVal) {
                chai_1.expect(eventVal).to.deep.equal(val);
                return done();
            });
            layer.position = val;
        });
        it('should fire an event when changing in Leaflet', function (done) {
            var val = leaflet_1.latLng(Math.random() * 100 - 50, Math.random() * 100 - 50);
            layer.positionChange.subscribe(function (eventVal) {
                chai_1.expect(eventVal).to.deep.equal(val);
                return done();
            });
            layer.setLatLng(val);
        });
    });
    // TODO: icon
    describe('[title]', function () {
        it('should be changed in Leaflet when changing in Angular', function () {
            var val = 'http://test';
            layer.title = val;
            chai_1.expect(layer.options.title).to.equal(val);
        });
        it('should be changed in Angular when changing in Angular', function () {
            var val = 'http://test';
            layer.title = val;
            chai_1.expect(layer.title).to.equal(val);
        });
    });
    describe('[alt]', function () {
        it('should be changed in Leaflet when changing in Angular', function () {
            var val = 'http://test';
            layer.alt = val;
            chai_1.expect(layer.options.alt).to.equal(val);
        });
        it('should be changed in Angular when changing in Angular', function () {
            var val = 'http://test';
            layer.alt = val;
            chai_1.expect(layer.alt).to.equal(val);
        });
    });
    describe('[draggable]', function () {
        it('should be changed to false in Leaflet when changing in Angular to false', function () {
            layer.draggable = false;
            chai_1.expect(layer.dragging.enabled()).to.equal(false);
        });
        it('should be changed to true in Leaflet when changing in Angular to true', function () {
            layer.dragging.disable();
            layer.draggable = true;
            chai_1.expect(layer.dragging.enabled()).to.equal(true);
        });
        it('should be changed in Angular to false when changing in Angular to false', function () {
            layer.draggable = false;
            chai_1.expect(layer.draggable).to.equal(false);
        });
        it('should be changed in Angular to true when changing in Angular to true', function () {
            layer.draggable = true;
            chai_1.expect(layer.draggable).to.equal(true);
        });
    });
    // Events
    describe('(dragend)', function () {
        it('should fire event in Angular when firing event in Leaflet', function (done) {
            var testHandle = {}, testEvent = { testHandle: testHandle };
            layer.dragendEvent.subscribe(function (event) {
                chai_1.expect(event.testHandle).to.equal(testHandle);
                return done();
            });
            layer.fire('dragend', testEvent);
        });
    });
    describe('(dragstart)', function () {
        it('should fire event in Angular when firing event in Leaflet', function (done) {
            var testHandle = {}, testEvent = { testHandle: testHandle };
            layer.dragstartEvent.subscribe(function (event) {
                chai_1.expect(event.testHandle).to.equal(testHandle);
                return done();
            });
            layer.fire('dragstart', testEvent);
        });
    });
    describe('(movestart)', function () {
        it('should fire event in Angular when firing event in Leaflet', function (done) {
            var testHandle = {}, testEvent = { testHandle: testHandle };
            layer.movestartEvent.subscribe(function (event) {
                chai_1.expect(event.testHandle).to.equal(testHandle);
                return done();
            });
            layer.fire('movestart', testEvent);
        });
    });
    describe('(drag)', function () {
        it('should fire event in Angular when firing event in Leaflet', function (done) {
            var testHandle = {}, testEvent = { testHandle: testHandle };
            layer.dragEvent.subscribe(function (event) {
                chai_1.expect(event.testHandle).to.equal(testHandle);
                return done();
            });
            layer.fire('drag', testEvent);
        });
    });
    describe('(moveend)', function () {
        it('should fire event in Angular when firing event in Leaflet', function (done) {
            var testHandle = {}, testEvent = { testHandle: testHandle };
            layer.moveendEvent.subscribe(function (event) {
                chai_1.expect(event.testHandle).to.equal(testHandle);
                return done();
            });
            layer.fire('moveend', testEvent);
        });
    });
    describe('Popup in Marker Directive', function () {
        var layerWithPopup, popup, testDiv;
        before(function () {
            testDiv = document.createElement('div');
            popup = new index_1.PopupDirective(map, { nativeElement: testDiv });
            // Hack to get write-access to readonly property
            layerWithPopup = Object.create(new index_1.MarkerDirective(map), { popupDirective: { value: popup } });
            layerWithPopup.ngAfterViewInit();
        });
        it('should bind popup', function () {
            chai_1.expect(layerWithPopup._popup).to.equal(popup);
        });
    });
    describe('Tooltip in Marker Directive', function () {
        var layerWithTooltip, tooltip, testDiv;
        before(function () {
            testDiv = document.createElement('div');
            tooltip = new index_1.TooltipDirective(map, { nativeElement: testDiv });
            // Hack to get write-access to readonly property
            layerWithTooltip = Object.create(new index_1.MarkerDirective(map), { tooltipDirective: { value: tooltip } });
            layerWithTooltip.ngAfterViewInit();
        });
        it('should bind tooltip', function () {
            chai_1.expect(layerWithTooltip._tooltip).to.equal(tooltip);
        });
    });
    describe('Icon in Marker Directive', function () {
        var layerWithIcon, icon, testDiv;
        before(function () {
            testDiv = document.createElement('div');
            icon = new index_1.IconDirective();
            icon.iconUrl = index_1.TRANSPARENT_PIXEL;
            // Hack to get write-access to readonly property
            layerWithIcon = Object.create(new index_1.MarkerDirective(map), { iconDirective: { value: icon } });
            layerWithIcon.ngAfterViewInit();
        });
        it('should bind icon', function () {
            chai_1.expect(layerWithIcon._icon.getAttribute('src')).to.equal(index_1.TRANSPARENT_PIXEL);
        });
        it('should bind icon again on changes in icon directive', function () {
            var TEST_VALUE = 'path/to/icon.png';
            icon.iconUrl = TEST_VALUE;
            chai_1.expect(layerWithIcon._icon.getAttribute('src')).to.equal(TEST_VALUE);
        });
    });
    describe('Destroying a Marker Directive', function () {
        it('should remove Marker Directive from map on destroy', function () {
            chai_1.expect(map.hasLayer(layer)).to.equal(true);
            layer.ngOnDestroy();
            chai_1.expect(map.hasLayer(layer)).to.equal(false);
        });
    });
});
//# sourceMappingURL=marker.directive.spec.js.map