一些检查失败了
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
52 行
1.3 KiB
TypeScript
52 行
1.3 KiB
TypeScript
import { TextSelection } from 'prosemirror-state';
|
|
import createTestEditor from '../testing/createTestEditor';
|
|
import joplinEditorApiPlugin from './joplinEditorApiPlugin';
|
|
import linkTooltipPlugin from './linkTooltipPlugin';
|
|
import { EditorView } from 'prosemirror-view';
|
|
|
|
const getTooltip = () => {
|
|
return document.querySelector('.link-tooltip:not(.-hidden)');
|
|
};
|
|
|
|
|
|
let editor: EditorView;
|
|
|
|
describe('linkTooltipPlugin', () => {
|
|
beforeEach(() => {
|
|
editor = createTestEditor({
|
|
parent: document.body,
|
|
html: '<p><a href="#test-heading">Jump to "Test"</a></p><h1>Test heading</h1><p>Done</p>',
|
|
plugins: [
|
|
linkTooltipPlugin,
|
|
joplinEditorApiPlugin,
|
|
],
|
|
});
|
|
});
|
|
|
|
afterEach(() => {
|
|
document.body.replaceChildren();
|
|
});
|
|
|
|
test('should show a link tooltip when the cursor is in a link', () => {
|
|
expect(getTooltip()).toBeFalsy();
|
|
|
|
editor.dispatch(
|
|
editor.state.tr.setSelection(TextSelection.create(editor.state.tr.doc, 3)),
|
|
);
|
|
|
|
expect(getTooltip()).toBeTruthy();
|
|
});
|
|
|
|
test('clicking on a hash link should move the cursor to the corresponding header', () => {
|
|
editor.dispatch(
|
|
editor.state.tr.setSelection(
|
|
TextSelection.create(editor.state.tr.doc, 3),
|
|
),
|
|
);
|
|
|
|
getTooltip().querySelector('button').click();
|
|
|
|
expect(editor.state.selection.$to.parent.textContent).toBe('Test heading');
|
|
});
|
|
});
|