Updating tests, fixing some old toggle and tab stuff

This commit is contained in:
Max Lynch
2013-10-29 12:04:44 -05:00
parent 4efd10765c
commit 599dd732d4
9 changed files with 4570 additions and 699 deletions

3858
dist/css/ionic.css vendored

File diff suppressed because one or more lines are too long

View File

@ -867,7 +867,7 @@ angular.module('ionic.ui.tabs', ['ngAnimate'])
this.add = function(controller) { this.add = function(controller) {
this.addController(controller); this.addController(controller);
this.select(0); this.select(0);
}; };
this.select = function(controllerIndex) { this.select = function(controllerIndex) {
@ -982,13 +982,15 @@ angular.module('ionic.ui.tabs', ['ngAnimate'])
index: '=' index: '='
}, },
link: function(scope, element, attrs, tabsCtrl) { link: function(scope, element, attrs, tabsCtrl) {
if(attrs.icon) {
scope.iconOn = scope.iconOff = attrs.icon;
}
scope.selectTab = function(index) { scope.selectTab = function(index) {
tabsCtrl.select(scope.index); tabsCtrl.select(scope.index);
}; };
}, },
template: template:
'<a href="#" ng-class="{active:active}" ng-click="selectTab()" class="tab-item">' + '<a href="#" ng-class="{active:active}" ng-click="selectTab()" class="tab-item">' +
'<i class="{{icon}}" ng-if="icon"></i>' +
'<i class="{{iconOn}}" ng-if="active"></i>' + '<i class="{{iconOn}}" ng-if="active"></i>' +
'<i class="{{iconOff}}" ng-if="!active"></i> {{title}}' + '<i class="{{iconOff}}" ng-if="!active"></i> {{title}}' +
'</a>' '</a>'
@ -1046,7 +1048,7 @@ angular.module('ionic.ui.toggle', [])
if(!ngModel) { return; } if(!ngModel) { return; }
checkbox = $element.children().eq(0); checkbox = $element.children().eq(0);
handle = track.children().eq(0); handle = $element.children().eq(1);
if(!checkbox.length || !handle.length) { return; } if(!checkbox.length || !handle.length) { return; }

1349
dist/js/ionic.js vendored

File diff suppressed because it is too large Load Diff

View File

