Tests organization and cleanup

Moved hacking tests to test folder, got rid of ionic=window.ionic for
wrapper functions in JS files.
This commit is contained in:
Max Lynch
2013-09-24 17:22:36 -05:00
parent 5aabbfbd0c
commit 37d708b05e
19 changed files with 75 additions and 74 deletions

54
dist/ionic.js vendored
View File

@ -1,5 +1,9 @@
window.ionic = {}; window.ionic = {};
// Create namespaces
ionic.controllers = {};
ionic.views = {};
function initalize() { function initalize() {
// remove the ready listeners // remove the ready listeners
document.removeEventListener( "DOMContentLoaded", initalize, false ); document.removeEventListener( "DOMContentLoaded", initalize, false );
@ -64,7 +68,7 @@ if ( document.readyState === "complete" ) {
} }
ionic.Platform.detect(); ionic.Platform.detect();
})(ionic = window.ionic || {}); })(window.ionic);
;(function(ionic) { ;(function(ionic) {
ionic.Utils = { ionic.Utils = {
@ -86,7 +90,7 @@ if ( document.readyState === "complete" ) {
return dest; return dest;
}, },
} }
})(ionic = window.ionic || {}); })(window.ionic);
;/** ;/**
* ion-events.js * ion-events.js
* *
@ -195,7 +199,7 @@ if ( document.readyState === "complete" ) {
// Set up various listeners // Set up various listeners
window.addEventListener('click', ionic.EventController.handleClick); window.addEventListener('click', ionic.EventController.handleClick);
})(ionic = window.ionic || {}); })(window.ionic);
;/** ;/**
* Simple gesture controllers with some common gestures that emit * Simple gesture controllers with some common gestures that emit
* gesture events. * gesture events.
@ -1623,7 +1627,7 @@ if ( document.readyState === "complete" ) {
} }
} }
}; };
})(ionic = window.ionic || {}); })(window.ionic);
;(function(ionic) { ;(function(ionic) {
ionic.Animator = { ionic.Animator = {
animate: function(element, className, fn) { animate: function(element, className, fn) {
@ -1666,7 +1670,7 @@ if ( document.readyState === "complete" ) {
}; };
} }
}; };
})(ionic = window.ionic || {}); })(window.ionic);
;(function(ionic) { ;(function(ionic) {
ionic.ViewController = function(options) { ionic.ViewController = function(options) {
this.init(); this.init();
@ -1680,18 +1684,16 @@ if ( document.readyState === "complete" ) {
destroy: function() { destroy: function() {
} }
}; };
})(ionic = window.ionic || {}); })(window.ionic);
;(function(ionic) { ;(function(ionic) {
ionic.ui = ionic.ui || {}; ionic.views.NavBar = function(opts) {
ionic.ui.NavBar = function(opts) {
this.el = opts.el; this.el = opts.el;
this._titleEl = this.el.querySelector('.title'); this._titleEl = this.el.querySelector('.title');
}; };
ionic.ui.NavBar.prototype = { ionic.views.NavBar.prototype = {
shouldGoBack: function() {}, shouldGoBack: function() {},
setTitle: function(title) { setTitle: function(title) {
@ -1724,18 +1726,18 @@ ionic.ui.NavBar.prototype = {
} }
} }
}; };
})(ionic = window.ionic || {}); })(window.ionic);
;(function(ionic) { ;(function(ionic) {
ionic.ui = ionic.ui || {}; ionic.views = ionic.views || {};
ionic.ui.SideMenu = function(opts) { ionic.views.SideMenu = function(opts) {
this.el = opts.el; this.el = opts.el;
this.width = opts.width; this.width = opts.width;
this.isEnabled = opts.isEnabled || true; this.isEnabled = opts.isEnabled || true;
}; };
ionic.ui.SideMenu.prototype = { ionic.views.SideMenu.prototype = {
getFullWidth: function() { getFullWidth: function() {
return this.width; return this.width;
}, },
@ -1749,17 +1751,15 @@ ionic.ui.SideMenu.prototype = {
this.el.style.zIndex = -1; this.el.style.zIndex = -1;
} }
}; };
})(ionic = window.ionic || {}); })(window.ionic);
;(function(ionic) { ;(function(ionic) {
ionic.ui = ionic.ui || {}; ionic.views.TabBarItem = function(el) {
ionic.ui.TabBarItem = function(el) {
this.el = el; this.el = el;
this._buildItem(); this._buildItem();
}; };
ionic.ui.TabBarItem.prototype = { ionic.views.TabBarItem.prototype = {
// Factory for creating an item from a given javascript object // Factory for creating an item from a given javascript object
create: function(itemData) { create: function(itemData) {
var item = document.createElement('a'); var item = document.createElement('a');
@ -1773,7 +1773,7 @@ ionic.ui.TabBarItem.prototype = {
} }
item.appendChild(document.createTextNode(itemData.title)); item.appendChild(document.createTextNode(itemData.title));
return new ionic.ui.TabBarItem(item); return new ionic.views.TabBarItem(item);
}, },
@ -1828,7 +1828,7 @@ ionic.ui.TabBarItem.prototype = {
} }
}; };
ionic.ui.TabBar = function(opts) { ionic.views.TabBar = function(opts) {
this.el = opts.el; this.el = opts.el;
this.items = []; this.items = [];
@ -1836,7 +1836,7 @@ ionic.ui.TabBar = function(opts) {
this._buildItems(); this._buildItems();
}; };
ionic.ui.TabBar.prototype = { ionic.views.TabBar.prototype = {
// get all the items for the TabBar // get all the items for the TabBar
getItems: function() { getItems: function() {
return this.items; return this.items;
@ -1845,7 +1845,7 @@ ionic.ui.TabBar.prototype = {
// Add an item to the tab bar // Add an item to the tab bar
addItem: function(item) { addItem: function(item) {
// Create a new TabItem // Create a new TabItem
var tabItem = ionic.ui.TabBarItem.prototype.create(item); var tabItem = ionic.views.TabBarItem.prototype.create(item);
this.appendItemElement(tabItem); this.appendItemElement(tabItem);
@ -1932,7 +1932,7 @@ ionic.ui.TabBar.prototype = {
var item, items = Array.prototype.slice.call(this.el.children); var item, items = Array.prototype.slice.call(this.el.children);
for(var i = 0, j = items.length; i < j; i += 1) { for(var i = 0, j = items.length; i < j; i += 1) {
item = new ionic.ui.TabBarItem(items[i]); item = new ionic.views.TabBarItem(items[i]);
this.items[i] = item; this.items[i] = item;
this._bindEventsOnItem(item); this._bindEventsOnItem(item);
} }
@ -1952,11 +1952,9 @@ ionic.ui.TabBar.prototype = {
} }
}; };
})(ionic = window.ionic || {}); })(window.ionic);
;(function(ionic) { ;(function(ionic) {
ionic.controllers = ionic.controllers || {};
ionic.controllers.NavController = function(opts) { ionic.controllers.NavController = function(opts) {
var _this = this; var _this = this;
@ -2060,7 +2058,7 @@ ionic.controllers.NavController.prototype = {
}, },
}; };
})(ionic = window.ionic || {}); })(window.ionic);
;(function(ionic) { ;(function(ionic) {
ionic.controllers = ionic.controllers || {}; ionic.controllers = ionic.controllers || {};

View File

@ -19,12 +19,11 @@ module.exports = function(config) {
'https://ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js', 'https://ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js',
'vendor/angular/1.2.0rc1/*', 'vendor/angular/1.2.0rc1/*',
'js/ionic-events.js', 'dist/ionic.js',
'js/ionic-gestures.js', 'test/**/*.js',
'test/utils/**/*.js',
//'ext/angular/src/**/*.js', //'ext/angular/src/**/*.js',
//'ext/angular/test/**/*.js', //'ext/angular/test/**/*.js',
'hacking/**/*.js', //'hacking/**/*.js',
//'test/**/*.js' //'test/**/*.js'
], ],

View File

@ -40,4 +40,4 @@
}; };
} }
}; };
})(ionic = window.ionic || {}); })(window.ionic);

View File

@ -1,7 +1,5 @@
(function(ionic) { (function(ionic) {
ionic.controllers = ionic.controllers || {};
ionic.controllers.NavController = function(opts) { ionic.controllers.NavController = function(opts) {
var _this = this; var _this = this;
@ -105,4 +103,4 @@ ionic.controllers.NavController.prototype = {
}, },
}; };
})(ionic = window.ionic || {}); })(window.ionic);

View File

@ -106,4 +106,4 @@
// Set up various listeners // Set up various listeners
window.addEventListener('click', ionic.EventController.handleClick); window.addEventListener('click', ionic.EventController.handleClick);
})(ionic = window.ionic || {}); })(window.ionic);

View File

@ -1425,4 +1425,4 @@
} }
} }
}; };
})(ionic = window.ionic || {}); })(window.ionic);

View File

@ -1,5 +1,9 @@
window.ionic = {}; window.ionic = {};
// Create namespaces
ionic.controllers = {};
ionic.views = {};
function initalize() { function initalize() {
// remove the ready listeners // remove the ready listeners
document.removeEventListener( "DOMContentLoaded", initalize, false ); document.removeEventListener( "DOMContentLoaded", initalize, false );

View File

@ -36,4 +36,4 @@
} }
ionic.Platform.detect(); ionic.Platform.detect();
})(ionic = window.ionic || {}); })(window.ionic);

