From 61125473deb6049f32e30d9b4e4f262a89d16c78 Mon Sep 17 00:00:00 2001 From: Max Lynch Date: Mon, 16 Sep 2013 11:26:54 -0500 Subject: [PATCH] Fixed tests and removed DOM call from TabBarController --- hacking/TabBar.js | 3 +++ hacking/TabBar.unit.js | 4 ++-- hacking/TabBarController.js | 4 ++-- hacking/TabBarController.unit.js | 2 +- 4 files changed, 8 insertions(+), 5 deletions(-) diff --git a/hacking/TabBar.js b/hacking/TabBar.js index 77aefca78f..9df4a0d913 100644 --- a/hacking/TabBar.js +++ b/hacking/TabBar.js @@ -148,6 +148,9 @@ TabBar.prototype = { } }, + // Try to select a given item. This triggers an event such + // that the view controller managing this tab bar can decide + // whether to select the item or cancel it. trySelectItem: function(item) { for(var i = 0, j = this.items.length; i < j; i += 1) { if(this.items[i] == item) { diff --git a/hacking/TabBar.unit.js b/hacking/TabBar.unit.js index d4a3fe1aa3..89215f3a2d 100644 --- a/hacking/TabBar.unit.js +++ b/hacking/TabBar.unit.js @@ -52,7 +52,7 @@ describe('TabBar view', function() { it('Should handle item click event', function() { var item = items[0]; - spyOn(tabBar, 'selectItem'); + spyOn(tabBar, 'trySelectItem'); var event = new CustomEvent('tap', { target: item.el @@ -60,7 +60,7 @@ describe('TabBar view', function() { item.el.dispatchEvent(event); //expect(item.onTap).toHaveBeenCalled(); - expect(tabBar.selectItem).toHaveBeenCalled(); + expect(tabBar.trySelectItem).toHaveBeenCalled(); }); diff --git a/hacking/TabBarController.js b/hacking/TabBarController.js index 8a0a2f0223..7fe1776654 100644 --- a/hacking/TabBarController.js +++ b/hacking/TabBarController.js @@ -59,11 +59,11 @@ TabBarController.prototype = { for(var i = 0, j = this.controllers.length; i < j; i ++) { c = this.controllers[i]; - c.el.style.display = 'none'; + c.detach && c.detach(); } c = this.controllers[index]; - c.el.style.display = 'block'; + c.attach && c.attach(); }, _clearSelected: function() { diff --git a/hacking/TabBarController.unit.js b/hacking/TabBarController.unit.js index 6767744653..e844344019 100644 --- a/hacking/TabBarController.unit.js +++ b/hacking/TabBarController.unit.js @@ -11,7 +11,7 @@ describe('TabBarController', function() { it('Should add Controllers', function() { ctrl.addController({ title: 'Item 1', - icon: 'icon-home' + icon: 'icon-home', }); expect(ctrl.getController(0).title).toEqual('Item 1');