UNPKG

geospatialdraw

Version:
178 lines 7.48 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); require("../../internal/tests"); var React = require("react"); var chai_1 = require("chai"); var enzyme_1 = require("enzyme"); var geometry_1 = require("../../geometry"); var units_1 = require("../units"); var flat_coordinate_list_geo_editor_1 = require("./flat-coordinate-list-geo-editor"); describe('<FlatCoordinateListGeoEditor />', function () { it('render', function () { var startGeo = (0, geometry_1.makeEmptyGeometry)('', 'Polygon'); startGeo.geometry.coordinates = [ [10, 12], [30, 50], [45, 34], [32, 24], [10, 12], ]; startGeo.bbox = [10, 12, 45, 50]; startGeo.properties.buffer = 1; startGeo.properties.bufferUnit = 'meters'; var wrapper = (0, enzyme_1.shallow)( // @ts-ignore React.createElement(flat_coordinate_list_geo_editor_1.FlatCoordinateListGeoEditor, { geo: startGeo, coordinateUnit: units_1.LAT_LON, onUpdateGeo: function (geo) { return geo; }, getCoordinatesFromGeo: function () { return [ [10, 12], [30, 50], [45, 34], [32, 24], ]; }, // @ts-ignore updateGeoCoordinates: function () { } })); (0, chai_1.expect)(wrapper.find('FlatCoordinateListEditor').prop('buffer')).to.equal(1); (0, chai_1.expect)(wrapper.find('FlatCoordinateListEditor').prop('bufferUnit')).to.equal('meters'); (0, chai_1.expect)(wrapper.find('FlatCoordinateListEditor').prop('coordinateList')).to.deep.equal([ [10, 12], [30, 50], [45, 34], [32, 24], ]); (0, chai_1.expect)(wrapper.find('FlatCoordinateListEditor').prop('coordinateUnit')).to.equal(units_1.LAT_LON); (0, chai_1.expect)(wrapper.find('FlatCoordinateListEditor').prop('lat')).to.equal(12); (0, chai_1.expect)(wrapper.find('FlatCoordinateListEditor').prop('lon')).to.equal(10); (0, chai_1.expect)(wrapper.exists()).to.equal(true); }); describe('set properties', function () { var startCoordinates = [ [10, 12], [30, 50], [45, 34], [32, 24], ]; var getWrapper = function (expected, onUpdateGeo) { var startGeo = (0, geometry_1.makeEmptyGeometry)('', 'Line'); startGeo.geometry.coordinates = startCoordinates; startGeo.bbox = [10, 12, 45, 50]; return (0, enzyme_1.shallow)( // @ts-ignore React.createElement(flat_coordinate_list_geo_editor_1.FlatCoordinateListGeoEditor // @ts-ignore , { // @ts-ignore getCoordinatesFromGeo: function () { return startCoordinates; }, updateGeoCoordinates: function (geo, coordinates) { (0, chai_1.expect)(coordinates).to.deep.equal(expected); return geo; }, geo: startGeo, coordinateUnit: units_1.LAT_LON, onUpdateGeo: onUpdateGeo })); }; it('setBuffer', function (done) { var wrapper = getWrapper(startCoordinates, function (geo) { (0, chai_1.expect)(geo.properties.buffer).to.equal(12.7); done(); }); // @ts-ignore wrapper.find('FlatCoordinateListEditor').prop('setBuffer')(12.7); }); it('setUnit', function (done) { var wrapper = getWrapper(startCoordinates, function (geo) { (0, chai_1.expect)(geo.properties.bufferUnit).to.equal('nautical miles'); done(); }); // @ts-ignore wrapper.find('FlatCoordinateListEditor').prop('setUnit')('nautical miles'); }); describe('edit coordinates', function () { var testSetCoordinateFactory = function (action) { return function (done, editIndex, expected) { var updateGeo = function (geo) { done(); return geo; }; var wrapper = getWrapper(expected, updateGeo); wrapper.setState({ editIndex: editIndex }); wrapper.find('FlatCoordinateListEditor').prop(action)(15.8, 13.6); }; }; describe('setCoordinate', function () { var testSetCoordinate = testSetCoordinateFactory('setCoordinate'); it('first coordinate', function (done) { testSetCoordinate(done, 0, [ [13.6, 15.8], [30, 50], [45, 34], [32, 24], ]); }); it('middle coordinate', function (done) { testSetCoordinate(done, 1, [ [10, 12], [13.6, 15.8], [45, 34], [32, 24], ]); }); it('last coordinate', function (done) { testSetCoordinate(done, 3, [ [10, 12], [30, 50], [45, 34], [13.6, 15.8], ]); }); }); describe('addCoordinate', function () { var testSetCoordinate = testSetCoordinateFactory('addCoordinate'); it('first coordinate', function (done) { testSetCoordinate(done, 0, [ [10, 12], [0, 0], [30, 50], [45, 34], [32, 24], ]); }); it('middle coordinate', function (done) { testSetCoordinate(done, 1, [ [10, 12], [30, 50], [0, 0], [45, 34], [32, 24], ]); }); it('last coordinate', function (done) { testSetCoordinate(done, 3, [ [10, 12], [30, 50], [45, 34], [32, 24], [0, 0], ]); }); }); describe('deleteCoordinate', function () { var testSetCoordinate = testSetCoordinateFactory('deleteCoordinate'); it('first coordinate', function (done) { testSetCoordinate(done, 0, [ [30, 50], [45, 34], [32, 24], ]); }); it('middle coordinate', function (done) { testSetCoordinate(done, 1, [ [10, 12], [45, 34], [32, 24], ]); }); it('last coordinate', function (done) { testSetCoordinate(done, 3, [ [10, 12], [30, 50], [45, 34], ]); }); }); }); }); }); //# sourceMappingURL=flat-coordinate-list-geo-editor.spec.js.map