Skip to content
Snippets Groups Projects

Refactor test cases handler

Merged Igor Markin requested to merge refactor-test-cases-handler into master
4 files
+ 142
140
Compare changes
  • Side-by-side
  • Inline
Files
4
import { describe, test, expect } from "@jest/globals";
import { JSDOM } from "jsdom";
import HTMLNormalizer from "../src/HTMLNormalizer";
import { describe } from "@jest/globals";
import { EMAIL_VENDORS } from "../src";
const fs = require("fs");
import { createDescribeHtmlTestCases } from "./utils";
const path = require("path");
// Test cases from https://code.vereign.com/alexey.lunin/outlook-files-upload
const TESTS_GLOBAL_PATH = "/files/outlook-outlook";
const SENT_HTML_NAME = "s_htmlContent.html";
const RECEIVED_HTML_NAME = "r_htmlContent.html";
const testsPath = path.resolve(__dirname, `.${TESTS_GLOBAL_PATH}`);
const getTestCasesDirs = (testCasesPath: string) => {
return fs.readdirSync(testCasesPath).filter(function (file) {
return fs.statSync(testCasesPath + "/" + file).isDirectory();
});
};
const getNormalizedHtml = (
testCasePath: string
): {
sentHtml: string;
receivedHtml: string;
} => {
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);
const sentNormalizedHtml = HTMLNormalizer.normalizeVendorHtml(
sentDOM.window.document,
EMAIL_VENDORS.OUTLOOK
);
const receivedNormalizedHtml = HTMLNormalizer.normalizeVendorHtml(
receivedDOM.window.document,
describe("Outlook emails HTML normalization", () => {
const describeFunction = createDescribeHtmlTestCases(
testsPath,
EMAIL_VENDORS.OUTLOOK
);
return {
sentHtml: sentNormalizedHtml,
receivedHtml: receivedNormalizedHtml,
};
};
describe("Outlook emails HTML normalization", () => {
const describeTestCases = (
casesGroupName: string,
failingCases: Array<string> = []
) => () => {
const testsCasesPath = testsPath + "/" + casesGroupName;
const testCasesDirs = getTestCasesDirs(testsCasesPath).filter(
(dir) => !failingCases.includes(dir)
);
test.each(testCasesDirs)("Case %s", (dirName: string) => {
const testCasePath = testsCasesPath + "/" + dirName;
let normalizedHtmls;
try {
normalizedHtmls = getNormalizedHtml(testCasePath);
} catch (e) {
console.log(`Invalid test case: ${casesGroupName}/${dirName}`);
return;
}
const { sentHtml, receivedHtml } = normalizedHtmls;
expect(receivedHtml.length).toBeGreaterThan(0);
expect(sentHtml.length).toBeGreaterThan(0);
expect(receivedHtml).toContain(sentHtml);
});
};
describe(
"Emails Chrome",
describeTestCases("chrome", [
describeFunction("chrome", [
"20",
"20forward",
"20reply",
@@ -97,7 +32,7 @@ describe("Outlook emails HTML normalization", () => {
describe(
"Emails Edge",
describeTestCases("edge", [
describeFunction("edge", [
"20",
"20forward",
"20reply",
@@ -112,7 +47,7 @@ describe("Outlook emails HTML normalization", () => {
);
describe(
"Emails Safari",
describeTestCases("safari", [
describeFunction("safari", [
"04",
"20",
"20forward",
@@ -130,11 +65,11 @@ describe("Outlook emails HTML normalization", () => {
);
// describe(
// "Emails MacOS",
// describeTestCases("macos", ["20", "21", "22", "23", "24", "25", "26"])
// describeFunction("macos", ["20", "21", "22", "23", "24", "25", "26"])
// );
describe(
"Emails Windows",
describeTestCases("windows", [
describeFunction("windows", [
"06",
"20",
"20forward",
Loading