View File

@ -19,4 +19,4 @@
return dest; return dest;
}, },
} }
})(ionic = window.ionic || {}); })(window.ionic);

View File

@ -11,4 +11,4 @@
destroy: function() { destroy: function() {
} }
}; };
})(ionic = window.ionic || {}); })(window.ionic);

View File

@ -1,14 +1,12 @@
(function(ionic) { (function(ionic) {
ionic.ui = ionic.ui || {}; ionic.views.NavBar = function(opts) {
ionic.ui.NavBar = function(opts) {
this.el = opts.el; this.el = opts.el;
this._titleEl = this.el.querySelector('.title'); this._titleEl = this.el.querySelector('.title');
}; };
ionic.ui.NavBar.prototype = { ionic.views.NavBar.prototype = {
shouldGoBack: function() {}, shouldGoBack: function() {},
setTitle: function(title) { setTitle: function(title) {
@ -41,4 +39,4 @@ ionic.ui.NavBar.prototype = {
} }
} }
}; };
})(ionic = window.ionic || {}); })(window.ionic);

View File

@ -1,14 +1,14 @@
(function(ionic) { (function(ionic) {
ionic.ui = ionic.ui || {}; ionic.views = ionic.views || {};
ionic.ui.SideMenu = function(opts) { ionic.views.SideMenu = function(opts) {
this.el = opts.el; this.el = opts.el;
this.width = opts.width; this.width = opts.width;
this.isEnabled = opts.isEnabled || true; this.isEnabled = opts.isEnabled || true;
}; };
ionic.ui.SideMenu.prototype = { ionic.views.SideMenu.prototype = {
getFullWidth: function() { getFullWidth: function() {
return this.width; return this.width;
}, },
@ -22,4 +22,4 @@ ionic.ui.SideMenu.prototype = {
this.el.style.zIndex = -1; this.el.style.zIndex = -1;
} }
}; };
})(ionic = window.ionic || {}); })(window.ionic);

View File

