文件
mynode/packages/editor/CodeMirror/editorCommands/jumpToHash.test.ts
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

51 行
1.6 KiB
TypeScript

import { EditorSelection } from '@codemirror/state';
import createTestEditor from '../testing/createTestEditor';
import jumpToHash from './jumpToHash';
describe('jumpToHash', () => {
test.each([
{
doc: 'This is an anchor: <a id="test">Test</a>',
expectedCursorLocation: 'This is an anchor: <a id="test">'.length,
waitForTags: ['HTMLTag'],
},
{
doc: '<div>HTML block: This is an anchor: <a id="test">Test</a></div>',
expectedCursorLocation: '<div>HTML block: This is an anchor: <a id="test">'.length,
waitForTags: ['HTMLBlock'],
},
])('should support jumping to elements with ID set to "test" (case %#)', async ({ doc: docText, expectedCursorLocation, waitForTags }) => {
const editor = await createTestEditor(
docText,
EditorSelection.cursor(1),
waitForTags,
);
expect(jumpToHash(editor, 'test')).toBe(true);
const cursorPosition = editor.state.selection.main.anchor;
expect(
editor.state.sliceDoc(0, cursorPosition),
).toBe(
editor.state.sliceDoc(0, expectedCursorLocation),
);
});
test('should jump to Markdown headers', async () => {
const editor = await createTestEditor(
'Line 1\n## Line 2',
EditorSelection.cursor(0),
['ATXHeading2'],
);
expect(jumpToHash(editor, 'line-2')).toBe(true);
expect(editor.state.selection.main.anchor).toBe(editor.state.doc.length);
});
test('should return false when no link target is found', async () => {
const editor = await createTestEditor(
'Line 1',
EditorSelection.cursor(0),
[],
);
expect(jumpToHash(editor, 'does-not-exist')).toBe(false);
});
});