Import Leaflet in tests using JavaScript modules (#8975)

This commit is contained in:
Jon Koops
2023-06-02 12:24:17 +02:00
committed by GitHub
parent 6994baf25f
commit bb048a3eac
57 changed files with 1830 additions and 1621 deletions

View File

@ -1,49 +1,51 @@
import {bounds, Bounds, point} from 'leaflet';
describe('Bounds', () => {
let a, b, c;
beforeEach(() => {
a = L.bounds(
a = bounds(
[14, 12], // left, top
[30, 40]); // right, bottom
b = L.bounds([
b = bounds([
[20, 12], // center, top
[14, 20], // left, middle
[30, 40] // right, bottom
]);
c = new L.Bounds();
c = new Bounds();
});
describe('constructor', () => {
it('creates bounds with proper min & max on (Point, Point)', () => {
expect(a.min).to.eql(L.point(14, 12));
expect(a.max).to.eql(L.point(30, 40));
expect(a.min).to.eql(point(14, 12));
expect(a.max).to.eql(point(30, 40));
});
it('creates bounds with proper min & max on (Point[])', () => {
expect(b.min).to.eql(L.point(14, 12));
expect(b.max).to.eql(L.point(30, 40));
expect(b.min).to.eql(point(14, 12));
expect(b.max).to.eql(point(30, 40));
});
});
describe('#extend', () => {
it('extends the bounds to contain the given point', () => {
a.extend([50, 20]);
expect(a.min).to.eql(L.point(14, 12));
expect(a.max).to.eql(L.point(50, 40));
expect(a.min).to.eql(point(14, 12));
expect(a.max).to.eql(point(50, 40));
b.extend([25, 50]);
expect(b.min).to.eql(L.point(14, 12));
expect(b.max).to.eql(L.point(30, 50));
expect(b.min).to.eql(point(14, 12));
expect(b.max).to.eql(point(30, 50));
});
it('extends the bounds by given bounds', () => {
a.extend([20, 50]);
expect(a.max).to.eql(L.point(30, 50));
expect(a.max).to.eql(point(30, 50));
});
it('extends the bounds by given bounds', () => {
a.extend([[20, 50], [8, 40]]);
expect(a.getBottomLeft()).to.eql(L.point(8, 50));
expect(a.getBottomLeft()).to.eql(point(8, 50));
});
it('extends the bounds by undefined', () => {
@ -52,24 +54,23 @@ describe('Bounds', () => {
it('extends the bounds by raw object', () => {
a.extend({x: 20, y: 50});
expect(a.max).to.eql(L.point(30, 50));
expect(a.max).to.eql(point(30, 50));
});
it('extend the bounds by an empty bounds object', () => {
expect(a.extend(L.bounds())).to.eql(a);
expect(a.extend(bounds())).to.eql(a);
});
});
describe('#getCenter', () => {
it('returns the center point', () => {
expect(a.getCenter()).to.eql(L.point(22, 26));
expect(a.getCenter()).to.eql(point(22, 26));
});
});
describe('#pad', () => {
it('pads the bounds by a given ratio', () => {
const bounds = a.pad(0.5);
expect(bounds).to.eql(L.bounds([[6, -2], [38, 54]]));
expect(a.pad(0.5)).to.eql(bounds([[6, -2], [38, 54]]));
});
});
@ -100,7 +101,7 @@ describe('Bounds', () => {
describe('#getSize', () => {
it('returns the size of the bounds as point', () => {
expect(a.getSize()).to.eql(L.point(16, 28));
expect(a.getSize()).to.eql(point(16, 28));
});
});
@ -137,32 +138,31 @@ describe('Bounds', () => {
describe('#getBottomLeft', () => {
it('returns the proper bounds bottom-left value', () => {
expect(a.getBottomLeft()).to.eql(L.point(14, 40)); // left, bottom
expect(a.getBottomLeft()).to.eql(point(14, 40)); // left, bottom
});
});
describe('#getTopRight', () => {
it('returns the proper bounds top-right value', () => {
expect(a.getTopRight()).to.eql(L.point(30, 12)); // right, top
expect(a.getTopRight()).to.eql(point(30, 12)); // right, top
});
});
describe('#getTopLeft', () => {
it('returns the proper bounds top-left value', () => {
expect(a.getTopLeft()).to.eql(L.point(14, 12)); // left, top
expect(a.getTopLeft()).to.eql(point(14, 12)); // left, top
});
});
describe('#getBottomRight', () => {
it('returns the proper bounds bottom-right value', () => {
expect(a.getBottomRight()).to.eql(L.point(30, 40)); // left, bottom
expect(a.getBottomRight()).to.eql(point(30, 40)); // left, bottom
});
});
describe('L.bounds factory', () => {
describe('bounds factory', () => {
it('creates bounds from array of number arrays', () => {
const bounds = L.bounds([[14, 12], [30, 40]]);
expect(bounds).to.eql(a);
expect(bounds([[14, 12], [30, 40]])).to.eql(a);
});
});