@ -92,11 +92,16 @@ ionic.controllers.TabBarController.prototype = {
return this.controllers; return this.controllers;
}, },
// Get the currently selected tab // Get the currently selected controller
getSelectedController: function() { getSelectedController: function() {
return this.selectedController; return this.selectedController;
}, },
// Get the index of the currently selected controller
getSelectedControllerIndex: function() {
return this.selectedIndex;
},
// Add a tab // Add a tab
addController: function(controller) { addController: function(controller) {
this.controllers.push(controller); this.controllers.push(controller);

View File

@ -15,7 +15,7 @@ angular.module('ionic.ui.tabs', ['ngAnimate'])
this.add = function(controller) { this.add = function(controller) {
this.addController(controller); this.addController(controller);
this.select(0); this.select(0);
}; };
this.select = function(controllerIndex) { this.select = function(controllerIndex) {
@ -130,13 +130,15 @@ angular.module('ionic.ui.tabs', ['ngAnimate'])
index: '=' index: '='
}, },
link: function(scope, element, attrs, tabsCtrl) { link: function(scope, element, attrs, tabsCtrl) {
if(attrs.icon) {
scope.iconOn = scope.iconOff = attrs.icon;
}
scope.selectTab = function(index) { scope.selectTab = function(index) {
tabsCtrl.select(scope.index); tabsCtrl.select(scope.index);
}; };
}, },
template: template:
'<a href="#" ng-class="{active:active}" ng-click="selectTab()" class="tab-item">' + '<a href="#" ng-class="{active:active}" ng-click="selectTab()" class="tab-item">' +
'<i class="{{icon}}" ng-if="icon"></i>' +
'<i class="{{iconOn}}" ng-if="active"></i>' + '<i class="{{iconOn}}" ng-if="active"></i>' +
'<i class="{{iconOff}}" ng-if="!active"></i> {{title}}' + '<i class="{{iconOff}}" ng-if="!active"></i> {{title}}' +
'</a>' '</a>'

View File

@ -16,7 +16,7 @@ angular.module('ionic.ui.toggle', [])
if(!ngModel) { return; } if(!ngModel) { return; }
checkbox = $element.children().eq(0); checkbox = $element.children().eq(0);
handle = track.children().eq(0); handle = $element.children().eq(1);
if(!checkbox.length || !handle.length) { return; } if(!checkbox.length || !handle.length) { return; }

View File

@ -1,24 +1,24 @@
describe('Tab Bar Controller', function() { describe('Tab Bar Controller', function() {
var compile, element, scope, ctrl; var compile, element, scope, ctrl;
beforeEach(module('ionic.ui.tabbar')); beforeEach(module('ionic.ui.tabs'));
beforeEach(inject(function($compile, $rootScope, $controller) { beforeEach(inject(function($compile, $rootScope, $controller) {
compile = $compile; compile = $compile;
scope = $rootScope; scope = $rootScope;
ctrl = $controller('TabBarCtrl', { $scope: scope, $element: null }); ctrl = $controller('TabsCtrl', { $scope: scope, $element: null });
})); }));
it('Select item in controller works', function() { it('Select item in controller works', function() {
ctrl.selectTabAtIndex(1); ctrl.selectController(1);
expect(ctrl.getSelectedTabIndex()).toEqual(1); expect(ctrl.getSelectedControllerIndex()).toEqual(1);
}); });
}); });
describe('Tab Bar directive', function() { describe('Tab Bar directive', function() {
var compile, element, scope; var compile, element, scope;
beforeEach(module('ionic.ui.tabbar')); beforeEach(module('ionic.ui.tabs'));
beforeEach(inject(function($compile, $rootScope) { beforeEach(inject(function($compile, $rootScope) {
compile = $compile; compile = $compile;
@ -34,7 +34,7 @@ describe('Tab Bar directive', function() {
describe('Tabs directive', function() { describe('Tabs directive', function() {
var compile, element, scope; var compile, element, scope;
beforeEach(module('ionic.ui.tabbar')); beforeEach(module('ionic.ui.tabs'));
beforeEach(inject(function($compile, $rootScope) { beforeEach(inject(function($compile, $rootScope) {
compile = $compile; compile = $compile;
@ -42,10 +42,10 @@ describe('Tabs directive', function() {
})); }));
it('Has tab class', function() { it('Has tab class', function() {
element = compile('<tab-bar><tabs></tabs></tab-bar>')(scope); element = compile('<tabs></tabs>')(scope);
scope.$digest(); scope.$digest();
console.log(element); console.log(element);
expect(element.find('.bar').hasClass('bar-tabs')).toBe(true); expect(element.find('.tabs').hasClass('tabs')).toBe(true);
}); });
it('Has tab children', function() { it('Has tab children', function() {
@ -54,7 +54,7 @@ describe('Tabs directive', function() {
{ text: 'Fun', icon: 'icon-fun' }, { text: 'Fun', icon: 'icon-fun' },
{ text: 'Beer', icon: 'icon-beer' }, { text: 'Beer', icon: 'icon-beer' },
]; ];
element = compile('<tab-bar><tabs></tabs></tab-bar>')(scope); element = compile('<tabs></tabs>')(scope);
scope.$digest(); scope.$digest();
expect(element.find('li').length).toBe(3); expect(element.find('li').length).toBe(3);
}); });
@ -63,16 +63,15 @@ describe('Tabs directive', function() {
describe('Tab Item directive', function() { describe('Tab Item directive', function() {
var compile, element, scope, ctrl; var compile, element, scope, ctrl;
beforeEach(module('ionic.ui.tabbar')); beforeEach(module('ionic.ui.tabs'));
beforeEach(inject(function($compile, $rootScope, $controller) { beforeEach(inject(function($compile, $rootScope, $controller) {
compile = $compile; compile = $compile;
scope = $rootScope; scope = $rootScope;
//ctrl = $controller('TabBarCtrl', { $scope: scope, $element: null });
element = compile('<tab-bar><tabs>' + element = compile('<tabs>' +
'<tab-item active="true" text="Item" icon="icon-default"></tab-item>' + '<tab active="true" text="Item" icon="icon-default"></tab>' +
'</tabs></tab-bar>')(scope); '</tabs>')(scope);
scope.$digest(); scope.$digest();
})); }));
@ -85,10 +84,11 @@ describe('Tab Item directive', function() {
}); });
it('Click sets correct tab index', function() { it('Click sets correct tab index', function() {
var a = element.find('a:eq(2)'); var a = element.find('a:eq(0)');
var itemScope = a.scope();
//spyOn(a, 'click'); //spyOn(a, 'click');
spyOn(scope, 'selectTab'); spyOn(itemScope, 'selectTab');
a.click(); a.click();
expect(scope.selectTab).toHaveBeenCalled(); expect(itemScope.selectTab).toHaveBeenCalled();
}); });
}); });

View File

@ -11,7 +11,6 @@ describe('Ionic Toggle', function() {
var toggleView = el.scope().toggle; var toggleView = el.scope().toggle;
expect(toggleView).not.toEqual(null); expect(toggleView).not.toEqual(null);
expect(toggleView.checkbox).not.toEqual(null); expect(toggleView.checkbox).not.toEqual(null);
expect(toggleView.track).not.toEqual(null);
expect(toggleView.handle).not.toEqual(null); expect(toggleView.handle).not.toEqual(null);
}); });

View File

@ -27,7 +27,7 @@ describe('List View', function() {
}); });
}); });
iit('Should init item height from CSS', function() { it('Should init item height from CSS', function() {
var list = new ionic.views.ListView({ var list = new ionic.views.ListView({
el: h, el: h,
listEl: listEl, listEl: listEl,
@ -37,7 +37,7 @@ describe('List View', function() {
expect(list.itemHeight).toEqual(50); expect(list.itemHeight).toEqual(50);
}); });
iit('Should support virtual scrolling', function() { it('Should support virtual scrolling', function() {
var list = new ionic.views.ListView({ var list = new ionic.views.ListView({
el: h, el: h,
listEl: listEl, listEl: listEl,