Fix workspace shortcut navigation

This commit is contained in:
Mohamed Boudra
2026-04-20 18:06:09 +07:00
parent 95c1d1fe0f
commit 2cd296e38f
16 changed files with 513 additions and 155 deletions
@@ -0,0 +1,39 @@
import { describe, expect, it } from "vitest";
import type { HostProfile } from "@/types/host-connection";
import { resolveActiveHost } from "./active-host";
function host(serverId: string): HostProfile {
return {
serverId,
label: serverId,
lifecycle: {},
connections: [],
preferredConnectionId: null,
createdAt: "",
updatedAt: "",
};
}
describe("resolveActiveHost", () => {
it("uses the route host when it exists", () => {
expect(
resolveActiveHost({
hosts: [host("srv-1"), host("srv-2")],
pathname: "/h/srv-2/workspace/ws-main",
})?.serverId,
).toBe("srv-2");
});
it("falls back to the first host when the route host is missing", () => {
expect(
resolveActiveHost({
hosts: [host("srv-1"), host("srv-2")],
pathname: "/h/missing/workspace/ws-main",
})?.serverId,
).toBe("srv-1");
});
it("returns null when no hosts exist", () => {
expect(resolveActiveHost({ hosts: [], pathname: "/settings" })).toBeNull();
});
});