aboutsummaryrefslogtreecommitdiffstats
path: root/test
diff options
context:
space:
mode:
Diffstat (limited to 'test')
-rw-r--r--test/ValidatorsTest.js34
-rw-r--r--test/directivesSpec.js16
-rw-r--r--test/servicesSpec.js113
-rw-r--r--test/widgetsSpec.js22
4 files changed, 124 insertions, 61 deletions
diff --git a/test/ValidatorsTest.js b/test/ValidatorsTest.js
index 49416ae4..b2403eab 100644
--- a/test/ValidatorsTest.js
+++ b/test/ValidatorsTest.js
@@ -88,17 +88,16 @@ describe('Validator:asynchronous', function(){
var value, fn;
beforeEach(function(){
- var invalidWidgets = [];
- invalidWidgets.markInvalid = function(element){
- invalidWidgets.push(element);
- };
+ var invalidWidgets = angularService('$invalidWidgets')();
value = null;
fn = null;
self = {
$element:jqLite('<input />'),
$invalidWidgets:invalidWidgets,
- $updateView: noop
+ $eval: noop
};
+ self.$element.data('$validate', noop);
+ self.$root = self;
});
afterEach(function(){
@@ -122,14 +121,14 @@ describe('Validator:asynchronous', function(){
expect(input.hasClass('ng-input-indicator-wait')).toBeTruthy();
fn("myError");
expect(input.hasClass('ng-input-indicator-wait')).toBeFalsy();
- expect(input.attr('ng-validation-error')).toEqual("myError");
+ expect(input.attr(NG_VALIDATION_ERROR)).toEqual("myError");
scope.$element.remove();
});
it("should not make second request to same value", function(){
asynchronous.call(self, "kai", function(v,f){value=v; fn=f;});
expect(value).toEqual('kai');
- expect(self.$invalidWidgets[0][0]).toEqual(self.$element[0]);
+ expect(self.$invalidWidgets[0]).toEqual(self.$element);
var spy = jasmine.createSpy();
asynchronous.call(self, "kai", spy);
@@ -145,9 +144,26 @@ describe('Validator:asynchronous', function(){
asynchronous.call(self, "second", function(v,f){value=v; secondCb=f;});
firstCb();
- expect(jqLite(self.$element).hasClass('ng-input-indicator-wait')).toBeTruthy();
+ expect(self.$element.hasClass('ng-input-indicator-wait')).toBeTruthy();
secondCb();
- expect(jqLite(self.$element).hasClass('ng-input-indicator-wait')).toBeFalsy();
+ expect(self.$element.hasClass('ng-input-indicator-wait')).toBeFalsy();
});
+
+ it("should handle update function", function(){
+ var scope = angular.compile('<input name="name" ng-validate="asynchronous:asyncFn:updateFn"/>');
+ scope.asyncFn = jasmine.createSpy();
+ scope.updateFn = jasmine.createSpy();
+ scope.name = 'misko';
+ scope.$init();
+ scope.$eval();
+ expect(scope.asyncFn).wasCalledWith('misko', scope.asyncFn.mostRecentCall.args[1]);
+ assertTrue(scope.$element.hasClass('ng-input-indicator-wait'));
+ scope.asyncFn.mostRecentCall.args[1]('myError', {id: 1234, data:'data'});
+ assertFalse(scope.$element.hasClass('ng-input-indicator-wait'));
+ assertEquals('myError', scope.$element.attr('ng-validation-error'));
+ expect(scope.updateFn.mostRecentCall.args[0]).toEqual({id: 1234, data:'data'});
+ scope.$element.remove();
+ });
+
});
diff --git a/test/directivesSpec.js b/test/directivesSpec.js
index 76a12616..1ddd7477 100644
--- a/test/directivesSpec.js
+++ b/test/directivesSpec.js
@@ -57,6 +57,22 @@ describe("directives", function(){
expect(element.attr('alt')).toEqual('myalt');
});
+ it('should remove special attributes on false', function(){
+ var scope = compile('<div disabled="{{disabled}}" readonly="{{readonly}}" checked="{{checked}}"/>');
+ expect(scope.$element.attr('disabled')).toEqual(null);
+ expect(scope.$element.attr('readonly')).toEqual(null);
+ expect(scope.$element.attr('checked')).toEqual(null);
+
+ scope.disabled = true;
+ scope.readonly = true;
+ scope.checked = true;
+ scope.$eval();
+
+ expect(scope.$element.attr('disabled')).not.toEqual(null);
+ expect(scope.$element.attr('readonly')).not.toEqual(null);
+ expect(scope.$element.attr('checked')).not.toEqual(null);
+ });
+
it('should ng-non-bindable', function(){
var scope = compile('<div ng-non-bindable><span ng-bind="name"></span></div>');
scope.$set('name', 'misko');
diff --git a/test/servicesSpec.js b/test/servicesSpec.js
index 715a232e..f917f968 100644
--- a/test/servicesSpec.js
+++ b/test/servicesSpec.js
@@ -9,53 +9,6 @@ describe("services", function(){
expect(scope.$window).toEqual(window);
});
- it("should inject $location", function(){
- scope.$location.parse('http://host:123/p/a/t/h.html?query=value#path?key=value');
- expect(scope.$location.href).toEqual("http://host:123/p/a/t/h.html?query=value#path?key=value");
- expect(scope.$location.protocol).toEqual("http");
- expect(scope.$location.host).toEqual("host");
- expect(scope.$location.port).toEqual("123");
- expect(scope.$location.path).toEqual("/p/a/t/h.html");
- expect(scope.$location.search).toEqual({query:'value'});
- expect(scope.$location.hash).toEqual('path?key=value');
- expect(scope.$location.hashPath).toEqual('path');
- expect(scope.$location.hashSearch).toEqual({key:'value'});
-
- scope.$location.hashPath = 'page=http://path';
- scope.$location.hashSearch = {k:'a=b'};
-
- expect(scope.$location.toString()).toEqual('http://host:123/p/a/t/h.html?query=value#page=http://path?k=a%3Db');
- });
-
- it('should parse file://', function(){
- scope.$location.parse('file:///Users/Shared/misko/work/angular.js/scenario/widgets.html');
- expect(scope.$location.href).toEqual("file:///Users/Shared/misko/work/angular.js/scenario/widgets.html");
- expect(scope.$location.protocol).toEqual("file");
- expect(scope.$location.host).toEqual("");
- expect(scope.$location.port).toEqual(null);
- expect(scope.$location.path).toEqual("/Users/Shared/misko/work/angular.js/scenario/widgets.html");
- expect(scope.$location.search).toEqual({});
- expect(scope.$location.hash).toEqual('');
- expect(scope.$location.hashPath).toEqual('');
- expect(scope.$location.hashSearch).toEqual({});
-
- expect(scope.$location.toString()).toEqual('file:///Users/Shared/misko/work/angular.js/scenario/widgets.html#');
- });
-
- it('should update url on hash change', function(){
- scope.$location.parse('http://server/#path?a=b');
- scope.$location.hash = '';
- expect(scope.$location.toString()).toEqual('http://server/#');
- expect(scope.$location.hashPath).toEqual('');
- });
-
- it('should update url on hashPath change', function(){
- scope.$location.parse('http://server/#path?a=b');
- scope.$location.hashPath = '';
- expect(scope.$location.toString()).toEqual('http://server/#?a=b');
- expect(scope.$location.hash).toEqual('?a=b');
- });
-
xit('should add stylesheets', function(){
scope.$document = {
getElementsByTagName: function(name){
@@ -64,9 +17,71 @@ describe("services", function(){
}
};
scope.$document.addStyleSheet('css/angular.css');
-
});
+ describe("$location", function(){
+ it("should inject $location", function(){
+ scope.$location.parse('http://host:123/p/a/t/h.html?query=value#path?key=value');
+ expect(scope.$location.href).toEqual("http://host:123/p/a/t/h.html?query=value#path?key=value");
+ expect(scope.$location.protocol).toEqual("http");
+ expect(scope.$location.host).toEqual("host");
+ expect(scope.$location.port).toEqual("123");
+ expect(scope.$location.path).toEqual("/p/a/t/h.html");
+ expect(scope.$location.search).toEqual({query:'value'});
+ expect(scope.$location.hash).toEqual('path?key=value');
+ expect(scope.$location.hashPath).toEqual('path');
+ expect(scope.$location.hashSearch).toEqual({key:'value'});
+
+ scope.$location.hashPath = 'page=http://path';
+ scope.$location.hashSearch = {k:'a=b'};
+
+ expect(scope.$location.toString()).toEqual('http://host:123/p/a/t/h.html?query=value#page=http://path?k=a%3Db');
+ });
+
+ it('should parse file://', function(){
+ scope.$location.parse('file:///Users/Shared/misko/work/angular.js/scenario/widgets.html');
+ expect(scope.$location.href).toEqual("file:///Users/Shared/misko/work/angular.js/scenario/widgets.html");
+ expect(scope.$location.protocol).toEqual("file");
+ expect(scope.$location.host).toEqual("");
+ expect(scope.$location.port).toEqual(null);
+ expect(scope.$location.path).toEqual("/Users/Shared/misko/work/angular.js/scenario/widgets.html");
+ expect(scope.$location.search).toEqual({});
+ expect(scope.$location.hash).toEqual('');
+ expect(scope.$location.hashPath).toEqual('');
+ expect(scope.$location.hashSearch).toEqual({});
+
+ expect(scope.$location.toString()).toEqual('file:///Users/Shared/misko/work/angular.js/scenario/widgets.html#');
+ });
+
+ it('should update url on hash change', function(){
+ scope.$location.parse('http://server/#path?a=b');
+ scope.$location.hash = '';
+ expect(scope.$location.toString()).toEqual('http://server/#');
+ expect(scope.$location.hashPath).toEqual('');
+ });
+
+ it('should update url on hashPath change', function(){
+ scope.$location.parse('http://server/#path?a=b');
+ scope.$location.hashPath = '';
+ expect(scope.$location.toString()).toEqual('http://server/#?a=b');
+ expect(scope.$location.hash).toEqual('?a=b');
+ });
+
+ it('should update hash before any processing', function(){
+ var scope = compile('<div>');
+ var log = '';
+ scope.$watch('$location.hash', function(){
+ log += this.$location.hashPath + ';';
+ });
+ expect(log).toEqual(';');
+
+ log = '';
+ scope.$location.hash = '/abc';
+ scope.$eval();
+ expect(log).toEqual('/abc;');
+ });
+
+ });
});
describe("service $invalidWidgets", function(){
@@ -135,5 +150,7 @@ describe("service $route", function(){
expect(log).toEqual('onChange();');
expect(scope.$route.current).toEqual(null);
+ scope.$route.when('/NONE', {template:'instant update'});
+ expect(scope.$route.current.template).toEqual('instant update');
});
});
diff --git a/test/widgetsSpec.js b/test/widgetsSpec.js
index 04b8b1ec..ae6a17df 100644
--- a/test/widgetsSpec.js
+++ b/test/widgetsSpec.js
@@ -76,6 +76,18 @@ describe("input widget", function(){
expect(element.attr('ng-validation-error')).toEqual('Not a number');
});
+ it("should ignore disabled widgets", function(){
+ compile('<input type="text" name="price" ng-required disabled/>');
+ expect(element.hasClass('ng-validation-error')).toBeFalsy();
+ expect(element.attr('ng-validation-error')).toBeFalsy();
+ });
+
+ it("should ignore readonly widgets", function(){
+ compile('<input type="text" name="price" ng-required readonly/>');
+ expect(element.hasClass('ng-validation-error')).toBeFalsy();
+ expect(element.attr('ng-validation-error')).toBeFalsy();
+ });
+
it("should process ng-required", function(){
compile('<input type="text" name="price" ng-required/>');
expect(element.hasClass('ng-validation-error')).toBeTruthy();
@@ -244,13 +256,15 @@ describe('ng:switch', function(){
describe('ng:include', function(){
it('should include on external file', function() {
- var element = jqLite('<ng:include src="myUrl"></ng:include>');
+ var element = jqLite('<ng:include src="url" scope="childScope"></ng:include>');
var scope = compile(element);
- scope.$browser.xhr.expect('GET', 'myUrl').respond('{{1+2}}');
+ scope.childScope = createScope();
+ scope.childScope.name = 'misko';
+ scope.url = 'myUrl';
+ scope.$browser.xhr.expect('GET', 'myUrl').respond('{{name}}');
scope.$init();
- expect(sortedHtml(element)).toEqual('<ng:include src="myUrl" switch-instance="compiled"></ng:include>');
scope.$browser.xhr.flush();
- expect(element.text()).toEqual('3');
+ expect(element.text()).toEqual('misko');
});
});