项目文件夹

文件
wehub-resource-sync 2771cff92b
CI / lint (push) Failing after 1s
CI / typecheck (push) Failing after 2s
CI / test (push) Failing after 1s
CI / build (push) Has been skipped
chore: import upstream snapshot with attribution
2026-07-13 12:22:56 +08:00

65 行
1.6 KiB
TypeScript

import { registerFileLinkHandler } from '@/utils/fileLink';
describe('registerFileLinkHandler', () => {
it('opens data-href target when present', () => {
const app = {
workspace: {
openLinkText: jest.fn(),
},
};
const link: any = {
dataset: { href: 'note#section' },
getAttribute: jest.fn().mockReturnValue('note'),
closest: jest.fn(),
};
link.closest.mockReturnValue(link);
const event = {
target: link,
preventDefault: jest.fn(),
} as any;
const component = {
registerDomEvent: (_el: HTMLElement, _event: string, cb: (event: MouseEvent) => void) => {
cb(event);
},
};
registerFileLinkHandler(app as any, {} as HTMLElement, component as any);
expect(event.preventDefault).toHaveBeenCalled();
expect(app.workspace.openLinkText).toHaveBeenCalledWith('note#section', '', 'tab');
});
it('falls back to href when data-href is missing', () => {
const app = {
workspace: {
openLinkText: jest.fn(),
},
};
const link: any = {
dataset: {},
getAttribute: jest.fn().mockReturnValue('note^block'),
closest: jest.fn(),
};
link.closest.mockReturnValue(link);
const event = {
target: link,
preventDefault: jest.fn(),
} as any;
const component = {
registerDomEvent: (_el: HTMLElement, _event: string, cb: (event: MouseEvent) => void) => {
cb(event);
},
};
registerFileLinkHandler(app as any, {} as HTMLElement, component as any);
expect(app.workspace.openLinkText).toHaveBeenCalledWith('note^block', '', 'tab');
});
});