Add more marker and line tests

pull/256/head
Candid Dauth 2024-03-16 00:33:46 +01:00
rodzic e7c377105f
commit 21e7aa70e3
2 zmienionych plików z 106 dodań i 5 usunięć

Wyświetl plik

@ -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

Wyświetl plik

@ -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();