diff --git a/__tests__/pseudoplain-outlook-outlook.test.ts b/__tests__/pseudoplain-outlook-outlook.test.ts new file mode 100644 index 0000000000000000000000000000000000000000..7f512ba3d5c92f4313b8a68eade451d562ad268a --- /dev/null +++ b/__tests__/pseudoplain-outlook-outlook.test.ts @@ -0,0 +1,97 @@ +import { diffStringsUnified } from "jest-diff"; +import { describe, test } from "@jest/globals"; +import { getDOMDocuments, getTestCasesDirs } from "./utils"; +const path = require("path"); + +const TESTS_GLOBAL_PATH = "/files/outlook-outlook"; +const testsPath = path.resolve(__dirname, `.${TESTS_GLOBAL_PATH}`); + +const createDescribePseudoPlainTestCases = (testsPath: string) => + /** + * @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, + failingCases?: Array<string>, + casesToCheckOnly?: Array<string> + ) => (): void => { + const testsCasesPath = testsPath + "/" + casesGroupName; + let testCasesDirs = getTestCasesDirs(testsCasesPath); + + if (casesToCheckOnly && casesToCheckOnly.length) { + testCasesDirs = testCasesDirs.filter((dir) => + casesToCheckOnly.includes(dir) + ); + } + + if (failingCases && failingCases.length) { + testCasesDirs = testCasesDirs.filter( + (dir) => !failingCases.includes(dir) + ); + } + + test.each(testCasesDirs)("Case %s", (dirName: string) => { + const testCasePath = testsCasesPath + "/" + dirName; + const { sentHtmlDocument, receivedHtmlDocument } = getDOMDocuments( + testCasePath + ); + + const difference = diffStringsUnified( + receivedHtmlDocument.body.textContent, + sentHtmlDocument.body.textContent + ); + + console.log(difference); + }); + }; + +describe("[Pseudo PLAIN] Outlook-Outlook normalization", () => { + const describeFunction = createDescribePseudoPlainTestCases(testsPath); + + // ["01"] - is a filter. Pass here names of directories with test cases you want to check + describe("Emails Chrome", describeFunction("chrome", null, ["01"])); + + // describe( + // "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, + // "08", + // ]) + // ); + + // Does not work at all + // describe( + // "Emails MacOS", + // describeFunction("macos", ["20", "21", "", "23", "24", "25", "26"]) + // ); + + // describe( + // "Emails Windows", + // describeFunction("windows", [ + // "06", + // "20", + // "20forward", + // "20reply", + // "21", + // "21forward", + // "21reply", + // "22", + // "23", + // "24", + // "25", + // "26", + // "28", + // "10", // missing files + // ]) + // ); +}); diff --git a/__tests__/utils.ts b/__tests__/utils.ts index 7a0e7b901caccb3cd579f1746b92f0f20c267119..33f9d3d4b465de8dadb07885df2d5f245d4fa238 100644 --- a/__tests__/utils.ts +++ b/__tests__/utils.ts @@ -129,3 +129,25 @@ export const createDescribePlainTestCases = (testsPath: string) => ( expect(receivedPlain).toContain(sentPlain); }); }; + +export const getDOMDocuments = ( + testCasePath: string +): { + sentHtmlDocument: HTMLDocument; + receivedHtmlDocument: HTMLDocument; +} => { + const sentHtml = fs + .readFileSync(`${testCasePath}/${SENT_HTML_NAME}`) + .toString(); + const receivedHtml = fs + .readFileSync(`${testCasePath}/${RECEIVED_HTML_NAME}`) + .toString(); + + const sentDOM = new JSDOM(sentHtml); + const receivedDOM = new JSDOM(receivedHtml); + + return { + sentHtmlDocument: sentDOM.window.document, + receivedHtmlDocument: receivedDOM.window.document, + }; +}; diff --git a/package.json b/package.json index 5805b72051fb21f31a605de843d07ed8acdae5ff..6831c4de178f66f35857b2f50a15608b6c282ad5 100644 --- a/package.json +++ b/package.json @@ -18,6 +18,7 @@ "eslint": "^7.7.0", "husky": "^4.2.5", "jest": "^26.4.2", + "jest-diff": "^26.6.2", "lint-staged": "^10.2.13", "prettier": "^2.1.1", "typescript": "^4.0.2"