diff --git a/__tests__/termsParser.test.ts b/__tests__/termsParser.test.ts new file mode 100644 index 0000000..3cd034a --- /dev/null +++ b/__tests__/termsParser.test.ts @@ -0,0 +1,147 @@ +/** + * Tests for the Terms/Privacy HTML parser used by WelcomeScreen. + * + * Two layers: + * 1. Deterministic unit tests over a fixed fixture — lock the parser's + * behaviour (block segmentation, inline formatting, entity decoding). + * 2. A live guard test that fetches https://minibits.cash/terms and asserts + * structural invariants. This is what catches an *unexpected* change to + * the live Terms markup (e.g. a new element type the parser can't handle, + * which would otherwise leak raw HTML into the app). Requires network. + */ + +import { htmlToBlocks, extractArticle, Block } from '../src/utils/htmlToBlocks' + +const TERMS_URL = 'https://minibits.cash/terms' + +const SAMPLE = `
ignored
+

Terms and Conditions

+

Bitango & friends said "hello" 'again'

+
+

Part 0 — General Terms

+

0.1 About

+

Read the Privacy Policy and the fine print.

+ +
+

IMPORTANT

+

Read carefully.

+
+
` + +const textOf = (block: Block): string => + block.type === 'hr' ? '' : block.segments.map(s => s.text).join('') + +describe('htmlToBlocks (fixture)', () => { + const blocks = htmlToBlocks(SAMPLE) + + test('extractArticle returns only the article inner HTML', () => { + const inner = extractArticle(SAMPLE) + expect(inner).toContain('

Terms and Conditions

') + expect(inner).not.toContain('
') + expect(inner).not.toContain('