SHA256
HEADER v3, primary аккаунты и подтверждения
This commit is contained in:
@@ -0,0 +1,29 @@
|
||||
import test from 'node:test';
|
||||
import assert from 'node:assert/strict';
|
||||
import { readFileSync } from 'node:fs';
|
||||
import { publicLikeCount, hasLikeStatistics } from '../js/services/public-like-count.js';
|
||||
|
||||
test('public likes only count declared Primary accounts', () => {
|
||||
const post = { likesCount: 20, primaryLikesCount: 5, shiningLikesCount: 2 };
|
||||
assert.equal(publicLikeCount(post), 5);
|
||||
assert.equal(hasLikeStatistics(post), true);
|
||||
assert.equal(publicLikeCount({ likesCount: 20, primaryLikesCount: 0 }), 0);
|
||||
assert.equal(hasLikeStatistics({ likesCount: 20, primaryLikesCount: 0 }), true);
|
||||
assert.equal(publicLikeCount({ likesCount: 20 }), 0);
|
||||
assert.equal(publicLikeCount({ primaryLikesCount: -1 }), 0);
|
||||
assert.equal(publicLikeCount({ primaryLikesCount: 'invalid' }), 0);
|
||||
assert.equal(hasLikeStatistics({ likesCount: 0, primaryLikesCount: 0 }), false);
|
||||
});
|
||||
|
||||
test('feed and both thread layouts use the public count and keep stats accessible', () => {
|
||||
const src = name => readFileSync(new URL(`../js/pages/${name}`, import.meta.url), 'utf8');
|
||||
const feed = src('channel-view.js');
|
||||
const thread = src('channel-thread-view.js');
|
||||
assert.match(feed, /likesStatsButton\.textContent = String\(publicLikeCount\(post\)\)/);
|
||||
assert.equal((feed.match(/hasLikeStatistics\(post\) \? \[likesStatsButton\]/g) || []).length, 2);
|
||||
assert.equal((thread.match(/const likes = publicLikeCount\(node\);/g) || []).length, 2);
|
||||
assert.match(thread, /commentLikeStats\.textContent = String\(likes\)/);
|
||||
assert.equal((thread.match(/hasLikeStatistics\(node\)/g) || []).length, 3);
|
||||
assert.match(feed, /counts: post/);
|
||||
assert.match(thread, /showLikeStatistics\(\{ counts: node \}\)/);
|
||||
});
|
||||
Reference in New Issue
Block a user