mirror of
https://github.com/home-assistant/frontend.git
synced 2025-12-20 02:38:53 +00:00
Invert floor sort order to match physical layout (#27580)
This commit is contained in:
@@ -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;
|
||||
|
||||
@@ -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",
|
||||
]);
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user