Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
37 changes: 37 additions & 0 deletions src/test/providers/pathOperationTreeProvider.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,18 @@ suite("getAppLabel", () => {
test("falls back to filename when no parent dirs", () => {
assert.strictEqual(getAppLabel(makeApp("app", "main.py")), "main")
})

test("decodes a URI path before using the parent directory", () => {
assert.strictEqual(
getAppLabel(
makeApp(
"app",
"file:///c%3A/project/day01_FastAPI%E5%9F%BA%E7%A1%80/%E4%BB%A3%E7%A0%81/01-%E8%B7%AF%E7%94%B1.py",
),
),
"代码",
)
})
})

suite("getRouterLabel", () => {
Expand Down Expand Up @@ -122,6 +134,31 @@ suite("getRouterLabel", () => {
"items",
)
})

test("decodes a URI path before using the filename", () => {
assert.strictEqual(
getRouterLabel(
makeRouter("/", {
filePath:
"file:///project/%E4%BB%A3%E7%A0%81/01-%E8%B7%AF%E7%94%B1.py",
}),
"/",
),
"01-路由",
)
})

test("decodes a URI path before using a generic filename's parent", () => {
assert.strictEqual(
getRouterLabel(
makeRouter("/", {
filePath: "file:///project/%E4%BB%A3%E7%A0%81/routes.py",
}),
"/",
),
"代码",
)
})
})

suite("getRouteLabel", () => {
Expand Down
4 changes: 2 additions & 2 deletions src/vscode/pathOperationTreeProvider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ const METHOD_ORDER: Record<RouteMethod, number> = {

export function getAppLabel(app: AppDefinition): string {
if (app.name !== "app") return app.name
const pathParts = app.filePath.split("/")
const pathParts = Uri.parse(app.filePath).path.split("/")
const fileName = pathParts.pop() ?? ""
const parentDir = pathParts.pop() ?? ""
const grandParentDir = pathParts.pop() ?? ""
Expand Down Expand Up @@ -73,7 +73,7 @@ export function getRouterLabel(
if (label !== "/") return label

if (router.tags.length > 0) return `/${router.tags[0]}`
const parts = router.location.filePath.split("/")
const parts = Uri.parse(router.location.filePath).path.split("/")
const fileName = parts.pop()?.replace(/\.py$/, "") ?? ""
if (fileName === "router" || fileName === "routes")
return parts.pop() ?? fileName
Expand Down
Loading