From 2a324b0b94e601aa35a1dd5d73032769323a1c39 Mon Sep 17 00:00:00 2001 From: Michael Siadak Date: Fri, 29 Sep 2017 09:04:48 -0500 Subject: [PATCH] Add tileerror tests to GridLayer spec (#5805) --- spec/suites/layer/tile/GridLayerSpec.js | 67 ++++++++++++++++++++++--- 1 file changed, 60 insertions(+), 7 deletions(-) diff --git a/spec/suites/layer/tile/GridLayerSpec.js b/spec/suites/layer/tile/GridLayerSpec.js index 50ed5f0c..9e573a52 100644 --- a/spec/suites/layer/tile/GridLayerSpec.js +++ b/spec/suites/layer/tile/GridLayerSpec.js @@ -122,11 +122,18 @@ describe('GridLayer', function () { }); describe('#createTile', function () { + var grid; beforeEach(function () { // Simpler sizes to test. div.style.width = '512px'; div.style.height = '512px'; + + map.remove(); + map = L.map(div); + map.setView([0, 0], 10); + + grid = L.gridLayer(); }); afterEach(function () { @@ -136,12 +143,7 @@ describe('GridLayer', function () { // Passes on Firefox, but fails on phantomJS: done is never called. it('only creates tiles for visible area on zoom in', function (done) { - map.remove(); - map = L.map(div); - map.setView([0, 0], 10); - - var grid = L.gridLayer(), - count = 0, + var count = 0, loadCount = 0; grid.createTile = function (coords) { count++; @@ -161,6 +163,58 @@ describe('GridLayer', function () { map.addLayer(grid); }); + describe('when done() is called with an error parameter', function () { + var keys; + + beforeEach(function () { + keys = []; + grid.createTile = function (coords, done) { + var tile = document.createElement('div'); + keys.push(this._tileCoordsToKey(coords)); + done('error', tile); + return tile; + }; + }); + + it('does not raise tileload events', function (done) { + var tileLoadRaised = sinon.spy(); + grid.on('tileload', tileLoadRaised); + grid.on('tileerror', function () { + if (keys.length === 4) { + expect(tileLoadRaised.notCalled).to.be(true); + done(); + } + }); + map.addLayer(grid); + }); + + it('raises tileerror events', function (done) { + var tileErrorRaised = sinon.spy(); + grid.on('tileerror', function () { + tileErrorRaised(); + if (keys.length === 4) { + expect(tileErrorRaised.callCount).to.be(4); + done(); + } + }); + map.addLayer(grid); + }); + + it('does not add the .leaflet-tile-loaded class to tile elements', function (done) { + var count = 0; + grid.on('tileerror', function (e) { + if (!L.DomUtil.hasClass(e.tile, 'leaflet-tile-loaded')) { + count++; + } + if (keys.length === 4) { + expect(count).to.be(4); + done(); + } + }); + map.addLayer(grid); + }); + }); + }); describe("#onAdd", function () { @@ -952,5 +1006,4 @@ describe('GridLayer', function () { }).to.throwError('Attempted to load an infinite number of tiles'); }); }); - });