import fs from 'fs'; import path from 'path'; import QuotedHTMLTransformer from '../../src/services/quoted-html-transformer'; describe('QuotedHTMLTransformer', function() { const readFile = function(fname) { const emailPath = path.resolve(__dirname, '..', 'fixtures', 'emails', fname); return fs.readFileSync(emailPath, 'utf8'); }; const removeQuotedHTML = function(fname, opts = {}) { return QuotedHTMLTransformer.removeQuotedHTML(readFile(fname), opts); }; for (let n = 1; n <= 28; n++) { it(`properly parses email_${n}`, function() { const opts = { keepIfWholeBodyIsQuote: true }; const actual = removeQuotedHTML(`email_${n}.html`, opts).trim(); const expected = readFile(`email_${n}_stripped.html`).trim(); if (actual !== expected) { fs.writeFileSync( path.resolve(__dirname, '..', 'fixtures', 'emails', `email_${n}_actual.html`), actual ); } expect(actual).toEqual(expected); }); } describe('manual quote detection tests', function() { const clean = str => str.replace(/[\n\r]/g, '').replace(/\s{2,}/g, ' '); // The key is the inHTML. The value is the outHTML const tests = []; // Test 1 tests.push({ before: `\
More text
ParentSubSub SubSub
The last quote!
More text
ParentSubSub SubSub
Nothing but quotes
Nothing but quotes
Nothing but quotes
Inline quoteWorld\ `, after: `\ Hello
Inline quoteWorld\ `, }); // Test 6: No quoted elements at all tests.push({ before: `\ Hello World\ `, after: `\ Hello World\ `, }); // Test 7: Common ancestor is a quoted node tests.push({ before: `\
Some content\ `, after: `\More contentOther content
Some contentMore contentOther content
Some text quoteSome text
A quote
Another quote
More quotes!\ `, after: `\
Some contentMore contentOther content
Some text quoteSome text
I'm inlineContent
Remove me
Foo
Bar
Baz\ `, after: `\
I'm inlineContent
Nothing but quotes
Nothing but quotes
A | B |
C | SAVE ME |
E | F |
A | B |
C | SAVE ME |
E | F |
QUOTED TEXT
QUOTED TEXT
foolololol'; const expect0 = 'hello world'; expect(QuotedHTMLTransformer.removeQuotedHTML(input0)).toEqual(expect0); }); it('preserves
foolololol'; const expect0 = 'hello
On Dec 16 2015, at 7:08 pm, Juan Tejada <juan@mailspring.com> wrote:\ `; const expect0 = ''; expect( QuotedHTMLTransformer.removeQuotedHTML(input0, { keepIfWholeBodyIsQuote: false }) ).toEqual(expect0); }); }); // We have a little utility method that you can manually uncomment to // generate what the current iteration of the QuotedHTMLTransformer things the // `removeQuotedHTML` should look like. These can be manually inspected in // a browser before getting their filename changed to // `email_${n}_stripped.html". The actually tests will run the current // iteration of the `removeQuotedHTML` against these files to catch if // anything has changed in the parser. // // It's inside of the specs here instaed of its own script because the // `QuotedHTMLTransformer` needs Electron booted up in order to work because // of the DOMParser. xit('Run this simple function to generate output files', () => [18, 20].forEach(function(n) { const newHTML = QuotedHTMLTransformer.removeQuotedHTML(readFile(`email_${n}.html`)); const outPath = path.resolve( __dirname, '..', 'fixtures', 'emails', `email_${n}_raw_stripped.html` ); fs.writeFileSync(outPath, newHTML); })); });
h2
he he hehehehehehe
dufjcasc