mirror of
https://github.com/bitsocialnet/5chan.git
synced 2026-08-03 07:41:04 +02:00
fix(post): align op permalinks to the outer thread container (#1050)
* fix(post): align op permalinks to the outer thread container * perf(scroll-to-reply): stop interval when max attempts/duration reached
This commit is contained in:
@@ -1,7 +1,7 @@
|
||||
import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest';
|
||||
import { copyToClipboard } from '../clipboard-utils';
|
||||
import { hashStringToColor, getTextColorForBackground, removeMarkdown } from '../post-utils';
|
||||
import { preloadThemeAssets } from '../preload-utils';
|
||||
import { preloadReplyModal, preloadThemeAssets } from '../preload-utils';
|
||||
import { computeOmittedCount, filterRepliesForDisplay, getPreviewDisplayReplies, getTotalReplyCount } from '../replies-preview-utils';
|
||||
import { getQuotedCidsFromContent, mergeQuotedCids } from '../reply-quote-utils';
|
||||
import { formatUserIDForDisplay, truncateWithEllipsisInMiddle } from '../string-utils';
|
||||
@@ -119,6 +119,38 @@ describe('misc utils', () => {
|
||||
expect(loadedSources).toEqual(['/buttons/default.png', '/buttons/hover.png', '/backgrounds/wallpaper.png']);
|
||||
});
|
||||
|
||||
it('schedules reply modal preload with requestIdleCallback when available', () => {
|
||||
const requestIdleCallback = vi.fn();
|
||||
|
||||
Object.defineProperty(window, 'requestIdleCallback', {
|
||||
configurable: true,
|
||||
value: requestIdleCallback,
|
||||
});
|
||||
|
||||
preloadReplyModal();
|
||||
|
||||
expect(requestIdleCallback).toHaveBeenCalledWith(expect.any(Function), { timeout: 1500 });
|
||||
});
|
||||
|
||||
it('falls back to setTimeout for reply modal preload when requestIdleCallback is unavailable', () => {
|
||||
const originalRequestIdleCallback = window.requestIdleCallback;
|
||||
// @ts-expect-error test fallback path
|
||||
delete window.requestIdleCallback;
|
||||
vi.useFakeTimers();
|
||||
const setTimeoutSpy = vi.spyOn(window, 'setTimeout');
|
||||
|
||||
preloadReplyModal();
|
||||
|
||||
expect(setTimeoutSpy).toHaveBeenCalledWith(expect.any(Function), 500);
|
||||
|
||||
if (originalRequestIdleCallback) {
|
||||
Object.defineProperty(window, 'requestIdleCallback', {
|
||||
configurable: true,
|
||||
value: originalRequestIdleCallback,
|
||||
});
|
||||
}
|
||||
});
|
||||
|
||||
it('builds reply previews, omitted counts, and fallback reply totals', () => {
|
||||
expect(filterRepliesForDisplay([{ cid: 'visible' }, { cid: 'deleted', deleted: true }, { cid: 'removed', deleted: false }])).toEqual([
|
||||
{ cid: 'visible' },
|
||||
|
||||
Reference in New Issue
Block a user