Skip to content

Commit

Permalink
[#IOCOM-538] Add "..." at the end of the message content when it's tr…
Browse files Browse the repository at this point in the history
…uncated (#280)
  • Loading branch information
Garma00 authored Sep 18, 2023
1 parent c9e98d6 commit aa9677b
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -388,7 +388,7 @@ Object {
</tr>
<tr>
<td align=\\"left\\" class=\\"text\\" style=\\"font-size:0px;padding:0px;word-break:break-word;\\">
<div style=\\"font-family:Titillium Web, system-ui, sans-serif;font-size:16px;font-weight:regular;line-height:24px;text-align:left;color:#17324D;\\"><p>testtesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttestte</p></div>
<div style=\\"font-family:Titillium Web, system-ui, sans-serif;font-size:16px;font-weight:regular;line-height:24px;text-align:left;color:#17324D;\\"><p>testtesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttestte...</p></div>
</td>
</tr>
</tbody>
Expand Down
3 changes: 2 additions & 1 deletion EmailNotification/__tests__/handler.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -225,7 +225,8 @@ describe("prepareBody", () => {
const markdown =
"# Header 1\nsome text\n## Header 2\nsome text\n### Header 3\nsome text\n#### Header 4\nsome text\n##### Header 5\nsome text\ntestesttesttesttestesttesttesttestesttesttesttestesttesttesttestesttesttesttestesttesttest";
const r = prepareBody(markdown);
expect(r).toHaveLength(134);
//this should be 134 + 3 cause "..." is added at the end
expect(r).toHaveLength(137);
expect(r).not.toContain("#");
});
});
17 changes: 16 additions & 1 deletion EmailNotification/__tests__/utils.test.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
import { contentToHtml, messageReducedToHtml } from "../utils";
import {
contentToHtml,
messageReducedToHtml,
truncateMarkdown
} from "../utils";
import * as E from "fp-ts/Either";
import {
aCreatedMessageEventSenderMetadata,
Expand Down Expand Up @@ -52,3 +56,14 @@ describe("messageReducedToHtml", () => {
expect(result).toEqual(E.left(anError));
});
});

describe("truncateMarkdown", () => {
test("should add '...' at the end of the string if the plain text length is > 134", () => {
expect(truncateMarkdown(aMessageContent.markdown).slice(-3)).toBe("...");
});
test("should not add '...' at the end of the string if the plain text length is <= 134", () => {
expect(truncateMarkdown("This message is < than 134 chars")).not.toContain(
"..."
);
});
});
5 changes: 4 additions & 1 deletion EmailNotification/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,10 @@ type MessageReducedToHtmlInput = {
};

export const truncateMarkdown = (plainText: string): string =>
plainText.substring(0, MAX_CHARACTER_FOR_BODY_MAIL);
// we add "..." only when the message is going to be truncate
plainText.length > MAX_CHARACTER_FOR_BODY_MAIL
? plainText.substring(0, MAX_CHARACTER_FOR_BODY_MAIL) + "..."
: plainText.substring(0, MAX_CHARACTER_FOR_BODY_MAIL);

export const prepareBody = (markdown: string): string =>
// eslint-disable-next-line functional/immutable-data
Expand Down

0 comments on commit aa9677b

Please sign in to comment.