SHA256
61 lines
3.2 KiB
JavaScript
61 lines
3.2 KiB
JavaScript
import test from 'node:test';
|
|
import assert from 'node:assert/strict';
|
|
import fs from 'node:fs';
|
|
import path from 'node:path';
|
|
import { fileURLToPath } from 'node:url';
|
|
|
|
const ui = path.resolve(path.dirname(fileURLToPath(import.meta.url)), '..');
|
|
const ru = JSON.parse(fs.readFileSync(path.join(ui, 'js/i18n/locales/ru.json'), 'utf8'));
|
|
const source = (name) => fs.readFileSync(path.join(ui, `js/${name}`), 'utf8');
|
|
const key = (name) => name.split('.').reduce((value, part) => value?.[part], ru);
|
|
|
|
test('русский словарь содержит новые блоки аудита диалогов', () => {
|
|
const required = [
|
|
'dialogs.final.consent.remember_public_history',
|
|
'dialogs.final.consent.public_history_warning',
|
|
'dialogs.final.chat.delete_contact_confirm',
|
|
'dialogs.final.chat.delete_protected_confirm',
|
|
'dialogs.final.chat.confirm_clear_history_text',
|
|
'dialogs.final.profile.char_limit',
|
|
'dialogs.remaining.components.share_sheet.markup.skopirovat_ssylku',
|
|
];
|
|
for (const name of required) {
|
|
assert.ok(typeof key(name) === 'string' && key(name).length, name);
|
|
}
|
|
assert.match(key('dialogs.final.chat.delete_contact_confirm'), /\{name\}/);
|
|
});
|
|
|
|
test('окно «Поделиться»: функция t не перекрыта локальной переменной', () => {
|
|
const share = source('components/share-sheet.js');
|
|
assert.match(share, /import \{ t \} from '\.\.\/i18n\/index\.js'/);
|
|
assert.doesNotMatch(share, /\b(?:const|let|var)\s+t\s*=/);
|
|
assert.match(share, /previewText\.textContent\s*=\s*text/);
|
|
assert.match(share, /t\('dialogs\.remaining\.components\.share_sheet\.markup\.skopirovat_ssylku'\)/);
|
|
});
|
|
|
|
test('подпись редактирования канала подставляется, а не показывается как ${t(...)}', () => {
|
|
const channel = source('pages/channel-view.js');
|
|
assert.match(channel, /title="\$\{t\('dialogs\.modals\.channel_view\.label_001'\)\}"/);
|
|
assert.doesNotMatch(channel, /title="\\\$\{t\(/);
|
|
});
|
|
|
|
test('переводы согласий вычисляются при открытии окна, а не при загрузке модуля', () => {
|
|
const consent = source('services/public-history-consent.js');
|
|
const likes = source('components/like-action-sheet.js');
|
|
const profile = source('pages/profile-edit-view.js');
|
|
assert.match(consent, /export function getPublicHistoryRememberLabel\(\)/);
|
|
assert.match(consent, /label:\s*getPublicHistoryRememberLabel\(\)/);
|
|
assert.match(likes, /getPublicHistoryRememberLabel\(\)/);
|
|
assert.doesNotMatch(likes, /PUBLIC_HISTORY_REMEMBER_LABEL/);
|
|
assert.match(profile, /function shiningSteps\(\)/);
|
|
assert.match(profile, /steps:\s*shiningSteps\(\)/);
|
|
assert.doesNotMatch(profile, /const SHINING_STEPS/);
|
|
});
|
|
|
|
test('динамические имена в подтверждениях чата экранируются для HTML', () => {
|
|
const chat = source('pages/chat-view.js');
|
|
assert.equal((chat.match(/function escapeDialogHtml\(/g) || []).length, 1);
|
|
assert.match(chat, /escapeDialogHtml\(t\('dialogs\.final\.chat\.delete_contact_confirm'/);
|
|
assert.match(chat, /escapeDialogHtml\(t\('dialogs\.final\.chat\.delete_protected_confirm'/);
|
|
});
|