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/directivesSpec.js | 599 ------------------------------------------------- 1 file changed, 599 deletions(-) delete mode 100644 test/directivesSpec.js (limited to 'test/directivesSpec.js') diff --git a/test/directivesSpec.js b/test/directivesSpec.js deleted file mode 100644 index 1ce6090b..00000000 --- a/test/directivesSpec.js +++ /dev/null @@ -1,599 +0,0 @@ -'use strict'; - -describe("directive", function() { - var element; - - beforeEach(function() { - element = null; - }); - - afterEach(function() { - dealoc(element); - }); - - - var $filterProvider, element; - - beforeEach(module(['$filterProvider', function(provider){ - $filterProvider = provider; - }])); - - afterEach(function() { - dealoc(element); - }); - - it("should ng:init", inject(function($rootScope, $compile) { - element = $compile('
')($rootScope); - expect($rootScope.a).toEqual(123); - })); - - describe('ng:bind', function() { - it('should set text', inject(function($rootScope, $compile) { - element = $compile('
')($rootScope); - expect(element.text()).toEqual(''); - $rootScope.a = 'misko'; - $rootScope.$digest(); - expect(element.hasClass('ng-binding')).toEqual(true); - expect(element.text()).toEqual('misko'); - })); - - it('should set text to blank if undefined', inject(function($rootScope, $compile) { - element = $compile('
')($rootScope); - $rootScope.a = 'misko'; - $rootScope.$digest(); - expect(element.text()).toEqual('misko'); - $rootScope.a = undefined; - $rootScope.$digest(); - expect(element.text()).toEqual(''); - $rootScope.a = null; - $rootScope.$digest(); - expect(element.text()).toEqual(''); - })); - - it('should set html', inject(function($rootScope, $compile) { - element = $compile('
')($rootScope); - $rootScope.html = '
hello
'; - $rootScope.$digest(); - expect(lowercase(element.html())).toEqual('
hello
'); - })); - - it('should set unsafe html', inject(function($rootScope, $compile) { - element = $compile('
')($rootScope); - $rootScope.html = '
hello
'; - $rootScope.$digest(); - expect(lowercase(element.html())).toEqual('
hello
'); - })); - - it('should suppress rendering of falsy values', inject(function($rootScope, $compile) { - element = $compile('
{{ null }}{{ undefined }}{{ "" }}-{{ 0 }}{{ false }}
')($rootScope); - $rootScope.$digest(); - expect(element.text()).toEqual('-0false'); - })); - - it('should render object as JSON ignore $$', inject(function($rootScope, $compile) { - element = $compile('
{{ {key:"value", $$key:"hide"} }}
')($rootScope); - $rootScope.$digest(); - expect(fromJson(element.text())).toEqual({key:'value'}); - })); - }); - - describe('ng:bind-template', function() { - it('should ng:bind-template', inject(function($rootScope, $compile) { - element = $compile('
')($rootScope); - $rootScope.name = 'Misko'; - $rootScope.$digest(); - expect(element.hasClass('ng-binding')).toEqual(true); - expect(element.text()).toEqual('Hello Misko!'); - })); - - it('should render object as JSON ignore $$', inject(function($rootScope, $compile) { - element = $compile('
{{ {key:"value", $$key:"hide"}  }}
')($rootScope); - $rootScope.$digest(); - expect(fromJson(element.text())).toEqual({key:'value'}); - })); - - }); - - describe('ng:bind-attr', function() { - it('should bind attributes', inject(function($rootScope, $compile) { - element = $compile('
')($rootScope); - $rootScope.$digest(); - expect(element.attr('src')).toEqual('http://localhost/mysrc'); - expect(element.attr('alt')).toEqual('myalt'); - })); - - it('should not pretty print JSON in attributes', inject(function($rootScope, $compile) { - element = $compile('{{ {a:1} }}')($rootScope); - $rootScope.$digest(); - expect(element.attr('alt')).toEqual('{"a":1}'); - })); - - it('should remove special attributes on false', inject(function($rootScope, $compile) { - element = $compile('')($rootScope); - var input = element[0]; - expect(input.disabled).toEqual(false); - expect(input.readOnly).toEqual(false); - expect(input.checked).toEqual(false); - - $rootScope.disabled = true; - $rootScope.readonly = true; - $rootScope.checked = true; - $rootScope.$digest(); - - expect(input.disabled).toEqual(true); - expect(input.readOnly).toEqual(true); - expect(input.checked).toEqual(true); - })); - - }); - - describe('ng:click', function() { - it('should get called on a click', inject(function($rootScope, $compile) { - element = $compile('
')($rootScope); - $rootScope.$digest(); - expect($rootScope.clicked).toBeFalsy(); - - browserTrigger(element, 'click'); - expect($rootScope.clicked).toEqual(true); - })); - - it('should pass event object', inject(function($rootScope, $compile) { - element = $compile('
')($rootScope); - $rootScope.$digest(); - - browserTrigger(element, 'click'); - expect($rootScope.event).toBeDefined(); - })); - }); - - - describe('ng:submit', function() { - it('should get called on form submit', inject(function($rootScope, $compile) { - element = $compile('
' + - '' + - '
')($rootScope); - $rootScope.$digest(); - expect($rootScope.submitted).not.toBeDefined(); - - browserTrigger(element.children()[0]); - expect($rootScope.submitted).toEqual(true); - })); - }); - - describe('ng:class', function() { - it('should add new and remove old classes dynamically', inject(function($rootScope, $compile) { - element = $compile('
')($rootScope); - $rootScope.dynClass = 'A'; - $rootScope.$digest(); - expect(element.hasClass('existing')).toBe(true); - expect(element.hasClass('A')).toBe(true); - - $rootScope.dynClass = 'B'; - $rootScope.$digest(); - expect(element.hasClass('existing')).toBe(true); - expect(element.hasClass('A')).toBe(false); - expect(element.hasClass('B')).toBe(true); - - delete $rootScope.dynClass; - $rootScope.$digest(); - expect(element.hasClass('existing')).toBe(true); - expect(element.hasClass('A')).toBe(false); - expect(element.hasClass('B')).toBe(false); - })); - - - it('should support adding multiple classes via an array', inject(function($rootScope, $compile) { - element = $compile('
')($rootScope); - $rootScope.$digest(); - expect(element.hasClass('existing')).toBeTruthy(); - expect(element.hasClass('A')).toBeTruthy(); - expect(element.hasClass('B')).toBeTruthy(); - })); - - - it('should support adding multiple classes conditionally via a map of class names to boolean' + - 'expressions', inject(function($rootScope, $compile) { - var element = $compile( - '
' + - '
')($rootScope); - $rootScope.conditionA = true; - $rootScope.$digest(); - expect(element.hasClass('existing')).toBeTruthy(); - expect(element.hasClass('A')).toBeTruthy(); - expect(element.hasClass('B')).toBeFalsy(); - expect(element.hasClass('AnotB')).toBeTruthy(); - - $rootScope.conditionB = function() { return true }; - $rootScope.$digest(); - expect(element.hasClass('existing')).toBeTruthy(); - expect(element.hasClass('A')).toBeTruthy(); - expect(element.hasClass('B')).toBeTruthy(); - expect(element.hasClass('AnotB')).toBeFalsy(); - })); - - - it('should support adding multiple classes via a space delimited string', inject(function($rootScope, $compile) { - element = $compile('
')($rootScope); - $rootScope.$digest(); - expect(element.hasClass('existing')).toBeTruthy(); - expect(element.hasClass('A')).toBeTruthy(); - expect(element.hasClass('B')).toBeTruthy(); - })); - - - it('should preserve class added post compilation with pre-existing classes', inject(function($rootScope, $compile) { - element = $compile('
')($rootScope); - $rootScope.dynClass = 'A'; - $rootScope.$digest(); - expect(element.hasClass('existing')).toBe(true); - - // add extra class, change model and eval - element.addClass('newClass'); - $rootScope.dynClass = 'B'; - $rootScope.$digest(); - - expect(element.hasClass('existing')).toBe(true); - expect(element.hasClass('B')).toBe(true); - expect(element.hasClass('newClass')).toBe(true); - })); - - - it('should preserve class added post compilation without pre-existing classes"', inject(function($rootScope, $compile) { - element = $compile('
')($rootScope); - $rootScope.dynClass = 'A'; - $rootScope.$digest(); - expect(element.hasClass('A')).toBe(true); - - // add extra class, change model and eval - element.addClass('newClass'); - $rootScope.dynClass = 'B'; - $rootScope.$digest(); - - expect(element.hasClass('B')).toBe(true); - expect(element.hasClass('newClass')).toBe(true); - })); - - - it('should preserve other classes with similar name"', inject(function($rootScope, $compile) { - element = $compile('
')($rootScope); - $rootScope.dynCls = 'panel'; - $rootScope.$digest(); - $rootScope.dynCls = 'foo'; - $rootScope.$digest(); - expect(element[0].className).toBe('ui-panel ui-selected ng-scope foo'); - })); - - - it('should not add duplicate classes', inject(function($rootScope, $compile) { - element = $compile('
')($rootScope); - $rootScope.dynCls = 'panel'; - $rootScope.$digest(); - expect(element[0].className).toBe('panel bar ng-scope'); - })); - - - it('should remove classes even if it was specified via class attribute', inject(function($rootScope, $compile) { - element = $compile('
')($rootScope); - $rootScope.dynCls = 'panel'; - $rootScope.$digest(); - $rootScope.dynCls = 'window'; - $rootScope.$digest(); - expect(element[0].className).toBe('bar ng-scope window'); - })); - - - it('should remove classes even if they were added by another code', inject(function($rootScope, $compile) { - element = $compile('
')($rootScope); - $rootScope.dynCls = 'foo'; - $rootScope.$digest(); - element.addClass('foo'); - $rootScope.dynCls = ''; - $rootScope.$digest(); - })); - - - it('should convert undefined and null values to an empty string', inject(function($rootScope, $compile) { - element = $compile('
')($rootScope); - $rootScope.dynCls = [undefined, null]; - $rootScope.$digest(); - })); - - - it('should ng:class odd/even', inject(function($rootScope, $compile) { - element = $compile('