Something went wrong. Try again.
Something went wrong. Try again.
12345678910111213141516171819202122232425262728293031323334353637383940414243import { describe, it, expect } from 'vitest';import { collapsePlainTextQuotes, buildQuoteCollapseScript, QUOTE_TOGGLE_ATTR } from '../quote-collapse';
const labels = { show: 'Show quoted text', hide: 'Hide quoted text' };
describe('collapsePlainTextQuotes', () => { it('wraps the trailing quote run in <details>', () => { const html = 'Thanks!\n\nOn Monday, Bob wrote:\n> original line 1\n>\n> original line 2'; const out = collapsePlainTextQuotes(html, labels); expect(out).toContain('<details><summary title="Show quoted text"'); expect(out).toContain('> original line 1\n>\n> original line 2</details>'); expect(out.startsWith('Thanks!\n\nOn Monday, Bob wrote:\n')).toBe(true); });
it('keeps a trailing signature block visible', () => { const html = 'Hi\n> quoted\n\n-- \nBob'; const out = collapsePlainTextQuotes(html, labels); expect(out).toContain('</details>\n\n-- \nBob'); });
it('is a no-op for interleaved replies and quote-only bodies', () => { expect(collapsePlainTextQuotes('> a\nreply below', labels)).toBe('> a\nreply below'); expect(collapsePlainTextQuotes('> only quote', labels)).toBe('> only quote'); expect(collapsePlainTextQuotes('no quotes here', labels)).toBe('no quotes here'); });
it('escapes the label', () => { const out = collapsePlainTextQuotes('a\n> b', { show: 'x"<y', hide: 'h' }); expect(out).toContain('title="x"<y"'); });});
describe('buildQuoteCollapseScript', () => { it('embeds the selectors and labels as JSON', () => { const script = buildQuoteCollapseScript(labels); expect(script).toContain('"div.gmail_quote"'); expect(script).toContain('"#divRplyFwdMsg"'); expect(script).toContain(`"${QUOTE_TOGGLE_ATTR}"`); expect(script).toContain('"Show quoted text"'); expect(script).toContain('"Hide quoted text"'); });});