Skip to content
Snippets Groups Projects
Commit 1c805c09 authored by Igor Markin's avatar Igor Markin
Browse files

Cover "chrome" cases

parent c83c8c12
No related branches found
No related tags found
1 merge request!1Initial
......@@ -78,6 +78,8 @@ describe("Outlook emails HTML normalization", () => {
test("Emails Chrome", async () => {
const normalizedCases = await getNormalizedTestCases("chrome");
normalizedCases.forEach(([sent, received]) => {
expect(received.length).toBeGreaterThan(0);
expect(sent.length).toBeGreaterThan(0);
expect(received).toContain(sent);
});
});
......
......@@ -31,10 +31,20 @@ export const pruneElement = (element: HTMLElement): boolean => {
return true;
}
if (
element.nodeName.toLowerCase() === "div" &&
element.childNodes.length === 0
) {
return true;
}
return !!ELEMENT_TYPES_TO_REMOVE[element.nodeName.toLowerCase()];
};
export const cloneAnchorFromPane = (a: HTMLAnchorElement, pane: HTMLElement): void => {
export const cloneAnchorFromPane = (
a: HTMLAnchorElement,
pane: HTMLElement
): void => {
try {
const url = new URL(a.href);
// If this is external url
......
// TODO: Move this logic to amendOutlookNodes
import {printHtmlChildren} from "../HTMLNormalizer";
import {ELEMENT_NODE} from "../../constants";
import {ATTRIBUTES_TO_KEEP, cloneAnchorFromPane, pruneElement} from "./common";
import { printHtmlChildren } from "../HTMLNormalizer";
import { ELEMENT_NODE } from "../../constants";
import {
ATTRIBUTES_TO_KEEP,
cloneAnchorFromPane,
pruneElement,
} from "./common";
export const printOutlookElement = (node: Node): string => {
if (node.nodeType === ELEMENT_NODE) {
......@@ -25,6 +29,21 @@ export const pruneOutlookElement = (element: HTMLElement): boolean => {
};
export const amendOutlookNodes = (document: HTMLDocument): void => {
/**
* Remove quoted text
*/
const appendOnSendNode = document.querySelector(
"[id*='appendonsend']"
) as Node;
if (appendOnSendNode) {
let child = appendOnSendNode;
while (child) {
const nextSibling = child.nextSibling;
child.parentNode.removeChild(child);
child = nextSibling as Node;
}
}
/**
* Get rid of attachments panes
*/
......@@ -45,9 +64,9 @@ export const amendOutlookNodes = (document: HTMLDocument): void => {
}
attachmentsPanesContainerEnd &&
attachmentsPanesContainerEnd.parentNode.removeChild(
attachmentsPanesContainerEnd
);
attachmentsPanesContainerEnd.parentNode.removeChild(
attachmentsPanesContainerEnd
);
/**
* Unwind spans, because sometimes Outlook wraps everything into span after sending
......@@ -55,9 +74,7 @@ export const amendOutlookNodes = (document: HTMLDocument): void => {
const spans = document.getElementsByTagName("span");
/**
* Sort spans by depth to start unwinding the deepest ones, which does not contain nested spans
*/
//Sort spans by depth to start unwinding the deepest ones, which does not contain nested spans
const spansDepths: { depth?: Array<Node> } = {};
Array.from(spans).forEach((span: Node) => {
let descendant = span;
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment