mirror of
https://github.com/ionic-team/ionic-framework.git
synced 2025-11-06 22:29:44 +08:00
Tab bar selection works
This commit is contained in:
@ -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');
|
||||
|
||||
Reference in New Issue
Block a user