import HTMLHelper from "./HTMLHelper";
describe("HTMLHelper", () => {
const document = `
Big Text
`;
describe("inlineCSS", () => {
it("should inline CSS from style tags", async () => {
const result = await HTMLHelper.inlineCSS(document);
expect(result).toBe(`
Big Text
`);
});
it("should initialize once", async () => {
const first = await HTMLHelper.inlineCSS(document);
const second = await HTMLHelper.inlineCSS(document);
expect(first).toBe(second);
});
});
describe("inlineImage", () => {
const redirectUrl = "/api/attachments.redirect?id=123";
const buffer = Buffer.from("small image");
it("should inline a small single-referenced image as a data URI", () => {
const html = `
`;
const result = HTMLHelper.inlineImage(
html,
redirectUrl,
"image/png",
buffer
);
expect(result).toBe(
`
`
);
});
it("should not inline non-image attachments", () => {
const html = `file`;
const result = HTMLHelper.inlineImage(
html,
redirectUrl,
"application/pdf",
buffer
);
expect(result).toBeNull();
});
it("should not inline images larger than the maximum size", () => {
const html = `
`;
const large = Buffer.alloc(HTMLHelper.maxInlineImageSize + 1);
const result = HTMLHelper.inlineImage(
html,
redirectUrl,
"image/png",
large
);
expect(result).toBeNull();
});
it("should not inline images referenced more than once", () => {
const html = `

`;
const result = HTMLHelper.inlineImage(
html,
redirectUrl,
"image/png",
buffer
);
expect(result).toBeNull();
});
it("should not inline an empty buffer", () => {
const html = `
`;
const result = HTMLHelper.inlineImage(
html,
redirectUrl,
"image/png",
Buffer.from("")
);
expect(result).toBeNull();
});
});
});