Basic NavController working with demo

This commit is contained in:
Max Lynch
2013-09-16 21:56:22 -05:00
parent 19d2aa5432
commit 0f5ce5b76e
5 changed files with 208 additions and 18 deletions

View File

@ -1,27 +1,41 @@
describe('NavController', function() {
var ctrl;
var ctrl, navBarEl, contentEl;
var content = function(title) {
return {
el: document.createElement('div'),
title: title,
detach: function() {
this.el.parentNode && this.el.parentNode.removeChild(this.el);
},
attach: function() {
}
}
}
beforeEach(function() {
navBarEl = document.createElement('div');
contentEl = document.createElement('div');
ctrl = new NavController({
navBar: new NavBar()
navBar: new NavBar({el: navBarEl }),
content: { el: contentEl }
});
});
it('Should load controllers', function() {
ctrl = new NavController({
navBar: new NavBar({el: navBarEl }),
content: { el: contentEl },
controllers: [{}]
});
expect(ctrl.getControllers().length).toEqual(1);
});
it('Should push controller', function() {
ctrl.push({
title: 'Page 1'
});
ctrl.push(content('Page 1'));
expect(ctrl.getControllers().length).toEqual(1);
ctrl.push({
title: 'Page 2'
});
ctrl.push(content('Page 2'));
expect(ctrl.getControllers().length).toEqual(2);
var last = ctrl.pop();
expect(ctrl.getControllers().length).toEqual(1);
@ -30,19 +44,17 @@ describe('NavController', function() {
it('Should change top view controller', function() {
expect(ctrl.getTopController()).toBe(undefined);
var c1 = {
title: 'Page 1'
};
var c2 = {
title: 'Page 2'
};
var c1 = content('Page 1');
var c2 = content('Page 2');
ctrl.push(c1);
expect(ctrl.getTopController()).toEqual(c1);
ctrl.push(c2);
expect(ctrl.getTopController()).toEqual(c2);
ctrl.pop();
expect(ctrl.getTopController()).toEqual(c1);
// Make sure we can't pop the first one off
ctrl.pop();
expect(ctrl.getTopController()).toEqual(undefined);
expect(ctrl.getTopController()).toEqual(c1);
});
});