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

100% Statements 258/258
100% Branches 4/4
100% Functions 87/87
100% Lines 258/258
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 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  51× 51× 51× 51× 51× 51×                                                                                                                                                                                                
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
var chai_1 = require("chai");
var leaflet_1 = require("leaflet");
var index_1 = require("./index");
var spec_1 = require("./spec");
describe("Tooltip Directive", function () {
    var map;
    var tooltip;
    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);
        tooltip = new index_1.TooltipDirective({ ref: leaflet_1.marker([0, 0]) }, { nativeElement: document.createElement("div") });
        tooltip._contentNode = document.createElement("div");
        tooltip._container = document.createElement("div");
    });
    describe("[(opened)]", function () {
        beforeEach(function () {
            tooltip._wrapper = document.createElement("div");
            tooltip.setLatLng(leaflet_1.latLng(0, 0));
            map.openTooltip(tooltip);
        });
        it("should remove DOM container when not opened", function () {
            tooltip.opened = false;
            /* istanbul ignore if */
            Iif (tooltip._container.parentNode) {
                throw new Error("Map is still parent element of the tooltip");
            }
        });
        it("should re-add DOM container when opened is true again", function () {
            tooltip.opened = true;
            /* istanbul ignore if */
            Iif (!tooltip._container.parentNode) {
                throw new Error("Map is still parent element of the tooltip");
            }
        });
    });
    describe("[(content)]", function () {
        it("should be changed in Leaflet when changing in Angular", function () {
            tooltip.content = index_1.EXAMPLE_CONTENT;
            chai_1.expect(tooltip._content).to.equal(index_1.EXAMPLE_CONTENT);
        });
        it("should be changed in Angular when changing in Angular", function () {
            tooltip.content = index_1.EXAMPLE_CONTENT;
            chai_1.expect(tooltip.content).to.equal(index_1.EXAMPLE_CONTENT);
        });
        it("should be changed in Angular when changing in Leaflet", function () {
            tooltip.setContent(index_1.EXAMPLE_CONTENT);
            chai_1.expect(tooltip.content).to.equal(index_1.EXAMPLE_CONTENT);
        });
        it("should fire an event when changing in Angular", function (done) {
            tooltip.contentChange.subscribe(function (eventVal) {
                chai_1.expect(eventVal).to.equal(index_1.EXAMPLE_CONTENT);
                return done();
            });
            tooltip.content = index_1.EXAMPLE_CONTENT;
        });
        it("should fire an event when changing in Leaflet", function (done) {
            tooltip.content = index_1.EXAMPLE_CONTENT;
            tooltip.contentChange.subscribe(function (eventVal) {
                chai_1.expect(eventVal).to.equal(index_1.EXAMPLE_CONTENT + "?test");
                return done();
            });
            tooltip.setContent(index_1.EXAMPLE_CONTENT + "?test");
        });
    });
    describe("[(opacity)]", function () {
        it("should be changed in Leaflet when changing in Angular", function () {
            var val = spec_1.randomNumber();
            tooltip.opacity = val;
            chai_1.expect(tooltip.options.opacity).to.equal(val);
        });
        it("should be changed in Angular when changing in Angular", function () {
            var val = spec_1.randomNumber();
            tooltip.opacity = val;
            chai_1.expect(tooltip.opacity).to.equal(val);
        });
        it("should be changed in Angular when changing in Leaflet", function () {
            var val = spec_1.randomNumber();
            tooltip.setOpacity(val);
            chai_1.expect(tooltip.opacity).to.equal(val);
        });
        it("should fire an event when changing in Angular", function (done) {
            var val = spec_1.randomNumber();
            tooltip.opacityChange.subscribe(function (eventVal) {
                chai_1.expect(eventVal).to.equal(val);
                return done();
            });
            tooltip.opacity = val;
        });
        it("should fire an event when changing in Leaflet", function (done) {
            var val = spec_1.randomNumber();
            tooltip.opacityChange.subscribe(function (eventVal) {
                chai_1.expect(eventVal).to.equal(val);
                return done();
            });
            tooltip.setOpacity(val);
        });
    });
    describe("[(lat)]", function () {
        beforeEach(function () {
            tooltip.setLatLng(leaflet_1.latLng(0, 0));
        });
        it("should be changed in Leaflet when changing in Angular", function () {
            var val = spec_1.randomLat();
            tooltip.lat = val;
            chai_1.expect(tooltip.getLatLng().lat).to.equal(val);
        });
        it("should be changed in Angular when changing in Angular", function () {
            var val = spec_1.randomLat();
            tooltip.lat = val;
            chai_1.expect(tooltip.lat).to.equal(val);
        });
        it("should be changed in Angular when changing in Leaflet", function () {
            var val = spec_1.randomLat();
            tooltip.setLatLng([val, 0]);
            chai_1.expect(tooltip.lat).to.equal(val);
        });
        it("should fire an event when changing in Angular", function (done) {
            var val = spec_1.randomLat();
            tooltip.latChange.subscribe(function (eventVal) {
                chai_1.expect(eventVal).to.equal(val);
                return done();
            });
            tooltip.lat = val;
        });
        it("should fire an event when changing in Leaflet", function (done) {
            var val = spec_1.randomLat();
            tooltip.latChange.subscribe(function (eventVal) {
                chai_1.expect(eventVal).to.equal(val);
                return done();
            });
            tooltip.setLatLng([val, 0]);
        });
    });
    describe("[(lng)]", function () {
        beforeEach(function () {
            tooltip.setLatLng(leaflet_1.latLng(0, 0));
        });
        it("should be changed in Leaflet when changing in Angular", function () {
            var val = spec_1.randomLng();
            tooltip.lng = val;
            chai_1.expect(tooltip.getLatLng().lng).to.equal(val);
        });
        it("should be changed in Angular when changing in Angular", function () {
            var val = spec_1.randomLng();
            tooltip.lng = val;
            chai_1.expect(tooltip.lng).to.equal(val);
        });
        it("should be changed in Angular when changing in Leaflet", function () {
            var val = spec_1.randomLng();
            tooltip.setLatLng([0, val]);
            chai_1.expect(tooltip.lng).to.equal(val);
        });
        it("should fire an event when changing in Angular", function (done) {
            var val = spec_1.randomLng();
            tooltip.lngChange.subscribe(function (eventVal) {
                chai_1.expect(eventVal).to.equal(val);
                return done();
            });
            tooltip.lng = val;
        });
        it("should fire an event when changing in Leaflet", function (done) {
            var val = spec_1.randomLng();
            tooltip.lngChange.subscribe(function (eventVal) {
                chai_1.expect(eventVal).to.equal(val);
                return done();
            });
            tooltip.setLatLng([0, val]);
        });
    });
    describe("[(position)]", function () {
        beforeEach(function () {
            tooltip.setLatLng(leaflet_1.latLng(0, 0));
        });
        it("should be changed in Leaflet when changing in Angular", function () {
            var val = spec_1.randomLatLng();
            tooltip.position = val;
            chai_1.expect(tooltip.getLatLng().equals(val)).to.equal(true);
        });
        it("should be changed in Angular when changing in Angular", function () {
            var val = spec_1.randomLatLng();
            tooltip.position = val;
            chai_1.expect(tooltip.position.equals(val)).to.equal(true);
        });
        it("should be changed in Angular when changing in Leaflet", function () {
            var val = spec_1.randomLatLng();
            tooltip.setLatLng(val);
            chai_1.expect(tooltip.position.equals(val)).to.equal(true);
        });
        it("should fire an event when changing in Angular", function (done) {
            var val = spec_1.randomLatLng();
            tooltip.positionChange.subscribe(function (eventVal) {
                chai_1.expect(eventVal.equals(val)).to.equal(true);
                return done();
            });
            tooltip.position = val;
        });
        it("should fire an event when changing in Leaflet", function (done) {
            var val = spec_1.randomLatLng();
            tooltip.positionChange.subscribe(function (eventVal) {
                chai_1.expect(eventVal.equals(val)).to.equal(true);
                return done();
            });
            tooltip.setLatLng(val);
        });
    });
    // Events
    describe("(open)", function () {
        beforeEach(function () {
            tooltip.setLatLng(leaflet_1.latLng(0, 0));
        });
        it("should fire event in Angular when firing event in Leaflet", function (done) {
            tooltip.openEvent.subscribe(function (event) {
                chai_1.expect(event.target).to.equal(tooltip);
                return done();
            });
            map.openTooltip(tooltip);
        });
    });
    describe("(close)", function () {
        beforeEach(function () {
            tooltip.setLatLng(leaflet_1.latLng(0, 0));
            map.openTooltip(tooltip);
        });
        it("should fire event in Angular when firing event in Leaflet", function (done) {
            tooltip.closeEvent.subscribe(function (event) {
                chai_1.expect(event.target).to.equal(tooltip);
                return done();
            });
            tooltip._close();
        });
    });
    // Inputs
    describe("[className]", function () {
        it("should be changed in Leaflet when changing in Angular", function () {
            var val = "test-class";
            tooltip.className = val;
            chai_1.expect(tooltip.options.className).to.equal(val);
        });
        it("should be changed in DOM when changing in Angular", function () {
            var val = "test-class";
            tooltip.className = val;
            chai_1.expect(tooltip._container.getAttribute("class").split(" ")).to.include(val);
        });
        it("should be changed in Angular when changing in Angular", function () {
            var val = "test-class";
            tooltip.className = val;
            chai_1.expect(tooltip.className).to.equal(val);
        });
    });
    describe("[pane]", function () {
        it("should be changed in Leaflet when changing in Angular", function () {
            var val = "test-class";
            tooltip.pane = val;
            chai_1.expect(tooltip.options.pane).to.equal(val);
        });
        it("should be changed in Angular when changing in Angular", function () {
            var val = "test-class";
            tooltip.pane = val;
            chai_1.expect(tooltip.pane).to.equal(val);
        });
    });
    describe("[direction]", function () {
        it("should be changed in Leaflet when changing in Angular", function () {
            var val = "top";
            tooltip.direction = val;
            chai_1.expect(tooltip.options.direction).to.equal(val);
        });
        it("should be changed in Angular when changing in Angular", function () {
            var val = "right";
            tooltip.direction = val;
            chai_1.expect(tooltip.direction).to.equal(val);
        });
    });
    describe("[offset]", function () {
        it("should be changed in Leaflet when changing in Angular", function () {
            var val = leaflet_1.point(12, 34);
            tooltip.offset = val;
            chai_1.expect(tooltip.options.offset).to.equal(val);
        });
        it("should be changed in Angular when changing in Angular", function () {
            var val = leaflet_1.point(12, 34);
            tooltip.offset = val;
            chai_1.expect(tooltip.offset).to.equal(val);
        });
    });
    describe("[interactive]", function () {
        it("should be changed to false in Leaflet when changing in Angular to false", function () {
            tooltip.interactive = false;
            chai_1.expect(tooltip.options.interactive).to.equal(false);
        });
        it("should be changed to true in Leaflet when changing in Angular to true", function () {
            tooltip.options.interactive = false;
            tooltip.interactive = true;
            chai_1.expect(tooltip.options.interactive).to.equal(true);
        });
        it("should be changed in Angular to false when changing in Angular to false", function () {
            tooltip.interactive = false;
            chai_1.expect(tooltip.interactive).to.equal(false);
        });
        it("should be changed in Angular to true when changing in Angular to true", function () {
            tooltip.interactive = true;
            chai_1.expect(tooltip.interactive).to.equal(true);
        });
    });
    describe("[sticky]", function () {
        it("should be changed to false in Leaflet when changing in Angular to false", function () {
            tooltip.sticky = false;
            chai_1.expect(tooltip.options.sticky).to.equal(false);
        });
        it("should be changed to true in Leaflet when changing in Angular to true", function () {
            tooltip.options.sticky = false;
            tooltip.sticky = true;
            chai_1.expect(tooltip.options.sticky).to.equal(true);
        });
        it("should be changed in Angular to false when changing in Angular to false", function () {
            tooltip.sticky = false;
            chai_1.expect(tooltip.sticky).to.equal(false);
        });
        it("should be changed in Angular to true when changing in Angular to true", function () {
            tooltip.sticky = true;
            chai_1.expect(tooltip.sticky).to.equal(true);
        });
    });
    describe("[permanent]", function () {
        it("should be changed to false in Leaflet when changing in Angular to false", function () {
            tooltip.permanent = false;
            chai_1.expect(tooltip.options.permanent).to.equal(false);
        });
        it("should be changed to true in Leaflet when changing in Angular to true", function () {
            tooltip.options.permanent = false;
            tooltip.permanent = true;
            chai_1.expect(tooltip.options.permanent).to.equal(true);
        });
        it("should be changed in Angular to false when changing in Angular to false", function () {
            tooltip.permanent = false;
            chai_1.expect(tooltip.permanent).to.equal(false);
        });
        it("should be changed in Angular to true when changing in Angular to true", function () {
            tooltip.permanent = true;
            chai_1.expect(tooltip.permanent).to.equal(true);
        });
    });
    describe("Remove from source element on destroy", function () {
        it("should call unbindPopup on destroy", function (done) {
            tooltip.layerProvider.ref = {
                unbindTooltip: done,
            };
            tooltip.ngOnDestroy();
        });
    });
});
//# sourceMappingURL=tooltip.directive.spec.js.map