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'/); });