From 4460328bc1173f5d97fb4ff54edc041968486fce Mon Sep 17 00:00:00 2001
From: Misko Hevery
Date: Sat, 23 Jan 2010 15:54:58 -0800
Subject: lots of cleanup to get it ready for OS
---
test/AngularTest.js | 15 -------
test/BinderTest.js | 105 +++++++++++++++++++++++++++--------------------
test/ControlBarTest.js | 2 -
test/ExternalApiTest.js | 15 -------
test/JsonTest.js | 11 +++++
test/ScenarioSpec.js | 66 +++++++++++++++++++++++++++++
test/ScopeTest.js | 2 +-
test/formsTest.js | 18 --------
test/testabilityPatch.js | 8 ++--
9 files changed, 142 insertions(+), 100 deletions(-)
delete mode 100644 test/ControlBarTest.js
delete mode 100644 test/ExternalApiTest.js
create mode 100644 test/ScenarioSpec.js
delete mode 100644 test/formsTest.js
(limited to 'test')
diff --git a/test/AngularTest.js b/test/AngularTest.js
index 9610ef76..a9146adf 100644
--- a/test/AngularTest.js
+++ b/test/AngularTest.js
@@ -1,20 +1,5 @@
AngularTest = TestCase('AngularTest');
-AngularTest.prototype.testDefaultDatabasePathFromSubdomain = function() {
- var loader = new Angular(null, null, {server:"http://account.getangular.com", database:"database"});
- loader.computeConfiguration();
- assertEquals("database", loader.config.database);
-
- loader = new Angular(null, null, {server:"http://account.getangular.com"});
- loader.computeConfiguration();
- assertEquals("account", loader.config.database);
-
- loader = new Angular(null, null, {server:"https://account.getangular.com"});
- loader.computeConfiguration();
- assertEquals("account", loader.config.database);
-};
-
-
UrlWatcherTest = TestCase('UrlWatcherTest');
diff --git a/test/BinderTest.js b/test/BinderTest.js
index 0ffd2120..bbb3eb8f 100644
--- a/test/BinderTest.js
+++ b/test/BinderTest.js
@@ -5,10 +5,10 @@ function compile(content, initialScope, config) {
config = config || {autoSubmit:true};
var scope = new Scope(initialScope, "ROOT");
h.data('scope', scope);
- var binder = new Binder(h[0], new WidgetFactory(), new MockUrlWatcher(), config);
+ var binder = new Binder(h[0], new WidgetFactory(), new MockLocation(), config);
var datastore = new DataStore();
scope.set("$datastore", datastore);
- scope.set("$binder", binder);
+ scope.set("$updateView", _(binder.updateView).bind(binder));
scope.set("$anchor", binder.anchor);
binder.entity(scope);
binder.compile();
@@ -120,7 +120,7 @@ BinderTest.prototype.testChangingTextareaUpdatesModel = function(){
var form = html('');
var scope = new Scope({model:{}});
form.data('scope', scope);
- var binder = new Binder(form.get(0), new WidgetFactory(), new MockUrlWatcher());
+ var binder = new Binder(form.get(0), new WidgetFactory(), new MockLocation());
binder.compile();
binder.updateView();
assertEquals(scope.get('model').note, 'abc');
@@ -131,7 +131,7 @@ BinderTest.prototype.testChangingRadioUpdatesModel = function(){
'');
var scope = new Scope({model:{}});
form.data('scope', scope);
- var binder = new Binder(form.get(0), new WidgetFactory(), new MockUrlWatcher());
+ var binder = new Binder(form.get(0), new WidgetFactory(), new MockLocation());
binder.compile();
binder.updateView();
assertEquals(scope.get('model').price, 'A');
@@ -141,7 +141,7 @@ BinderTest.prototype.testChangingCheckboxUpdatesModel = function(){
var form = html('');
var scope = new Scope({model:{}});
form.data('scope', scope);
- var binder = new Binder(form.get(0), new WidgetFactory(), new MockUrlWatcher());
+ var binder = new Binder(form.get(0), new WidgetFactory(), new MockLocation());
binder.compile();
binder.updateView();
assertEquals('A', scope.get('model').price);
@@ -157,7 +157,7 @@ BinderTest.prototype.testChangingSelectNonSelectedUpdatesModel = function(){
var form = html('');
var scope = new Scope({model:{}});
form.data('scope', scope);
- var binder = new Binder(form.get(0), new WidgetFactory(), new MockUrlWatcher());
+ var binder = new Binder(form.get(0), new WidgetFactory(), new MockLocation());
binder.compile();
binder.updateView();
assertEquals('A', scope.get('model').price);
@@ -171,7 +171,7 @@ BinderTest.prototype.testChangingMultiselectUpdatesModel = function(){
'');
var scope = new Scope({Invoice:{}});
form.data('scope', scope);
- var binder = new Binder(form.get(0), new WidgetFactory(), new MockUrlWatcher());
+ var binder = new Binder(form.get(0), new WidgetFactory(), new MockLocation());
binder.compile();
binder.updateView();
assertJsonEquals(["A", "B"], scope.get('Invoice').options);
@@ -181,7 +181,7 @@ BinderTest.prototype.testChangingSelectSelectedUpdatesModel = function(){
var form = html('');
var scope = new Scope({model:{}});
form.data('scope', scope);
- var binder = new Binder(form.get(0), new WidgetFactory(), new MockUrlWatcher());
+ var binder = new Binder(form.get(0), new WidgetFactory(), new MockLocation());
binder.compile();
binder.updateView();
assertEquals(scope.get('model').price, 'b');
@@ -210,7 +210,7 @@ BinderTest.prototype.testApplyTextBindings = function(){
var form = html('
x
');
var scope = new Scope({model:{a:123}});
form.data('scope', scope);
- var binder = new Binder(form.get(0), null, new MockUrlWatcher());
+ var binder = new Binder(form.get(0), null, new MockLocation());
binder.compile();
binder.updateView();
assertEquals('123', form.text());
@@ -287,7 +287,7 @@ BinderTest.prototype.testExistingAttrbindingIsAppended = function() {
BinderTest.prototype.testAttributesAreEvaluated = function(){
var form = html('');
form.data('scope', new Scope({a:1, b:2}));
- var binder = new Binder(form.get(0), null, new MockUrlWatcher());
+ var binder = new Binder(form.get(0), null, new MockLocation());
binder.compile();
binder.updateView();
var a = form.find("a");
@@ -304,7 +304,7 @@ BinderTest.prototype.testInputsAreUpdated = function(){
'' +
'' +
'');
- var binder = new Binder(form.get(0), new WidgetFactory(), new MockUrlWatcher());
+ var binder = new Binder(form.get(0), new WidgetFactory(), new MockLocation());
form.data('scope', new Scope({A:{text:"t1", textarea:"t2", radio:"r", checkbox:"c", select:"S"}}));
binder.compile();
binder.updateView();
@@ -348,21 +348,27 @@ BinderTest.prototype.testButtonElementActionExecutesInScope = function(){
};
BinderTest.prototype.testParseEmptyAnchor = function(){
- var binder = new Binder(null, null, new MockUrlWatcher());
+ var location = new MockLocation();
+ var binder = new Binder(null, null, location);
var anchor = binder.anchor;
- binder.parseAnchor("a#x=1");
+ location.url = "a#x=1";
+ binder.parseAnchor();
assertEquals(1, binder.anchor.x);
- binder.parseAnchor("a#");
+ location.url = "a#";
+ binder.parseAnchor();
assertTrue("old values did not get removed", !binder.anchor.x);
assertTrue("anchor gor replaced", anchor === binder.anchor);
assertEquals('undefined', typeof (anchor[""]));
};
BinderTest.prototype.testParseAnchor = function(){
- var binder = new Binder(null, null, new MockUrlWatcher());
- binder.parseAnchor("a#x=1");
+ var location = new MockLocation();
+ var binder = new Binder(null, null, location);
+ location.url = "a#x=1";
+ binder.parseAnchor();
assertEquals(binder.anchor.x, "1");
- binder.parseAnchor("a#a=b&c=%20&d");
+ location.url = "a#a=b&c=%20&d";
+ binder.parseAnchor();
assertEquals(binder.anchor.a, 'b');
assertEquals(binder.anchor.c, ' ');
assertTrue(binder.anchor.d !== null);
@@ -370,27 +376,27 @@ BinderTest.prototype.testParseAnchor = function(){
};
BinderTest.prototype.testWriteAnchor = function(){
- var binder = new Binder(null, null, new MockUrlWatcher());
- binder.urlWatcher.setUrl('a');
+ var binder = new Binder(null, null, new MockLocation());
+ binder.location.set('a');
binder.anchor.a = 'b';
binder.anchor.c = ' ';
binder.anchor.d = true;
binder.updateAnchor();
- assertEquals(binder.urlWatcher.getUrl(), "a#a=b&c=%20&d");
+ assertEquals(binder.location.get(), "a#a=b&c=%20&d");
};
BinderTest.prototype.testWriteAnchorAsPartOfTheUpdateView = function(){
- var binder = new Binder(html("")[0], null, new MockUrlWatcher());
- binder.urlWatcher.setUrl('a');
+ var binder = new Binder(html("")[0], null, new MockLocation());
+ binder.location.set('a');
$(binder.doc).data('scope', new Scope());
binder.anchor.a = 'b';
binder.updateView();
- assertEquals(binder.urlWatcher.getUrl(), "a#a=b");
+ assertEquals(binder.location.get(), "a#a=b");
};
BinderTest.prototype.testRepeaterUpdateBindings = function(){
var form = html('
');
- var binder = new Binder(form.get(0), null, new MockUrlWatcher());
+ var binder = new Binder(form.get(0), null, new MockLocation());
var items = [{a:"A"}, {a:"B"}];
form.data('scope', new Scope({model:{items:items}}));
binder.compile();
@@ -423,7 +429,7 @@ BinderTest.prototype.testRepeaterUpdateBindings = function(){
BinderTest.prototype.testRepeaterContentDoesNotBind = function(){
var form = html('
');
form.data('scope', new Scope({model:{items:[{a:"A"}]}}));
- var binder = new Binder(form.get(0), null, new MockUrlWatcher());
+ var binder = new Binder(form.get(0), null, new MockLocation());
binder.compile();
binder.updateView();
assertEquals('
' +
@@ -449,7 +455,7 @@ BinderTest.prototype.testRepeaterInputContentDoesNotBind = function(){
var form =
html('
' +
'
');
- var binder = new Binder(form.get(0), null, new MockUrlWatcher());
+ var binder = new Binder(form.get(0), null, new MockLocation());
var items = [{a:"A"}];
form.data('scope', new Scope({model:{items:items}}));
@@ -493,7 +499,7 @@ BinderTest.prototype.testReplaceFileUploadWithSwf = function(){
var form = jQuery("body").append('');
form.data('scope', new Scope());
var factory = {};
- var binder = new Binder(form.get(0), factory, new MockUrlWatcher());
+ var binder = new Binder(form.get(0), factory, new MockLocation());
factory.createController = function(node){
assertEquals(node.attr('type'), 'file');
return {updateModel:function(){}};
@@ -504,7 +510,7 @@ BinderTest.prototype.testReplaceFileUploadWithSwf = function(){
BinderTest.prototype.testRepeaterAdd = function(){
var doc = $('');
- var binder = new Binder(doc[0], new WidgetFactory(), new MockUrlWatcher());
+ var binder = new Binder(doc[0], new WidgetFactory(), new MockLocation());
doc.data('scope', new Scope({items:[{x:'a'}, {x:'b'}], $binder:binder}));
binder.compile();
binder.updateView();
@@ -521,7 +527,7 @@ BinderTest.prototype.testIfTextBindingThrowsErrorDecorateTheSpan = function(){
var doc = $('
{{error.throw()}}
');
var scope = new Scope();
doc.data('scope', scope);
- var binder = new Binder(doc[0], new WidgetFactory(), new MockUrlWatcher());
+ var binder = new Binder(doc[0], new WidgetFactory(), new MockLocation());
binder.compile();
scope.set('error.throw', function(){throw "ErrorMsg1";});
@@ -549,7 +555,7 @@ BinderTest.prototype.testIfAttrBindingThrowsErrorDecorateTheSpan = function(){
var doc = $('');
var scope = new Scope();
doc.data('scope', scope);
- var binder = new Binder(doc[0], new WidgetFactory(), new MockUrlWatcher());
+ var binder = new Binder(doc[0], new WidgetFactory(), new MockLocation());
binder.compile();
scope.set('error.throw', function(){throw "ErrorMsg";});
@@ -571,7 +577,7 @@ BinderTest.prototype.testNestedRepeater = function() {
'');
var scope = new Scope();
doc.data('scope', scope);
- var binder = new Binder(doc[0], new WidgetFactory(), new MockUrlWatcher());
+ var binder = new Binder(doc[0], new WidgetFactory(), new MockLocation());
binder.compile();
scope.set('model', [{name:'a', item:['a1', 'a2']}, {name:'b', item:['b1', 'b2']}]);
@@ -595,7 +601,7 @@ BinderTest.prototype.testRadioButtonGetsPrefixed = function () {
var doc = html('');
var scope = new Scope();
doc.data('scope', scope);
- var binder = new Binder(doc[0], new WidgetFactory(), new MockUrlWatcher());
+ var binder = new Binder(doc[0], new WidgetFactory(), new MockLocation());
binder.compile();
scope.set('model', ['a1', 'a2']);
@@ -612,7 +618,7 @@ BinderTest.prototype.testHideBindingExpression = function() {
var doc = html('');
var scope = new Scope();
doc.data('scope', scope);
- var binder = new Binder(doc[0], new WidgetFactory(), new MockUrlWatcher());
+ var binder = new Binder(doc[0], new WidgetFactory(), new MockLocation());
binder.compile();
scope.set('hidden', 3);
@@ -630,7 +636,7 @@ BinderTest.prototype.testHideBinding = function() {
var doc = html('');
var scope = new Scope();
doc.data('scope', scope);
- var binder = new Binder(doc[0], new WidgetFactory(), new MockUrlWatcher());
+ var binder = new Binder(doc[0], new WidgetFactory(), new MockLocation());
binder.compile();
scope.set('hidden', 'true');
@@ -653,7 +659,7 @@ BinderTest.prototype.testShowBinding = function() {
var doc = html('');
var scope = new Scope();
doc.data('scope', scope);
- var binder = new Binder(doc[0], new WidgetFactory(), new MockUrlWatcher());
+ var binder = new Binder(doc[0], new WidgetFactory(), new MockLocation());
binder.compile();
scope.set('show', 'true');
@@ -685,7 +691,7 @@ BinderTest.prototype.testBindClass = function() {
var doc = html('');
var scope = new Scope();
doc.data('scope', scope);
- var binder = new Binder(doc[0], new WidgetFactory(), new MockUrlWatcher());
+ var binder = new Binder(doc[0], new WidgetFactory(), new MockLocation());
binder.compile();
scope.set('class', 'testClass');
@@ -714,7 +720,7 @@ BinderTest.prototype.testBindStyle = function() {
var doc = html('');
var scope = new Scope();
doc.data('scope', scope);
- var binder = new Binder(doc[0], new WidgetFactory(), new MockUrlWatcher());
+ var binder = new Binder(doc[0], new WidgetFactory(), new MockLocation());
binder.compile();
scope.eval('style={color:"red"}');
@@ -797,7 +803,7 @@ BinderTest.prototype.testDissableAutoSubmit = function() {
BinderTest.prototype.testSettingAnchorToNullOrUndefinedRemovesTheAnchorFromURL = function() {
var c = compile('');
- c.binder.urlWatcher.setUrl("http://server/#a=1&b=2");
+ c.binder.location.set("http://server/#a=1&b=2");
c.binder.parseAnchor();
assertEquals('1', c.binder.anchor.a);
assertEquals('2', c.binder.anchor.b);
@@ -805,7 +811,7 @@ BinderTest.prototype.testSettingAnchorToNullOrUndefinedRemovesTheAnchorFromURL =
c.binder.anchor.a = null;
c.binder.anchor.b = null;
c.binder.updateAnchor();
- assertEquals('http://server/#', c.binder.urlWatcher.getUrl());
+ assertEquals('http://server/#', c.binder.location.get());
};
BinderTest.prototype.testFillInOptionValueWhenMissing = function() {
@@ -875,15 +881,24 @@ BinderTest.prototype.testItShouldCallListenersWhenAnchorChanges = function() {
log += oldValue + "->" + newValue + ";";
});
assertEquals(0, c.scope.get("count"));
- c.binder.onUrlChange("#counter=1");
+ c.binder.location.url = "#counter=1";
+ c.binder.onUrlChange();
assertEquals(1, c.scope.get("count"));
- c.binder.onUrlChange("#counter=1");
+
+ c.binder.location.url = "#counter=1";
+ c.binder.onUrlChange();
assertEquals(1, c.scope.get("count"));
- c.binder.onUrlChange("#counter=2");
+
+ c.binder.location.url = "#counter=2";
+ c.binder.onUrlChange();
assertEquals(2, c.scope.get("count"));
- c.binder.onUrlChange("#counter=2");
+
+ c.binder.location.url = "#counter=2";
+ c.binder.onUrlChange();
assertEquals(2, c.scope.get("count"));
- c.binder.onUrlChange("#");
+
+ c.binder.location.url = "#";
+ c.binder.onUrlChange();
assertEquals("undefined->1;1->2;2->undefined;", log);
assertEquals(3, c.scope.get("count"));
};
@@ -904,7 +919,7 @@ BinderTest.prototype.testParseQueryString = function(){
BinderTest.prototype.testSetBinderAnchorTriggersListeners = function(){
expectAsserts(2);
var doc = html("")[0];
- var binder = new Binder(doc, null, new MockUrlWatcher());
+ var binder = new Binder(doc, null, new MockLocation());
var scope = new Scope({$binder:binder, $anchor:binder.anchor});
jQuery(doc).data('scope', scope);
diff --git a/test/ControlBarTest.js b/test/ControlBarTest.js
deleted file mode 100644
index c914c8ff..00000000
--- a/test/ControlBarTest.js
+++ /dev/null
@@ -1,2 +0,0 @@
-ControlBarTest = TestCase("ControlBarTest");
-
diff --git a/test/ExternalApiTest.js b/test/ExternalApiTest.js
deleted file mode 100644
index cc102ae0..00000000
--- a/test/ExternalApiTest.js
+++ /dev/null
@@ -1,15 +0,0 @@
-ExternalApiTest = TestCase("ExternalApiTest");
-
-ExternalApiTest.prototype = {
- testItShouldExposefactory:function(){
- var node = $('
{{b=a+1}}
')[0];
- var scope = angular.compile(node);
- scope.init();
- assertEquals(1, scope.get('a'));
- assertEquals(2, scope.get('b'));
- },
-
- testItShouldRegisterAnchorListener: function (){
-
- }
-};
diff --git a/test/JsonTest.js b/test/JsonTest.js
index cf49bec3..9b275248 100644
--- a/test/JsonTest.js
+++ b/test/JsonTest.js
@@ -67,3 +67,14 @@ JsonTest.prototype.testItShouldUTCDates = function() {
assertEquals(date.getTime(),
fromJson('"2009-10-09T01:02:03Z"').getTime());
};
+
+JsonTest.prototype.testItShouldPreventRecursion = function () {
+ var obj = {a:'b'};
+ obj.recursion = obj;
+ assertEquals('{"a":"b","recursion":RECURSION}', angular.toJson(obj));
+};
+
+JsonTest.prototype.testItShouldSerializeSameObjectsMultipleTimes = function () {
+ var obj = {a:'b'};
+ assertEquals('{"A":{"a":"b"},"B":{"a":"b"}}', angular.toJson({A:obj, B:obj}));
+};
diff --git a/test/ScenarioSpec.js b/test/ScenarioSpec.js
new file mode 100644
index 00000000..c3c29f02
--- /dev/null
+++ b/test/ScenarioSpec.js
@@ -0,0 +1,66 @@
+describe("ScenarioSpec: Compilation", function(){
+ it("should compile dom node and return scope", function(){
+ var node = $('
{{b=a+1}}
')[0];
+ var scope = angular.compile(node);
+ scope.init();
+ expect(scope.get('a')).toEqual(1);
+ expect(scope.get('b')).toEqual(2);
+ });
+
+ it("should compile jQuery node and return scope", function(){
+ var scope = angular.compile($('
{{a=123}}
')).init();
+ expect($(scope.element).text()).toEqual('123');
+ });
+
+ it("should compile text node and return scope", function(){
+ var scope = angular.compile('