Skip to content

Commit

Permalink
Adding tests
Browse files Browse the repository at this point in the history
  • Loading branch information
karimnaaji committed Aug 31, 2022
1 parent 690b3ba commit 1dc1903
Show file tree
Hide file tree
Showing 2 changed files with 94 additions and 0 deletions.
36 changes: 36 additions & 0 deletions test/unit/ui/camera.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
58 changes: 58 additions & 0 deletions test/unit/ui/map.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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');
Expand Down

0 comments on commit 1dc1903

Please sign in to comment.