refactor(app): extract project icon placeholder label logic
This commit is contained in:
@@ -0,0 +1,27 @@
|
||||
import { describe, expect, it } from "vitest";
|
||||
import {
|
||||
projectDisplayNameFromProjectId,
|
||||
projectIconPlaceholderLabelFromDisplayName,
|
||||
} from "./project-display-name";
|
||||
|
||||
describe("projectDisplayNameFromProjectId", () => {
|
||||
it("shows owner and repo for GitHub remote ids", () => {
|
||||
expect(projectDisplayNameFromProjectId("remote:github.com/getpaseo/paseo")).toBe(
|
||||
"getpaseo/paseo"
|
||||
);
|
||||
});
|
||||
|
||||
it("shows the trailing directory name for local projects", () => {
|
||||
expect(projectDisplayNameFromProjectId("/Users/me/dev/paseo")).toBe("paseo");
|
||||
});
|
||||
});
|
||||
|
||||
describe("projectIconPlaceholderLabelFromDisplayName", () => {
|
||||
it("uses repo name instead of owner for GitHub-style display names", () => {
|
||||
expect(projectIconPlaceholderLabelFromDisplayName("getpaseo/paseo")).toBe("paseo");
|
||||
});
|
||||
|
||||
it("returns the original display name when it has no path separator", () => {
|
||||
expect(projectIconPlaceholderLabelFromDisplayName("paseo")).toBe("paseo");
|
||||
});
|
||||
});
|
||||
@@ -7,3 +7,15 @@ export function projectDisplayNameFromProjectId(projectId: string): string {
|
||||
const segments = projectId.split(/[\\/]/).filter(Boolean);
|
||||
return segments[segments.length - 1] || projectId;
|
||||
}
|
||||
|
||||
export function projectIconPlaceholderLabelFromDisplayName(
|
||||
displayName: string
|
||||
): string {
|
||||
const trimmedDisplayName = displayName.trim();
|
||||
if (!trimmedDisplayName) {
|
||||
return "";
|
||||
}
|
||||
|
||||
const segments = trimmedDisplayName.split("/").filter(Boolean);
|
||||
return segments[segments.length - 1] || trimmedDisplayName;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user