-
Notifications
You must be signed in to change notification settings - Fork 216
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
7 changed files
with
213 additions
and
23 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
100 changes: 100 additions & 0 deletions
100
src/js/test/foreground/view/behavior/tooltipable.spec.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,100 @@ | ||
define(function(require) { | ||
'use strict'; | ||
|
||
var Tooltipable = require('foreground/view/behavior/tooltipable'); | ||
|
||
describe('Tooltipable', function() { | ||
beforeEach(function() { | ||
this.tooltipable = new Tooltipable(); | ||
}); | ||
|
||
it('should hide any tooltips when its view is destroyed', function() { | ||
sinon.stub(this.tooltipable, '_hideTooltip'); | ||
this.tooltipable.onBeforeDestroy(); | ||
expect(this.tooltipable._hideTooltip.calledOnce).to.equal(true); | ||
this.tooltipable._hideTooltip.restore(); | ||
}); | ||
|
||
it('should be able to mark a target as hovered', function() { | ||
sinon.stub(window, 'setTimeout'); | ||
var target = document.createElement('div'); | ||
target.setAttribute('data-tooltip-text', 'hello, world'); | ||
this.tooltipable._setHovered(target); | ||
expect($(target).data('is-hovered')).to.equal(true); | ||
expect(window.setTimeout.calledOnce).to.equal(true); | ||
window.setTimeout.restore(); | ||
}); | ||
|
||
it('should not re-mark an already hovered target', function() { | ||
sinon.stub(window, 'setTimeout'); | ||
var target = document.createElement('div'); | ||
$(target).data('is-hovered', true); | ||
this.tooltipable._setHovered(target); | ||
expect(window.setTimeout.calledOnce).to.equal(false); | ||
window.setTimeout.restore(); | ||
}); | ||
|
||
it('should not mark a target which does not have tooltip text', function() { | ||
sinon.stub(window, 'setTimeout'); | ||
var target = document.createElement('div'); | ||
this.tooltipable._setHovered(target); | ||
expect(window.setTimeout.calledOnce).to.equal(false); | ||
window.setTimeout.restore(); | ||
}); | ||
|
||
it('should not mark a target which does has an empty string for tooltip text', function() { | ||
sinon.stub(window, 'setTimeout'); | ||
var target = document.createElement('div'); | ||
target.setAttribute('data-tooltip-text', ''); | ||
this.tooltipable._setHovered(target); | ||
expect(window.setTimeout.calledOnce).to.equal(false); | ||
window.setTimeout.restore(); | ||
}); | ||
|
||
it('should be able to hide shown tooltips', function() { | ||
this.tooltipable.isShowingTooltip = true; | ||
this.tooltipable.mutationObserver = new MutationObserver(_.noop); | ||
this.tooltipable._hideTooltip(); | ||
expect(this.tooltipable.isShowingTooltip).to.equal(false); | ||
}); | ||
|
||
it('should set a mutation observer when watching a target', function() { | ||
var target = document.createElement('div'); | ||
this.tooltipable._watchTooltipText(target, {}); | ||
expect(this.tooltipable.mutationObserver).not.to.equal(null); | ||
}); | ||
|
||
it('should indicate that a tooltip should not be shown if target is not hovered', function() { | ||
var target = document.createElement('div'); | ||
var showTooltip = this.tooltipable._needShowTooltip(target); | ||
expect(showTooltip).to.equal(false); | ||
}); | ||
|
||
it('should indicate that a tooltip should be shown if target is hovered and does not need an overflow check', function() { | ||
var target = document.createElement('div'); | ||
$(target).data('is-hovered', true); | ||
var showTooltip = this.tooltipable._needShowTooltip(target); | ||
expect(showTooltip).to.equal(true); | ||
}); | ||
|
||
it('should indicate that a tooltip should not be shown if target is hovered and fails an overflow check', function() { | ||
var target = document.createElement('div'); | ||
$(target).data('is-hovered', true); | ||
target.classList.add('js-textTooltipable'); | ||
var showTooltip = this.tooltipable._needShowTooltip(target); | ||
expect(showTooltip).to.equal(false); | ||
}); | ||
|
||
it('should be able to show a tooltip', function() { | ||
sinon.stub(Streamus.channels.tooltip.commands, 'trigger'); | ||
|
||
this.tooltipable._showTooltip({}, ''); | ||
|
||
expect(this.tooltipable.isShowingTooltip).to.equal(true); | ||
expect(Streamus.channels.tooltip.commands.trigger.calledOnce).to.equal(true); | ||
expect(Streamus.channels.tooltip.commands.trigger.calledWithMatch('show:tooltip', {})).to.equal(true); | ||
|
||
Streamus.channels.tooltip.commands.trigger.restore(); | ||
}); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,76 @@ | ||
define(function(require) { | ||
'use strict'; | ||
|
||
var TooltipRegion = require('foreground/view/tooltip/tooltipRegion'); | ||
var TooltipView = require('foreground/view/tooltip/tooltipView'); | ||
|
||
describe('TooltipRegion', function() { | ||
|
||
beforeEach(function() { | ||
this.tooltipRegion = new TooltipRegion({ | ||
el: document.createDocumentFragment() | ||
}); | ||
}); | ||
|
||
it('should be able to show a tooltip view', function() { | ||
sinon.stub(window, 'requestAnimationFrame'); | ||
|
||
this.tooltipRegion._showTooltip({ | ||
text: 'Hello, world', | ||
targetBoundingClientRect: { | ||
top: 0, | ||
left: 0, | ||
bottom: 0, | ||
right: 0, | ||
width: 0, | ||
height: 0 | ||
} | ||
}); | ||
|
||
expect(this.tooltipRegion.currentView).not.to.equal(undefined); | ||
expect(window.requestAnimationFrame.calledOnce).to.equal(true); | ||
|
||
window.requestAnimationFrame.restore(); | ||
}); | ||
|
||
it('should not throw an error if asked to hide a non-existing tooltip view', function() { | ||
sinon.spy(this.tooltipRegion, '_hideTooltip'); | ||
this.tooltipRegion._hideTooltip(); | ||
expect(this.tooltipRegion._hideTooltip.threw()).to.equal(false); | ||
this.tooltipRegion._hideTooltip.restore(); | ||
}); | ||
|
||
it('should be able to hide an existing view', function() { | ||
var tooltipView = new TooltipView(); | ||
sinon.stub(tooltipView, 'hide'); | ||
|
||
this.tooltipRegion.currentView = tooltipView; | ||
this.tooltipRegion._hideTooltip(); | ||
expect(tooltipView.hide.calledOnce).to.equal(true); | ||
tooltipView.hide.restore(); | ||
}); | ||
|
||
it('should be able to set a tooltipview offset', function() { | ||
var tooltipView = new TooltipView(); | ||
sinon.stub(tooltipView, 'showAtOffset'); | ||
|
||
var boundingClientRect = {}; | ||
this.tooltipRegion._setTooltipViewOffset(tooltipView, boundingClientRect); | ||
|
||
expect(tooltipView.showAtOffset.calledOnce).to.equal(true); | ||
tooltipView.showAtOffset.restore(); | ||
}); | ||
|
||
xit('should be able to get the adjusted offset', function() { | ||
|
||
}); | ||
|
||
xit('should be able to get the shiftLeft offset', function() { | ||
|
||
}); | ||
|
||
xit('should be able to get the flipInvertTop offset', function() { | ||
|
||
}); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters