Files
paseo/packages/app/src/components/project-picker-options.test.ts
T
Mohamed BoudraandGitHub a929ea9726 Show an error for missing project paths (#1490)
* Fix missing project paths flashing in the sidebar

* Log project lifecycle changes

* Address project picker review feedback

* Show project picker transport errors

* Inject session filesystem for workspace tests
2026-06-12 23:42:21 +08:00

81 lines
2.4 KiB
TypeScript

import { describe, expect, it } from "vitest";
import { buildProjectPickerOptions, isOpenableProjectPath } from "./project-picker-options";
describe("isOpenableProjectPath", () => {
it("accepts POSIX, tilde, Windows drive-letter, and UNC paths", () => {
expect(isOpenableProjectPath("/repo")).toBe(true);
expect(isOpenableProjectPath("~/src")).toBe(true);
expect(isOpenableProjectPath("C:\\Users\\mo")).toBe(true);
expect(isOpenableProjectPath("c:/users/mo")).toBe(true);
expect(isOpenableProjectPath("\\\\server\\share")).toBe(true);
});
it("rejects relative input", () => {
expect(isOpenableProjectPath("repo")).toBe(false);
expect(isOpenableProjectPath("repo/sub")).toBe(false);
expect(isOpenableProjectPath("c:repo")).toBe(false);
expect(isOpenableProjectPath("")).toBe(false);
});
});
describe("buildProjectPickerOptions", () => {
it("does not create an open-path row for word queries", () => {
const options = buildProjectPickerOptions({
recommendedPaths: ["/repo/api"],
serverPaths: ["/repo/app"],
query: "repo",
});
expect(options).toEqual([
{ kind: "suggestion", path: "/repo/api" },
{ kind: "suggestion", path: "/repo/app" },
]);
});
it("puts an absolute path row first", () => {
const options = buildProjectPickerOptions({
recommendedPaths: ["/repo/api"],
serverPaths: [],
query: "/repo",
});
expect(options).toEqual([
{ kind: "path", path: "/repo" },
{ kind: "suggestion", path: "/repo/api" },
]);
});
it("puts a home-relative path row first", () => {
const options = buildProjectPickerOptions({
recommendedPaths: ["/Users/mo/src/api"],
serverPaths: [],
query: "~/src",
});
expect(options).toEqual([
{ kind: "path", path: "~/src" },
{ kind: "suggestion", path: "/Users/mo/src/api" },
]);
});
it("creates an open-path row for Windows paths", () => {
const options = buildProjectPickerOptions({
recommendedPaths: [],
serverPaths: [],
query: "C:\\Users\\mo\\src",
});
expect(options).toEqual([{ kind: "path", path: "C:\\Users\\mo\\src" }]);
});
it("does not duplicate an existing suggestion", () => {
const options = buildProjectPickerOptions({
recommendedPaths: ["/repo/api"],
serverPaths: ["/repo/app"],
query: "/repo/app",
});
expect(options).toEqual([{ kind: "suggestion", path: "/repo/app" }]);
});
});