geospatialdraw
Version:
Geospatial Map Drawing Library
143 lines • 5.9 kB
JavaScript
Object.defineProperty(exports, "__esModule", { value: true });
var chai_1 = require("chai");
var mock_drawing_context_1 = require("./test/mock-drawing-context");
var bounding_box_drawing_control_1 = require("./bounding-box-drawing-control");
describe('BoundingBoxDrawingControl', function () {
var makePolygonJSON = function () {
return ({
type: 'Feature',
properties: {
color: '#996600',
shape: 'Bounding Box',
id: 'identifier',
buffer: 0,
bufferUnit: 'meters',
},
geometry: {
type: 'Polygon',
coordinates: [
[
[10, 10],
[50, 10],
[50, 50],
[10, 50],
[10, 10],
],
],
},
bbox: [10, 10, 50, 50],
});
};
describe('constructor', function () {
it('default', function () {
var context = new mock_drawing_context_1.default();
var receiver = function () { };
new bounding_box_drawing_control_1.default(context, receiver);
});
});
describe('setGeo', function () {
it('default', function () {
var context = new mock_drawing_context_1.default();
var receiver = function () { };
var control = new bounding_box_drawing_control_1.default(context, receiver);
control.setGeo(makePolygonJSON());
var expected = makePolygonJSON();
(0, chai_1.expect)(context
.getMethodCalls()
.updateFeature[0][0].getGeometry()
.getCoordinates()).to.deep.equal(expected.geometry.coordinates);
(0, chai_1.expect)(context.getMethodCalls().updateFeature.length).to.equal(1);
(0, chai_1.expect)(context.getMethodCalls().removeFeature.length).to.equal(0);
(0, chai_1.expect)(control.isDrawing()).to.equal(true);
});
});
describe('startDrawing', function () {
it('default', function () {
var context = new mock_drawing_context_1.default();
var receiver = function () { };
var control = new bounding_box_drawing_control_1.default(context, receiver);
control.startDrawing();
(0, chai_1.expect)(context.getMethodCalls().addInteractions.length).to.equal(0);
(0, chai_1.expect)(context.getMethodCalls().addInteractionsWithoutModify.length).to.equal(1);
(0, chai_1.expect)(context.getMethodCalls().setEvent.length).to.equal(1);
(0, chai_1.expect)(context.getMethodCalls().setDrawInteraction.length).to.equal(1);
(0, chai_1.expect)(context.getMethodCalls().updateFeature.length).to.equal(0);
(0, chai_1.expect)(context.getMethodCalls().removeFeature.length).to.equal(1);
(0, chai_1.expect)(control.isDrawing()).to.equal(true);
});
});
describe('cancelDrawing', function () {
it('default', function () {
var context = new mock_drawing_context_1.default();
var receiver = function () { };
var control = new bounding_box_drawing_control_1.default(context, receiver);
control.cancelDrawing();
(0, chai_1.expect)(context.getMethodCalls().removeListeners.length).to.equal(1);
(0, chai_1.expect)(context.getMethodCalls().removeInteractions.length).to.equal(1);
(0, chai_1.expect)(control.isDrawing()).to.equal(false);
});
});
describe('extentChanged', function () {
var makeExtent = function () {
return [11, 20, 50, 60];
};
var makeExpectedJSON = function () { return ({
type: 'Feature',
properties: {
color: '#996600',
shape: 'Bounding Box',
id: '',
buffer: 0,
bufferUnit: 'meters',
},
geometry: {
type: 'Polygon',
coordinates: [
[
[11, 20],
[50, 20],
[50, 60],
[11, 60],
[11, 20],
],
],
},
bbox: makeExtent(),
}); };
it('default', function () {
var context = new mock_drawing_context_1.default();
var updated = null;
var receiver = function (geoJSON) {
updated = geoJSON;
};
var control = new bounding_box_drawing_control_1.default(context, receiver);
control.extentChanged({
extent: makeExtent(),
});
var expected = makeExpectedJSON();
(0, chai_1.expect)(updated).to.deep.equal(expected);
});
it('startDrawing -> extentChanged', function () {
var context = new mock_drawing_context_1.default();
var updated = null;
var receiver = function (geoJSON) {
updated = geoJSON;
};
// @ts-ignore
var control = new bounding_box_drawing_control_1.default(context, receiver);
control.startDrawing();
// @ts-ignore
control.setGeo(makePolygonJSON());
control.extentChanged({
// @ts-ignore
extent: makeExtent(),
});
var expected = makeExpectedJSON();
expected.properties.id = 'identifier';
expected.properties.color = '#996600';
(0, chai_1.expect)(updated).to.deep.equal(expected);
});
});
});
//# sourceMappingURL=bounding-box-drawing-control.spec.js.map
;