All files / src/test helpers.ts

86.95% Statements 20/23
50% Branches 2/4
70% Functions 7/10
87.5% Lines 14/16

Press n or j to go to the next uncovered block, b, p or k for the previous block.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87  1x   1x 25x             16x                 1x               1x                     34x                     24x   19x                   1x 9x             1x 10x               1x              
import { Feature, FeatureCollection, LineString } from "geojson";
import { TerraDrawExtend, TerraDrawMouseEvent } from "terra-draw";
 
export function MockModeConfig() {
    return {
        mode: "routesnap",
        store: new TerraDrawExtend.GeoJSONStore(),
        setCursor: jest.fn(),
        onChange: jest.fn(),
        onSelect: jest.fn(),
        onDeselect: jest.fn(),
        project: jest.fn((lng, lat) => ({ x: lng * 40, y: lat * 40 })),
        unproject: jest.fn((x, y) => ({ lng: x / 40, lat: y / 40 })),
        setDoubleClickToZoom: jest.fn(),
        onFinish: jest.fn(),
        coordinatePrecision: 9,
        projection: "web-mercator",
    };
}
 
export function MockRouteFinder() {
    return {
        getRoute: jest.fn(),
        setNetwork: jest.fn(),
        expandNetwork: jest.fn(),
    };
}
 
export const MockCursorEvent = ({
    lng,
    lat,
    button,
    isContextMenu,
}: {
    lng: TerraDrawMouseEvent["lng"];
    lat: TerraDrawMouseEvent["lat"];
    button?: TerraDrawMouseEvent["button"];
    isContextMenu?: boolean;
}) =>
    ({
        lng,
        lat,
        containerX: lng * 40,
        containerY: lat * 40,
        button: button ? button : ("left" as const),
        heldKeys: [],
        isContextMenu: isContextMenu ? isContextMenu : false,
    }) as TerraDrawMouseEvent;
 
 
export const CreateLineStringCollection = (lineStringCoordinates: LineString['coordinates'][]): FeatureCollection<LineString> => ({
    type: "FeatureCollection",
    features: lineStringCoordinates.map(coords => ({
        type: "Feature",
        geometry: {
            type: "LineString",
            coordinates: coords
        },
        properties: {}
    })),
});
 
export const CreateTwoPointNetwork = () =>
    CreateLineStringCollection([
        [
            [1, 2],
            [3, 4],
        ],
    ]);
 
export const CreateThreePointNetwork = () =>
    CreateLineStringCollection([
        [
            [1, 2],
            [3, 4],
            [5, 6],
        ],
    ]);
 
export const CreateLineString = (coordinates: LineString['coordinates']): Feature<LineString> => ({
    type: "Feature",
    geometry: {
        type: "LineString",
        coordinates
    },
    properties: {}
});