From f54db2ccda399f2677e4ca7588018cb31545a2b4 Mon Sep 17 00:00:00 2001 From: Igor Minar Date: Thu, 8 Mar 2012 15:00:38 -0800 Subject: chore(directives,widgets): reorg the code under directive/ dir --- test/directive/booleanAttrDirSpecs.js | 111 ++++++++++++++++++++++++++++++++++ 1 file changed, 111 insertions(+) create mode 100644 test/directive/booleanAttrDirSpecs.js (limited to 'test/directive/booleanAttrDirSpecs.js') diff --git a/test/directive/booleanAttrDirSpecs.js b/test/directive/booleanAttrDirSpecs.js new file mode 100644 index 00000000..2c47d81a --- /dev/null +++ b/test/directive/booleanAttrDirSpecs.js @@ -0,0 +1,111 @@ +'use strict'; + +describe('boolean attr directives', function() { + var element; + + afterEach(function() { + dealoc(element); + }); + + + it('should bind href', inject(function($rootScope, $compile) { + element = $compile('')($rootScope) + $rootScope.url = 'http://server' + $rootScope.$digest(); + expect(element.attr('href')).toEqual('http://server'); + })); + + + it('should bind disabled', inject(function($rootScope, $compile) { + element = $compile('')($rootScope) + $rootScope.isDisabled = false; + $rootScope.$digest(); + expect(element.attr('disabled')).toBeFalsy(); + $rootScope.isDisabled = true; + $rootScope.$digest(); + expect(element.attr('disabled')).toBeTruthy(); + })); + + + it('should bind checked', inject(function($rootScope, $compile) { + element = $compile('')($rootScope) + $rootScope.isChecked = false; + $rootScope.$digest(); + expect(element.attr('checked')).toBeFalsy(); + $rootScope.isChecked=true; + $rootScope.$digest(); + expect(element.attr('checked')).toBeTruthy(); + })); + + + it('should bind selected', inject(function($rootScope, $compile) { + element = $compile('')($rootScope) + jqLite(document.body).append(element) + $rootScope.isSelected=false; + $rootScope.$digest(); + expect(element.children()[1].selected).toBeFalsy(); + $rootScope.isSelected=true; + $rootScope.$digest(); + expect(element.children()[1].selected).toBeTruthy(); + })); + + + it('should bind readonly', inject(function($rootScope, $compile) { + element = $compile('')($rootScope) + $rootScope.isReadonly=false; + $rootScope.$digest(); + expect(element.attr('readOnly')).toBeFalsy(); + $rootScope.isReadonly=true; + $rootScope.$digest(); + expect(element.attr('readOnly')).toBeTruthy(); + })); + + + it('should bind multiple', inject(function($rootScope, $compile) { + element = $compile('')($rootScope) + $rootScope.isMultiple=false; + $rootScope.$digest(); + expect(element.attr('multiple')).toBeFalsy(); + $rootScope.isMultiple='multiple'; + $rootScope.$digest(); + expect(element.attr('multiple')).toBeTruthy(); + })); + + + it('should bind src', inject(function($rootScope, $compile) { + element = $compile('
')($rootScope) + $rootScope.url = 'http://localhost/'; + $rootScope.$digest(); + expect(element.attr('src')).toEqual('http://localhost/'); + })); + + + it('should bind href and merge with other attrs', inject(function($rootScope, $compile) { + element = $compile('')($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 Text with no Bindings', inject(function($compile, $rootScope) { + forEach(['checked', 'disabled', 'multiple', 'readonly', 'selected'], function(name) { + element = $compile('')($rootScope) + $rootScope.$digest(); + expect(element.attr(name)).toBe(name); + dealoc(element); + }); + + element = $compile('')($rootScope) + $rootScope.$digest(); + expect(element.attr('src')).toEqual('some'); + dealoc(element); + + element = $compile('')($rootScope) + $rootScope.$digest(); + expect(element.attr('href')).toEqual('some'); + dealoc(element); + })); +}); -- cgit v1.2.3