Newer
Older
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
import { describe, test, expect } from "@jest/globals";
import { JSDOM } from "jsdom";
import HTMLNormalizer from "../src/HTMLNormalizer";
import { EMAIL_VENDORS } from "../src/constants";
const fs = require("fs");
const path = require("path");
const util = require("util");
// Test cases from https://code.vereign.com/alexey.lunin/outlook-files-upload
const TESTS_GLOBAL_PATH = "/outlook-files-upload/uploads";
const SENT_HTML_NAME = "s_initialHtmlContent.data";
const RECEIVED_HTML_NAME = "r_htmlContent.data";
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,
EMAIL_VENDORS.OUTLOOK
);
return {
sentHtml: sentNormalizedHtml,
receivedHtml: receivedNormalizedHtml,
};
};
describe("Outlook emails HTML normalization", () => {
const describeTestCases = (casesName: string) => () => {
const testsCasesPath = testsPath + "/" + casesName;
const testCasesDirs = getTestCasesDirs(testsCasesPath);
test.each(testCasesDirs)("Case %s", (dirName: string) => {
const testCasePath = testsCasesPath + "/" + dirName;
let normalizedHtmls;
try {
normalizedHtmls = getNormalizedHtml(testCasePath);
} catch (e) {
console.log("Invalid test case: " + 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"));
describe("Emails Edge", describeTestCases("edge"));
//describe("Emails Gmail", describeTestCases("gmail"));
// it("Emails Edge", () => {
// })
//
// it("Emails Gmail", () => {
// })
//
// it("Emails MacOS", () => {
// })
//
// it("Emails Safari", () => {
// })
//
// it("Emails Windows", () => {
// })
});