feat: blob images
This commit is contained in:
85
publish.test.ts
Normal file
85
publish.test.ts
Normal file
@@ -0,0 +1,85 @@
|
||||
import { test, expect, describe } from "bun:test";
|
||||
import { stripUnpublishedLinks, extractLocalImages } from "./publish";
|
||||
|
||||
describe("stripUnpublishedLinks", () => {
|
||||
const isUnpublished = (href: string) =>
|
||||
!href.startsWith("http://") && !href.startsWith("https://");
|
||||
|
||||
test("strips links to unpublished notes", () => {
|
||||
const md = "Check out [my draft](draft-note) for details.";
|
||||
expect(stripUnpublishedLinks(md, isUnpublished)).toBe(
|
||||
"Check out my draft for details.",
|
||||
);
|
||||
});
|
||||
|
||||
test("keeps links to published URLs", () => {
|
||||
const md = "Visit [Google](https://google.com) today.";
|
||||
expect(stripUnpublishedLinks(md, isUnpublished)).toBe(md);
|
||||
});
|
||||
|
||||
test("strips multiple unpublished links", () => {
|
||||
const md = "See [note A](note-a) and [note B](note-b).";
|
||||
expect(stripUnpublishedLinks(md, isUnpublished)).toBe(
|
||||
"See note A and note B.",
|
||||
);
|
||||
});
|
||||
|
||||
test("handles mixed links", () => {
|
||||
const md =
|
||||
"Read [docs](https://docs.example.com) and [my note](local-note).";
|
||||
expect(stripUnpublishedLinks(md, isUnpublished)).toBe(
|
||||
"Read [docs](https://docs.example.com) and my note.",
|
||||
);
|
||||
});
|
||||
|
||||
test("does not strip image references", () => {
|
||||
const md = "";
|
||||
expect(stripUnpublishedLinks(md, isUnpublished)).toBe(md);
|
||||
});
|
||||
|
||||
test("handles empty link text", () => {
|
||||
const md = "[](unpublished-ref)";
|
||||
expect(stripUnpublishedLinks(md, isUnpublished)).toBe("");
|
||||
});
|
||||
});
|
||||
|
||||
describe("extractLocalImages", () => {
|
||||
test("extracts local image paths", () => {
|
||||
const md = "";
|
||||
const result = extractLocalImages(md);
|
||||
expect(result).toEqual([
|
||||
{ full: "", alt: "photo", path: "./images/photo.png" },
|
||||
]);
|
||||
});
|
||||
|
||||
test("skips URL images", () => {
|
||||
const md = "";
|
||||
expect(extractLocalImages(md)).toEqual([]);
|
||||
});
|
||||
|
||||
test("extracts multiple local images", () => {
|
||||
const md = `
|
||||

|
||||
Some text
|
||||

|
||||

|
||||
`;
|
||||
const result = extractLocalImages(md);
|
||||
expect(result).toHaveLength(2);
|
||||
expect(result[0].path).toBe("./a.png");
|
||||
expect(result[1].path).toBe("../assets/b.jpg");
|
||||
});
|
||||
|
||||
test("handles images with empty alt", () => {
|
||||
const md = "";
|
||||
const result = extractLocalImages(md);
|
||||
expect(result).toEqual([
|
||||
{ full: "", alt: "", path: "./no-alt.png" },
|
||||
]);
|
||||
});
|
||||
|
||||
test("handles http:// URLs (case insensitive)", () => {
|
||||
const md = "";
|
||||
expect(extractLocalImages(md)).toEqual([]);
|
||||
});
|
||||
});
|
||||
Reference in New Issue
Block a user