@jjlmoya/utils-babies 1.8.0 → 1.9.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.
package/package.json
CHANGED
package/src/index.ts
CHANGED
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
import { describe, it, expect } from 'vitest';
|
|
2
|
+
import { babiesCategory as toolsCategory } from '../category/index';
|
|
3
|
+
import type { CategoryLocaleContent } from '../types';
|
|
4
|
+
|
|
5
|
+
const EXPECTED_LOCALES = [
|
|
6
|
+
'de', 'en', 'es', 'fr', 'id', 'it', 'ja', 'ko', 'nl', 'pl', 'pt', 'ru', 'sv', 'tr', 'zh'
|
|
7
|
+
];
|
|
8
|
+
|
|
9
|
+
const sharingLocales = ['ja', 'ko', 'zh'];
|
|
10
|
+
const allowedDuplicateSlugs = ['bebes', 'babys'];
|
|
11
|
+
|
|
12
|
+
describe('Category Validation', () => {
|
|
13
|
+
it('should have all 15 required locales', () => {
|
|
14
|
+
const registeredLocales = Object.keys(toolsCategory.i18n);
|
|
15
|
+
EXPECTED_LOCALES.forEach((locale) => {
|
|
16
|
+
expect(
|
|
17
|
+
registeredLocales,
|
|
18
|
+
`Category is missing locale "${locale}"`,
|
|
19
|
+
).toContain(locale);
|
|
20
|
+
});
|
|
21
|
+
});
|
|
22
|
+
|
|
23
|
+
describe('Category Slug Validation', () => {
|
|
24
|
+
async function getEnSlug(locales: string[]): Promise<string> {
|
|
25
|
+
if (!locales.includes('en')) return '';
|
|
26
|
+
const enLoader = toolsCategory.i18n['en' as keyof typeof toolsCategory.i18n];
|
|
27
|
+
const enContent = (await enLoader?.()) as CategoryLocaleContent;
|
|
28
|
+
return enContent.slug;
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
function validateNonEnSlug(locale: string, slug: string, enSlug: string, slugs: Map<string, string>) {
|
|
32
|
+
if (sharingLocales.includes(locale)) {
|
|
33
|
+
expect(slug, `Category locale "${locale}" must use the same slug as "en" ("${enSlug}").`).toBe(enSlug);
|
|
34
|
+
} else {
|
|
35
|
+
expect(slug, `Category locale "${locale}" has the same slug as "en" ("${enSlug}"). Cada slug tiene que estar en su propio idioma`).not.toBe(enSlug);
|
|
36
|
+
if (slugs.has(slug) && !allowedDuplicateSlugs.includes(slug)) {
|
|
37
|
+
expect(false, `Category locales "${locale}" and "${slugs.get(slug)}" share the same slug ("${slug}"). Cada slug tiene que estar en su propia idioma`).toBe(true);
|
|
38
|
+
}
|
|
39
|
+
slugs.set(slug, locale);
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
it('every locale should have a unique, translated slug and follow format rules', async () => {
|
|
44
|
+
const slugs = new Map<string, string>();
|
|
45
|
+
const locales = Object.keys(toolsCategory.i18n);
|
|
46
|
+
const enSlug = await getEnSlug(locales);
|
|
47
|
+
|
|
48
|
+
for (const locale of locales) {
|
|
49
|
+
const loader = toolsCategory.i18n[locale as keyof typeof toolsCategory.i18n];
|
|
50
|
+
const content = (await loader?.()) as CategoryLocaleContent;
|
|
51
|
+
|
|
52
|
+
expect(content.slug, `Category locale "${locale}" has an invalid slug ("${content.slug}"). Slugs must be transliterated (only a-z, 0-9, and -).`).toMatch(/^[a-z0-9-]+$/);
|
|
53
|
+
expect(content.slug, `Category locale "${locale}" slug ("${content.slug}") cannot end with a 2-letter language code (e.g., -ja, -ru, -ko).`).not.toMatch(/-[a-z]{2}$/);
|
|
54
|
+
|
|
55
|
+
if (locale !== 'en') validateNonEnSlug(locale, content.slug, enSlug, slugs);
|
|
56
|
+
}
|
|
57
|
+
});
|
|
58
|
+
});
|
|
59
|
+
});
|
|
@@ -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('Slug Language Code Format Validation', () => {
|
|
6
|
+
ALL_TOOLS.forEach((tool) => {
|
|
7
|
+
describe(`Tool: ${tool.entry.id}`, () => {
|
|
8
|
+
it('slug should not end with 2-letter language codes like -ja, -ru, -ko', async () => {
|
|
9
|
+
const locales = Object.keys(tool.entry.i18n);
|
|
10
|
+
|
|
11
|
+
for (const locale of locales) {
|
|
12
|
+
const loader = tool.entry.i18n[locale as keyof typeof tool.entry.i18n];
|
|
13
|
+
const content = (await loader?.()) as ToolLocaleContent;
|
|
14
|
+
|
|
15
|
+
expect(
|
|
16
|
+
content.slug,
|
|
17
|
+
`Tool "${tool.entry.id}" locale "${locale}" slug ("${content.slug}") cannot end with a 2-letter language code (e.g., -ja, -ru, -ko).`,
|
|
18
|
+
).not.toMatch(/-[a-z]{2}$/);
|
|
19
|
+
}
|
|
20
|
+
});
|
|
21
|
+
});
|
|
22
|
+
});
|
|
23
|
+
});
|