view client/tests/unit/geo/geo.spec.js @ 696:1db1ae344087

refac: test adjusted. testdata as JSON string
author Thomas Junk <thomas.junk@intevation.de>
date Thu, 20 Sep 2018 15:54:34 +0200
parents 87ea9d267c2b
children 0c5cbbafbd94
line wrap: on
line source

import { prepareProfile } from "../../../src/application/lib/geo";

const geoJSON = JSON.parse(`{
	"type": "Feature",
	"geometry": {
		"type": "MultiLineString",
		"coordinates": [
			[
				[17.216391563415527, 48.0245195664277, 123],
				[17.216777801513672, 48.024720482272315, 124]
			],
			[
				[17.218494415283203, 48.02540933065123, 125],
				[17.219438552856445, 48.02586855778941, 126],
				[17.220726013183594, 48.02647128719908, 127],
				[17.221627235412598, 48.026987906797494, 128],
				[17.222957611083984, 48.02759062311748, 129],
				[17.223901748657227, 48.0280785311666, 130],
				[17.224159240722656, 48.02819333238926, 131]
			],
			[
				[17.225961685180664, 48.02891083423718, 132],
				[17.227892875671383, 48.02997271864036, 133]
			]
		]
	},
	"properties": {}
}`);

test("prepare diagram", () => {
  const coordinates = geoJSON.geometry.coordinates;
  const firstSegment = coordinates[0];
  const lastSegment = coordinates[coordinates.length - 1];
  const startPoint = firstSegment[0];
  const endPoint = lastSegment[lastSegment.length - 1];
  const result = prepareProfile({ geoJSON, startPoint, endPoint });
  const alts = result.points.reduce((o, n) => {
    let y = n.map(e => {
      return e.y;
    });
    o = o.concat(y);
    return o;
  }, []);
  const growing = values => {
    let first = values[0].x;
    for (let v of values) {
      if (first > v.x) return false;
    }
    return true;
  };
  const minAlt = Math.min(...alts);
  const maxAlt = Math.max(...alts);
  expect(result.minAlt).toBe(minAlt);
  expect(result.maxAlt).toBe(maxAlt);
  expect(growing(result.points[0])).toBe(true);
  expect(result.lengthPolyLine == 1051.5361933142963).toBe(true);
});