From 86099a8502bdacdce5ce5987f8b318f731f4f338 Mon Sep 17 00:00:00 2001 From: ghybs Date: Fri, 19 Jan 2018 06:12:11 +0400 Subject: [PATCH] Test(TileLayer): check zoomOffset option is used (#6011) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit following issue #6004 (fixed by PR #6006). Added 2 dedicated tests. Unfortunately I could not add a test for detectRetina option that easily, because since the move to Rollup, Browser values became internal variables, and overriding them later on does not have any effect on Leaflet internal references… Not sure how to workaround this for the sake of testing. --- spec/suites/layer/tile/TileLayerSpec.js | 41 +++++++++++++++++++++++++ 1 file changed, 41 insertions(+) diff --git a/spec/suites/layer/tile/TileLayerSpec.js b/spec/suites/layer/tile/TileLayerSpec.js index 7e7730c8..dbb85776 100644 --- a/spec/suites/layer/tile/TileLayerSpec.js +++ b/spec/suites/layer/tile/TileLayerSpec.js @@ -377,5 +377,46 @@ describe('TileLayer', function () { expect(['q', 'r', 's'].indexOf(img.src[7]) >= 0).to.eql(true); }); }); + + it('uses zoomOffset option', function () { + // Map view is set at zoom 2 in beforeEach. + var layer = L.tileLayer('http://example.com/{z}/{y}/{x}.png', { + zoomOffset: 1 // => zoom 2 + zoomOffset 1 => z 3 in URL. + }).addTo(map); + + var urls = [ + 'http://example.com/3/1/1.png', + 'http://example.com/3/1/2.png', + 'http://example.com/3/2/1.png', + 'http://example.com/3/2/2.png' + ]; + + var i = 0; + eachImg(layer, function (img) { + expect(img.src).to.eql(urls[i]); + i++; + }); + }); + + it('uses negative zoomOffset option', function () { + // Map view is set at zoom 2 in beforeEach. + var layer = L.tileLayer('http://example.com/{z}/{y}/{x}.png', { + zoomOffset: -3 // => zoom 2 + zoomOffset -3 => z -1 in URL. + }).addTo(map); + + var urls = [ + 'http://example.com/-1/1/1.png', + 'http://example.com/-1/1/2.png', + 'http://example.com/-1/2/1.png', + 'http://example.com/-1/2/2.png' + ]; + + var i = 0; + eachImg(layer, function (img) { + expect(img.src).to.eql(urls[i]); + i++; + }); + }); + }); });