fix: Email for document update can include empty diff block

This commit is contained in:
Tom Moor
2023-07-07 08:23:42 -04:00
parent 814bacbead
commit 8cc2853102
3 changed files with 34 additions and 6 deletions

View File

@@ -76,12 +76,14 @@ export default class DocumentPublishedOrUpdatedEmail extends BaseEmail<
});
// inline all css so that it works in as many email providers as possible.
body = await inlineCss(content, {
body = content
? await inlineCss(content, {
url: env.URL,
applyStyleTags: true,
applyLinkTags: false,
removeStyleTags: true,
});
})
: undefined;
}
}

View File

@@ -113,6 +113,25 @@ same on both sides`,
expect(html).not.toContain("this is a highlight");
});
it("should return undefined if no diff is renderable", async () => {
const before = new Revision({
title: "Title",
text: `
This is a test paragraph`,
});
const after = new Revision({
title: "Title",
text: `
This is a [test paragraph](https://example.net)`,
});
// Note: This test may fail in the future when support for diffing marks
// is improved.
const html = await DocumentHelper.toEmailDiff(before, after);
expect(html).toBeUndefined();
});
it("should trim table rows to show minimal diff including header", async () => {
const before = new Revision({
title: "Title",

View File

@@ -195,6 +195,13 @@ export default class DocumentHelper {
const containsDiffElement = (node: Element | null) =>
node && node.innerHTML.includes("data-operation-index");
// The diffing lib isn't able to catch all changes currently, e.g. changing
// the type of a mark will result in an empty diff.
// see: https://github.com/tnwinc/htmldiff.js/issues/10
if (!containsDiffElement(doc.querySelector("#content"))) {
return;
}
// We use querySelectorAll to get a static NodeList as we'll be modifying
// it as we iterate, rather than getting content.childNodes.
const contents = doc.querySelectorAll("#content > *");