3 changed files with 54 additions and 0 deletions
@ -0,0 +1,2 @@ |
|||||
|
/** 发现页用户列表每页条数(与公开列表一致) */ |
||||
|
export const DISCOVER_LIST_PAGE_SIZE = 10; |
||||
@ -0,0 +1,30 @@ |
|||||
|
import { describe, expect, test } from "bun:test"; |
||||
|
import { discoverCardAvatarUrl, discoverCardLocationLine } from "./discover-card"; |
||||
|
|
||||
|
describe("discoverCardAvatarUrl", () => { |
||||
|
test("returns null when visibility is not public", () => { |
||||
|
expect(discoverCardAvatarUrl("https://x/a.png", "private")).toBeNull(); |
||||
|
expect(discoverCardAvatarUrl("https://x/a.png", "unlisted")).toBeNull(); |
||||
|
}); |
||||
|
|
||||
|
test("returns null when avatar empty", () => { |
||||
|
expect(discoverCardAvatarUrl(null, "public")).toBeNull(); |
||||
|
expect(discoverCardAvatarUrl(" ", "public")).toBeNull(); |
||||
|
}); |
||||
|
|
||||
|
test("returns trimmed url when public", () => { |
||||
|
expect(discoverCardAvatarUrl(" https://x/a.png ", "public")).toBe("https://x/a.png"); |
||||
|
}); |
||||
|
}); |
||||
|
|
||||
|
describe("discoverCardLocationLine", () => { |
||||
|
test("returns null when show flag false or text empty", () => { |
||||
|
expect(discoverCardLocationLine(true, false, "北京")).toBeNull(); |
||||
|
expect(discoverCardLocationLine(true, true, "")).toBeNull(); |
||||
|
expect(discoverCardLocationLine(true, true, " ")).toBeNull(); |
||||
|
}); |
||||
|
|
||||
|
test("returns trimmed text when allowed", () => { |
||||
|
expect(discoverCardLocationLine(true, true, " 上海 ")).toBe("上海"); |
||||
|
}); |
||||
|
}); |
||||
@ -0,0 +1,22 @@ |
|||||
|
export function discoverCardAvatarUrl( |
||||
|
avatar: string | null | undefined, |
||||
|
avatarVisibility: string, |
||||
|
): string | null { |
||||
|
if (avatarVisibility !== "public") { |
||||
|
return null; |
||||
|
} |
||||
|
const t = typeof avatar === "string" ? avatar.trim() : ""; |
||||
|
return t.length > 0 ? t : null; |
||||
|
} |
||||
|
|
||||
|
export function discoverCardLocationLine( |
||||
|
discoverVisible: boolean, |
||||
|
discoverShowLocation: boolean, |
||||
|
discoverLocation: string | null | undefined, |
||||
|
): string | null { |
||||
|
if (!discoverVisible || !discoverShowLocation) { |
||||
|
return null; |
||||
|
} |
||||
|
const t = typeof discoverLocation === "string" ? discoverLocation.trim() : ""; |
||||
|
return t.length > 0 ? t : null; |
||||
|
} |
||||
Loading…
Reference in new issue