import test from 'node:test'; import assert from 'node:assert/strict'; import { readFileSync } from 'node:fs'; import { supportStatsValues } from '../js/components/support-stats.js'; function file(path) { return readFileSync(new URL(path, import.meta.url), 'utf8'); } test('three displayed counters: sent, received, direct DAO in star cents', () => { assert.deepEqual(supportStatsValues({ supportSent: 1_000_000_000n, supportReceived: 900_000_000n, daoDirect: 200_000_000n }), [1_000_000_000n, 900_000_000n, 200_000_000n]); assert.deepEqual(supportStatsValues({}), [0n, 0n, 0n]); assert.deepEqual(supportStatsValues({ supportSent: '10000000000000000000', supportReceived: '9000000000000000000', daoDirect: '250000000000000000' }), [10000000000000000000n, 9000000000000000000n, 250000000000000000n]); }); test('profile views attach counters from server cache and support user action', () => { assert.match(file('../js/pages/profile-view.js'), /attachSupportStats\(body/); const other = file('../js/pages/user-profile-view.js'); assert.match(other, /attachSupportStats\(body/); assert.match(other, /data-profile-action=\\?"support/); assert.match(other, /openShineSupportDialog\(\{ recipientLogin: card\.login/); }); test('wallet offers SHiNE economy donation through the menu, not the Solana wallet', () => { const wallet = file('../js/pages/wallet-view.js'); const menu = wallet.split('function renderWalletChoice()')[1].split('async function renderShineBlockchainWallet()')[0]; assert.match(menu, /openShineSupportDialog\(\)/); assert.doesNotMatch(wallet, /id="donate-shine"/); }); test('message buttons pass checked block hashes, not message text', () => { for (const page of ['channel-view.js', 'channel-thread-view.js']) { const src = file(`../js/pages/${page}`); assert.match(src, /hexHash32\(rootHash\)/); assert.match(src, /hexHash32\(msgHash\)|hexHash32\(messageHash\)/); assert.match(src, /type: 2/); } }); test('shared modal requires Stars and oracle quote', () => { const src = file('../js/components/shine-support-dialog.js'); assert.match(src, /supportShineUserOnSolana/); assert.match(src, /supportShineDaoOnSolana/); assert.match(src, /starCentsToLamports/); assert.match(src, /getStarsQuoteFromRpc/); assert.match(src, /parseStarCents/); }); test('profile statistics use server API without Solana RPC', () => { const component = file('../js/components/support-stats.js'); const auth = file('../js/services/auth-service.js'); assert.match(component, /authService\.getSupportStats\(login\)/); assert.doesNotMatch(component, /readShineUserPda/); assert.match(component, /if \(!stats\.ready\)/); assert.match(auth, /this\.ws\.request\('GetSupportStats'/); }); test('support card collapses as one block: layers share a cell, only the card drives the height', () => { const css = file('../styles/features/profile-support.css'); const rule = (selector) => { const start = css.indexOf(`\n${selector} {`); assert.notEqual(start, -1, `${selector} rule is missing`); return css.slice(start, css.indexOf('}', start)); }; // Две доли одной сетки (1fr 0fr ↔ 0fr 1fr) всегда дают в сумме высоту карточки: при сворачивании блок // не сжимался, а строка растягивалась на всю его высоту пустым прямоугольником. assert.doesNotMatch(css, /grid-template-rows:\s*(?:1fr\s+0fr|0fr\s+1fr)/); assert.match(rule('.profile-support > *'), /grid-area: 1 \/ 1/); assert.match(rule('.profile-support'), /overflow: hidden/); assert.match(rule('.profile-support'), /align-items: start/); assert.match(rule('.profile-support__panel'), /grid-template-rows: 0fr/); assert.match(rule('.profile-support__panel'), /visibility: hidden/); // Ряд панели — только добавка карточки к строке: иначе сжатие упирается в строку на полном ходу и кончается рывком. assert.match(rule('.profile-support__panel'), /margin-top: var\(--ps-line\)/); assert.match(rule('.profile-support .profile-support-stats'), /margin-top: calc\(-1 \* var\(--ps-line\)\)/); assert.match(rule('.profile-support__summary'), /min-height: var\(--ps-line\)/); assert.match(rule(".profile-support[data-expanded='true'] .profile-support__panel"), /grid-template-rows: 1fr/); assert.match(rule(".profile-support[data-expanded='true'] .profile-support__line"), /visibility: hidden/); // Сияние ждёт конца перехода именно той панели, которая теперь анимируется. assert.match(file('../js/components/support-stats.js'), /panel\.getAnimations/); });