mirror of
https://github.com/bitsocialnet/5chan.git
synced 2026-08-03 07:41:04 +02:00
test: expand markdown and post menu coverage
Adds focused regression coverage for quote previews, markdown link rendering, embed toggles, and desktop/mobile post-menu actions. It also fixes the undefined feed-state crash in use-state-string.ts and removes unnecessary runtime imports with import type.
This commit is contained in:
@@ -0,0 +1,44 @@
|
||||
import * as React from 'react';
|
||||
import { createElement } from 'react';
|
||||
import { createRoot, type Root } from 'react-dom/client';
|
||||
import { afterEach, beforeEach, describe, expect, it } from 'vitest';
|
||||
import LoadingEllipsis from '../loading-ellipsis';
|
||||
|
||||
(globalThis as { IS_REACT_ACT_ENVIRONMENT?: boolean }).IS_REACT_ACT_ENVIRONMENT = true;
|
||||
const act = (React as { act?: (cb: () => void | Promise<void>) => void | Promise<void> }).act as (cb: () => void | Promise<void>) => void | Promise<void>;
|
||||
|
||||
let container: HTMLDivElement;
|
||||
let root: Root;
|
||||
|
||||
describe('LoadingEllipsis', () => {
|
||||
beforeEach(() => {
|
||||
container = document.createElement('div');
|
||||
document.body.appendChild(container);
|
||||
root = createRoot(container);
|
||||
});
|
||||
|
||||
afterEach(() => {
|
||||
act(() => root.unmount());
|
||||
container.remove();
|
||||
});
|
||||
|
||||
it('keeps the last word inside the nowrap span and preserves the prefix text', () => {
|
||||
act(() => {
|
||||
root.render(createElement(LoadingEllipsis, { string: 'Downloading board' }));
|
||||
});
|
||||
|
||||
const spans = container.querySelectorAll('span');
|
||||
expect(container.textContent).toBe('Downloading board');
|
||||
expect(spans[1]?.textContent).toBe('board');
|
||||
expect(spans[2]).toBeTruthy();
|
||||
});
|
||||
|
||||
it('renders single-word strings without a leading space', () => {
|
||||
act(() => {
|
||||
root.render(createElement(LoadingEllipsis, { string: 'Loading' }));
|
||||
});
|
||||
|
||||
expect(container.textContent).toBe('Loading');
|
||||
expect(container.firstChild?.textContent).toBe('Loading');
|
||||
});
|
||||
});
|
||||
Reference in New Issue
Block a user