@ -1,13 +1,11 @@
(function(ionic) { (function(ionic) {
ionic.ui = ionic.ui || {}; ionic.views.TabBarItem = function(el) {
ionic.ui.TabBarItem = function(el) {
this.el = el; this.el = el;
this._buildItem(); this._buildItem();
}; };
ionic.ui.TabBarItem.prototype = { ionic.views.TabBarItem.prototype = {
// Factory for creating an item from a given javascript object // Factory for creating an item from a given javascript object
create: function(itemData) { create: function(itemData) {
var item = document.createElement('a'); var item = document.createElement('a');
@ -21,7 +19,7 @@ ionic.ui.TabBarItem.prototype = {
} }
item.appendChild(document.createTextNode(itemData.title)); item.appendChild(document.createTextNode(itemData.title));
return new ionic.ui.TabBarItem(item); return new ionic.views.TabBarItem(item);
}, },
@ -76,7 +74,7 @@ ionic.ui.TabBarItem.prototype = {
} }
}; };
ionic.ui.TabBar = function(opts) { ionic.views.TabBar = function(opts) {
this.el = opts.el; this.el = opts.el;
this.items = []; this.items = [];
@ -84,7 +82,7 @@ ionic.ui.TabBar = function(opts) {
this._buildItems(); this._buildItems();
}; };
ionic.ui.TabBar.prototype = { ionic.views.TabBar.prototype = {
// get all the items for the TabBar // get all the items for the TabBar
getItems: function() { getItems: function() {
return this.items; return this.items;
@ -93,7 +91,7 @@ ionic.ui.TabBar.prototype = {
// Add an item to the tab bar // Add an item to the tab bar
addItem: function(item) { addItem: function(item) {
// Create a new TabItem // Create a new TabItem
var tabItem = ionic.ui.TabBarItem.prototype.create(item); var tabItem = ionic.views.TabBarItem.prototype.create(item);
this.appendItemElement(tabItem); this.appendItemElement(tabItem);
@ -180,7 +178,7 @@ ionic.ui.TabBar.prototype = {
var item, items = Array.prototype.slice.call(this.el.children); var item, items = Array.prototype.slice.call(this.el.children);
for(var i = 0, j = items.length; i < j; i += 1) { for(var i = 0, j = items.length; i < j; i += 1) {
item = new ionic.ui.TabBarItem(items[i]); item = new ionic.views.TabBarItem(items[i]);
this.items[i] = item; this.items[i] = item;
this._bindEventsOnItem(item); this._bindEventsOnItem(item);
} }
@ -200,4 +198,4 @@ ionic.ui.TabBar.prototype = {
} }
}; };
})(ionic = window.ionic || {}); })(window.ionic);

View File

@ -17,15 +17,15 @@ describe('NavController', function() {
navBarEl = document.createElement('div'); navBarEl = document.createElement('div');
contentEl = document.createElement('div'); contentEl = document.createElement('div');
ctrl = new NavController({ ctrl = new ionic.controllers.NavController({
navBar: new NavBar({el: navBarEl }), navBar: new ionic.views.NavBar({el: navBarEl }),
content: { el: contentEl } content: { el: contentEl }
}); });
}); });
it('Should load controllers', function() { it('Should load controllers', function() {
ctrl = new NavController({ ctrl = new ionic.controllers.NavController({
navBar: new NavBar({el: navBarEl }), navBar: new ionic.views.NavBar({el: navBarEl }),
content: { el: contentEl }, content: { el: contentEl },
controllers: [{}] controllers: [{}]
}); });

View File

@ -27,11 +27,11 @@ describe('SideMenuController', function() {
}; };
beforeEach(function() { beforeEach(function() {
l = new SideMenu({ el: document.createElement('div'), width: 270 }); l = new ionic.views.SideMenu({ el: document.createElement('div'), width: 270 });
r = new SideMenu({ el: document.createElement('div'), width: 270 }); r = new ionic.views.SideMenu({ el: document.createElement('div'), width: 270 });
c = new Controller({ el: document.createElement('div') }); c = new Controller({ el: document.createElement('div') });
ctrl = new SideMenuController({ ctrl = new ionic.controllers.SideMenuController({
left: l, left: l,
right: r, right: r,
content: c content: c

View File

@ -3,8 +3,8 @@ describe('TabBarController', function() {
beforeEach(function() { beforeEach(function() {
var tabEl = $('<div class="tabs"></div>'); var tabEl = $('<div class="tabs"></div>');
ctrl = new TabBarController({ ctrl = new ionic.controllers.TabBarController({
tabBar: new TabBar({ tabBar: new ionic.views.TabBar({
el: tabEl.get(0) el: tabEl.get(0)
}) })
}); });
@ -65,8 +65,8 @@ describe('TabBarController', function() {
it('Should allow cancelling Controller switch', function() { it('Should allow cancelling Controller switch', function() {
var tabEl = $('<div class="tabs"></div>'); var tabEl = $('<div class="tabs"></div>');
ctrl = new TabBarController({ ctrl = new ionic.controllers.TabBarController({
tabBar: new TabBar({ el: tabEl.get(0) }), tabBar: new ionic.views.TabBar({ el: tabEl.get(0) }),
controllerWillChange: function(Controller) { return false; } controllerWillChange: function(Controller) { return false; }
}); });

6
test/js/events.unit.js Normal file
View File

@ -0,0 +1,6 @@
describe('Ionic Events', function() {
it('Should block all click events', function() {
var a = document.createElement('a');
a.click();
});
});

View File

@ -3,7 +3,7 @@ describe('SideMenu', function() {
beforeEach(function() { beforeEach(function() {
var d = document.createElement('div'); var d = document.createElement('div');
menu = new SideMenu({ menu = new ionic.views.SideMenu({
el: d, el: d,
width: 270 width: 270
}); });

View File

@ -7,7 +7,7 @@ describe('TabBar view', function() {
'<a href="#" class="tab-item">Tab 2</a>' + '<a href="#" class="tab-item">Tab 2</a>' +
'<a href="#" class="tab-item">Tab 3</a>'); '<a href="#" class="tab-item">Tab 3</a>');
tabBar = new TabBar({ tabBar = new ionic.views.TabBar({
el: element.get(0) el: element.get(0)
}); });
@ -98,7 +98,7 @@ describe('TabBarItem view', function() {
'<a href="#" class="tab-item">Tab 2</a>' + '<a href="#" class="tab-item">Tab 2</a>' +
'<a href="#" class="tab-item">Tab 3</a>'); '<a href="#" class="tab-item">Tab 3</a>');
tabBar = new TabBar({ tabBar = new ionic.views.TabBar({
el: element.get(0) el: element.get(0)
}); });