-
Notifications
You must be signed in to change notification settings - Fork 167
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add tests to HyperLink plugin #1329
Conversation
}); | ||
|
||
it('Removes title attribute if nothing is being hovered', () => { | ||
div.dispatchEvent(new MouseEvent('mouseover')); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
instead of really dispatch an event, we prefer to mock a PluginEvent and call plugin.onPluginEvent() directly since we don't really need to test browser's code, but just test our plugin code only.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Same for the others
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this is handled by mouseover and mouseout events, not onPluginEvent
Should I (<any>plugin).onMouse
and just test them directly?
roosterjs/packages/roosterjs-editor-plugins/lib/plugins/HyperLink/HyperLink.ts
Lines 46 to 66 in 64fd5e5
this.disposer = editor.addDomEventHandler({ | |
mouseover: <DOMEventHandler>this.onMouse, | |
mouseout: <DOMEventHandler>this.onMouse, | |
blur: <DOMEventHandler>this.onBlur, | |
}); | |
} | |
protected onMouse = (e: MouseEvent) => { | |
const a = this.editor?.getElementAtCursor( | |
'a[href]', | |
<Node>e.target | |
) as HTMLAnchorElement | null; | |
const href = a && this.tryGetHref(a); | |
if (href) { | |
this.editor?.setEditorDomAttribute( | |
'title', | |
e.type == 'mouseover' ? this.getTooltipCallback(href, a) : null | |
); | |
} | |
}; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@ianeli1 I think you can mock/spy editor.addDomEventHandler, so that you can easily get the onMouse callback in an elegant way.
}); | ||
|
||
it('Removes title attribute if nothing is being hovered', () => { | ||
div.dispatchEvent(new MouseEvent('mouseover')); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Same for the others
it('Opens the link whenever Ctrl+Click', () => { | ||
const openSpy = spyOn(window, 'open'); | ||
div.appendChild(anchor); | ||
plugin.onPluginEvent({ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this is nice
This test suite covers: