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

Add pseudoplain tests

parent b26ccc5e
Branches
Tags
1 merge request!6Implement pseudo plain parsing
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
// ])
// );
});
......@@ -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,
};
};
......@@ -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"
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment