// The Hub's email layout (2.10.0): HTML and plain text from the same blocks, everything escaped. const { render, logoAttachment } = require('../src/utils/emailLayout'); const { notesBlocks } = require('../src/utils/jobs'); describe('render', () => { test('makes the HTML and its plain-text twin from the same blocks', () => { const { html, text } = render({ heading: 'Installed', sub: 'Now set it up', blocks: [ { hello: 'Jane' }, { p: 'See https://hub.test/jobs/1 for more.' }, { note: { kind: 'warning', title: 'Careful', text: 'Two lines\nhere' } }, { rows: [['Site', 'events.hope.co.za'], ['Empty', null]] }, { steps: [{ outcome: 'ok', name: 'Backup' }, { outcome: 'failed', name: 'Migrate', detail: 'P3009' }] }, { numbered: [{ text: 'Add the site.' }, { text: 'Add this:', code: 'location ^~ /api/ {\n}' }] }, { code: 'line 1\nline 2', label: 'Last log lines' }, { button: { label: 'Open the job', url: 'https://hub.test/jobs/1' } }, null, ], }); expect(text).toBe([ 'Installed', 'Now set it up', 'Hi Jane,', 'See https://hub.test/jobs/1 for more.', 'Careful\nTwo lines\nhere', 'Site: events.hope.co.za', ' ✓ Backup\n ✗ Migrate (P3009)', '1. Add the site.\n\n2. Add this:\n\n location ^~ /api/ {\n }', 'Last log lines:\nline 1\nline 2', 'Open the job: https://hub.test/jobs/1', ].join('\n\n')); expect(html).toContain('https://hub.test/jobs/1 for more.'); expect(html).toContain('Two lines
here'); expect(html).not.toContain('Empty'); expect(html).toContain('location ^~ /api/ {'); expect(html).toContain('>Open the job'); }); test('escapes everything and only links http(s)', () => { const { html } = render({ heading: '', blocks: [{ p: 'Tom & "Jerry" ' }, { button: { label: 'Go', url: 'javascript:alert(1)' } }, { code: '' }], }); expect(html).not.toContain('