'use strict'; describe('Ionic List', function() { var compile, scope, listElement, listCtrl; beforeEach(module('ionic.ui.list')); beforeEach(inject(function($compile, $rootScope, $controller) { compile = $compile; scope = $rootScope; })); beforeEach(inject(function (_$compile_, _$rootScope_) { scope.showDelete = false; scope.showReorder = false; listElement = angular.element(''); listElement = _$compile_(listElement)(scope); listCtrl = listElement.controller('list'); scope.$digest(); })); it('Should init', function() { var element = compile('' + '' + '' + '')(scope); expect(element.children().length).toBe(2); }); it('Should add animation class', function() { var element = compile('')(scope); expect(element.hasClass('my-animation')).toBe(true); }); it('Should add list-editing class', function() { expect(listElement.hasClass('list-editing')).toBe(false); scope.showDelete = true; scope.$digest(); expect(listElement.hasClass('list-editing')).toBe(true); }); it('Should add list-reordering class', function() { expect(listElement.hasClass('list-reordering')).toBe(false); scope.showReorder = true; scope.$digest(); expect(listElement.hasClass('list-reordering')).toBe(true); }); it('Should add item-options-hide class', function() { expect(listElement.hasClass('item-options-hide')).toBe(false); scope.showReorder = true; scope.$digest(); expect(listElement.hasClass('item-options-hide')).toBe(true); }); }); describe('Ionic Item Directive', function () { var $rootScope, $compile, listCtrl, options, listScope, itemScope, listElement, itemElement; beforeEach(module('ionic.ui.list')); beforeEach(inject(function (_$compile_, _$rootScope_) { $rootScope = _$rootScope_; $compile = _$compile_; $rootScope.showDelete = false; listElement = angular.element(''); listElement = _$compile_(listElement)($rootScope); listScope = listElement.isolateScope(); listCtrl = listElement.controller('list'); itemElement = angular.element('').appendTo(listElement); itemElement = _$compile_(itemElement)($rootScope); $rootScope.$digest(); itemScope = itemElement.isolateScope(); })); it('Should set item type from item attribute', inject(function ($timeout) { itemElement = angular.element('').appendTo(listElement); itemElement = $compile(itemElement)($rootScope); $rootScope.$digest(); itemScope = itemElement.isolateScope(); expect(itemScope.itemClass).toBe(undefined); itemElement = angular.element('').appendTo(listElement); itemElement = $compile(itemElement)($rootScope); $rootScope.$digest(); itemScope = itemElement.isolateScope(); expect(itemScope.itemClass).toBe("item-type-test"); expect(itemElement.hasClass('item-type-test')).toBe(true); })); it('Should set item type from list attribute', inject(function ($timeout) { listElement = angular.element(''); listElement = $compile(listElement)($rootScope); itemElement = angular.element('').appendTo(listElement); itemElement = $compile(itemElement)($rootScope); $rootScope.$digest(); itemScope = itemElement.isolateScope(); expect(itemScope.itemClass).toBe('list-item-type-test'); expect(itemElement.hasClass('list-item-type-test')).toBe(true); })); it('Should item option buttons from item attribute', inject(function ($timeout) { itemElement = angular.element('').appendTo(listElement); itemElement = $compile(itemElement)($rootScope); $rootScope.$digest(); itemScope = itemElement.isolateScope(); expect(itemScope.optionButtons()).toBe(undefined); expect(itemScope.itemOptionButtons).toBe(undefined); expect(itemElement.find('.item-options').length).toBe(0); $rootScope.buttons = [ { text: 'Edit' }, { text: 'Cancel' } ]; itemElement = angular.element('').appendTo(listElement); itemElement = $compile(itemElement)($rootScope); $rootScope.$digest(); itemScope = itemElement.isolateScope(); expect(itemScope.optionButtons().length).toBe(2); expect(itemScope.itemOptionButtons.length).toBe(2); expect(itemElement.find('.item-options').find('button').length).toBe(2); })); it('Should item option buttons from list attribute', inject(function ($timeout) { $rootScope.buttons = [ { text: 'Edit' }, { text: 'Cancel' } ]; listElement = angular.element(''); listElement = $compile(listElement)($rootScope); listScope = listElement.isolateScope(); expect(listScope.optionButtons().length ).toBe(2); itemElement = angular.element('').appendTo(listElement); itemElement = $compile(itemElement)($rootScope); $rootScope.$digest(); itemScope = itemElement.isolateScope(); expect(itemScope.optionButtons()).toBe(undefined); expect(itemScope.itemOptionButtons.length).toBe(2); expect(itemElement.find('.item-options').find('button').length).toBe(2); })); it('Should have no option buttons by disabling item canSwipe', inject(function ($timeout) { $rootScope.buttons = [ { text: 'Edit' }, { text: 'Cancel' } ]; itemElement = angular.element('').appendTo(listElement); itemElement = $compile(itemElement)($rootScope); $rootScope.$digest(); itemScope = itemElement.isolateScope(); expect(itemScope.itemOptionButtons).toBe(undefined); })); it('Should have no option buttons by disabling list canSwipe', inject(function ($timeout) { $rootScope.buttons = [ { text: 'Edit' }, { text: 'Cancel' } ]; listElement = angular.element(''); listElement = $compile(listElement)($rootScope); listScope = listElement.isolateScope(); expect(listScope.optionButtons().length ).toBe(2); itemElement = angular.element('').appendTo(listElement); itemElement = $compile(itemElement)($rootScope); $rootScope.$digest(); itemScope = itemElement.isolateScope(); expect(itemScope.itemOptionButtons).toBe(undefined); })); it('Should hide delete w/ item can-delete attribute true but no list or item onDelete', inject(function ($timeout) { itemElement = angular.element('').appendTo(listElement); itemElement = $compile(itemElement)($rootScope); $rootScope.$digest(); itemScope = itemElement.isolateScope(); expect(itemScope.deleteClick).toBe(undefined); expect(itemElement.find('.item-edit').length).toBe(0); })); it('Should hide delete w/ item can-delete attribute false but with item onDelete', inject(function ($timeout) { $rootScope.onDelete = function() {}; itemElement = angular.element('').appendTo(listElement); itemElement = $compile(itemElement)($rootScope); $rootScope.$digest(); itemScope = itemElement.isolateScope(); expect(itemScope.deleteClick).toBe(undefined); expect(itemElement.find('.item-edit').length).toBe(0); })); it('Should show delete w/ no item can-delete attribute but with item onDelete', inject(function ($timeout) { $rootScope.onDelete = function() {}; itemElement = angular.element('').appendTo(listElement); itemElement = $compile(itemElement)($rootScope); $rootScope.$digest(); itemScope = itemElement.isolateScope(); expect(itemScope.deleteClick).not.toBe(undefined); expect(itemElement.find('.item-edit').length).toBe(1); expect(itemScope.deleteIconClass).toBe("test-icon"); })); it('Should hide delete w/ list can-delete attribute true but no list or item onDelete', inject(function ($timeout) { $rootScope.onDelete = function() {}; listElement = angular.element(''); listElement = $compile(listElement)($rootScope); listScope = listElement.isolateScope(); itemElement = angular.element('').appendTo(listElement); itemElement = $compile(itemElement)($rootScope); $rootScope.$digest(); itemScope = itemElement.isolateScope(); expect(itemScope.deleteClick).toBe(undefined); expect(itemElement.find('.item-edit').length).toBe(0); })); it('Should hide delete w/ list can-delete attribute false but with list onDelete', inject(function ($timeout) { $rootScope.onDelete = function() {}; listElement = angular.element(''); listElement = $compile(listElement)($rootScope); listScope = listElement.isolateScope(); itemElement = angular.element('').appendTo(listElement); itemElement = $compile(itemElement)($rootScope); $rootScope.$digest(); itemScope = itemElement.isolateScope(); expect(itemScope.deleteClick).toBe(undefined); expect(itemElement.find('.item-edit').length).toBe(0); })); it('Should hide delete w/ list can-delete attribute false but with item onDelete', inject(function ($timeout) { $rootScope.onDelete = function() {}; listElement = angular.element(''); listElement = $compile(listElement)($rootScope); listScope = listElement.isolateScope(); itemElement = angular.element('').appendTo(listElement); itemElement = $compile(itemElement)($rootScope); $rootScope.$digest(); itemScope = itemElement.isolateScope(); expect(itemScope.deleteClick).toBe(undefined); expect(itemElement.find('.item-edit').length).toBe(0); })); it('Should show delete w/ no can-delete attribute but with list onDelete', inject(function ($timeout) { $rootScope.onDelete = function() {}; listElement = angular.element(''); listElement = $compile(listElement)($rootScope); listScope = listElement.isolateScope(); itemElement = angular.element('').appendTo(listElement); itemElement = $compile(itemElement)($rootScope); $rootScope.$digest(); itemScope = itemElement.isolateScope(); expect(itemScope.deleteClick).not.toBe(undefined); expect(itemElement.find('.item-edit').length).toBe(1); expect(itemScope.deleteIconClass).toBe("test-icon"); })); it('Should not be able to reorder cuz no item or list can-reorder attribute true', inject(function ($timeout) { itemElement = angular.element('').appendTo(listElement); itemElement = $compile(itemElement)($rootScope); $rootScope.$digest(); itemScope = itemElement.isolateScope(); expect(itemScope.reorderIconClass).toBe(undefined); expect(itemElement.find('.item-drag').length).toBe(0); })); it('Should be able to reorder cuz item can-reorder attribute true', inject(function ($timeout) { itemElement = angular.element('').appendTo(listElement); itemElement = $compile(itemElement)($rootScope); $rootScope.$digest(); itemScope = itemElement.isolateScope(); expect(itemScope.reorderIconClass).toBe('test-icon'); expect(itemElement.find('.item-drag').length).toBe(1); })); it('Should be able to reorder cuz list can-reorder attribute true', inject(function ($timeout) { listElement = angular.element(''); listElement = $compile(listElement)($rootScope); listScope = listElement.isolateScope(); itemElement = angular.element('').appendTo(listElement); itemElement = $compile(itemElement)($rootScope); $rootScope.$digest(); itemScope = itemElement.isolateScope(); expect(itemScope.reorderIconClass).toBe('test-icon'); expect(itemElement.find('.item-drag').length).toBe(1); })); it('Should not have options cuz no optionButtons', inject(function ($timeout) { itemElement = angular.element('').appendTo(listElement); itemElement = $compile(itemElement)($rootScope); $rootScope.$digest(); itemScope = itemElement.isolateScope(); expect(itemScope.itemOptionButtons).toBe(undefined); expect(itemElement.find('.item-options').length).toBe(0); })); it('Should be able to reorder cuz list can-reorder attribute false and item can-reorder true', inject(function ($timeout) { listElement = angular.element(''); listElement = $compile(listElement)($rootScope); listScope = listElement.isolateScope(); itemElement = angular.element('').appendTo(listElement); itemElement = $compile(itemElement)($rootScope); $rootScope.$digest(); itemScope = itemElement.isolateScope(); expect(itemScope.reorderIconClass).toBe('ion-navicon'); expect(itemElement.find('.item-drag').length).toBe(1); })); it('Should not have options cuz item can-swipe false', inject(function ($timeout) { $rootScope.optionButtons = [{text:'BUTTON'}]; itemElement = angular.element('').appendTo(listElement); itemElement = $compile(itemElement)($rootScope); $rootScope.$digest(); itemScope = itemElement.isolateScope(); expect(itemScope.itemOptionButtons).toBe(undefined); expect(itemElement.find('.item-options').length).toBe(0); })); it('Should not have options cuz list can-swipe false', inject(function ($timeout) { $rootScope.optionButtons = [{text:'BUTTON'}]; listElement = angular.element(''); listElement = $compile(listElement)($rootScope); listScope = listElement.isolateScope(); itemElement = angular.element('').appendTo(listElement); itemElement = $compile(itemElement)($rootScope); $rootScope.$digest(); itemScope = itemElement.isolateScope(); expect(itemScope.itemOptionButtons).toBe(undefined); expect(itemElement.find('.item-options').length).toBe(0); })); it('Should have options cuz item option-buttons and no can-swipe false', inject(function ($timeout) { $rootScope.optionButtons = [{text:'BUTTON'}]; itemElement = angular.element('').appendTo(listElement); itemElement = $compile(itemElement)($rootScope); $rootScope.$digest(); itemScope = itemElement.isolateScope(); expect(itemScope.itemOptionButtons.length).toBe(1); expect(itemElement.find('.item-options').find('button').length).toBe(1); })); it('Should have options cuz list option-buttons and no can-swipe false', inject(function ($timeout) { $rootScope.optionButtons = [{text:'BUTTON'}]; listElement = angular.element(''); listElement = $compile(listElement)($rootScope); listScope = listElement.isolateScope(); itemElement = angular.element('').appendTo(listElement); itemElement = $compile(itemElement)($rootScope); $rootScope.$digest(); itemScope = itemElement.isolateScope(); expect(itemScope.itemOptionButtons.length).toBe(1); expect(itemElement.find('.item-options').find('button').length).toBe(1); })); }); describe('Ionic Link Item Directive', function () { var $rootScope, $compile, listCtrl, options, listScope, itemScope, listElement, itemElement; beforeEach(module('ionic.ui.list')); beforeEach(inject(function (_$compile_, _$rootScope_) { $rootScope = _$rootScope_; $compile = _$compile_; listElement = angular.element(''); listElement = _$compile_(listElement)($rootScope); listScope = listElement.isolateScope(); listCtrl = listElement.controller('list'); itemElement = angular.element('').appendTo(listElement); itemElement = _$compile_(itemElement)($rootScope); $rootScope.$digest(); itemScope = itemElement.isolateScope(); })); it('Should set link-item href', inject(function ($timeout) { itemElement = angular.element('').appendTo(listElement); itemElement = $compile(itemElement)($rootScope); $rootScope.$digest(); itemScope = itemElement.isolateScope(); expect(itemScope.href).toBe("http://drifty.com/"); expect(itemElement.attr('href')).toBe("http://drifty.com/"); })); });