import { describe, it, expect } from 'vitest' import { findOverflowRisks } from '../extract.js' // Invariant under test: every `` and every `font-mono` value in a `user` // doc page carries a break utility (`break-all` / `break-words` / `overflow-wrap`). // Without it a long unbreakable token (URL, permission key, namespace) fixes a // wide min-content on its grid/flex cell and overflows the card — the exact // PERMISSION / URL regression the gate now blocks. describe('extract-doc / findOverflowRisks — overflow-prone technical tokens', () => { it('flags a value with no break utility (the URL / permission card case)', () => { const tsx = `
{t('access.permission')}
` const hits = findOverflowRisks(tsx, 'src/pages/docs/business/platform/administration/themes/index.tsx') expect(hits).toHaveLength(1) expect(hits[0].token).toBe('code-no-break') expect(hits[0].line).toBe(2) // 1-based, points at the offending element }) it('flags a font-mono table cell with no break utility (API endpoints table)', () => { const tsx = `{ep.permission}` const hits = findOverflowRisks(tsx, 'themes/index.tsx') expect(hits.map((h) => h.token)).toEqual(['mono-no-break']) }) it('does NOT flag a that already carries break-all', () => { const tsx = `{t('access.url')}` expect(findOverflowRisks(tsx, 'themes/index.tsx')).toEqual([]) }) it('does NOT flag a font-mono cell that carries break-all', () => { const tsx = `{ep.path}` expect(findOverflowRisks(tsx, 'themes/index.tsx')).toEqual([]) }) it('accepts break-words / overflow-wrap as valid break utilities', () => { const tsx = `{t('a')} {t('b')}` expect(findOverflowRisks(tsx, 'themes/index.tsx')).toEqual([]) }) it('does NOT flag a non-mono badge span (HTTP method badge)', () => { const tsx = `{ep.method}` expect(findOverflowRisks(tsx, 'themes/index.tsx')).toEqual([]) }) it('does NOT flag a plain annotated Mock UI line', () => { const tsx = `

{t('objective')}

` expect(findOverflowRisks(tsx, 'themes/index.tsx')).toEqual([]) }) it('reports a single finding for (code precedence, not double)', () => { const tsx = `{t('access.url')}` const hits = findOverflowRisks(tsx, 'themes/index.tsx') expect(hits).toHaveLength(1) expect(hits[0].token).toBe('code-no-break') }) it('does not scan i18n JSON (only the page TSX carries layout)', () => { const json = `{ "access": { "url": "/administration/uiconfiguration/themes" } }` expect(findOverflowRisks(json, 'src/i18n/locales/fr/docs-administration-themes.json')).toEqual([]) }) it('returns nothing for a fully compliant access section', () => { const tsx = `
{t('access.url')}
{t('access.permission')}
` expect(findOverflowRisks(tsx, 'themes/index.tsx')).toEqual([]) }) })