@jjlmoya/utils-civic 1.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (119) hide show
  1. package/.github/workflows/npm-publish.yml +40 -0
  2. package/.gitignore +6 -0
  3. package/.stylelintrc.json +98 -0
  4. package/astro.config.mjs +19 -0
  5. package/eslint.config.js +201 -0
  6. package/package.json +79 -0
  7. package/prompts/create_tool.md +98 -0
  8. package/prompts/i18n/de.md +16 -0
  9. package/prompts/i18n/en.md +16 -0
  10. package/prompts/i18n/es.md +16 -0
  11. package/prompts/i18n/fr.md +16 -0
  12. package/prompts/i18n/id.md +16 -0
  13. package/prompts/i18n/it.md +16 -0
  14. package/prompts/i18n/ja.md +16 -0
  15. package/prompts/i18n/ko.md +16 -0
  16. package/prompts/i18n/nl.md +16 -0
  17. package/prompts/i18n/pl.md +16 -0
  18. package/prompts/i18n/pt.md +16 -0
  19. package/prompts/i18n/ru.md +16 -0
  20. package/prompts/i18n/sv.md +16 -0
  21. package/prompts/i18n/tr.md +16 -0
  22. package/prompts/i18n/zh.md +16 -0
  23. package/prompts/seo.md +58 -0
  24. package/prompts/translations/french.md +33 -0
  25. package/scripts/postinstall.mjs +27 -0
  26. package/src/category/CivicCategorySEO.astro +9 -0
  27. package/src/category/i18n/de.ts +21 -0
  28. package/src/category/i18n/en.ts +25 -0
  29. package/src/category/i18n/es.ts +21 -0
  30. package/src/category/i18n/fr.ts +21 -0
  31. package/src/category/i18n/id.ts +21 -0
  32. package/src/category/i18n/it.ts +21 -0
  33. package/src/category/i18n/ja.ts +21 -0
  34. package/src/category/i18n/ko.ts +21 -0
  35. package/src/category/i18n/nl.ts +21 -0
  36. package/src/category/i18n/pl.ts +21 -0
  37. package/src/category/i18n/pt.ts +21 -0
  38. package/src/category/i18n/ru.ts +21 -0
  39. package/src/category/i18n/sv.ts +21 -0
  40. package/src/category/i18n/tr.ts +21 -0
  41. package/src/category/i18n/zh.ts +21 -0
  42. package/src/category/index.ts +24 -0
  43. package/src/components/PreviewNavSidebar.astro +116 -0
  44. package/src/components/PreviewToolbar.astro +143 -0
  45. package/src/data.ts +10 -0
  46. package/src/entries.ts +9 -0
  47. package/src/env.d.ts +5 -0
  48. package/src/index.ts +20 -0
  49. package/src/layouts/PreviewLayout.astro +117 -0
  50. package/src/pages/[locale]/[slug].astro +163 -0
  51. package/src/pages/[locale].astro +253 -0
  52. package/src/pages/index.astro +4 -0
  53. package/src/tests/bibliography_wellformed_export.test.ts +46 -0
  54. package/src/tests/category_seo_quality.test.ts +79 -0
  55. package/src/tests/diacritics_density.test.ts +118 -0
  56. package/src/tests/faq_count.test.ts +18 -0
  57. package/src/tests/i18n_coverage.test.ts +34 -0
  58. package/src/tests/inverted_punctuation.test.ts +84 -0
  59. package/src/tests/locale_completeness.test.ts +23 -0
  60. package/src/tests/mocks/astro_mock.js +2 -0
  61. package/src/tests/no_em_dash.test.ts +47 -0
  62. package/src/tests/no_en_dash.test.ts +70 -0
  63. package/src/tests/no_h1_in_components.test.ts +48 -0
  64. package/src/tests/pagespeed_best_practices.test.ts +198 -0
  65. package/src/tests/qa-test-helpers.ts +31 -0
  66. package/src/tests/qa_bibliography_links.test.ts +53 -0
  67. package/src/tests/qa_claim_evidence.test.ts +68 -0
  68. package/src/tests/qa_logic_reference_coverage.test.ts +45 -0
  69. package/src/tests/qa_runtime_i18n.test.ts +100 -0
  70. package/src/tests/registry_contract.test.ts +67 -0
  71. package/src/tests/schemas_fulfillment.test.ts +23 -0
  72. package/src/tests/script_density.test.ts +94 -0
  73. package/src/tests/seo_length.test.ts +23 -0
  74. package/src/tests/seo_parity.test.ts +60 -0
  75. package/src/tests/seo_translation_completeness.test.ts +75 -0
  76. package/src/tests/seo_wellformed_export.test.ts +65 -0
  77. package/src/tests/shared-test-helpers.ts +56 -0
  78. package/src/tests/slug_language_code_format.test.ts +23 -0
  79. package/src/tests/slug_uniqueness.test.ts +81 -0
  80. package/src/tests/spanish_leakage.test.ts +175 -0
  81. package/src/tests/title_quality.test.ts +55 -0
  82. package/src/tests/tool_exports.test.ts +34 -0
  83. package/src/tests/tool_validation.test.ts +16 -0
  84. package/src/tests/translation_copy.test.ts +123 -0
  85. package/src/tool/election-seat-apportionment-calculator/bibliography.astro +6 -0
  86. package/src/tool/election-seat-apportionment-calculator/bibliography.ts +16 -0
  87. package/src/tool/election-seat-apportionment-calculator/component.astro +69 -0
  88. package/src/tool/election-seat-apportionment-calculator/controller.ts +181 -0
  89. package/src/tool/election-seat-apportionment-calculator/dom-views.ts +75 -0
  90. package/src/tool/election-seat-apportionment-calculator/election-seat-apportionment-calculator.css +585 -0
  91. package/src/tool/election-seat-apportionment-calculator/entry.ts +28 -0
  92. package/src/tool/election-seat-apportionment-calculator/evaluator.ts +20 -0
  93. package/src/tool/election-seat-apportionment-calculator/i18n/de.ts +55 -0
  94. package/src/tool/election-seat-apportionment-calculator/i18n/en.ts +108 -0
  95. package/src/tool/election-seat-apportionment-calculator/i18n/es.ts +50 -0
  96. package/src/tool/election-seat-apportionment-calculator/i18n/fr.ts +48 -0
  97. package/src/tool/election-seat-apportionment-calculator/i18n/id.ts +48 -0
  98. package/src/tool/election-seat-apportionment-calculator/i18n/it.ts +48 -0
  99. package/src/tool/election-seat-apportionment-calculator/i18n/ja.ts +48 -0
  100. package/src/tool/election-seat-apportionment-calculator/i18n/ko.ts +48 -0
  101. package/src/tool/election-seat-apportionment-calculator/i18n/nl.ts +48 -0
  102. package/src/tool/election-seat-apportionment-calculator/i18n/pl.ts +48 -0
  103. package/src/tool/election-seat-apportionment-calculator/i18n/pt.ts +48 -0
  104. package/src/tool/election-seat-apportionment-calculator/i18n/ru.ts +48 -0
  105. package/src/tool/election-seat-apportionment-calculator/i18n/sv.ts +48 -0
  106. package/src/tool/election-seat-apportionment-calculator/i18n/tr.ts +48 -0
  107. package/src/tool/election-seat-apportionment-calculator/i18n/zh.ts +48 -0
  108. package/src/tool/election-seat-apportionment-calculator/index.ts +11 -0
  109. package/src/tool/election-seat-apportionment-calculator/logic.test.ts +90 -0
  110. package/src/tool/election-seat-apportionment-calculator/logic.ts +268 -0
  111. package/src/tool/election-seat-apportionment-calculator/seo.astro +14 -0
  112. package/src/tool/election-seat-apportionment-calculator/sharing.test.ts +34 -0
  113. package/src/tool/election-seat-apportionment-calculator/sharing.ts +88 -0
  114. package/src/tool/election-seat-apportionment-calculator/storage.ts +28 -0
  115. package/src/tool/election-seat-apportionment-calculator/ui.ts +92 -0
  116. package/src/tools.ts +7 -0
  117. package/src/types.ts +69 -0
  118. package/tsconfig.json +15 -0
  119. package/vitest.config.ts +20 -0
