文件
chen 301194963b
一些检查失败了
automerge / automerge (push) Has been cancelled
react-native-android-build-apk / AssembleRelease (push) Has been cancelled
Build macOS M1 / Main (push) Has been cancelled
Joplin Continuous Integration / Main (macos-15-intel) (push) Has been cancelled
Joplin Continuous Integration / Main (ubuntu-22.04) (push) Has been cancelled
Joplin Continuous Integration / Main (ubuntu-22.04-arm) (push) Has been cancelled
Joplin Continuous Integration / Main (windows-11-vs2026-arm) (push) Has been cancelled
Joplin Continuous Integration / Main (windows-2025) (push) Has been cancelled
Joplin Continuous Integration / ServerDockerImage (ubuntu-22.04) (push) Has been cancelled
Joplin Continuous Integration / ServerDockerImage (ubuntu-22.04-arm) (push) Has been cancelled
Joplin UI tests / Main (ubuntu-22.04) (push) Has been cancelled
Joplin UI tests / Main (windows-2025) (push) Has been cancelled
Joplin UI tests / Mobile (push) Has been cancelled
Close stale issues / ProcessStaleIssues (push) Has been cancelled
feat: Initial clean release of CHM
2026-11-04 11:29:39 +08:00

56 行
2.0 KiB
TypeScript

import createTestEditor from '../../testing/createTestEditor';
import { EditorSelection } from '@codemirror/state';
import replaceLinks from './replaceLinks';
import visibleEditorText from '../../testing/visibleEditorText';
describe('replaceLinks', () => {
it.each([
{
label: 'should not hide link Markdown when the label is empty',
markup: 'test: [](https://example.com)',
expectedText: 'test: [](https://example.com)',
expectedSyntaxTags: ['URL', 'LinkMark', 'Link'],
},
{
label: 'should not hide whitespace-only links',
markup: 'test: [ ](https://example.com)',
expectedText: 'test: [ ](https://example.com)',
expectedSyntaxTags: ['URL', 'LinkMark', 'Link'],
},
{
label: 'should hide link Markdown when a title is present',
markup: 'test: [test](https://example.com)',
expectedText: 'test: test',
expectedSyntaxTags: ['URL', 'LinkMark', 'Link'],
},
{
label: 'should not hide URLs with no label section',
markup: 'test: https://example.com',
expectedText: 'test: https://example.com',
expectedSyntaxTags: ['URL'],
},
])('$label', async ({ markup, expectedText, expectedSyntaxTags }) => {
const editor = await createTestEditor(markup, EditorSelection.cursor(0), expectedSyntaxTags, [replaceLinks]);
expect(visibleEditorText(editor)).toBe(expectedText);
});
it('should not move cursor when URL is already visible', async () => {
const markup = '[test](https://example.com/)';
const initialCursor = markup.indexOf('test');
const clickedCursor = markup.indexOf('example');
const editor = await createTestEditor(markup, EditorSelection.cursor(initialCursor), ['URL', 'LinkMark', 'Link'], [replaceLinks]);
expect(editor.contentDOM.textContent).toBe(markup);
editor.contentDOM.dispatchEvent(new MouseEvent('mousedown', { button: 0, bubbles: true }));
editor.dispatch({ selection: EditorSelection.cursor(clickedCursor) });
editor.contentDOM.ownerDocument.dispatchEvent(new MouseEvent('mouseup', { button: 0 }));
expect(editor.state.selection.main.anchor).toBe(clickedCursor);
});
});