-
Notifications
You must be signed in to change notification settings - Fork 241
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #658 from Steimel/feature/LUM-29
LUM-29 #comment Finished unit tests for js/menubar components
- Loading branch information
Showing
2 changed files
with
296 additions
and
0 deletions.
There are no files selected for viewing
144 changes: 144 additions & 0 deletions
144
web/war/src/main/webapp/test/unit/spec/menubar/activityTest.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,144 @@ | ||
describeComponent('menubar/activity/activity', function(Activity) { | ||
|
||
beforeEach(function() { | ||
setupComponent(this); | ||
}) | ||
|
||
describe('Activity', function() { | ||
|
||
describe('on initialize', function(){ | ||
|
||
it('should initialize', function() { | ||
var c = this.component | ||
}) | ||
|
||
}) | ||
|
||
describe('on activityUpdated events', function() { | ||
|
||
describe('when the badge does not exist', function() { | ||
|
||
it('should do nothing when the count is zero', function() { | ||
var c = this.component, | ||
count = 0, | ||
data = { | ||
count: count | ||
}; | ||
|
||
expect(getBadge(c).length).to.eql(0); | ||
|
||
c.trigger('activityUpdated', data); | ||
|
||
_.defer(function() { | ||
expect(getBadge(c).length).to.eql(0); | ||
}) | ||
}) | ||
|
||
it('should create the badge and set the count when the count is non-zero', function() { | ||
var c = this.component, | ||
count = 2, | ||
data = { | ||
count: count | ||
}; | ||
|
||
expect(getBadge(c).length).to.eql(0); | ||
|
||
c.trigger('activityUpdated', data); | ||
|
||
_.defer(function() { | ||
expect(getBadge(c).length).to.eql(1); | ||
expect(getBadge(c).html()).to.eql(count.toString()); | ||
}) | ||
}) | ||
|
||
}) | ||
|
||
describe('when the badge exists', function() { | ||
|
||
beforeEach(function() { | ||
var c = this.component, | ||
count = 7, | ||
data = { | ||
count: count | ||
}; | ||
|
||
c.trigger('activityUpdated', data); | ||
}) | ||
|
||
it('should set the count when the count is zero', function() { | ||
var c = this.component, | ||
count = 0, | ||
data = { | ||
count: count | ||
}; | ||
|
||
expect(getBadge(c).length).to.eql(1); | ||
|
||
c.trigger('activityUpdated', data); | ||
|
||
_.defer(function() { | ||
expect(getBadge(c).length).to.eql(1); | ||
expect(getBadge(c).html()).to.eql(count.toString()); | ||
}) | ||
}) | ||
|
||
it('should remove the animating class when the count is zero', function() { | ||
var c = this.component, | ||
count = 0, | ||
data = { | ||
count: count | ||
}; | ||
|
||
expect(c.$node.hasClass('animating')).to.be.true; | ||
|
||
c.trigger('activityUpdated', data); | ||
|
||
_.defer(function() { | ||
expect(c.$node.hasClass('animating')).to.be.false; | ||
}) | ||
}) | ||
|
||
it('should set the count when the count is non-zero', function() { | ||
var c = this.component, | ||
count = 2, | ||
data = { | ||
count: count | ||
}; | ||
|
||
expect(getBadge(c).length).to.eql(1); | ||
|
||
c.trigger('activityUpdated', data); | ||
|
||
_.defer(function() { | ||
expect(getBadge(c).length).to.eql(1); | ||
expect(getBadge(c).html()).to.eql(count.toString()); | ||
}) | ||
}) | ||
|
||
it('should not remove the animating class when the count is non-zero', function() { | ||
var c = this.component, | ||
count = 2, | ||
data = { | ||
count: count | ||
}; | ||
|
||
expect(c.$node.hasClass('animating')).to.be.true; | ||
|
||
c.trigger('activityUpdated', data); | ||
|
||
_.defer(function() { | ||
expect(c.$node.hasClass('animating')).to.be.true; | ||
}) | ||
}) | ||
|
||
}) | ||
|
||
}) | ||
|
||
}) | ||
|
||
function getBadge(c) { | ||
return c.$node.find('div.activityCount'); | ||
} | ||
|
||
}) |
152 changes: 152 additions & 0 deletions
152
web/war/src/main/webapp/test/unit/spec/menubar/menubarTest.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,152 @@ | ||
describeComponent('menubar/menubar', function(Menubar) { | ||
|
||
beforeEach(function() { | ||
setupComponent(this); | ||
}) | ||
|
||
describe('Menubar', function() { | ||
|
||
var BUTTONS = 'dashboard graph map search workspaces admin activity logout'.split(' '); | ||
|
||
describe('on initialize', function(){ | ||
|
||
it('should initialize', function() { | ||
var c = this.component | ||
}) | ||
|
||
it('should create the buttons', function() { | ||
var c = this.component; | ||
|
||
BUTTONS.forEach(function(name) { | ||
var found = false; | ||
for(var i = 0; i < getTopButtons(c).length; i++) { | ||
if($(getTopButtons(c)[i]).hasClass(name)) { | ||
found = true; | ||
} | ||
} | ||
for(var i = 0; i < getBottomButtons(c).length; i++) { | ||
if($(getBottomButtons(c)[i]).hasClass(name)) { | ||
found = true; | ||
} | ||
} | ||
expect(found).to.be.true; | ||
}); | ||
}) | ||
|
||
}) | ||
|
||
describe('on menubarToggleDisplay events', function() { | ||
|
||
BUTTONS.forEach(function(name) { | ||
|
||
describe('when ' + name + ' is toggled', function() { | ||
|
||
describe('when ' + name + ' is already active', function() { | ||
|
||
beforeEach(function() { | ||
var c = this.component; | ||
activate(c, name); | ||
}) | ||
|
||
it('should deactivate the option', function(done) { | ||
var c = this.component, | ||
data = { | ||
name: name | ||
}; | ||
|
||
expect(isActive(c, name)).to.be.true; | ||
|
||
c.trigger('menubarToggleDisplay', data); | ||
|
||
_.delay(function() { | ||
expect(isActive(c, name)).to.be.false; | ||
done(); | ||
}, 500); | ||
}) | ||
|
||
}) | ||
|
||
describe('when ' + name + ' is not active', function() { | ||
|
||
beforeEach(function() { | ||
var c = this.component; | ||
deactivate(c, name); | ||
}) | ||
|
||
it('should activate the option', function() { | ||
var c = this.component, | ||
data = { | ||
name: name | ||
}; | ||
|
||
expect(isActive(c, name)).to.be.false; | ||
|
||
c.trigger('menubarToggleDisplay', data); | ||
|
||
expect(isActive(c, name)).to.be.true; | ||
}) | ||
|
||
}) | ||
|
||
}) | ||
|
||
}) | ||
|
||
|
||
|
||
|
||
}) | ||
|
||
describe('on click events', function() { | ||
|
||
BUTTONS.forEach(function(name) { | ||
|
||
describe('when ' + name + ' is clicked', function() { | ||
|
||
it('should trigger a menubarToggleDisplay event', function(done) { | ||
var c = this.component; | ||
selector = name + 'IconSelector', | ||
oldTooltip = $.fn.tooltip; | ||
|
||
c.on(document, 'menubarToggleDisplay', function() { | ||
$.fn.tooltip = oldTooltip; | ||
done(); | ||
}) | ||
|
||
$.fn.tooltip = function(){/* noop to avoid tooltip init issues on this test */}; | ||
c.select(selector).click(); | ||
}) | ||
|
||
}) | ||
|
||
}) | ||
|
||
}) | ||
|
||
}) | ||
|
||
function getTopButtons(c) { | ||
return c.$node.find('ul.menu-top').find('li').not('.divider'); | ||
} | ||
|
||
function getBottomButtons(c) { | ||
return c.$node.find('ul.menu-bottom').find('li').not('.divider'); | ||
} | ||
|
||
function activate(c, name) { | ||
toggleActivate(c, name, true); | ||
} | ||
|
||
function deactivate(c, name) { | ||
toggleActivate(c, name, false); | ||
} | ||
|
||
function toggleActivate(c, name, active) { | ||
c.select(name + 'IconSelector').toggleClass('active', active); | ||
} | ||
|
||
function isActive(c, name) { | ||
return c.select(name + 'IconSelector').hasClass('active'); | ||
} | ||
|
||
}) |