mirror of
https://github.com/bitsocialnet/5chan.git
synced 2026-08-03 07:41:04 +02:00
fix(markdown): handle unavailable reply quote links
This commit is contained in:
@@ -0,0 +1,45 @@
|
||||
import { describe, expect, it } from 'vitest';
|
||||
import { formatQuoteNumber, isUnavailableQuoteTarget, shouldShowFloatingQuotePreview } from '../quote-link-utils';
|
||||
|
||||
describe('quote-link-utils', () => {
|
||||
it('formats quote numbers with the expected prefix', () => {
|
||||
expect(formatQuoteNumber(123)).toBe('>>123');
|
||||
expect(formatQuoteNumber()).toBe('>>?');
|
||||
});
|
||||
|
||||
it('marks deleted and removed comments as unavailable quote targets', () => {
|
||||
expect(isUnavailableQuoteTarget(undefined)).toBe(false);
|
||||
expect(isUnavailableQuoteTarget({ deleted: true, removed: false })).toBe(true);
|
||||
expect(isUnavailableQuoteTarget({ deleted: false, removed: true })).toBe(true);
|
||||
expect(isUnavailableQuoteTarget({ deleted: false, removed: false })).toBe(false);
|
||||
});
|
||||
|
||||
it('only shows floating previews for available targets that are hovered out of view', () => {
|
||||
expect(
|
||||
shouldShowFloatingQuotePreview({
|
||||
hoveredCid: 'cid-1',
|
||||
outOfViewCid: 'cid-1',
|
||||
quoteCid: 'cid-1',
|
||||
isUnavailable: false,
|
||||
}),
|
||||
).toBe(true);
|
||||
|
||||
expect(
|
||||
shouldShowFloatingQuotePreview({
|
||||
hoveredCid: 'cid-1',
|
||||
outOfViewCid: 'cid-1',
|
||||
quoteCid: 'cid-1',
|
||||
isUnavailable: true,
|
||||
}),
|
||||
).toBe(false);
|
||||
|
||||
expect(
|
||||
shouldShowFloatingQuotePreview({
|
||||
hoveredCid: 'cid-1',
|
||||
outOfViewCid: 'cid-2',
|
||||
quoteCid: 'cid-1',
|
||||
isUnavailable: false,
|
||||
}),
|
||||
).toBe(false);
|
||||
});
|
||||
});
|
||||
@@ -0,0 +1,17 @@
|
||||
import type { Comment } from '@bitsocialhq/bitsocial-react-hooks';
|
||||
|
||||
export const formatQuoteNumber = (number?: number) => `>>${number ?? '?'}`;
|
||||
|
||||
export const isUnavailableQuoteTarget = (comment?: Partial<Pick<Comment, 'deleted' | 'removed'>> | null) => Boolean(comment?.deleted || comment?.removed);
|
||||
|
||||
export const shouldShowFloatingQuotePreview = ({
|
||||
hoveredCid,
|
||||
outOfViewCid,
|
||||
quoteCid,
|
||||
isUnavailable,
|
||||
}: {
|
||||
hoveredCid: string | null;
|
||||
outOfViewCid: string | null;
|
||||
quoteCid?: string;
|
||||
isUnavailable?: boolean;
|
||||
}) => Boolean(quoteCid && !isUnavailable && hoveredCid === quoteCid && outOfViewCid === quoteCid);
|
||||
Reference in New Issue
Block a user