UNPKG

isoxml-angular

Version:

JavaScript library to parse and generate ISOXML (ISO11783-10) files

67 lines (66 loc) 3.69 kB
"use strict"; var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); } return new (P || (P = Promise))(function (resolve, reject) { function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } } function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } } function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); } step((generator = generator.apply(thisArg, _arguments || [])).next()); }); }; Object.defineProperty(exports, "__esModule", { value: true }); const fs_1 = require("fs"); const ISOXMLManager_1 = require("../ISOXMLManager"); const Task_1 = require("./Task"); const baseEntities_1 = require("../baseEntities"); describe('Task Entity', () => { it('should add Grid from GeoJSON', () => __awaiter(void 0, void 0, void 0, function* () { const geoJSONdata = JSON.parse((0, fs_1.readFileSync)('./data/test.geojson', 'utf-8')); const isoxmlManager = new ISOXMLManager_1.ISOXMLManager(); const task = new Task_1.ExtendedTask({ TaskStatus: "1" /* TaskTaskStatusEnum.Planned */ }, isoxmlManager); task.addGridFromGeoJSON(geoJSONdata, 1); expect(task.attributes.TreatmentZone).toHaveLength(2); expect(task.attributes.Grid).toHaveLength(1); })); it('should return Grid as GeoJSON', () => __awaiter(void 0, void 0, void 0, function* () { const geoJSONdata = JSON.parse((0, fs_1.readFileSync)('./data/test.geojson', 'utf-8')); const isoxmlManager = new ISOXMLManager_1.ISOXMLManager(); const task = new Task_1.ExtendedTask({ TaskStatus: "1" /* TaskTaskStatusEnum.Planned */ }, isoxmlManager); task.addGridFromGeoJSON(geoJSONdata, 1); const geoJSON = task.getGridAsGeoJSON(); expect(geoJSON).toBeTruthy(); expect(geoJSON.features[0].properties.DOSE).toBe(16); // 15.7 should be rounded to 16 })); it('should return grid values description', () => __awaiter(void 0, void 0, void 0, function* () { const geoJSONdata = JSON.parse((0, fs_1.readFileSync)('./data/test.geojson', 'utf-8')); const isoxmlManager = new ISOXMLManager_1.ISOXMLManager(); const task = new Task_1.ExtendedTask({ TaskStatus: "1" /* TaskTaskStatusEnum.Planned */ }, isoxmlManager); const descriptionBefore = task.getGridValuesDescription(); expect(descriptionBefore).toHaveLength(0); task.addGridFromGeoJSON(geoJSONdata, 1); const descriptionAfter = task.getGridValuesDescription(); expect(descriptionAfter).toHaveLength(1); expect(descriptionAfter[0].DDINumber).toBe(1); expect(descriptionAfter[0].scale).toBe(0.01); expect(descriptionAfter[0].offset).toBe(0); const vpn = new baseEntities_1.ValuePresentation({ Offset: 20, Scale: 2, NumberOfDecimals: 1, UnitDesignator: 'custom-unit' }, isoxmlManager); task.addGridFromGeoJSON(geoJSONdata, 1, null, isoxmlManager.registerEntity(vpn)); const descriptionAfterWithVPN = task.getGridValuesDescription(); expect(descriptionAfterWithVPN).toHaveLength(1); expect(descriptionAfterWithVPN[0].DDINumber).toBe(1); expect(descriptionAfterWithVPN[0].scale).toBe(2); expect(descriptionAfterWithVPN[0].offset).toBe(20); expect(descriptionAfterWithVPN[0].unit).toBe('custom-unit'); })); });