- Implemented StationListLoadingState component for loading messages. - Created MenuLED component to display LED information with loading animations. - Developed MenuMap component for interactive map features, including user location markers and station markers. - Introduced LEDFrame component for consistent styling of LED displays. - Enhanced LED_vision component to support embedded rendering and content readiness. - Added menuStationSelectors for managing nearby and favorite station groups. - Updated Menu component to integrate new loading states and map functionalities. - Added tests for menuStationSelectors to ensure correct grouping and selection logic.
125 lines
3.2 KiB
TypeScript
125 lines
3.2 KiB
TypeScript
import { strict as assert } from "node:assert";
|
|
import { test } from "node:test";
|
|
import type { OriginalStationList, StationProps } from "../lib/CommonTypes";
|
|
import {
|
|
getMenuStationGroups,
|
|
getNearbyStationGroups,
|
|
} from "../lib/menuStationSelectors";
|
|
import type { StationSource } from "../types";
|
|
|
|
const station = (overrides: Partial<StationProps>): StationProps => ({
|
|
DispNum: "",
|
|
MyStation: "",
|
|
StationMap: "",
|
|
StationNumber: null,
|
|
StationTimeTable: "",
|
|
StationName: "",
|
|
Station_EN: "",
|
|
Station_JP: "",
|
|
jslodApi: "",
|
|
lat: 0,
|
|
lng: 0,
|
|
...overrides,
|
|
});
|
|
|
|
const lineNames = ["yosan"];
|
|
const lineWebIds = { yosan: "yosan" };
|
|
const stationIds = { yosan: "Y" };
|
|
|
|
test("nearby selector groups duplicate station names in distance order", () => {
|
|
const originalStationList: OriginalStationList = {
|
|
yosan: [
|
|
station({
|
|
Station_JP: "高松",
|
|
StationNumber: "Y00",
|
|
lat: 0.02,
|
|
}),
|
|
station({
|
|
Station_JP: "高松",
|
|
StationNumber: "Y00-alt",
|
|
lat: 0.01,
|
|
}),
|
|
station({
|
|
Station_JP: "坂出",
|
|
StationNumber: "Y10",
|
|
lat: 0.005,
|
|
}),
|
|
],
|
|
観光スポット: [
|
|
station({
|
|
Station_JP: "栗林公園",
|
|
StationNumber: "spot",
|
|
lat: 0.003,
|
|
}),
|
|
],
|
|
};
|
|
|
|
const groups = getNearbyStationGroups({
|
|
coordinates: { latitude: 0, longitude: 0 },
|
|
originalStationList,
|
|
lineNames,
|
|
});
|
|
|
|
assert.deepEqual(
|
|
groups.map((group) => group.map((item) => item.StationNumber)),
|
|
[["spot"], ["Y10"], ["Y00-alt", "Y00"]],
|
|
);
|
|
});
|
|
|
|
const selectorBase = (originalStationList: OriginalStationList) => ({
|
|
originalStationList,
|
|
nearbyPositionStations: [],
|
|
favoriteStations: [],
|
|
findStationsByName: (_query: string) => [],
|
|
lineWebIds,
|
|
stationIds,
|
|
});
|
|
|
|
test("menu selector returns only stations for a selected line", () => {
|
|
const selected = station({ StationNumber: "Y00", Station_JP: "高松" });
|
|
const other = station({ StationNumber: null, Station_JP: "駅間" });
|
|
|
|
const result = getMenuStationGroups({
|
|
...selectorBase({ yosan: [selected, other] }),
|
|
stationSource: { type: "search", query: "", lineId: "Y" },
|
|
});
|
|
|
|
assert.deepEqual(result, [[selected]]);
|
|
});
|
|
|
|
test("menu selector groups search results by station name", () => {
|
|
const yosan = station({ StationNumber: "Y00", Station_JP: "高松" });
|
|
const kotoku = station({ StationNumber: "T28", Station_JP: "高松" });
|
|
const source: StationSource = { type: "search", query: "高", lineId: undefined };
|
|
|
|
const result = getMenuStationGroups({
|
|
...selectorBase({}),
|
|
stationSource: source,
|
|
findStationsByName: () => [yosan, kotoku],
|
|
});
|
|
|
|
assert.deepEqual(result, [[yosan, kotoku]]);
|
|
});
|
|
|
|
test("menu selector preserves position and favorite station groups", () => {
|
|
const position = [[station({ StationNumber: "Y00" })]];
|
|
const favorite = [[station({ StationNumber: "T28" })]];
|
|
|
|
assert.deepEqual(
|
|
getMenuStationGroups({
|
|
...selectorBase({}),
|
|
nearbyPositionStations: position,
|
|
stationSource: { type: "position" },
|
|
}),
|
|
position,
|
|
);
|
|
assert.deepEqual(
|
|
getMenuStationGroups({
|
|
...selectorBase({}),
|
|
favoriteStations: favorite,
|
|
stationSource: { type: "favorite" },
|
|
}),
|
|
favorite,
|
|
);
|
|
});
|