This commit is contained in:
1 parent
8efd032cc6
commit
df38dccbf1
735 files changed
+128321
-120870
No files matched your search
+30
-28
@@ -2,41 +2,43 @@ import { describe, expect, it } from "vitest";
|
||||
import { avatarImageUrl, excerpt, slugify } from "./format";
|
||||
|
||||
describe("slugify", () => {
|
||||
it("lowercases and hyphenates", () => {
|
||||
expect(slugify("Hello World!")).toBe("hello-world");
|
||||
});
|
||||
it("strips accents via NFKD", () => {
|
||||
expect(slugify("Café del Mar")).toBe("cafe-del-mar");
|
||||
});
|
||||
it("falls back to 'article' for empty input", () => {
|
||||
expect(slugify(" *** ")).toBe("article");
|
||||
});
|
||||
it("lowercases and hyphenates", () => {
|
||||
expect(slugify("Hello World!")).toBe("hello-world");
|
||||
});
|
||||
it("strips accents via NFKD", () => {
|
||||
expect(slugify("Café del Mar")).toBe("cafe-del-mar");
|
||||
});
|
||||
it("falls back to 'article' for empty input", () => {
|
||||
expect(slugify(" *** ")).toBe("article");
|
||||
});
|
||||
});
|
||||
|
||||
describe("avatarImageUrl", () => {
|
||||
const base = "https://www.habbo.com/habbo-imaging/avatarimage";
|
||||
const base = "https://www.habbo.com/habbo-imaging/avatarimage";
|
||||
|
||||
it("appends the figure and options", () => {
|
||||
const url = avatarImageUrl(base, "hr-100", { size: "l", headOnly: true });
|
||||
expect(url).toContain("figure=hr-100");
|
||||
expect(url).toContain("size=l");
|
||||
expect(url).toContain("headonly=1");
|
||||
expect(url.startsWith(`${base}?`)).toBe(true);
|
||||
});
|
||||
it("appends the figure and options", () => {
|
||||
const url = avatarImageUrl(base, "hr-100", { size: "l", headOnly: true });
|
||||
expect(url).toContain("figure=hr-100");
|
||||
expect(url).toContain("size=l");
|
||||
expect(url).toContain("headonly=1");
|
||||
expect(url.startsWith(`${base}?`)).toBe(true);
|
||||
});
|
||||
|
||||
it("uses & when the base already has a query string", () => {
|
||||
expect(avatarImageUrl(`${base}?x=1`, "hr-100").includes("?x=1&figure=hr-100")).toBe(true);
|
||||
});
|
||||
it("uses & when the base already has a query string", () => {
|
||||
expect(
|
||||
avatarImageUrl(`${base}?x=1`, "hr-100").includes("?x=1&figure=hr-100"),
|
||||
).toBe(true);
|
||||
});
|
||||
});
|
||||
|
||||
describe("excerpt", () => {
|
||||
it("returns short text unchanged", () => {
|
||||
expect(excerpt("hello", 160)).toBe("hello");
|
||||
});
|
||||
it("returns short text unchanged", () => {
|
||||
expect(excerpt("hello", 160)).toBe("hello");
|
||||
});
|
||||
|
||||
it("truncates on a word boundary with an ellipsis", () => {
|
||||
const out = excerpt("the quick brown fox jumps", 12);
|
||||
expect(out).toBe("the quick…");
|
||||
expect(out.length).toBeLessThanOrEqual(13);
|
||||
});
|
||||
it("truncates on a word boundary with an ellipsis", () => {
|
||||
const out = excerpt("the quick brown fox jumps", 12);
|
||||
expect(out).toBe("the quick…");
|
||||
expect(out.length).toBeLessThanOrEqual(13);
|
||||
});
|
||||
});
|
||||
Reference in new issue
Block a user