mirror of
https://github.com/ionic-team/ionic-framework.git
synced 2025-11-06 22:29:44 +08:00
This is more inline with iOS style, where the controllers that show content drive the tabs, not the tab list.
73 lines
1.6 KiB
JavaScript
73 lines
1.6 KiB
JavaScript
describe('TabBarController', function() {
|
|
var ctrl;
|
|
|
|
beforeEach(function() {
|
|
ctrl = new TabBarController({
|
|
tabBar: new TabBar()
|
|
});
|
|
})
|
|
|
|
it('Should add Controllers', function() {
|
|
ctrl.addController({
|
|
title: 'Item 1'
|
|
});
|
|
|
|
expect(ctrl.getController(0).title).toEqual('Item 1');
|
|
});
|
|
|
|
it('Should set Controllers', function() {
|
|
var Controllers = [
|
|
{ title: 'Item 1' },
|
|
{ title: 'Item 2' },
|
|
{ title: 'Item 3' },
|
|
];
|
|
ctrl.setControllers(Controllers);
|
|
|
|
expect(ctrl.getControllers()).toBe(Controllers);
|
|
});
|
|
|
|
it('Should select Controller', function() {
|
|
Controller = {
|
|
title: 'Item 1'
|
|
};
|
|
|
|
ctrl.addController(Controller);
|
|
|
|
ctrl.selectController(0);
|
|
|
|
expect(ctrl.getSelectedController()).toEqual(Controller);
|
|
});
|
|
|
|
it('Should trigger lifecycle methods', function() {
|
|
Controller = {
|
|
title: 'Item 1'
|
|
};
|
|
|
|
spyOn(ctrl, 'controllerWillChange');
|
|
spyOn(ctrl, 'controllerChanged');
|
|
|
|
ctrl.addController(Controller);
|
|
ctrl.selectController(0);
|
|
expect(ctrl.controllerWillChange).toHaveBeenCalled();
|
|
expect(ctrl.controllerChanged).toHaveBeenCalled();
|
|
});
|
|
|
|
it('Should allow cancelling Controller switch', function() {
|
|
ctrl = new TabBarController({
|
|
tabBar: new TabBar(),
|
|
controllerWillChange: function(Controller) { return false; }
|
|
});
|
|
|
|
ctrl.addController({
|
|
title: 'Item 1'
|
|
});
|
|
ctrl.addController({
|
|
title: 'Item 2'
|
|
});
|
|
ctrl.selectController(1);
|
|
|
|
// Make sure the Controller didn't switch
|
|
expect(ctrl.getSelectedController()).toBe(ctrl.getController(0));
|
|
});
|
|
|
|
}) |