From 21e7aa70e310b9bd6ad6ce2e1fa9b95bb92c1261 Mon Sep 17 00:00:00 2001 From: Candid Dauth Date: Sat, 16 Mar 2024 00:33:46 +0100 Subject: [PATCH] Add more marker and line tests --- integration-tests/src/lines.test.ts | 42 ++++++++++++++-- integration-tests/src/markers.test.ts | 69 ++++++++++++++++++++++++++- 2 files changed, 106 insertions(+), 5 deletions(-) diff --git a/integration-tests/src/lines.test.ts b/integration-tests/src/lines.test.ts index 134add24..d18eeeff 100644 --- a/integration-tests/src/lines.test.ts +++ b/integration-tests/src/lines.test.ts @@ -1,8 +1,8 @@ import { expect, test, vi } from "vitest"; import { createTemporaryPad, emit, getTemporaryPadData, openClient, openSocket, retry } from "./utils"; -import { SocketVersion, CRU, type Line, type LinePointsEvent } from "facilmap-types"; +import { SocketVersion, CRU, type Line, type LinePointsEvent, type FindOnMapLine } from "facilmap-types"; import type { LineWithTrackPoints } from "facilmap-client"; -import { cloneDeep, isEqual, omit } from "lodash-es"; +import { cloneDeep, omit } from "lodash-es"; test("Create line (using default values)", async () => { // client1: Creates the line and has it in its bbox @@ -360,6 +360,42 @@ test("Delete line", async () => { }); }); +test("Find line", async () => { + const client1 = await openClient(); + + await createTemporaryPad(client1, {}, async (createPadData, padData) => { + const client2 = await openClient(padData.id); + + const lineType = Object.values(client1.types).find((t) => t.type === "line")!; + + const marker = await client1.addLine({ + name: "Line test", + routePoints: [ + { lat: 6, lon: 6 }, + { lat: 14, lon: 14 } + ], + typeId: lineType.id + }); + + const expectedResult: FindOnMapLine = { + id: marker.id, + kind: "line", + similarity: 1, + typeId: lineType.id, + name: "Line test", + top: 14, + right: 14, + bottom: 6, + left: 6 + }; + + expect(await client2.findOnMap({ query: "Test" })).toEqual([{ ...expectedResult, similarity: 0.4 }]); + expect(await client2.findOnMap({ query: "T_st" })).toEqual([{ ...expectedResult, similarity: 0.2 }]); + expect(await client2.findOnMap({ query: "L%e" })).toEqual([{ ...expectedResult, similarity: 0 }]); + expect(await client2.findOnMap({ query: "Bla" })).toEqual([]); + }); +}); + test("Try to create line with marker type", async () => { const client = await openClient(); @@ -553,8 +589,6 @@ test("Socket v1 line name", async () => { } }); -// TODO: findOnMap - // getLineTemplate // exportLine // findOnMap \ No newline at end of file diff --git a/integration-tests/src/markers.test.ts b/integration-tests/src/markers.test.ts index 235cbca0..23e84440 100644 --- a/integration-tests/src/markers.test.ts +++ b/integration-tests/src/markers.test.ts @@ -1,6 +1,6 @@ import { expect, test, vi } from "vitest"; import { createTemporaryPad, emit, getTemporaryPadData, openClient, openSocket, retry } from "./utils"; -import { SocketVersion, CRU, type Marker } from "facilmap-types"; +import { SocketVersion, CRU, type Marker, type FindOnMapMarker } from "facilmap-types"; import { cloneDeep } from "lodash-es"; test("Create marker (using default values)", async () => { @@ -225,6 +225,73 @@ test("Delete marker", async () => { }); }); +test("Get marker", async () => { + const client1 = await openClient(); + + await createTemporaryPad(client1, {}, async (createPadData, padData) => { + const client2 = await openClient(padData.id); + + const markerType = Object.values(client1.types).find((t) => t.type === "marker")!; + + const marker = await client1.addMarker({ + lat: 10, + lon: 10, + typeId: markerType.id + }); + + const expectedMarker = { + id: marker.id, + lat: 10, + lon: 10, + typeId: markerType.id, + padId: padData.id, + name: "", + colour: "ff0000", + size: 30, + symbol: "", + shape: "", + data: {}, + ele: null + } satisfies Marker; + + expect(await client2.getMarker({ id: marker.id })).toEqual(expectedMarker); + }); +}); + +test("Find marker", async () => { + const client1 = await openClient(); + + await createTemporaryPad(client1, {}, async (createPadData, padData) => { + const client2 = await openClient(padData.id); + + const markerType = Object.values(client1.types).find((t) => t.type === "marker")!; + + const marker = await client1.addMarker({ + name: "Marker test", + lat: 10, + lon: 10, + typeId: markerType.id, + symbol: "a" + }); + + const expectedResult: FindOnMapMarker = { + id: marker.id, + kind: "marker", + similarity: 1, + lat: 10, + lon: 10, + typeId: markerType.id, + name: "Marker test", + symbol: "a" + }; + + expect(await client2.findOnMap({ query: "Test" })).toEqual([{ ...expectedResult, similarity: 0.3333333333333333 }]); + expect(await client2.findOnMap({ query: "T_st" })).toEqual([{ ...expectedResult, similarity: 0.16666666666666666 }]); + expect(await client2.findOnMap({ query: "M%r" })).toEqual([{ ...expectedResult, similarity: 0 }]); + expect(await client2.findOnMap({ query: "Bla" })).toEqual([]); + }); +}); + test("Try to create marker with line type", async () => { const client = await openClient();