import test from 'node:test'; import assert from 'node:assert/strict'; import { readFileSync } from 'node:fs'; import { dirname, resolve } from 'node:path'; import { fileURLToPath } from 'node:url'; import { preventPagePinchZoom } from '../js/services/pwa-viewport-gestures.js'; const ui = resolve(dirname(fileURLToPath(import.meta.url)), '..'); const source = (path) => readFileSync(resolve(ui, path), 'utf8'); test('PWA запрещает масштабирование, сохраняя прокрутку содержимого', () => { const html = source('index.html'); assert.match(html, /initial-scale=1, maximum-scale=1, user-scalable=no/); const shell = source('styles/app-shell.css'); assert.match(shell, /\.screen-content\s*\{[^}]*overflow-y:\s*auto/s); assert.match(shell, /\.screen-content\s*\{[^}]*overflow-x:\s*hidden/s); assert.match(source('styles/main.css'), /touch-action:\s*pan-x pan-y/); }); test('pinch-zoom блокируется, но одно касание не блокируется', () => { const handlers = new Map(); const target = { addEventListener(name, callback, options) { handlers.set(name, { callback, options }); } }; preventPagePinchZoom(target); for (const name of ['gesturestart', 'gesturechange', 'touchmove']) { assert.equal(handlers.get(name).options.passive, false); } let prevented = 0; const event = (count) => ({ touches: Array(count).fill({}), cancelable: true, preventDefault() { prevented++; } }); handlers.get('touchmove').callback(event(1)); assert.equal(prevented, 0); handlers.get('touchmove').callback(event(2)); assert.equal(prevented, 1); handlers.get('gesturestart').callback(event(2)); handlers.get('gesturechange').callback(event(2)); assert.equal(prevented, 3); }); test('единый просмотр аватара подключён к обоим профилям и закрывается при cleanup', () => { for (const page of ['profile-view.js', 'user-profile-view.js']) { const js = source(`js/pages/${page}`); assert.match(js, /attachProfileAvatarPreview\(body\.querySelector\('\.user-profile-avatar-slot'\), card\)/); assert.match(js, /avatarPreview\?\.cleanup\(\)/); } const viewer = source('js/components/profile-avatar-preview.js'); assert.match(viewer, /largeButton\.append\(avatar\)/); assert.match(viewer, /trigger\.append\(avatar\)/); assert.match(viewer, /event\.key === 'Escape'/); assert.match(viewer, /window\.addEventListener\('popstate', onPopState\)/); });