You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 

30 lines
1.2 KiB

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("上海");
});
});