2026-03-12 16:40:48 +08:00
|
|
|
import type { Comment } from '@bitsocialnet/bitsocial-react-hooks';
|
|
|
|
|
import { describe, expect, it } from 'vitest';
|
|
|
|
|
import { getRenderableMobileBacklinks } from '../reply-backlink-utils';
|
|
|
|
|
|
|
|
|
|
const createReply = (overrides: Partial<Comment> = {}) =>
|
|
|
|
|
({
|
|
|
|
|
cid: 'reply-cid',
|
|
|
|
|
parentCid: 'target-cid',
|
2026-04-17 10:48:27 +07:00
|
|
|
communityAddress: 'music.eth',
|
2026-03-12 16:40:48 +08:00
|
|
|
...overrides,
|
|
|
|
|
}) as Comment;
|
|
|
|
|
|
|
|
|
|
describe('getRenderableMobileBacklinks', () => {
|
|
|
|
|
it('does not report mobile reply backlinks until a renderable backlink exists', () => {
|
|
|
|
|
const unpublishedReply = createReply({
|
|
|
|
|
number: undefined,
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
const beforePublish = getRenderableMobileBacklinks({
|
|
|
|
|
cid: 'target-cid',
|
|
|
|
|
parentCid: 'op-cid',
|
|
|
|
|
quotedByMap: new Map([['target-cid', [unpublishedReply]]]),
|
|
|
|
|
directRepliesByParentCid: new Map([['target-cid', [unpublishedReply]]]),
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
expect(beforePublish.directReplyBacklinks).toHaveLength(0);
|
|
|
|
|
expect(beforePublish.quotedReplyBacklinks).toHaveLength(0);
|
|
|
|
|
|
|
|
|
|
const publishedReply = createReply({
|
|
|
|
|
cid: 'published-reply-cid',
|
|
|
|
|
number: 42,
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
const afterPublish = getRenderableMobileBacklinks({
|
|
|
|
|
cid: 'target-cid',
|
|
|
|
|
parentCid: 'op-cid',
|
|
|
|
|
quotedByMap: new Map([['target-cid', [publishedReply]]]),
|
|
|
|
|
directRepliesByParentCid: new Map([['target-cid', [publishedReply]]]),
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
expect(afterPublish.directReplyBacklinks).toEqual([publishedReply]);
|
|
|
|
|
expect(afterPublish.quotedReplyBacklinks).toHaveLength(0);
|
|
|
|
|
});
|
|
|
|
|
});
|