2011-07-17 08:05:43 +00:00
|
|
|
'use strict';
|
|
|
|
|
|
2012-03-08 23:00:38 +00:00
|
|
|
describe('boolean attr directives', function() {
|
2011-11-23 05:28:39 +00:00
|
|
|
var element;
|
|
|
|
|
|
|
|
|
|
afterEach(function() {
|
|
|
|
|
dealoc(element);
|
|
|
|
|
});
|
2010-03-23 21:57:11 +00:00
|
|
|
|
2010-03-25 21:43:05 +00:00
|
|
|
|
2012-04-04 15:12:39 +00:00
|
|
|
it('should properly evaluate 0 as false', inject(function($rootScope, $compile) {
|
|
|
|
|
// jQuery does not treat 0 as false, when setting attr()
|
|
|
|
|
element = $compile('<button ng-disabled="isDisabled">Button</button>')($rootScope)
|
|
|
|
|
$rootScope.isDisabled = 0;
|
|
|
|
|
$rootScope.$digest();
|
|
|
|
|
expect(element.attr('disabled')).toBeFalsy();
|
|
|
|
|
$rootScope.isDisabled = 1;
|
|
|
|
|
$rootScope.$digest();
|
|
|
|
|
expect(element.attr('disabled')).toBeTruthy();
|
|
|
|
|
}));
|
|
|
|
|
|
|
|
|
|
|
2011-10-26 05:21:21 +00:00
|
|
|
it('should bind disabled', inject(function($rootScope, $compile) {
|
2012-03-23 22:53:04 +00:00
|
|
|
element = $compile('<button ng-disabled="isDisabled">Button</button>')($rootScope)
|
2011-10-17 23:56:56 +00:00
|
|
|
$rootScope.isDisabled = false;
|
|
|
|
|
$rootScope.$digest();
|
2011-06-06 19:13:07 +00:00
|
|
|
expect(element.attr('disabled')).toBeFalsy();
|
2011-10-17 23:56:56 +00:00
|
|
|
$rootScope.isDisabled = true;
|
|
|
|
|
$rootScope.$digest();
|
2011-06-06 19:13:07 +00:00
|
|
|
expect(element.attr('disabled')).toBeTruthy();
|
2011-10-17 23:56:56 +00:00
|
|
|
}));
|
2011-06-06 19:13:07 +00:00
|
|
|
|
2012-03-08 23:00:38 +00:00
|
|
|
|
2011-10-26 05:21:21 +00:00
|
|
|
it('should bind checked', inject(function($rootScope, $compile) {
|
2012-03-23 22:53:04 +00:00
|
|
|
element = $compile('<input type="checkbox" ng-checked="isChecked" />')($rootScope)
|
2011-10-17 23:56:56 +00:00
|
|
|
$rootScope.isChecked = false;
|
|
|
|
|
$rootScope.$digest();
|
2011-06-06 19:13:07 +00:00
|
|
|
expect(element.attr('checked')).toBeFalsy();
|
2011-10-17 23:56:56 +00:00
|
|
|
$rootScope.isChecked=true;
|
|
|
|
|
$rootScope.$digest();
|
2011-06-06 19:13:07 +00:00
|
|
|
expect(element.attr('checked')).toBeTruthy();
|
2011-10-17 23:56:56 +00:00
|
|
|
}));
|
2011-06-06 19:13:07 +00:00
|
|
|
|
2012-03-08 23:00:38 +00:00
|
|
|
|
2011-10-26 05:21:21 +00:00
|
|
|
it('should bind selected', inject(function($rootScope, $compile) {
|
2012-03-23 22:53:04 +00:00
|
|
|
element = $compile('<select><option value=""></option><option ng-selected="isSelected">Greetings!</option></select>')($rootScope)
|
2011-09-15 03:36:00 +00:00
|
|
|
jqLite(document.body).append(element)
|
2011-10-17 23:56:56 +00:00
|
|
|
$rootScope.isSelected=false;
|
|
|
|
|
$rootScope.$digest();
|
2011-06-06 19:13:07 +00:00
|
|
|
expect(element.children()[1].selected).toBeFalsy();
|
2011-10-17 23:56:56 +00:00
|
|
|
$rootScope.isSelected=true;
|
|
|
|
|
$rootScope.$digest();
|
2011-06-06 19:13:07 +00:00
|
|
|
expect(element.children()[1].selected).toBeTruthy();
|
2011-10-17 23:56:56 +00:00
|
|
|
}));
|
2011-06-06 19:13:07 +00:00
|
|
|
|
2012-03-08 23:00:38 +00:00
|
|
|
|
2011-10-26 05:21:21 +00:00
|
|
|
it('should bind readonly', inject(function($rootScope, $compile) {
|
2012-03-23 22:53:04 +00:00
|
|
|
element = $compile('<input type="text" ng-readonly="isReadonly" />')($rootScope)
|
2011-10-17 23:56:56 +00:00
|
|
|
$rootScope.isReadonly=false;
|
|
|
|
|
$rootScope.$digest();
|
2011-06-06 19:13:07 +00:00
|
|
|
expect(element.attr('readOnly')).toBeFalsy();
|
2011-10-17 23:56:56 +00:00
|
|
|
$rootScope.isReadonly=true;
|
|
|
|
|
$rootScope.$digest();
|
2011-06-06 19:13:07 +00:00
|
|
|
expect(element.attr('readOnly')).toBeTruthy();
|
2011-10-17 23:56:56 +00:00
|
|
|
}));
|
2011-06-06 19:13:07 +00:00
|
|
|
|
2012-03-08 23:00:38 +00:00
|
|
|
|
2011-10-26 05:21:21 +00:00
|
|
|
it('should bind multiple', inject(function($rootScope, $compile) {
|
2012-03-23 22:53:04 +00:00
|
|
|
element = $compile('<select ng-multiple="isMultiple"></select>')($rootScope)
|
2011-10-17 23:56:56 +00:00
|
|
|
$rootScope.isMultiple=false;
|
|
|
|
|
$rootScope.$digest();
|
2011-06-06 19:13:07 +00:00
|
|
|
expect(element.attr('multiple')).toBeFalsy();
|
2011-10-17 23:56:56 +00:00
|
|
|
$rootScope.isMultiple='multiple';
|
|
|
|
|
$rootScope.$digest();
|
2011-06-06 19:13:07 +00:00
|
|
|
expect(element.attr('multiple')).toBeTruthy();
|
2011-10-17 23:56:56 +00:00
|
|
|
}));
|
2012-03-23 22:53:04 +00:00
|
|
|
});
|
2011-10-17 23:56:56 +00:00
|
|
|
|
2012-03-08 23:00:38 +00:00
|
|
|
|
2012-04-09 18:20:55 +00:00
|
|
|
describe('ngSrc', function() {
|
2011-08-25 23:31:00 +00:00
|
|
|
|
2012-03-23 22:53:04 +00:00
|
|
|
it('should interpolate the expression and bind to src', inject(function($compile, $rootScope) {
|
2012-05-06 23:30:24 +00:00
|
|
|
var element = $compile('<div ng-src="some/{{id}}"></div>')($rootScope);
|
|
|
|
|
|
2011-10-17 23:56:56 +00:00
|
|
|
$rootScope.$digest();
|
2012-03-23 22:53:04 +00:00
|
|
|
expect(element.attr('src')).toEqual('some/');
|
|
|
|
|
|
|
|
|
|
$rootScope.$apply(function() {
|
|
|
|
|
$rootScope.id = 1;
|
|
|
|
|
});
|
|
|
|
|
expect(element.attr('src')).toEqual('some/1');
|
|
|
|
|
|
2011-10-17 23:56:56 +00:00
|
|
|
dealoc(element);
|
2012-03-23 22:53:04 +00:00
|
|
|
}));
|
2012-05-06 23:30:24 +00:00
|
|
|
|
|
|
|
|
if (msie) {
|
|
|
|
|
it('should update the element property as well as the attribute', inject(
|
|
|
|
|
function($compile, $rootScope) {
|
|
|
|
|
// on IE, if "ng:src" directive declaration is used and "src" attribute doesn't exist
|
|
|
|
|
// then calling element.setAttribute('src', 'foo') doesn't do anything, so we need
|
|
|
|
|
// to set the property as well to achieve the desired effect
|
|
|
|
|
|
|
|
|
|
var element = $compile('<div ng-src="some/{{id}}"></div>')($rootScope);
|
|
|
|
|
|
|
|
|
|
$rootScope.$digest();
|
|
|
|
|
expect(element.prop('src')).toEqual('some/');
|
|
|
|
|
|
|
|
|
|
$rootScope.$apply(function() {
|
|
|
|
|
$rootScope.id = 1;
|
|
|
|
|
});
|
|
|
|
|
expect(element.prop('src')).toEqual('some/1');
|
|
|
|
|
|
|
|
|
|
dealoc(element);
|
|
|
|
|
}));
|
|
|
|
|
}
|
2012-03-23 22:53:04 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
2012-04-09 18:20:55 +00:00
|
|
|
describe('ngHref', function() {
|
2012-04-04 22:01:27 +00:00
|
|
|
var element;
|
|
|
|
|
|
|
|
|
|
afterEach(function() {
|
|
|
|
|
dealoc(element);
|
|
|
|
|
});
|
|
|
|
|
|
2011-10-17 23:56:56 +00:00
|
|
|
|
2012-03-23 22:53:04 +00:00
|
|
|
it('should interpolate the expression and bind to href', inject(function($compile, $rootScope) {
|
2012-04-04 22:01:27 +00:00
|
|
|
element = $compile('<div ng-href="some/{{id}}"></div>')($rootScope)
|
2011-10-17 23:56:56 +00:00
|
|
|
$rootScope.$digest();
|
2012-03-23 22:53:04 +00:00
|
|
|
expect(element.attr('href')).toEqual('some/');
|
|
|
|
|
|
|
|
|
|
$rootScope.$apply(function() {
|
|
|
|
|
$rootScope.id = 1;
|
|
|
|
|
});
|
|
|
|
|
expect(element.attr('href')).toEqual('some/1');
|
2012-04-04 22:01:27 +00:00
|
|
|
}));
|
2012-03-23 22:53:04 +00:00
|
|
|
|
2012-04-04 22:01:27 +00:00
|
|
|
|
|
|
|
|
it('should bind href and merge with other attrs', inject(function($rootScope, $compile) {
|
|
|
|
|
element = $compile('<a ng-href="{{url}}" rel="{{rel}}"></a>')($rootScope);
|
|
|
|
|
$rootScope.url = 'http://server';
|
|
|
|
|
$rootScope.rel = 'REL';
|
|
|
|
|
$rootScope.$digest();
|
|
|
|
|
expect(element.attr('href')).toEqual('http://server');
|
|
|
|
|
expect(element.attr('rel')).toEqual('REL');
|
|
|
|
|
}));
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
it('should bind href even if no interpolation', inject(function($rootScope, $compile) {
|
|
|
|
|
element = $compile('<a ng-href="http://server"></a>')($rootScope)
|
|
|
|
|
$rootScope.$digest();
|
|
|
|
|
expect(element.attr('href')).toEqual('http://server');
|
2011-10-17 23:56:56 +00:00
|
|
|
}));
|
2010-12-02 04:29:54 +00:00
|
|
|
});
|