Tab bar selection works

This commit is contained in:
Max Lynch
2013-09-13 16:57:37 -05:00
parent 0634e07b01
commit 3fd6b41636
4 changed files with 153 additions and 27 deletions

View File

@ -11,11 +11,9 @@ describe('TabBar view', function() {
el: element.get(0)
});
items = tabBar.getItems();
});
it('Should read tabs', function() {
items = tabBar.getItems();
expect(items.length).toEqual(3);
expect(items[0].getTitle()).toEqual('Tab 1');
expect(items[1].getTitle()).toEqual('Tab 2');
@ -29,8 +27,6 @@ describe('TabBar view', function() {
});
it('Should select', function() {
items = tabBar.getItems();
// Track selection object
tabBar.setSelectedItem(1);
expect(tabBar.getSelectedItem().getTitle()).toEqual('Tab 2');
@ -53,14 +49,24 @@ describe('TabBar view', function() {
expect(items[2].el.classList.contains('active')).toEqual(false);
});
it('Should set item icon', function() {
items = tabBar.getItems();
var item = items[0];
expect(item.getIcon()).toBe(undefined);
});
it('Should handle item click event', function() {
debugger;
var item = items[0];
spyOn(item, 'onTap');
spyOn(tabBar, '_itemTapHandler');
var event = new CustomEvent('tap', {
target: item.el
});
item.el.dispatchEvent(event);
expect(item.onTap).toHaveBeenCalled();
expect(tabBar._itemTapHandler).toHaveBeenCalled();
});
it('Should unbind item on destroy', function() {
var item = items[0];
spyOn(item, 'onTap');
@ -70,8 +76,45 @@ describe('TabBar view', function() {
item.el.dispatchEvent(event);
expect(item.onTap).toHaveBeenCalled();
});
item.onTap.isSpy = false;
spyOn(item, 'onTap');
tabBar.destroy();
var event = new CustomEvent('tap', {
target: item.el
});
item.el.dispatchEvent(event);
expect(item.onTap).not.toHaveBeenCalled();
});
});
describe('TabBarItem view', function() {
var element, tabBar, items;
beforeEach(function() {
element = $('<div class="tabs">' +
'<a href="#" class="tab-item"><i class="icon-home"></i> Tab 1</a>' +
'<a href="#" class="tab-item">Tab 2</a>' +
'<a href="#" class="tab-item">Tab 3</a>');
tabBar = new TabBar({
el: element.get(0)
});
items = tabBar.getItems();
});
it('Should set item title', function() {
var item = items[0];
expect(item.getTitle()).toBe('Tab 1');
});
it('Should set item icon', function() {
var item = items[0];
expect(item.getIcon()).toBe('icon-home');
});
it('Should unbind item on destroy', function() {
var item = items[0];
spyOn(item, 'onTap');