();
const { container } = render(
,
);
const textbox = screen.getByTestId('textbox');
expect(textbox).toHaveValue('const a = 1;');
expect(ref.current).toBe(textbox);
expect(container.querySelector('.w-tc-editor-preview')?.innerHTML).not.toContain('token');
});
it('processHtml uses an empty plugin list by default', () => {
expect(processHtml('ok')).toBe(processHtml('ok', []));
});
it('htmlEncode escapes markup once, including text inside fenced code blocks', () => {
expect(htmlEncode('```tsx\nconst x = "&";\n```')).toBe('```tsx\nconst x = "<div>&";\n```');
});
it('shortcuts uses nativeEvent.code and the default indent width', () => {
const textarea = mountTextarea('a', 0, 0);
const preventDefault = jest.fn();
const stopPropagation = jest.fn();
shortcuts({
code: '',
nativeEvent: { code: 'Tab' },
shiftKey: false,
target: textarea,
preventDefault,
stopPropagation,
} as unknown as React.KeyboardEvent);
expect(textarea.value).toBe(' a');
expect(textarea.selectionStart).toBe(2);
expect(textarea.selectionEnd).toBe(2);
expect(preventDefault).toHaveBeenCalledTimes(1);
expect(stopPropagation).toHaveBeenCalledTimes(1);
textarea.remove();
});
it('SelectionText getSelectedValue accepts an explicit end', () => {
const textarea = mountTextarea('abcdef', 1, 3);
const api = new SelectionText(textarea);
// A finite end takes the true branch, and that branch slices through `start`.
expect(api.getSelectedValue(undefined, 5)).toBe('bcdef');
expect(api.getSelectedValue(1, 4)).toBe('');
expect(api.getSelectedValue(2, Number.NaN)).toBe('c');
textarea.remove();
});
it('SelectionText ignores an empty indent', () => {
const textarea = mountTextarea('a\nb', 0, 3);
const api = new SelectionText(textarea);
expect(api.lineStarInstert('')).toBe(api);
api.lineStarRemove('');
expect(textarea.value).toBe('a\nb');
expect(textarea.selectionStart).toBe(0);
expect(textarea.selectionEnd).toBe(3);
textarea.remove();
});