mirror of
https://github.com/pulsar-edit/pulsar.git
synced 2024-11-10 10:17:11 +03:00
78e61c3ff9
It’s incompatible with returning a disposable because there’s no way to distinguish multiple tooltips added to the body with different selectors. Maybe someday.
73 lines
2.7 KiB
CoffeeScript
73 lines
2.7 KiB
CoffeeScript
TooltipManager = require '../src/tooltip-manager'
|
|
{$} = require '../src/space-pen-extensions'
|
|
|
|
describe "TooltipManager", ->
|
|
[manager, element] = []
|
|
|
|
beforeEach ->
|
|
manager = new TooltipManager
|
|
element = document.createElement('div')
|
|
element.classList.add('foo')
|
|
jasmine.attachToDOM(element)
|
|
|
|
hover = (element, fn) ->
|
|
$(element).trigger 'mouseenter'
|
|
advanceClock(manager.defaults.delay.show)
|
|
fn()
|
|
$(element).trigger 'mouseleave'
|
|
advanceClock(manager.defaults.delay.hide)
|
|
|
|
describe "::add(target, options)", ->
|
|
describe "when the target is an element", ->
|
|
it "creates a tooltip based on the given options when hovering over the target element", ->
|
|
manager.add element, title: "Title"
|
|
hover element, ->
|
|
expect(document.body.querySelector(".tooltip")).toHaveText("Title")
|
|
|
|
describe "when a keyBindingCommand is specified", ->
|
|
describe "when a title is specified", ->
|
|
it "appends the key binding corresponding to the command to the title", ->
|
|
atom.keymaps.add 'test',
|
|
'.foo': 'ctrl-x ctrl-y': 'test-command'
|
|
'.bar': 'ctrl-x ctrl-z': 'test-command'
|
|
|
|
manager.add element, title: "Title", keyBindingCommand: 'test-command'
|
|
|
|
hover element, ->
|
|
tooltipElement = document.body.querySelector(".tooltip")
|
|
expect(tooltipElement).toHaveText "Title ⌃X ⌃Y"
|
|
|
|
describe "when no title is specified", ->
|
|
it "shows the key binding corresponding to the command alone", ->
|
|
atom.keymaps.add 'test', '.foo': 'ctrl-x ctrl-y': 'test-command'
|
|
|
|
manager.add element, keyBindingCommand: 'test-command'
|
|
|
|
hover element, ->
|
|
tooltipElement = document.body.querySelector(".tooltip")
|
|
expect(tooltipElement).toHaveText "⌃X ⌃Y"
|
|
|
|
describe "when a keyBindingTarget is specified", ->
|
|
it "looks up the key binding relative to the target", ->
|
|
atom.keymaps.add 'test',
|
|
'.bar': 'ctrl-x ctrl-z': 'test-command'
|
|
'.foo': 'ctrl-x ctrl-y': 'test-command'
|
|
|
|
manager.add element, keyBindingCommand: 'test-command', keyBindingTarget: element
|
|
|
|
hover element, ->
|
|
tooltipElement = document.body.querySelector(".tooltip")
|
|
expect(tooltipElement).toHaveText "⌃X ⌃Y"
|
|
|
|
describe "when .dispose() is called on the returned disposable", ->
|
|
it "no longer displays the tooltip on hover", ->
|
|
disposable = manager.add element, title: "Title"
|
|
|
|
hover element, ->
|
|
expect(document.body.querySelector(".tooltip")).toHaveText("Title")
|
|
|
|
disposable.dispose()
|
|
|
|
hover element, ->
|
|
expect(document.body.querySelector(".tooltip")).toBeNull()
|