From 1dc19031fa28c2db88aaa5e9dd3c826469802a78 Mon Sep 17 00:00:00 2001 From: Karim Naaji Date: Mon, 29 Aug 2022 14:08:22 -0700 Subject: [PATCH] Adding tests --- test/unit/ui/camera.test.js | 36 +++++++++++++++++++++++ test/unit/ui/map.test.js | 58 +++++++++++++++++++++++++++++++++++++ 2 files changed, 94 insertions(+) diff --git a/test/unit/ui/camera.test.js b/test/unit/ui/camera.test.js index 64fe924b361..79bf8c4d22d 100644 --- a/test/unit/ui/camera.test.js +++ b/test/unit/ui/camera.test.js @@ -2126,6 +2126,42 @@ test('camera', (t) => { t.end(); }); + t.test('#cameraForBounds with Globe', (t) => { + t.test('no options passed', (t) => { + const camera = createCamera({projection: {name: 'globe'}}); + const bb = [[-133, 16], [-68, 50]]; + + const transform = camera.cameraForBounds(bb); + t.deepEqual(fixedLngLat(transform.center, 4), {lng: -100.5, lat: 34.716}, 'correctly calculates coordinates for new bounds'); + t.equal(fixedNum(transform.zoom, 3), 2.106); + t.end(); + }); + + t.test('bearing positive number', (t) => { + const camera = createCamera({projection: {name: 'globe'}}); + const bb = [[-133, 16], [-68, 50]]; + + const transform = camera.cameraForBounds(bb, {bearing: 175}); + t.deepEqual(fixedLngLat(transform.center, 4), {lng: -100.5, lat: 34.716}, 'correctly calculates coordinates for new bounds'); + t.equal(fixedNum(transform.zoom, 3), 2.034); + t.equal(transform.bearing, 175); + t.end(); + }); + + t.test('bearing negative number', (t) => { + const camera = createCamera({projection: {name: 'globe'}}); + const bb = [[-133, 16], [-68, 50]]; + + const transform = camera.cameraForBounds(bb, {bearing: -30}); + t.deepEqual(fixedLngLat(transform.center, 4), {lng: -100.5, lat: 34.716}, 'correctly calculates coordinates for new bounds'); + t.equal(fixedNum(transform.zoom, 3), 1.868); + t.equal(transform.bearing, -30); + t.end(); + }); + + t.end(); + }); + t.test('#fitBounds', (t) => { t.test('no padding passed', (t) => { const camera = createCamera(); diff --git a/test/unit/ui/map.test.js b/test/unit/ui/map.test.js index 5993963a4b0..7fe9cbe7bc9 100755 --- a/test/unit/ui/map.test.js +++ b/test/unit/ui/map.test.js @@ -188,6 +188,64 @@ test('Map', (t) => { function pass() { t.end(); } }); + t.test('#cameraForBounds', (t) => { + t.test('crossing globe-mercator threshold globe -> mercator does not affect cameraForBounds result', (t) => { + const map = createMap(t); + map.setProjection('globe'); + const bb = [[-133, 16], [-132, 18]]; + + let transform; + + map.setZoom(0); + map._updateProjectionTransition(); + + t.equal(map.transform.projection.name, "globe"); + + transform = map.cameraForBounds(bb); + t.deepEqual(fixedLngLat(transform.center, 4), {lng: -132.5, lat: 17.0027}); + t.equal(fixedNum(transform.zoom, 3), 6.071); + + map.setZoom(10); + map._updateProjectionTransition(); + + t.equal(map.transform.projection.name, "mercator"); + + transform = map.cameraForBounds(bb); + t.deepEqual(fixedLngLat(transform.center, 4), {lng: -132.5, lat: 17.0027}); + t.equal(fixedNum(transform.zoom, 3), 6.071); + t.end(); + }); + + t.test('crossing globe-mercator threshold mercator -> globe does not affect cameraForBounds result', (t) => { + const map = createMap(t); + map.setProjection('globe'); + const bb = [[-133, 16], [-68, 50]]; + + let transform; + + map.setZoom(10); + map._updateProjectionTransition(); + + t.equal(map.transform.projection.name, "mercator"); + + transform = map.cameraForBounds(bb); + t.deepEqual(fixedLngLat(transform.center, 4), {lng: -100.5, lat: 34.716}); + t.equal(fixedNum(transform.zoom, 3), 0.75); + + map.setZoom(0); + map._updateProjectionTransition(); + + t.equal(map.transform.projection.name, "globe"); + + transform = map.cameraForBounds(bb); + t.deepEqual(fixedLngLat(transform.center, 4), {lng: -100.5, lat: 34.716}); + t.equal(fixedNum(transform.zoom, 3), 0.75); + t.end(); + }); + + t.end(); + }); + t.test('#setStyle', (t) => { t.test('returns self', (t) => { t.stub(Map.prototype, '_detectMissingCSS');