Open-source personal finance manager. Self-hosted, privacy-first.
feat: add vitest configuration and add i18n validation tests (#291)
Geovane Pereiraf3112e53c76d
diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.ymlindex 2ffe44a7..07de8341 100644--- a/.github/workflows/ci.yml+++ b/.github/workflows/ci.yml@@ -86,3 +86,6 @@ jobs:- name: Type check & Buildrun: npm run build++ - name: Run tests+ run: npm testdiff --git a/frontend/package-lock.json b/frontend/package-lock.jsonindex 40f91eb5..912c57a3 100644--- a/frontend/package-lock.json+++ b/frontend/package-lock.json@@ -53,7 +53,8 @@"tw-animate-css": "^1.4.0","typescript": "~5.9.3","typescript-eslint": "^8.48.0",- "vite": "^7.3.1"+ "vite": "^7.3.1",+ "vitest": "^4.1.8"}},"node_modules/@antfu/ni": {@@ -4340,6 +4341,17 @@"@babel/types": "^7.28.2"}},+ "node_modules/@types/chai": {+ "version": "5.2.3",+ "resolved": "https://registry.npmjs.org/@types/chai/-/chai-5.2.3.tgz",+ "integrity": "sha512-Mw558oeA9fFbv65/y4mHtXDs9bPnFMZAL/jxdPFUpOHHIXX91mcgEHbS5Lahr+pwZFR8A7GQleRWeI6cGFC2UA==",+ "dev": true,+ "license": "MIT",+ "dependencies": {+ "@types/deep-eql": "*",+ "assertion-error": "^2.0.1"+ }+ },"node_modules/@types/d3-array": {"version": "3.2.2","resolved": "https://registry.npmjs.org/@types/d3-array/-/d3-array-3.2.2.tgz",@@ -4439,6 +4451,13 @@"@types/ms": "*"}},+ "node_modules/@types/deep-eql": {+ "version": "4.0.2",+ "resolved": "https://registry.npmjs.org/@types/deep-eql/-/deep-eql-4.0.2.tgz",+ "integrity": "sha512-c9h9dVVMigMPc4bwTvC5dxqtqJZwQPePsWjPlpSOnojbor6pGqdk541lfA7AqFQr5pB1BRdq0juY9db81BwyFw==",+ "dev": true,+ "license": "MIT"+ },"node_modules/@types/estree": {"version": "1.0.8","resolved": "https://registry.npmjs.org/@types/estree/-/estree-1.0.8.tgz",@@ -4862,6 +4881,119 @@"vite": "^4.2.0 || ^5.0.0 || ^6.0.0 || ^7.0.0"}},+ "node_modules/@vitest/expect": {+ "version": "4.1.8",+ "resolved": "https://registry.npmjs.org/@vitest/expect/-/expect-4.1.8.tgz",+ "integrity": "sha512-h3nDO677RDLEGlBxyQ5CW8RlMThSKSRLUePLOx09gNIWRL40edgA1GCZSZgf1W55MFAG6/Sw14KeaAnqv0NKdQ==",+ "dev": true,+ "license": "MIT",+ "dependencies": {+ "@standard-schema/spec": "^1.1.0",+ "@types/chai": "^5.2.2",+ "@vitest/spy": "4.1.8",+ "@vitest/utils": "4.1.8",+ "chai": "^6.2.2",+ "tinyrainbow": "^3.1.0"+ },+ "funding": {+ "url": "https://opencollective.com/vitest"+ }+ },+ "node_modules/@vitest/mocker": {+ "version": "4.1.8",+ "resolved": "https://registry.npmjs.org/@vitest/mocker/-/mocker-4.1.8.tgz",+ "integrity": "sha512-LEiN/xe4OSIbKe9HQIp5OC24agGD9J5CnmMgsLohVVoOPWL9a2sBoR6VBx43jQZb7Kr1l4RCuyCJzcAa0+dojw==",+ "dev": true,+ "license": "MIT",+ "dependencies": {+ "@vitest/spy": "4.1.8",+ "estree-walker": "^3.0.3",+ "magic-string": "^0.30.21"+ },+ "funding": {+ "url": "https://opencollective.com/vitest"+ },+ "peerDependencies": {+ "msw": "^2.4.9",+ "vite": "^6.0.0 || ^7.0.0 || ^8.0.0"+ },+ "peerDependenciesMeta": {+ "msw": {+ "optional": true+ },+ "vite": {+ "optional": true+ }+ }+ },+ "node_modules/@vitest/pretty-format": {+ "version": "4.1.8",+ "resolved": "https://registry.npmjs.org/@vitest/pretty-format/-/pretty-format-4.1.8.tgz",+ "integrity": "sha512-9GasEBxpZ1VYIpqHf/0+YGg121uSNwCKOJqIrTwWP/TB7DmFCiaBpNl3aPZzoLWfWkuqhbH8vJIVobZkvdo2cA==",+ "dev": true,+ "license": "MIT",+ "dependencies": {+ "tinyrainbow": "^3.1.0"+ },+ "funding": {+ "url": "https://opencollective.com/vitest"+ }+ },+ "node_modules/@vitest/runner": {+ "version": "4.1.8",+ "resolved": "https://registry.npmjs.org/@vitest/runner/-/runner-4.1.8.tgz",+ "integrity": "sha512-EmVxeBAfMJvycdjd6Hm+RbFBbA9fKvo0Kx37hNpBYoYeavH3RNsBXWDooR1mgD52dCrxIIuP7UotpfiwOikvcg==",+ "dev": true,+ "license": "MIT",+ "dependencies": {+ "@vitest/utils": "4.1.8",+ "pathe": "^2.0.3"+ },+ "funding": {+ "url": "https://opencollective.com/vitest"+ }+ },+ "node_modules/@vitest/snapshot": {+ "version": "4.1.8",+ "resolved": "https://registry.npmjs.org/@vitest/snapshot/-/snapshot-4.1.8.tgz",+ "integrity": "sha512-acfZboRmAIf05DEKcBQy33VXojFJjtUdLyo7oOmV9kebb2xdU01UknNiPuPZoJZQyO7DF0gZdTGTpeAzET9QPQ==",+ "dev": true,+ "license": "MIT",+ "dependencies": {+ "@vitest/pretty-format": "4.1.8",+ "@vitest/utils": "4.1.8",+ "magic-string": "^0.30.21",+ "pathe": "^2.0.3"+ },+ "funding": {+ "url": "https://opencollective.com/vitest"+ }+ },+ "node_modules/@vitest/spy": {+ "version": "4.1.8",+ "resolved": "https://registry.npmjs.org/@vitest/spy/-/spy-4.1.8.tgz",+ "integrity": "sha512-6EevtBp6OZOPF7bmz36HrGMeP3txgVSrgebWxHOafDXGkhIzfXK14f8KF6MuFfgXXUeHxmpD3BQxkV00/3s5mA==",+ "dev": true,+ "license": "MIT",+ "funding": {+ "url": "https://opencollective.com/vitest"+ }+ },+ "node_modules/@vitest/utils": {+ "version": "4.1.8",+ "resolved": "https://registry.npmjs.org/@vitest/utils/-/utils-4.1.8.tgz",+ "integrity": "sha512-uOJamYALNhfJ6iolExyQM40yIQwDqYnkKtQ5VCiSe17E33H0aQ/u+1GlRuz4LZBk6Mm3sg90G9hEbmEt37C1Zg==",+ "dev": true,+ "license": "MIT",+ "dependencies": {+ "@vitest/pretty-format": "4.1.8",+ "convert-source-map": "^2.0.0",+ "tinyrainbow": "^3.1.0"+ },+ "funding": {+ "url": "https://opencollective.com/vitest"+ }+ },"node_modules/accepts": {"version": "2.0.0","resolved": "https://registry.npmjs.org/accepts/-/accepts-2.0.0.tgz",@@ -5053,6 +5185,16 @@"node": ">=10"}},+ "node_modules/assertion-error": {+ "version": "2.0.1",+ "resolved": "https://registry.npmjs.org/assertion-error/-/assertion-error-2.0.1.tgz",+ "integrity": "sha512-Izi8RQcffqCeNVgFigKli1ssklIbpHnCYc6AknXGYoB6grJqyeby7jv12JUQgmTAnIDnbck1uxksT4dzN3PWBA==",+ "dev": true,+ "license": "MIT",+ "engines": {+ "node": ">=12"+ }+ },"node_modules/ast-types": {"version": "0.16.1","resolved": "https://registry.npmjs.org/ast-types/-/ast-types-0.16.1.tgz",@@ -5304,6 +5446,16 @@"url": "https://github.com/sponsors/wooorm"}},+ "node_modules/chai": {+ "version": "6.2.2",+ "resolved": "https://registry.npmjs.org/chai/-/chai-6.2.2.tgz",+ "integrity": "sha512-NUPRluOfOiTKBKvWPtSD4PhFvWCqOi0BGStNWs57X9js7XGTprSmFoz5F0tWhR4WPjNeR9jXqdC7/UpSJTnlRg==",+ "dev": true,+ "license": "MIT",+ "engines": {+ "node": ">=18"+ }+ },"node_modules/chalk": {"version": "4.1.2","resolved": "https://registry.npmjs.org/chalk/-/chalk-4.1.2.tgz",@@ -6217,6 +6369,13 @@"node": ">= 0.4"}},+ "node_modules/es-module-lexer": {+ "version": "2.1.0",+ "resolved": "https://registry.npmjs.org/es-module-lexer/-/es-module-lexer-2.1.0.tgz",+ "integrity": "sha512-n27zTYMjYu1aj4MjCWzSP7G9r75utsaoc8m61weK+W8JMBGGQybd43GstCXZ3WNmSFtGT9wi59qQTW6mhTR5LQ==",+ "dev": true,+ "license": "MIT"+ },"node_modules/es-object-atoms": {"version": "1.1.1","resolved": "https://registry.npmjs.org/es-object-atoms/-/es-object-atoms-1.1.1.tgz",@@ -6524,6 +6683,16 @@"url": "https://opencollective.com/unified"}},+ "node_modules/estree-walker": {+ "version": "3.0.3",+ "resolved": "https://registry.npmjs.org/estree-walker/-/estree-walker-3.0.3.tgz",+ "integrity": "sha512-7RUKfXgSMMkzt6ZuXmqapOurLGPPfgj6l9uRZ7lRGolvk0y2yocc35LdcxKC5PQZdn2DMqioAQ2NoWcrTKmm6g==",+ "dev": true,+ "license": "MIT",+ "dependencies": {+ "@types/estree": "^1.0.0"+ }+ },"node_modules/esutils": {"version": "2.0.3","resolved": "https://registry.npmjs.org/esutils/-/esutils-2.0.3.tgz",@@ -6600,6 +6769,16 @@"url": "https://github.com/sindresorhus/execa?sponsor=1"}},+ "node_modules/expect-type": {+ "version": "1.3.0",+ "resolved": "https://registry.npmjs.org/expect-type/-/expect-type-1.3.0.tgz",+ "integrity": "sha512-knvyeauYhqjOYvQ66MznSMs83wmHrCycNEN6Ao+2AeYEfxUIkuiVxdEa1qlGEPK+We3n0THiDciYSsCcgW/DoA==",+ "dev": true,+ "license": "Apache-2.0",+ "engines": {+ "node": ">=12.0.0"+ }+ },"node_modules/express": {"version": "5.2.1","resolved": "https://registry.npmjs.org/express/-/express-5.2.1.tgz",@@ -9546,6 +9725,20 @@"node": ">= 10"}},+ "node_modules/obug": {+ "version": "2.1.2",+ "resolved": "https://registry.npmjs.org/obug/-/obug-2.1.2.tgz",+ "integrity": "sha512-AWGB9WFcRXOQs48Z/udjI5ZcZMHXwX8XPByNpOydgcGsDLIzjGizhoMWJyKAWze7AVW/2W1i+/gPX4YtKe5cyg==",+ "dev": true,+ "funding": [+ "https://github.com/sponsors/sxzz",+ "https://opencollective.com/debug"+ ],+ "license": "MIT",+ "engines": {+ "node": ">=12.20.0"+ }+ },"node_modules/on-finished": {"version": "2.4.1","resolved": "https://registry.npmjs.org/on-finished/-/on-finished-2.4.1.tgz",@@ -9821,6 +10014,13 @@"dev": true,"license": "MIT"},+ "node_modules/pathe": {+ "version": "2.0.3",+ "resolved": "https://registry.npmjs.org/pathe/-/pathe-2.0.3.tgz",+ "integrity": "sha512-WUjGcAqP1gQacoQe+OBJsFA7Ld4DyXuUIjZ5cc75cLHvJ7dtNsTugphxIADwspS+AraAUePCKrSVtPLFj/F88w==",+ "dev": true,+ "license": "MIT"+ },"node_modules/pdfjs-dist": {"version": "5.5.207","resolved": "https://registry.npmjs.org/pdfjs-dist/-/pdfjs-dist-5.5.207.tgz",@@ -11020,6 +11220,13 @@"url": "https://github.com/sponsors/ljharb"}},+ "node_modules/siginfo": {+ "version": "2.0.0",+ "resolved": "https://registry.npmjs.org/siginfo/-/siginfo-2.0.0.tgz",+ "integrity": "sha512-ybx0WO1/8bSBLEWXZvEd7gMW3Sn3JFlW3TvX1nREbDLRNQNaeNN8WK0meBwPdAaOI7TtRRRJn/Es1zhrrCHu7g==",+ "dev": true,+ "license": "ISC"+ },"node_modules/signal-exit": {"version": "4.1.0","resolved": "https://registry.npmjs.org/signal-exit/-/signal-exit-4.1.0.tgz",@@ -11080,6 +11287,13 @@"url": "https://github.com/sponsors/wooorm"}},+ "node_modules/stackback": {+ "version": "0.0.2",+ "resolved": "https://registry.npmjs.org/stackback/-/stackback-0.0.2.tgz",+ "integrity": "sha512-1XMJE5fQo1jGH6Y/7ebnwPOBEkIEnT4QF32d5R1+VXdXveM0IBMJt8zfaxX1P3QhVwrYe+576+jkANtSS2mBbw==",+ "dev": true,+ "license": "MIT"+ },"node_modules/statuses": {"version": "2.0.2","resolved": "https://registry.npmjs.org/statuses/-/statuses-2.0.2.tgz",@@ -11090,6 +11304,13 @@"node": ">= 0.8"}},+ "node_modules/std-env": {+ "version": "4.1.0",+ "resolved": "https://registry.npmjs.org/std-env/-/std-env-4.1.0.tgz",+ "integrity": "sha512-Rq7ybcX2RuC55r9oaPVEW7/xu3tj8u4GeBYHBWCychFtzMIr86A7e3PPEBPT37sHStKX3+TiX/Fr/ACmJLVlLQ==",+ "dev": true,+ "license": "MIT"+ },"node_modules/stdin-discarder": {"version": "0.2.2","resolved": "https://registry.npmjs.org/stdin-discarder/-/stdin-discarder-0.2.2.tgz",@@ -11293,6 +11514,13 @@"integrity": "sha512-+FbBPE1o9QAYvviau/qC5SE3caw21q3xkvWKBtja5vgqOWIHHJ3ioaq1VPfn/Szqctz2bU/oYeKd9/z5BL+PVg==","license": "MIT"},+ "node_modules/tinybench": {+ "version": "2.9.0",+ "resolved": "https://registry.npmjs.org/tinybench/-/tinybench-2.9.0.tgz",+ "integrity": "sha512-0+DUvqWMValLmha6lr4kD8iAMK1HzV0/aKnCtWb9v9641TnP/MFb7Pc2bxoxQjTXAErryXVgUOfv2YqNllqGeg==",+ "dev": true,+ "license": "MIT"+ },"node_modules/tinyexec": {"version": "1.0.2","resolved": "https://registry.npmjs.org/tinyexec/-/tinyexec-1.0.2.tgz",@@ -11320,6 +11548,16 @@"url": "https://github.com/sponsors/SuperchupuDev"}},+ "node_modules/tinyrainbow": {+ "version": "3.1.0",+ "resolved": "https://registry.npmjs.org/tinyrainbow/-/tinyrainbow-3.1.0.tgz",+ "integrity": "sha512-Bf+ILmBgretUrdJxzXM0SgXLZ3XfiaUuOj/IKQHuTXip+05Xn+uyEYdVg0kYDipTBcLrCVyUzAPz7QmArb0mmw==",+ "dev": true,+ "license": "MIT",+ "engines": {+ "node": ">=14.0.0"+ }+ },"node_modules/tldts": {"version": "7.0.23","resolved": "https://registry.npmjs.org/tldts/-/tldts-7.0.23.tgz",@@ -11947,6 +12185,96 @@}}},+ "node_modules/vitest": {+ "version": "4.1.8",+ "resolved": "https://registry.npmjs.org/vitest/-/vitest-4.1.8.tgz",+ "integrity": "sha512-flY6ScbCIt9HThs+C5HS7jvGOB560DJtk/Z15IQROTA6zEy49Nh8T/dofWTQL+n3vswqn87sbJNiuqw1SDp5Ig==",+ "dev": true,+ "license": "MIT",+ "dependencies": {+ "@vitest/expect": "4.1.8",+ "@vitest/mocker": "4.1.8",+ "@vitest/pretty-format": "4.1.8",+ "@vitest/runner": "4.1.8",+ "@vitest/snapshot": "4.1.8",+ "@vitest/spy": "4.1.8",+ "@vitest/utils": "4.1.8",+ "es-module-lexer": "^2.0.0",+ "expect-type": "^1.3.0",+ "magic-string": "^0.30.21",+ "obug": "^2.1.1",+ "pathe": "^2.0.3",+ "picomatch": "^4.0.3",+ "std-env": "^4.0.0-rc.1",+ "tinybench": "^2.9.0",+ "tinyexec": "^1.0.2",+ "tinyglobby": "^0.2.15",+ "tinyrainbow": "^3.1.0",+ "vite": "^6.0.0 || ^7.0.0 || ^8.0.0",+ "why-is-node-running": "^2.3.0"+ },+ "bin": {+ "vitest": "vitest.mjs"+ },+ "engines": {+ "node": "^20.0.0 || ^22.0.0 || >=24.0.0"+ },+ "funding": {+ "url": "https://opencollective.com/vitest"+ },+ "peerDependencies": {+ "@edge-runtime/vm": "*",+ "@opentelemetry/api": "^1.9.0",+ "@types/node": "^20.0.0 || ^22.0.0 || >=24.0.0",+ "@vitest/browser-playwright": "4.1.8",+ "@vitest/browser-preview": "4.1.8",+ "@vitest/browser-webdriverio": "4.1.8",+ "@vitest/coverage-istanbul": "4.1.8",+ "@vitest/coverage-v8": "4.1.8",+ "@vitest/ui": "4.1.8",+ "happy-dom": "*",+ "jsdom": "*",+ "vite": "^6.0.0 || ^7.0.0 || ^8.0.0"+ },+ "peerDependenciesMeta": {+ "@edge-runtime/vm": {+ "optional": true+ },+ "@opentelemetry/api": {+ "optional": true+ },+ "@types/node": {+ "optional": true+ },+ "@vitest/browser-playwright": {+ "optional": true+ },+ "@vitest/browser-preview": {+ "optional": true+ },+ "@vitest/browser-webdriverio": {+ "optional": true+ },+ "@vitest/coverage-istanbul": {+ "optional": true+ },+ "@vitest/coverage-v8": {+ "optional": true+ },+ "@vitest/ui": {+ "optional": true+ },+ "happy-dom": {+ "optional": true+ },+ "jsdom": {+ "optional": true+ },+ "vite": {+ "optional": false+ }+ }+ },"node_modules/void-elements": {"version": "3.1.0","resolved": "https://registry.npmjs.org/void-elements/-/void-elements-3.1.0.tgz",@@ -11982,6 +12310,23 @@"node": ">= 8"}},+ "node_modules/why-is-node-running": {+ "version": "2.3.0",+ "resolved": "https://registry.npmjs.org/why-is-node-running/-/why-is-node-running-2.3.0.tgz",+ "integrity": "sha512-hUrmaWBdVDcxvYqnyh09zunKzROWjbZTiNy8dBEjkS7ehEDQibXJ7XvlmtbwuTclUiIyN+CyXQD4Vmko8fNm8w==",+ "dev": true,+ "license": "MIT",+ "dependencies": {+ "siginfo": "^2.0.0",+ "stackback": "0.0.2"+ },+ "bin": {+ "why-is-node-running": "cli.js"+ },+ "engines": {+ "node": ">=8"+ }+ },"node_modules/word-wrap": {"version": "1.2.5","resolved": "https://registry.npmjs.org/word-wrap/-/word-wrap-1.2.5.tgz",diff --git a/frontend/package.json b/frontend/package.jsonindex ea0e334c..fb82fdb7 100644--- a/frontend/package.json+++ b/frontend/package.json@@ -8,7 +8,8 @@"build": "tsc -b && vite build","lint": "eslint .","preview": "vite preview",- "dev:docker": "node ../scripts/dev-frontend.mjs"+ "dev:docker": "node ../scripts/dev-frontend.mjs",+ "test": "vitest run"},"dependencies": {"@hookform/resolvers": "^5.2.2",@@ -56,6 +57,7 @@"tw-animate-css": "^1.4.0","typescript": "~5.9.3","typescript-eslint": "^8.48.0",- "vite": "^7.3.1"+ "vite": "^7.3.1",+ "vitest": "^4.1.8"}}diff --git a/frontend/src/locales/es.json b/frontend/src/locales/es.jsonindex e9718d1f..324c31fd 100644--- a/frontend/src/locales/es.json+++ b/frontend/src/locales/es.json@@ -279,6 +279,8 @@"transactions": {"title": "Transacciones","section": "Financiero",+ "monthPrevious": "Mes anterior",+ "monthNext": "Mes siguiente","description": "Descripción","amount": "Importe","status": "Estado",diff --git a/frontend/src/locales/i18n.test.ts b/frontend/src/locales/i18n.test.tsnew file mode 100644index 00000000..1528f75e--- /dev/null+++ b/frontend/src/locales/i18n.test.ts@@ -0,0 +1,194 @@+/// <reference types="node" />+import { readFileSync, readdirSync } from 'node:fs'+import path from 'node:path'+import { fileURLToPath } from 'node:url'+import { describe, expect, it } from 'vitest'++const LOCALES_DIR = path.dirname(fileURLToPath(import.meta.url))+const LOCALES = readdirSync(LOCALES_DIR)+ .filter((f: string) => f.endsWith('.json'))+ .map((f: string) => f.replace(/\.json$/, ''))++function readRaw(locale: string): string {+ return readFileSync(path.join(LOCALES_DIR, `${locale}.json`), 'utf-8')+}++function flattenKeys(obj: Record<string, unknown>, prefix = ''): string[] {+ return Object.entries(obj).flatMap(([k, v]) => {+ const full = prefix ? `${prefix}.${k}` : k+ return v !== null && typeof v === 'object' && !Array.isArray(v)+ ? flattenKeys(v as Record<string, unknown>, full)+ : [full]+ })+}++function flattenValues(obj: Record<string, unknown>, prefix = ''): Map<string, string> {+ const result = new Map<string, string>()+ for (const [k, v] of Object.entries(obj)) {+ const full = prefix ? `${prefix}.${k}` : k+ if (typeof v === 'string') result.set(full, v)+ else if (v !== null && typeof v === 'object' && !Array.isArray(v))+ for (const entry of flattenValues(v as Record<string, unknown>, full))+ result.set(entry[0], entry[1])+ }+ return result+}++function extractPlaceholders(value: string): Set<string> {+ return new Set((value.match(/\{\{(\w+)\}\}/g) ?? []))+}++// i18next plural suffixes — some languages (e.g. Polish) expand a single base+// key into _zero/_one/_two/_few/_many/_other forms instead of using one string.+const PLURAL_SUFFIXES = ['_zero', '_one', '_two', '_few', '_many', '_other']++function pluralBase(key: string): string | null {+ for (const s of PLURAL_SUFFIXES) {+ if (key.endsWith(s)) return key.slice(0, -s.length)+ }+ return null+}++function hasKeyOrPluralForms(keys: Set<string>, baseKey: string): boolean {+ return keys.has(baseKey) || PLURAL_SUFFIXES.some((s) => keys.has(`${baseKey}${s}`))+}++/**+ * Minimal JSON parser that detects duplicate keys at any nesting level.+ * JSON.parse silently discards duplicates (last-wins), so we need our own walk.+ */+function findDuplicateKeys(source: string): string[] {+ const duplicates: string[] = []+ let i = 0++ const ws = () => { while (i < source.length && ' \t\r\n'.includes(source[i])) i++ }++ const str = (): string => {+ i++ // skip "+ let s = ''+ while (i < source.length && source[i] !== '"') {+ if (source[i] === '\\') { i++; s += source[i++] }+ else s += source[i++]+ }+ i++ // skip "+ return s+ }++ const val = (keyPath: string): void => {+ ws()+ if (source[i] === '{') obj(keyPath)+ else if (source[i] === '[') arr(keyPath)+ else if (source[i] === '"') str()+ else while (i < source.length && !' \t\r\n,}]'.includes(source[i])) i+++ }++ const obj = (keyPath: string): void => {+ i++ // skip {+ ws()+ const seen = new Set<string>()+ while (i < source.length && source[i] !== '}') {+ ws()+ if (source[i] !== '"') break+ const key = str()+ const full = keyPath ? `${keyPath}.${key}` : key+ if (seen.has(key)) duplicates.push(full)+ seen.add(key)+ ws(); i++ // skip :+ val(full)+ ws()+ if (source[i] === ',') i+++ ws()+ }+ i++ // skip }+ }++ const arr = (keyPath: string): void => {+ i++ // skip [+ ws()+ let idx = 0+ while (i < source.length && source[i] !== ']') {+ val(`${keyPath}[${idx++}]`)+ ws()+ if (source[i] === ',') i+++ ws()+ }+ i++ // skip ]+ }++ ws(); val('')+ return duplicates+}++describe('i18n locale files', () => {+ describe('no duplicate keys', () => {+ for (const locale of LOCALES) {+ it(`${locale}.json`, () => {+ const duplicates = findDuplicateKeys(readRaw(locale))+ expect(duplicates, `Duplicate keys: ${duplicates.join(', ')}`).toEqual([])+ })+ }+ })++ describe('all languages contain all keys from en.json', () => {+ const enKeys = new Set(flattenKeys(JSON.parse(readRaw('en'))))++ for (const locale of LOCALES.filter((l: string) => l !== 'en')) {+ it(locale, () => {+ const keys = new Set(flattenKeys(JSON.parse(readRaw(locale))))+ // A key is covered if the locale has the key directly OR has at least one+ // i18next plural form of it (e.g. _one/_few/_many/_other for Polish).+ const missing = [...enKeys].filter((k) => !hasKeyOrPluralForms(keys, k))+ expect(missing, `Keys missing in ${locale}:`).toEqual([])+ })+ }+ })++ describe('no extra keys not present in en.json', () => {+ const enKeys = new Set(flattenKeys(JSON.parse(readRaw('en'))))++ for (const locale of LOCALES.filter((l: string) => l !== 'en')) {+ it(locale, () => {+ const keys = new Set(flattenKeys(JSON.parse(readRaw(locale))))+ // A key is valid if it exists in en directly, OR if it is a plural form+ // of a key that exists in en (e.g. "foo_few" is valid when en has "foo").+ const extra = [...keys].filter((k) => {+ if (enKeys.has(k)) return false+ const base = pluralBase(k)+ return !(base && enKeys.has(base))+ })+ expect(extra, `Extra keys in ${locale} not in en:`).toEqual([])+ })+ }+ })++ describe('placeholder variables match en.json', () => {+ const enValues = flattenValues(JSON.parse(readRaw('en')))++ for (const locale of LOCALES.filter((l: string) => l !== 'en')) {+ it(locale, () => {+ const localeValues = flattenValues(JSON.parse(readRaw(locale)))+ const mismatches: string[] = []++ for (const [key, enValue] of enValues) {+ const enPlaceholders = extractPlaceholders(enValue)+ if (enPlaceholders.size === 0) continue++ // For plural-form locales the base key won't exist — check each plural form instead.+ const keysToCheck = localeValues.has(key)+ ? [key]+ : PLURAL_SUFFIXES.map((s) => `${key}${s}`).filter((k) => localeValues.has(k))++ for (const localeKey of keysToCheck) {+ const missing = [...enPlaceholders].filter(+ (p) => !extractPlaceholders(localeValues.get(localeKey)!).has(p),+ )+ if (missing.length > 0)+ mismatches.push(`${localeKey}: missing ${missing.map((p) => `{{${p}}}`).join(', ')}`)+ }+ }++ expect(mismatches, `Placeholder mismatches in ${locale}:`).toEqual([])+ })+ }+ })+})diff --git a/frontend/src/locales/it.json b/frontend/src/locales/it.jsonindex 77ee1097..5ab24c14 100644--- a/frontend/src/locales/it.json+++ b/frontend/src/locales/it.json@@ -105,6 +105,7 @@"dashboard": "Dashboard","transactions": "Transazioni","accounts": "Conti",+ "collections": "Collezioni","import": "Importa","rules": "Regole","categories": "Categorie",@@ -124,6 +125,32 @@"agents": "Agenti","aiAgents": "Agenti IA"},+ "collections": {+ "title": "Collezioni",+ "subtitle": "Raggruppa i tuoi conti in collezioni con nome (es. Azienda, Lungo termine, Quotidiano) per filtrare dashboard, report e transazioni.",+ "allAccounts": "Tutti i conti",+ "viewing": "Visualizzando",+ "clearFilter": "Cancella",+ "manage": "Gestisci collezioni",+ "add": "Nuova collezione",+ "edit": "Modifica collezione",+ "empty": "Ancora nessuna collezione. Creane una per raggruppare i tuoi conti.",+ "accountCount": "{{count}} conti",+ "name": "Nome",+ "namePlaceholder": "es. Azienda, Lungo termine, Fondo di emergenza",+ "color": "Colore",+ "accounts": "Conti",+ "accountsHint": "{{count}} selezionati",+ "wallets": "Portafogli",+ "walletsHint": "{{count}} selezionati",+ "walletCount": "{{count}} portafogli",+ "noAccounts": "Ancora nessun conto.",+ "created": "Collezione creata",+ "updated": "Collezione aggiornata",+ "deleted": "Collezione eliminata",+ "confirmDeleteTitle": "Eliminare la collezione?",+ "confirmDeleteDesc": "\"{{name}}\" verrà rimossa. I tuoi conti e dati non sono interessati."+ },"auth": {"login": "Accedi","register": "Crea account",@@ -1025,6 +1052,7 @@"balance": "Saldo","inflow": "Entrate","outflow": "Uscite",+ "change": "Variazione","inflowOutflow": "Entrate vs Uscite","startingBalance": "Saldo iniziale","endingBalance": "Saldo previsto",diff --git a/frontend/tsconfig.app.json b/frontend/tsconfig.app.jsonindex 1fdd51e5..5c877a0f 100644--- a/frontend/tsconfig.app.json+++ b/frontend/tsconfig.app.json@@ -29,5 +29,6 @@"noFallthroughCasesInSwitch": true,"noUncheckedSideEffectImports": true},- "include": ["src"]+ "include": ["src"],+ "exclude": ["**/*.test.ts", "**/*.test.tsx"]}diff --git a/frontend/tsconfig.node.json b/frontend/tsconfig.node.jsonindex 8a67f62f..8a94e959 100644--- a/frontend/tsconfig.node.json+++ b/frontend/tsconfig.node.json@@ -22,5 +22,5 @@"noFallthroughCasesInSwitch": true,"noUncheckedSideEffectImports": true},- "include": ["vite.config.ts"]+ "include": ["vite.config.ts", "vitest.config.ts", "src/**/*.test.ts", "src/**/*.test.tsx"]}diff --git a/frontend/vitest.config.ts b/frontend/vitest.config.tsnew file mode 100644index 00000000..06bc614b--- /dev/null+++ b/frontend/vitest.config.ts@@ -0,0 +1,13 @@+import { defineConfig } from 'vitest/config'+import path from 'node:path'++export default defineConfig({+ resolve: {+ alias: {+ '@': path.resolve(__dirname, './src'),+ },+ },+ test: {+ environment: 'node',+ },+})