From bfd9fb4bd9ef7797a0a17fd8e3a167a4e257ee8a Mon Sep 17 00:00:00 2001 From: iamsivin Date: Tue, 5 May 2026 12:11:11 +0530 Subject: [PATCH] chore: clean up --- .../helper/specs/emailQuoteExtractor.spec.js | 55 +++++++++---------- 1 file changed, 27 insertions(+), 28 deletions(-) diff --git a/app/javascript/dashboard/helper/specs/emailQuoteExtractor.spec.js b/app/javascript/dashboard/helper/specs/emailQuoteExtractor.spec.js index 09210094e..cdfecfb0a 100644 --- a/app/javascript/dashboard/helper/specs/emailQuoteExtractor.spec.js +++ b/app/javascript/dashboard/helper/specs/emailQuoteExtractor.spec.js @@ -53,33 +53,20 @@ const cleaned = html => { describe('EmailQuoteExtractor', () => { it('removes blockquote-based quotes from the email body', () => { - const cleanedHtml = EmailQuoteExtractor.extractQuotes(SAMPLE_EMAIL_HTML); - - const container = document.createElement('div'); - container.innerHTML = cleanedHtml; - - expect(container.querySelectorAll('blockquote').length).toBe(0); - expect(container.textContent?.trim()).toBe('method'); - expect(container.textContent).not.toContain( - 'On Mon, Sep 29, 2025 at 5:18 PM' - ); + const c = cleaned(SAMPLE_EMAIL_HTML); + expect(c.querySelectorAll('blockquote').length).toBe(0); + expect(c.textContent?.trim()).toBe('method'); + expect(c.textContent).not.toContain('On Mon, Sep 29, 2025 at 5:18 PM'); }); it('keeps blockquote fallback when it is not the last top-level element', () => { - const cleanedHtml = EmailQuoteExtractor.extractQuotes( - EMAIL_WITH_FOLLOW_UP_CONTENT - ); - - const container = document.createElement('div'); - container.innerHTML = cleanedHtml; - - expect(container.querySelector('blockquote')).not.toBeNull(); - expect(container.lastElementChild?.tagName).toBe('P'); + const c = cleaned(EMAIL_WITH_FOLLOW_UP_CONTENT); + expect(c.querySelector('blockquote')).not.toBeNull(); + expect(c.lastElementChild?.tagName).toBe('P'); }); it('detects quote indicators in nested blockquotes', () => { - const result = EmailQuoteExtractor.hasQuotes(SAMPLE_EMAIL_HTML); - expect(result).toBe(true); + expect(EmailQuoteExtractor.hasQuotes(SAMPLE_EMAIL_HTML)).toBe(true); }); it('does not flag blockquotes that are followed by other elements', () => { @@ -89,22 +76,34 @@ describe('EmailQuoteExtractor', () => { }); it('returns false when no quote indicators are present', () => { - const html = '

Plain content

'; - expect(EmailQuoteExtractor.hasQuotes(html)).toBe(false); + expect(EmailQuoteExtractor.hasQuotes('

Plain content

')).toBe(false); }); it('removes trailing blockquotes while preserving trailing signatures', () => { - const cleanedHtml = EmailQuoteExtractor.extractQuotes(EMAIL_WITH_SIGNATURE); - - expect(cleanedHtml).toContain('

Thanks,

'); - expect(cleanedHtml).toContain('

Jane Doe

'); - expect(cleanedHtml).not.toContain(' { expect(EmailQuoteExtractor.hasQuotes(EMAIL_WITH_SIGNATURE)).toBe(true); }); + describe('robustness', () => { + it('handles large email bodies without throwing', () => { + const bigHtml = '

line

'.repeat(5000); + expect(() => EmailQuoteExtractor.extractQuotes(bigHtml)).not.toThrow(); + expect(() => EmailQuoteExtractor.hasQuotes(bigHtml)).not.toThrow(); + }); + + it('does not crash on malformed HTML', () => { + const malformed = '
<><<

weird

EmailQuoteExtractor.extractQuotes(malformed)).not.toThrow(); + expect(() => EmailQuoteExtractor.hasQuotes(malformed)).not.toThrow(); + }); + }); + describe('HTML sanitization', () => { it('removes onerror handlers from img tags in extractQuotes', () => { const maliciousHtml = '

Hello

';