Skip to content

Commit

Permalink
Test: Test Outlook hack
Browse files Browse the repository at this point in the history
  • Loading branch information
Gum-Joe committed Aug 5, 2024
1 parent 79e2c8b commit 9a66746
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 2 deletions.
5 changes: 3 additions & 2 deletions email/libmailmerge/src/graph/uploadDrafts.ts
Original file line number Diff line number Diff line change
Expand Up @@ -169,15 +169,16 @@ export class EmailUploader {
}
// HACK: Replace </p><p> (adjacent paragraphs) with </p><p><br></p><p>
// to create blank lines in outlook
let htmlToUpload = html;
if (options.enableOutlookParagraphSpacingHack) {
html = html.replace(/<\/p>\s<p>/g, "</p><p><br></p><p>");
htmlToUpload = html.replace(/<\/p>\s*<p>/g, "</p><p><br></p><p>");
}
try {
const draftMessage = {
subject,
body: {
contentType: "HTML",
content: html,
content: htmlToUpload,
},
toRecipients: to.map((email) => ({
emailAddress: {
Expand Down
33 changes: 33 additions & 0 deletions email/libmailmerge/test/graph/uploadDrafts.ts
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,39 @@ describe("EmailUploader", () => {
expect(mockClient.post).toHaveBeenCalled();
});

it("should apply the outlook paragraph hack", async () => {
const mockClient = {
api: jest.fn().mockReturnThis(),
/// @ts-expect-error: Mocking method
post: jest.fn().mockResolvedValue({ id: "messageId" }),
};

/// @ts-expect-error: Mocking property
emailUploader["client"] = mockClient;

await emailUploader.uploadEmail(
["[email protected]"],
"Subject",
"<p>HTML content</p><p>And some more</p> <p>And some more</p>",
[],
{ cc: [], bcc: [] },
{ enableOutlookParagraphSpacingHack: true },
);

expect(mockClient.api).toHaveBeenCalledWith("/me/messages");
expect(mockClient.post).toHaveBeenCalledWith({
subject: "Subject",
toRecipients: [{ emailAddress: { address: "[email protected]" } }],
ccRecipients: [],
bccRecipients: [],
body: {
contentType: "HTML",
content:
"<p>HTML content</p><p><br></p><p>And some more</p><p><br></p><p>And some more</p>",
},
});
});

it("should upload email successfully with attachments", async () => {
const mockClient = {
api: jest.fn().mockReturnThis(),
Expand Down

0 comments on commit 9a66746

Please sign in to comment.