diff --git a/src/data/floor_registry.ts b/src/data/floor_registry.ts index 052cc34bd0..8bff8df5a3 100644 --- a/src/data/floor_registry.ts +++ b/src/data/floor_registry.ts @@ -76,7 +76,7 @@ export const floorCompare = const floorA = entries?.[a]; const floorB = entries?.[b]; if (floorA && floorB && floorA.level !== floorB.level) { - return (floorA.level ?? 9999) - (floorB.level ?? 9999); + return (floorB.level ?? -9999) - (floorA.level ?? -9999); } const nameA = floorA?.name ?? a; const nameB = floorB?.name ?? b; diff --git a/test/data/floor_registry.test.ts b/test/data/floor_registry.test.ts index 585247281b..abb14e89b0 100644 --- a/test/data/floor_registry.test.ts +++ b/test/data/floor_registry.test.ts @@ -26,7 +26,7 @@ describe("floorCompare", () => { }); describe("floorCompare(entries)", () => { - it("sorts by level, then by name", () => { + it("sorts by level descending (highest to lowest), then by name", () => { const entries = { floor1: { name: "Ground Floor", level: 0 } as FloorRegistryEntry, floor2: { name: "First Floor", level: 1 } as FloorRegistryEntry, @@ -35,13 +35,13 @@ describe("floorCompare", () => { const floors = ["floor1", "floor2", "floor3"]; expect(floors.sort(floorCompare(entries))).toEqual([ - "floor3", - "floor1", "floor2", + "floor1", + "floor3", ]); }); - it("treats null level as 9999, placing it at the end", () => { + it("treats null level as -9999, placing it at the end", () => { const entries = { floor1: { name: "Ground Floor", level: 0 } as FloorRegistryEntry, floor2: { name: "First Floor", level: 1 } as FloorRegistryEntry, @@ -50,8 +50,8 @@ describe("floorCompare", () => { const floors = ["floor2", "floor3", "floor1"]; expect(floors.sort(floorCompare(entries))).toEqual([ - "floor1", "floor2", + "floor1", "floor3", ]); });