import test from 'node:test'; import assert from 'node:assert/strict'; import { readFileSync } from 'node:fs'; const source = (path) => readFileSync(new URL(path, import.meta.url), 'utf8'); const chat = source('../js/pages/chat-view.js'); const css = source('../styles/features/chat.css'); const ru = JSON.parse(source('../js/i18n/locales/ru.json')); const en = JSON.parse(source('../js/i18n/locales/en.json')); for (const [locale, language] of [['ru', ru], ['en', en]]) { test(`в ${locale} есть полный текст предупреждения DM`, () => { const note = language.screens.chat_view.security_notice; for (const key of ['title', 'encryption', 'servers', 'derivation', 'rotation', 'source', 'warning_label', 'warning', 'recovery']) { assert.ok(typeof note[key] === 'string' && note[key].trim(), `${locale}/${key}`); } }); } test('уведомление формируется только локально и добавляется первым элементом ленты', () => { const start = chat.indexOf('function createDmEncryptionNotice()'); const end = chat.indexOf('function renderLog(', start); const functionBody = chat.slice(start, end); assert.ok(start >= 0 && end > start); assert.match(functionBody, /document\.createElement\('aside'\)/); assert.match(functionBody, /dm-security-notice/); assert.match(chat, /list\.innerHTML = '';\s*list\.append\(createDmEncryptionNotice\(\)\);\s*const messages = getChatMessages\(chatId\);/); assert.doesNotMatch(functionBody, /authService|addSignedMessageToChat|sendDirectMessage|AddBlock|fetch\(/); }); test('уведомление имеет собственные серые стили и не оформляется как bubble', () => { assert.match(css, /\.dm-security-notice\s*\{[\s\S]*?color: var\(--text-secondary\)/); assert.doesNotMatch(chat.slice(chat.indexOf('function createDmEncryptionNotice()'), chat.indexOf('function renderLog(')), /className = ['"`]bubble/); });