import test from 'node:test'; import assert from 'node:assert/strict'; import { readFileSync } from 'node:fs'; import { fileURLToPath } from 'node:url'; import { dirname, resolve } from 'node:path'; import { makeSharedProfileRoute, makeProfileRoute, makeShineChannelRoute, makeShineChannelShortRoute, makeShineChannelStreamRoute, makeShineMessageRoute, } from '../js/services/shine-routes.js'; import { profileCardHtml } from '../js/components/profile-card.js'; const ui = resolve(dirname(fileURLToPath(import.meta.url)), '..'); const source = (name) => readFileSync(resolve(ui, name), 'utf8'); test('публичная ссылка профиля содержит /SHiNE/Prof/', () => { assert.equal(makeSharedProfileRoute('alice@free'), 'SHiNE/Prof/alice@free'); assert.equal(makeSharedProfileRoute('Пользователь'), 'SHiNE/Prof/%D0%9F%D0%BE%D0%BB%D1%8C%D0%B7%D0%BE%D0%B2%D0%B0%D1%82%D0%B5%D0%BB%D1%8C'); assert.equal(makeProfileRoute('alice@free'), 'SHiNE/alice@free'); }); test('открытые ссылки профиля, канала и сообщения показывают @, а не %40', () => { assert.equal(makeSharedProfileRoute('@innaa@free'), 'SHiNE/Prof/innaa@free'); assert.equal(makeProfileRoute('innaa@free'), 'SHiNE/innaa@free'); assert.equal(makeShineChannelShortRoute({ ownerLogin: 'innaa@free', channelName: 'news' }), 'SHiNE/innaa@free/news'); assert.equal(makeShineChannelStreamRoute({ ownerLogin: 'innaa@free', channelName: 'news', messageOrdinal: 19 }), 'SHiNE/innaa@free/news/s/19'); assert.equal(makeShineChannelRoute({ ownerBlockchainName: 'innaa@free-002', channelName: 'news' }), 'SHiNE/innaa@free-002/news'); assert.equal(makeShineMessageRoute({ ownerLogin: 'innaa@free', messageBlockchainName: 'innaa@free-002', messageBlockNumber: 25, messageOrdinal: 3, channelName: 'news' }), 'SHiNE/innaa@free/news/3'); assert.equal(makeShineMessageRoute({ messageBlockchainName: 'innaa@free-002', messageBlockNumber: 25 }), 'SHiNE/innaa@free-002/25'); // Без потери безопасности: пробел, слэш и Unicode в пути по-прежнему кодируются. assert.equal(makeShineChannelShortRoute({ ownerLogin: 'innaa@free', channelName: 'мои новости/2026' }), 'SHiNE/innaa@free/%D0%BC%D0%BE%D0%B8%20%D0%BD%D0%BE%D0%B2%D0%BE%D1%81%D1%82%D0%B8%2F2026'); const url = new URL('https://t2.shineup.me'); url.pathname = `/${makeSharedProfileRoute('innaa@free')}`; assert.equal(url.toString(), 'https://t2.shineup.me/SHiNE/Prof/innaa@free'); }); test('отображение профиля не добавляет вторую собачку перед логином', () => { for (const value of ['innaa@free', '@innaa@free']) { const html = profileCardHtml({ card: { login: value }, isSelf: false }); assert.match(html, /
innaa@free<\/div>/); assert.doesNotMatch(html, /@innaa@free/); } const shareSource = source('js/pages/profile-view.js'); assert.doesNotMatch(shareSource, /kicker: name \?[^\n]*· @\$\{login\}/); }); test('при навигации старые вручную закодированные SHiNE-пути становятся читаемыми', async () => { const previousWindow = globalThis.window; globalThis.window = { location: { pathname: '/' } }; try { const { toPrettyPath } = await import('../js/router.js'); assert.equal(toPrettyPath('SHiNE/innaa%40free/news/3'), 'SHiNE/innaa@free/news/3'); assert.equal(toPrettyPath('SHiNE/Prof/innaa%40free'), 'SHiNE/Prof/innaa@free'); assert.equal(toPrettyPath('chat/innaa%40free'), 'chat/innaa%40free'); } finally { globalThis.window = previousWindow; } }); test('новые и старые ссылки профиля ведут на пользователя, не на канал', async () => { const previousWindow = globalThis.window; globalThis.window = { location: { pathname: '/' } }; try { const { parseRouteFromPath } = await import('../js/router.js'); for (const route of ['/SHiNE/Prof/alice@free', '/SHiNE/Prof/alice%40free', '/shine/prof/alice%40free', '/SHiNE/alice@free', '/SHiNE/alice%40free']) { const page = parseRouteFromPath(route); assert.equal(page.pageId, 'user'); assert.equal(page.params.login, 'alice@free'); } for (const path of ['/SHiNE/alice@free/news', '/SHiNE/alice%40free/news']) { const channel = parseRouteFromPath(path); assert.equal(channel.pageId, 'channel-view'); assert.equal(channel.params.channelName, 'news'); } for (const path of ['/SHiNE/alice@free/news/3', '/SHiNE/alice%40free/news/3']) { const thread = parseRouteFromPath(path); assert.equal(thread.pageId, 'channel-thread-view'); assert.equal(thread.params.messageOrdinal, '3'); } } finally { globalThis.window = previousWindow; } }); test('лента получает логин владельца и может запросить фото канала', () => { const js = source('js/pages/channel-view.js'); assert.match(js, /name: payload\.channel\?\.channelName[^\n]*\n\s+ownerLogin,/); assert.match(js, /authorLogin: String\(channel\?\.ownerLogin \|\| channel\?\.ownerName/); assert.match(js, /hasEventAvatar \? event\?\.avaSha256 : fallbackChannel\?\.avaSha256/); assert.doesNotMatch(js, /Аватар<\/span>.*Установлен/); assert.match(js, /class="channel-meta-avatar-slot"/); }); test('аватары каналов в списке, карточках, обсуждениях и шапке круглые', () => { const files = [ ['styles/features/channel.css', ['.channel-profile-avatar', '.channel-about-avatar.avatar']], ['styles/features/channels-common.css', ['.topbar-identity .avatar.channel-profile-avatar', '.channel-message-card--threads .avatar.channel-profile-avatar']], ['styles/features/channel-thread.css', ['.thread-comment--ancestor .avatar.channel-profile-avatar']], ]; for (const [file, selectors] of files) { const css = source(file); for (const selector of selectors) { const declaration = css.slice(css.indexOf(selector) + selector.length).match(/^\s*\{([^}]+)\}/); assert.ok(declaration, `${file} ${selector}`); assert.match(declaration[1], /border-radius:\s*50%\s*;/, `${file} ${selector}`); } } const channelsListCss = source('styles/features/channels-list.css'); assert.match(channelsListCss, /\.channels-screen--list \.channel-row \.avatar\s*\{[^}]*border-radius:\s*50%;/s); });