@@ -0,0 +1,253 @@
1
+ ---
2
+ import PreviewLayout from '../layouts/PreviewLayout.astro';
3
+ import PreviewNavSidebar from '../components/PreviewNavSidebar.astro';
4
+ import { civicCategory, ALL_TOOLS } from '../index';
5
+ import { Icon } from 'astro-icon/components';
6
+ import type { KnownLocale, ToolLocaleContent } from '../types';
7
+
8
+ export async function getStaticPaths() {
9
+ const locales = ['de', 'en', 'es', 'fr', 'id', 'it', 'ja', 'ko', 'nl', 'pl', 'pt', 'ru', 'sv', 'tr', 'zh'] as KnownLocale[];
10
+ return locales.map(locale => ({ params: { locale } }));
11
+ }
12
+
13
+ const { locale: currentLocale } = Astro.params as { locale: KnownLocale };
14
+
15
+ const categoryContent = await civicCategory.i18n[currentLocale]!();
16
+
17
+ const tools = ALL_TOOLS || [];
18
+
19
+ const toolsWithContent = tools.length > 0
20
+ ? await Promise.all(
21
+ tools.map(async ({ entry, Component }) => {
22
+ const languages = Object.keys(entry.i18n);
23
+ const localeEntries = await Promise.all(
24
+ languages.map(async (l) => {
25
+ const content = await entry.i18n[l as KnownLocale]!();
26
+ return [l, content];
27
+ })
28
+ );
29
+
30
+ const localeContents = Object.fromEntries(localeEntries) as Record<string, ToolLocaleContent<Record<string, string>>>;
31
+
32
+ const currentLocaleContent = localeContents[currentLocale] || localeContents['en'];
33
+ const availableLocales: Record<string, string> = {};
34
+
35
+ for (const l of languages) {
36
+ const lCont = localeContents[l];
37
+ if (lCont) {
38
+ availableLocales[l] = `/${l}/${lCont.slug}`;
39
+ }
40
+ }
41
+
42
+ return { entry, Component, locale: currentLocaleContent, availableLocales };
43
+ })
44
+ )
45
+ : [];
46
+ ---
47
+
48
+ <PreviewLayout
49
+ title={categoryContent.title}
50
+ currentLocale={currentLocale}
51
+ hasSidebar={true}
52
+ >
53
+ <PreviewNavSidebar
54
+ slot="sidebar"
55
+ categoryTitle={categoryContent.title}
56
+ tools={toolsWithContent.map(({ entry, locale, availableLocales }) => {
57
+ const href = availableLocales[currentLocale] || (locale ? `/${currentLocale}/${locale.slug}` : '#');
58
+ return {
59
+ id: entry.id,
60
+ title: locale?.title || entry.id,
61
+ href: href,
62
+ };
63
+ })}
64
+ />
65
+ <div class="dashboard">
66
+ <header class="preview-header">
67
+ <span class="badge">preview · @jjlmoya/utils-civic</span>
68
+ <h1>{categoryContent.title}</h1>
69
+ <p>{categoryContent.description}</p>
70
+ </header>
71
+
72
+ <div class="tool-list">
73
+ {toolsWithContent?.map(({ entry, locale, availableLocales }) => (
74
+ <article class="tool-card">
75
+ <a href={availableLocales?.[currentLocale] || (locale ? `/${currentLocale}/${locale.slug}` : '#')} class="tool-card-link">
76
+ <div class="tool-icons">
77
+ <div class="icon-wrapper bg">
78
+ <Icon name={entry.icons.bg} />
79
+ </div>
80
+ <div class="icon-wrapper fg">
81
+ <Icon name={entry.icons.fg} />
82
+ </div>
83
+ </div>
84
+ <div class="tool-card-content">
85
+ <h2 class="tool-title">{locale?.title}</h2>
86
+ <p class="tool-description">{locale?.description}</p>
87
+ </div>
88
+ <div class="tool-card-meta">
89
+ <span class="tool-id">{entry.id}</span>
90
+ </div>
91
+ </a>
92
+
93
+ {availableLocales && Object.keys(availableLocales).length > 1 && (
94
+ <div class="tool-locales">
95
+ {Object.entries(availableLocales).map(([l, url]) => (
96
+ <a href={url} class="locale-badge" title={`Ver en ${l.toUpperCase()}`} class:list={{ active: l === currentLocale }}>
97
+ {l.toUpperCase()}
98
+ </a>
99
+ ))}
100
+ </div>
101
+ )}
102
+ </article>
103
+ ))}
104
+ </div>
105
+
106
+ </div>
107
+ </PreviewLayout>
108
+
109
+ <style>
110
+ .dashboard {
111
+ display: flex;
112
+ flex-direction: column;
113
+ gap: 5rem;
114
+ }
115
+ .preview-header {
116
+ text-align: center;
117
+ padding-bottom: 3rem;
118
+ border-bottom: 1px solid var(--border-color);
119
+ }
120
+ .badge {
121
+ display: inline-block;
122
+ padding: 0.25rem 0.75rem;
123
+ background: var(--accent);
124
+ border-radius: 99px;
125
+ font-size: 0.7rem;
126
+ font-weight: 800;
127
+ margin-bottom: 1.5rem;
128
+ color: var(--text-base);
129
+ letter-spacing: 0.05em;
130
+ }
131
+ h1 {
132
+ font-size: clamp(2rem, 6vw, 3.5rem);
133
+ font-weight: 900;
134
+ margin: 0 0 1rem;
135
+ background: linear-gradient(to bottom, var(--text-base), var(--text-muted));
136
+ -webkit-background-clip: text;
137
+ -webkit-text-fill-color: transparent;
138
+ background-clip: text;
139
+ }
140
+ .preview-header p {
141
+ color: var(--text-muted);
142
+ font-size: 1.1rem;
143
+ margin: 0;
144
+ }
145
+ .tool-list {
146
+ display: grid;
147
+ grid-template-columns: repeat(auto-fill, minmax(320px, 1fr));
148
+ gap: 2rem;
149
+ }
150
+
151
+ .tool-card {
152
+ display: flex;
153
+ flex-direction: column;
154
+ gap: 1rem;
155
+ }
156
+ .tool-card-link {
157
+ flex: 1;
158
+ display: flex;
159
+ flex-direction: column;
160
+ padding: 1.5rem;
161
+ background: var(--bg-surface);
162
+ border: 1px solid var(--border-color);
163
+ border-radius: 0.75rem;
164
+ text-decoration: none;
165
+ transition: all 0.2s ease;
166
+ }
167
+ .tool-card-link:hover {
168
+ border-color: var(--accent);
169
+ background: rgba(244, 63, 94, 0.05);
170
+ transform: translateY(-2px);
171
+ }
172
+ .tool-icons {
173
+ display: flex;
174
+ align-items: center;
175
+ gap: 1rem;
176
+ margin-bottom: 1.25rem;
177
+ }
178
+ .icon-wrapper {
179
+ display: flex;
180
+ align-items: center;
181
+ justify-content: center;
182
+ width: 3rem;
183
+ height: 3rem;
184
+ border-radius: 0.5rem;
185
+ font-size: 1.5rem;
186
+ }
187
+ .icon-wrapper.bg {
188
+ background: var(--accent);
189
+ color: var(--text-base);
190
+ }
191
+ .icon-wrapper.fg {
192
+ background: var(--bg-page);
193
+ border: 1px solid var(--border-color);
194
+ color: var(--accent);
195
+ }
196
+ .tool-card-content {
197
+ flex: 1;
198
+ display: flex;
199
+ flex-direction: column;
200
+ }
201
+ .tool-title {
202
+ font-size: 1.25rem;
203
+ font-weight: 700;
204
+ margin: 0 0 0.5rem;
205
+ color: var(--text-base);
206
+ }
207
+ .tool-description {
208
+ font-size: 0.9375rem;
209
+ color: var(--text-muted);
210
+ line-height: 1.5;
211
+ margin: 0;
212
+ }
213
+ .tool-card-meta {
214
+ padding-top: 1rem;
215
+ border-top: 1px solid var(--border-color);
216
+ margin-top: 1.5rem;
217
+ }
218
+ .tool-id {
219
+ display: inline-block;
220
+ font-size: 0.7rem;
221
+ background: var(--bg-page);
222
+ border: 1px solid var(--border-color);
223
+ padding: 0.35rem 0.75rem;
224
+ border-radius: 0.4rem;
225
+ color: var(--accent);
226
+ font-weight: 600;
227
+ }
228
+ .tool-locales {
229
+ display: flex;
230
+ gap: 0.5rem;
231
+ flex-wrap: wrap;
232
+ }
233
+ .locale-badge {
234
+ display: inline-block;
235
+ padding: 0.4rem 0.85rem;
236
+ background: var(--bg-page);
237
+ border: 1px solid var(--border-color);
238
+ border-radius: 0.4rem;
239
+ color: var(--text-muted);
240
+ text-decoration: none;
241
+ font-size: 0.75rem;
242
+ font-weight: 600;
243
+ text-transform: uppercase;
244
+ letter-spacing: 0.05em;
245
+ transition: all 0.15s ease;
246
+ }
247
+ .locale-badge:hover,
248
+ .locale-badge.active {
249
+ color: var(--accent);
250
+ border-color: var(--accent);
251
+ background: rgba(244, 63, 94, 0.1);
252
+ }
253
+ </style>
@@ -0,0 +1,4 @@
1
+ ---
2
+ ---
3
+ <meta http-equiv="refresh" content="0;url=/es" />
4
+
@@ -0,0 +1,46 @@
1
+ import { describe, it, expect } from 'vitest';
2
+ import { readdirSync, readFileSync, existsSync } from 'fs';
3
+ import { join, relative } from 'path';
4
+
5
+ function findBibliographyAstroFiles(dir: string): string[] {
6
+ const files: string[] = [];
7
+ if (!existsSync(dir)) return files;
8
+ const entries = readdirSync(dir, { withFileTypes: true });
9
+
10
+ for (const entry of entries) {
11
+ const fullPath = join(dir, entry.name);
12
+ if (entry.isDirectory()) {
13
+ files.push(...findBibliographyAstroFiles(fullPath));
14
+ } else if (entry.isFile() && entry.name === 'bibliography.astro') {
15
+ files.push(fullPath);
16
+ }
17
+ }
18
+
19
+ return files;
20
+ }
21
+
22
+ const toolDir = join(process.cwd(), 'src', 'tool');
23
+ const bibliographyFiles = findBibliographyAstroFiles(toolDir);
24
+
25
+ describe('Bibliography Component Wellformed Export', () => {
26
+ it('found tool bibliography.astro components', () => {
27
+ expect(bibliographyFiles.length).toBeGreaterThan(0);
28
+ });
29
+
30
+ bibliographyFiles.forEach((file) => {
31
+ const relativePath = relative(process.cwd(), file);
32
+
33
+ it(`${relativePath} should use SharedBibliography from @jjlmoya/utils-shared`, () => {
34
+ const content = readFileSync(file, 'utf-8');
35
+
36
+ const usesSharedComponent =
37
+ content.includes('@jjlmoya/utils-shared') &&
38
+ (content.includes('Bibliography') || content.includes('SharedBibliography'));
39
+
40
+ expect(
41
+ usesSharedComponent,
42
+ `File "${relativePath}" does not use the standard Bibliography component from @jjlmoya/utils-shared, resulting in unstyled or raw bibliography output.`,
43
+ ).toBe(true);
44
+ });
45
+ });
46
+ });
@@ -0,0 +1,79 @@
1
+ import { describe, expect, it } from 'vitest';
2
+ import type { CategoryLocaleContent } from '../types';
3
+
4
+ const EXPECTED_LOCALES = ['de', 'en', 'es', 'fr', 'id', 'it', 'ja', 'ko', 'nl', 'pl', 'pt', 'ru', 'sv', 'tr', 'zh'] as const;
5
+ const ENGLISH_SLUG_LOCALES = new Set(['en', 'ja', 'ko', 'zh']);
6
+ const EXPECTED_CATEGORY_SLUG = 'civic';
7
+ const COMPACT_LOCALES = new Set(['ja', 'ko', 'zh']);
8
+
9
+ const localeModules = import.meta.glob('../category/i18n/*.ts', { eager: true }) as Record<
10
+ string,
11
+ { content: CategoryLocaleContent }
12
+ >;
13
+
14
+ function textFrom(value: unknown): string {
15
+ if (typeof value === 'string') return value.replace(/<[^>]*>/g, ' ');
16
+ if (Array.isArray(value)) return value.map(textFrom).join(' ');
17
+ if (value && typeof value === 'object') return Object.values(value).map(textFrom).join(' ');
18
+ return '';
19
+ }
20
+
21
+ const STRONG_CLAIM = /\b(?:garantiz\w*|guarante\w*|validat(?:ed)|valid(?:ated|ado|ada|ados|adas|ée|ées)|actualizad\w*)\b/iu;
22
+
23
+ function getContents(): Map<string, CategoryLocaleContent> {
24
+ return new Map(
25
+ Object.entries(localeModules).map(([file, module]) => [file.match(/\/([a-z]{2})\.ts$/u)?.[1] ?? file, module.content]),
26
+ );
27
+ }
28
+
29
+ function validateContent(locale: string, content: CategoryLocaleContent): string[] {
30
+ const failures: string[] = [];
31
+ const check = (condition: boolean, message: string) => { if (!condition) failures.push(`${locale}: ${message}`); };
32
+ const minimumTitleLength = COMPACT_LOCALES.has(locale) ? 4 : 12;
33
+ const minimumDescriptionLength = COMPACT_LOCALES.has(locale) ? 20 : 60;
34
+ check(content.title.trim().length >= minimumTitleLength && content.title.trim().length <= 70, 'title must use a useful 4/12–70 character length');
35
+ check(content.description.trim().length >= minimumDescriptionLength && content.description.trim().length <= 180, 'description must use a useful 20/60–180 character length');
36
+ check(content.seo.length >= 2, 'SEO needs at least two sections');
37
+ check(content.seo.some((section) => section.type === 'paragraph'), 'SEO needs visible explanatory copy');
38
+
39
+ const seoText = textFrom(content.seo).replace(/\s+/g, ' ').trim();
40
+ const minimumSeoLength = COMPACT_LOCALES.has(locale) ? 120 : 240;
41
+ check(seoText.length >= minimumSeoLength, 'SEO copy must contain the minimum visible copy for its script');
42
+ check(content.seo.filter((section) => section.type === 'title').length >= 1, 'SEO needs a section heading');
43
+ check(!/[�]/u.test(seoText), 'SEO contains replacement characters');
44
+ check(!/ {2,}/u.test(seoText), 'SEO contains duplicated whitespace');
45
+ check(!STRONG_CLAIM.test(seoText), 'SEO contains an unsupported strong claim');
46
+
47
+ check(content.slug.trim().length > 0 && /^[a-z0-9-]+$/u.test(content.slug), 'slug must be a non-empty URL-safe value');
48
+ if (ENGLISH_SLUG_LOCALES.has(locale)) {
49
+ check(content.slug === EXPECTED_CATEGORY_SLUG, `slug must use the English category slug "${EXPECTED_CATEGORY_SLUG}"`);
50
+ } else {
51
+ check(content.slug !== EXPECTED_CATEGORY_SLUG, 'slug must be translated for this locale');
52
+ }
53
+ return failures;
54
+ }
55
+
56
+ describe('Category SEO quality contract', () => {
57
+ it('has one content file for every configured locale', () => {
58
+ const contents = getContents();
59
+ expect([...contents.keys()].sort()).toEqual([...EXPECTED_LOCALES].sort());
60
+ });
61
+
62
+ it('keeps metadata, SEO structure and copy quality above the minimum in every locale', () => {
63
+ const contents = getContents();
64
+ const english = contents.get('en');
65
+ expect(english, 'English category content is required as the structural reference').toBeDefined();
66
+
67
+ const failures = EXPECTED_LOCALES.flatMap((locale) => {
68
+ const content = contents.get(locale);
69
+ return content ? validateContent(locale, content) : [];
70
+ });
71
+
72
+ for (const locale of EXPECTED_LOCALES) {
73
+ const content = contents.get(locale);
74
+ if (!content) failures.push(`${locale}: category content is missing`);
75
+ }
76
+
77
+ expect(failures, 'category SEO quality failures').toEqual([]);
78
+ }, 30000);
79
+ });
@@ -0,0 +1,118 @@
1
+ import { describe, expect, it } from 'vitest';
2
+ import { ALL_TOOLS } from '../tools';
3
+
4
+ type LocaleWithDiacritics = keyof typeof DIACRITIC_RULES;
5
+
6
+ const DIACRITIC_RULES = {
7
+ de: {
8
+ language: 'German',
9
+ expectedCharacters: 'ä ö ü ß',
10
+ characters: /[äöüÄÖÜß]/g,
11
+ minPerThousandLetters: 0.1,
12
+ },
13
+ es: {
14
+ language: 'Spanish',
15
+ expectedCharacters: 'á é í ó ú ü ñ',
16
+ characters: /[áéíóúüñÁÉÍÓÚÜÑ]/g,
17
+ minPerThousandLetters: 0.1,
18
+ },
19
+ fr: {
20
+ language: 'French',
21
+ expectedCharacters: 'à â æ ç é è ê ë î ï ô œ ù û ü ÿ',
22
+ characters: /[àâæçéèêëîïôœùûüÿÀÂÆÇÉÈÊËÎÏÔŒÙÛÜŸ]/g,
23
+ minPerThousandLetters: 0.1,
24
+ },
25
+ it: {
26
+ language: 'Italian',
27
+ expectedCharacters: 'à è é ì í î ò ó ù ú',
28
+ characters: /[àèéìíîòóùúÀÈÉÌÍÎÒÓÙÚ]/g,
29
+ minPerThousandLetters: 0.1,
30
+ },
31
+ pl: {
32
+ language: 'Polish',
33
+ expectedCharacters: 'ą ć ę ł ń ó ś ź ż',
34
+ characters: /[ąćęłńóśźżĄĆĘŁŃÓŚŹŻ]/g,
35
+ minPerThousandLetters: 0.1,
36
+ },
37
+ pt: {
38
+ language: 'Portuguese',
39
+ expectedCharacters: 'á â ã à ç é ê í ó ô õ ú ü',
40
+ characters: /[áâãàçéêíóôõúüÁÂÃÀÇÉÊÍÓÔÕÚÜ]/g,
41
+ minPerThousandLetters: 0.1,
42
+ },
43
+ sv: {
44
+ language: 'Swedish',
45
+ expectedCharacters: 'å ä ö',
46
+ characters: /[åäöÅÄÖ]/g,
47
+ minPerThousandLetters: 0.1,
48
+ },
49
+ tr: {
50
+ language: 'Turkish',
51
+ expectedCharacters: 'ç ğ ı İ ö ş ü',
52
+ characters: /[çğıöşüÇĞİÖŞÜ]/g,
53
+ minPerThousandLetters: 0.1,
54
+ },
55
+ } as const;
56
+
57
+ const LETTERS = /\p{L}/gu;
58
+ const TRANSLATABLE_KEYS = ['title', 'description', 'ui', 'seo', 'faq', 'howTo'] as const;
59
+
60
+ function collectStrings(value: unknown): string[] {
61
+ if (typeof value === 'string') return [value];
62
+ if (!value || typeof value !== 'object') return [];
63
+ if (Array.isArray(value)) return value.flatMap(collectStrings);
64
+ return Object.values(value).flatMap(collectStrings);
65
+ }
66
+
67
+ function normalizeText(value: unknown): string {
68
+ return collectStrings(value).join(' ').normalize('NFC');
69
+ }
70
+
71
+ function translatableContent(content: Record<string, unknown>) {
72
+ return TRANSLATABLE_KEYS.map((key) => content[key]);
73
+ }
74
+
75
+ function letterCount(text: string): number {
76
+ return text.match(LETTERS)?.length ?? 0;
77
+ }
78
+
79
+ function diacriticCount(text: string, locale: LocaleWithDiacritics): number {
80
+ return text.match(DIACRITIC_RULES[locale].characters)?.length ?? 0;
81
+ }
82
+
83
+ function diacriticsPerThousandLetters(text: string, locale: LocaleWithDiacritics): number {
84
+ const letters = letterCount(text);
85
+ if (letters === 0) return 0;
86
+ return diacriticCount(text, locale) / letters * 1000;
87
+ }
88
+
89
+ describe('Diacritics density validation', () => {
90
+ ALL_TOOLS.forEach((tool) => {
91
+ describe(`Tool: ${tool.entry.id}`, () => {
92
+ Object.keys(DIACRITIC_RULES).forEach((locale) => {
93
+ it(`${locale} keeps the expected accent and special-letter set`, async () => {
94
+ const typedLocale = locale as LocaleWithDiacritics;
95
+ const loader = tool.entry.i18n[typedLocale];
96
+ if (!loader) return;
97
+
98
+ const content = await loader();
99
+ const text = normalizeText(translatableContent(content as unknown as Record<string, unknown>));
100
+ const rule = DIACRITIC_RULES[typedLocale];
101
+ const letters = letterCount(text);
102
+ const matches = diacriticCount(text, typedLocale);
103
+ const density = diacriticsPerThousandLetters(text, typedLocale);
104
+
105
+ expect(
106
+ density,
107
+ [
108
+ `Possible spelling or encoding issue detected in ${tool.entry.id}/${typedLocale} (${rule.language}).`,
109
+ `The text has ${matches} special characters (${density.toFixed(2)} per 1000 letters, ${letters} letters analyzed).`,
110
+ `This locale should include some of these characters: ${rule.expectedCharacters}.`,
111
+ 'If the count is 0 or near 0, accents, tildes, or special letters were probably stripped by encoding or normalization.',
112
+ ].join(' '),
113
+ ).toBeGreaterThanOrEqual(rule.minPerThousandLetters);
114
+ });
115
+ });
116
+ });
117
+ });
118
+ });
@@ -0,0 +1,18 @@
1
+ import { describe, it, expect } from 'vitest';
2
+ import type * as DATA from '../data';
3
+
4
+ const TOOLS: typeof DATA.civicCategory[] = [];
5
+
6
+ describe('FAQ Content Validation', () => {
7
+ TOOLS.forEach((entry) => {
8
+ describe(`Tool: ${entry.icon}`, () => {
9
+ it('placeholder', () => {
10
+ expect(true).toBe(true);
11
+ });
12
+ });
13
+ });
14
+
15
+ it('no tools registered yet', () => {
16
+ expect(TOOLS.length).toBe(0);
17
+ });
18
+ });
@@ -0,0 +1,34 @@
1
+ import { describe, it, expect } from 'vitest';
2
+ import { ALL_TOOLS } from '../tools';
3
+
4
+ const EXPECTED_LOCALES = ['de', 'en', 'es', 'fr', 'id', 'it', 'ja', 'ko', 'nl', 'pl', 'pt', 'ru', 'sv', 'tr', 'zh'];
5
+
6
+ describe('I18n Coverage Validation', () => {
7
+ it('all tools should be registered', () => {
8
+ expect(ALL_TOOLS.length).toBeGreaterThan(0);
9
+ });
10
+
11
+ ALL_TOOLS.forEach(({ entry }: { entry: any }) => {
12
+ describe(`Tool: ${entry.id}`, () => {
13
+ it('should have all 15 required locales', () => {
14
+ const registeredLocales = Object.keys(entry.i18n);
15
+ EXPECTED_LOCALES.forEach((locale) => {
16
+ expect(
17
+ registeredLocales,
18
+ `Tool "${entry.id}" is missing locale "${locale}"`,
19
+ ).toContain(locale);
20
+ });
21
+ });
22
+
23
+ it('all locale loaders should be functions', () => {
24
+ EXPECTED_LOCALES.forEach((locale) => {
25
+ const loader = entry.i18n[locale as keyof typeof entry.i18n];
26
+ expect(
27
+ typeof loader,
28
+ `Tool "${entry.id}" locale "${locale}" loader is not a function`,
29
+ ).toBe('function');
30
+ });
31
+ });
32
+ });
33
+ });
34
+ });
@@ -0,0 +1,84 @@
1
+ import { describe, expect, it } from 'vitest';
2
+ import { ALL_TOOLS } from '../tools';
3
+
4
+ const INVERTED_PUNCTUATION_LOCALES = {
5
+ es: {
6
+ language: 'Spanish',
7
+ questionStart: '¿',
8
+ questionEnd: '?',
9
+ exclamationStart: '¡',
10
+ exclamationEnd: '!',
11
+ },
12
+ } as const;
13
+
14
+ type InvertedPunctuationLocale = keyof typeof INVERTED_PUNCTUATION_LOCALES;
15
+
16
+ const TRANSLATABLE_KEYS = ['title', 'description', 'ui', 'seo', 'faq', 'howTo'] as const;
17
+
18
+ function collectStrings(value: unknown): string[] {
19
+ if (typeof value === 'string') return [value];
20
+ if (!value || typeof value !== 'object') return [];
21
+ if (Array.isArray(value)) return value.flatMap(collectStrings);
22
+ return Object.values(value).flatMap(collectStrings);
23
+ }
24
+
25
+ function translatableStrings(content: Record<string, unknown>): string[] {
26
+ return TRANSLATABLE_KEYS.flatMap((key) => collectStrings(content[key]));
27
+ }
28
+
29
+ function sentenceStart(text: string, endIndex: number): string {
30
+ const beforeMark = text.slice(0, endIndex).trimEnd();
31
+ const boundary = Math.max(
32
+ beforeMark.lastIndexOf('.'),
33
+ beforeMark.lastIndexOf(':'),
34
+ beforeMark.lastIndexOf(';'),
35
+ beforeMark.lastIndexOf('\n'),
36
+ );
37
+
38
+ return beforeMark.slice(boundary + 1).trimStart();
39
+ }
40
+
41
+ function findMissingInvertedMarks(
42
+ text: string,
43
+ startMark: string,
44
+ endMark: string,
45
+ ): string[] {
46
+ return [...text.matchAll(new RegExp(`\\${endMark}`, 'g'))]
47
+ .map((match) => sentenceStart(text, match.index ?? 0))
48
+ .filter((segment) => segment.length > 0 && !segment.includes(startMark))
49
+ .map((segment) => `${segment}${endMark}`);
50
+ }
51
+
52
+ describe('Inverted punctuation validation', () => {
53
+ ALL_TOOLS.forEach((tool) => {
54
+ describe(`Tool: ${tool.entry.id}`, () => {
55
+ Object.keys(INVERTED_PUNCTUATION_LOCALES).forEach((locale) => {
56
+ it(`${locale} uses opening punctuation marks for questions and exclamations`, async () => {
57
+ const typedLocale = locale as InvertedPunctuationLocale;
58
+ const loader = tool.entry.i18n[typedLocale];
59
+ if (!loader) return;
60
+
61
+ const rule = INVERTED_PUNCTUATION_LOCALES[typedLocale];
62
+ const content = await loader();
63
+ const strings = translatableStrings(content as unknown as Record<string, unknown>);
64
+ const missingQuestions = strings.flatMap((text) =>
65
+ findMissingInvertedMarks(text, rule.questionStart, rule.questionEnd)
66
+ );
67
+ const missingExclamations = strings.flatMap((text) =>
68
+ findMissingInvertedMarks(text, rule.exclamationStart, rule.exclamationEnd)
69
+ );
70
+ const failures = [...missingQuestions, ...missingExclamations];
71
+
72
+ expect(
73
+ failures,
74
+ [
75
+ `Missing opening punctuation marks in ${tool.entry.id}/${typedLocale} (${rule.language}).`,
76
+ `Questions must use ${rule.questionStart}...${rule.questionEnd} and exclamations must use ${rule.exclamationStart}...${rule.exclamationEnd}.`,
77
+ `Examples: ${failures.slice(0, 5).join(' | ')}`,
78
+ ].join(' '),
79
+ ).toHaveLength(0);
80
+ });
81
+ });
82
+ });
83
+ });
84
+ });
@@ -0,0 +1,23 @@
1
+ import { describe, it, expect } from 'vitest';
2
+ import { ALL_TOOLS } from '../tools';
3
+ import type { ToolLocaleContent } from '../types';
4
+
5
+ describe('Locale Completeness Validation', () => {
6
+ ALL_TOOLS.forEach((tool) => {
7
+ describe(`Tool: ${tool.entry.id}`, () => {
8
+ Object.keys(tool.entry.i18n).forEach((locale) => {
9
+ describe(`Locale: ${locale}`, () => {
10
+ it('bibliography should be defined when faq items exist', async () => {
11
+ const loader = tool.entry.i18n[locale as keyof typeof tool.entry.i18n];
12
+ const content = (await loader?.()) as ToolLocaleContent;
13
+ expect(content.bibliography, `Tool "${tool.entry.id}" locale "${locale}" is missing bibliography`).toBeDefined();
14
+ });
15
+ });
16
+ });
17
+ });
18
+ });
19
+
20
+ it('all tools registered', () => {
21
+ expect(ALL_TOOLS.length).toBe(1);
22
+ });
23
+ });
@@ -0,0 +1,2 @@
1
+ export default function () { return null; }
2
+