From f0f077aa8b56f0333a779b233af85dfbc1b4ce26 Mon Sep 17 00:00:00 2001 From: Tommy Steimel Date: Thu, 21 May 2015 16:32:41 -0400 Subject: [PATCH] LUM-29 #comment Finished unit tests for js/menubar components --- .../test/unit/spec/menubar/activityTest.js | 144 +++++++++++++++++ .../test/unit/spec/menubar/menubarTest.js | 152 ++++++++++++++++++ 2 files changed, 296 insertions(+) create mode 100644 web/war/src/main/webapp/test/unit/spec/menubar/activityTest.js create mode 100644 web/war/src/main/webapp/test/unit/spec/menubar/menubarTest.js diff --git a/web/war/src/main/webapp/test/unit/spec/menubar/activityTest.js b/web/war/src/main/webapp/test/unit/spec/menubar/activityTest.js new file mode 100644 index 0000000000..0f3f46cc27 --- /dev/null +++ b/web/war/src/main/webapp/test/unit/spec/menubar/activityTest.js @@ -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'); + } + +}) \ No newline at end of file diff --git a/web/war/src/main/webapp/test/unit/spec/menubar/menubarTest.js b/web/war/src/main/webapp/test/unit/spec/menubar/menubarTest.js new file mode 100644 index 0000000000..c9f83433d8 --- /dev/null +++ b/web/war/src/main/webapp/test/unit/spec/menubar/menubarTest.js @@ -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'); + } + +}) \ No newline at end of file