Refractoring Stage 2 Add Refractor plan.md
This commit is contained in:
@@ -0,0 +1,37 @@
|
||||
const test = require('node:test');
|
||||
const assert = require('node:assert/strict');
|
||||
const { extractMailContent } = require('../desktop/mail-content.cjs');
|
||||
|
||||
test('extracts bounded display content, links, and non-PGP attachment metadata', () => {
|
||||
const result = extractMailContent({
|
||||
text: 'First paragraph\r\n\r\nSecond paragraph',
|
||||
html: '<a href="https://example.com/a?x=1&y=2">one</a><a href="/next">two</a>',
|
||||
attachments: [
|
||||
{ filename: 'signature.asc', contentType: 'application/pgp-signature', size: 20 },
|
||||
{ filename: 'report.pdf', contentType: 'application/pdf', size: 1048576 }
|
||||
]
|
||||
});
|
||||
|
||||
assert.equal(result.bodyText, 'First paragraph\n\nSecond paragraph');
|
||||
assert.deepEqual(result.body, ['First paragraph', 'Second paragraph']);
|
||||
assert.deepEqual(result.links, ['https://example.com/a?x=1&y=2', '/next']);
|
||||
assert.deepEqual(result.attachments, [{ filename: 'report.pdf', size: 1048576 }]);
|
||||
assert.equal(result.attachment, 'report.pdf');
|
||||
assert.equal(result.size, '1.0 MB');
|
||||
});
|
||||
|
||||
test('bounds text, HTML, and links and supplies an empty-body fallback', () => {
|
||||
const result = extractMailContent({
|
||||
text: `${'x'.repeat(20001)}\n\n${Array.from({ length: 45 }, (_, index) => `p${index}`).join('\n\n')}`,
|
||||
html: `${'<a href="https://example.com">link</a>'.repeat(31)}${'h'.repeat(100001)}`
|
||||
});
|
||||
|
||||
assert.equal(result.bodyText.length, 20000);
|
||||
assert.equal(result.body.length, 1);
|
||||
assert.equal(result.html.length, 100000);
|
||||
assert.equal(result.links.length, 30);
|
||||
|
||||
const empty = extractMailContent({});
|
||||
assert.deepEqual(empty.body, ['This message has no plain-text body.']);
|
||||
assert.deepEqual(empty.attachments, []);
|
||||
});
|
||||
Reference in New Issue
Block a user