69 lines
2.3 KiB
TypeScript
69 lines
2.3 KiB
TypeScript
import { readFileSync } from 'node:fs';
|
|
import path from 'node:path';
|
|
import { describe, it, expect } from 'vitest';
|
|
import { ACTION_KEYS } from '../src/pages/Logs';
|
|
|
|
const LOCALES_DIR = path.join(__dirname, '..', 'src', 'i18n', 'locales');
|
|
|
|
type Json = Record<string, unknown>;
|
|
|
|
function load(locale: string, ns: string): Json {
|
|
return JSON.parse(readFileSync(path.join(LOCALES_DIR, locale, `${ns}.json`), 'utf8')) as Json;
|
|
}
|
|
|
|
function flatKeys(node: Json, prefix = ''): string[] {
|
|
return Object.entries(node).flatMap(([key, value]) => {
|
|
const full = prefix ? `${prefix}.${key}` : key;
|
|
if (value && typeof value === 'object') return flatKeys(value as Json, full);
|
|
return [full];
|
|
});
|
|
}
|
|
|
|
function actionKeys(locale: string): Set<string> {
|
|
return new Set(flatKeys(load(locale, 'logs').actions as Json));
|
|
}
|
|
|
|
describe('logs: pokrycie tłumaczeń akcji audytu', () => {
|
|
it('każda akcja z filtra ma tłumaczenie w pl i en', () => {
|
|
const pl = actionKeys('pl');
|
|
const en = actionKeys('en');
|
|
const missingPl = ACTION_KEYS.filter((a) => !pl.has(a));
|
|
const missingEn = ACTION_KEYS.filter((a) => !en.has(a));
|
|
expect(missingPl).toEqual([]);
|
|
expect(missingEn).toEqual([]);
|
|
});
|
|
|
|
it('klucze akcji planu i konta nie wypadają z tłumaczeń', () => {
|
|
for (const locale of ['pl', 'en']) {
|
|
const keys = actionKeys(locale);
|
|
for (const action of [
|
|
'plan.template.cloned',
|
|
'plan.template.saved',
|
|
'plan.suspended',
|
|
'plan.resumed',
|
|
'plan.gym.updated',
|
|
'plan.day.moved',
|
|
'plan.day.skip.accepted',
|
|
'user.password.changed',
|
|
]) {
|
|
expect(keys.has(action), `${locale}: brak tłumaczenia ${action}`).toBe(true);
|
|
}
|
|
}
|
|
});
|
|
|
|
it('pl i en mają identyczne klucze w namespace logs', () => {
|
|
expect(flatKeys(load('en', 'logs')).sort()).toEqual(flatKeys(load('pl', 'logs')).sort());
|
|
});
|
|
|
|
it('żadne tłumaczenie nie jest puste', () => {
|
|
for (const locale of ['pl', 'en']) {
|
|
const raw = load(locale, 'logs');
|
|
const empty = flatKeys(raw).filter((k) => {
|
|
const value = k.split('.').reduce<unknown>((acc, part) => (acc as Json)[part], raw);
|
|
return typeof value !== 'string' || value.trim() === '';
|
|
});
|
|
expect(empty).toEqual([]);
|
|
}
|
|
});
|
|
});
|