import { describe, it, expect } from 'vitest'
import { findForbidden } from '../extract.js'
describe('extract-doc / findForbidden — i18n JSON', () => {
it('flags benefits / beforeAfter section-label keys', () => {
const json = `{
"sections": {
"objective": "Objectif",
"benefits": "Benefices concrets",
"beforeAfter": "Avant / Apres",
"faq": "Questions frequentes"
}
}`
const hits = findForbidden(json, 'src/i18n/locales/fr/docs-support-sla.json')
expect(hits.map((h) => h.token).sort()).toEqual(['beforeAfter', 'benefits'])
// line numbers are 1-based and point at the offending key
expect(hits.every((h) => h.line > 0)).toBe(true)
})
it('flags overview.problem / overview.solution keys', () => {
const json = `{
"overview": {
"objective": "Gestion des SLA",
"problem": "Les engagements ne sont pas suivis",
"solution": "Monitoring automatique"
}
}`
const hits = findForbidden(json, 'fr/docs-support-sla.json')
expect(hits.map((h) => h.token).sort()).toEqual(['problem', 'solution'])
})
it('does NOT flag a FAQ answer that merely contains the word "solution"', () => {
const json = `{
"faq": {
"1": {
"question": "Quel est le probleme resolu ?",
"answer": "La solution couvre le suivi automatique des SLA."
}
}
}`
expect(findForbidden(json, 'fr/docs-support-sla.json')).toEqual([])
})
it('reports EVERY forbidden key on a single compact line', () => {
const json = `{ "overview": { "objective": "x", "problem": "p", "solution": "s" } }`
const hits = findForbidden(json, 'fr/docs-support-sla.json')
expect(hits.map((h) => h.token).sort()).toEqual(['problem', 'solution'])
expect(hits.every((h) => h.line === 1)).toBe(true)
})
it('returns nothing for a clean i18n file', () => {
const json = `{
"title": "SLA",
"objective": "Description factuelle",
"access": { "navigation": "Navigation" },
"features": { "1": { "title": "Config", "description": "..." } }
}`
expect(findForbidden(json, 'fr/docs-support-sla.json')).toEqual([])
})
})
describe('extract-doc / findForbidden — doc-data.ts', () => {
it('flags benefits / beforeAfter object keys', () => {
const ts = `export const docData: DocData = {
overview: { objective: 'docsSupportSla.overview.objective' },
benefits: [
{ icon: 'time', value: '-70%' },
],
beforeAfter: {
beforeItems: ['Manual tracking'],
afterItems: ['Automated'],
},
}`
const hits = findForbidden(ts, 'src/pages/docs/business/platform/support/sla/doc-data.ts')
expect(hits.map((h) => h.token).sort()).toEqual(['beforeAfter', 'benefits'])
})
it('flags overview.problem / overview.solution object keys', () => {
const ts = `export const docData: DocData = {
overview: {
objective: 'x',
problem: 'x',
solution: 'x',
},
}`
const hits = findForbidden(ts, 'sla/doc-data.ts')
expect(hits.map((h) => h.token).sort()).toEqual(['problem', 'solution'])
})
it('returns nothing for a clean doc-data.ts', () => {
const ts = `export const docData: DocData = {
overview: { objective: 'x', stats: { useCases: 4 } },
useCases: [{ id: 'UC-001', name: 'Create' }],
features: [{ id: 'F-001', title: 'Config' }],
}`
expect(findForbidden(ts, 'sla/doc-data.ts')).toEqual([])
})
})
describe('extract-doc / findForbidden — user TSX', () => {
it('flags a t() reference to a benefits/beforeAfter/problem/solution key', () => {
const tsx = `export default function SlaDocPage() {
const { t } = useTranslation('docsSupportSla')
return (
{t('overview.solution')}{t('sections.benefits')}
{t('objective')}