From 7d4f8bcf18d4894476e850794b39a3bec2e8d44a Mon Sep 17 00:00:00 2001 From: igor <igor.markin@vereign.com> Date: Wed, 2 Dec 2020 18:55:18 +0300 Subject: [PATCH] Fixes --- __tests__/html-gmail-outlook.test.ts | 3 +++ __tests__/html-outlook-outlook.test.ts | 6 +++++- __tests__/utils.ts | 11 +++++++---- src/HTMLNormalizer/HTMLNormalizer.ts | 2 +- src/HTMLNormalizer/strategies/common.ts | 7 ------- src/HTMLNormalizer/strategies/outlook.ts | 2 +- 6 files changed, 17 insertions(+), 14 deletions(-) diff --git a/__tests__/html-gmail-outlook.test.ts b/__tests__/html-gmail-outlook.test.ts index a17b718..f2b34d5 100644 --- a/__tests__/html-gmail-outlook.test.ts +++ b/__tests__/html-gmail-outlook.test.ts @@ -49,6 +49,9 @@ describe("[HTML] GMail-Outlook", () => { "25reply", "26reply", "27reply", + "21forward", // missing files + "23forward", // missing files + "24forward", // missing files ]) ); }); diff --git a/__tests__/html-outlook-outlook.test.ts b/__tests__/html-outlook-outlook.test.ts index 1acaa4a..7cc5eda 100644 --- a/__tests__/html-outlook-outlook.test.ts +++ b/__tests__/html-outlook-outlook.test.ts @@ -17,12 +17,15 @@ describe("Outlook emails HTML normalization", () => { "Emails Edge", describeFunction("edge", [ "21", // This case has a src mismatch for the same image. Reproduce this case again + "08", // Files are missing for test case + "10", // Files are missing for test case ]) ); describe( "Emails Safari", describeFunction("safari", [ - "04", // This case contains <section> tag which is ignored by Outlook, and it also inserts a plenty of empty divs + "04", // This case contains <section> tag which is ignored by Outlook, and it also inserts a plenty of empty divs, + "08", ]) ); @@ -48,6 +51,7 @@ describe("Outlook emails HTML normalization", () => { "25", "26", "28", + "10", // missing files ]) ); }); diff --git a/__tests__/utils.ts b/__tests__/utils.ts index a4e76a0..696873f 100644 --- a/__tests__/utils.ts +++ b/__tests__/utils.ts @@ -1,5 +1,4 @@ import { JSDOM } from "jsdom"; -import { DOM } from "@vereign/dom"; const fs = require("fs"); const SENT_HTML_NAME = "s_htmlContent.html"; @@ -8,6 +7,7 @@ const SENT_PLAIN_NAME = "s_plainContent.data"; const RECEIVED_PLAIN_NAME = "r_plainContent.data"; import { PlainNormalizer, HTMLNormalizer } from "../src"; import { expect, test } from "@jest/globals"; +import { DOM } from "@vereign/dom"; export const getNormalizedPlain = ( testCasePath: string @@ -76,6 +76,7 @@ export const createDescribeHtmlTestCases = ( /** * @param casesGroupName - name of the folder with cases * @param failingCases - a list of cases that are failing and ignored. Pending to be fixed + * @param casesToCheckOnly - a filter to use if you want to check specific cases */ ( casesGroupName: string, @@ -85,14 +86,16 @@ export const createDescribeHtmlTestCases = ( const testsCasesPath = testsPath + "/" + casesGroupName; let testCasesDirs = getTestCasesDirs(testsCasesPath); - if (casesToCheckOnly) { + if (casesToCheckOnly && casesToCheckOnly.length) { testCasesDirs = testCasesDirs.filter((dir) => casesToCheckOnly.includes(dir) ); } - if (failingCases) { - testCasesDirs.filter((dir) => !failingCases.includes(dir)); + if (failingCases && failingCases.length) { + testCasesDirs = testCasesDirs.filter( + (dir) => !failingCases.includes(dir) + ); } test.each(testCasesDirs)("Case %s", (dirName: string) => { diff --git a/src/HTMLNormalizer/HTMLNormalizer.ts b/src/HTMLNormalizer/HTMLNormalizer.ts index 291336c..3eb2bc8 100644 --- a/src/HTMLNormalizer/HTMLNormalizer.ts +++ b/src/HTMLNormalizer/HTMLNormalizer.ts @@ -183,7 +183,7 @@ export const pruneHtmlNode = ( case DOCUMENT_TYPE_NODE: toBeRemoved = true; break; - case node.TEXT_NODE: { + case TEXT_NODE: { const trimmedText = node.textContent.trim(); if (trimmedText === "") { toBeRemoved = true; diff --git a/src/HTMLNormalizer/strategies/common.ts b/src/HTMLNormalizer/strategies/common.ts index d07e8dc..bc2b330 100644 --- a/src/HTMLNormalizer/strategies/common.ts +++ b/src/HTMLNormalizer/strategies/common.ts @@ -36,13 +36,6 @@ 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()]; }; diff --git a/src/HTMLNormalizer/strategies/outlook.ts b/src/HTMLNormalizer/strategies/outlook.ts index ab31b1a..2f47a2b 100644 --- a/src/HTMLNormalizer/strategies/outlook.ts +++ b/src/HTMLNormalizer/strategies/outlook.ts @@ -36,7 +36,7 @@ const removeQrCodeNodes = (document: HTMLDocument) => { let child = node.firstChild; while (child) { - if (child.nodeType == child.ELEMENT_NODE) { + if (child.nodeType == ELEMENT_NODE) { toRemove = [...toRemove, ...remove(child as Element)]; const childElement = child as Element; -- GitLab