From c9c176a53b1632ca2b1c6ed27382ab72ac21d45d Mon Sep 17 00:00:00 2001 From: Adam Abrons Date: Tue, 5 Jan 2010 16:36:58 -0800 Subject: angular.js --- test/ApiTest.js | 252 +++++++++++ test/Base64Test.js | 5 + test/BinderTest.js | 1001 +++++++++++++++++++++++++++++++++++++++++ test/ConsoleTest.js | 13 + test/ControlBarTest.js | 2 + test/DataStoreTest.js | 617 +++++++++++++++++++++++++ test/EntityDeclarationTest.js | 46 ++ test/FileControllerTest.js | 98 ++++ test/FiltersTest.js | 153 +++++++ test/JsonTest.js | 69 +++ test/LoaderTest.js | 70 +++ test/ModelTest.js | 84 ++++ test/ParserTest.js | 462 +++++++++++++++++++ test/ScopeTest.js | 144 ++++++ test/ServerTest.js | 42 ++ test/UsersTest.js | 26 ++ test/ValidatorsTest.js | 65 +++ test/WidgetsTest.js | 269 +++++++++++ test/XSitePostTest.js | 47 ++ test/formsTest.js | 22 + test/test/StepsTest.js | 7 + test/testabilityPatch.js | 129 ++++++ 22 files changed, 3623 insertions(+) create mode 100644 test/ApiTest.js create mode 100644 test/Base64Test.js create mode 100644 test/BinderTest.js create mode 100644 test/ConsoleTest.js create mode 100644 test/ControlBarTest.js create mode 100644 test/DataStoreTest.js create mode 100644 test/EntityDeclarationTest.js create mode 100644 test/FileControllerTest.js create mode 100644 test/FiltersTest.js create mode 100644 test/JsonTest.js create mode 100644 test/LoaderTest.js create mode 100644 test/ModelTest.js create mode 100644 test/ParserTest.js create mode 100644 test/ScopeTest.js create mode 100644 test/ServerTest.js create mode 100644 test/UsersTest.js create mode 100644 test/ValidatorsTest.js create mode 100644 test/WidgetsTest.js create mode 100644 test/XSitePostTest.js create mode 100644 test/formsTest.js create mode 100644 test/test/StepsTest.js create mode 100644 test/testabilityPatch.js (limited to 'test') diff --git a/test/ApiTest.js b/test/ApiTest.js new file mode 100644 index 00000000..250a27b1 --- /dev/null +++ b/test/ApiTest.js @@ -0,0 +1,252 @@ +ApiTest = TestCase("ApiTest"); + +ApiTest.prototype.testItShouldReturnTypeOf = function (){ + assertEquals("undefined", angular.Object.typeOf(undefined)); + assertEquals("null", angular.Object.typeOf(null)); + assertEquals("object", angular.Collection.typeOf({})); + assertEquals("array", angular.Array.typeOf([])); + assertEquals("string", angular.Object.typeOf("")); + assertEquals("date", angular.Object.typeOf(new Date())); + assertEquals("element", angular.Object.typeOf(document.body)); + assertEquals("function", angular.Object.typeOf(function(){})); +}; + +ApiTest.prototype.testItShouldReturnSize = function(){ + assertEquals(0, angular.Collection.size({})); + assertEquals(1, angular.Collection.size({a:"b"})); + assertEquals(0, angular.Object.size({})); + assertEquals(1, angular.Array.size([0])); +}; + +ApiTest.prototype.testIncludeIf = function() { + var array = []; + var obj = {}; + + angular.Array.includeIf(array, obj, true); + angular.Array.includeIf(array, obj, true); + assertTrue(_.include(array, obj)); + assertEquals(1, array.length); + + angular.Array.includeIf(array, obj, false); + assertFalse(_.include(array, obj)); + assertEquals(0, array.length); + + angular.Array.includeIf(array, obj, 'x'); + assertTrue(_.include(array, obj)); + assertEquals(1, array.length); + angular.Array.includeIf(array, obj, ''); + assertFalse(_.include(array, obj)); + assertEquals(0, array.length); +}; + +ApiTest.prototype.testSum = function(){ + assertEquals(3, angular.Array.sum([{a:"1"}, {a:"2"}], 'a')); +}; + +ApiTest.prototype.testSumContainingNaN = function(){ + assertEquals(1, angular.Array.sum([{a:1}, {a:Number.NaN}], 'a')); + assertEquals(1, angular.Array.sum([{a:1}, {a:Number.NaN}], function($){return $.a;})); +}; + +ApiTest.prototype.testInclude = function(){ + assertTrue(angular.Array.include(['a'], 'a')); + assertTrue(angular.Array.include(['a', 'b'], 'a')); + assertTrue(!angular.Array.include(['c'], 'a')); + assertTrue(!angular.Array.include(['c', 'b'], 'a')); +}; + +ApiTest.prototype.testIndex = function(){ + assertEquals(angular.Array.indexOf(['a'], 'a'), 0); + assertEquals(angular.Array.indexOf(['a', 'b'], 'a'), 0); + assertEquals(angular.Array.indexOf(['b', 'a'], 'a'), 1); + assertEquals(angular.Array.indexOf(['b', 'b'],'x'), -1); +}; + +ApiTest.prototype.testRemove = function(){ + var items = ['a', 'b', 'c']; + assertEquals(angular.Array.remove(items, 'q'), 'q'); + assertEquals(items.length, 3); + + assertEquals(angular.Array.remove(items, 'b'), 'b'); + assertEquals(items.length, 2); + + assertEquals(angular.Array.remove(items, 'a'), 'a'); + assertEquals(items.length, 1); + + assertEquals(angular.Array.remove(items, 'c'), 'c'); + assertEquals(items.length, 0); + + assertEquals(angular.Array.remove(items, 'q'), 'q'); + assertEquals(items.length, 0); +}; + +ApiTest.prototype.testFindById = function() { + var items = [{$id:1}, {$id:2}, {$id:3}]; + assertNull(angular.Array.findById(items, 0)); + assertEquals(items[0], angular.Array.findById(items, 1)); + assertEquals(items[1], angular.Array.findById(items, 2)); + assertEquals(items[2], angular.Array.findById(items, 3)); +}; + +ApiTest.prototype.testFilter = function() { + var items = ["MIsKO", {name:"shyam"}, ["adam"], 1234]; + assertEquals(4, angular.Array.filter(items, "").length); + assertEquals(4, angular.Array.filter(items, undefined).length); + + assertEquals(1, angular.Array.filter(items, 'iSk').length); + assertEquals("MIsKO", angular.Array.filter(items, 'isk')[0]); + + assertEquals(1, angular.Array.filter(items, 'yam').length); + assertEquals(items[1], angular.Array.filter(items, 'yam')[0]); + + assertEquals(1, angular.Array.filter(items, 'da').length); + assertEquals(items[2], angular.Array.filter(items, 'da')[0]); + + assertEquals(1, angular.Array.filter(items, '34').length); + assertEquals(1234, angular.Array.filter(items, '34')[0]); + + assertEquals(0, angular.Array.filter(items, "I don't exist").length); +}; + +ApiTest.prototype.testShouldNotFilterOnSystemData = function() { + assertEquals("", "".charAt(0)); // assumption + var items = [{$name:"misko"}]; + assertEquals(0, angular.Array.filter(items, "misko").length); +}; + +ApiTest.prototype.testFilterOnSpecificProperty = function() { + var items = [{ignore:"a", name:"a"}, {ignore:"a", name:"abc"}]; + assertEquals(2, angular.Array.filter(items, {}).length); + + assertEquals(2, angular.Array.filter(items, {name:'a'}).length); + + assertEquals(1, angular.Array.filter(items, {name:'b'}).length); + assertEquals("abc", angular.Array.filter(items, {name:'b'})[0].name); +}; + +ApiTest.prototype.testFilterOnFunction = function() { + var items = [{name:"a"}, {name:"abc", done:true}]; + assertEquals(1, angular.Array.filter(items, function(i){return i.done;}).length); +}; + +ApiTest.prototype.testFilterIsAndFunction = function() { + var items = [{first:"misko", last:"hevery"}, + {first:"adam", last:"abrons"}]; + + assertEquals(2, angular.Array.filter(items, {first:'', last:''}).length); + assertEquals(1, angular.Array.filter(items, {first:'', last:'hevery'}).length); + assertEquals(0, angular.Array.filter(items, {first:'adam', last:'hevery'}).length); + assertEquals(1, angular.Array.filter(items, {first:'misko', last:'hevery'}).length); + assertEquals(items[0], angular.Array.filter(items, {first:'misko', last:'hevery'})[0]); +}; + +ApiTest.prototype.testFilterNot = function() { + var items = ["misko", "adam"]; + + assertEquals(1, angular.Array.filter(items, '!isk').length); + assertEquals(items[1], angular.Array.filter(items, '!isk')[0]); +}; + +ApiTest.prototype.testAdd = function() { + var add = angular.Array.add; + assertJsonEquals([{}, "a"], add(add([]),"a")); +}; + +ApiTest.prototype.testCount = function() { + var array = [{name:'a'},{name:'b'},{name:''}]; + var obj = {}; + + assertEquals(3, angular.Array.count(array)); + assertEquals(2, angular.Array.count(array, 'name')); + assertEquals(1, angular.Array.count(array, 'name=="a"')); +}; + +ApiTest.prototype.testFind = function() { + var array = [{name:'a'},{name:'b'},{name:''}]; + var obj = {}; + + assertEquals(undefined, angular.Array.find(array, 'false')); + assertEquals('default', angular.Array.find(array, 'false', 'default')); + assertEquals('a', angular.Array.find(array, 'name == "a"').name); + assertEquals('', angular.Array.find(array, 'name == ""').name); +}; + +ApiTest.prototype.testItShouldSortArray = function() { + assertEquals([2,15], angular.Array.orderBy([15,2])); + assertEquals(["a","B", "c"], angular.Array.orderBy(["c","B", "a"])); + assertEquals([15,"2"], angular.Array.orderBy([15,"2"])); + assertEquals(["15","2"], angular.Array.orderBy(["15","2"])); + assertJsonEquals([{a:2},{a:15}], angular.Array.orderBy([{a:15},{a:2}], 'a')); + assertJsonEquals([{a:2},{a:15}], angular.Array.orderBy([{a:15},{a:2}], 'a', "F")); +}; + +ApiTest.prototype.testItShouldSortArrayInReverse = function() { + assertJsonEquals([{a:15},{a:2}], angular.Array.orderBy([{a:15},{a:2}], 'a', true)); + assertJsonEquals([{a:15},{a:2}], angular.Array.orderBy([{a:15},{a:2}], 'a', "T")); + assertJsonEquals([{a:15},{a:2}], angular.Array.orderBy([{a:15},{a:2}], 'a', "reverse")); +}; + +ApiTest.prototype.testItShouldSortArrayByPredicate = function() { + assertJsonEquals([{a:2, b:1},{a:15, b:1}], + angular.Array.orderBy([{a:15, b:1},{a:2, b:1}], ['a', 'b'])); + assertJsonEquals([{a:2, b:1},{a:15, b:1}], + angular.Array.orderBy([{a:15, b:1},{a:2, b:1}], ['b', 'a'])); + assertJsonEquals([{a:15, b:1},{a:2, b:1}], + angular.Array.orderBy([{a:15, b:1},{a:2, b:1}], ['+b', '-a'])); +}; + +ApiTest.prototype.testQuoteString = function(){ + assertEquals(angular.String.quote('a'), '"a"'); + assertEquals(angular.String.quote('\\'), '"\\\\"'); + assertEquals(angular.String.quote("'a'"), '"\'a\'"'); + assertEquals(angular.String.quote('"a"'), '"\\"a\\""'); + assertEquals(angular.String.quote('\n\f\r\t'), '"\\n\\f\\r\\t"'); +}; + +ApiTest.prototype.testQuoteStringBug = function(){ + assertEquals(angular.String.quote('"7\\\\\\\"7"', "7\\\"7")); +}; + +ApiTest.prototype.testQuoteUnicode = function(){ + assertEquals('"abc\\u00a0def"', angular.String.quoteUnicode('abc\u00A0def')); +}; + +ApiTest.prototype.testMerge = function() { + var array = [{name:"misko"}]; + angular.Array.merge(array, 0, {name:"", email:"email1"}); + angular.Array.merge(array, 1, {name:"adam", email:"email2"}); + assertJsonEquals([{"email":"email1","name":"misko"},{"email":"email2","name":"adam"}], array); +}; + +ApiTest.prototype.testOrderByToggle = function() { + var orderByToggle = angular.Array.orderByToggle; + var predicate = []; + assertEquals(['+a'], orderByToggle(predicate, 'a')); + assertEquals(['-a'], orderByToggle(predicate, 'a')); + + assertEquals(['-a', '-b'], orderByToggle(['-b', 'a'], 'a')); +}; + +ApiTest.prototype.testOrderByToggle = function() { + var orderByDirection = angular.Array.orderByDirection; + assertEquals("", orderByDirection(['+a','b'], 'x')); + assertEquals("", orderByDirection(['+a','b'], 'b')); + assertEquals('ng-ascend', orderByDirection(['a','b'], 'a')); + assertEquals('ng-ascend', orderByDirection(['+a','b'], 'a')); + assertEquals('ng-descend', orderByDirection(['-a','b'], 'a')); + assertEquals('up', orderByDirection(['+a','b'], 'a', 'up', 'down')); + assertEquals('down', orderByDirection(['-a','b'], 'a', 'up', 'down')); +}; + +ApiTest.prototype.testDateToUTC = function(){ + var date = new Date("Sep 10 2003 13:02:03 GMT"); + assertEquals("date", angular.Object.typeOf(date)); + assertEquals("2003-09-10T13:02:03Z", angular.Date.toString(date)); +}; + +ApiTest.prototype.testStringFromUTC = function(){ + var date = angular.String.toDate("2003-09-10T13:02:03Z"); + assertEquals("date", angular.Object.typeOf(date)); + assertEquals("2003-09-10T13:02:03Z", angular.Date.toString(date)); + assertEquals("str", angular.String.toDate("str")); +}; diff --git a/test/Base64Test.js b/test/Base64Test.js new file mode 100644 index 00000000..a9353186 --- /dev/null +++ b/test/Base64Test.js @@ -0,0 +1,5 @@ +Base64Test = TestCase('Base64Test'); + +Base64Test.prototype.testEncodeDecode = function(){ + assertEquals(Base64.decode(Base64.encode('hello')), 'hello'); +}; diff --git a/test/BinderTest.js b/test/BinderTest.js new file mode 100644 index 00000000..d033996d --- /dev/null +++ b/test/BinderTest.js @@ -0,0 +1,1001 @@ +BinderTest = TestCase('BinderTest'); + +function compile(content, initialScope, config) { + var h = html(content); + config = config || {autoSubmit:true}; + var scope = new nglr.Scope(initialScope, "ROOT"); + h.data('scope', scope); + var binder = new nglr.Binder(h[0], new nglr.WidgetFactory(), new MockUrlWatcher(), config); + var datastore = new nglr.DataStore(); + scope.set("$datastore", datastore); + scope.set("$binder", binder); + scope.set("$anchor", binder.anchor); + binder.entity(scope); + binder.compile(); + return {node:h, binder:binder, scope:scope}; +} + +function compileToHtml(content) { + return compile(content).node.sortedHtml(); +} + + +BinderTest.prototype.testParseTextWithNoBindings = function(){ + var parts = nglr.Binder.parseBindings("a"); + assertEquals(parts.length, 1); + assertEquals(parts[0], "a"); + assertTrue(!nglr.Binder.binding(parts[0])); +}; + +BinderTest.prototype.testParseEmptyText = function(){ + var parts = nglr.Binder.parseBindings(""); + assertEquals(parts.length, 1); + assertEquals(parts[0], ""); + assertTrue(!nglr.Binder.binding(parts[0])); +}; + +BinderTest.prototype.testParseInnerBinding = function(){ + var parts = nglr.Binder.parseBindings("a{{b}}c"); + assertEquals(parts.length, 3); + assertEquals(parts[0], "a"); + assertTrue(!nglr.Binder.binding(parts[0])); + assertEquals(parts[1], "{{b}}"); + assertEquals(nglr.Binder.binding(parts[1]), "b"); + assertEquals(parts[2], "c"); + assertTrue(!nglr.Binder.binding(parts[2])); +}; + +BinderTest.prototype.testParseEndingBinding = function(){ + var parts = nglr.Binder.parseBindings("a{{b}}"); + assertEquals(parts.length, 2); + assertEquals(parts[0], "a"); + assertTrue(!nglr.Binder.binding(parts[0])); + assertEquals(parts[1], "{{b}}"); + assertEquals(nglr.Binder.binding(parts[1]), "b"); +}; + +BinderTest.prototype.testParseBeggingBinding = function(){ + var parts = nglr.Binder.parseBindings("{{b}}c"); + assertEquals(parts.length, 2); + assertEquals(parts[0], "{{b}}"); + assertEquals(nglr.Binder.binding(parts[0]), "b"); + assertEquals(parts[1], "c"); + assertTrue(!nglr.Binder.binding(parts[1])); +}; + +BinderTest.prototype.testParseLoanBinding = function(){ + var parts = nglr.Binder.parseBindings("{{b}}"); + assertEquals(parts.length, 1); + assertEquals(parts[0], "{{b}}"); + assertEquals(nglr.Binder.binding(parts[0]), "b"); +}; + +BinderTest.prototype.testParseTwoBindings = function(){ + var parts = nglr.Binder.parseBindings("{{b}}{{c}}"); + assertEquals(parts.length, 2); + assertEquals(parts[0], "{{b}}"); + assertEquals(nglr.Binder.binding(parts[0]), "b"); + assertEquals(parts[1], "{{c}}"); + assertEquals(nglr.Binder.binding(parts[1]), "c"); +}; + +BinderTest.prototype.testParseTwoBindingsWithTextInMiddle = function(){ + var parts = nglr.Binder.parseBindings("{{b}}x{{c}}"); + assertEquals(parts.length, 3); + assertEquals(parts[0], "{{b}}"); + assertEquals(nglr.Binder.binding(parts[0]), "b"); + assertEquals(parts[1], "x"); + assertTrue(!nglr.Binder.binding(parts[1])); + assertEquals(parts[2], "{{c}}"); + assertEquals(nglr.Binder.binding(parts[2]), "c"); +}; + +BinderTest.prototype.testParseMultiline = function(){ + var parts = nglr.Binder.parseBindings('"X\nY{{A\nB}}C\nD"'); + assertTrue(!!nglr.Binder.binding('{{A\nB}}')); + assertEquals(parts.length, 3); + assertEquals(parts[0], '"X\nY'); + assertEquals(parts[1], '{{A\nB}}'); + assertEquals(parts[2], 'C\nD"'); +}; + +BinderTest.prototype.testHasBinding = function(){ + assertTrue(nglr.Binder.hasBinding("{{a}}")); + assertTrue(!nglr.Binder.hasBinding("a")); + assertTrue(nglr.Binder.hasBinding("{{b}}x{{c}}")); +}; + + +BinderTest.prototype.tearDown = function(){ + jQuery("*", document).die(); + jQuery(document).unbind(); +}; + +BinderTest.prototype.testChangingTextfieldUpdatesModel = function(){ + var state = compile('', {model:{}}); + state.binder.updateView(); + assertEquals('abc', state.scope.get('model').price); +}; + +BinderTest.prototype.testChangingTextareaUpdatesModel = function(){ + var form = html(''); + var scope = new nglr.Scope({model:{}}); + form.data('scope', scope); + var binder = new nglr.Binder(form.get(0), new nglr.WidgetFactory(), new MockUrlWatcher()); + binder.compile(); + binder.updateView(); + assertEquals(scope.get('model').note, 'abc'); +}; + +BinderTest.prototype.testChangingRadioUpdatesModel = function(){ + var form = html('' + + ''); + var scope = new nglr.Scope({model:{}}); + form.data('scope', scope); + var binder = new nglr.Binder(form.get(0), new nglr.WidgetFactory(), new MockUrlWatcher()); + binder.compile(); + binder.updateView(); + assertEquals(scope.get('model').price, 'A'); +}; + +BinderTest.prototype.testChangingCheckboxUpdatesModel = function(){ + var form = html(''); + var scope = new nglr.Scope({model:{}}); + form.data('scope', scope); + var binder = new nglr.Binder(form.get(0), new nglr.WidgetFactory(), new MockUrlWatcher()); + binder.compile(); + binder.updateView(); + assertEquals('A', scope.get('model').price); +}; + +BinderTest.prototype.testBindUpdate = function() { + var c = compile('
'); + c.binder.updateView(); + assertEquals(123, c.scope.get('a')); +}; + +BinderTest.prototype.testChangingSelectNonSelectedUpdatesModel = function(){ + var form = html(''); + var scope = new nglr.Scope({model:{}}); + form.data('scope', scope); + var binder = new nglr.Binder(form.get(0), new nglr.WidgetFactory(), new MockUrlWatcher()); + binder.compile(); + binder.updateView(); + assertEquals('A', scope.get('model').price); +}; + +BinderTest.prototype.testChangingMultiselectUpdatesModel = function(){ + var form = html(''); + var scope = new nglr.Scope({Invoice:{}}); + form.data('scope', scope); + var binder = new nglr.Binder(form.get(0), new nglr.WidgetFactory(), new MockUrlWatcher()); + binder.compile(); + binder.updateView(); + assertJsonEquals(["A", "B"], scope.get('Invoice').options); +}; + +BinderTest.prototype.testChangingSelectSelectedUpdatesModel = function(){ + var form = html(''); + var scope = new nglr.Scope({model:{}}); + form.data('scope', scope); + var binder = new nglr.Binder(form.get(0), new nglr.WidgetFactory(), new MockUrlWatcher()); + binder.compile(); + binder.updateView(); + assertEquals(scope.get('model').price, 'b'); +}; + +BinderTest.prototype.testExecuteInitialization = function() { + var form = html('
'); + var scope = new nglr.Scope(); + form.data('scope', scope); + var binder = new nglr.Binder(form.get(0)); + binder.executeInit(); + assertEquals(scope.get('a'), 123); +}; + +BinderTest.prototype.testExecuteInitializationStatements = function() { + var form = html('
'); + var scope = new nglr.Scope(); + form.data('scope', scope); + var binder = new nglr.Binder(form.get(0)); + binder.executeInit(); + assertEquals(scope.get('a'), 123); + assertEquals(scope.get('b'), 345); +}; + +BinderTest.prototype.testApplyTextBindings = function(){ + var form = html('
x
'); + var scope = new nglr.Scope({model:{a:123}}); + form.data('scope', scope); + var binder = new nglr.Binder(form.get(0), null, new MockUrlWatcher()); + binder.compile(); + binder.updateView(); + assertEquals('123', form.text()); +}; + +BinderTest.prototype.testReplaceBindingInTextWithSpan = function() { + assertEquals(compileToHtml("a{{b}}c"), 'ac'); + assertEquals(compileToHtml("{{b}}"), ''); +}; + +BinderTest.prototype.testReplaceBindingCreatesCorrectNumberOfWidgets = function() { + var h = html("space{{a}}{{a}}a{{a}}{{a}}"); + h.data('scope', new nglr.Scope()); + var binder = new nglr.Binder(h.get(0), new nglr.WidgetFactory()); + binder.compile(); + + assertEquals(4, h.scope().widgets.length); +}; + +BinderTest.prototype.testBindingSpaceConfusesIE = function() { + if (!nglr.msie) return; + var span = document.createElement("span"); + span.innerHTML = ' '; + var nbsp = span.firstChild.nodeValue; + assertEquals( + ''+nbsp+'', + compileToHtml("{{a}} {{b}}")); + assertEquals( + ''+nbsp+'x '+nbsp+'(', + compileToHtml("{{A}} x {{B}} ({{C}})")); +}; + +BinderTest.prototype.testBindingOfAttributes = function() { + var form = html(""); + form.data('scope', new nglr.Scope()); + var binder = new nglr.Binder(form.get(0)); + binder.compile(); + var attrbinding = form.find("a").attr("ng-bind-attr"); + var bindings = nglr.fromJson(attrbinding); + assertEquals("http://s/a{{b}}c", decodeURI(bindings.href)); + assertTrue(!bindings.foo); +}; + +BinderTest.prototype.testMarkMultipleAttributes = function() { + var form = html(""); + form.data('scope', new nglr.Scope()); + var binder = new nglr.Binder(form.get(0)); + binder.compile(); + var attrbinding = form.find("a").attr("ng-bind-attr"); + var bindings = nglr.fromJson(attrbinding); + assertEquals(decodeURI(bindings.href), "http://s/a{{b}}c"); + assertEquals(bindings.foo, "{{d}}"); +}; + +BinderTest.prototype.testAttributesNoneBound = function() { + var form = html(""); + form.data('scope', new nglr.Scope()); + var binder = new nglr.Binder(form.get(0)); + binder.compile(); + var a = form.find("a"); + assertEquals(a.get(0).nodeName, "A"); + assertTrue(!a.attr("ng-bind-attr")); +}; + +BinderTest.prototype.testExistingAttrbindingIsAppended = function() { + var form = html(""); + form.data('scope', new nglr.Scope()); + var binder = new nglr.Binder(form.get(0)); + binder.compile(); + var a = form.find("a"); + assertEquals('{"b":"{{def}}","href":"http://s/{{abc}}"}', a.attr('ng-bind-attr')); +}; + +BinderTest.prototype.testAttributesAreEvaluated = function(){ + var form = html(''); + form.data('scope', new nglr.Scope({a:1, b:2})); + var binder = new nglr.Binder(form.get(0), null, new MockUrlWatcher()); + binder.compile(); + binder.updateView(); + var a = form.find("a"); + assertEquals(a.attr('a'), 'a'); + assertEquals(a.attr('b'), 'a+b=3'); +}; + +BinderTest.prototype.testInputsAreUpdated = function(){ + var form = + html('' + + ''); - var scope = new nglr.Scope({model:{}}); + var scope = new Scope({model:{}}); form.data('scope', scope); - var binder = new nglr.Binder(form.get(0), new nglr.WidgetFactory(), new MockUrlWatcher()); + var binder = new Binder(form.get(0), new WidgetFactory(), new MockUrlWatcher()); binder.compile(); binder.updateView(); assertEquals(scope.get('model').note, 'abc'); @@ -130,9 +129,9 @@ BinderTest.prototype.testChangingTextareaUpdatesModel = function(){ BinderTest.prototype.testChangingRadioUpdatesModel = function(){ var form = html('' + ''); - var scope = new nglr.Scope({model:{}}); + var scope = new Scope({model:{}}); form.data('scope', scope); - var binder = new nglr.Binder(form.get(0), new nglr.WidgetFactory(), new MockUrlWatcher()); + var binder = new Binder(form.get(0), new WidgetFactory(), new MockUrlWatcher()); binder.compile(); binder.updateView(); assertEquals(scope.get('model').price, 'A'); @@ -140,9 +139,9 @@ BinderTest.prototype.testChangingRadioUpdatesModel = function(){ BinderTest.prototype.testChangingCheckboxUpdatesModel = function(){ var form = html(''); - var scope = new nglr.Scope({model:{}}); + var scope = new Scope({model:{}}); form.data('scope', scope); - var binder = new nglr.Binder(form.get(0), new nglr.WidgetFactory(), new MockUrlWatcher()); + var binder = new Binder(form.get(0), new WidgetFactory(), new MockUrlWatcher()); binder.compile(); binder.updateView(); assertEquals('A', scope.get('model').price); @@ -156,9 +155,9 @@ BinderTest.prototype.testBindUpdate = function() { BinderTest.prototype.testChangingSelectNonSelectedUpdatesModel = function(){ var form = html(''); - var scope = new nglr.Scope({model:{}}); + var scope = new Scope({model:{}}); form.data('scope', scope); - var binder = new nglr.Binder(form.get(0), new nglr.WidgetFactory(), new MockUrlWatcher()); + var binder = new Binder(form.get(0), new WidgetFactory(), new MockUrlWatcher()); binder.compile(); binder.updateView(); assertEquals('A', scope.get('model').price); @@ -170,9 +169,9 @@ BinderTest.prototype.testChangingMultiselectUpdatesModel = function(){ '' + '' + ''); - var scope = new nglr.Scope({Invoice:{}}); + var scope = new Scope({Invoice:{}}); form.data('scope', scope); - var binder = new nglr.Binder(form.get(0), new nglr.WidgetFactory(), new MockUrlWatcher()); + var binder = new Binder(form.get(0), new WidgetFactory(), new MockUrlWatcher()); binder.compile(); binder.updateView(); assertJsonEquals(["A", "B"], scope.get('Invoice').options); @@ -180,9 +179,9 @@ BinderTest.prototype.testChangingMultiselectUpdatesModel = function(){ BinderTest.prototype.testChangingSelectSelectedUpdatesModel = function(){ var form = html(''); - var scope = new nglr.Scope({model:{}}); + var scope = new Scope({model:{}}); form.data('scope', scope); - var binder = new nglr.Binder(form.get(0), new nglr.WidgetFactory(), new MockUrlWatcher()); + var binder = new Binder(form.get(0), new WidgetFactory(), new MockUrlWatcher()); binder.compile(); binder.updateView(); assertEquals(scope.get('model').price, 'b'); @@ -190,18 +189,18 @@ BinderTest.prototype.testChangingSelectSelectedUpdatesModel = function(){ BinderTest.prototype.testExecuteInitialization = function() { var form = html('
'); - var scope = new nglr.Scope(); + var scope = new Scope(); form.data('scope', scope); - var binder = new nglr.Binder(form.get(0)); + var binder = new Binder(form.get(0)); binder.executeInit(); assertEquals(scope.get('a'), 123); }; BinderTest.prototype.testExecuteInitializationStatements = function() { var form = html('
'); - var scope = new nglr.Scope(); + var scope = new Scope(); form.data('scope', scope); - var binder = new nglr.Binder(form.get(0)); + var binder = new Binder(form.get(0)); binder.executeInit(); assertEquals(scope.get('a'), 123); assertEquals(scope.get('b'), 345); @@ -209,9 +208,9 @@ BinderTest.prototype.testExecuteInitializationStatements = function() { BinderTest.prototype.testApplyTextBindings = function(){ var form = html('
x
'); - var scope = new nglr.Scope({model:{a:123}}); + var scope = new Scope({model:{a:123}}); form.data('scope', scope); - var binder = new nglr.Binder(form.get(0), null, new MockUrlWatcher()); + var binder = new Binder(form.get(0), null, new MockUrlWatcher()); binder.compile(); binder.updateView(); assertEquals('123', form.text()); @@ -224,15 +223,15 @@ BinderTest.prototype.testReplaceBindingInTextWithSpan = function() { BinderTest.prototype.testReplaceBindingCreatesCorrectNumberOfWidgets = function() { var h = html("space{{a}}{{a}}a{{a}}{{a}}"); - h.data('scope', new nglr.Scope()); - var binder = new nglr.Binder(h.get(0), new nglr.WidgetFactory()); + h.data('scope', new Scope()); + var binder = new Binder(h.get(0), new WidgetFactory()); binder.compile(); assertEquals(4, h.scope().widgets.length); }; BinderTest.prototype.testBindingSpaceConfusesIE = function() { - if (!nglr.msie) return; + if (!msie) return; var span = document.createElement("span"); span.innerHTML = ' '; var nbsp = span.firstChild.nodeValue; @@ -246,30 +245,30 @@ BinderTest.prototype.testBindingSpaceConfusesIE = function() { BinderTest.prototype.testBindingOfAttributes = function() { var form = html(""); - form.data('scope', new nglr.Scope()); - var binder = new nglr.Binder(form.get(0)); + form.data('scope', new Scope()); + var binder = new Binder(form.get(0)); binder.compile(); var attrbinding = form.find("a").attr("ng-bind-attr"); - var bindings = nglr.fromJson(attrbinding); + var bindings = fromJson(attrbinding); assertEquals("http://s/a{{b}}c", decodeURI(bindings.href)); assertTrue(!bindings.foo); }; BinderTest.prototype.testMarkMultipleAttributes = function() { var form = html(""); - form.data('scope', new nglr.Scope()); - var binder = new nglr.Binder(form.get(0)); + form.data('scope', new Scope()); + var binder = new Binder(form.get(0)); binder.compile(); var attrbinding = form.find("a").attr("ng-bind-attr"); - var bindings = nglr.fromJson(attrbinding); + var bindings = fromJson(attrbinding); assertEquals(decodeURI(bindings.href), "http://s/a{{b}}c"); assertEquals(bindings.foo, "{{d}}"); }; BinderTest.prototype.testAttributesNoneBound = function() { var form = html(""); - form.data('scope', new nglr.Scope()); - var binder = new nglr.Binder(form.get(0)); + form.data('scope', new Scope()); + var binder = new Binder(form.get(0)); binder.compile(); var a = form.find("a"); assertEquals(a.get(0).nodeName, "A"); @@ -278,8 +277,8 @@ BinderTest.prototype.testAttributesNoneBound = function() { BinderTest.prototype.testExistingAttrbindingIsAppended = function() { var form = html(""); - form.data('scope', new nglr.Scope()); - var binder = new nglr.Binder(form.get(0)); + form.data('scope', new Scope()); + var binder = new Binder(form.get(0)); binder.compile(); var a = form.find("a"); assertEquals('{"b":"{{def}}","href":"http://s/{{abc}}"}', a.attr('ng-bind-attr')); @@ -287,8 +286,8 @@ BinderTest.prototype.testExistingAttrbindingIsAppended = function() { BinderTest.prototype.testAttributesAreEvaluated = function(){ var form = html(''); - form.data('scope', new nglr.Scope({a:1, b:2})); - var binder = new nglr.Binder(form.get(0), null, new MockUrlWatcher()); + form.data('scope', new Scope({a:1, b:2})); + var binder = new Binder(form.get(0), null, new MockUrlWatcher()); binder.compile(); binder.updateView(); var a = form.find("a"); @@ -305,8 +304,8 @@ BinderTest.prototype.testInputsAreUpdated = function(){ '' + '' + ''); - var binder = new nglr.Binder(form.get(0), new nglr.WidgetFactory(), new MockUrlWatcher()); - form.data('scope', new nglr.Scope({A:{text:"t1", textarea:"t2", radio:"r", checkbox:"c", select:"S"}})); + var binder = new Binder(form.get(0), new WidgetFactory(), new MockUrlWatcher()); + form.data('scope', new Scope({A:{text:"t1", textarea:"t2", radio:"r", checkbox:"c", select:"S"}})); binder.compile(); binder.updateView(); assertEquals(form.find("input[type=text]").attr('value'), 't1'); @@ -349,7 +348,7 @@ BinderTest.prototype.testButtonElementActionExecutesInScope = function(){ }; BinderTest.prototype.testParseEmptyAnchor = function(){ - var binder = new nglr.Binder(null, null, new MockUrlWatcher()); + var binder = new Binder(null, null, new MockUrlWatcher()); var anchor = binder.anchor; binder.parseAnchor("a#x=1"); assertEquals(1, binder.anchor.x); @@ -360,7 +359,7 @@ BinderTest.prototype.testParseEmptyAnchor = function(){ }; BinderTest.prototype.testParseAnchor = function(){ - var binder = new nglr.Binder(null, null, new MockUrlWatcher()); + var binder = new Binder(null, null, new MockUrlWatcher()); binder.parseAnchor("a#x=1"); assertEquals(binder.anchor.x, "1"); binder.parseAnchor("a#a=b&c=%20&d"); @@ -371,7 +370,7 @@ BinderTest.prototype.testParseAnchor = function(){ }; BinderTest.prototype.testWriteAnchor = function(){ - var binder = new nglr.Binder(null, null, new MockUrlWatcher()); + var binder = new Binder(null, null, new MockUrlWatcher()); binder.urlWatcher.setUrl('a'); binder.anchor.a = 'b'; binder.anchor.c = ' '; @@ -381,9 +380,9 @@ BinderTest.prototype.testWriteAnchor = function(){ }; BinderTest.prototype.testWriteAnchorAsPartOfTheUpdateView = function(){ - var binder = new nglr.Binder(html("
")[0], null, new MockUrlWatcher()); + var binder = new Binder(html("
")[0], null, new MockUrlWatcher()); binder.urlWatcher.setUrl('a'); - $(binder.doc).data('scope', new nglr.Scope()); + $(binder.doc).data('scope', new Scope()); binder.anchor.a = 'b'; binder.updateView(); assertEquals(binder.urlWatcher.getUrl(), "a#a=b"); @@ -391,9 +390,9 @@ BinderTest.prototype.testWriteAnchorAsPartOfTheUpdateView = function(){ BinderTest.prototype.testRepeaterUpdateBindings = function(){ var form = html('
'); - var binder = new nglr.Binder(form.get(0), null, new MockUrlWatcher()); + var binder = new Binder(form.get(0), null, new MockUrlWatcher()); var items = [{a:"A"}, {a:"B"}]; - form.data('scope', new nglr.Scope({model:{items:items}})); + form.data('scope', new Scope({model:{items:items}})); binder.compile(); binder.updateView(); @@ -423,8 +422,8 @@ BinderTest.prototype.testRepeaterUpdateBindings = function(){ BinderTest.prototype.testRepeaterContentDoesNotBind = function(){ var form = html('
'); - form.data('scope', new nglr.Scope({model:{items:[{a:"A"}]}})); - var binder = new nglr.Binder(form.get(0), null, new MockUrlWatcher()); + form.data('scope', new Scope({model:{items:[{a:"A"}]}})); + var binder = new Binder(form.get(0), null, new MockUrlWatcher()); binder.compile(); binder.updateView(); assertEquals('
    ' + @@ -450,9 +449,9 @@ BinderTest.prototype.testRepeaterInputContentDoesNotBind = function(){ var form = html('
    • ' + '
    '); - var binder = new nglr.Binder(form.get(0), null, new MockUrlWatcher()); + var binder = new Binder(form.get(0), null, new MockUrlWatcher()); var items = [{a:"A"}]; - form.data('scope', new nglr.Scope({model:{items:items}})); + form.data('scope', new Scope({model:{items:items}})); assertEquals(form.find(":input").attr("value"), "OLD"); }; @@ -492,9 +491,9 @@ BinderTest.prototype.testDoNotOverwriteCustomAction = function(){ BinderTest.prototype.testReplaceFileUploadWithSwf = function(){ expectAsserts(1); var form = jQuery("body").append('
    '); - form.data('scope', new nglr.Scope()); + form.data('scope', new Scope()); var factory = {}; - var binder = new nglr.Binder(form.get(0), factory, new MockUrlWatcher()); + var binder = new Binder(form.get(0), factory, new MockUrlWatcher()); factory.createController = function(node){ assertEquals(node.attr('type'), 'file'); return {updateModel:function(){}}; @@ -505,8 +504,8 @@ BinderTest.prototype.testReplaceFileUploadWithSwf = function(){ BinderTest.prototype.testRepeaterAdd = function(){ var doc = $('
    '); - var binder = new nglr.Binder(doc[0], new nglr.WidgetFactory(), new MockUrlWatcher()); - doc.data('scope', new nglr.Scope({items:[{x:'a'}, {x:'b'}], $binder:binder})); + var binder = new Binder(doc[0], new WidgetFactory(), new MockUrlWatcher()); + doc.data('scope', new Scope({items:[{x:'a'}, {x:'b'}], $binder:binder})); binder.compile(); binder.updateView(); assertEquals('a', doc.find(':input')[0].value); @@ -520,16 +519,16 @@ BinderTest.prototype.testRepeaterAdd = function(){ BinderTest.prototype.testIfTextBindingThrowsErrorDecorateTheSpan = function(){ var doc = $('
    {{error.throw()}}
    '); - var scope = new nglr.Scope(); + var scope = new Scope(); doc.data('scope', scope); - var binder = new nglr.Binder(doc[0], new nglr.WidgetFactory(), new MockUrlWatcher()); + var binder = new Binder(doc[0], new WidgetFactory(), new MockUrlWatcher()); binder.compile(); scope.set('error.throw', function(){throw "ErrorMsg1";}); binder.updateView(); var span = doc.find('span'); assertTrue(span.hasClass('ng-exception')); - assertEquals('ErrorMsg1', nglr.fromJson(span.text())); + assertEquals('ErrorMsg1', fromJson(span.text())); assertEquals('"ErrorMsg1"', span.attr('ng-error')); scope.set('error.throw', function(){throw "MyError";}); @@ -548,9 +547,9 @@ BinderTest.prototype.testIfTextBindingThrowsErrorDecorateTheSpan = function(){ BinderTest.prototype.testIfAttrBindingThrowsErrorDecorateTheSpan = function(){ var doc = $('
    '); - var scope = new nglr.Scope(); + var scope = new Scope(); doc.data('scope', scope); - var binder = new nglr.Binder(doc[0], new nglr.WidgetFactory(), new MockUrlWatcher()); + var binder = new Binder(doc[0], new WidgetFactory(), new MockUrlWatcher()); binder.compile(); scope.set('error.throw', function(){throw "ErrorMsg";}); @@ -570,9 +569,9 @@ BinderTest.prototype.testNestedRepeater = function() { var doc = html('
    ' + '
      ' + '
      '); - var scope = new nglr.Scope(); + var scope = new Scope(); doc.data('scope', scope); - var binder = new nglr.Binder(doc[0], new nglr.WidgetFactory(), new MockUrlWatcher()); + var binder = new Binder(doc[0], new WidgetFactory(), new MockUrlWatcher()); binder.compile(); scope.set('model', [{name:'a', item:['a1', 'a2']}, {name:'b', item:['b1', 'b2']}]); @@ -594,9 +593,9 @@ BinderTest.prototype.testNestedRepeater = function() { BinderTest.prototype.testRadioButtonGetsPrefixed = function () { var doc = html(''); - var scope = new nglr.Scope(); + var scope = new Scope(); doc.data('scope', scope); - var binder = new nglr.Binder(doc[0], new nglr.WidgetFactory(), new MockUrlWatcher()); + var binder = new Binder(doc[0], new WidgetFactory(), new MockUrlWatcher()); binder.compile(); scope.set('model', ['a1', 'a2']); @@ -611,9 +610,9 @@ BinderTest.prototype.testRadioButtonGetsPrefixed = function () { BinderTest.prototype.testHideBindingExpression = function() { var doc = html('
      '); - var scope = new nglr.Scope(); + var scope = new Scope(); doc.data('scope', scope); - var binder = new nglr.Binder(doc[0], new nglr.WidgetFactory(), new MockUrlWatcher()); + var binder = new Binder(doc[0], new WidgetFactory(), new MockUrlWatcher()); binder.compile(); scope.set('hidden', 3); @@ -629,9 +628,9 @@ BinderTest.prototype.testHideBindingExpression = function() { BinderTest.prototype.testHideBinding = function() { var doc = html('
      '); - var scope = new nglr.Scope(); + var scope = new Scope(); doc.data('scope', scope); - var binder = new nglr.Binder(doc[0], new nglr.WidgetFactory(), new MockUrlWatcher()); + var binder = new Binder(doc[0], new WidgetFactory(), new MockUrlWatcher()); binder.compile(); scope.set('hidden', 'true'); @@ -652,9 +651,9 @@ BinderTest.prototype.testHideBinding = function() { BinderTest.prototype.testShowBinding = function() { var doc = html('
      '); - var scope = new nglr.Scope(); + var scope = new Scope(); doc.data('scope', scope); - var binder = new nglr.Binder(doc[0], new nglr.WidgetFactory(), new MockUrlWatcher()); + var binder = new Binder(doc[0], new WidgetFactory(), new MockUrlWatcher()); binder.compile(); scope.set('show', 'true'); @@ -684,9 +683,9 @@ BinderTest.prototype.testBindClassUndefined = function() { BinderTest.prototype.testBindClass = function() { var doc = html('
      '); - var scope = new nglr.Scope(); + var scope = new Scope(); doc.data('scope', scope); - var binder = new nglr.Binder(doc[0], new nglr.WidgetFactory(), new MockUrlWatcher()); + var binder = new Binder(doc[0], new WidgetFactory(), new MockUrlWatcher()); binder.compile(); scope.set('class', 'testClass'); @@ -713,9 +712,9 @@ BinderTest.prototype.testBindClassEvenOdd = function() { BinderTest.prototype.testBindStyle = function() { var doc = html('
      '); - var scope = new nglr.Scope(); + var scope = new Scope(); doc.data('scope', scope); - var binder = new nglr.Binder(doc[0], new nglr.WidgetFactory(), new MockUrlWatcher()); + var binder = new Binder(doc[0], new WidgetFactory(), new MockUrlWatcher()); binder.compile(); scope.eval('style={color:"red"}'); @@ -734,7 +733,7 @@ BinderTest.prototype.testActionOnAHrefThrowsError = function(){ var state = compile('Add Phone', model); var input = state.node.find('a'); input.click(); - assertEquals('abc', nglr.fromJson(input.attr('ng-error')).a); + assertEquals('abc', fromJson(input.attr('ng-error')).a); assertNotNull(input.data('qtip')); assertTrue("should have an error class", input.hasClass('ng-exception')); @@ -890,7 +889,7 @@ BinderTest.prototype.testItShouldCallListenersWhenAnchorChanges = function() { }; BinderTest.prototype.testParseQueryString = function(){ - var binder = new nglr.Binder(); + var binder = new Binder(); assertJsonEquals({"a":"1"}, binder.parseQueryString("a=1")); assertJsonEquals({"a":"1", "b":"two"}, binder.parseQueryString("a=1&b=two")); assertJsonEquals({}, binder.parseQueryString("")); @@ -905,8 +904,8 @@ BinderTest.prototype.testParseQueryString = function(){ BinderTest.prototype.testSetBinderAnchorTriggersListeners = function(){ expectAsserts(2); var doc = html("
      ")[0]; - var binder = new nglr.Binder(doc, null, new MockUrlWatcher()); - var scope = new nglr.Scope({$binder:binder, $anchor:binder.anchor}); + var binder = new Binder(doc, null, new MockUrlWatcher()); + var scope = new Scope({$binder:binder, $anchor:binder.anchor}); jQuery(doc).data('scope', scope); scope.addWatchListener("$anchor.name", function(newVal, oldVal) { diff --git a/test/ConsoleTest.js b/test/ConsoleTest.js index 56e223bd..f659752f 100644 --- a/test/ConsoleTest.js +++ b/test/ConsoleTest.js @@ -1,13 +1,12 @@ ConsoleTest = TestCase('ConsoleTest'); ConsoleTest.prototype.testConsoleWrite = function(){ - var consoleNode = $("
      ")[0]; - nglr.consoleNode = consoleNode; - nglr.consoleLog("error", ["Hello", "world"]); + consoleNode = $("
      ")[0]; + consoleLog("error", ["Hello", "world"]); assertEquals($(consoleNode)[0].nodeName, 'DIV'); assertEquals($(consoleNode).text(), 'Hello world'); assertEquals($('div', consoleNode)[0].className, 'error'); - nglr.consoleLog("error",["Bye"]); + consoleLog("error",["Bye"]); assertEquals($(consoleNode).text(), 'Hello worldBye'); - nglr.consoleNode = null; + consoleNode = null; }; \ No newline at end of file diff --git a/test/DataStoreTest.js b/test/DataStoreTest.js index 9fe6c3df..2dd4a582 100644 --- a/test/DataStoreTest.js +++ b/test/DataStoreTest.js @@ -11,14 +11,14 @@ DataStoreTest.prototype.testSavePostsToServer = function(){ assertEquals("123", posted.$id); assertEquals("1", posted.$version); assertFalse('function' == typeof posted.save); - response = nglr.fromJson(nglr.toJson(posted)); + response = fromJson(toJson(posted)); response.$entity = "abc"; response.$id = "123"; response.$version = "2"; callback(200, [response]); }; var model; - var datastore = new nglr.DataStore(post); + var datastore = new DataStore(post); model = datastore.entity('abc', {name: "value"})(); model.$id = "123"; model.$version = "1"; @@ -44,7 +44,7 @@ DataStoreTest.prototype.testLoadGetsFromServer = function(){ response = [{$entity:'abc', $id:'1', $version:'2', key:"value"}]; callback(200, response); }; - var datastore = new nglr.DataStore(post); + var datastore = new DataStore(post); var model = datastore.entity("abc", {merge:true})(); assertEquals(datastore.load(model, '1', function(obj){ @@ -72,14 +72,14 @@ DataStoreTest.prototype.testRemove = function(){ assertEquals("123", posted.$id); assertEquals("1", posted.$version); assertFalse('function' == typeof posted.save); - response = nglr.fromJson(nglr.toJson(posted)); + response = fromJson(toJson(posted)); response.$entity = "abc"; response.$id = "123"; response.$version = "2"; callback(200, [response]); }; var model; - var datastore = new nglr.DataStore(post); + var datastore = new DataStore(post); model = datastore.entity('abc', {name: "value"})(); model.$id = "123"; model.$version = "1"; @@ -101,7 +101,7 @@ DataStoreTest.prototype.test401ResponseDoesNotCallCallback = function(){ callback(200, {$status_code: 401}); }; - var datastore = new nglr.DataStore(post, {login:function(){ + var datastore = new DataStore(post, {login:function(){ assertTrue(true); }}); @@ -119,7 +119,7 @@ DataStoreTest.prototype.test403ResponseDoesNotCallCallback = function(){ callback(200, [{$status_code: 403}]); }; - var datastore = new nglr.DataStore(post, {notAuthorized:function(){ + var datastore = new DataStore(post, {notAuthorized:function(){ assertTrue(true); }}); @@ -136,14 +136,14 @@ DataStoreTest.prototype.testLoadCalledWithoutIdShouldBeNoop = function(){ var post = function(url, callback){ assertTrue(false); }; - var datastore = new nglr.DataStore(post); + var datastore = new DataStore(post); var model = datastore.entity("abc")(); assertEquals(datastore.load(model, undefined), model); assertEquals(model.$entity, "abc"); }; DataStoreTest.prototype.testEntityFactory = function(){ - var ds = new nglr.DataStore(); + var ds = new DataStore(); var Recipe = ds.entity("Recipe", {a:1, b:2}); assertEquals(Recipe.title, "Recipe"); assertEquals(Recipe.defaults.a, 1); @@ -161,7 +161,7 @@ DataStoreTest.prototype.testEntityFactory = function(){ }; DataStoreTest.prototype.testEntityFactoryNoDefaults = function(){ - var ds = new nglr.DataStore(); + var ds = new DataStore(); var Recipe = ds.entity("Recipe"); assertEquals(Recipe.title, "Recipe"); @@ -170,7 +170,7 @@ DataStoreTest.prototype.testEntityFactoryNoDefaults = function(){ }; DataStoreTest.prototype.testEntityFactoryWithInitialValues = function(){ - var ds = new nglr.DataStore(); + var ds = new DataStore(); var Recipe = ds.entity("Recipe"); var recipe = Recipe({name: "name"}); @@ -178,7 +178,7 @@ DataStoreTest.prototype.testEntityFactoryWithInitialValues = function(){ }; DataStoreTest.prototype.testEntityLoad = function(){ - var ds = new nglr.DataStore(); + var ds = new DataStore(); var Recipe = ds.entity("Recipe", {a:1, b:2}); ds.load = function(instance, id, callback){ callback.apply(instance); @@ -192,7 +192,7 @@ DataStoreTest.prototype.testEntityLoad = function(){ }; DataStoreTest.prototype.testSaveScope = function(){ - var ds = new nglr.DataStore(); + var ds = new DataStore(); var log = ""; var Person = ds.entity("Person"); var person1 = Person({name:"A", $entity:"Person", $id:"1", $version:"1"}, ds); @@ -215,7 +215,7 @@ DataStoreTest.prototype.testSaveScope = function(){ }; DataStoreTest.prototype.testEntityLoadAllRows = function(){ - var ds = new nglr.DataStore(); + var ds = new DataStore(); var Recipe = ds.entity("Recipe"); var list = []; ds.loadAll = function(entity, callback){ @@ -236,7 +236,7 @@ DataStoreTest.prototype.testLoadAll = function(){ assertEquals("A", data[0][1]); callback(200, [[{$entity:'A', $id:'1'},{$entity:'A', $id:'2'}]]); }; - var datastore = new nglr.DataStore(post); + var datastore = new DataStore(post); var list = datastore.entity("A").all(function(){ assertTrue(true); }); @@ -256,7 +256,7 @@ DataStoreTest.prototype.testQuery = function(){ callback(200, [[{$entity:"Employee", $id: "456", managerId: "123ABC"}]]); }; - var datastore = new nglr.DataStore(post); + var datastore = new DataStore(post); var Employee = datastore.entity("Employee"); var list = Employee.query('managerId', "123abc", function(){ assertTrue(true); @@ -269,7 +269,7 @@ DataStoreTest.prototype.testQuery = function(){ DataStoreTest.prototype.testLoadingDocumentRefreshesExistingArrays = function() { expectAsserts(12); var post; - var datastore = new nglr.DataStore(function(r, c){post(r,c);}); + var datastore = new DataStore(function(r, c){post(r,c);}); var Book = datastore.entity('Book'); post = function(req, callback) { callback(200, [[{$id:1, $entity:"Book", name:"Moby"}, @@ -285,7 +285,7 @@ DataStoreTest.prototype.testLoadingDocumentRefreshesExistingArrays = function() assertEquals("Dick", queryBooks[1].name); post = function(req, callback) { - assertEquals('[["GET","Book/1"]]', nglr.toJson(req)); + assertEquals('[["GET","Book/1"]]', toJson(req)); callback(200, [{$id:1, $entity:"Book", name:"Moby Dick"}]); }; var book = Book.load(1); @@ -307,7 +307,7 @@ DataStoreTest.prototype.testLoadingDocumentRefreshesExistingArrays = function() DataStoreTest.prototype.testEntityProperties = function() { expectAsserts(2); - var datastore = new nglr.DataStore(); + var datastore = new DataStore(); var callback = {}; datastore._jsonRequest = function(request, callbackFn) { @@ -322,11 +322,11 @@ DataStoreTest.prototype.testEntityProperties = function() { DataStoreTest.prototype.testLoadInstanceIsNotFromCache = function() { var post; - var datastore = new nglr.DataStore(function(r, c){post(r,c);}); + var datastore = new DataStore(function(r, c){post(r,c);}); var Book = datastore.entity('Book'); post = function(req, callback) { - assertEquals('[["GET","Book/1"]]', nglr.toJson(req)); + assertEquals('[["GET","Book/1"]]', toJson(req)); callback(200, [{$id:1, $entity:"Book", name:"Moby Dick"}]); }; var book = Book.load(1); @@ -336,14 +336,14 @@ DataStoreTest.prototype.testLoadInstanceIsNotFromCache = function() { }; DataStoreTest.prototype.testLoadStarsIsNewDocument = function() { - var datastore = new nglr.DataStore(); + var datastore = new DataStore(); var Book = datastore.entity('Book'); var book = Book.load('*'); assertEquals('Book', book.$entity); }; DataStoreTest.prototype.testUndefinedEntityReturnsNullValueObject = function() { - var datastore = new nglr.DataStore(); + var datastore = new DataStore(); var Entity = datastore.entity(undefined); var all = Entity.all(); assertEquals(0, all.length); @@ -355,7 +355,7 @@ DataStoreTest.prototype.testFetchEntities = function(){ assertJsonEquals(["GET", "$entities"], data[0]); callback(200, [{A:0, B:0}]); }; - var datastore = new nglr.DataStore(post); + var datastore = new DataStore(post); var entities = datastore.entities(function(){ assertTrue(true); }); @@ -367,20 +367,20 @@ DataStoreTest.prototype.testFetchEntities = function(){ }; DataStoreTest.prototype.testItShouldMigrateSchema = function() { - var datastore = new nglr.DataStore(); + var datastore = new DataStore(); var Entity = datastore.entity("Entity", {a:[], user:{name:"Misko", email:""}}); var doc = Entity().$loadFrom({b:'abc', user:{email:"misko@hevery.com"}}); assertFalse( - nglr.toJson({a:[], b:'abc', user:{name:"Misko", email:"misko@hevery.com"}}) == - nglr.toJson(doc)); + toJson({a:[], b:'abc', user:{name:"Misko", email:"misko@hevery.com"}}) == + toJson(doc)); doc.$migrate(); assertEquals( - nglr.toJson({a:[], b:'abc', user:{name:"Misko", email:"misko@hevery.com"}}), - nglr.toJson(doc)); + toJson({a:[], b:'abc', user:{name:"Misko", email:"misko@hevery.com"}}), + toJson(doc)); }; DataStoreTest.prototype.testItShouldCollectRequestsForBulk = function() { - var ds = new nglr.DataStore(); + var ds = new DataStore(); var Book = ds.entity("Book"); var Library = ds.entity("Library"); Book.all(); @@ -391,7 +391,7 @@ DataStoreTest.prototype.testItShouldCollectRequestsForBulk = function() { }; DataStoreTest.prototype.testEmptyFlushShouldDoNothing = function () { - var ds = new nglr.DataStore(function(){ + var ds = new DataStore(function(){ fail("expecting noop"); }); ds.flush(); @@ -400,17 +400,17 @@ DataStoreTest.prototype.testEmptyFlushShouldDoNothing = function () { DataStoreTest.prototype.testFlushShouldCallAllCallbacks = function() { var log = ""; function post(request, callback){ - log += 'BulkRequest:' + nglr.toJson(request) + ';'; + log += 'BulkRequest:' + toJson(request) + ';'; callback(200, [[{$id:'ABC'}], {$id:'XYZ'}]); } - var ds = new nglr.DataStore(post); + var ds = new DataStore(post); var Book = ds.entity("Book"); var Library = ds.entity("Library"); Book.all(function(instance){ - log += nglr.toJson(instance) + ';'; + log += toJson(instance) + ';'; }); Library.load("123", function(instance){ - log += nglr.toJson(instance) + ';'; + log += toJson(instance) + ';'; }); assertEquals("", log); ds.flush(); @@ -421,7 +421,7 @@ DataStoreTest.prototype.testFlushShouldCallAllCallbacks = function() { DataStoreTest.prototype.testSaveOnNotLoggedInRetriesAfterLoggin = function(){ var log = ""; var book; - var ds = new nglr.DataStore(null, {login:function(c){c();}}); + var ds = new DataStore(null, {login:function(c){c();}}); ds.post = function (request, callback){ assertJsonEquals([["POST", "", book]], request); ds.post = function(request, callback){ @@ -439,7 +439,7 @@ DataStoreTest.prototype.testSaveOnNotLoggedInRetriesAfterLoggin = function(){ DataStoreTest.prototype.testItShouldRemoveItemFromCollectionWhenDeleted = function() { expectAsserts(6); - var ds = new nglr.DataStore(); + var ds = new DataStore(); ds.post = function(request, callback){ assertJsonEquals([["GET", "Book"]], request); callback(200, [[{name:"Moby Dick", $id:123, $entity:'Book'}]]); @@ -462,7 +462,7 @@ DataStoreTest.prototype.testItShouldRemoveItemFromCollectionWhenDeleted = functi DataStoreTest.prototype.testItShouldAddToAll = function() { expectAsserts(8); - var ds = new nglr.DataStore(); + var ds = new DataStore(); ds.post = function(request, callback){ assertJsonEquals([["GET", "Book"]], request); callback(200, [[]]); @@ -490,7 +490,7 @@ DataStoreTest.prototype.testItShouldAddToAll = function() { DataStoreTest.prototype.testItShouldReturnCreatedDocumentCountByUser = function(){ expectAsserts(2); - var datastore = new nglr.DataStore( + var datastore = new DataStore( function(request, callback){ assertJsonEquals([["GET", "$users"]], request); callback(200, [{misko:1, adam:1}]); @@ -502,7 +502,7 @@ DataStoreTest.prototype.testItShouldReturnCreatedDocumentCountByUser = function( DataStoreTest.prototype.testItShouldReturnDocumentIdsForUeserByEntity = function(){ expectAsserts(2); - var datastore = new nglr.DataStore( + var datastore = new DataStore( function(request, callback){ assertJsonEquals([["GET", "$users/misko@hevery.com"]], request); callback(200, [{Book:["1"], Library:["2"]}]); @@ -514,7 +514,7 @@ DataStoreTest.prototype.testItShouldReturnDocumentIdsForUeserByEntity = function DataStoreTest.prototype.testItShouldReturnNewInstanceOn404 = function(){ expectAsserts(7); var log = ""; - var datastore = new nglr.DataStore( + var datastore = new DataStore( function(request, callback){ assertJsonEquals([["GET", "User/misko"]], request); callback(200, [{$status_code:404}]); @@ -532,13 +532,13 @@ DataStoreTest.prototype.testItShouldReturnNewInstanceOn404 = function(){ DataStoreTest.prototype.testItShouldReturnNewInstanceOn404 = function(){ var log = ""; - var datastore = new nglr.DataStore( + var datastore = new DataStore( function(request, callback){ assertJsonEquals([["GET", "User/misko"],["GET", "User/adam"]], request); callback(200, [{$id:'misko'},{$id:'adam'}]); }); var User = datastore.entity("User"); - var users = User.loadMany(['misko', 'adam'], function(i){log+="cb "+nglr.toJson(i)+";";}); + var users = User.loadMany(['misko', 'adam'], function(i){log+="cb "+toJson(i)+";";}); datastore.flush(); assertEquals("misko", users[0].$id); assertEquals("adam", users[1].$id); @@ -546,7 +546,7 @@ DataStoreTest.prototype.testItShouldReturnNewInstanceOn404 = function(){ }; DataStoreTest.prototype.testItShouldCreateJoinAndQuery = function() { - var datastore = new nglr.DataStore(); + var datastore = new DataStore(); var Invoice = datastore.entity("Invoice"); var Customer = datastore.entity("Customer"); var InvoiceWithCustomer = datastore.join({ @@ -568,7 +568,7 @@ DataStoreTest.prototype.testItShouldCreateJoinAndQuery = function() { }; DataStoreTest.prototype.testItShouldThrowIfMoreThanOneEntityIsPrimary = function() { - var datastore = new nglr.DataStore(); + var datastore = new DataStore(); var Invoice = datastore.entity("Invoice"); var Customer = datastore.entity("Customer"); assertThrows("Exactly one entity needs to be primary.", function(){ @@ -580,7 +580,7 @@ DataStoreTest.prototype.testItShouldThrowIfMoreThanOneEntityIsPrimary = function }; DataStoreTest.prototype.testItShouldThrowIfLoopInReferences = function() { - var datastore = new nglr.DataStore(); + var datastore = new DataStore(); var Invoice = datastore.entity("Invoice"); var Customer = datastore.entity("Customer"); assertThrows("Infinite loop in join: invoice -> customer", function(){ @@ -592,7 +592,7 @@ DataStoreTest.prototype.testItShouldThrowIfLoopInReferences = function() { }; DataStoreTest.prototype.testItShouldThrowIfReferenceToNonExistantJoin = function() { - var datastore = new nglr.DataStore(); + var datastore = new DataStore(); var Invoice = datastore.entity("Invoice"); var Customer = datastore.entity("Customer"); assertThrows("Named entity 'x' is undefined.", function(){ @@ -604,7 +604,7 @@ DataStoreTest.prototype.testItShouldThrowIfReferenceToNonExistantJoin = function }; DataStoreTest.prototype.testItShouldThrowIfQueryOnNonPrimary = function() { - var datastore = new nglr.DataStore(); + var datastore = new DataStore(); var Invoice = datastore.entity("Invoice"); var Customer = datastore.entity("Customer"); var InvoiceWithCustomer = datastore.join({ diff --git a/test/EntityDeclarationTest.js b/test/EntityDeclarationTest.js index 5cab90f4..d64dd775 100644 --- a/test/EntityDeclarationTest.js +++ b/test/EntityDeclarationTest.js @@ -2,7 +2,7 @@ EntityDeclarationTest = TestCase('EntityDeclarationTest'); EntityDeclarationTest.prototype.testEntityTypeOnly = function(){ expectAsserts(2); - var scope = new nglr.Scope({$datastore:{entity:function(name){ + var scope = new Scope({$datastore:{entity:function(name){ assertEquals("Person", name); }}}); var init = scope.entity("Person"); @@ -11,7 +11,7 @@ EntityDeclarationTest.prototype.testEntityTypeOnly = function(){ EntityDeclarationTest.prototype.testWithDefaults = function(){ expectAsserts(4); - var scope = new nglr.Scope({$datastore:{entity:function(name, init){ + var scope = new Scope({$datastore:{entity:function(name, init){ assertEquals("Person", name); assertEquals("=a:", init.a); assertEquals(0, init.b.length); @@ -22,7 +22,7 @@ EntityDeclarationTest.prototype.testWithDefaults = function(){ EntityDeclarationTest.prototype.testWithName = function(){ expectAsserts(2); - var scope = new nglr.Scope({$datastore:{entity:function(name, init){ + var scope = new Scope({$datastore:{entity:function(name, init){ assertEquals("Person", name); return function (){ return {}; }; }}}); @@ -34,7 +34,7 @@ EntityDeclarationTest.prototype.testMultipleEntities = function(){ expectAsserts(3); var expect = ['Person', 'Book']; var i=0; - var scope = new nglr.Scope({$datastore:{entity:function(name, init){ + var scope = new Scope({$datastore:{entity:function(name, init){ assertEquals(expect[i], name); i++; return function (){ return {}; }; diff --git a/test/FileControllerTest.js b/test/FileControllerTest.js index ca5925e4..09eb6fc5 100644 --- a/test/FileControllerTest.js +++ b/test/FileControllerTest.js @@ -3,7 +3,7 @@ FileControllerTest = TestCase('FileControllerTest'); FileControllerTest.prototype.testOnSelectUpdateView = function(){ var view = jQuery(''); var swf = {}; - var controller = new nglr.FileController(view, null, swf); + var controller = new FileController(view, null, swf); swf.uploadFile = function(path){}; controller._on_select('A', 9, '9 bytes'); assertEquals(view.find('a').text(), "A"); @@ -11,14 +11,14 @@ FileControllerTest.prototype.testOnSelectUpdateView = function(){ }; FileControllerTest.prototype.testUpdateModelView = function(){ - var view = nglr.FileController.template(''); + var view = FileController.template(''); var input = $(''); var controller; - var scope = new nglr.Scope({value:{}, $binder:{updateView:function(){ + var scope = new Scope({value:{}, $binder:{updateView:function(){ controller.updateView(scope); }}}); view.data('scope', scope); - controller = new nglr.FileController(view, 'value.input', null, "http://server_base"); + controller = new FileController(view, 'value.input', null, "http://server_base"); var value = '{"text":"A", "size":123, "id":"890"}'; controller._on_uploadCompleteData(value); controller.updateView(scope); @@ -34,7 +34,7 @@ FileControllerTest.prototype.testUpdateModelView = function(){ FileControllerTest.prototype.testFileUpload = function(){ expectAsserts(1); var swf = {}; - var controller = new nglr.FileController(null, null, swf, "http://server_base"); + var controller = new FileController(null, null, swf, "http://server_base"); swf.uploadFile = function(path){ assertEquals("http://server_base/_attachments", path); }; @@ -47,16 +47,16 @@ FileControllerTest.prototype.testFileUploadNoFileIsNoop = function(){ var swf = {uploadFile:function(path){ fail(); }}; - var controller = new nglr.FileController(null, swf); + var controller = new FileController(null, swf); controller.upload("basePath", null); }; FileControllerTest.prototype.testRemoveAttachment = function(){ - var doc = nglr.FileController.template(); + var doc = FileController.template(); var input = $(''); - var scope = new nglr.Scope(); + var scope = new Scope(); input.data('scope', scope); - var controller = new nglr.FileController(doc, 'file', null, null); + var controller = new FileController(doc, 'file', null, null); controller.updateView(scope); assertEquals(false, doc.find('input').attr('checked')); @@ -75,10 +75,10 @@ FileControllerTest.prototype.testRemoveAttachment = function(){ }; FileControllerTest.prototype.testShouldEmptyOutOnUndefined = function () { - var view = nglr.FileController.template('hello'); - var controller = new nglr.FileController(view, 'abc', null, null); + var view = FileController.template('hello'); + var controller = new FileController(view, 'abc', null, null); - var scope = new nglr.Scope(); + var scope = new Scope(); scope.set('abc', {text: 'myname', url: 'myurl', size: 1234}); controller.updateView(scope); diff --git a/test/FiltersTest.js b/test/FiltersTest.js index 8943fdd4..c219f24f 100644 --- a/test/FiltersTest.js +++ b/test/FiltersTest.js @@ -3,7 +3,7 @@ FiltersTest = TestCase('FiltersTest'); FiltersTest.prototype.testCurrency = function(){ var html = $(''); var context = {element:html[0]}; - var currency = nglr.bind(context, angular.filter.currency); + var currency = bind(context, angular.filter.currency); assertEquals(currency(0), '$0.00'); assertEquals(html.hasClass('ng-format-negative'), false); @@ -15,8 +15,8 @@ FiltersTest.prototype.testCurrency = function(){ FiltersTest.prototype.testFilterThisIsContext = function(){ expectAsserts(2); - var scope = new nglr.Scope(); - nglr.Scope.expressionCache = {}; + var scope = new Scope(); + Scope.expressionCache = {}; var context = {element:123}; angular.filter.testFn = function () { assertEquals('Context not equal', this, context); @@ -28,7 +28,7 @@ FiltersTest.prototype.testFilterThisIsContext = function(){ FiltersTest.prototype.testNumberFormat = function(){ var context = {jqElement:$('')}; - var number = nglr.bind(context, angular.filter.number); + var number = bind(context, angular.filter.number); assertEquals('0', number(0, 0)); assertEquals('0.00', number(0)); @@ -40,7 +40,7 @@ FiltersTest.prototype.testNumberFormat = function(){ }; FiltersTest.prototype.testJson = function () { - assertEquals(nglr.toJson({a:"b"}, true), angular.filter.json({a:"b"})); + assertEquals(toJson({a:"b"}, true), angular.filter.json({a:"b"})); }; FiltersTest.prototype.testPackageTracking = function () { @@ -48,9 +48,9 @@ FiltersTest.prototype.testPackageTracking = function () { var val = angular.filter.trackPackage(trackingNo, title); assertNotNull("Did Not Match: " + trackingNo, val); assertEquals(angular.filter.Meta.TAG, val.TAG); - assertEquals(title + ": " + nglr.trim(trackingNo), val.text); + assertEquals(title + ": " + trim(trackingNo), val.text); assertNotNull(val.url); - assertEquals(nglr.trim(trackingNo), val.trackingNo); + assertEquals(trim(trackingNo), val.trackingNo); assertEquals('' + val.text + '', val.html); }; assert('UPS', ' 1Z 999 999 99 9999 999 9 '); @@ -83,7 +83,7 @@ FiltersTest.prototype.testLink = function() { }; FiltersTest.prototype.testBytes = function(){ - var controller = new nglr.FileController(); + var controller = new FileController(); assertEquals(angular.filter.bytes(123), '123 bytes'); assertEquals(angular.filter.bytes(1234), '1.2 KB'); assertEquals(angular.filter.bytes(1234567), '1.1 MB'); diff --git a/test/JsonTest.js b/test/JsonTest.js index 5c3644f5..cf49bec3 100644 --- a/test/JsonTest.js +++ b/test/JsonTest.js @@ -1,69 +1,69 @@ JsonTest = TestCase("JsonTest"); JsonTest.prototype.testPrimitives = function () { - assertEquals("null", nglr.toJson(0/0)); - assertEquals("null", nglr.toJson(null)); - assertEquals("true", nglr.toJson(true)); - assertEquals("false", nglr.toJson(false)); - assertEquals("123.45", nglr.toJson(123.45)); - assertEquals('"abc"', nglr.toJson("abc")); - assertEquals('"a \\t \\n \\r b \\\\"', nglr.toJson("a \t \n \r b \\")); + assertEquals("null", toJson(0/0)); + assertEquals("null", toJson(null)); + assertEquals("true", toJson(true)); + assertEquals("false", toJson(false)); + assertEquals("123.45", toJson(123.45)); + assertEquals('"abc"', toJson("abc")); + assertEquals('"a \\t \\n \\r b \\\\"', toJson("a \t \n \r b \\")); }; JsonTest.prototype.testEscaping = function () { - assertEquals("\"7\\\\\\\"7\"", nglr.toJson("7\\\"7")); + assertEquals("\"7\\\\\\\"7\"", toJson("7\\\"7")); }; JsonTest.prototype.testObjects = function () { - assertEquals('{"a":1,"b":2}', nglr.toJson({a:1,b:2})); - assertEquals('{"a":{"b":2}}', nglr.toJson({a:{b:2}})); - assertEquals('{"a":{"b":{"c":0}}}', nglr.toJson({a:{b:{c:0}}})); - assertEquals('{"a":{"b":null}}', nglr.toJson({a:{b:0/0}})); + assertEquals('{"a":1,"b":2}', toJson({a:1,b:2})); + assertEquals('{"a":{"b":2}}', toJson({a:{b:2}})); + assertEquals('{"a":{"b":{"c":0}}}', toJson({a:{b:{c:0}}})); + assertEquals('{"a":{"b":null}}', toJson({a:{b:0/0}})); }; JsonTest.prototype.testObjectPretty = function () { - assertEquals('{\n "a":1,\n "b":2}', nglr.toJson({a:1,b:2}, true)); - assertEquals('{\n "a":{\n "b":2}}', nglr.toJson({a:{b:2}}, true)); + assertEquals('{\n "a":1,\n "b":2}', toJson({a:1,b:2}, true)); + assertEquals('{\n "a":{\n "b":2}}', toJson({a:{b:2}}, true)); }; JsonTest.prototype.testArray = function () { - assertEquals('[]', nglr.toJson([])); - assertEquals('[1,"b"]', nglr.toJson([1,"b"])); + assertEquals('[]', toJson([])); + assertEquals('[1,"b"]', toJson([1,"b"])); }; JsonTest.prototype.testIgnoreFunctions = function () { - assertEquals('[null,1]', nglr.toJson([function(){},1])); - assertEquals('{}', nglr.toJson({a:function(){}})); + assertEquals('[null,1]', toJson([function(){},1])); + assertEquals('{}', toJson({a:function(){}})); }; JsonTest.prototype.testParseNull = function () { - assertNull(nglr.fromJson("null")); + assertNull(fromJson("null")); }; JsonTest.prototype.testParseBoolean = function () { - assertTrue(nglr.fromJson("true")); - assertFalse(nglr.fromJson("false")); + assertTrue(fromJson("true")); + assertFalse(fromJson("false")); }; JsonTest.prototype.test$$isIgnored = function () { - assertEquals("{}", nglr.toJson({$$:0})); + assertEquals("{}", toJson({$$:0})); }; JsonTest.prototype.testArrayWithEmptyItems = function () { var a = []; a[1] = "X"; - assertEquals('[null,"X"]', nglr.toJson(a)); + assertEquals('[null,"X"]', toJson(a)); }; JsonTest.prototype.testItShouldEscapeUnicode = function () { assertEquals(1, "\u00a0".length); - assertEquals(8, nglr.toJson("\u00a0").length); - assertEquals(1, nglr.fromJson(nglr.toJson("\u00a0")).length); + assertEquals(8, toJson("\u00a0").length); + assertEquals(1, fromJson(toJson("\u00a0")).length); }; JsonTest.prototype.testItShouldUTCDates = function() { var date = angular.String.toDate("2009-10-09T01:02:03Z"); - assertEquals('"2009-10-09T01:02:03Z"', nglr.toJson(date)); + assertEquals('"2009-10-09T01:02:03Z"', toJson(date)); assertEquals(date.getTime(), - nglr.fromJson('"2009-10-09T01:02:03Z"').getTime()); + fromJson('"2009-10-09T01:02:03Z"').getTime()); }; diff --git a/test/LoaderTest.js b/test/LoaderTest.js index 91a804a5..88ae3efa 100644 --- a/test/LoaderTest.js +++ b/test/LoaderTest.js @@ -3,7 +3,7 @@ LoaderTest = TestCase('LoaderTest'); LoaderTest.prototype.testLoadCss = function(){ if ($.browser.safari) return; var head = jQuery('')[0]; - var loader = new nglr.Loader(document, head, {}); + var loader = new Loader(document, head, {}); var log = ''; loader.config.server = 'http://'; loader.loadCss('x'); @@ -11,15 +11,15 @@ LoaderTest.prototype.testLoadCss = function(){ }; LoaderTest.prototype.testDefaultDatabasePathFromSubdomain = function() { - var loader = new nglr.Loader(null, null, {server:"http://account.getangular.com", database:"database"}); + var loader = new Loader(null, null, {server:"http://account.getangular.com", database:"database"}); loader.computeConfiguration(); assertEquals("database", loader.config.database); - loader = new nglr.Loader(null, null, {server:"http://account.getangular.com"}); + loader = new Loader(null, null, {server:"http://account.getangular.com"}); loader.computeConfiguration(); assertEquals("account", loader.config.database); - loader = new nglr.Loader(null, null, {server:"https://account.getangular.com"}); + loader = new Loader(null, null, {server:"https://account.getangular.com"}); loader.computeConfiguration(); assertEquals("account", loader.config.database); }; @@ -31,7 +31,7 @@ UrlWatcherTest = TestCase('UrlWatcherTest'); UrlWatcherTest.prototype.testUrlWatcher = function () { expectAsserts(2); var location = {href:"http://server", hash:""}; - var watcher = new nglr.UrlWatcher(location); + var watcher = new UrlWatcher(location); watcher.delay = 1; watcher.listener = function(url){ assertEquals('http://getangular.test', url); @@ -49,9 +49,9 @@ UrlWatcherTest.prototype.testUrlWatcher = function () { UrlWatcherTest.prototype.testItShouldFireOnUpdateEventWhenSpecialURLSet = function(){ expectAsserts(2); var location = {href:"http://server", hash:"#$iframe_notify=1234"}; - var watcher = new nglr.UrlWatcher(location); - nglr._iframe_notify_1234 = function () { - assertEquals("undefined", typeof nglr._iframe_notify_1234); + var watcher = new UrlWatcher(location); + callbacks._iframe_notify_1234 = function () { + assertEquals("undefined", typeof callbacks._iframe_notify_1234); assertEquals("http://server2#", location.href); }; watcher.delay = 1; @@ -66,5 +66,5 @@ UrlWatcherTest.prototype.testItShouldFireOnUpdateEventWhenSpecialURLSet = functi FunctionTest = TestCase("FunctionTest"); FunctionTest.prototype.testEscapeHtml = function () { - assertEquals("<div>&amp;</div>", nglr.escapeHtml('
      &
      ')); + assertEquals("<div>&amp;</div>", escapeHtml('
      &
      ')); }; \ No newline at end of file diff --git a/test/ModelTest.js b/test/ModelTest.js index 5d9119a1..dbd97778 100644 --- a/test/ModelTest.js +++ b/test/ModelTest.js @@ -1,7 +1,7 @@ ModelTest = TestCase('ModelTest'); ModelTest.prototype.testLoadSaveOperations = function(){ - var m1 = new nglr.DataStore().entity('A')(); + var m1 = new DataStore().entity('A')(); m1.a = 1; var m2 = {b:1}; @@ -13,7 +13,7 @@ ModelTest.prototype.testLoadSaveOperations = function(){ }; ModelTest.prototype.testLoadfromDoesNotClobberFunctions = function(){ - var m1 = new nglr.DataStore().entity('A')(); + var m1 = new DataStore().entity('A')(); m1.id = function(){return 'OK';}; m1.$loadFrom({id:null}); assertEquals(m1.id(), 'OK'); @@ -24,7 +24,7 @@ ModelTest.prototype.testLoadfromDoesNotClobberFunctions = function(){ }; ModelTest.prototype.testDataStoreDoesNotGetClobbered = function(){ - var ds = new nglr.DataStore(); + var ds = new DataStore(); var m = ds.entity('A')(); assertTrue(m.$$entity.datastore === ds); m.$loadFrom({}); @@ -33,7 +33,7 @@ ModelTest.prototype.testDataStoreDoesNotGetClobbered = function(){ ModelTest.prototype.testManagedModelDelegatesMethodsToDataStore = function(){ expectAsserts(7); - var datastore = new nglr.DataStore(); + var datastore = new DataStore(); var model = datastore.entity("A", {a:1})(); var fn = {}; datastore.save = function(instance, callback) { @@ -56,7 +56,7 @@ ModelTest.prototype.testManagedModelDelegatesMethodsToDataStore = function(){ ModelTest.prototype.testManagedModelCanBeForcedToFlush = function(){ expectAsserts(6); - var datastore = new nglr.DataStore(); + var datastore = new DataStore(); var model = datastore.entity("A", {a:1})(); datastore.save = function(instance, callback) { @@ -77,7 +77,7 @@ ModelTest.prototype.testManagedModelCanBeForcedToFlush = function(){ ModelTest.prototype.testItShouldMakeDeepCopyOfInitialValues = function (){ var initial = {a:[]}; - var entity = new nglr.DataStore().entity("A", initial); + var entity = new DataStore().entity("A", initial); var model = entity(); model.a.push(1); assertEquals(0, entity().a.length); diff --git a/test/ParserTest.js b/test/ParserTest.js index 7fe8e6a4..058010f3 100644 --- a/test/ParserTest.js +++ b/test/ParserTest.js @@ -1,7 +1,7 @@ LexerTest = TestCase('LexerTest'); LexerTest.prototype.testTokenizeAString = function(){ - var lexer = new nglr.Lexer("a.bc[22]+1.3|f:'a\\\'c':\"d\\\"e\""); + var lexer = new Lexer("a.bc[22]+1.3|f:'a\\\'c':\"d\\\"e\""); var tokens = lexer.parse(); var i = 0; assertEquals(tokens[i].index, 0); @@ -54,7 +54,7 @@ LexerTest.prototype.testTokenizeAString = function(){ LexerTest.prototype.testTokenizeRegExp = function(){ - var lexer = new nglr.Lexer("/r 1/"); + var lexer = new Lexer("/r 1/"); var tokens = lexer.parse(); var i = 0; assertEquals(tokens[i].index, 0); @@ -64,7 +64,7 @@ LexerTest.prototype.testTokenizeRegExp = function(){ LexerTest.prototype.testQuotedString = function(){ var str = "['\\'', \"\\\"\"]"; - var lexer = new nglr.Lexer(str); + var lexer = new Lexer(str); var tokens = lexer.parse(); assertEquals(1, tokens[1].index); @@ -77,21 +77,21 @@ LexerTest.prototype.testQuotedString = function(){ LexerTest.prototype.testQuotedStringEscape = function(){ var str = '"\\"\\n\\f\\r\\t\\v\\u00A0"'; - var lexer = new nglr.Lexer(str); + var lexer = new Lexer(str); var tokens = lexer.parse(); assertEquals('"\n\f\r\t\v\u00A0', tokens[0].text); }; LexerTest.prototype.testTokenizeUnicode = function(){ - var lexer = new nglr.Lexer('"\\u00A0"'); + var lexer = new Lexer('"\\u00A0"'); var tokens = lexer.parse(); assertEquals(1, tokens.length); assertEquals('\u00a0', tokens[0].text); }; LexerTest.prototype.testTokenizeRegExpWithOptions = function(){ - var lexer = new nglr.Lexer("/r/g"); + var lexer = new Lexer("/r/g"); var tokens = lexer.parse(); var i = 0; assertEquals(tokens[i].index, 0); @@ -101,7 +101,7 @@ LexerTest.prototype.testTokenizeRegExpWithOptions = function(){ }; LexerTest.prototype.testTokenizeRegExpWithEscape = function(){ - var lexer = new nglr.Lexer("/\\/\\d/"); + var lexer = new Lexer("/\\/\\d/"); var tokens = lexer.parse(); var i = 0; assertEquals(tokens[i].index, 0); @@ -110,14 +110,14 @@ LexerTest.prototype.testTokenizeRegExpWithEscape = function(){ }; LexerTest.prototype.testIgnoreWhitespace = function(){ - var lexer = new nglr.Lexer("a \t \n \r b"); + var lexer = new Lexer("a \t \n \r b"); var tokens = lexer.parse(); assertEquals(tokens[0].text, 'a'); assertEquals(tokens[1].text, 'b'); }; LexerTest.prototype.testRelation = function(){ - var lexer = new nglr.Lexer("! == != < > <= >="); + var lexer = new Lexer("! == != < > <= >="); var tokens = lexer.parse(); assertEquals(tokens[0].text, '!'); assertEquals(tokens[1].text, '=='); @@ -129,7 +129,7 @@ LexerTest.prototype.testRelation = function(){ }; LexerTest.prototype.testStatements = function(){ - var lexer = new nglr.Lexer("a;b;"); + var lexer = new Lexer("a;b;"); var tokens = lexer.parse(); assertEquals(tokens[0].text, 'a'); assertEquals(tokens[1].text, ';'); @@ -140,7 +140,7 @@ LexerTest.prototype.testStatements = function(){ ParserTest = TestCase('ParserTest'); ParserTest.prototype.testExpressions = function(){ - var scope = new nglr.Scope(); + var scope = new Scope(); assertEquals(scope.eval("-1"), -1); assertEquals(scope.eval("1 + 2.5"), 3.5); assertEquals(scope.eval("1 + -2.5"), -1.5); @@ -151,7 +151,7 @@ ParserTest.prototype.testExpressions = function(){ }; ParserTest.prototype.testComparison = function(){ - var scope = new nglr.Scope(); + var scope = new Scope(); assertEquals(scope.eval("false"), false); assertEquals(scope.eval("!true"), false); assertEquals(scope.eval("1==1"), true); @@ -163,14 +163,14 @@ ParserTest.prototype.testComparison = function(){ }; ParserTest.prototype.testLogical = function(){ - var scope = new nglr.Scope(); + var scope = new Scope(); assertEquals(scope.eval("0&&2"), 0&&2); assertEquals(scope.eval("0||2"), 0||2); assertEquals(scope.eval("0||1&&2"), 0||1&&2); }; ParserTest.prototype.testString = function(){ - var scope = new nglr.Scope(); + var scope = new Scope(); assertEquals(scope.eval("'a' + 'b c'"), "ab c"); }; @@ -182,7 +182,7 @@ ParserTest.prototype.testFilters = function(){ angular.filter.upper = {_case:function(input) { return input.toUpperCase(); }}; - var scope = new nglr.Scope(); + var scope = new Scope(); try { scope.eval("1|nonExistant"); fail(); @@ -196,7 +196,7 @@ ParserTest.prototype.testFilters = function(){ }; ParserTest.prototype.testScopeAccess = function(){ - var scope = new nglr.Scope(); + var scope = new Scope(); scope.set('a', 123); scope.set('b.c', 456); assertEquals(scope.eval("a", scope), 123); @@ -205,16 +205,16 @@ ParserTest.prototype.testScopeAccess = function(){ }; ParserTest.prototype.testGrouping = function(){ - var scope = new nglr.Scope(); + var scope = new Scope(); assertEquals(scope.eval("(1+2)*3"), (1+2)*3); }; ParserTest.prototype.testAssignments = function(){ - var scope = new nglr.Scope(); + var scope = new Scope(); assertEquals(scope.eval("a=12"), 12); assertEquals(scope.get("a"), 12); - scope = new nglr.Scope(); + scope = new Scope(); assertEquals(scope.eval("x.y.z=123;"), 123); assertEquals(scope.get("x.y.z"), 123); @@ -224,13 +224,13 @@ ParserTest.prototype.testAssignments = function(){ }; ParserTest.prototype.testFunctionCallsNoArgs = function(){ - var scope = new nglr.Scope(); + var scope = new Scope(); scope.set('const', function(a,b){return 123;}); assertEquals(scope.eval("const()"), 123); }; ParserTest.prototype.testFunctionCalls = function(){ - var scope = new nglr.Scope(); + var scope = new Scope(); scope.set('add', function(a,b){ return a+b; }); @@ -238,7 +238,7 @@ ParserTest.prototype.testFunctionCalls = function(){ }; ParserTest.prototype.testCalculationBug = function(){ - var scope = new nglr.Scope(); + var scope = new Scope(); scope.set('taxRate', 8); scope.set('subTotal', 100); assertEquals(scope.eval("taxRate / 100 * subTotal"), 8); @@ -246,7 +246,7 @@ ParserTest.prototype.testCalculationBug = function(){ }; ParserTest.prototype.testArray = function(){ - var scope = new nglr.Scope(); + var scope = new Scope(); assertEquals(scope.eval("[]").length, 0); assertEquals(scope.eval("[1, 2]").length, 2); assertEquals(scope.eval("[1, 2]")[0], 1); @@ -254,7 +254,7 @@ ParserTest.prototype.testArray = function(){ }; ParserTest.prototype.testArrayAccess = function(){ - var scope = new nglr.Scope(); + var scope = new Scope(); assertEquals(scope.eval("[1][0]"), 1); assertEquals(scope.eval("[[1]][0][0]"), 1); assertEquals(scope.eval("[].length"), 0); @@ -262,33 +262,33 @@ ParserTest.prototype.testArrayAccess = function(){ }; ParserTest.prototype.testObject = function(){ - var scope = new nglr.Scope(); - assertEquals(nglr.toJson(scope.eval("{}")), "{}"); - assertEquals(nglr.toJson(scope.eval("{a:'b'}")), '{"a":"b"}'); - assertEquals(nglr.toJson(scope.eval("{'a':'b'}")), '{"a":"b"}'); - assertEquals(nglr.toJson(scope.eval("{\"a\":'b'}")), '{"a":"b"}'); + var scope = new Scope(); + assertEquals(toJson(scope.eval("{}")), "{}"); + assertEquals(toJson(scope.eval("{a:'b'}")), '{"a":"b"}'); + assertEquals(toJson(scope.eval("{'a':'b'}")), '{"a":"b"}'); + assertEquals(toJson(scope.eval("{\"a\":'b'}")), '{"a":"b"}'); }; ParserTest.prototype.testObjectAccess = function(){ - var scope = new nglr.Scope(); + var scope = new Scope(); assertEquals("WC", scope.eval("{false:'WC', true:'CC'}[false]")); }; ParserTest.prototype.testJSON = function(){ - var scope = new nglr.Scope(); - assertEquals(nglr.toJson(scope.eval("[{}]")), "[{}]"); - assertEquals(nglr.toJson(scope.eval("[{a:[]}, {b:1}]")), '[{"a":[]},{"b":1}]'); + var scope = new Scope(); + assertEquals(toJson(scope.eval("[{}]")), "[{}]"); + assertEquals(toJson(scope.eval("[{a:[]}, {b:1}]")), '[{"a":[]},{"b":1}]'); }; ParserTest.prototype.testMultippleStatements = function(){ - var scope = new nglr.Scope(); + var scope = new Scope(); assertEquals(scope.eval("a=1;b=3;a+b"), 4); assertEquals(scope.eval(";;1;;"), 1); }; ParserTest.prototype.testParseThrow = function(){ expectAsserts(1); - var scope = new nglr.Scope(); + var scope = new Scope(); scope.set('e', 'abc'); try { scope.eval("throw e"); @@ -298,7 +298,7 @@ ParserTest.prototype.testParseThrow = function(){ }; ParserTest.prototype.testMethodsGetDispatchedWithCorrectThis = function(){ - var scope = new nglr.Scope(); + var scope = new Scope(); var C = function (){ this.a=123; }; @@ -310,7 +310,7 @@ ParserTest.prototype.testMethodsGetDispatchedWithCorrectThis = function(){ assertEquals(123, scope.eval("obj.getA()")); }; ParserTest.prototype.testMethodsArgumentsGetCorrectThis = function(){ - var scope = new nglr.Scope(); + var scope = new Scope(); var C = function (){ this.a=123; }; @@ -326,13 +326,13 @@ ParserTest.prototype.testMethodsArgumentsGetCorrectThis = function(){ }; ParserTest.prototype.testObjectPointsToScopeValue = function(){ - var scope = new nglr.Scope(); + var scope = new Scope(); scope.set('a', "abc"); assertEquals("abc", scope.eval("{a:a}").a); }; ParserTest.prototype.testFieldAccess = function(){ - var scope = new nglr.Scope(); + var scope = new Scope(); var fn = function(){ return {name:'misko'}; }; @@ -341,14 +341,14 @@ ParserTest.prototype.testFieldAccess = function(){ }; ParserTest.prototype.testArrayIndexBug = function () { - var scope = new nglr.Scope(); + var scope = new Scope(); scope.set('items', [{}, {name:'misko'}]); assertEquals("misko", scope.eval('items[1].name')); }; ParserTest.prototype.testArrayAssignment = function () { - var scope = new nglr.Scope(); + var scope = new Scope(); scope.set('items', []); assertEquals("abc", scope.eval('items[1] = "abc"')); @@ -359,30 +359,30 @@ ParserTest.prototype.testArrayAssignment = function () { }; ParserTest.prototype.testFiltersCanBeGrouped = function () { - var scope = new nglr.Scope({name:'MISKO'}); + var scope = new Scope({name:'MISKO'}); assertEquals('misko', scope.eval('n = (name|lowercase)')); assertEquals('misko', scope.eval('n')); }; ParserTest.prototype.testFiltersCanBeGrouped = function () { - var scope = new nglr.Scope({name:'MISKO'}); + var scope = new Scope({name:'MISKO'}); assertEquals('misko', scope.eval('n = (name|lowercase)')); assertEquals('misko', scope.eval('n')); }; ParserTest.prototype.testRemainder = function () { - var scope = new nglr.Scope(); + var scope = new Scope(); assertEquals(1, scope.eval('1%2')); }; ParserTest.prototype.testSumOfUndefinedIsNotUndefined = function () { - var scope = new nglr.Scope(); + var scope = new Scope(); assertEquals(1, scope.eval('1+undefined')); assertEquals(1, scope.eval('undefined+1')); }; ParserTest.prototype.testMissingThrowsError = function() { - var scope = new nglr.Scope(); + var scope = new Scope(); try { scope.eval('[].count('); fail(); @@ -392,7 +392,7 @@ ParserTest.prototype.testMissingThrowsError = function() { }; ParserTest.prototype.testItShouldParseOnChangeIntoHashSet = function () { - var scope = new nglr.Scope({count:0}); + var scope = new Scope({count:0}); scope.watch("$anchor.a:count=count+1;$anchor.a:count=count+20;b:count=count+300"); scope.watchListeners["$anchor.a"].listeners[0](); @@ -403,7 +403,7 @@ ParserTest.prototype.testItShouldParseOnChangeIntoHashSet = function () { assertEquals(321, scope.get("count")); }; ParserTest.prototype.testItShouldParseOnChangeBlockIntoHashSet = function () { - var scope = new nglr.Scope({count:0}); + var scope = new Scope({count:0}); var listeners = {a:[], b:[]}; scope.watch("a:{count=count+1;count=count+20;};b:count=count+300", function(n, fn){listeners[n].push(fn);}); @@ -417,12 +417,12 @@ ParserTest.prototype.testItShouldParseOnChangeBlockIntoHashSet = function () { }; ParserTest.prototype.testItShouldParseEmptyOnChangeAsNoop = function () { - var scope = new nglr.Scope(); + var scope = new Scope(); scope.watch("", function(){fail();}); }; ParserTest.prototype.testItShouldCreateClosureFunctionWithNoArguments = function () { - var scope = new nglr.Scope(); + var scope = new Scope(); var fn = scope.eval("{:value}"); scope.set("value", 1); assertEquals(1, fn()); @@ -433,7 +433,7 @@ ParserTest.prototype.testItShouldCreateClosureFunctionWithNoArguments = function }; ParserTest.prototype.testItShouldCreateClosureFunctionWithArguments = function () { - var scope = new nglr.Scope(); + var scope = new Scope(); var fn = scope.eval("{(a):value+a}"); scope.set("value", 1); assertEquals(11, fn(10)); @@ -444,14 +444,14 @@ ParserTest.prototype.testItShouldCreateClosureFunctionWithArguments = function ( }; ParserTest.prototype.testItShouldHaveDefaultArugument = function(){ - var scope = new nglr.Scope(); + var scope = new Scope(); var fn = scope.eval("{:$*2}"); assertEquals(4, fn(2)); }; ParserTest.prototype.testReturnFunctionsAreNotBound = function(){ - var scope = new nglr.Scope(); - scope.set("$datastore", new nglr.DataStore()); + var scope = new Scope(); + scope.set("$datastore", new DataStore()); scope.entity("Group"); var Group = scope.get("Group"); assertEquals("eval Group", "function", typeof scope.eval("Group")); diff --git a/test/ScopeTest.js b/test/ScopeTest.js index c66a2329..e1c5c8ce 100644 --- a/test/ScopeTest.js +++ b/test/ScopeTest.js @@ -23,13 +23,13 @@ ScopeTest.prototype.testNoScopeDoesNotCauseInfiniteRecursion = function(){ }; ScopeTest.prototype.testScopeEval = function(){ - var scope = new nglr.Scope({b:345}); + var scope = new Scope({b:345}); assertEquals(scope.eval('b = 123'), 123); assertEquals(scope.get('b'), 123); }; ScopeTest.prototype.testScopeFromPrototype = function(){ - var scope = new nglr.Scope({b:123}); + var scope = new Scope({b:123}); scope.eval('a = b'); scope.eval('b = 456'); assertEquals(scope.get('a'), 123); @@ -37,32 +37,32 @@ ScopeTest.prototype.testScopeFromPrototype = function(){ }; ScopeTest.prototype.testSetScopeGet = function(){ - var scope = new nglr.Scope(); + var scope = new Scope(); scope.set('a', 987); assertEquals(scope.get('a'), 987); assertEquals(scope.eval('a'), 987); }; ScopeTest.prototype.testGetChain = function(){ - var scope = new nglr.Scope({a:{b:987}}); + var scope = new Scope({a:{b:987}}); assertEquals(scope.get('a.b'), 987); assertEquals(scope.eval('a.b'), 987); }; ScopeTest.prototype.testGetUndefinedChain = function(){ - var scope = new nglr.Scope(); + var scope = new Scope(); assertEquals(typeof scope.get('a.b'), 'undefined'); }; ScopeTest.prototype.testSetChain = function(){ - var scope = new nglr.Scope({a:{}}); + var scope = new Scope({a:{}}); scope.set('a.b', 987); assertEquals(scope.get('a.b'), 987); assertEquals(scope.eval('a.b'), 987); }; ScopeTest.prototype.testSetGetOnChain = function(){ - var scope = new nglr.Scope(); + var scope = new Scope(); scope.set('a.b', 987); assertEquals(scope.get('a.b'), 987); assertEquals(scope.eval('a.b'), 987); @@ -70,7 +70,7 @@ ScopeTest.prototype.testSetGetOnChain = function(){ ScopeTest.prototype.testGlobalFunctionAccess =function(){ window['scopeAddTest'] = function (a, b) {return a+b;}; - var scope = new nglr.Scope({window:window}); + var scope = new Scope({window:window}); assertEquals(scope.eval('window.scopeAddTest(1,2)'), 3); scope.set('add', function (a, b) {return a+b;}); @@ -82,7 +82,7 @@ ScopeTest.prototype.testGlobalFunctionAccess =function(){ ScopeTest.prototype.testValidationEval = function(){ expectAsserts(4); - var scope = new nglr.Scope(); + var scope = new Scope(); angular.validator.testValidator = function(value, expect){ assertEquals(scope, this.scope); return value == expect ? null : "Error text"; @@ -96,7 +96,7 @@ ScopeTest.prototype.testValidationEval = function(){ ScopeTest.prototype.testCallingNonExistantMethodShouldProduceFriendlyException = function() { expectAsserts(1); - var scope = new nglr.Scope({obj:{}}); + var scope = new Scope({obj:{}}); try { scope.eval("obj.iDontExist()"); fail(); @@ -106,7 +106,7 @@ ScopeTest.prototype.testCallingNonExistantMethodShouldProduceFriendlyException = }; ScopeTest.prototype.testAccessingWithInvalidPathShouldThrowError = function() { - var scope = new nglr.Scope(); + var scope = new Scope(); try { scope.get('a.{{b}}'); fail(); @@ -116,25 +116,25 @@ ScopeTest.prototype.testAccessingWithInvalidPathShouldThrowError = function() { }; ScopeTest.prototype.testItShouldHave$parent = function() { - var parent = new nglr.Scope({}, "ROOT"); - var child = new nglr.Scope(parent.state); + var parent = new Scope({}, "ROOT"); + var child = new Scope(parent.state); assertSame("parent", child.state.$parent, parent.state); assertSame("root", child.state.$root, parent.state); }; ScopeTest.prototype.testItShouldHave$root = function() { - var scope = new nglr.Scope({}, "ROOT"); + var scope = new Scope({}, "ROOT"); assertSame(scope.state.$root, scope.state); }; ScopeTest.prototype.testItShouldBuildPathOnUndefined = function(){ - var scope = new nglr.Scope({}, "ROOT"); + var scope = new Scope({}, "ROOT"); scope.setEval("a.$b.c", 1); assertJsonEquals({$b:{c:1}}, scope.get("a")); }; ScopeTest.prototype.testItShouldMapUnderscoreFunctions = function(){ - var scope = new nglr.Scope({}, "ROOT"); + var scope = new Scope({}, "ROOT"); scope.set("a", [1,2,3]); assertEquals('function', typeof scope.get("a.$size")); scope.eval("a.$includeIf(4,true)"); diff --git a/test/ServerTest.js b/test/ServerTest.js index d1f662f9..e367c90a 100644 --- a/test/ServerTest.js +++ b/test/ServerTest.js @@ -1,7 +1,7 @@ ServerTest = TestCase("ServerTest"); ServerTest.prototype.testBreakLargeRequestIntoPackets = function() { var log = ""; - var server = new nglr.Server("http://server", function(url){ + var server = new Server("http://server", function(url){ log += "|" + url; }); server.maxSize = 30; @@ -10,7 +10,7 @@ ServerTest.prototype.testBreakLargeRequestIntoPackets = function() { assertEquals(200, code); assertEquals("response", r); }); - nglr.uuid0("response"); + callbacks.uuid0("response"); assertEquals( "|http://server/$/uuid0/2/1?h=eyJtIjoiUE9TVCIsInAiOnt9LCJ1Ij" + "|http://server/$/uuid0/2/2?h=oiL2RhdGEvZGF0YWJhc2UifQ==", @@ -18,7 +18,7 @@ ServerTest.prototype.testBreakLargeRequestIntoPackets = function() { }; ServerTest.prototype.testItShouldEncodeUsingUrlRules = function() { - var server = new nglr.Server("http://server"); + var server = new Server("http://server"); assertEquals("fn5-fn5-", server.base64url("~~~~~~")); assertEquals("fn5_fn5_", server.base64url("~~\u007f~~\u007f")); }; @@ -28,13 +28,13 @@ FrameServerTest = TestCase("FrameServerTest"); FrameServerTest.prototype = { testRead:function(){ var window = {name:'$DATASET:"MyData"'}; - var server = new nglr.FrameServer(window); + var server = new FrameServer(window); server.read(); assertEquals("MyData", server.data); }, testWrite:function(){ var window = {}; - var server = new nglr.FrameServer(window); + var server = new FrameServer(window); server.data = "TestData" server.write(); assertEquals('$DATASET:"TestData"', window.name); diff --git a/test/UsersTest.js b/test/UsersTest.js index c808885c..f0ff545a 100644 --- a/test/UsersTest.js +++ b/test/UsersTest.js @@ -10,10 +10,10 @@ UsersTest.prototype = { testItShouldFetchCurrentUser:function(){ expectAsserts(5); var user; - var users = new nglr.Users({request:function(method, url, request, callback){ + var users = new Users({request:function(method, url, request, callback){ assertEquals("GET", method); assertEquals("/account.json", url); - assertEquals("{}", nglr.toJson(request)); + assertEquals("{}", toJson(request)); callback(200, {$status_code:200, user:{name:'misko'}}); }}); users.fetchCurrentUser(function(u){ diff --git a/test/WidgetsTest.js b/test/WidgetsTest.js index a245abda..fe20e664 100644 --- a/test/WidgetsTest.js +++ b/test/WidgetsTest.js @@ -2,8 +2,8 @@ WidgetTest = TestCase('WidgetTest'); WidgetTest.prototype.testRequired = function () { var view = $(''); - var scope = new nglr.Scope({$invalidWidgets:[]}); - var cntl = new nglr.TextController(view[0], 'a'); + var scope = new Scope({$invalidWidgets:[]}); + var cntl = new TextController(view[0], 'a'); cntl.updateView(scope); assertTrue(view.hasClass('ng-validation-error')); assertEquals("Required Value", view.attr('ng-error')); @@ -15,8 +15,8 @@ WidgetTest.prototype.testRequired = function () { WidgetTest.prototype.testValidator = function () { var view = $(''); - var scope = new nglr.Scope({$invalidWidgets:[]}); - var cntl = new nglr.TextController(view[0], 'a'); + var scope = new Scope({$invalidWidgets:[]}); + var cntl = new TextController(view[0], 'a'); angular.validator.testValidator = function(value, expect){ return value == expect ? null : "Error text"; }; @@ -43,8 +43,8 @@ WidgetTest.prototype.testValidator = function () { WidgetTest.prototype.testRequiredValidator = function () { var view = $(''); - var scope = new nglr.Scope({$invalidWidgets:[]}); - var cntl = new nglr.TextController(view[0], 'a'); + var scope = new Scope({$invalidWidgets:[]}); + var cntl = new TextController(view[0], 'a'); angular.validator.testValidator = function(value, expect){ return value == expect ? null : "Error text"; }; @@ -67,29 +67,29 @@ WidgetTest.prototype.testRequiredValidator = function () { delete angular.validator['testValidator']; }; -TextController = TestCase("TextController"); +TextControllerTest = TestCase("TextControllerTest"); -TextController.prototype.testDatePicker = function() { +TextControllerTest.prototype.testDatePicker = function() { var input = $(''); - input.data('scope', new nglr.Scope()); + input.data('scope', new Scope()); var body = $(document.body); body.append(input); - var binder = new nglr.Binder(input[0], new nglr.WidgetFactory()); + var binder = new Binder(input[0], new WidgetFactory()); assertTrue('before', input.data('datepicker') === undefined); binder.compile(); assertTrue('after', input.data('datepicker') !== null); assertTrue(body.html(), input.hasClass('hasDatepicker')); }; -RepeaterUpdater = TestCase("RepeaterUpdater"); +RepeaterUpdaterTest = TestCase("RepeaterUpdaterTest"); -RepeaterUpdater.prototype.testRemoveThenAdd = function() { +RepeaterUpdaterTest.prototype.testRemoveThenAdd = function() { var view = $("
      "); var template = function () { return $("
    • "); }; - var repeater = new nglr.RepeaterUpdater(view.find("span"), "a in b", template, ""); - var scope = new nglr.Scope(); + var repeater = new RepeaterUpdater(view.find("span"), "a in b", template, ""); + var scope = new Scope(); scope.set('b', [1,2]); repeater.updateView(scope); @@ -102,14 +102,14 @@ RepeaterUpdater.prototype.testRemoveThenAdd = function() { assertEquals(1, view.find("li").size()); }; -RepeaterUpdater.prototype.testShouldBindWidgetOnRepeaterClone = function(){ +RepeaterUpdaterTest.prototype.testShouldBindWidgetOnRepeaterClone = function(){ //fail(); }; -RepeaterUpdater.prototype.testShouldThrowInformativeSyntaxError= function(){ +RepeaterUpdaterTest.prototype.testShouldThrowInformativeSyntaxError= function(){ expectAsserts(1); try { - var repeater = new nglr.RepeaterUpdater(null, "a=b"); + var repeater = new RepeaterUpdater(null, "a=b"); } catch (e) { assertEquals("Expected ng-repeat in form of 'item in collection' but got 'a=b'.", e); } @@ -118,17 +118,17 @@ RepeaterUpdater.prototype.testShouldThrowInformativeSyntaxError= function(){ SelectControllerTest = TestCase("SelectControllerTest"); SelectControllerTest.prototype.testShouldUpdateModelNullOnNothingSelected = function(){ - var scope = new nglr.Scope(); + var scope = new Scope(); var view = {selectedIndex:-1, options:[]}; - var cntl = new nglr.SelectController(view, 'abc'); + var cntl = new SelectController(view, 'abc'); cntl.updateModel(scope); assertNull(scope.get('abc')); }; SelectControllerTest.prototype.testShouldUpdateModelWhenNothingSelected = function(){ - var scope = new nglr.Scope(); + var scope = new Scope(); var view = {value:'123'}; - var cntl = new nglr.SelectController(view, 'abc'); + var cntl = new SelectController(view, 'abc'); cntl.updateView(scope); assertEquals("123", scope.get('abc')); }; @@ -137,8 +137,8 @@ BindUpdaterTest = TestCase("BindUpdaterTest"); BindUpdaterTest.prototype.testShouldDisplayNothingForUndefined = function () { var view = $(''); - var controller = new nglr.BindUpdater(view[0], "{{a}}"); - var scope = new nglr.Scope(); + var controller = new BindUpdater(view[0], "{{a}}"); + var scope = new Scope(); scope.set('a', undefined); controller.updateView(scope); @@ -151,20 +151,20 @@ BindUpdaterTest.prototype.testShouldDisplayNothingForUndefined = function () { BindUpdaterTest.prototype.testShouldDisplayJsonForNonStrings = function () { var view = $(''); - var controller = new nglr.BindUpdater(view[0], "{{obj}}"); + var controller = new BindUpdater(view[0], "{{obj}}"); - controller.updateView(new nglr.Scope({obj:[]})); + controller.updateView(new Scope({obj:[]})); assertEquals("[]", view.text()); - controller.updateView(new nglr.Scope({obj:{text:'abc'}})); - assertEquals('abc', nglr.fromJson(view.text()).text); + controller.updateView(new Scope({obj:{text:'abc'}})); + assertEquals('abc', fromJson(view.text()).text); }; BindUpdaterTest.prototype.testShouldInsertHtmlNode = function () { var view = $(''); - var controller = new nglr.BindUpdater(view[0], "&{{obj}}"); - var scope = new nglr.Scope(); + var controller = new BindUpdater(view[0], "&{{obj}}"); + var scope = new Scope(); scope.set("obj", $('
      myDiv
      ')[0]); controller.updateView(scope); @@ -174,8 +174,8 @@ BindUpdaterTest.prototype.testShouldInsertHtmlNode = function () { BindUpdaterTest.prototype.testShouldDisplayTextMethod = function () { var view = $('
      '); - var controller = new nglr.BindUpdater(view[0], "{{obj}}"); - var scope = new nglr.Scope(); + var controller = new BindUpdater(view[0], "{{obj}}"); + var scope = new Scope(); scope.set("obj", new angular.filter.Meta({text:function(){return "abc";}})); controller.updateView(scope); @@ -187,13 +187,13 @@ BindUpdaterTest.prototype.testShouldDisplayTextMethod = function () { scope.set("obj", {text:"123"}); controller.updateView(scope); - assertEquals("123", nglr.fromJson(view.text()).text); + assertEquals("123", fromJson(view.text()).text); }; BindUpdaterTest.prototype.testShouldDisplayHtmlMethod = function () { var view = $('
      '); - var controller = new nglr.BindUpdater(view[0], "{{obj}}"); - var scope = new nglr.Scope(); + var controller = new BindUpdater(view[0], "{{obj}}"); + var scope = new Scope(); scope.set("obj", new angular.filter.Meta({html:function(){return "a
      b
      c";}})); controller.updateView(scope); @@ -205,13 +205,13 @@ BindUpdaterTest.prototype.testShouldDisplayHtmlMethod = function () { scope.set("obj", {html:"123"}); controller.updateView(scope); - assertEquals("123", nglr.fromJson(view.text()).html); + assertEquals("123", fromJson(view.text()).html); }; BindUpdaterTest.prototype.testUdateBoolean = function() { var view = $('
      '); - var controller = new nglr.BindUpdater(view[0], "{{true}}, {{false}}"); - controller.updateView(new nglr.Scope()); + var controller = new BindUpdater(view[0], "{{true}}, {{false}}"); + controller.updateView(new Scope()); assertEquals('true, false', view.text()); }; @@ -219,9 +219,9 @@ BindAttrUpdaterTest = TestCase("BindAttrUpdaterTest"); BindAttrUpdaterTest.prototype.testShouldLoadBlankImageWhenBindingIsUndefined = function () { var view = $(''); - var controller = new nglr.BindAttrUpdater(view[0], {src: '{{imageUrl}}'}); + var controller = new BindAttrUpdater(view[0], {src: '{{imageUrl}}'}); - var scope = new nglr.Scope(); + var scope = new Scope(); scope.set('imageUrl', undefined); scope.set('config.server', 'http://server'); @@ -229,16 +229,15 @@ BindAttrUpdaterTest.prototype.testShouldLoadBlankImageWhenBindingIsUndefined = f assertEquals("http://server/images/blank.gif", view.attr('src')); }; -RepeaterUpdaterTest = TestCase("RepeaterUpdaterTest"); RepeaterUpdaterTest.prototype.testShouldNotDieWhenRepeatExpressionIsNull = function() { - var rep = new nglr.RepeaterUpdater(null, "$item in items", null, null); - var scope = new nglr.Scope(); + var rep = new RepeaterUpdater(null, "$item in items", null, null); + var scope = new Scope(); scope.set('items', undefined); rep.updateView(scope); }; RepeaterUpdaterTest.prototype.testShouldIterateOverKeys = function() { - var rep = new nglr.RepeaterUpdater(null, "($k,_v) in items", null, null); + var rep = new RepeaterUpdater(null, "($k,_v) in items", null, null); assertEquals("items", rep.iteratorExp); assertEquals("_v", rep.valueExp); assertEquals("$k", rep.keyExp); @@ -247,14 +246,14 @@ RepeaterUpdaterTest.prototype.testShouldIterateOverKeys = function() { EvalUpdaterTest = TestCase("EvalUpdaterTest"); EvalUpdaterTest.prototype.testEvalThrowsException = function(){ var view = $('
      '); - var eval = new nglr.EvalUpdater(view[0], 'undefined()'); + var eval = new EvalUpdater(view[0], 'undefined()'); - eval.updateView(new nglr.Scope()); + eval.updateView(new Scope()); assertTrue(!!view.attr('ng-error')); assertTrue(view.hasClass('ng-exception')); eval.exp = "1"; - eval.updateView(new nglr.Scope()); + eval.updateView(new Scope()); assertFalse(!!view.attr('ng-error')); assertFalse(view.hasClass('ng-exception')); }; @@ -262,8 +261,8 @@ EvalUpdaterTest.prototype.testEvalThrowsException = function(){ RadioControllerTest = TestCase("RadioController"); RadioControllerTest.prototype.testItShouldTreatTrueStringAsBoolean = function () { var view = $(''); - var radio = new nglr.RadioController(view[0], 'select'); - var scope = new nglr.Scope({select:true}); + var radio = new RadioController(view[0], 'select'); + var scope = new Scope({select:true}); radio.updateView(scope); assertTrue(view[0].checked); }; diff --git a/test/XSitePostTest.js b/test/XSitePostTest.js deleted file mode 100644 index 8a3e4d6f..00000000 --- a/test/XSitePostTest.js +++ /dev/null @@ -1,47 +0,0 @@ -XSitePost = TestCase("XSitePost"); - -var e = function(text){ return Base64.encode(text); }; - -XSitePost.prototype.testMessageReceived = function () { - expectAsserts(4); - var xPost = new nglr.XSitePost(); - xPost.baseUrl = "http://getangular.test"; - xPost.post = function(url, request, callback){ - assertEquals('http://getangular.test/url', url); - assertEquals('abc', request.a); - assertEquals('xyz', request.x); - }; - xPost.incomingFragment('#id;0;1;'+e('/url')+':a:'+e('abc')+':x:'+e('xyz')); - assertEquals('{}', nglr.toJson(xPost.inQueue)); -}; - -XSitePost.prototype.testMessageReceivedInParts = function () { - expectAsserts(5); - var xPost = new nglr.XSitePost(); - xPost.baseUrl = "http://getangular.test"; - xPost.post = function(url, request, callback){ - assertEquals('http://getangular.test/url', url); - assertEquals('abc', request.a); - assertEquals('xyz', request.x); - }; - xPost.incomingFragment('#id;1;2;:x:'+e('xyz')); - assertNotSame('{}', nglr.toJson(xPost.inQueue)); - xPost.incomingFragment('#id;0;2;'+e('/url')+':a:'+e('abc')); - assertEquals('{}', nglr.toJson(xPost.inQueue)); -}; - -XSitePost.prototype.testPostResponsIsEnqueued = function () { - var xPost = new nglr.XSitePost(); - xPost.maxMsgSize = 11; - xPost.response("id", "response", "status"); - - assertEquals('["id:0:2:cmVzcG9uc2U","id:1:2:="]', - nglr.toJson(xPost.outQueue)); -}; - -XSitePost.prototype.testPush = function () { - var window = {}; - var xPost = new nglr.XSitePost(window); - xPost.response("id", "response", "status"); - assertEquals('id:0:1:cmVzcG9uc2U=', xPost.outQueue[0]); -}; diff --git a/test/formsTest.js b/test/formsTest.js index 66c4ec69..ccade915 100644 --- a/test/formsTest.js +++ b/test/formsTest.js @@ -2,7 +2,7 @@ nglrTest = TestCase('nglrTest'); nglrTest.prototype.testShiftBind = function(){ expectAsserts(3); - nglr.shiftBind('this', function(target, arg) { + shiftBind('this', function(target, arg) { assertEquals(this, 'this'); assertEquals(target, 'target'); assertEquals(arg, 'arg'); @@ -11,7 +11,7 @@ nglrTest.prototype.testShiftBind = function(){ nglrTest.prototype.testBind = function(){ expectAsserts(2); - nglr.bind('this', function(arg) { + bind('this', function(arg) { assertEquals(this, 'this'); assertEquals(arg, 'arg'); }).apply('XXX', ['arg']); diff --git a/test/testabilityPatch.js b/test/testabilityPatch.js index 13378d36..dde21846 100644 --- a/test/testabilityPatch.js +++ b/test/testabilityPatch.js @@ -6,8 +6,8 @@ HIDDEN = jQuery.browser.msie ? ' style="display: none; "' : ' style="display: none;"'; -nglr.msie = jQuery.browser.msie; -nglr.alert = function(msg) {jstestdriver.console.log("ALERT: " + msg);}; +msie = jQuery.browser.msie; +alert = function(msg) {jstestdriver.console.log("ALERT: " + msg);}; function noop(){} @@ -50,7 +50,7 @@ jQuery.fn.sortedHtml = function() { var toString = function(index, node) { node = node || this; if (node.nodeName == "#text") { - html += nglr.escapeHtml(node.nodeValue); + html += escapeHtml(node.nodeValue); } else { html += '<' + node.nodeName.toLowerCase(); var attributes = node.attributes || []; @@ -89,14 +89,14 @@ jQuery.fn.sortedHtml = function() { }; function encode64(obj){ - return Base64.encode(nglr.toJson(obj)); + return Base64.encode(toJson(obj)); } function decode64(base64){ - return nglr.fromJson(Base64.decode(base64)); + return fromJson(Base64.decode(base64)); } -nglr.Loader.prototype.configureJQueryPlugins(); +Loader.prototype.configureJQueryPlugins(); function assertHidden(node) { var display = node.css('display'); @@ -110,7 +110,7 @@ function assertVisible(node) { } function assertJsonEquals(expected, actual) { - assertEquals(nglr.toJson(expected), nglr.toJson(actual)); + assertEquals(toJson(expected), toJson(actual)); } function assertUndefined(value) { @@ -118,7 +118,7 @@ function assertUndefined(value) { } function assertDefined(value) { - assertTrue(nglr.toJson(value), !!value); + assertTrue(toJson(value), !!value); } function assertThrows(error, fn){ -- cgit v1.2.3 From 1a42a3fab99ca02af0476f5a87175c53104aa2e3 Mon Sep 17 00:00:00 2001 From: Misko Hevery Date: Mon, 11 Jan 2010 16:15:12 -0800 Subject: green --- test/LoaderTest.js | 4 ++-- test/ServerTest.js | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) (limited to 'test') diff --git a/test/LoaderTest.js b/test/LoaderTest.js index 88ae3efa..a474c8a4 100644 --- a/test/LoaderTest.js +++ b/test/LoaderTest.js @@ -50,8 +50,8 @@ UrlWatcherTest.prototype.testItShouldFireOnUpdateEventWhenSpecialURLSet = functi expectAsserts(2); var location = {href:"http://server", hash:"#$iframe_notify=1234"}; var watcher = new UrlWatcher(location); - callbacks._iframe_notify_1234 = function () { - assertEquals("undefined", typeof callbacks._iframe_notify_1234); + angular.callbacks._iframe_notify_1234 = function () { + assertEquals("undefined", typeof angularCallbacks._iframe_notify_1234); assertEquals("http://server2#", location.href); }; watcher.delay = 1; diff --git a/test/ServerTest.js b/test/ServerTest.js index e367c90a..02fab84c 100644 --- a/test/ServerTest.js +++ b/test/ServerTest.js @@ -10,7 +10,7 @@ ServerTest.prototype.testBreakLargeRequestIntoPackets = function() { assertEquals(200, code); assertEquals("response", r); }); - callbacks.uuid0("response"); + angularCallbacks.uuid0("response"); assertEquals( "|http://server/$/uuid0/2/1?h=eyJtIjoiUE9TVCIsInAiOnt9LCJ1Ij" + "|http://server/$/uuid0/2/2?h=oiL2RhdGEvZGF0YWJhc2UifQ==", @@ -35,7 +35,7 @@ FrameServerTest.prototype = { testWrite:function(){ var window = {}; var server = new FrameServer(window); - server.data = "TestData" + server.data = "TestData"; server.write(); assertEquals('$DATASET:"TestData"', window.name); } -- cgit v1.2.3 From 6d5471c9bea9671dec7900a7bc548aea8ddd5a3e Mon Sep 17 00:00:00 2001 From: Misko Hevery Date: Mon, 11 Jan 2010 17:32:33 -0800 Subject: all files converted to prototype= {} --- test/DataStoreTest.js | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) (limited to 'test') diff --git a/test/DataStoreTest.js b/test/DataStoreTest.js index 2dd4a582..87c5be2e 100644 --- a/test/DataStoreTest.js +++ b/test/DataStoreTest.js @@ -17,9 +17,8 @@ DataStoreTest.prototype.testSavePostsToServer = function(){ response.$version = "2"; callback(200, [response]); }; - var model; var datastore = new DataStore(post); - model = datastore.entity('abc', {name: "value"})(); + var model = datastore.entity('abc', {name: "value"})(); model.$id = "123"; model.$version = "1"; -- cgit v1.2.3 From 13dee60685216a1da9e3bce4d5130693f6f5c624 Mon Sep 17 00:00:00 2001 From: Misko Hevery Date: Tue, 12 Jan 2010 08:40:10 -0800 Subject: dissable URL watching --- test/ExternalApiTest.js | 4 ++++ 1 file changed, 4 insertions(+) (limited to 'test') diff --git a/test/ExternalApiTest.js b/test/ExternalApiTest.js index 40cb0ab4..7356915b 100644 --- a/test/ExternalApiTest.js +++ b/test/ExternalApiTest.js @@ -6,5 +6,9 @@ ExternalApiTest.prototype = { var scope = angular.compile(node); assertEquals(1, scope.get('a')); assertEquals(2, scope.get('b')); + }, + + testItShouldRegisterAnchorListener: function (){ + } }; -- cgit v1.2.3 From 27709c3f69384a7630aa336a1e73e730ea5f9790 Mon Sep 17 00:00:00 2001 From: Misko Hevery Date: Tue, 12 Jan 2010 14:19:19 -0800 Subject: break out init phase into scope --- test/ExternalApiTest.js | 1 + 1 file changed, 1 insertion(+) (limited to 'test') diff --git a/test/ExternalApiTest.js b/test/ExternalApiTest.js index 7356915b..cc102ae0 100644 --- a/test/ExternalApiTest.js +++ b/test/ExternalApiTest.js @@ -4,6 +4,7 @@ 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')); }, -- cgit v1.2.3 From 595b4ea097bcb512173b6d4a12924ea1a3d70ecd Mon Sep 17 00:00:00 2001 From: Misko Hevery Date: Mon, 18 Jan 2010 10:47:03 -0800 Subject: checkpoint for integration with angular --- test/AngularTest.js | 60 +++++++++++++++++++++++++++++++++++++++++ test/LoaderTest.js | 70 ------------------------------------------------ test/testabilityPatch.js | 2 +- 3 files changed, 61 insertions(+), 71 deletions(-) create mode 100644 test/AngularTest.js delete mode 100644 test/LoaderTest.js (limited to 'test') diff --git a/test/AngularTest.js b/test/AngularTest.js new file mode 100644 index 00000000..9610ef76 --- /dev/null +++ b/test/AngularTest.js @@ -0,0 +1,60 @@ +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'); + +UrlWatcherTest.prototype.testUrlWatcher = function () { + expectAsserts(2); + var location = {href:"http://server", hash:""}; + var watcher = new UrlWatcher(location); + watcher.delay = 1; + watcher.listener = function(url){ + assertEquals('http://getangular.test', url); + }; + watcher.setTimeout = function(fn, delay){ + assertEquals(1, delay); + location.href = "http://getangular.test"; + watcher.setTimeout = function(fn, delay) { + }; + fn(); + }; + watcher.watch(); +}; + +UrlWatcherTest.prototype.testItShouldFireOnUpdateEventWhenSpecialURLSet = function(){ + expectAsserts(2); + var location = {href:"http://server", hash:"#$iframe_notify=1234"}; + var watcher = new UrlWatcher(location); + angular.callbacks._iframe_notify_1234 = function () { + assertEquals("undefined", typeof angularCallbacks._iframe_notify_1234); + assertEquals("http://server2#", location.href); + }; + watcher.delay = 1; + watcher.expectedUrl = "http://server2"; + watcher.setTimeout = function(fn, delay){ + watcher.setTimeout = function(fn, delay) {}; + fn(); + }; + watcher.watch(); +}; + +FunctionTest = TestCase("FunctionTest"); + +FunctionTest.prototype.testEscapeHtml = function () { + assertEquals("<div>&amp;</div>", escapeHtml('
      &
      ')); +}; \ No newline at end of file diff --git a/test/LoaderTest.js b/test/LoaderTest.js deleted file mode 100644 index a474c8a4..00000000 --- a/test/LoaderTest.js +++ /dev/null @@ -1,70 +0,0 @@ -LoaderTest = TestCase('LoaderTest'); - -LoaderTest.prototype.testLoadCss = function(){ - if ($.browser.safari) return; - var head = jQuery('')[0]; - var loader = new Loader(document, head, {}); - var log = ''; - loader.config.server = 'http://'; - loader.loadCss('x'); - assertEquals($(head).find('link').attr('href'), 'http://x'); -}; - -LoaderTest.prototype.testDefaultDatabasePathFromSubdomain = function() { - var loader = new Loader(null, null, {server:"http://account.getangular.com", database:"database"}); - loader.computeConfiguration(); - assertEquals("database", loader.config.database); - - loader = new Loader(null, null, {server:"http://account.getangular.com"}); - loader.computeConfiguration(); - assertEquals("account", loader.config.database); - - loader = new Loader(null, null, {server:"https://account.getangular.com"}); - loader.computeConfiguration(); - assertEquals("account", loader.config.database); -}; - - - -UrlWatcherTest = TestCase('UrlWatcherTest'); - -UrlWatcherTest.prototype.testUrlWatcher = function () { - expectAsserts(2); - var location = {href:"http://server", hash:""}; - var watcher = new UrlWatcher(location); - watcher.delay = 1; - watcher.listener = function(url){ - assertEquals('http://getangular.test', url); - }; - watcher.setTimeout = function(fn, delay){ - assertEquals(1, delay); - location.href = "http://getangular.test"; - watcher.setTimeout = function(fn, delay) { - }; - fn(); - }; - watcher.watch(); -}; - -UrlWatcherTest.prototype.testItShouldFireOnUpdateEventWhenSpecialURLSet = function(){ - expectAsserts(2); - var location = {href:"http://server", hash:"#$iframe_notify=1234"}; - var watcher = new UrlWatcher(location); - angular.callbacks._iframe_notify_1234 = function () { - assertEquals("undefined", typeof angularCallbacks._iframe_notify_1234); - assertEquals("http://server2#", location.href); - }; - watcher.delay = 1; - watcher.expectedUrl = "http://server2"; - watcher.setTimeout = function(fn, delay){ - watcher.setTimeout = function(fn, delay) {}; - fn(); - }; - watcher.watch(); -}; - -FunctionTest = TestCase("FunctionTest"); - -FunctionTest.prototype.testEscapeHtml = function () { - assertEquals("<div>&amp;</div>", escapeHtml('
      &
      ')); -}; \ No newline at end of file diff --git a/test/testabilityPatch.js b/test/testabilityPatch.js index dde21846..78ffd380 100644 --- a/test/testabilityPatch.js +++ b/test/testabilityPatch.js @@ -96,7 +96,7 @@ function decode64(base64){ return fromJson(Base64.decode(base64)); } -Loader.prototype.configureJQueryPlugins(); +Angular.prototype.configureJQueryPlugins(); function assertHidden(node) { var display = node.css('display'); -- cgit v1.2.3 From 0e566fe6cb41de388df6793b350fb81aaa4a8476 Mon Sep 17 00:00:00 2001 From: Misko Hevery Date: Mon, 18 Jan 2010 17:56:08 -0800 Subject: tweeter demo client --- test/FiltersTest.js | 9 +++++++++ 1 file changed, 9 insertions(+) (limited to 'test') diff --git a/test/FiltersTest.js b/test/FiltersTest.js index c219f24f..fee59bac 100644 --- a/test/FiltersTest.js +++ b/test/FiltersTest.js @@ -151,3 +151,12 @@ FiltersTest.prototype.testHtml = function() { angular.filter.html("acd").html); assertTrue(angular.filter.html("acd") instanceof angular.filter.Meta); }; + +FiltersTest.prototype.testLinky = function() { + assertEquals( + 'a (http://a) http://a \n http://1.2/v:~-123. c', + angular.filter.linky("a (http://a) http://a \n http://1.2/v:~-123. c").html); + assertTrue(angular.filter.linky("a") instanceof angular.filter.Meta); +}; + + -- cgit v1.2.3 From db2031c5a1df205e6db40ca6aba80930375069c0 Mon Sep 17 00:00:00 2001 From: Misko Hevery Date: Tue, 19 Jan 2010 17:53:20 -0800 Subject: added debug info; fix parser bug with double negation --- test/ParserTest.js | 8 ++++++++ 1 file changed, 8 insertions(+) (limited to 'test') diff --git a/test/ParserTest.js b/test/ParserTest.js index 058010f3..fbd9f508 100644 --- a/test/ParserTest.js +++ b/test/ParserTest.js @@ -460,3 +460,11 @@ ParserTest.prototype.testReturnFunctionsAreNotBound = function(){ assertEquals("direct Group.all", "function", typeof Group.query); }; +ParserTest.prototype.testDoubleNegationBug = function (){ + var scope = new Scope(); + assertEquals(true, scope.eval('true')); + assertEquals(false, scope.eval('!true')); + assertEquals(true, scope.eval('!!true')); + assertEquals('a', scope.eval('{true:"a", false:"b"}[!!true]')); +}; + -- cgit v1.2.3 From dc0db57b36bb6cd47dfea835a315f61b34ed8e1b Mon Sep 17 00:00:00 2001 From: Misko Hevery Date: Wed, 20 Jan 2010 06:52:50 -0800 Subject: tweek tweeter --- test/FiltersTest.js | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) (limited to 'test') diff --git a/test/FiltersTest.js b/test/FiltersTest.js index fee59bac..5ca63ca7 100644 --- a/test/FiltersTest.js +++ b/test/FiltersTest.js @@ -153,10 +153,15 @@ FiltersTest.prototype.testHtml = function() { }; FiltersTest.prototype.testLinky = function() { + var linky = angular.filter.linky; assertEquals( - 'a (http://a) http://a \n http://1.2/v:~-123. c', - angular.filter.linky("a (http://a) http://a \n http://1.2/v:~-123. c").html); - assertTrue(angular.filter.linky("a") instanceof angular.filter.Meta); + 'http://ab ' + + '(http://a) ' + + '<http://a> \n ' + + 'http://1.2/v:~-123. c', + linky("http://ab (http://a) \n http://1.2/v:~-123. c").html); + assertTrue(linky("a") instanceof angular.filter.Meta); + assertEquals(undefined, linky(undefined)); }; -- cgit v1.2.3 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('
        {{a=123}}
        ').init(); + expect($(scope.element).text()).toEqual('123'); + }); +}); + +describe("ScenarioSpec: Scope", function(){ + it("should have set, get, eval, init, updateView methods", function(){ + var scope = angular.compile('
        {{a}}
        ').init(); + expect(scope.set("a", 2)).toEqual(2); + expect(scope.get("a")).toEqual(2); + expect(scope.eval("a=3")).toEqual(3); + scope.updateView(); + expect($(scope.element).text()).toEqual('3'); + }); + + it("should have config", function(){ + expect(angular.compile('', {a:'b'}).config.a).toEqual('b'); + }); + + it("should have $ objects", function(){ + var scope = angular.compile('
        ', {a:"b"}); + expect(scope.get('$anchor')).toBeDefined(); + expect(scope.get('$updateView')).toBeDefined(); + expect(scope.get('$config')).toBeDefined(); + expect(scope.get('$config.a')).toEqual("b"); + expect(scope.get('$datastore')).toBeDefined(); + }); +}); + +describe("ScenarioSpec: configuration", function(){ + it("should take location object", function(){ + var url = "http://server/#book=moby"; + var onUrlChange; + var location = { + listen:function(fn){onUrlChange=fn;}, + set:function(u){url = u;}, + get:function(){return url;} + }; + var scope = angular.compile("
        {{$anchor}}
        ", {location:location}); + var $anchor = scope.get('$anchor'); + expect($anchor.book).toBeUndefined(); + expect(onUrlChange).toBeUndefined(); + scope.init(); + expect($anchor.book).toEqual('moby'); + expect(onUrlChange).toBeDefined(); + + url = "http://server/#book=none"; + onUrlChange(); + expect($anchor.book).toEqual('none'); + }); +}); diff --git a/test/ScopeTest.js b/test/ScopeTest.js index e1c5c8ce..b066f0cb 100644 --- a/test/ScopeTest.js +++ b/test/ScopeTest.js @@ -38,7 +38,7 @@ ScopeTest.prototype.testScopeFromPrototype = function(){ ScopeTest.prototype.testSetScopeGet = function(){ var scope = new Scope(); - scope.set('a', 987); + assertEquals(987, scope.set('a', 987)); assertEquals(scope.get('a'), 987); assertEquals(scope.eval('a'), 987); }; diff --git a/test/formsTest.js b/test/formsTest.js deleted file mode 100644 index ccade915..00000000 --- a/test/formsTest.js +++ /dev/null @@ -1,18 +0,0 @@ -nglrTest = TestCase('nglrTest'); - -nglrTest.prototype.testShiftBind = function(){ - expectAsserts(3); - shiftBind('this', function(target, arg) { - assertEquals(this, 'this'); - assertEquals(target, 'target'); - assertEquals(arg, 'arg'); - }).apply('target', ['arg']); -}; - -nglrTest.prototype.testBind = function(){ - expectAsserts(2); - bind('this', function(arg) { - assertEquals(this, 'this'); - assertEquals(arg, 'arg'); - }).apply('XXX', ['arg']); -}; diff --git a/test/testabilityPatch.js b/test/testabilityPatch.js index 78ffd380..8fac7598 100644 --- a/test/testabilityPatch.js +++ b/test/testabilityPatch.js @@ -35,13 +35,13 @@ function report(reportTest){ }); } -MockUrlWatcher = function() { +MockLocation = function() { this.url = "http://server"; }; -MockUrlWatcher.prototype.getUrl = function(){ +MockLocation.prototype.get = function(){ return this.url; }; -MockUrlWatcher.prototype.setUrl = function(url){ +MockLocation.prototype.set = function(url){ this.url = url; }; @@ -96,7 +96,7 @@ function decode64(base64){ return fromJson(Base64.decode(base64)); } -Angular.prototype.configureJQueryPlugins(); +configureJQueryPlugins(); function assertHidden(node) { var display = node.css('display'); -- cgit v1.2.3 From b8ee8b8912ef4fa2f9ff55dc4f7ed27780da34bd Mon Sep 17 00:00:00 2001 From: Misko Hevery Date: Sat, 23 Jan 2010 15:58:12 -0800 Subject: fix broken test --- test/BinderTest.js | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) (limited to 'test') diff --git a/test/BinderTest.js b/test/BinderTest.js index bbb3eb8f..56ada614 100644 --- a/test/BinderTest.js +++ b/test/BinderTest.js @@ -509,11 +509,11 @@ BinderTest.prototype.testReplaceFileUploadWithSwf = function(){ }; BinderTest.prototype.testRepeaterAdd = function(){ - var doc = $('
        '); - 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(); + var c = compile('
        '); + var doc = c.node; + c.scope.set('items', [{x:'a'}, {x:'b'}]); + c.binder.compile(); + c.binder.updateView(); assertEquals('a', doc.find(':input')[0].value); assertEquals('b', doc.find(':input')[1].value); -- cgit v1.2.3 From efad9ec5be8da442af5fb3dffc08510f7a71e10f Mon Sep 17 00:00:00 2001 From: Misko Hevery Date: Sun, 24 Jan 2010 17:10:58 -0800 Subject: changes to make it closure compiler compatible --- test/BinderTest.js | 308 +++++++++++++++++------------------------- test/EntityDeclarationTest.js | 28 ++-- test/ParserTest.js | 3 +- test/ScenarioSpec.js | 2 +- 4 files changed, 141 insertions(+), 200 deletions(-) (limited to 'test') diff --git a/test/BinderTest.js b/test/BinderTest.js index 56ada614..6ef46fae 100644 --- a/test/BinderTest.js +++ b/test/BinderTest.js @@ -5,14 +5,13 @@ 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 MockLocation(), config); var datastore = new DataStore(); - scope.set("$datastore", datastore); + var binder = new Binder(h[0], new WidgetFactory(), datastore, new MockLocation(), config); scope.set("$updateView", _(binder.updateView).bind(binder)); scope.set("$anchor", binder.anchor); binder.entity(scope); binder.compile(); - return {node:h, binder:binder, scope:scope}; + return {node:h, binder:binder, scope:scope, datastore:datastore}; } function compileToHtml(content) { @@ -117,34 +116,23 @@ BinderTest.prototype.testChangingTextfieldUpdatesModel = function(){ }; 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 MockLocation()); - binder.compile(); - binder.updateView(); - assertEquals(scope.get('model').note, 'abc'); + var c = compile(''); + c.binder.updateView(); + assertEquals(c.scope.get('model').note, 'abc'); }; BinderTest.prototype.testChangingRadioUpdatesModel = function(){ - var form = html('' + + var c = compile('' + ''); - var scope = new Scope({model:{}}); - form.data('scope', scope); - var binder = new Binder(form.get(0), new WidgetFactory(), new MockLocation()); - binder.compile(); - binder.updateView(); - assertEquals(scope.get('model').price, 'A'); + c.binder.updateView(); + assertEquals(c.scope.get('model').price, 'A'); }; 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 MockLocation()); - binder.compile(); - binder.updateView(); - assertEquals('A', scope.get('model').price); + var form = compile(''); + form.scope.set('model', {}); + form.binder.updateView(); + assertEquals('A', form.scope.get('model').price); }; BinderTest.prototype.testBindUpdate = function() { @@ -154,37 +142,28 @@ BinderTest.prototype.testBindUpdate = function() { }; 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 MockLocation()); - binder.compile(); - binder.updateView(); - assertEquals('A', scope.get('model').price); + var form = compile(''); + form.scope.set('model', {}); + form.binder.updateView(); + assertEquals('A', form.scope.get('model').price); }; BinderTest.prototype.testChangingMultiselectUpdatesModel = function(){ - var form = html('' + '' + '' + '' + ''); - var scope = new Scope({Invoice:{}}); - form.data('scope', scope); - var binder = new Binder(form.get(0), new WidgetFactory(), new MockLocation()); - binder.compile(); - binder.updateView(); - assertJsonEquals(["A", "B"], scope.get('Invoice').options); + form.scope.set("Invoice", {}); + form.binder.updateView(); + assertJsonEquals(["A", "B"], form.scope.get('Invoice').options); }; 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 MockLocation()); - binder.compile(); - binder.updateView(); - assertEquals(scope.get('model').price, 'b'); + var form = compile(''); + form.scope.set('model', {}); + form.binder.updateView(); + assertEquals(form.scope.get('model').price, 'b'); }; BinderTest.prototype.testExecuteInitialization = function() { @@ -207,13 +186,11 @@ BinderTest.prototype.testExecuteInitializationStatements = function() { }; 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 MockLocation()); - binder.compile(); - binder.updateView(); - assertEquals('123', form.text()); + var form = compile('
        x
        '); + form.scope.set('model', {a:123}); + form.binder.compile(); + form.binder.updateView(); + assertEquals('123', form.node.text()); }; BinderTest.prototype.testReplaceBindingInTextWithSpan = function() { @@ -285,10 +262,9 @@ 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 MockLocation()); - binder.compile(); + var c = compile(''); + var binder = c.binder, form = c.node; + c.scope.eval('a=1;b=2'); binder.updateView(); var a = form.find("a"); assertEquals(a.attr('a'), 'a'); @@ -296,16 +272,16 @@ BinderTest.prototype.testAttributesAreEvaluated = function(){ }; BinderTest.prototype.testInputsAreUpdated = function(){ - var form = - html('' + - '' + + '' + + '' + + '' + + '' + + ''); + var binder = a.binder, form = a.node; + a.scope.set('A', {text:"t1", textarea:"t2", radio:"r", checkbox:"c", select:"S"}); binder.compile(); binder.updateView(); assertEquals(form.find("input[type=text]").attr('value'), 't1'); @@ -348,8 +324,8 @@ BinderTest.prototype.testButtonElementActionExecutesInScope = function(){ }; BinderTest.prototype.testParseEmptyAnchor = function(){ - var location = new MockLocation(); - var binder = new Binder(null, null, location); + var binder = compile("
        ").binder; + var location = binder.location; var anchor = binder.anchor; location.url = "a#x=1"; binder.parseAnchor(); @@ -362,8 +338,8 @@ BinderTest.prototype.testParseEmptyAnchor = function(){ }; BinderTest.prototype.testParseAnchor = function(){ - var location = new MockLocation(); - var binder = new Binder(null, null, location); + var binder = compile("
        ").binder; + var location = binder.location; location.url = "a#x=1"; binder.parseAnchor(); assertEquals(binder.anchor.x, "1"); @@ -376,7 +352,7 @@ BinderTest.prototype.testParseAnchor = function(){ }; BinderTest.prototype.testWriteAnchor = function(){ - var binder = new Binder(null, null, new MockLocation()); + var binder = compile("
        ").binder; binder.location.set('a'); binder.anchor.a = 'b'; binder.anchor.c = ' '; @@ -386,22 +362,20 @@ BinderTest.prototype.testWriteAnchor = function(){ }; BinderTest.prototype.testWriteAnchorAsPartOfTheUpdateView = function(){ - var binder = new Binder(html("
        ")[0], null, new MockLocation()); + var binder = compile("
        ").binder; binder.location.set('a'); - $(binder.doc).data('scope', new Scope()); binder.anchor.a = 'b'; binder.updateView(); assertEquals(binder.location.get(), "a#a=b"); }; BinderTest.prototype.testRepeaterUpdateBindings = function(){ - var form = html('
        '); - var binder = new Binder(form.get(0), null, new MockLocation()); + var a = compile('
        '); + var form = a.node; var items = [{a:"A"}, {a:"B"}]; - form.data('scope', new Scope({model:{items:items}})); - binder.compile(); + a.scope.set('model', {items:items}); - binder.updateView(); + a.binder.updateView(); assertEquals('
          ' + '<#comment>' + '
        • A
        • ' + @@ -409,7 +383,7 @@ BinderTest.prototype.testRepeaterUpdateBindings = function(){ '
        ', form.sortedHtml()); items.unshift({a:'C'}); - binder.updateView(); + a.binder.updateView(); assertEquals('
          ' + '<#comment>' + '
        • C
        • ' + @@ -418,7 +392,7 @@ BinderTest.prototype.testRepeaterUpdateBindings = function(){ '
        ', form.sortedHtml()); items.shift(); - binder.updateView(); + a.binder.updateView(); assertEquals('
          ' + '<#comment>' + '
        • A
        • ' + @@ -427,15 +401,13 @@ 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 MockLocation()); - binder.compile(); - binder.updateView(); + var a = compile('
          '); + a.scope.set('model', {items:[{a:"A"}]}); + a.binder.updateView(); assertEquals('
            ' + '<#comment>' + '
          • A
          • ' + - '
          ', form.sortedHtml()); + '
        ', a.node.sortedHtml()); }; BinderTest.prototype.testShouldBindActionsOnRepeaterClone = function(){ @@ -524,64 +496,55 @@ BinderTest.prototype.testRepeaterAdd = function(){ }; 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 MockLocation()); - binder.compile(); + var a = compile('
        {{error.throw()}}
        '); + var doc = a.node.find('div'); - scope.set('error.throw', function(){throw "ErrorMsg1";}); - binder.updateView(); + a.scope.set('error.throw', function(){throw "ErrorMsg1";}); + a.binder.updateView(); var span = doc.find('span'); assertTrue(span.hasClass('ng-exception')); assertEquals('ErrorMsg1', fromJson(span.text())); assertEquals('"ErrorMsg1"', span.attr('ng-error')); - scope.set('error.throw', function(){throw "MyError";}); - binder.updateView(); + a.scope.set('error.throw', function(){throw "MyError";}); + a.binder.updateView(); span = doc.find('span'); assertTrue(span.hasClass('ng-exception')); assertTrue(span.text(), span.text().match('MyError') !== null); assertEquals('"MyError"', span.attr('ng-error')); - scope.set('error.throw', function(){return "ok";}); - binder.updateView(); + a.scope.set('error.throw', function(){return "ok";}); + a.binder.updateView(); assertFalse(span.hasClass('ng-exception')); assertEquals('ok', span.text()); assertEquals(null, span.attr('ng-error')); }; BinderTest.prototype.testIfAttrBindingThrowsErrorDecorateTheSpan = function(){ - var doc = $('
        '); - var scope = new Scope(); - doc.data('scope', scope); - var binder = new Binder(doc[0], new WidgetFactory(), new MockLocation()); - binder.compile(); + var a = compile('
        '); + var doc = a.node.find("div"); - scope.set('error.throw', function(){throw "ErrorMsg";}); - binder.updateView(); + a.scope.set('error.throw', function(){throw "ErrorMsg";}); + a.binder.updateView(); assertTrue('ng-exception', doc.hasClass('ng-exception')); assertEquals('before ["ErrorMsg"] after', doc.attr('attr')); assertEquals('"ErrorMsg"', doc.attr('ng-error')); - scope.set('error.throw', function(){ return 'X';}); - binder.updateView(); + a.scope.set('error.throw', function(){ return 'X';}); + a.binder.updateView(); assertFalse('!ng-exception', doc.hasClass('ng-exception')); assertEquals('before X after', doc.attr('attr')); assertEquals(null, doc.attr('ng-error')); + }; BinderTest.prototype.testNestedRepeater = function() { - var doc = html('
        ' + + var a = compile('
        ' + '
          ' + '
          '); - var scope = new Scope(); - doc.data('scope', scope); - 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']}]); - binder.updateView(); + a.scope.set('model', [{name:'a', item:['a1', 'a2']}, {name:'b', item:['b1', 'b2']}]); + a.binder.updateView(); assertEquals( //'<#comment>'+ @@ -594,88 +557,71 @@ BinderTest.prototype.testNestedRepeater = function() { '<#comment>'+ '
            '+ '
              '+ - '
              ', doc.sortedHtml()); + '
              ', a.node.sortedHtml()); }; BinderTest.prototype.testRadioButtonGetsPrefixed = function () { - var doc = html(''); - var scope = new Scope(); - doc.data('scope', scope); - var binder = new Binder(doc[0], new WidgetFactory(), new MockLocation()); - binder.compile(); - - scope.set('model', ['a1', 'a2']); - binder.updateView(); + var a = compile(''); + a.scope.set('model', ['a1', 'a2']); + a.binder.updateView(); assertEquals( //'<#comment>'+ ''+ '', - doc.sortedHtml()); + a.node.sortedHtml()); }; BinderTest.prototype.testHideBindingExpression = function() { - var doc = html('
              '); - var scope = new Scope(); - doc.data('scope', scope); - var binder = new Binder(doc[0], new WidgetFactory(), new MockLocation()); - binder.compile(); + var a = compile('
              '); - scope.set('hidden', 3); - binder.updateView(); + a.scope.set('hidden', 3); + a.binder.updateView(); - assertHidden(doc.children()); + assertHidden(a.node.children()); - scope.set('hidden', 2); - binder.updateView(); + a.scope.set('hidden', 2); + a.binder.updateView(); - assertVisible(doc.children()); + assertVisible(a.node.children()); }; BinderTest.prototype.testHideBinding = function() { - var doc = html('
              '); - var scope = new Scope(); - doc.data('scope', scope); - var binder = new Binder(doc[0], new WidgetFactory(), new MockLocation()); - binder.compile(); + var c = compile('
              '); - scope.set('hidden', 'true'); - binder.updateView(); + c.scope.set('hidden', 'true'); + c.binder.updateView(); - assertHidden(doc.children()); + assertHidden(c.node.children()); - scope.set('hidden', 'false'); - binder.updateView(); + c.scope.set('hidden', 'false'); + c.binder.updateView(); - assertVisible(doc.children()); + assertVisible(c.node.children()); - scope.set('hidden', ''); - binder.updateView(); + c.scope.set('hidden', ''); + c.binder.updateView(); - assertVisible(doc.children()); + assertVisible(c.node.children()); }; BinderTest.prototype.testShowBinding = function() { - var doc = html('
              '); - var scope = new Scope(); - doc.data('scope', scope); - var binder = new Binder(doc[0], new WidgetFactory(), new MockLocation()); - binder.compile(); + var c = compile('
              '); - scope.set('show', 'true'); - binder.updateView(); + c.scope.set('show', 'true'); + c.binder.updateView(); - assertVisible(doc.children()); + assertVisible(c.node.children()); - scope.set('show', 'false'); - binder.updateView(); + c.scope.set('show', 'false'); + c.binder.updateView(); - assertHidden(doc.children()); + assertHidden(c.node.children()); - scope.set('show', ''); - binder.updateView(); + c.scope.set('show', ''); + c.binder.updateView(); - assertHidden(doc.children()); + assertHidden(c.node.children()); }; BinderTest.prototype.testBindClassUndefined = function() { @@ -688,22 +634,18 @@ BinderTest.prototype.testBindClassUndefined = function() { }; BinderTest.prototype.testBindClass = function() { - var doc = html('
              '); - var scope = new Scope(); - doc.data('scope', scope); - var binder = new Binder(doc[0], new WidgetFactory(), new MockLocation()); - binder.compile(); + var c = compile('
              '); - scope.set('class', 'testClass'); - binder.updateView(); + c.scope.set('class', 'testClass'); + c.binder.updateView(); - assertEquals(doc.sortedHtml(), + assertEquals(c.node.sortedHtml(), '
              '); - scope.set('class', ['a', 'b']); - binder.updateView(); + c.scope.set('class', ['a', 'b']); + c.binder.updateView(); - assertEquals(doc.sortedHtml(), + assertEquals(c.node.sortedHtml(), '
              '); }; @@ -717,21 +659,17 @@ BinderTest.prototype.testBindClassEvenOdd = function() { }; BinderTest.prototype.testBindStyle = function() { - var doc = html('
              '); - var scope = new Scope(); - doc.data('scope', scope); - var binder = new Binder(doc[0], new WidgetFactory(), new MockLocation()); - binder.compile(); + var c = compile('
              '); - scope.eval('style={color:"red"}'); - binder.updateView(); + c.scope.eval('style={color:"red"}'); + c.binder.updateView(); - assertEquals("red", doc.find('div').css('color')); + assertEquals("red", c.node.find('div').css('color')); - scope.eval('style={}'); - binder.updateView(); + c.scope.eval('style={}'); + c.binder.updateView(); - assertEquals(doc.sortedHtml(), '
              '); + assertEquals(c.node.sortedHtml(), '
              '); }; BinderTest.prototype.testActionOnAHrefThrowsError = function(){ @@ -919,7 +857,7 @@ BinderTest.prototype.testParseQueryString = function(){ BinderTest.prototype.testSetBinderAnchorTriggersListeners = function(){ expectAsserts(2); var doc = html("
              ")[0]; - var binder = new Binder(doc, null, new MockLocation()); + var binder = new Binder(doc, null, null, new MockLocation()); var scope = new Scope({$binder:binder, $anchor:binder.anchor}); jQuery(doc).data('scope', scope); diff --git a/test/EntityDeclarationTest.js b/test/EntityDeclarationTest.js index d64dd775..28986ea8 100644 --- a/test/EntityDeclarationTest.js +++ b/test/EntityDeclarationTest.js @@ -2,31 +2,34 @@ EntityDeclarationTest = TestCase('EntityDeclarationTest'); EntityDeclarationTest.prototype.testEntityTypeOnly = function(){ expectAsserts(2); - var scope = new Scope({$datastore:{entity:function(name){ + var datastore = {entity:function(name){ assertEquals("Person", name); - }}}); - var init = scope.entity("Person"); + }}; + var scope = new Scope(); + var init = scope.entity("Person", datastore); assertEquals("", init); }; EntityDeclarationTest.prototype.testWithDefaults = function(){ expectAsserts(4); - var scope = new Scope({$datastore:{entity:function(name, init){ + var datastore = {entity:function(name, init){ assertEquals("Person", name); assertEquals("=a:", init.a); assertEquals(0, init.b.length); - }}}); - var init = scope.entity('Person:{a:"=a:", b:[]}'); + }}; + var scope = new Scope(); + var init = scope.entity('Person:{a:"=a:", b:[]}', datastore); assertEquals("", init); }; EntityDeclarationTest.prototype.testWithName = function(){ expectAsserts(2); - var scope = new Scope({$datastore:{entity:function(name, init){ + var datastore = {entity:function(name, init){ assertEquals("Person", name); return function (){ return {}; }; - }}}); - var init = scope.entity('friend=Person'); + }}; + var scope = new Scope(); + var init = scope.entity('friend=Person', datastore); assertEquals("$anchor.friend:{friend=Person.load($anchor.friend);friend.$$anchor=\"friend\";};", init); }; @@ -34,12 +37,13 @@ EntityDeclarationTest.prototype.testMultipleEntities = function(){ expectAsserts(3); var expect = ['Person', 'Book']; var i=0; - var scope = new Scope({$datastore:{entity:function(name, init){ + var datastore = {entity:function(name, init){ assertEquals(expect[i], name); i++; return function (){ return {}; }; - }}}); - var init = scope.entity('friend=Person;book=Book;'); + }}; + var scope = new Scope(); + var init = scope.entity('friend=Person;book=Book;', datastore); assertEquals("$anchor.friend:{friend=Person.load($anchor.friend);friend.$$anchor=\"friend\";};" + "$anchor.book:{book=Book.load($anchor.book);book.$$anchor=\"book\";};", init); diff --git a/test/ParserTest.js b/test/ParserTest.js index fbd9f508..2fcbc7fe 100644 --- a/test/ParserTest.js +++ b/test/ParserTest.js @@ -451,8 +451,7 @@ ParserTest.prototype.testItShouldHaveDefaultArugument = function(){ ParserTest.prototype.testReturnFunctionsAreNotBound = function(){ var scope = new Scope(); - scope.set("$datastore", new DataStore()); - scope.entity("Group"); + scope.entity("Group", new DataStore()); var Group = scope.get("Group"); assertEquals("eval Group", "function", typeof scope.eval("Group")); assertEquals("direct Group", "function", typeof Group); diff --git a/test/ScenarioSpec.js b/test/ScenarioSpec.js index c3c29f02..2ca1de2f 100644 --- a/test/ScenarioSpec.js +++ b/test/ScenarioSpec.js @@ -29,7 +29,7 @@ describe("ScenarioSpec: Scope", function(){ }); it("should have config", function(){ - expect(angular.compile('', {a:'b'}).config.a).toEqual('b'); + expect(angular.compile('
              ', {a:'b'}).config.a).toEqual('b'); }); it("should have $ objects", function(){ -- cgit v1.2.3 From a5c446441fee005975a82885771e8d931e7a4e7a Mon Sep 17 00:00:00 2001 From: Misko Hevery Date: Sun, 24 Jan 2010 19:12:01 -0800 Subject: fix closure compiler incompatibilities --- test/FileControllerTest.js | 4 ++-- test/WidgetsTest.js | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) (limited to 'test') diff --git a/test/FileControllerTest.js b/test/FileControllerTest.js index 09eb6fc5..454e7624 100644 --- a/test/FileControllerTest.js +++ b/test/FileControllerTest.js @@ -5,7 +5,7 @@ FileControllerTest.prototype.testOnSelectUpdateView = function(){ var swf = {}; var controller = new FileController(view, null, swf); swf.uploadFile = function(path){}; - controller._on_select('A', 9, '9 bytes'); + controller.select('A', 9, '9 bytes'); assertEquals(view.find('a').text(), "A"); assertEquals(view.find('span').text(), "9 bytes"); }; @@ -20,7 +20,7 @@ FileControllerTest.prototype.testUpdateModelView = function(){ view.data('scope', scope); controller = new FileController(view, 'value.input', null, "http://server_base"); var value = '{"text":"A", "size":123, "id":"890"}'; - controller._on_uploadCompleteData(value); + controller.uploadCompleteData(value); controller.updateView(scope); assertEquals(scope.get('value.input.text'), 'A'); assertEquals(scope.get('value.input.size'), 123); diff --git a/test/WidgetsTest.js b/test/WidgetsTest.js index fe20e664..c0a2d082 100644 --- a/test/WidgetsTest.js +++ b/test/WidgetsTest.js @@ -223,10 +223,10 @@ BindAttrUpdaterTest.prototype.testShouldLoadBlankImageWhenBindingIsUndefined = f var scope = new Scope(); scope.set('imageUrl', undefined); - scope.set('config.server', 'http://server'); + scope.set('$config.blankImage', 'http://server/blank.gif'); controller.updateView(scope); - assertEquals("http://server/images/blank.gif", view.attr('src')); + assertEquals("http://server/blank.gif", view.attr('src')); }; RepeaterUpdaterTest.prototype.testShouldNotDieWhenRepeatExpressionIsNull = function() { -- cgit v1.2.3 From a2540fd581f35e8f79240d827d2252da5798c3a2 Mon Sep 17 00:00:00 2001 From: Misko Hevery Date: Mon, 25 Jan 2010 23:49:52 -0800 Subject: fixes to make it pass on IE --- test/ApiTest.js | 2 +- test/BinderTest.js | 2 +- test/testabilityPatch.js | 5 ++--- 3 files changed, 4 insertions(+), 5 deletions(-) (limited to 'test') diff --git a/test/ApiTest.js b/test/ApiTest.js index 250a27b1..fc9190ed 100644 --- a/test/ApiTest.js +++ b/test/ApiTest.js @@ -204,7 +204,7 @@ ApiTest.prototype.testQuoteString = function(){ }; ApiTest.prototype.testQuoteStringBug = function(){ - assertEquals(angular.String.quote('"7\\\\\\\"7"', "7\\\"7")); + assertEquals('"7\\\\\\\"7"', angular.String.quote("7\\\"7")); }; ApiTest.prototype.testQuoteUnicode = function(){ diff --git a/test/BinderTest.js b/test/BinderTest.js index 6ef46fae..cf2fa31a 100644 --- a/test/BinderTest.js +++ b/test/BinderTest.js @@ -401,7 +401,7 @@ BinderTest.prototype.testRepeaterUpdateBindings = function(){ }; BinderTest.prototype.testRepeaterContentDoesNotBind = function(){ - var a = compile('
              '); + var a = compile('
              '); a.scope.set('model', {items:[{a:"A"}]}); a.binder.updateView(); assertEquals('
                ' + diff --git a/test/testabilityPatch.js b/test/testabilityPatch.js index 8fac7598..d9aed6f2 100644 --- a/test/testabilityPatch.js +++ b/test/testabilityPatch.js @@ -1,5 +1,3 @@ -TestCase = function(name) { return jstestdriver.testCaseManager.TestCase(name); }; - HIDDEN = jQuery.browser.msie ? '' : jQuery.browser.safari ? @@ -7,7 +5,7 @@ HIDDEN = jQuery.browser.msie ? ' style="display: none;"'; msie = jQuery.browser.msie; -alert = function(msg) {jstestdriver.console.log("ALERT: " + msg);}; +//alert = function(msg) {jstestdriver.console.log("ALERT: " + msg);}; function noop(){} @@ -35,6 +33,7 @@ function report(reportTest){ }); } + MockLocation = function() { this.url = "http://server"; }; -- cgit v1.2.3 From 3d99e0f6dee6569ca9471d419bda79aec95b9ebc Mon Sep 17 00:00:00 2001 From: Misko Hevery Date: Thu, 28 Jan 2010 20:44:34 -0800 Subject: work --- test/ApiTest.js | 2 +- test/FormatersTest.js | 6 ++++++ 2 files changed, 7 insertions(+), 1 deletion(-) create mode 100644 test/FormatersTest.js (limited to 'test') diff --git a/test/ApiTest.js b/test/ApiTest.js index 250a27b1..35cbbd81 100644 --- a/test/ApiTest.js +++ b/test/ApiTest.js @@ -204,7 +204,7 @@ ApiTest.prototype.testQuoteString = function(){ }; ApiTest.prototype.testQuoteStringBug = function(){ - assertEquals(angular.String.quote('"7\\\\\\\"7"', "7\\\"7")); + assertEquals(angular.String.quote("7\\\"7"), '"7\\\\\\\"7"'); }; ApiTest.prototype.testQuoteUnicode = function(){ diff --git a/test/FormatersTest.js b/test/FormatersTest.js new file mode 100644 index 00000000..0122b6ad --- /dev/null +++ b/test/FormatersTest.js @@ -0,0 +1,6 @@ +TestCase("formaterTest", { + testNoop: function(){ + assertEquals("abc", angular.formater.noop("abc")); + assertEquals("xyz", angular.formater.noop("abc", "xyz")); + } +}); -- cgit v1.2.3 From a9c182764b5feeb2466c4bb32f7572762f7fab6d Mon Sep 17 00:00:00 2001 From: Misko Hevery Date: Thu, 28 Jan 2010 22:10:49 -0800 Subject: added formatters --- test/BinderTest.js | 17 +++++++++++++++-- test/FormatersTest.js | 6 ------ test/FormattersTest.js | 28 ++++++++++++++++++++++++++++ test/WidgetsTest.js | 6 +++--- 4 files changed, 46 insertions(+), 11 deletions(-) delete mode 100644 test/FormatersTest.js create mode 100644 test/FormattersTest.js (limited to 'test') diff --git a/test/BinderTest.js b/test/BinderTest.js index cf2fa31a..450100e4 100644 --- a/test/BinderTest.js +++ b/test/BinderTest.js @@ -129,10 +129,10 @@ BinderTest.prototype.testChangingRadioUpdatesModel = function(){ }; BinderTest.prototype.testChangingCheckboxUpdatesModel = function(){ - var form = compile(''); + var form = compile(''); form.scope.set('model', {}); form.binder.updateView(); - assertEquals('A', form.scope.get('model').price); + assertEquals(true, form.scope.get('model').price); }; BinderTest.prototype.testBindUpdate = function() { @@ -951,3 +951,16 @@ BinderTest.prototype.testItShouldRenderMultiRootHtmlInBinding = function() { '
                before acdafter
                ', x.node.sortedHtml()); }; + +BinderTest.prototype.testItShouldUseFormaterForText = function() { + var x = compile(''); + x.binder.updateView(); + assertEquals(['a','b'], x.scope.get('a')); + var input = x.node.find('input'); + input[0].value = ' x,,yz'; + input.change(); + assertEquals(['x','yz'], x.scope.get('a')); + x.scope.set('a', [1 ,2, 3]); + x.binder.updateView(); + assertEquals('1, 2, 3', input[0].value); +}; diff --git a/test/FormatersTest.js b/test/FormatersTest.js deleted file mode 100644 index 0122b6ad..00000000 --- a/test/FormatersTest.js +++ /dev/null @@ -1,6 +0,0 @@ -TestCase("formaterTest", { - testNoop: function(){ - assertEquals("abc", angular.formater.noop("abc")); - assertEquals("xyz", angular.formater.noop("abc", "xyz")); - } -}); diff --git a/test/FormattersTest.js b/test/FormattersTest.js new file mode 100644 index 00000000..b71e68dc --- /dev/null +++ b/test/FormattersTest.js @@ -0,0 +1,28 @@ +TestCase("formatterTest", { + testNoop: function(){ + assertEquals("abc", angular.formatter.noop.format("abc")); + assertEquals("xyz", angular.formatter.noop.parse("xyz")); + assertEquals(null, angular.formatter.noop.parse(null)); + }, + + testList: function() { + assertEquals('a, b', angular.formatter.list.format(['a', 'b'])); + assertEquals(['abc', 'c'], angular.formatter.list.parse(" , abc , c ,,")); + assertEquals(null, angular.formatter.list.parse(null)); + }, + + testBoolean: function() { + assertEquals('true', angular.formatter.boolean.format(true)); + assertEquals('false', angular.formatter.boolean.format(false)); + assertEquals(true, angular.formatter.boolean.parse("true")); + assertEquals(false, angular.formatter.boolean.parse("")); + assertEquals(false, angular.formatter.boolean.parse("false")); + assertEquals(null, angular.formatter.boolean.parse(null)); + }, + + testNumber: function() { + assertEquals('1', angular.formatter.number.format(1)); + assertEquals(1, angular.formatter.number.format('1')); + } + +}); diff --git a/test/WidgetsTest.js b/test/WidgetsTest.js index c0a2d082..4e3852a5 100644 --- a/test/WidgetsTest.js +++ b/test/WidgetsTest.js @@ -3,7 +3,7 @@ WidgetTest = TestCase('WidgetTest'); WidgetTest.prototype.testRequired = function () { var view = $(''); var scope = new Scope({$invalidWidgets:[]}); - var cntl = new TextController(view[0], 'a'); + var cntl = new TextController(view[0], 'a', angularFormatter.noop); cntl.updateView(scope); assertTrue(view.hasClass('ng-validation-error')); assertEquals("Required Value", view.attr('ng-error')); @@ -16,7 +16,7 @@ WidgetTest.prototype.testRequired = function () { WidgetTest.prototype.testValidator = function () { var view = $(''); var scope = new Scope({$invalidWidgets:[]}); - var cntl = new TextController(view[0], 'a'); + var cntl = new TextController(view[0], 'a', angularFormatter.noop); angular.validator.testValidator = function(value, expect){ return value == expect ? null : "Error text"; }; @@ -44,7 +44,7 @@ WidgetTest.prototype.testValidator = function () { WidgetTest.prototype.testRequiredValidator = function () { var view = $(''); var scope = new Scope({$invalidWidgets:[]}); - var cntl = new TextController(view[0], 'a'); + var cntl = new TextController(view[0], 'a', angularFormatter.noop); angular.validator.testValidator = function(value, expect){ return value == expect ? null : "Error text"; }; -- cgit v1.2.3 From 302472f4fa50f995085ebf36b8990bedf3806973 Mon Sep 17 00:00:00 2001 From: Misko Hevery Date: Thu, 4 Feb 2010 11:12:34 -0800 Subject: list formater always should return arry --- test/FormattersTest.js | 4 +++- test/testabilityPatch.js | 3 +-- 2 files changed, 4 insertions(+), 3 deletions(-) (limited to 'test') diff --git a/test/FormattersTest.js b/test/FormattersTest.js index b71e68dc..e91fd37f 100644 --- a/test/FormattersTest.js +++ b/test/FormattersTest.js @@ -7,8 +7,10 @@ TestCase("formatterTest", { testList: function() { assertEquals('a, b', angular.formatter.list.format(['a', 'b'])); + assertEquals('', angular.formatter.list.format([])); assertEquals(['abc', 'c'], angular.formatter.list.parse(" , abc , c ,,")); - assertEquals(null, angular.formatter.list.parse(null)); + assertEquals([], angular.formatter.list.parse("")); + assertEquals([], angular.formatter.list.parse(null)); }, testBoolean: function() { diff --git a/test/testabilityPatch.js b/test/testabilityPatch.js index d9aed6f2..44199b66 100644 --- a/test/testabilityPatch.js +++ b/test/testabilityPatch.js @@ -12,7 +12,7 @@ function noop(){} jstd = jstestdriver; swfobject = { - createSwf:function(){ + createSwf:function() { fail("must mock out swfobject.createSwf in test."); } }; @@ -33,7 +33,6 @@ function report(reportTest){ }); } - MockLocation = function() { this.url = "http://server"; }; -- cgit v1.2.3 From 5dd43b85e73ca1708e7fd85094b533b02266a79a Mon Sep 17 00:00:00 2001 From: Misko Hevery Date: Thu, 4 Feb 2010 11:45:38 -0800 Subject: ng-required treats whitespace as empty --- test/BinderTest.js | 8 ++++++++ 1 file changed, 8 insertions(+) (limited to 'test') diff --git a/test/BinderTest.js b/test/BinderTest.js index 450100e4..a45183a4 100644 --- a/test/BinderTest.js +++ b/test/BinderTest.js @@ -767,6 +767,14 @@ BinderTest.prototype.testValidateForm = function() { c.binder.updateView(); assertEquals(3, c.scope.get("$invalidWidgets.length")); + c.scope.set('name', ''); + c.binder.updateView(); + assertEquals(3, c.scope.get("$invalidWidgets.length")); + + c.scope.set('name', ' '); + c.binder.updateView(); + assertEquals(3, c.scope.get("$invalidWidgets.length")); + c.scope.set('name', 'abc'); c.binder.updateView(); assertEquals(2, c.scope.get("$invalidWidgets.length")); -- cgit v1.2.3 From 1da18e73a4d09b2a1ace92a4094eeba014eb7dc4 Mon Sep 17 00:00:00 2001 From: Misko Hevery Date: Thu, 4 Feb 2010 13:27:56 -0800 Subject: consider widget errors only when widgets are visible --- test/BinderTest.js | 11 +++++++++++ test/FormattersTest.js | 7 +++++++ test/testabilityPatch.js | 12 ++++++++---- 3 files changed, 26 insertions(+), 4 deletions(-) (limited to 'test') diff --git a/test/BinderTest.js b/test/BinderTest.js index a45183a4..41319b52 100644 --- a/test/BinderTest.js +++ b/test/BinderTest.js @@ -788,6 +788,17 @@ BinderTest.prototype.testValidateForm = function() { assertEquals(0, c.scope.get("$invalidWidgets.length")); }; +BinderTest.prototype.testValidateOnlyVisibleItems = function(){ + var c = compile(''); + c.scope.set("show", true); + c.binder.updateView(); + assertEquals(2, c.scope.get("$invalidWidgets.length")); + + c.scope.set("show", false); + c.binder.updateView(); + assertEquals(1, c.scope.get("$invalidWidgets.length")); +}; + BinderTest.prototype.testDeleteAttributeIfEvaluatesFalse = function() { var c = compile( '' + diff --git a/test/FormattersTest.js b/test/FormattersTest.js index e91fd37f..59f12c1f 100644 --- a/test/FormattersTest.js +++ b/test/FormattersTest.js @@ -25,6 +25,13 @@ TestCase("formatterTest", { testNumber: function() { assertEquals('1', angular.formatter.number.format(1)); assertEquals(1, angular.formatter.number.format('1')); + }, + + testTrim: function() { + assertEquals('', angular.formatter.trim.format(null)); + assertEquals('', angular.formatter.trim.format("")); + assertEquals('a', angular.formatter.trim.format(" a ")); + assertEquals('a', angular.formatter.trim.parse(' a ')); } }); diff --git a/test/testabilityPatch.js b/test/testabilityPatch.js index 44199b66..cb1432f7 100644 --- a/test/testabilityPatch.js +++ b/test/testabilityPatch.js @@ -96,15 +96,19 @@ function decode64(base64){ configureJQueryPlugins(); +function isVisible(node) { + var display = $(node).css('display'); + if (display == 'block') display = ""; + return display != 'none'; +} + function assertHidden(node) { var display = node.css('display'); - assertEquals("Node should be hidden but vas visible: " + node.sortedHtml(), 'none', display); + assertFalse("Node should be hidden but vas visible: " + node.sortedHtml(), isVisible(node)); } function assertVisible(node) { - var display = node.css('display'); - if (display == 'block') display = ""; - assertEquals("Node should be visible but vas hidden: " + node.sortedHtml(), '', display); + assertTrue("Node should be visible but vas hidden: " + node.sortedHtml(), isVisible(node)); } function assertJsonEquals(expected, actual) { -- cgit v1.2.3 From 9f919c42f0885e39870195fab8ce2a22621119b7 Mon Sep 17 00:00:00 2001 From: Misko Hevery Date: Thu, 4 Feb 2010 14:02:20 -0800 Subject: better handling of $invalidWidgets --- test/BinderTest.js | 13 +++++-------- 1 file changed, 5 insertions(+), 8 deletions(-) (limited to 'test') diff --git a/test/BinderTest.js b/test/BinderTest.js index 41319b52..f10ed9b1 100644 --- a/test/BinderTest.js +++ b/test/BinderTest.js @@ -3,7 +3,7 @@ BinderTest = TestCase('BinderTest'); function compile(content, initialScope, config) { var h = html(content); config = config || {autoSubmit:true}; - var scope = new Scope(initialScope, "ROOT"); + var scope = new Scope($.extend({$invalidWidgets:[]}, initialScope), "ROOT"); h.data('scope', scope); var datastore = new DataStore(); var binder = new Binder(h[0], new WidgetFactory(), datastore, new MockLocation(), config); @@ -875,18 +875,15 @@ BinderTest.prototype.testParseQueryString = function(){ BinderTest.prototype.testSetBinderAnchorTriggersListeners = function(){ expectAsserts(2); - var doc = html("
                ")[0]; - var binder = new Binder(doc, null, null, new MockLocation()); - var scope = new Scope({$binder:binder, $anchor:binder.anchor}); - jQuery(doc).data('scope', scope); + var doc = compile("
                "); - scope.addWatchListener("$anchor.name", function(newVal, oldVal) { + doc.scope.addWatchListener("$anchor.name", function(newVal, oldVal) { assertEquals("new", newVal); assertEquals(undefined, oldVal); }); - binder.anchor.name = "new"; - binder.onUrlChange("http://base#name=new"); + doc.binder.anchor.name = "new"; + doc.binder.onUrlChange("http://base#name=new"); }; BinderTest.prototype.testItShouldDisplayErrorWhenActionIsSyntacticlyIncorect = function(){ -- cgit v1.2.3 From 251fab40291183c8e50ea0fabd23c30341cc72d3 Mon Sep 17 00:00:00 2001 From: Misko Hevery Date: Thu, 4 Feb 2010 15:04:28 -0800 Subject: updateView is now called on binder instead of scope --- test/ScenarioSpec.js | 2 ++ test/testabilityPatch.js | 3 +++ 2 files changed, 5 insertions(+) (limited to 'test') diff --git a/test/ScenarioSpec.js b/test/ScenarioSpec.js index 2ca1de2f..690ce464 100644 --- a/test/ScenarioSpec.js +++ b/test/ScenarioSpec.js @@ -21,10 +21,12 @@ describe("ScenarioSpec: Compilation", function(){ describe("ScenarioSpec: Scope", function(){ it("should have set, get, eval, init, updateView methods", function(){ var scope = angular.compile('
                {{a}}
                ').init(); + scope.eval("$invalidWidgets.push({})"); expect(scope.set("a", 2)).toEqual(2); expect(scope.get("a")).toEqual(2); expect(scope.eval("a=3")).toEqual(3); scope.updateView(); + expect(scope.eval("$invalidWidgets")).toEqual([]); expect($(scope.element).text()).toEqual('3'); }); diff --git a/test/testabilityPatch.js b/test/testabilityPatch.js index cb1432f7..293553da 100644 --- a/test/testabilityPatch.js +++ b/test/testabilityPatch.js @@ -135,3 +135,6 @@ function assertThrows(error, fn){ } assertEquals(error, exception); } + +log = noop; +error = noop; \ No newline at end of file -- cgit v1.2.3 From 6d75afe6d2ea26bb412becd1e8f7cab8031eaab4 Mon Sep 17 00:00:00 2001 From: Misko Hevery Date: Fri, 5 Feb 2010 14:13:19 -0800 Subject: fixed memory leak on repeaters --- test/BinderTest.js | 8 ++++++++ 1 file changed, 8 insertions(+) (limited to 'test') diff --git a/test/BinderTest.js b/test/BinderTest.js index f10ed9b1..a3f1eac5 100644 --- a/test/BinderTest.js +++ b/test/BinderTest.js @@ -373,6 +373,8 @@ BinderTest.prototype.testRepeaterUpdateBindings = function(){ var a = compile('
                '); var form = a.node; var items = [{a:"A"}, {a:"B"}]; + var initialDataCount = _(jQuery.cache).size(); + assertTrue("" + initialDataCount, initialDataCount > 0); a.scope.set('model', {items:items}); a.binder.updateView(); @@ -398,6 +400,12 @@ BinderTest.prototype.testRepeaterUpdateBindings = function(){ '
              • A
              • ' + '
              • B
              • ' + '
              ', form.sortedHtml()); + + items.shift(); + items.shift(); + a.binder.updateView(); + var currentDataCount = _(jQuery.cache).size(); + assertEquals("I have leaked " + (currentDataCount - initialDataCount), initialDataCount, currentDataCount); }; BinderTest.prototype.testRepeaterContentDoesNotBind = function(){ -- cgit v1.2.3 From 9d566a0cd0225685efb192c195280b6857628d32 Mon Sep 17 00:00:00 2001 From: Misko Hevery Date: Fri, 5 Feb 2010 14:41:45 -0800 Subject: better integer farmater --- test/ValidatorsTest.js | 2 ++ 1 file changed, 2 insertions(+) (limited to 'test') diff --git a/test/ValidatorsTest.js b/test/ValidatorsTest.js index 22c7f390..f06e0b3a 100644 --- a/test/ValidatorsTest.js +++ b/test/ValidatorsTest.js @@ -19,6 +19,8 @@ ValidatorTest.prototype.testNumber = function() { ValidatorTest.prototype.testInteger = function() { assertEquals(angular.validator.integer("ab"), "Value is not a number."); assertEquals(angular.validator.integer("1.1"), "Value is not a whole number."); + assertEquals(angular.validator.integer("1.0"), "Value is not a whole number."); + assertEquals(angular.validator.integer("1."), "Value is not a whole number."); assertEquals(angular.validator.integer("-1",0), "Value can not be less than 0."); assertEquals(angular.validator.integer("11",0,10), "Value can not be greater than 10."); assertEquals(angular.validator.integer("1"), null); -- cgit v1.2.3 From 799d72931a5a01de74bba69d8a6638cd57cec315 Mon Sep 17 00:00:00 2001 From: Misko Hevery Date: Tue, 9 Feb 2010 13:13:18 -0800 Subject: added onUpdateView listener for config --- test/AngularTest.js | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) (limited to 'test') diff --git a/test/AngularTest.js b/test/AngularTest.js index a9146adf..8db723e5 100644 --- a/test/AngularTest.js +++ b/test/AngularTest.js @@ -1,6 +1,5 @@ AngularTest = TestCase('AngularTest'); - UrlWatcherTest = TestCase('UrlWatcherTest'); UrlWatcherTest.prototype.testUrlWatcher = function () { @@ -42,4 +41,4 @@ FunctionTest = TestCase("FunctionTest"); FunctionTest.prototype.testEscapeHtml = function () { assertEquals("<div>&amp;</div>", escapeHtml('
              &
              ')); -}; \ No newline at end of file +}; -- cgit v1.2.3 From 9d566fe98c3fa0091efef4adb0178f063da74f7c Mon Sep 17 00:00:00 2001 From: Misko Hevery Date: Tue, 9 Feb 2010 14:59:24 -0800 Subject: missing test --- test/AngularSpec.js | 10 ++++++++++ 1 file changed, 10 insertions(+) create mode 100644 test/AngularSpec.js (limited to 'test') diff --git a/test/AngularSpec.js b/test/AngularSpec.js new file mode 100644 index 00000000..65a32279 --- /dev/null +++ b/test/AngularSpec.js @@ -0,0 +1,10 @@ +describe('Angular', function(){ + it('should fire on updateEvents', function(){ + var onUpdateView = jasmine.createSpy(); + var scope = angular.compile("
              ", { onUpdateView: onUpdateView }); + expect(onUpdateView).wasNotCalled(); + scope.init(); + scope.updateView(); + expect(onUpdateView).wasCalled(); + }); +}); \ No newline at end of file -- cgit v1.2.3 From b2a8a089b6c31c8ff176c2483f659caae4f71afb Mon Sep 17 00:00:00 2001 From: Misko Hevery Date: Thu, 11 Feb 2010 09:57:42 -0800 Subject: make validator more leniant for errors which are false instead of null --- test/WidgetsTest.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'test') diff --git a/test/WidgetsTest.js b/test/WidgetsTest.js index 4e3852a5..313d7372 100644 --- a/test/WidgetsTest.js +++ b/test/WidgetsTest.js @@ -18,7 +18,7 @@ WidgetTest.prototype.testValidator = function () { var scope = new Scope({$invalidWidgets:[]}); var cntl = new TextController(view[0], 'a', angularFormatter.noop); angular.validator.testValidator = function(value, expect){ - return value == expect ? null : "Error text"; + return value == expect ? false : "Error text"; }; scope.set('a', ''); -- cgit v1.2.3 From 6cc946413622f1cef97997849e73a06a00f876fd Mon Sep 17 00:00:00 2001 From: Misko Hevery Date: Fri, 12 Feb 2010 14:16:33 -0800 Subject: Fixed negation grouping bug Make 'this' of validation be scope --- test/FiltersTest.js | 8 ++++---- test/ParserTest.js | 10 ++++++++++ test/ScopeTest.js | 3 ++- test/ValidatorsTest.js | 18 +++++++++++++++++- 4 files changed, 33 insertions(+), 6 deletions(-) (limited to 'test') diff --git a/test/FiltersTest.js b/test/FiltersTest.js index 5ca63ca7..e6e8b662 100644 --- a/test/FiltersTest.js +++ b/test/FiltersTest.js @@ -2,7 +2,7 @@ FiltersTest = TestCase('FiltersTest'); FiltersTest.prototype.testCurrency = function(){ var html = $(''); - var context = {element:html[0]}; + var context = {$element:html[0]}; var currency = bind(context, angular.filter.currency); assertEquals(currency(0), '$0.00'); @@ -17,10 +17,10 @@ FiltersTest.prototype.testFilterThisIsContext = function(){ expectAsserts(2); var scope = new Scope(); Scope.expressionCache = {}; - var context = {element:123}; + var context = {$element:123, self:{name:'misko'}}; angular.filter.testFn = function () { - assertEquals('Context not equal', this, context); - assertEquals('scope not equal', this.scope, scope); + assertEquals('Context not equal', 123, this.$element); + assertEquals('scope not equal', 'misko', this.name); }; scope.eval("0|testFn", context); delete angular.filter['testFn']; diff --git a/test/ParserTest.js b/test/ParserTest.js index 2fcbc7fe..09c3b8de 100644 --- a/test/ParserTest.js +++ b/test/ParserTest.js @@ -160,6 +160,9 @@ ParserTest.prototype.testComparison = function(){ assertEquals(scope.eval("1<=1"), true); assertEquals(scope.eval("1>2"), 1>2); assertEquals(scope.eval("2>=1"), 2>=1); + + assertEquals(true==2<3, scope.eval("true==2<3")); + }; ParserTest.prototype.testLogical = function(){ @@ -467,3 +470,10 @@ ParserTest.prototype.testDoubleNegationBug = function (){ assertEquals('a', scope.eval('{true:"a", false:"b"}[!!true]')); }; +ParserTest.prototype.testNegationBug = function () { + var scope = new Scope(); + assertEquals(!false || true, scope.eval("!false || true")); + assertEquals(!11 == 10, scope.eval("!11 == 10")); + assertEquals(12/6/2, scope.eval("12/6/2")); +}; + diff --git a/test/ScopeTest.js b/test/ScopeTest.js index b066f0cb..24febf19 100644 --- a/test/ScopeTest.js +++ b/test/ScopeTest.js @@ -83,8 +83,9 @@ ScopeTest.prototype.testGlobalFunctionAccess =function(){ ScopeTest.prototype.testValidationEval = function(){ expectAsserts(4); var scope = new Scope(); + scope.set("name", "misko"); angular.validator.testValidator = function(value, expect){ - assertEquals(scope, this.scope); + assertEquals("misko", this.name); return value == expect ? null : "Error text"; }; diff --git a/test/ValidatorsTest.js b/test/ValidatorsTest.js index f06e0b3a..a4e603fa 100644 --- a/test/ValidatorsTest.js +++ b/test/ValidatorsTest.js @@ -1,5 +1,22 @@ ValidatorTest = TestCase('ValidatorTest'); +ValidatorTest.prototype.testItShouldHaveThisSet = function() { + expectAsserts(5); + var self; + angular.validator.myValidator = function(first, last){ + assertEquals('misko', first); + assertEquals('hevery', last); + self = this; + }; + var c = compile(''); + c.scope.set('name', 'misko'); + c.scope.set('state', 'abc'); + c.binder.updateView(); + assertEquals('abc', self.state); + assertEquals('misko', self.name); + assertEquals('name', self.$element.name); +}; + ValidatorTest.prototype.testRegexp = function() { assertEquals(angular.validator.regexp("abc", /x/, "E1"), "E1"); assertEquals(angular.validator.regexp("abc", '/x/'), @@ -64,4 +81,3 @@ ValidatorTest.prototype.testJson = function() { assertNotNull(angular.validator.json("''X")); assertNull(angular.validator.json("{}")); }; - -- cgit v1.2.3 From 3f9a2ab9bdfcd12cb7df74b0d38cecf2ee4ac94a Mon Sep 17 00:00:00 2001 From: Misko Hevery Date: Fri, 12 Feb 2010 19:39:01 -0800 Subject: added asynchronous validator --- test/ValidatorsTest.js | 55 ++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 55 insertions(+) (limited to 'test') diff --git a/test/ValidatorsTest.js b/test/ValidatorsTest.js index a4e603fa..5449ebb0 100644 --- a/test/ValidatorsTest.js +++ b/test/ValidatorsTest.js @@ -81,3 +81,58 @@ ValidatorTest.prototype.testJson = function() { assertNotNull(angular.validator.json("''X")); assertNull(angular.validator.json("{}")); }; + +describe('Validator:asynchronous', function(){ + var asynchronous = angular.validator.asynchronous; + var self; + var value, fn; + + beforeEach(function(){ + value = null; + fn = null; + self = { + $element:$('')[0], + $invalidWidgets:[], + $updateView: noop + }; + }); + + it('should make a request and show spinner', function(){ + var x = compile('') + var asyncFn = function(v,f){value=v; fn=f}; + var input = x.node.find(":input"); + x.scope.set("asyncFn", asyncFn); + x.scope.set("name", "misko"); + x.binder.updateView(); + expect(value).toEqual('misko'); + expect(input.hasClass('ng-input-indicator-wait')).toBeTruthy(); + fn("myError"); + expect(input.hasClass('ng-input-indicator-wait')).toBeFalsy(); + expect(input.attr('ng-error')).toEqual("myError"); + }); + + 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).toEqual([self.$element]); + + var spy = jasmine.createSpy(); + asynchronous.call(self, "kai", spy); + expect(spy).wasNotCalled(); + + asynchronous.call(self, "misko", spy); + expect(spy).wasCalled(); + }); + + it("should ignore old callbacks, and not remove spinner", function(){ + var firstCb, secondCb; + asynchronous.call(self, "first", function(v,f){value=v; firstCb=f;}); + asynchronous.call(self, "second", function(v,f){value=v; secondCb=f;}); + + firstCb(); + expect($(self.$element).hasClass('ng-input-indicator-wait')).toBeTruthy(); + + secondCb(); + expect($(self.$element).hasClass('ng-input-indicator-wait')).toBeFalsy(); + }); +}); \ No newline at end of file -- cgit v1.2.3 From 7e14dff90516a41ff1903cc44fe3389710f15556 Mon Sep 17 00:00:00 2001 From: Misko Hevery Date: Wed, 17 Feb 2010 16:05:26 -0800 Subject: fix this on filter to point to scope --- test/FiltersTest.js | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'test') diff --git a/test/FiltersTest.js b/test/FiltersTest.js index e6e8b662..9552c820 100644 --- a/test/FiltersTest.js +++ b/test/FiltersTest.js @@ -17,7 +17,8 @@ FiltersTest.prototype.testFilterThisIsContext = function(){ expectAsserts(2); var scope = new Scope(); Scope.expressionCache = {}; - var context = {$element:123, self:{name:'misko'}}; + scope.set('name', 'misko'); + var context = {$element:123}; angular.filter.testFn = function () { assertEquals('Context not equal', 123, this.$element); assertEquals('scope not equal', 'misko', this.name); -- cgit v1.2.3 From b628de9758c313b106d22468f4b49bd223698fd5 Mon Sep 17 00:00:00 2001 From: Misko Hevery Date: Sat, 20 Feb 2010 17:27:21 -0800 Subject: fix option value bug --- test/BinderTest.js | 22 ++++++++++++++++------ 1 file changed, 16 insertions(+), 6 deletions(-) (limited to 'test') diff --git a/test/BinderTest.js b/test/BinderTest.js index a3f1eac5..d565ee30 100644 --- a/test/BinderTest.js +++ b/test/BinderTest.js @@ -400,7 +400,7 @@ BinderTest.prototype.testRepeaterUpdateBindings = function(){ '
            • A
            • ' + '
            • B
            • ' + '
            ', form.sortedHtml()); - + items.shift(); items.shift(); a.binder.updateView(); @@ -761,10 +761,20 @@ BinderTest.prototype.testSettingAnchorToNullOrUndefinedRemovesTheAnchorFromURL = }; BinderTest.prototype.testFillInOptionValueWhenMissing = function() { - var c = compile(''); - assertEquals( - '', - c.node.sortedHtml()); + var c = compile( + ''); + c.scope.set('a', 'A'); + c.scope.set('b', 'B'); + c.binder.updateView(); + + expect(c.node.find("option:first").attr('value')).toEqual('A'); + expect(c.node.find("option:first").text()).toEqual('A'); + + expect(c.node.find("option:nth-child(2)").attr('value')).toEqual(''); + expect(c.node.find("option:nth-child(2)").text()).toEqual('B'); + + expect(c.node.find("option:last").attr('value')).toEqual('C'); + expect(c.node.find("option:last").text()).toEqual('C'); }; BinderTest.prototype.testValidateForm = function() { @@ -972,7 +982,7 @@ BinderTest.prototype.testItShouldRenderMultiRootHtmlInBinding = function() { x.scope.set("a", "acd"); x.binder.updateView(); assertEquals( - '
            before acdafter
            ', + '
            before acdafter
            ', x.node.sortedHtml()); }; -- cgit v1.2.3 From 6431efef8cb6d0c77bf107b09b64b6f013b75965 Mon Sep 17 00:00:00 2001 From: Misko Hevery Date: Fri, 26 Feb 2010 13:08:28 -0800 Subject: corrected repeater not removing when hash(instead of array) shrinks. --- test/BinderTest.js | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) (limited to 'test') diff --git a/test/BinderTest.js b/test/BinderTest.js index d565ee30..9ddf38ab 100644 --- a/test/BinderTest.js +++ b/test/BinderTest.js @@ -503,6 +503,23 @@ BinderTest.prototype.testRepeaterAdd = function(){ assertEquals(doc.scope().get('items')[0].x, 'ABC'); }; +BinderTest.prototype.testItShouldRemoveExtraChildrenWhenIteratingOverHash = function(){ + var c = compile('
            {{i}}
            '); + var items = {}; + c.scope.set("items", items); + + c.binder.updateView(); + expect(c.node.find("div").size()).toEqual(0); + + items.name = "misko"; + c.binder.updateView(); + expect(c.node.find("div").size()).toEqual(1); + + delete items.name; + c.binder.updateView(); + expect(c.node.find("div").size()).toEqual(0); +}; + BinderTest.prototype.testIfTextBindingThrowsErrorDecorateTheSpan = function(){ var a = compile('
            {{error.throw()}}
            '); var doc = a.node.find('div'); -- cgit v1.2.3 From cc71b745c3c821f5e012a363ae3267252a81fddb Mon Sep 17 00:00:00 2001 From: Misko Hevery Date: Mon, 15 Mar 2010 14:36:50 -0700 Subject: added resources; removed compiled code --- test/AngularSpec.js | 36 ++++++++++- test/ResourceSpec.js | 159 +++++++++++++++++++++++++++++++++++++++++++++++ test/testabilityPatch.js | 7 ++- 3 files changed, 200 insertions(+), 2 deletions(-) create mode 100644 test/ResourceSpec.js (limited to 'test') diff --git a/test/AngularSpec.js b/test/AngularSpec.js index 65a32279..043f7bf3 100644 --- a/test/AngularSpec.js +++ b/test/AngularSpec.js @@ -7,4 +7,38 @@ describe('Angular', function(){ scope.updateView(); expect(onUpdateView).wasCalled(); }); -}); \ No newline at end of file +}); + +describe("copy", function(){ + it("should return same object", function (){ + var obj = {}; + var arr = []; + assertSame(obj, copy({}, obj)); + assertSame(arr, copy([], arr)); + }); + + it("should copy array", function(){ + var src = [1, {name:"value"}]; + var dst = [{key:"v"}]; + assertSame(dst, copy(src, dst)); + assertEquals([1, {name:"value"}], dst); + assertEquals({name:"value"}, dst[1]); + assertNotSame(src[1], dst[1]); + }); + + it('should copy empty array', function() { + var src = []; + var dst = [{key: "v"}]; + assertEquals([], copy(src, dst)); + assertEquals([], dst); + }); + + it("should copy object", function(){ + var src = {a:{name:"value"}}; + var dst = {b:{key:"v"}}; + assertSame(dst, copy(src, dst)); + assertEquals({a:{name:"value"}}, dst); + assertEquals(src.a, dst.a); + assertNotSame(src.a, dst.a); + }); +}); diff --git a/test/ResourceSpec.js b/test/ResourceSpec.js new file mode 100644 index 00000000..562d6500 --- /dev/null +++ b/test/ResourceSpec.js @@ -0,0 +1,159 @@ +function MockXHR(){ + this.expectations = { + 'GET': {}, + 'POST': {}, + 'DELETE': {} + }; + this.queue = []; +} +MockXHR.prototype = { + method: function(verb, url, data, callback) { + if (verb == 'POST') + url += '|' + angular.toJson(data); + var response = this.expectations[verb][url]; + if (!response) + throw "No expectation for " + verb + " on '" + url + "'."; + this.queue.push(function(){ + callback(response); + }); + }, + + expectGET: function(url) { + var self = this; + return { + respond: function(response){ + self.expectations.GET[url] = response; + } + }; + }, + + expectDELETE: function(url) { + var self = this; + return { + respond: function(response){ + self.expectations.DELETE[url] = response; + } + }; + }, + + expectPOST: function(url) { + var self = this; + return { + data: function(data){ + return { + respond: function(response){ + self.expectations.POST[url + '|' + angular.toJson(data)] = response; + } + }; + } + }; + }, + + flush: function(){ + while(this.queue.length) { + this.queue.shift()(); + } + } +}; + +describe("resource", function() { + var xhr, resource, CreditCard, callback; + + beforeEach(function(){ + xhr = new MockXHR(); + resource = new ResourceFactory(xhr); + CreditCard = resource.route('/CreditCard/:id:verb', {id:'id.key'}, { + charge:{ + method:'POST', + params:{verb:'!charge'} + } + }); + callback = jasmine.createSpy(); + }); + + it("should build resource", function(){ + expect(typeof CreditCard).toBe('function'); + expect(typeof CreditCard.get).toBe('function'); + expect(typeof CreditCard.save).toBe('function'); + expect(typeof CreditCard.remove).toBe('function'); + expect(typeof CreditCard['delete']).toBe('function'); + expect(typeof CreditCard.query).toBe('function'); + }); + + it("should create resource", function(){ + xhr.expectPOST('/CreditCard').data({name:'misko'}).respond({id:123, name:'misko'}); + + var cc = CreditCard.save({name:'misko'}, callback); + nakedExpect(cc).toEqual({name:'misko'}); + expect(callback).wasNotCalled(); + xhr.flush(); + nakedExpect(cc).toEqual({id:123, name:'misko'}); + expect(callback).wasCalledWith(cc); + }); + + it("should read resource", function(){ + xhr.expectGET("/CreditCard/123").respond({id:123, number:'9876'}); + var cc = CreditCard.get({id:123}, callback); + expect(cc instanceof CreditCard).toBeTruthy(); + nakedExpect(cc).toEqual({}); + expect(callback).wasNotCalled(); + xhr.flush(); + nakedExpect(cc).toEqual({id:123, number:'9876'}); + expect(callback).wasCalledWith(cc); + }); + + it("should update resource", function(){ + xhr.expectPOST('/CreditCard/123').data({id:{key:123}, name:'misko'}).respond({id:{key:123}, name:'rama'}); + + var cc = CreditCard.save({id:{key:123}, name:'misko'}, callback); + nakedExpect(cc).toEqual({id:{key:123}, name:'misko'}); + expect(callback).wasNotCalled(); + xhr.flush(); + nakedExpect(cc).toEqual({id:{key:123}, name:'rama'}); + expect(callback).wasCalledWith(cc); + }); + + it("should query resource", function(){ + xhr.expectGET("/CreditCard?key=value").respond([{id:1}, {id:2}]); + + var ccs = CreditCard.query({key:'value'}, callback); + expect(ccs).toEqual([]); + expect(callback).wasNotCalled(); + xhr.flush(); + nakedExpect(ccs).toEqual([{id:1}, {id:2}]); + expect(callback).wasCalledWith(ccs); + }); + + it('should delete resource', function(){ + xhr.expectDELETE("/CreditCard/123").respond({}); + + CreditCard.remove({id:123}, callback); + expect(callback).wasNotCalled(); + xhr.flush(); + nakedExpect(callback.mostRecentCall.args).toEqual([{}]); + }); + + it('should post charge verb', function(){ + xhr.expectPOST('/CreditCard/123!charge?amount=10').data({auth:'abc'}).respond({success:'ok'}); + + CreditCard.charge({id:123, amount:10},{auth:'abc'}, callback); + }); + + it('should create on save', function(){ + xhr.expectPOST('/CreditCard').data({name:'misko'}).respond({id:123}); + var cc = new CreditCard(); + expect(cc.$get).not.toBeDefined(); + expect(cc.$query).not.toBeDefined(); + expect(cc.$remove).toBeDefined(); + expect(cc.$save).toBeDefined(); + + cc.name = 'misko'; + cc.$save(callback); + nakedExpect(cc).toEqual({name:'misko'}); + xhr.flush(); + nakedExpect(cc).toEqual({id:123}); + expect(callback).wasCalledWith(cc); + }); + + +}); diff --git a/test/testabilityPatch.js b/test/testabilityPatch.js index 293553da..e7ebb386 100644 --- a/test/testabilityPatch.js +++ b/test/testabilityPatch.js @@ -10,6 +10,11 @@ msie = jQuery.browser.msie; function noop(){} jstd = jstestdriver; +dump = _(jstd.console.log).bind(jstd.console); + +function nakedExpect(obj) { + return expect(angular.fromJson(angular.toJson(obj))); +}; swfobject = { createSwf:function() { @@ -137,4 +142,4 @@ function assertThrows(error, fn){ } log = noop; -error = noop; \ No newline at end of file +error = noop; -- cgit v1.2.3 From 79b743e52feb2c57ba0ae42d6d2742bc2189b22f Mon Sep 17 00:00:00 2001 From: Adam Abrons Date: Mon, 15 Mar 2010 15:57:12 -0700 Subject: resources, with bind() --- test/ResourceSpec.js | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) (limited to 'test') diff --git a/test/ResourceSpec.js b/test/ResourceSpec.js index 562d6500..799c7378 100644 --- a/test/ResourceSpec.js +++ b/test/ResourceSpec.js @@ -62,7 +62,7 @@ describe("resource", function() { beforeEach(function(){ xhr = new MockXHR(); resource = new ResourceFactory(xhr); - CreditCard = resource.route('/CreditCard/:id:verb', {id:'id.key'}, { + CreditCard = resource.route('/CreditCard/:id:verb', {id:'@id.key'}, { charge:{ method:'POST', params:{verb:'!charge'} @@ -80,6 +80,15 @@ describe("resource", function() { expect(typeof CreditCard.query).toBe('function'); }); + it("should build resource with default param", function(){ + xhr.expectGET('/Order/123/Line/456.visa?minimum=0.05').respond({id:'abc'}); + var LineItem = resource.route('/Order/:orderId/Line/:id:verb', {orderId: '123', id: '@id.key', verb:'.visa', minimum:0.05}); + var item = LineItem.get({id:456}); + xhr.flush(); + nakedExpect(item).toEqual({id:'abc'}); + + }); + it("should create resource", function(){ xhr.expectPOST('/CreditCard').data({name:'misko'}).respond({id:123, name:'misko'}); @@ -155,5 +164,12 @@ describe("resource", function() { expect(callback).wasCalledWith(cc); }); + it('should bind default parameters', function(){ + xhr.expectGET('/CreditCard/123.visa?minimum=0.05').respond({id:123}); + var Visa = CreditCard.bind({verb:'.visa', minimum:0.05}); + var visa = Visa.get({id:123}); + xhr.flush(); + nakedExpect(visa).toEqual({id:123}); + }); }); -- cgit v1.2.3 From 39c6c5975bedf6e1610f7328a088acda9ab3406a Mon Sep 17 00:00:00 2001 From: Adam Abrons Date: Mon, 15 Mar 2010 17:02:54 -0700 Subject: get scenarios running again - open Runner.html in a browser to run them --- test/scenario/StepsTest.js | 7 +++++++ test/test/StepsTest.js | 7 ------- 2 files changed, 7 insertions(+), 7 deletions(-) create mode 100644 test/scenario/StepsTest.js delete mode 100644 test/test/StepsTest.js (limited to 'test') diff --git a/test/scenario/StepsTest.js b/test/scenario/StepsTest.js new file mode 100644 index 00000000..9d64d0a9 --- /dev/null +++ b/test/scenario/StepsTest.js @@ -0,0 +1,7 @@ +StepsTest = TestCase("StepsTest"); + +StepsTest.prototype.testGivenDataset=function(){ + var self = {frame:{}, dataset:[]}; + angular.test.GIVEN.dataset.call(self); + assertEquals('$DATASET:{"dataset":[]}', self.frame.name); +}; diff --git a/test/test/StepsTest.js b/test/test/StepsTest.js deleted file mode 100644 index 9d64d0a9..00000000 --- a/test/test/StepsTest.js +++ /dev/null @@ -1,7 +0,0 @@ -StepsTest = TestCase("StepsTest"); - -StepsTest.prototype.testGivenDataset=function(){ - var self = {frame:{}, dataset:[]}; - angular.test.GIVEN.dataset.call(self); - assertEquals('$DATASET:{"dataset":[]}', self.frame.name); -}; -- cgit v1.2.3 From c9aba8b442adce496f0600c88764f7ffcc166879 Mon Sep 17 00:00:00 2001 From: Adam Abrons Date: Tue, 16 Mar 2010 14:48:11 -0700 Subject: make xhr just a method --- test/ResourceSpec.js | 7 ++++++- test/scenario/StepsTest.js | 2 +- 2 files changed, 7 insertions(+), 2 deletions(-) (limited to 'test') diff --git a/test/ResourceSpec.js b/test/ResourceSpec.js index 799c7378..0c7af00a 100644 --- a/test/ResourceSpec.js +++ b/test/ResourceSpec.js @@ -61,7 +61,7 @@ describe("resource", function() { beforeEach(function(){ xhr = new MockXHR(); - resource = new ResourceFactory(xhr); + resource = new ResourceFactory(_(xhr.method).bind(xhr)); CreditCard = resource.route('/CreditCard/:id:verb', {id:'@id.key'}, { charge:{ method:'POST', @@ -80,6 +80,11 @@ describe("resource", function() { expect(typeof CreditCard.query).toBe('function'); }); + it('should default to empty parameters', function(){ + xhr.expectGET('URL').respond({}); + resource.route('URL').query(); + }); + it("should build resource with default param", function(){ xhr.expectGET('/Order/123/Line/456.visa?minimum=0.05').respond({id:'abc'}); var LineItem = resource.route('/Order/:orderId/Line/:id:verb', {orderId: '123', id: '@id.key', verb:'.visa', minimum:0.05}); diff --git a/test/scenario/StepsTest.js b/test/scenario/StepsTest.js index 9d64d0a9..32ef637d 100644 --- a/test/scenario/StepsTest.js +++ b/test/scenario/StepsTest.js @@ -2,6 +2,6 @@ StepsTest = TestCase("StepsTest"); StepsTest.prototype.testGivenDataset=function(){ var self = {frame:{}, dataset:[]}; - angular.test.GIVEN.dataset.call(self); + angular.scenario.GIVEN.dataset.call(self); assertEquals('$DATASET:{"dataset":[]}', self.frame.name); }; -- cgit v1.2.3 From 7634a3ed5227f8bc2a2ba83752d0e2c78adb6051 Mon Sep 17 00:00:00 2001 From: Misko Hevery Date: Thu, 18 Mar 2010 12:20:06 -0700 Subject: initial revision of new plugable compiler --- test/CompilerSpec.js | 186 +++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 186 insertions(+) create mode 100644 test/CompilerSpec.js (limited to 'test') diff --git a/test/CompilerSpec.js b/test/CompilerSpec.js new file mode 100644 index 00000000..35e0e605 --- /dev/null +++ b/test/CompilerSpec.js @@ -0,0 +1,186 @@ +function Template() { + this.paths = []; + this.children = []; + this.inits = []; +} + +Template.prototype = { + init: function(element, scope) { + foreach(this.inits, function(fn) { + scope.apply(fn, element); + }); + + var i, + childNodes = element.childNodes, + children = this.children, + paths = this.paths, + length = paths.length; + for (i = 0; i < length; i++) { + children[i].init(childNodes[paths[i]], scope); + } + }, + + addInit:function(init) { + if (init) { + this.inits.push(init); + } + }, + + + addChild: function(index, template) { + this.paths.push(index); + this.children.push(template); + } +}; + +function Compiler(directives){ + this.directives = directives; +} + +DIRECTIVE = /^ng-(.*)$/; + +/** + * return { + * element: + * init: function(element){...} + * } + * + * internal data structure: { + * paths: [4, 5, 6], + * directive: name, + * init: function(expression, element){} + * } + * + * template : { + * inits: [fn(), fn()} + * paths: [1, 5], + * templates: [ + * inits: [] + * paths: [] + * templates: + * ] + * } + */ +Compiler.prototype = { + compile: function(element) { + var template = this.templetize(element); + return function(){ + var scope = new Scope(); + return { + scope: scope, + element:element, + init: bind(template, template.init, element, scope) + }; + }; + }, + + templetize: function(element){ + var items, item, length, i, directive, init, template, + childTemplate, recurse = true; + + // Process attributes/directives + for (i = 0, items = element.attributes, length = items.length; + i < length; i++) { + item = items[i]; + var match = item.name.match(DIRECTIVE); + if (match) { + directive = this.directives[match[1]]; + if (directive) { + init = directive.call({}, item.value, element); + template = template || new Template(); + template.addInit(init); + recurse = recurse && init; + } + } + } + + // Process children + if (recurse) { + for (i = 0, items = element.childNodes, length = items.length; + i < length; i++) { + if(childTemplate = this.templetize(items[i])) { + template = template || new Template(); + template.addChild(i, childTemplate); + } + } + } + return template; + } +}; + +describe('compiler', function(){ + function element(html) { + return jQuery(html)[0]; + } + + var compiler, directives, compile, log; + + beforeEach(function(){ + log = ""; + directives = { + hello: function(expression, element){ + log += "hello "; + return function() { + log += expression; + }; + }, + + watch: function(expression, element){ + return function() { + this.$watch(expression, function(val){ + log += ":" + val; + }); + }; + } + + }; + compiler = new Compiler(directives); + compile = function(html){ + var e = element(html); + var view = compiler.compile(e)(e); + view.init(); + return view.scope; + }; + }); + + it('should recognize a directive', function(){ + var e = element('
            '); + directives.directive = function(expression, element){ + log += "found"; + expect(expression).toEqual("expr"); + expect(element).toEqual(e); + return function initFn() { + log += ":init"; + }; + }; + var template = compiler.compile(e); + var init = template(e).init; + expect(log).toEqual("found"); + init(); + expect(log).toEqual("found:init"); + }); + + it('should recurse to children', function(){ + var scope = compile('
            '); + expect(log).toEqual("hello misko"); + }); + + it('should watch scope', function(){ + var scope = compile(''); + expect(log).toEqual(""); + scope.updateView(); + scope.set('name', 'misko'); + scope.updateView(); + scope.updateView(); + scope.set('name', 'adam'); + scope.updateView(); + scope.updateView(); + expect(log).toEqual(":misko:adam"); + }); + + it('should prevent recursion', function(){ + directives.stop = function(){ return false; }; + var scope = compile(''); + expect(log).toEqual("hello misko"); + }); +}); -- cgit v1.2.3 From df607da0d1b9726bce6584238fe3ad7e9b65a966 Mon Sep 17 00:00:00 2001 From: Misko Hevery Date: Thu, 18 Mar 2010 14:43:49 -0700 Subject: support for templates --- test/CompilerSpec.js | 95 ++++++++++++++++++++++++++++++++++++---------------- 1 file changed, 67 insertions(+), 28 deletions(-) (limited to 'test') diff --git a/test/CompilerSpec.js b/test/CompilerSpec.js index 35e0e605..4ffdf7f5 100644 --- a/test/CompilerSpec.js +++ b/test/CompilerSpec.js @@ -1,3 +1,9 @@ +/** + * Template provides directions an how to bind to a given element. + * It contains a list of init functions which need to be called to + * bind to a new instance of elements. It also provides a list + * of child paths which contain child templates + */ function Template() { this.paths = []; this.children = []; @@ -26,6 +32,11 @@ Template.prototype = { } }, + setExclusiveInit: function(init) { + this.inits = [init]; + this.addInit = noop; + }, + addChild: function(index, template) { this.paths.push(index); @@ -33,39 +44,22 @@ Template.prototype = { } }; +/////////////////////////////////// +// Compiler +////////////////////////////////// + function Compiler(directives){ this.directives = directives; } DIRECTIVE = /^ng-(.*)$/; -/** - * return { - * element: - * init: function(element){...} - * } - * - * internal data structure: { - * paths: [4, 5, 6], - * directive: name, - * init: function(expression, element){} - * } - * - * template : { - * inits: [fn(), fn()} - * paths: [1, 5], - * templates: [ - * inits: [] - * paths: [] - * templates: - * ] - * } - */ Compiler.prototype = { compile: function(element) { - var template = this.templetize(element); - return function(){ + var template = this.templetize(element) || new Template(); + return function(element){ var scope = new Scope(); + scope.element = element; return { scope: scope, element:element, @@ -79,17 +73,24 @@ Compiler.prototype = { childTemplate, recurse = true; // Process attributes/directives - for (i = 0, items = element.attributes, length = items.length; + for (i = 0, items = element.attributes || [], length = items.length; i < length; i++) { item = items[i]; var match = item.name.match(DIRECTIVE); if (match) { directive = this.directives[match[1]]; if (directive) { - init = directive.call({}, item.value, element); + init = directive.call(this, item.value, element); template = template || new Template(); - template.addInit(init); + if (directive.exclusive) { + template.setExclusiveInit(init); + i = length; // quit iterations + } else { + template.addInit(init); + } recurse = recurse && init; + } else { + error("Directive '" + match[0] + "' is not recognized."); } } } @@ -136,7 +137,7 @@ describe('compiler', function(){ }; compiler = new Compiler(directives); compile = function(html){ - var e = element(html); + var e = element("
            " + html + "
            "); var view = compiler.compile(e)(e); view.init(); return view.scope; @@ -183,4 +184,42 @@ describe('compiler', function(){ var scope = compile(''); expect(log).toEqual("hello misko"); }); + + it('should allow creation of templates', function(){ + directives.duplicate = function(expr, element){ + var template, + marker = document.createComment("marker"), + parentNode = element.parentNode; + parentNode.insertBefore(marker, element); + parentNode.removeChild(element); + element.removeAttribute("ng-duplicate"); + template = this.compile(element); + return function(marker) { + var parentNode = marker.parentNode; + this.$eval(function() { + parentNode.insertBefore( + template(element.cloneNode(true)).element, + marker.nextSibling); + }); + }; + }; + var scope = compile('beforexafter'); + expect($(scope.element).html()).toEqual('beforeafter'); + scope.updateView(); + expect($(scope.element).html()).toEqual('beforexafter'); + scope.updateView(); + expect($(scope.element).html()).toEqual('beforexxafter'); + }); + + it('should allow for exculsive tags which suppress others', function(){ + directives.exclusive = function(){ + return function() { + log += ('exclusive'); + }; + }; + directives.exclusive.exclusive = true; + + compile(''); + expect(log).toEqual('exclusive'); + }); }); -- cgit v1.2.3 From 509b0320899c019a60b8f397a0f1d3a8ea7dd032 Mon Sep 17 00:00:00 2001 From: Misko Hevery Date: Thu, 18 Mar 2010 15:50:14 -0700 Subject: markup now works --- test/CompilerSpec.js | 46 ++++++++++++++++++++++++++++++++++++---------- 1 file changed, 36 insertions(+), 10 deletions(-) (limited to 'test') diff --git a/test/CompilerSpec.js b/test/CompilerSpec.js index 4ffdf7f5..f428b04c 100644 --- a/test/CompilerSpec.js +++ b/test/CompilerSpec.js @@ -48,7 +48,8 @@ Template.prototype = { // Compiler ////////////////////////////////// -function Compiler(directives){ +function Compiler(markup, directives){ + this.markup = markup; this.directives = directives; } @@ -69,16 +70,26 @@ Compiler.prototype = { }, templetize: function(element){ - var items, item, length, i, directive, init, template, - childTemplate, recurse = true; + var chldrn, item, child, length, i, j, directive, init, template, + childTemplate, recurse = true, directives = this.directives, + markup = this.markup, markupLength = markup.length; + + for (i = 0, chldrn = element.childNodes, length = chldrn.length; + i < length; i++) { + if ((child = chldrn[i]).nodeType == Node.TEXT_NODE) { + for (j = 0; j < markupLength; j++) { + markup[j].call(this, child.nodeValue, child, element); + } + } + } // Process attributes/directives - for (i = 0, items = element.attributes || [], length = items.length; + for (i = 0, chldrn = element.attributes || [], length = chldrn.length; i < length; i++) { - item = items[i]; + item = chldrn[i]; var match = item.name.match(DIRECTIVE); if (match) { - directive = this.directives[match[1]]; + directive = directives[match[1]]; if (directive) { init = directive.call(this, item.value, element); template = template || new Template(); @@ -97,9 +108,10 @@ Compiler.prototype = { // Process children if (recurse) { - for (i = 0, items = element.childNodes, length = items.length; + for (i = 0, chldrn = element.childNodes, length = chldrn.length; i < length; i++) { - if(childTemplate = this.templetize(items[i])) { + if((child = chldrn[i]).nodeType != Node.TEXT_NODE && + (childTemplate = this.templetize(child))) { template = template || new Template(); template.addChild(i, childTemplate); } @@ -114,7 +126,7 @@ describe('compiler', function(){ return jQuery(html)[0]; } - var compiler, directives, compile, log; + var compiler, markup, directives, compile, log; beforeEach(function(){ log = ""; @@ -135,7 +147,8 @@ describe('compiler', function(){ } }; - compiler = new Compiler(directives); + markup = []; + compiler = new Compiler(markup, directives); compile = function(html){ var e = element("
            " + html + "
            "); var view = compiler.compile(e)(e); @@ -222,4 +235,17 @@ describe('compiler', function(){ compile(''); expect(log).toEqual('exclusive'); }); + + it('should process markup before directives', function(){ + markup.push(function(text, textNode, parentNode) { + if (text == 'middle') { + expect(textNode.nodeValue).toEqual(text); + parentNode.setAttribute('ng-hello', text); + textNode.nodeValue = 'replaced'; + } + }); + var scope = compile('beforemiddleafter'); + expect(scope.element.innerHTML).toEqual('beforereplacedafter'); + expect(log).toEqual("hello middle"); + }); }); -- cgit v1.2.3 From 79f868cbca4a14030447e321ba59348cf1eb8a02 Mon Sep 17 00:00:00 2001 From: Misko Hevery Date: Thu, 18 Mar 2010 16:20:02 -0700 Subject: cleanup work --- test/CompilerSpec.js | 123 --------------------------------------------------- 1 file changed, 123 deletions(-) (limited to 'test') diff --git a/test/CompilerSpec.js b/test/CompilerSpec.js index f428b04c..4033ebdc 100644 --- a/test/CompilerSpec.js +++ b/test/CompilerSpec.js @@ -1,126 +1,3 @@ -/** - * Template provides directions an how to bind to a given element. - * It contains a list of init functions which need to be called to - * bind to a new instance of elements. It also provides a list - * of child paths which contain child templates - */ -function Template() { - this.paths = []; - this.children = []; - this.inits = []; -} - -Template.prototype = { - init: function(element, scope) { - foreach(this.inits, function(fn) { - scope.apply(fn, element); - }); - - var i, - childNodes = element.childNodes, - children = this.children, - paths = this.paths, - length = paths.length; - for (i = 0; i < length; i++) { - children[i].init(childNodes[paths[i]], scope); - } - }, - - addInit:function(init) { - if (init) { - this.inits.push(init); - } - }, - - setExclusiveInit: function(init) { - this.inits = [init]; - this.addInit = noop; - }, - - - addChild: function(index, template) { - this.paths.push(index); - this.children.push(template); - } -}; - -/////////////////////////////////// -// Compiler -////////////////////////////////// - -function Compiler(markup, directives){ - this.markup = markup; - this.directives = directives; -} - -DIRECTIVE = /^ng-(.*)$/; - -Compiler.prototype = { - compile: function(element) { - var template = this.templetize(element) || new Template(); - return function(element){ - var scope = new Scope(); - scope.element = element; - return { - scope: scope, - element:element, - init: bind(template, template.init, element, scope) - }; - }; - }, - - templetize: function(element){ - var chldrn, item, child, length, i, j, directive, init, template, - childTemplate, recurse = true, directives = this.directives, - markup = this.markup, markupLength = markup.length; - - for (i = 0, chldrn = element.childNodes, length = chldrn.length; - i < length; i++) { - if ((child = chldrn[i]).nodeType == Node.TEXT_NODE) { - for (j = 0; j < markupLength; j++) { - markup[j].call(this, child.nodeValue, child, element); - } - } - } - - // Process attributes/directives - for (i = 0, chldrn = element.attributes || [], length = chldrn.length; - i < length; i++) { - item = chldrn[i]; - var match = item.name.match(DIRECTIVE); - if (match) { - directive = directives[match[1]]; - if (directive) { - init = directive.call(this, item.value, element); - template = template || new Template(); - if (directive.exclusive) { - template.setExclusiveInit(init); - i = length; // quit iterations - } else { - template.addInit(init); - } - recurse = recurse && init; - } else { - error("Directive '" + match[0] + "' is not recognized."); - } - } - } - - // Process children - if (recurse) { - for (i = 0, chldrn = element.childNodes, length = chldrn.length; - i < length; i++) { - if((child = chldrn[i]).nodeType != Node.TEXT_NODE && - (childTemplate = this.templetize(child))) { - template = template || new Template(); - template.addChild(i, childTemplate); - } - } - } - return template; - } -}; - describe('compiler', function(){ function element(html) { return jQuery(html)[0]; -- cgit v1.2.3 From be3c7a66709952ffd21e4e59268ba6370e09d7ed Mon Sep 17 00:00:00 2001 From: Misko Hevery Date: Thu, 18 Mar 2010 17:12:38 -0700 Subject: cleanup work --- test/CompilerSpec.js | 30 ++++++++++++++++++++---------- 1 file changed, 20 insertions(+), 10 deletions(-) (limited to 'test') diff --git a/test/CompilerSpec.js b/test/CompilerSpec.js index 4033ebdc..2c156cc4 100644 --- a/test/CompilerSpec.js +++ b/test/CompilerSpec.js @@ -3,7 +3,7 @@ describe('compiler', function(){ return jQuery(html)[0]; } - var compiler, markup, directives, compile, log; + var compiler, markup, directives, widgets, compile, log; beforeEach(function(){ log = ""; @@ -25,7 +25,8 @@ describe('compiler', function(){ }; markup = []; - compiler = new Compiler(markup, directives); + widgets = {}; + compiler = new Compiler(markup, directives, widgets); compile = function(html){ var e = element("
            " + html + "
            "); var view = compiler.compile(e)(e); @@ -39,7 +40,7 @@ describe('compiler', function(){ directives.directive = function(expression, element){ log += "found"; expect(expression).toEqual("expr"); - expect(element).toEqual(e); + expect(element.element).toEqual(e); return function initFn() { log += ":init"; }; @@ -78,17 +79,15 @@ describe('compiler', function(){ it('should allow creation of templates', function(){ directives.duplicate = function(expr, element){ var template, - marker = document.createComment("marker"), - parentNode = element.parentNode; - parentNode.insertBefore(marker, element); - parentNode.removeChild(element); + marker = document.createComment("marker"); + element.replaceWith(marker); element.removeAttribute("ng-duplicate"); template = this.compile(element); return function(marker) { var parentNode = marker.parentNode; this.$eval(function() { parentNode.insertBefore( - template(element.cloneNode(true)).element, + template(element.clone()).element, marker.nextSibling); }); }; @@ -116,8 +115,8 @@ describe('compiler', function(){ it('should process markup before directives', function(){ markup.push(function(text, textNode, parentNode) { if (text == 'middle') { - expect(textNode.nodeValue).toEqual(text); - parentNode.setAttribute('ng-hello', text); + expect(textNode.text()).toEqual(text); + parentNode.attr('ng-hello', text); textNode.nodeValue = 'replaced'; } }); @@ -125,4 +124,15 @@ describe('compiler', function(){ expect(scope.element.innerHTML).toEqual('beforereplacedafter'); expect(log).toEqual("hello middle"); }); + + it('should replace widgets', function(){ + widgets.button = function(element) { + element.parentNode.replaceChild(button, element); + return function(element) { + log += 'init'; + }; + }; + var scope = compile('push me'); + expect(scope.element.innerHTML).toEqual('beforereplacedafter'); + }); }); -- cgit v1.2.3 From c3eac13aa7106d099e8f09c39518051ccf939060 Mon Sep 17 00:00:00 2001 From: Misko Hevery Date: Fri, 19 Mar 2010 16:41:02 -0700 Subject: showing off problem to corry --- test/CompilerSpec.js | 14 ++++++-------- 1 file changed, 6 insertions(+), 8 deletions(-) (limited to 'test') diff --git a/test/CompilerSpec.js b/test/CompilerSpec.js index 2c156cc4..7bf48d18 100644 --- a/test/CompilerSpec.js +++ b/test/CompilerSpec.js @@ -78,17 +78,14 @@ describe('compiler', function(){ it('should allow creation of templates', function(){ directives.duplicate = function(expr, element){ - var template, - marker = document.createComment("marker"); - element.replaceWith(marker); + element.replaceWith(document.createComment("marker")); element.removeAttribute("ng-duplicate"); - template = this.compile(element); + var template = this.compile(element); return function(marker) { - var parentNode = marker.parentNode; this.$eval(function() { - parentNode.insertBefore( - template(element.clone()).element, - marker.nextSibling); + dump("A"); + marker.after(template(element.clone()).element); + dump("B"); }); }; }; @@ -135,4 +132,5 @@ describe('compiler', function(){ var scope = compile('push me'); expect(scope.element.innerHTML).toEqual('beforereplacedafter'); }); + }); -- cgit v1.2.3 From f6664ed7f6f6dd1f4f9756f57611a316089149cb Mon Sep 17 00:00:00 2001 From: Misko Hevery Date: Fri, 19 Mar 2010 22:18:39 -0700 Subject: tests fixed, still missing widgets --- test/CompilerSpec.js | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) (limited to 'test') diff --git a/test/CompilerSpec.js b/test/CompilerSpec.js index 7bf48d18..9f02262d 100644 --- a/test/CompilerSpec.js +++ b/test/CompilerSpec.js @@ -83,9 +83,7 @@ describe('compiler', function(){ var template = this.compile(element); return function(marker) { this.$eval(function() { - dump("A"); marker.after(template(element.clone()).element); - dump("B"); }); }; }; @@ -114,7 +112,7 @@ describe('compiler', function(){ if (text == 'middle') { expect(textNode.text()).toEqual(text); parentNode.attr('ng-hello', text); - textNode.nodeValue = 'replaced'; + textNode.text('replaced'); } }); var scope = compile('beforemiddleafter'); @@ -122,7 +120,7 @@ describe('compiler', function(){ expect(log).toEqual("hello middle"); }); - it('should replace widgets', function(){ + xit('should replace widgets', function(){ widgets.button = function(element) { element.parentNode.replaceChild(button, element); return function(element) { -- cgit v1.2.3 From 84552f7f8ac3f39c4dbd7d946ae2938d63302840 Mon Sep 17 00:00:00 2001 From: Misko Hevery Date: Mon, 22 Mar 2010 13:58:04 -0700 Subject: got few directives working --- test/CompilerSpec.js | 33 +++++++++++------------ test/ParserTest.js | 19 +++++++++----- test/directivesSpec.js | 71 ++++++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 100 insertions(+), 23 deletions(-) create mode 100644 test/directivesSpec.js (limited to 'test') diff --git a/test/CompilerSpec.js b/test/CompilerSpec.js index 9f02262d..3ea2e473 100644 --- a/test/CompilerSpec.js +++ b/test/CompilerSpec.js @@ -36,7 +36,7 @@ describe('compiler', function(){ }); it('should recognize a directive', function(){ - var e = element('
            '); + var e = element('
            '); directives.directive = function(expression, element){ log += "found"; expect(expression).toEqual("expr"); @@ -53,12 +53,12 @@ describe('compiler', function(){ }); it('should recurse to children', function(){ - var scope = compile('
            '); + var scope = compile('
            '); expect(log).toEqual("hello misko"); }); it('should watch scope', function(){ - var scope = compile(''); + var scope = compile(''); expect(log).toEqual(""); scope.updateView(); scope.set('name', 'misko'); @@ -70,24 +70,24 @@ describe('compiler', function(){ expect(log).toEqual(":misko:adam"); }); - it('should prevent recursion', function(){ - directives.stop = function(){ return false; }; - var scope = compile(''); + it('should prevent descend', function(){ + directives.stop = function(){ this.descend(false); }; + var scope = compile(''); expect(log).toEqual("hello misko"); }); it('should allow creation of templates', function(){ directives.duplicate = function(expr, element){ element.replaceWith(document.createComment("marker")); - element.removeAttribute("ng-duplicate"); + element.removeAttr("duplicate"); var template = this.compile(element); return function(marker) { - this.$eval(function() { + this.$addEval(function() { marker.after(template(element.clone()).element); }); }; }; - var scope = compile('beforexafter'); + var scope = compile('beforexafter'); expect($(scope.element).html()).toEqual('beforeafter'); scope.updateView(); expect($(scope.element).html()).toEqual('beforexafter'); @@ -103,7 +103,7 @@ describe('compiler', function(){ }; directives.exclusive.exclusive = true; - compile(''); + compile(''); expect(log).toEqual('exclusive'); }); @@ -111,24 +111,25 @@ describe('compiler', function(){ markup.push(function(text, textNode, parentNode) { if (text == 'middle') { expect(textNode.text()).toEqual(text); - parentNode.attr('ng-hello', text); + parentNode.attr('hello', text); textNode.text('replaced'); } }); var scope = compile('beforemiddleafter'); - expect(scope.element.innerHTML).toEqual('beforereplacedafter'); + expect(scope.element.innerHTML).toEqual('beforereplacedafter'); expect(log).toEqual("hello middle"); }); - xit('should replace widgets', function(){ - widgets.button = function(element) { - element.parentNode.replaceChild(button, element); + it('should replace widgets', function(){ + widgets['NG:BUTTON'] = function(element) { + element.replaceWith('
            button
            ', element); return function(element) { log += 'init'; }; }; var scope = compile('push me'); - expect(scope.element.innerHTML).toEqual('beforereplacedafter'); + expect(scope.element.innerHTML).toEqual('
            button
            '); + expect(log).toEqual('init'); }); }); diff --git a/test/ParserTest.js b/test/ParserTest.js index 09c3b8de..53ca9eda 100644 --- a/test/ParserTest.js +++ b/test/ParserTest.js @@ -41,7 +41,7 @@ LexerTest.prototype.testTokenizeAString = function(){ i++; assertEquals(tokens[i].index, 15); - assertEquals(tokens[i].text, "a'c"); + assertEquals(tokens[i].string, "a'c"); i++; assertEquals(tokens[i].index, 21); @@ -49,7 +49,7 @@ LexerTest.prototype.testTokenizeAString = function(){ i++; assertEquals(tokens[i].index, 22); - assertEquals(tokens[i].text, 'd"e'); + assertEquals(tokens[i].string, 'd"e'); }; @@ -68,10 +68,10 @@ LexerTest.prototype.testQuotedString = function(){ var tokens = lexer.parse(); assertEquals(1, tokens[1].index); - assertEquals("'", tokens[1].text); + assertEquals("'", tokens[1].string); assertEquals(7, tokens[3].index); - assertEquals('"', tokens[3].text); + assertEquals('"', tokens[3].string); }; @@ -80,14 +80,14 @@ LexerTest.prototype.testQuotedStringEscape = function(){ var lexer = new Lexer(str); var tokens = lexer.parse(); - assertEquals('"\n\f\r\t\v\u00A0', tokens[0].text); + assertEquals('"\n\f\r\t\v\u00A0', tokens[0].string); }; LexerTest.prototype.testTokenizeUnicode = function(){ var lexer = new Lexer('"\\u00A0"'); var tokens = lexer.parse(); assertEquals(1, tokens.length); - assertEquals('\u00a0', tokens[0].text); + assertEquals('\u00a0', tokens[0].string); }; LexerTest.prototype.testTokenizeRegExpWithOptions = function(){ @@ -408,7 +408,7 @@ ParserTest.prototype.testItShouldParseOnChangeIntoHashSet = function () { ParserTest.prototype.testItShouldParseOnChangeBlockIntoHashSet = function () { var scope = new Scope({count:0}); var listeners = {a:[], b:[]}; - scope.watch("a:{count=count+1;count=count+20;};b:count=count+300", + scope.watch("a:{count=count+1;count=count+20;};b:count=count+300", function(n, fn){listeners[n].push(fn);}); assertEquals(1, scope.watchListeners.a.listeners.length); @@ -477,3 +477,8 @@ ParserTest.prototype.testNegationBug = function () { assertEquals(12/6/2, scope.eval("12/6/2")); }; +ParserTest.prototype.testBugStringConfusesParser = function() { + var scope = new Scope(); + assertEquals('!', scope.eval('suffix = "!"')); +}; + diff --git a/test/directivesSpec.js b/test/directivesSpec.js new file mode 100644 index 00000000..176f9e70 --- /dev/null +++ b/test/directivesSpec.js @@ -0,0 +1,71 @@ +describe("directives", function(){ + + var compile, element; + + beforeEach(function() { + var compiler = new Compiler(angularMarkup, angularDirective, angularWidget); + compile = function(html) { + element = jqLite(html); + var view = compiler.compile(element.element)(element.element); + view.init(); + return view.scope; + }; + }); + + it("should ng-init", function() { + var scope = compile('
            '); + expect(scope.get('a')).toEqual(123); + }); + + it("should ng-eval", function() { + var scope = compile('
            '); + expect(scope.get('a')).toEqual(0); + scope.updateView(); + expect(scope.get('a')).toEqual(1); + scope.updateView(); + expect(scope.get('a')).toEqual(2); + }); + + it('should ng-bind', function() { + var scope = compile('
            '); + expect(element.text()).toEqual(''); + scope.set('a', 'misko'); + scope.updateView(); + expect(element.text()).toEqual('misko'); + }); + + it('should ng-bind-attr', function(){ + var scope = compile(''); + expect(element.attr('src')).toEqual(null); + expect(element.attr('alt')).toEqual(null); + scope.updateView(); + expect(element.attr('src')).toEqual('mysrc'); + expect(element.attr('alt')).toEqual('myalt'); + }); + + it('should ng-non-bindable', function(){ + var scope = compile('
            '); + scope.set('name', 'misko'); + scope.updateView(); + expect(element.text()).toEqual(''); + }); + + it('should ng-repeat over array', function(){ + var scope = compile('
            '); + + scope.set('items', ['misko', 'shyam']); + scope.updateView(); + expect(element.text()).toEqual('misko;shyam;'); + + scope.set('items', ['adam', 'kai', 'brad']); + scope.updateView(); + expect(element.text()).toEqual('adam;kai;brad;'); + + scope.set('items', ['brad']); + scope.updateView(); + expect(element.text()).toEqual('brad;'); + }); + + it('should ng-repeat over object', function(){}); + it('should error on wrong parsing of ng-repeat', function(){}); +}); -- cgit v1.2.3 From b4561ff951ff452e55e820f6f8344dc2668cfd90 Mon Sep 17 00:00:00 2001 From: Misko Hevery Date: Mon, 22 Mar 2010 15:46:34 -0700 Subject: ng-repeat works --- test/directivesSpec.js | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-) (limited to 'test') diff --git a/test/directivesSpec.js b/test/directivesSpec.js index 176f9e70..2cee20d1 100644 --- a/test/directivesSpec.js +++ b/test/directivesSpec.js @@ -66,6 +66,20 @@ describe("directives", function(){ expect(element.text()).toEqual('brad;'); }); - it('should ng-repeat over object', function(){}); - it('should error on wrong parsing of ng-repeat', function(){}); + it('should ng-repeat over object', function(){ + var scope = compile('
            '); + scope.set('items', {misko:'swe', shyam:'set'}); + scope.updateView(); + expect(element.text()).toEqual('misko:swe;shyam:set;'); + }); + + it('should error on wrong parsing of ng-repeat', function(){ + var scope = compile('
            '); + var log = ""; + element.eachNode(function(li){ + log += li.attr('ng-error') + ';'; + log += li.hasClass('ng-exception') + ';'; + }); + expect(log).toEqual("\"Expected ng-repeat in form of 'item in collection' but got 'i dont parse'.\";true;"); + }); }); -- cgit v1.2.3 From 6f8276a8e3735396999bd158005ca86bb1bb0978 Mon Sep 17 00:00:00 2001 From: Misko Hevery Date: Mon, 22 Mar 2010 16:07:42 -0700 Subject: ng-watch directive --- test/directivesSpec.js | 12 ++++++++++++ 1 file changed, 12 insertions(+) (limited to 'test') diff --git a/test/directivesSpec.js b/test/directivesSpec.js index 2cee20d1..e0e53eeb 100644 --- a/test/directivesSpec.js +++ b/test/directivesSpec.js @@ -82,4 +82,16 @@ describe("directives", function(){ }); expect(log).toEqual("\"Expected ng-repeat in form of 'item in collection' but got 'i dont parse'.\";true;"); }); + + it('should ng-watch', function(){ + var scope = compile('
            '); + scope.updateView(); + scope.updateView(); + expect(scope.get('count')).toEqual(0); + + scope.set('i', 0); + scope.updateView(); + scope.updateView(); + expect(scope.get('count')).toEqual(1); + }); }); -- cgit v1.2.3 From 7c87c17d08dbba318af1a149c0bbedb696b03458 Mon Sep 17 00:00:00 2001 From: Misko Hevery Date: Mon, 22 Mar 2010 18:20:49 -0700 Subject: upgraded jquery to 1.4.2 and made ng-action work with jquery --- test/BinderTest.js | 1 - test/directivesSpec.js | 9 +++++++++ 2 files changed, 9 insertions(+), 1 deletion(-) (limited to 'test') diff --git a/test/BinderTest.js b/test/BinderTest.js index 9ddf38ab..e37026e7 100644 --- a/test/BinderTest.js +++ b/test/BinderTest.js @@ -703,7 +703,6 @@ BinderTest.prototype.testActionOnAHrefThrowsError = function(){ var input = state.node.find('a'); input.click(); assertEquals('abc', fromJson(input.attr('ng-error')).a); - assertNotNull(input.data('qtip')); assertTrue("should have an error class", input.hasClass('ng-exception')); input.attr('ng-action', '0'); diff --git a/test/directivesSpec.js b/test/directivesSpec.js index e0e53eeb..447698a3 100644 --- a/test/directivesSpec.js +++ b/test/directivesSpec.js @@ -94,4 +94,13 @@ describe("directives", function(){ scope.updateView(); expect(scope.get('count')).toEqual(1); }); + + it('should ng-action', function(){ + var scope = compile('
            '); + scope.updateView(); + expect(scope.get('clicked')).toBeFalsy(); + + jQuery(element.element).click(); + expect(scope.get('clicked')).toEqual(true); + }); }); -- cgit v1.2.3 From a8227086748e37c31c1bb71dec50c96d63c45eef Mon Sep 17 00:00:00 2001 From: Misko Hevery Date: Mon, 22 Mar 2010 20:20:05 -0700 Subject: rudementary event bind and trigger for jqlite --- test/directivesSpec.js | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) (limited to 'test') diff --git a/test/directivesSpec.js b/test/directivesSpec.js index 447698a3..7e0446ef 100644 --- a/test/directivesSpec.js +++ b/test/directivesSpec.js @@ -12,6 +12,11 @@ describe("directives", function(){ }; }); + afterEach(function(){ + element.remove(); + expect(_(jqCache).size()).toEqual(0); + }); + it("should ng-init", function() { var scope = compile('
            '); expect(scope.get('a')).toEqual(123); @@ -100,7 +105,7 @@ describe("directives", function(){ scope.updateView(); expect(scope.get('clicked')).toBeFalsy(); - jQuery(element.element).click(); + element.click(); expect(scope.get('clicked')).toEqual(true); }); }); -- cgit v1.2.3 From 6ff550cfa9524bbb124d10caf1fc13c911ab3b4b Mon Sep 17 00:00:00 2001 From: Misko Hevery Date: Mon, 22 Mar 2010 21:29:57 -0700 Subject: all angular.js directives now work --- test/CompilerSpec.js | 2 +- test/directivesSpec.js | 45 ++++++++++++++++++++++++++++++++++++++++++++- 2 files changed, 45 insertions(+), 2 deletions(-) (limited to 'test') diff --git a/test/CompilerSpec.js b/test/CompilerSpec.js index 3ea2e473..57b597c4 100644 --- a/test/CompilerSpec.js +++ b/test/CompilerSpec.js @@ -40,7 +40,7 @@ describe('compiler', function(){ directives.directive = function(expression, element){ log += "found"; expect(expression).toEqual("expr"); - expect(element.element).toEqual(e); + expect(element[0]).toEqual(e); return function initFn() { log += ":init"; }; diff --git a/test/directivesSpec.js b/test/directivesSpec.js index 7e0446ef..d125d326 100644 --- a/test/directivesSpec.js +++ b/test/directivesSpec.js @@ -6,7 +6,7 @@ describe("directives", function(){ var compiler = new Compiler(angularMarkup, angularDirective, angularWidget); compile = function(html) { element = jqLite(html); - var view = compiler.compile(element.element)(element.element); + var view = compiler.compile(element)(element); view.init(); return view.scope; }; @@ -108,4 +108,47 @@ describe("directives", function(){ element.click(); expect(scope.get('clicked')).toEqual(true); }); + + it('should ng-class', function(){ + var scope = compile('
            '); + scope.updateView(); + expect(element.hasClass('existing')).toBeTruthy(); + expect(element.hasClass('A')).toBeTruthy(); + expect(element.hasClass('B')).toBeTruthy(); + }); + + it('should ng-class odd/even', function(){ + var scope = compile('
              • '); + scope.updateView(); + var e1 = jQuery(element.parent()[0]).find('li:first'); + var e2 = jQuery(element.parent()[0]).find('li:last'); + expect(e1.hasClass('existing')).toBeTruthy(); + expect(e1.hasClass('even')).toBeTruthy(); + expect(e2.hasClass('existing')).toBeTruthy(); + expect(e2.hasClass('odd')).toBeTruthy(); + }); + + it('should ng-style', function(){ + var scope = compile('
                '); + scope.updateView(); + expect(element.css('color')).toEqual('red'); + }); + + it('should ng-show', function(){ + var scope = compile('
                '); + scope.updateView(); + expect(element.css('display')).toEqual(''); + scope.set('hide', true); + scope.updateView(); + expect(element.css('display')).toEqual('none'); + }); + + it('should ng-hide', function(){ + var scope = compile('
                '); + scope.updateView(); + expect(element.css('display')).toEqual('none'); + scope.set('show', true); + scope.updateView(); + expect(element.css('display')).toEqual(''); + }); }); -- cgit v1.2.3 From bb98ae14f2aef74efbd8345e93f62ac67f460f7f Mon Sep 17 00:00:00 2001 From: Misko Hevery Date: Tue, 23 Mar 2010 14:57:11 -0700 Subject: markup now wroks, some refactorings --- test/CompilerSpec.js | 9 +++++---- test/directivesSpec.js | 12 ++++++++++-- test/markupSpec.js | 49 +++++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 64 insertions(+), 6 deletions(-) create mode 100644 test/markupSpec.js (limited to 'test') diff --git a/test/CompilerSpec.js b/test/CompilerSpec.js index 57b597c4..a49a2551 100644 --- a/test/CompilerSpec.js +++ b/test/CompilerSpec.js @@ -3,7 +3,7 @@ describe('compiler', function(){ return jQuery(html)[0]; } - var compiler, markup, directives, widgets, compile, log; + var compiler, textMarkup, directives, widgets, compile, log; beforeEach(function(){ log = ""; @@ -24,9 +24,10 @@ describe('compiler', function(){ } }; - markup = []; + textMarkup = []; + attrMarkup = []; widgets = {}; - compiler = new Compiler(markup, directives, widgets); + compiler = new Compiler(textMarkup, attrMarkup, directives, widgets); compile = function(html){ var e = element("
                " + html + "
                "); var view = compiler.compile(e)(e); @@ -108,7 +109,7 @@ describe('compiler', function(){ }); it('should process markup before directives', function(){ - markup.push(function(text, textNode, parentNode) { + textMarkup.push(function(text, textNode, parentNode) { if (text == 'middle') { expect(textNode.text()).toEqual(text); parentNode.attr('hello', text); diff --git a/test/directivesSpec.js b/test/directivesSpec.js index d125d326..18bedb64 100644 --- a/test/directivesSpec.js +++ b/test/directivesSpec.js @@ -3,7 +3,7 @@ describe("directives", function(){ var compile, element; beforeEach(function() { - var compiler = new Compiler(angularMarkup, angularDirective, angularWidget); + var compiler = new Compiler(angularTextMarkup, angularAttrMarkup, angularDirective, angularWidget); compile = function(html) { element = jqLite(html); var view = compiler.compile(element)(element); @@ -39,6 +39,14 @@ describe("directives", function(){ expect(element.text()).toEqual('misko'); }); + it('should ng-bind-template', function() { + var scope = compile('
                '); + expect(element.text()).toEqual(''); + scope.set('name', 'Misko'); + scope.updateView(); + expect(element.text()).toEqual('Hello Misko!'); + }); + it('should ng-bind-attr', function(){ var scope = compile(''); expect(element.attr('src')).toEqual(null); @@ -81,7 +89,7 @@ describe("directives", function(){ it('should error on wrong parsing of ng-repeat', function(){ var scope = compile('
                '); var log = ""; - element.eachNode(function(li){ + eachNode(element, function(li){ log += li.attr('ng-error') + ';'; log += li.hasClass('ng-exception') + ';'; }); diff --git a/test/markupSpec.js b/test/markupSpec.js new file mode 100644 index 00000000..9e89af7b --- /dev/null +++ b/test/markupSpec.js @@ -0,0 +1,49 @@ +describe("markups", function(){ + + var compile, element, scope; + + beforeEach(function() { + scope = null; + element = null; + var compiler = new Compiler(angularTextMarkup, angularAttrMarkup, angularDirective, angularWidget); + compile = function(html) { + element = jqLite(html); + var view = compiler.compile(element)(element); + view.init(); + scope = view.scope; + }; + }); + + afterEach(function(){ + if (element) { + element.remove(); + } + expect(_(jqCache).size()).toEqual(0); + }); + + it('should translate {{}} in text', function(){ + compile('
                hello {{name}}!
                '); + expect(element.html()).toEqual('hello !'); + scope.set('name', 'Misko'); + scope.updateView(); + expect(element.html()).toEqual('hello Misko!'); + }); + + it('should translate {{}} in terminal nodes', function(){ + compile(''); + expect(element.html()).toEqual(''); + scope.set('name', 'Misko'); + scope.updateView(); + expect(element.html()).toEqual(''); + }); + + it('should translate {{}} in attributes', function(){ + compile(''); + expect(element.attr('src')).toEqual(); + expect(element.attr('ng-bind-attr')).toEqual('{"src":"http://server/{{path}}.png"}'); + scope.set('path', 'a/b'); + scope.updateView(); + expect(element.attr('src')).toEqual("http://server/a/b.png"); + }); + +}); -- cgit v1.2.3 From 03ddc4570b786a7b945e1b40a16f29d2349c68b8 Mon Sep 17 00:00:00 2001 From: Shyam Seshadri Date: Wed, 24 Mar 2010 10:35:01 -0700 Subject: Fix parsing bug with strings for - --- test/CompilerSpec.js | 2 +- test/ParserTest.js | 23 ++++++++++++++++------- 2 files changed, 17 insertions(+), 8 deletions(-) (limited to 'test') diff --git a/test/CompilerSpec.js b/test/CompilerSpec.js index 7bf48d18..8487b139 100644 --- a/test/CompilerSpec.js +++ b/test/CompilerSpec.js @@ -1,4 +1,4 @@ -describe('compiler', function(){ +xdescribe('compiler', function(){ function element(html) { return jQuery(html)[0]; } diff --git a/test/ParserTest.js b/test/ParserTest.js index 09c3b8de..c8d323f2 100644 --- a/test/ParserTest.js +++ b/test/ParserTest.js @@ -41,7 +41,7 @@ LexerTest.prototype.testTokenizeAString = function(){ i++; assertEquals(tokens[i].index, 15); - assertEquals(tokens[i].text, "a'c"); + assertEquals(tokens[i].string, "a'c"); i++; assertEquals(tokens[i].index, 21); @@ -49,7 +49,7 @@ LexerTest.prototype.testTokenizeAString = function(){ i++; assertEquals(tokens[i].index, 22); - assertEquals(tokens[i].text, 'd"e'); + assertEquals(tokens[i].string, 'd"e'); }; @@ -68,10 +68,10 @@ LexerTest.prototype.testQuotedString = function(){ var tokens = lexer.parse(); assertEquals(1, tokens[1].index); - assertEquals("'", tokens[1].text); + assertEquals("'", tokens[1].string); assertEquals(7, tokens[3].index); - assertEquals('"', tokens[3].text); + assertEquals('"', tokens[3].string); }; @@ -80,14 +80,14 @@ LexerTest.prototype.testQuotedStringEscape = function(){ var lexer = new Lexer(str); var tokens = lexer.parse(); - assertEquals('"\n\f\r\t\v\u00A0', tokens[0].text); + assertEquals('"\n\f\r\t\v\u00A0', tokens[0].string); }; LexerTest.prototype.testTokenizeUnicode = function(){ var lexer = new Lexer('"\\u00A0"'); var tokens = lexer.parse(); assertEquals(1, tokens.length); - assertEquals('\u00a0', tokens[0].text); + assertEquals('\u00a0', tokens[0].string); }; LexerTest.prototype.testTokenizeRegExpWithOptions = function(){ @@ -408,7 +408,7 @@ ParserTest.prototype.testItShouldParseOnChangeIntoHashSet = function () { ParserTest.prototype.testItShouldParseOnChangeBlockIntoHashSet = function () { var scope = new Scope({count:0}); var listeners = {a:[], b:[]}; - scope.watch("a:{count=count+1;count=count+20;};b:count=count+300", + scope.watch("a:{count=count+1;count=count+20;};b:count=count+300", function(n, fn){listeners[n].push(fn);}); assertEquals(1, scope.watchListeners.a.listeners.length); @@ -477,3 +477,12 @@ ParserTest.prototype.testNegationBug = function () { assertEquals(12/6/2, scope.eval("12/6/2")); }; +ParserTest.prototype.testBugStringConfusesParser = function() { + var scope = new Scope(); + assertEquals('!', scope.eval('suffix = "!"')); +}; + +ParserTest.prototype.testParsingBug = function () { + var scope = new Scope(); + assertEquals({a: "-"}, scope.eval("{a:'-'}")); +}; -- cgit v1.2.3 From 0c42eb9909d554807549cd3394e0ea0c715cc2d1 Mon Sep 17 00:00:00 2001 From: Misko Hevery Date: Wed, 24 Mar 2010 16:13:42 -0700 Subject: input[type=text] now works with binding, validation, formatter, required --- test/ValidatorsTest.js | 34 ++++++++++++------------- test/widgetsSpec.js | 68 +++++++++++++++++++++++++++++++++++++++++++++----- 2 files changed, 79 insertions(+), 23 deletions(-) (limited to 'test') diff --git a/test/ValidatorsTest.js b/test/ValidatorsTest.js index 5449ebb0..6b61c273 100644 --- a/test/ValidatorsTest.js +++ b/test/ValidatorsTest.js @@ -26,7 +26,7 @@ ValidatorTest.prototype.testRegexp = function() { }; ValidatorTest.prototype.testNumber = function() { - assertEquals(angular.validator.number("ab"), "Value is not a number."); + assertEquals(angular.validator.number("ab"), "Not a number"); assertEquals(angular.validator.number("-0.1",0), "Value can not be less than 0."); assertEquals(angular.validator.number("10.1",0,10), "Value can not be greater than 10."); assertEquals(angular.validator.number("1.2"), null); @@ -34,10 +34,10 @@ ValidatorTest.prototype.testNumber = function() { }; ValidatorTest.prototype.testInteger = function() { - assertEquals(angular.validator.integer("ab"), "Value is not a number."); - assertEquals(angular.validator.integer("1.1"), "Value is not a whole number."); - assertEquals(angular.validator.integer("1.0"), "Value is not a whole number."); - assertEquals(angular.validator.integer("1."), "Value is not a whole number."); + assertEquals(angular.validator.integer("ab"), "Not a number"); + assertEquals(angular.validator.integer("1.1"), "Not a whole number"); + assertEquals(angular.validator.integer("1.0"), "Not a whole number"); + assertEquals(angular.validator.integer("1."), "Not a whole number"); assertEquals(angular.validator.integer("-1",0), "Value can not be less than 0."); assertEquals(angular.validator.integer("11",0,10), "Value can not be greater than 10."); assertEquals(angular.validator.integer("1"), null); @@ -86,7 +86,7 @@ describe('Validator:asynchronous', function(){ var asynchronous = angular.validator.asynchronous; var self; var value, fn; - + beforeEach(function(){ value = null; fn = null; @@ -96,10 +96,10 @@ describe('Validator:asynchronous', function(){ $updateView: noop }; }); - + it('should make a request and show spinner', function(){ - var x = compile('') - var asyncFn = function(v,f){value=v; fn=f}; + var x = compile(''); + var asyncFn = function(v,f){value=v; fn=f;}; var input = x.node.find(":input"); x.scope.set("asyncFn", asyncFn); x.scope.set("name", "misko"); @@ -110,29 +110,29 @@ describe('Validator:asynchronous', function(){ expect(input.hasClass('ng-input-indicator-wait')).toBeFalsy(); expect(input.attr('ng-error')).toEqual("myError"); }); - + 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).toEqual([self.$element]); - + var spy = jasmine.createSpy(); asynchronous.call(self, "kai", spy); expect(spy).wasNotCalled(); - + asynchronous.call(self, "misko", spy); - expect(spy).wasCalled(); + expect(spy).wasCalled(); }); - + it("should ignore old callbacks, and not remove spinner", function(){ var firstCb, secondCb; asynchronous.call(self, "first", function(v,f){value=v; firstCb=f;}); asynchronous.call(self, "second", function(v,f){value=v; secondCb=f;}); - + firstCb(); expect($(self.$element).hasClass('ng-input-indicator-wait')).toBeTruthy(); - + secondCb(); expect($(self.$element).hasClass('ng-input-indicator-wait')).toBeFalsy(); }); -}); \ No newline at end of file +}); diff --git a/test/widgetsSpec.js b/test/widgetsSpec.js index 3b6be8ec..da9d5f9b 100644 --- a/test/widgetsSpec.js +++ b/test/widgetsSpec.js @@ -1,4 +1,4 @@ -describe("widgets", function(){ +describe("input widget", function(){ var compile, element, scope; @@ -15,14 +15,70 @@ describe("widgets", function(){ }); afterEach(function(){ - if (element) { - element.remove(); - } + if (element) element.remove(); expect(_(jqCache).size()).toEqual(0); }); - it('should fail', function(){ - fail('iueoi'); + it('should input-text auto init and handle keyup/change events', function(){ + compile(''); + expect(scope.get('name')).toEqual("Misko"); + + scope.set('name', 'Adam'); + scope.updateView(); + expect(element.attr('value')).toEqual("Adam"); + + element.attr('value', 'Shyam'); + element.trigger('keyup'); + expect(scope.get('name')).toEqual('Shyam'); + + element.attr('value', 'Kai'); + element.trigger('change'); + expect(scope.get('name')).toEqual('Kai'); + }); + + it("should process ng-format", function(){ + compile(''); + expect(scope.get('list')).toEqual(['a', 'b', 'c']); + + scope.set('list', ['x', 'y', 'z']); + scope.updateView(); + expect(element.attr('value')).toEqual("x, y, z"); + + element.attr('value', '1, 2, 3'); + element.trigger('keyup'); + expect(scope.get('list')).toEqual(['1', '2', '3']); + }); + + it("should process ng-validation", function(){ + compile(''); + expect(element.hasClass('ng-validation-error')).toBeTruthy(); + expect(element.attr('ng-error')).toEqual('Not a number'); + + scope.set('price', '123'); + scope.updateView(); + expect(element.hasClass('ng-validation-error')).toBeFalsy(); + expect(element.attr('ng-error')).toBeFalsy(); + + element.attr('value', 'x'); + element.trigger('keyup'); + expect(element.hasClass('ng-validation-error')).toBeTruthy(); + expect(element.attr('ng-error')).toEqual('Not a number'); + }); + + it("should process ng-required", function(){ + compile(''); + expect(element.hasClass('ng-validation-error')).toBeTruthy(); + expect(element.attr('ng-error')).toEqual('Required'); + + scope.set('price', 'xxx'); + scope.updateView(); + expect(element.hasClass('ng-validation-error')).toBeFalsy(); + expect(element.attr('ng-error')).toBeFalsy(); + + element.attr('value', ''); + element.trigger('keyup'); + expect(element.hasClass('ng-validation-error')).toBeTruthy(); + expect(element.attr('ng-error')).toEqual('Required'); }); }); -- cgit v1.2.3 From f29f6a47c4d81c5b8e365a3dae307159f1b12968 Mon Sep 17 00:00:00 2001 From: Misko Hevery Date: Wed, 24 Mar 2010 16:47:11 -0700 Subject: fixed .value vs attr(value) access --- test/widgetsSpec.js | 32 +++++++++++++++++++++++++------- 1 file changed, 25 insertions(+), 7 deletions(-) (limited to 'test') diff --git a/test/widgetsSpec.js b/test/widgetsSpec.js index da9d5f9b..aeb7a613 100644 --- a/test/widgetsSpec.js +++ b/test/widgetsSpec.js @@ -25,13 +25,13 @@ describe("input widget", function(){ scope.set('name', 'Adam'); scope.updateView(); - expect(element.attr('value')).toEqual("Adam"); + expect(element.val()).toEqual("Adam"); - element.attr('value', 'Shyam'); + element.val('Shyam'); element.trigger('keyup'); expect(scope.get('name')).toEqual('Shyam'); - element.attr('value', 'Kai'); + element.val('Kai'); element.trigger('change'); expect(scope.get('name')).toEqual('Kai'); }); @@ -42,9 +42,9 @@ describe("input widget", function(){ scope.set('list', ['x', 'y', 'z']); scope.updateView(); - expect(element.attr('value')).toEqual("x, y, z"); + expect(element.val()).toEqual("x, y, z"); - element.attr('value', '1, 2, 3'); + element.val('1, 2, 3'); element.trigger('keyup'); expect(scope.get('list')).toEqual(['1', '2', '3']); }); @@ -59,7 +59,7 @@ describe("input widget", function(){ expect(element.hasClass('ng-validation-error')).toBeFalsy(); expect(element.attr('ng-error')).toBeFalsy(); - element.attr('value', 'x'); + element.val('x'); element.trigger('keyup'); expect(element.hasClass('ng-validation-error')).toBeTruthy(); expect(element.attr('ng-error')).toEqual('Not a number'); @@ -75,10 +75,28 @@ describe("input widget", function(){ expect(element.hasClass('ng-validation-error')).toBeFalsy(); expect(element.attr('ng-error')).toBeFalsy(); - element.attr('value', ''); + element.val(''); element.trigger('keyup'); expect(element.hasClass('ng-validation-error')).toBeTruthy(); expect(element.attr('ng-error')).toEqual('Required'); }); + it("should process ng-required", function() { + compile(''); + expect(scope.get('name')).toEqual("Misko"); + + scope.set('name', 'Adam'); + scope.updateView(); + expect(element.val()).toEqual("Adam"); + + element.val('Shyam'); + element.trigger('keyup'); + expect(scope.get('name')).toEqual('Shyam'); + + element.val('Kai'); + element.trigger('change'); + expect(scope.get('name')).toEqual('Kai'); + }); + + }); -- cgit v1.2.3 From b814c79b58deeeeaa12b03261399ef80c0d6cc9f Mon Sep 17 00:00:00 2001 From: Misko Hevery Date: Thu, 25 Mar 2010 13:01:08 -0700 Subject: checkbox and radio now working --- test/ParserTest.js | 17 ++++++++++++++ test/directivesSpec.js | 2 +- test/widgetsSpec.js | 60 ++++++++++++++++++++++++++++++++++++++++++++++++-- 3 files changed, 76 insertions(+), 3 deletions(-) (limited to 'test') diff --git a/test/ParserTest.js b/test/ParserTest.js index c8d323f2..d3813812 100644 --- a/test/ParserTest.js +++ b/test/ParserTest.js @@ -52,6 +52,16 @@ LexerTest.prototype.testTokenizeAString = function(){ assertEquals(tokens[i].string, 'd"e'); }; +LexerTest.prototype.testTokenizeUndefined = function(){ + var lexer = new Lexer("undefined"); + var tokens = lexer.parse(); + var i = 0; + assertEquals(tokens[i].index, 0); + assertEquals(tokens[i].text, 'undefined'); + assertEquals(undefined, tokens[i].fn()); +}; + + LexerTest.prototype.testTokenizeRegExp = function(){ var lexer = new Lexer("/r 1/"); @@ -486,3 +496,10 @@ ParserTest.prototype.testParsingBug = function () { var scope = new Scope(); assertEquals({a: "-"}, scope.eval("{a:'-'}")); }; + +ParserTest.prototype.testUndefined = function () { + var scope = new Scope(); + assertEquals(undefined, scope.eval("undefined")); + assertEquals(undefined, scope.eval("a=undefined")); + assertEquals(undefined, scope.get("a")); +}; diff --git a/test/directivesSpec.js b/test/directivesSpec.js index 18bedb64..83a270c1 100644 --- a/test/directivesSpec.js +++ b/test/directivesSpec.js @@ -12,7 +12,7 @@ describe("directives", function(){ }; }); - afterEach(function(){ + afterEach(function() { element.remove(); expect(_(jqCache).size()).toEqual(0); }); diff --git a/test/widgetsSpec.js b/test/widgetsSpec.js index aeb7a613..44a3d225 100644 --- a/test/widgetsSpec.js +++ b/test/widgetsSpec.js @@ -1,6 +1,6 @@ describe("input widget", function(){ - var compile, element, scope; + var compile, element, scope, model; beforeEach(function() { scope = null; @@ -11,6 +11,7 @@ describe("input widget", function(){ var view = compiler.compile(element)(element); view.init(); scope = view.scope; + model = scope.state; }; }); @@ -20,8 +21,9 @@ describe("input widget", function(){ }); it('should input-text auto init and handle keyup/change events', function(){ - compile(''); + compile(''); expect(scope.get('name')).toEqual("Misko"); + expect(scope.get('count')).toEqual(0); scope.set('name', 'Adam'); scope.updateView(); @@ -30,10 +32,12 @@ describe("input widget", function(){ element.val('Shyam'); element.trigger('keyup'); expect(scope.get('name')).toEqual('Shyam'); + expect(scope.get('count')).toEqual(1); element.val('Kai'); element.trigger('change'); expect(scope.get('name')).toEqual('Kai'); + expect(scope.get('count')).toEqual(2); }); it("should process ng-format", function(){ @@ -98,5 +102,57 @@ describe("input widget", function(){ expect(scope.get('name')).toEqual('Kai'); }); + it('should call ng-action on button click', function(){ + compile(''); + element.click(); + expect(scope.get('clicked')).toEqual(true); + }); + + it('should type="checkbox"', function(){ + compile(''); + expect(scope.get('checkbox')).toEqual(true); + element.click(); + expect(scope.get('checkbox')).toEqual(false); + expect(scope.get('action')).toEqual(true); + element.click(); + expect(scope.get('checkbox')).toEqual(true); + }); + + it('should type="radio"', function(){ + compile('
                ' + + '' + + '' + + '
                '); + var a = element[0].childNodes[0]; + var b = element[0].childNodes[1]; + expect(model.chose).toEqual('B'); + expect(model.clicked).not.toBeDefined(); + model.chose = 'A'; + model.$updateView(); + expect(a.checked).toEqual(true); + + model.chose = 'B'; + model.$updateView(); + expect(a.checked).toEqual(false); + expect(b.checked).toEqual(true); + expect(model.clicked).not.toBeDefined(); + + jqLite(a).click(); + expect(model.chose).toEqual('A'); + expect(model.clicked).toEqual(1); + }); + + it('should report error on missing field', function(){ + + }); + + it('should report error on assignment error', function(){ + + }); + + it('should report error on ng-action exception', function(){ + + }); + }); -- cgit v1.2.3 From 4fa166866b97d4f4dbd21514dbd674347da0a109 Mon Sep 17 00:00:00 2001 From: Misko Hevery Date: Thu, 25 Mar 2010 14:43:05 -0700 Subject: input select-one now works --- test/markupSpec.js | 11 ++++++++--- test/widgetsSpec.js | 21 +++++++++++++++++++++ 2 files changed, 29 insertions(+), 3 deletions(-) (limited to 'test') diff --git a/test/markupSpec.js b/test/markupSpec.js index 9e89af7b..8ea88f08 100644 --- a/test/markupSpec.js +++ b/test/markupSpec.js @@ -30,11 +30,11 @@ describe("markups", function(){ }); it('should translate {{}} in terminal nodes', function(){ - compile(''); - expect(element.html()).toEqual(''); + compile(''); + expect(element.html()).toEqual(''); scope.set('name', 'Misko'); scope.updateView(); - expect(element.html()).toEqual(''); + expect(element.html()).toEqual(''); }); it('should translate {{}} in attributes', function(){ @@ -46,4 +46,9 @@ describe("markups", function(){ expect(element.attr('src')).toEqual("http://server/a/b.png"); }); + it('should populate value attribute on OPTION', function(){ + compile(''); + expect(element.html()).toEqual(''); + }); + }); diff --git a/test/widgetsSpec.js b/test/widgetsSpec.js index 44a3d225..9471a718 100644 --- a/test/widgetsSpec.js +++ b/test/widgetsSpec.js @@ -108,6 +108,12 @@ describe("input widget", function(){ expect(scope.get('clicked')).toEqual(true); }); + it('should support button alias', function(){ + compile(''); + element.click(); + expect(scope.get('clicked')).toEqual(true); + }); + it('should type="checkbox"', function(){ compile(''); expect(scope.get('checkbox')).toEqual(true); @@ -142,6 +148,21 @@ describe("input widget", function(){ expect(model.clicked).toEqual(1); }); + it('should type="radio"', function(){ + compile( + ''); + expect(element[0].selectedIndex).toEqual(1); + expect(element[0].value).toEqual('B'); + expect(model.selection).toEqual('B'); + model.selection = 'A'; + model.$updateView(); + expect(model.selection).toEqual('A'); + expect(element[0].childNodes[0].selected).toEqual(true); + }); + it('should report error on missing field', function(){ }); -- cgit v1.2.3 From 0cc9b0732003451537a5bfc444fb6590f4ed103a Mon Sep 17 00:00:00 2001 From: Misko Hevery Date: Thu, 25 Mar 2010 14:51:42 -0700 Subject: input select-multiple now works --- test/widgetsSpec.js | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) (limited to 'test') diff --git a/test/widgetsSpec.js b/test/widgetsSpec.js index 9471a718..0f416278 100644 --- a/test/widgetsSpec.js +++ b/test/widgetsSpec.js @@ -148,14 +148,12 @@ describe("input widget", function(){ expect(model.clicked).toEqual(1); }); - it('should type="radio"', function(){ + it('should type="select-one"', function(){ compile( ''); - expect(element[0].selectedIndex).toEqual(1); - expect(element[0].value).toEqual('B'); expect(model.selection).toEqual('B'); model.selection = 'A'; model.$updateView(); @@ -163,6 +161,18 @@ describe("input widget", function(){ expect(element[0].childNodes[0].selected).toEqual(true); }); + it('should type="select-multiple"', function(){ + compile( + ''); + expect(model.selection).toEqual(['B']); + model.selection = ['A']; + model.$updateView(); + expect(element[0].childNodes[0].selected).toEqual(true); + }); + it('should report error on missing field', function(){ }); -- cgit v1.2.3 From d934054cfc22325d817eb0643dc061f9d212804d Mon Sep 17 00:00:00 2001 From: Misko Hevery Date: Thu, 25 Mar 2010 22:03:11 -0700 Subject: major refactoring of scope --- test/directivesSpec.js | 96 ++++++++++++++++++++++++-------------------------- test/markupSpec.js | 17 +++++---- test/widgetsSpec.js | 96 ++++++++++++++++++++++++-------------------------- 3 files changed, 102 insertions(+), 107 deletions(-) (limited to 'test') diff --git a/test/directivesSpec.js b/test/directivesSpec.js index 83a270c1..4ef57dce 100644 --- a/test/directivesSpec.js +++ b/test/directivesSpec.js @@ -1,49 +1,49 @@ describe("directives", function(){ - var compile, element; + var compile, model, element; beforeEach(function() { var compiler = new Compiler(angularTextMarkup, angularAttrMarkup, angularDirective, angularWidget); compile = function(html) { element = jqLite(html); - var view = compiler.compile(element)(element); - view.init(); - return view.scope; + model = compiler.compile(element)(element); + model.$init(); + return model; }; }); afterEach(function() { - element.remove(); + model.$element.remove(); expect(_(jqCache).size()).toEqual(0); }); it("should ng-init", function() { var scope = compile('
                '); - expect(scope.get('a')).toEqual(123); + expect(scope.a).toEqual(123); }); it("should ng-eval", function() { var scope = compile('
                '); - expect(scope.get('a')).toEqual(0); - scope.updateView(); - expect(scope.get('a')).toEqual(1); - scope.updateView(); - expect(scope.get('a')).toEqual(2); + expect(scope.a).toEqual(0); + scope.$eval(); + expect(scope.a).toEqual(1); + scope.$eval(); + expect(scope.a).toEqual(2); }); it('should ng-bind', function() { var scope = compile('
                '); expect(element.text()).toEqual(''); - scope.set('a', 'misko'); - scope.updateView(); + scope.a = 'misko'; + scope.$eval(); expect(element.text()).toEqual('misko'); }); it('should ng-bind-template', function() { var scope = compile('
                '); expect(element.text()).toEqual(''); - scope.set('name', 'Misko'); - scope.updateView(); + scope.$set('name', 'Misko'); + scope.$eval(); expect(element.text()).toEqual('Hello Misko!'); }); @@ -51,75 +51,73 @@ describe("directives", function(){ var scope = compile(''); expect(element.attr('src')).toEqual(null); expect(element.attr('alt')).toEqual(null); - scope.updateView(); + scope.$eval(); expect(element.attr('src')).toEqual('mysrc'); expect(element.attr('alt')).toEqual('myalt'); }); it('should ng-non-bindable', function(){ var scope = compile('
                '); - scope.set('name', 'misko'); - scope.updateView(); + scope.$set('name', 'misko'); + scope.$eval(); expect(element.text()).toEqual(''); }); it('should ng-repeat over array', function(){ var scope = compile('
                '); - scope.set('items', ['misko', 'shyam']); - scope.updateView(); + scope.$set('items', ['misko', 'shyam']); + scope.$eval(); expect(element.text()).toEqual('misko;shyam;'); - scope.set('items', ['adam', 'kai', 'brad']); - scope.updateView(); + scope.$set('items', ['adam', 'kai', 'brad']); + scope.$eval(); expect(element.text()).toEqual('adam;kai;brad;'); - scope.set('items', ['brad']); - scope.updateView(); + scope.$set('items', ['brad']); + scope.$eval(); expect(element.text()).toEqual('brad;'); }); it('should ng-repeat over object', function(){ var scope = compile('
                '); - scope.set('items', {misko:'swe', shyam:'set'}); - scope.updateView(); + scope.$set('items', {misko:'swe', shyam:'set'}); + scope.$eval(); expect(element.text()).toEqual('misko:swe;shyam:set;'); }); it('should error on wrong parsing of ng-repeat', function(){ var scope = compile('
                '); var log = ""; - eachNode(element, function(li){ - log += li.attr('ng-error') + ';'; - log += li.hasClass('ng-exception') + ';'; - }); + log += element.attr('ng-error') + ';'; + log += element.hasClass('ng-exception') + ';'; expect(log).toEqual("\"Expected ng-repeat in form of 'item in collection' but got 'i dont parse'.\";true;"); }); it('should ng-watch', function(){ var scope = compile('
                '); - scope.updateView(); - scope.updateView(); - expect(scope.get('count')).toEqual(0); + scope.$eval(); + scope.$eval(); + expect(scope.$get('count')).toEqual(0); - scope.set('i', 0); - scope.updateView(); - scope.updateView(); - expect(scope.get('count')).toEqual(1); + scope.$set('i', 0); + scope.$eval(); + scope.$eval(); + expect(scope.$get('count')).toEqual(1); }); it('should ng-action', function(){ var scope = compile('
                '); - scope.updateView(); - expect(scope.get('clicked')).toBeFalsy(); + scope.$eval(); + expect(scope.$get('clicked')).toBeFalsy(); element.click(); - expect(scope.get('clicked')).toEqual(true); + expect(scope.$get('clicked')).toEqual(true); }); it('should ng-class', function(){ var scope = compile('
                '); - scope.updateView(); + scope.$eval(); expect(element.hasClass('existing')).toBeTruthy(); expect(element.hasClass('A')).toBeTruthy(); expect(element.hasClass('B')).toBeTruthy(); @@ -127,7 +125,7 @@ describe("directives", function(){ it('should ng-class odd/even', function(){ var scope = compile('
                  • '); - scope.updateView(); + scope.$eval(); var e1 = jQuery(element.parent()[0]).find('li:first'); var e2 = jQuery(element.parent()[0]).find('li:last'); expect(e1.hasClass('existing')).toBeTruthy(); @@ -138,25 +136,25 @@ describe("directives", function(){ it('should ng-style', function(){ var scope = compile('
                    '); - scope.updateView(); + scope.$eval(); expect(element.css('color')).toEqual('red'); }); it('should ng-show', function(){ var scope = compile('
                    '); - scope.updateView(); + scope.$eval(); expect(element.css('display')).toEqual(''); - scope.set('hide', true); - scope.updateView(); + scope.$set('hide', true); + scope.$eval(); expect(element.css('display')).toEqual('none'); }); it('should ng-hide', function(){ var scope = compile('
                    '); - scope.updateView(); + scope.$eval(); expect(element.css('display')).toEqual('none'); - scope.set('show', true); - scope.updateView(); + scope.$set('show', true); + scope.$eval(); expect(element.css('display')).toEqual(''); }); }); diff --git a/test/markupSpec.js b/test/markupSpec.js index 8ea88f08..c83f27ff 100644 --- a/test/markupSpec.js +++ b/test/markupSpec.js @@ -8,9 +8,8 @@ describe("markups", function(){ var compiler = new Compiler(angularTextMarkup, angularAttrMarkup, angularDirective, angularWidget); compile = function(html) { element = jqLite(html); - var view = compiler.compile(element)(element); - view.init(); - scope = view.scope; + scope = compiler.compile(element)(element); + scope.$init(); }; }); @@ -24,16 +23,16 @@ describe("markups", function(){ it('should translate {{}} in text', function(){ compile('
                    hello {{name}}!
                    '); expect(element.html()).toEqual('hello !'); - scope.set('name', 'Misko'); - scope.updateView(); + scope.$set('name', 'Misko'); + scope.$eval(); expect(element.html()).toEqual('hello Misko!'); }); it('should translate {{}} in terminal nodes', function(){ compile(''); expect(element.html()).toEqual(''); - scope.set('name', 'Misko'); - scope.updateView(); + scope.$set('name', 'Misko'); + scope.$eval(); expect(element.html()).toEqual(''); }); @@ -41,8 +40,8 @@ describe("markups", function(){ compile(''); expect(element.attr('src')).toEqual(); expect(element.attr('ng-bind-attr')).toEqual('{"src":"http://server/{{path}}.png"}'); - scope.set('path', 'a/b'); - scope.updateView(); + scope.$set('path', 'a/b'); + scope.$eval(); expect(element.attr('src')).toEqual("http://server/a/b.png"); }); diff --git a/test/widgetsSpec.js b/test/widgetsSpec.js index 0f416278..7c9ea04a 100644 --- a/test/widgetsSpec.js +++ b/test/widgetsSpec.js @@ -1,6 +1,6 @@ describe("input widget", function(){ - var compile, element, scope, model; + var compile, element, scope; beforeEach(function() { scope = null; @@ -8,10 +8,8 @@ describe("input widget", function(){ var compiler = new Compiler(angularTextMarkup, angularAttrMarkup, angularDirective, angularWidget); compile = function(html) { element = jqLite(html); - var view = compiler.compile(element)(element); - view.init(); - scope = view.scope; - model = scope.state; + scope = compiler.compile(element)(element); + scope.$init(); }; }); @@ -22,35 +20,35 @@ describe("input widget", function(){ it('should input-text auto init and handle keyup/change events', function(){ compile(''); - expect(scope.get('name')).toEqual("Misko"); - expect(scope.get('count')).toEqual(0); + expect(scope.$get('name')).toEqual("Misko"); + expect(scope.$get('count')).toEqual(0); - scope.set('name', 'Adam'); - scope.updateView(); + scope.$set('name', 'Adam'); + scope.$eval(); expect(element.val()).toEqual("Adam"); element.val('Shyam'); element.trigger('keyup'); - expect(scope.get('name')).toEqual('Shyam'); - expect(scope.get('count')).toEqual(1); + expect(scope.$get('name')).toEqual('Shyam'); + expect(scope.$get('count')).toEqual(1); element.val('Kai'); element.trigger('change'); - expect(scope.get('name')).toEqual('Kai'); - expect(scope.get('count')).toEqual(2); + expect(scope.$get('name')).toEqual('Kai'); + expect(scope.$get('count')).toEqual(2); }); it("should process ng-format", function(){ compile(''); - expect(scope.get('list')).toEqual(['a', 'b', 'c']); + expect(scope.$get('list')).toEqual(['a', 'b', 'c']); - scope.set('list', ['x', 'y', 'z']); - scope.updateView(); + scope.$set('list', ['x', 'y', 'z']); + scope.$eval(); expect(element.val()).toEqual("x, y, z"); element.val('1, 2, 3'); element.trigger('keyup'); - expect(scope.get('list')).toEqual(['1', '2', '3']); + expect(scope.$get('list')).toEqual(['1', '2', '3']); }); it("should process ng-validation", function(){ @@ -58,8 +56,8 @@ describe("input widget", function(){ expect(element.hasClass('ng-validation-error')).toBeTruthy(); expect(element.attr('ng-error')).toEqual('Not a number'); - scope.set('price', '123'); - scope.updateView(); + scope.$set('price', '123'); + scope.$eval(); expect(element.hasClass('ng-validation-error')).toBeFalsy(); expect(element.attr('ng-error')).toBeFalsy(); @@ -74,8 +72,8 @@ describe("input widget", function(){ expect(element.hasClass('ng-validation-error')).toBeTruthy(); expect(element.attr('ng-error')).toEqual('Required'); - scope.set('price', 'xxx'); - scope.updateView(); + scope.$set('price', 'xxx'); + scope.$eval(); expect(element.hasClass('ng-validation-error')).toBeFalsy(); expect(element.attr('ng-error')).toBeFalsy(); @@ -87,41 +85,41 @@ describe("input widget", function(){ it("should process ng-required", function() { compile(''); - expect(scope.get('name')).toEqual("Misko"); + expect(scope.$get('name')).toEqual("Misko"); - scope.set('name', 'Adam'); - scope.updateView(); + scope.$set('name', 'Adam'); + scope.$eval(); expect(element.val()).toEqual("Adam"); element.val('Shyam'); element.trigger('keyup'); - expect(scope.get('name')).toEqual('Shyam'); + expect(scope.$get('name')).toEqual('Shyam'); element.val('Kai'); element.trigger('change'); - expect(scope.get('name')).toEqual('Kai'); + expect(scope.$get('name')).toEqual('Kai'); }); it('should call ng-action on button click', function(){ compile(''); element.click(); - expect(scope.get('clicked')).toEqual(true); + expect(scope.$get('clicked')).toEqual(true); }); it('should support button alias', function(){ compile(''); element.click(); - expect(scope.get('clicked')).toEqual(true); + expect(scope.$get('clicked')).toEqual(true); }); it('should type="checkbox"', function(){ compile(''); - expect(scope.get('checkbox')).toEqual(true); + expect(scope.$get('checkbox')).toEqual(true); element.click(); - expect(scope.get('checkbox')).toEqual(false); - expect(scope.get('action')).toEqual(true); + expect(scope.$get('checkbox')).toEqual(false); + expect(scope.$get('action')).toEqual(true); element.click(); - expect(scope.get('checkbox')).toEqual(true); + expect(scope.$get('checkbox')).toEqual(true); }); it('should type="radio"', function(){ @@ -131,21 +129,21 @@ describe("input widget", function(){ '
                '); var a = element[0].childNodes[0]; var b = element[0].childNodes[1]; - expect(model.chose).toEqual('B'); - expect(model.clicked).not.toBeDefined(); - model.chose = 'A'; - model.$updateView(); + expect(scope.chose).toEqual('B'); + expect(scope.clicked).not.toBeDefined(); + scope.chose = 'A'; + scope.$eval(); expect(a.checked).toEqual(true); - model.chose = 'B'; - model.$updateView(); + scope.chose = 'B'; + scope.$eval(); expect(a.checked).toEqual(false); expect(b.checked).toEqual(true); - expect(model.clicked).not.toBeDefined(); + expect(scope.clicked).not.toBeDefined(); jqLite(a).click(); - expect(model.chose).toEqual('A'); - expect(model.clicked).toEqual(1); + expect(scope.chose).toEqual('A'); + expect(scope.clicked).toEqual(1); }); it('should type="select-one"', function(){ @@ -154,10 +152,10 @@ describe("input widget", function(){ '' + '' + ''); - expect(model.selection).toEqual('B'); - model.selection = 'A'; - model.$updateView(); - expect(model.selection).toEqual('A'); + expect(scope.selection).toEqual('B'); + scope.selection = 'A'; + scope.$eval(); + expect(scope.selection).toEqual('A'); expect(element[0].childNodes[0].selected).toEqual(true); }); @@ -167,14 +165,14 @@ describe("input widget", function(){ '' + '' + ''); - expect(model.selection).toEqual(['B']); - model.selection = ['A']; - model.$updateView(); + expect(scope.selection).toEqual(['B']); + scope.selection = ['A']; + scope.$eval(); expect(element[0].childNodes[0].selected).toEqual(true); }); it('should report error on missing field', function(){ - + //compile(''); }); it('should report error on assignment error', function(){ -- cgit v1.2.3 From 1990cbbf2817e04657ccd616da1d9d6b78cc2949 Mon Sep 17 00:00:00 2001 From: Misko Hevery Date: Thu, 25 Mar 2010 22:07:36 -0700 Subject: added few extra tests --- test/ScopeSpec.js | 90 +++++++++++++++++++++++++++++++++++++++++++++++++++++ test/widgetsSpec.js | 10 ++++-- 2 files changed, 97 insertions(+), 3 deletions(-) create mode 100644 test/ScopeSpec.js (limited to 'test') diff --git a/test/ScopeSpec.js b/test/ScopeSpec.js new file mode 100644 index 00000000..0a0b4241 --- /dev/null +++ b/test/ScopeSpec.js @@ -0,0 +1,90 @@ +describe('scope/model', function(){ + + it('should create a scope with parent', function(){ + var model = scope({name:'Misko'}); + expect(model.name).toEqual('Misko'); + }); + + it('should have $get/set$/parent$', function(){ + var parent = {}; + var model = scope(parent); + model.$set('name', 'adam'); + expect(model.name).toEqual('adam'); + expect(model.$get('name')).toEqual('adam'); + expect(model.$parent).toEqual(parent); + }); + + //$eval + it('should eval function with correct this and pass arguments', function(){ + var model = scope(); + model.$eval(function(name){ + this.name = name; + }, 'works'); + expect(model.name).toEqual('works'); + }); + + it('should eval expression with correct this', function(){ + var model = scope(); + model.$eval('name="works"'); + expect(model.name).toEqual('works'); + }); + + //$onEval + it('should watch an expression for change', function(){ + var model = scope(); + model.oldValue = ""; + var count = 0; + model.name = 'adam'; + model.$watch('name', function(){ count ++; }); + model.$watch(function(){return model.name;}, function(newValue, oldValue){ + this.newValue = newValue; + this.oldValue = oldValue; + }); + model.name = 'misko'; + model.$eval(); + expect(count).toEqual(1); + expect(model.newValue).toEqual('misko'); + expect(model.oldValue).toEqual('adam'); + }); + + it('should eval with no arguments', function(){ + var model = scope(); + var count = 0; + model.$onEval(function(){count++;}); + model.$eval(); + expect(count).toEqual(1); + }); + + //$bind + it('should curry a function with respect to scope', function(){ + var model = scope(); + model.name = 'misko'; + expect(model.$bind(function(){return this.name;})()).toEqual('misko'); + }); + + //$behavior + it('should behave as class', function(){ + function Printer(brand){ + this.brand = brand; + }; + Printer.prototype.print = function(){ + this.printed = true; + }; + var model = scope({ name: 'parent' }, Printer, 'hp'); + expect(model.brand).toEqual('hp'); + model.print(); + expect(model.printed).toEqual(true); + }); + + + + //$tryEval + it('should report error on element', function(){ + + }); + + it('should report error on visible element', function(){ + + }); + +}); diff --git a/test/widgetsSpec.js b/test/widgetsSpec.js index 7c9ea04a..d6c44f68 100644 --- a/test/widgetsSpec.js +++ b/test/widgetsSpec.js @@ -172,15 +172,19 @@ describe("input widget", function(){ }); it('should report error on missing field', function(){ - //compile(''); + compile(''); + expect(element.hasClass('ng-exception')).toBeTruthy(); }); it('should report error on assignment error', function(){ - + compile(''); + expect(element.hasClass('ng-exception')).toBeTruthy(); }); it('should report error on ng-action exception', function(){ - + compile(''); + element.click(); + expect(element.hasClass('ng-exception')).toBeTruthy(); }); -- cgit v1.2.3 From 258ca5f16581f0e8befa493644225a02ae2fc002 Mon Sep 17 00:00:00 2001 From: Misko Hevery Date: Fri, 26 Mar 2010 16:27:18 -0700 Subject: moved all uneeded files out, widgets.html works, tests horribly broken --- test/Base64Test.js | 5 - test/DataStoreTest.js | 616 ------------------------- test/EntityDeclarationTest.js | 50 -- test/ModelTest.js | 84 ---- test/ScopeSpec.js | 16 +- test/ScopeTest.js | 145 ------ test/ServerTest.js | 42 -- test/UsersTest.js | 26 -- test/delete/ScopeTest.js | 145 ++++++ test/moveToAngularCom/Base64Test.js | 5 + test/moveToAngularCom/DataStoreTest.js | 616 +++++++++++++++++++++++++ test/moveToAngularCom/EntityDeclarationTest.js | 50 ++ test/moveToAngularCom/ModelTest.js | 84 ++++ test/moveToAngularCom/ServerTest.js | 42 ++ test/moveToAngularCom/UsersTest.js | 26 ++ 15 files changed, 976 insertions(+), 976 deletions(-) delete mode 100644 test/Base64Test.js delete mode 100644 test/DataStoreTest.js delete mode 100644 test/EntityDeclarationTest.js delete mode 100644 test/ModelTest.js delete mode 100644 test/ScopeTest.js delete mode 100644 test/ServerTest.js delete mode 100644 test/UsersTest.js create mode 100644 test/delete/ScopeTest.js create mode 100644 test/moveToAngularCom/Base64Test.js create mode 100644 test/moveToAngularCom/DataStoreTest.js create mode 100644 test/moveToAngularCom/EntityDeclarationTest.js create mode 100644 test/moveToAngularCom/ModelTest.js create mode 100644 test/moveToAngularCom/ServerTest.js create mode 100644 test/moveToAngularCom/UsersTest.js (limited to 'test') diff --git a/test/Base64Test.js b/test/Base64Test.js deleted file mode 100644 index a9353186..00000000 --- a/test/Base64Test.js +++ /dev/null @@ -1,5 +0,0 @@ -Base64Test = TestCase('Base64Test'); - -Base64Test.prototype.testEncodeDecode = function(){ - assertEquals(Base64.decode(Base64.encode('hello')), 'hello'); -}; diff --git a/test/DataStoreTest.js b/test/DataStoreTest.js deleted file mode 100644 index 87c5be2e..00000000 --- a/test/DataStoreTest.js +++ /dev/null @@ -1,616 +0,0 @@ -DataStoreTest = TestCase('DataStoreTest'); - -DataStoreTest.prototype.testSavePostsToServer = function(){ - expectAsserts(10); - var response; - var post = function(data, callback){ - var method = data[0][0]; - var posted = data[0][2]; - assertEquals("POST", method); - assertEquals("abc", posted.$entity); - assertEquals("123", posted.$id); - assertEquals("1", posted.$version); - assertFalse('function' == typeof posted.save); - response = fromJson(toJson(posted)); - response.$entity = "abc"; - response.$id = "123"; - response.$version = "2"; - callback(200, [response]); - }; - var datastore = new DataStore(post); - var model = datastore.entity('abc', {name: "value"})(); - model.$id = "123"; - model.$version = "1"; - - datastore.save(model, function(obj){ - assertTrue(obj === model); - assertEquals(obj.$entity, "abc"); - assertEquals(obj.$id, "123"); - assertEquals(obj.$version, "2"); - assertEquals(obj.name, "value"); - obj.after = true; - }); - datastore.flush(); -}; - -DataStoreTest.prototype.testLoadGetsFromServer = function(){ - expectAsserts(12); - var post = function(data, callback){ - var method = data[0][0]; - var path = data[0][1]; - assertEquals("GET", method); - assertEquals("abc/1", path); - response = [{$entity:'abc', $id:'1', $version:'2', key:"value"}]; - callback(200, response); - }; - var datastore = new DataStore(post); - - var model = datastore.entity("abc", {merge:true})(); - assertEquals(datastore.load(model, '1', function(obj){ - assertEquals(obj.$entity, "abc"); - assertEquals(obj.$id, "1"); - assertEquals(obj.$version, "2"); - assertEquals(obj.key, "value"); - }), model); - datastore.flush(); - assertEquals(model.$entity, "abc"); - assertEquals(model.$id, "1"); - assertEquals(model.$version, "2"); - assertEquals(model.key, "value"); - assertEquals(model.merge, true); -}; - -DataStoreTest.prototype.testRemove = function(){ - expectAsserts(8); - var response; - var post = function(data, callback){ - var method = data[0][0]; - var posted = data[0][2]; - assertEquals("DELETE", method); - assertEquals("abc", posted.$entity); - assertEquals("123", posted.$id); - assertEquals("1", posted.$version); - assertFalse('function' == typeof posted.save); - response = fromJson(toJson(posted)); - response.$entity = "abc"; - response.$id = "123"; - response.$version = "2"; - callback(200, [response]); - }; - var model; - var datastore = new DataStore(post); - model = datastore.entity('abc', {name: "value"})(); - model.$id = "123"; - model.$version = "1"; - - datastore.remove(model, function(obj){ - assertEquals(obj.$id, "123"); - assertEquals(obj.$version, "2"); - assertEquals(obj.name, "value"); - obj.after = true; - }); - datastore.flush(); - -}; - - -DataStoreTest.prototype.test401ResponseDoesNotCallCallback = function(){ - expectAsserts(1); - var post = function(data, callback) { - callback(200, {$status_code: 401}); - }; - - var datastore = new DataStore(post, {login:function(){ - assertTrue(true); - }}); - - var onLoadAll = function(){ - assertTrue(false, "onLoadAll should not be called when response is status 401"); - }; - datastore.bulkRequest.push({}); - datastore.flush(); - datastore.loadAll({type: "A"}, onLoadAll); -}; - -DataStoreTest.prototype.test403ResponseDoesNotCallCallback = function(){ - expectAsserts(1); - var post = function(data, callback) { - callback(200, [{$status_code: 403}]); - }; - - var datastore = new DataStore(post, {notAuthorized:function(){ - assertTrue(true); - }}); - - var onLoadAll = function(){ - assertTrue(false, "onLoadAll should not be called when response is status 403"); - }; - datastore.bulkRequest.push({}); - datastore.flush(); - datastore.loadAll({type: "A"}, onLoadAll); -}; - -DataStoreTest.prototype.testLoadCalledWithoutIdShouldBeNoop = function(){ - expectAsserts(2); - var post = function(url, callback){ - assertTrue(false); - }; - var datastore = new DataStore(post); - var model = datastore.entity("abc")(); - assertEquals(datastore.load(model, undefined), model); - assertEquals(model.$entity, "abc"); -}; - -DataStoreTest.prototype.testEntityFactory = function(){ - var ds = new DataStore(); - var Recipe = ds.entity("Recipe", {a:1, b:2}); - assertEquals(Recipe.title, "Recipe"); - assertEquals(Recipe.defaults.a, 1); - assertEquals(Recipe.defaults.b, 2); - - var recipe = Recipe(); - assertEquals(recipe.$entity, "Recipe"); - assertEquals(recipe.a, 1); - assertEquals(recipe.b, 2); - - recipe = new Recipe(); - assertEquals(recipe.$entity, "Recipe"); - assertEquals(recipe.a, 1); - assertEquals(recipe.b, 2); -}; - -DataStoreTest.prototype.testEntityFactoryNoDefaults = function(){ - var ds = new DataStore(); - var Recipe = ds.entity("Recipe"); - assertEquals(Recipe.title, "Recipe"); - - recipe = new Recipe(); - assertEquals(recipe.$entity, "Recipe"); -}; - -DataStoreTest.prototype.testEntityFactoryWithInitialValues = function(){ - var ds = new DataStore(); - var Recipe = ds.entity("Recipe"); - - var recipe = Recipe({name: "name"}); - assertEquals("name", recipe.name); -}; - -DataStoreTest.prototype.testEntityLoad = function(){ - var ds = new DataStore(); - var Recipe = ds.entity("Recipe", {a:1, b:2}); - ds.load = function(instance, id, callback){ - callback.apply(instance); - return instance; - }; - var instance = null; - var recipe2 = Recipe.load("ID", function(){ - instance = this; - }); - assertTrue(recipe2 === instance); -}; - -DataStoreTest.prototype.testSaveScope = function(){ - var ds = new DataStore(); - var log = ""; - var Person = ds.entity("Person"); - var person1 = Person({name:"A", $entity:"Person", $id:"1", $version:"1"}, ds); - person1.$$anchor = "A"; - var person2 = Person({name:"B", $entity:"Person", $id:"2", $version:"2"}, ds); - person2.$$anchor = "B"; - var anchor = {}; - ds.anchor = anchor; - ds._jsonRequest = function(request, callback){ - log += "save(" + request[2].$id + ");"; - callback({$id:request[2].$id}); - }; - ds.saveScope({person1:person1, person2:person2, - ignoreMe:{name: "ignore", save:function(callback){callback();}}}, function(){ - log += "done();"; - }); - assertEquals("save(1);save(2);done();", log); - assertEquals(1, anchor.A); - assertEquals(2, anchor.B); -}; - -DataStoreTest.prototype.testEntityLoadAllRows = function(){ - var ds = new DataStore(); - var Recipe = ds.entity("Recipe"); - var list = []; - ds.loadAll = function(entity, callback){ - assertTrue(Recipe === entity); - callback.apply(list); - return list; - }; - var items = Recipe.all(function(){ - assertTrue(list === this); - }); - assertTrue(items === list); -}; - -DataStoreTest.prototype.testLoadAll = function(){ - expectAsserts(8); - var post = function(data, callback){ - assertEquals("GET", data[0][0]); - assertEquals("A", data[0][1]); - callback(200, [[{$entity:'A', $id:'1'},{$entity:'A', $id:'2'}]]); - }; - var datastore = new DataStore(post); - var list = datastore.entity("A").all(function(){ - assertTrue(true); - }); - datastore.flush(); - assertEquals(list.length, 2); - assertEquals(list[0].$entity, "A"); - assertEquals(list[0].$id, "1"); - assertEquals(list[1].$entity, "A"); - assertEquals(list[1].$id, "2"); -}; - -DataStoreTest.prototype.testQuery = function(){ - expectAsserts(5); - var post = function(data, callback) { - assertEquals("GET", data[0][0]); - assertEquals("Employee/managerId=123abc", data[0][1]); - callback(200, [[{$entity:"Employee", $id: "456", managerId: "123ABC"}]]); - - }; - var datastore = new DataStore(post); - var Employee = datastore.entity("Employee"); - var list = Employee.query('managerId', "123abc", function(){ - assertTrue(true); - }); - datastore.flush(); - assertJsonEquals([[{$entity:"Employee", $id: "456", managerId: "123ABC"}]], datastore._cache.$collections); - assertEquals(list[0].$id, "456"); -}; - -DataStoreTest.prototype.testLoadingDocumentRefreshesExistingArrays = function() { - expectAsserts(12); - var post; - var datastore = new DataStore(function(r, c){post(r,c);}); - var Book = datastore.entity('Book'); - post = function(req, callback) { - callback(200, [[{$id:1, $entity:"Book", name:"Moby"}, - {$id:2, $entity:"Book", name:"Dick"}]]); - }; - var allBooks = Book.all(); - datastore.flush(); - var queryBooks = Book.query("a", "b"); - datastore.flush(); - assertEquals("Moby", allBooks[0].name); - assertEquals("Dick", allBooks[1].name); - assertEquals("Moby", queryBooks[0].name); - assertEquals("Dick", queryBooks[1].name); - - post = function(req, callback) { - assertEquals('[["GET","Book/1"]]', toJson(req)); - callback(200, [{$id:1, $entity:"Book", name:"Moby Dick"}]); - }; - var book = Book.load(1); - datastore.flush(); - assertEquals("Moby Dick", book.name); - assertEquals("Moby Dick", allBooks[0].name); - assertEquals("Moby Dick", queryBooks[0].name); - - post = function(req, callback) { - assertEquals('POST', req[0][0]); - callback(200, [{$id:1, $entity:"Book", name:"The Big Fish"}]); - }; - book.$save(); - datastore.flush(); - assertEquals("The Big Fish", book.name); - assertEquals("The Big Fish", allBooks[0].name); - assertEquals("The Big Fish", queryBooks[0].name); -}; - -DataStoreTest.prototype.testEntityProperties = function() { - expectAsserts(2); - var datastore = new DataStore(); - var callback = {}; - - datastore._jsonRequest = function(request, callbackFn) { - assertJsonEquals(["GET", "Cheese/$properties"], request); - assertEquals(callback, callbackFn); - }; - - var Cheese = datastore.entity("Cheese"); - Cheese.properties(callback); - -}; - -DataStoreTest.prototype.testLoadInstanceIsNotFromCache = function() { - var post; - var datastore = new DataStore(function(r, c){post(r,c);}); - var Book = datastore.entity('Book'); - - post = function(req, callback) { - assertEquals('[["GET","Book/1"]]', toJson(req)); - callback(200, [{$id:1, $entity:"Book", name:"Moby Dick"}]); - }; - var book = Book.load(1); - datastore.flush(); - assertEquals("Moby Dick", book.name); - assertFalse(book === datastore._cache['Book/1']); -}; - -DataStoreTest.prototype.testLoadStarsIsNewDocument = function() { - var datastore = new DataStore(); - var Book = datastore.entity('Book'); - var book = Book.load('*'); - assertEquals('Book', book.$entity); -}; - -DataStoreTest.prototype.testUndefinedEntityReturnsNullValueObject = function() { - var datastore = new DataStore(); - var Entity = datastore.entity(undefined); - var all = Entity.all(); - assertEquals(0, all.length); -}; - -DataStoreTest.prototype.testFetchEntities = function(){ - expectAsserts(6); - var post = function(data, callback){ - assertJsonEquals(["GET", "$entities"], data[0]); - callback(200, [{A:0, B:0}]); - }; - var datastore = new DataStore(post); - var entities = datastore.entities(function(){ - assertTrue(true); - }); - datastore.flush(); - assertJsonEquals([], datastore.bulkRequest); - assertEquals(2, entities.length); - assertEquals("A", entities[0].title); - assertEquals("B", entities[1].title); -}; - -DataStoreTest.prototype.testItShouldMigrateSchema = function() { - var datastore = new DataStore(); - var Entity = datastore.entity("Entity", {a:[], user:{name:"Misko", email:""}}); - var doc = Entity().$loadFrom({b:'abc', user:{email:"misko@hevery.com"}}); - assertFalse( - toJson({a:[], b:'abc', user:{name:"Misko", email:"misko@hevery.com"}}) == - toJson(doc)); - doc.$migrate(); - assertEquals( - toJson({a:[], b:'abc', user:{name:"Misko", email:"misko@hevery.com"}}), - toJson(doc)); -}; - -DataStoreTest.prototype.testItShouldCollectRequestsForBulk = function() { - var ds = new DataStore(); - var Book = ds.entity("Book"); - var Library = ds.entity("Library"); - Book.all(); - Library.load("123"); - assertEquals(2, ds.bulkRequest.length); - assertJsonEquals(["GET", "Book"], ds.bulkRequest[0]); - assertJsonEquals(["GET", "Library/123"], ds.bulkRequest[1]); -}; - -DataStoreTest.prototype.testEmptyFlushShouldDoNothing = function () { - var ds = new DataStore(function(){ - fail("expecting noop"); - }); - ds.flush(); -}; - -DataStoreTest.prototype.testFlushShouldCallAllCallbacks = function() { - var log = ""; - function post(request, callback){ - log += 'BulkRequest:' + toJson(request) + ';'; - callback(200, [[{$id:'ABC'}], {$id:'XYZ'}]); - } - var ds = new DataStore(post); - var Book = ds.entity("Book"); - var Library = ds.entity("Library"); - Book.all(function(instance){ - log += toJson(instance) + ';'; - }); - Library.load("123", function(instance){ - log += toJson(instance) + ';'; - }); - assertEquals("", log); - ds.flush(); - assertJsonEquals([], ds.bulkRequest); - assertEquals('BulkRequest:[["GET","Book"],["GET","Library/123"]];[{"$id":"ABC"}];{"$id":"XYZ"};', log); -}; - -DataStoreTest.prototype.testSaveOnNotLoggedInRetriesAfterLoggin = function(){ - var log = ""; - var book; - var ds = new DataStore(null, {login:function(c){c();}}); - ds.post = function (request, callback){ - assertJsonEquals([["POST", "", book]], request); - ds.post = function(request, callback){ - assertJsonEquals([["POST", "", book]], request); - ds.post = function(){fail("too much recursion");}; - callback(200, [{saved:"ok"}]); - }; - callback(200, {$status_code:401}); - }; - book = ds.entity("Book")({name:"misko"}); - book.$save(); - ds.flush(); - assertJsonEquals({saved:"ok"}, book); -}; - -DataStoreTest.prototype.testItShouldRemoveItemFromCollectionWhenDeleted = function() { - expectAsserts(6); - var ds = new DataStore(); - ds.post = function(request, callback){ - assertJsonEquals([["GET", "Book"]], request); - callback(200, [[{name:"Moby Dick", $id:123, $entity:'Book'}]]); - }; - var Book = ds.entity("Book"); - var books = Book.all(); - ds.flush(); - assertJsonEquals([[{name:"Moby Dick", $id:123, $entity:'Book'}]], ds._cache.$collections); - assertDefined(ds._cache['Book/123']); - var book = Book({$id:123}); - ds.post = function(request, callback){ - assertJsonEquals([["DELETE", "", book]], request); - callback(200, [book]); - }; - ds.remove(book); - ds.flush(); - assertUndefined(ds._cache['Book/123']); - assertJsonEquals([[]],ds._cache.$collections); -}; - -DataStoreTest.prototype.testItShouldAddToAll = function() { - expectAsserts(8); - var ds = new DataStore(); - ds.post = function(request, callback){ - assertJsonEquals([["GET", "Book"]], request); - callback(200, [[]]); - }; - var Book = ds.entity("Book"); - var books = Book.all(); - assertEquals(0, books.length); - ds.flush(); - var moby = Book({name:'moby'}); - moby.$save(); - ds.post = function(request, callback){ - assertJsonEquals([["POST", "", moby]], request); - moby.$id = '123'; - callback(200, [moby]); - }; - ds.flush(); - assertEquals(1, books.length); - assertEquals(moby, books[0]); - - moby.$save(); - ds.flush(); - assertEquals(1, books.length); - assertEquals(moby, books[0]); -}; - -DataStoreTest.prototype.testItShouldReturnCreatedDocumentCountByUser = function(){ - expectAsserts(2); - var datastore = new DataStore( - function(request, callback){ - assertJsonEquals([["GET", "$users"]], request); - callback(200, [{misko:1, adam:1}]); - }); - var users = datastore.documentCountsByUser(); - assertJsonEquals({misko:1, adam:1}, users); -}; - - -DataStoreTest.prototype.testItShouldReturnDocumentIdsForUeserByEntity = function(){ - expectAsserts(2); - var datastore = new DataStore( - function(request, callback){ - assertJsonEquals([["GET", "$users/misko@hevery.com"]], request); - callback(200, [{Book:["1"], Library:["2"]}]); - }); - var users = datastore.userDocumentIdsByEntity("misko@hevery.com"); - assertJsonEquals({Book:["1"], Library:["2"]}, users); -}; - -DataStoreTest.prototype.testItShouldReturnNewInstanceOn404 = function(){ - expectAsserts(7); - var log = ""; - var datastore = new DataStore( - function(request, callback){ - assertJsonEquals([["GET", "User/misko"]], request); - callback(200, [{$status_code:404}]); - }); - var User = datastore.entity("User", {admin:false}); - var user = User.loadOrCreate('misko', function(i){log+="cb "+i.$id+";";}); - datastore.flush(); - assertEquals("misko", user.$id); - assertEquals("User", user.$entity); - assertEquals(false, user.admin); - assertEquals("undefined", typeof user.$secret); - assertEquals("undefined", typeof user.$version); - assertEquals("cb misko;", log); -}; - -DataStoreTest.prototype.testItShouldReturnNewInstanceOn404 = function(){ - var log = ""; - var datastore = new DataStore( - function(request, callback){ - assertJsonEquals([["GET", "User/misko"],["GET", "User/adam"]], request); - callback(200, [{$id:'misko'},{$id:'adam'}]); - }); - var User = datastore.entity("User"); - var users = User.loadMany(['misko', 'adam'], function(i){log+="cb "+toJson(i)+";";}); - datastore.flush(); - assertEquals("misko", users[0].$id); - assertEquals("adam", users[1].$id); - assertEquals('cb [{"$id":"misko"},{"$id":"adam"}];', log); -}; - -DataStoreTest.prototype.testItShouldCreateJoinAndQuery = function() { - var datastore = new DataStore(); - var Invoice = datastore.entity("Invoice"); - var Customer = datastore.entity("Customer"); - var InvoiceWithCustomer = datastore.join({ - invoice:{join:Invoice}, - customer:{join:Customer, on:"invoice.customer"} - }); - var invoiceWithCustomer = InvoiceWithCustomer.query("invoice.month", 1); - assertEquals([], invoiceWithCustomer); - assertJsonEquals([["GET", "Invoice/month=1"]], datastore.bulkRequest); - var request = datastore.bulkRequest.shift(); - request.$$callback([{$id:1, customer:1},{$id:2, customer:1},{$id:3, customer:3}]); - assertJsonEquals([["GET","Customer/1"],["GET","Customer/3"]], datastore.bulkRequest); - datastore.bulkRequest.shift().$$callback({$id:1}); - datastore.bulkRequest.shift().$$callback({$id:3}); - assertJsonEquals([ - {invoice:{$id:1,customer:1},customer:{$id:1}}, - {invoice:{$id:2,customer:1},customer:{$id:1}}, - {invoice:{$id:3,customer:3},customer:{$id:3}}], invoiceWithCustomer); -}; - -DataStoreTest.prototype.testItShouldThrowIfMoreThanOneEntityIsPrimary = function() { - var datastore = new DataStore(); - var Invoice = datastore.entity("Invoice"); - var Customer = datastore.entity("Customer"); - assertThrows("Exactly one entity needs to be primary.", function(){ - datastore.join({ - invoice:{join:Invoice}, - customer:{join:Customer} - }); - }); -}; - -DataStoreTest.prototype.testItShouldThrowIfLoopInReferences = function() { - var datastore = new DataStore(); - var Invoice = datastore.entity("Invoice"); - var Customer = datastore.entity("Customer"); - assertThrows("Infinite loop in join: invoice -> customer", function(){ - datastore.join({ - invoice:{join:Invoice, on:"customer.invoice"}, - customer:{join:Customer, on:"invoice.customer"} - }); - }); -}; - -DataStoreTest.prototype.testItShouldThrowIfReferenceToNonExistantJoin = function() { - var datastore = new DataStore(); - var Invoice = datastore.entity("Invoice"); - var Customer = datastore.entity("Customer"); - assertThrows("Named entity 'x' is undefined.", function(){ - datastore.join({ - invoice:{join:Invoice, on:"x.invoice"}, - customer:{join:Customer, on:"invoice.customer"} - }); - }); -}; - -DataStoreTest.prototype.testItShouldThrowIfQueryOnNonPrimary = function() { - var datastore = new DataStore(); - var Invoice = datastore.entity("Invoice"); - var Customer = datastore.entity("Customer"); - var InvoiceWithCustomer = datastore.join({ - invoice:{join:Invoice}, - customer:{join:Customer, on:"invoice.customer"} - }); - assertThrows("Named entity 'customer' is not a primary entity.", function(){ - InvoiceWithCustomer.query("customer.month", 1); - }); -}; diff --git a/test/EntityDeclarationTest.js b/test/EntityDeclarationTest.js deleted file mode 100644 index 28986ea8..00000000 --- a/test/EntityDeclarationTest.js +++ /dev/null @@ -1,50 +0,0 @@ -EntityDeclarationTest = TestCase('EntityDeclarationTest'); - -EntityDeclarationTest.prototype.testEntityTypeOnly = function(){ - expectAsserts(2); - var datastore = {entity:function(name){ - assertEquals("Person", name); - }}; - var scope = new Scope(); - var init = scope.entity("Person", datastore); - assertEquals("", init); -}; - -EntityDeclarationTest.prototype.testWithDefaults = function(){ - expectAsserts(4); - var datastore = {entity:function(name, init){ - assertEquals("Person", name); - assertEquals("=a:", init.a); - assertEquals(0, init.b.length); - }}; - var scope = new Scope(); - var init = scope.entity('Person:{a:"=a:", b:[]}', datastore); - assertEquals("", init); -}; - -EntityDeclarationTest.prototype.testWithName = function(){ - expectAsserts(2); - var datastore = {entity:function(name, init){ - assertEquals("Person", name); - return function (){ return {}; }; - }}; - var scope = new Scope(); - var init = scope.entity('friend=Person', datastore); - assertEquals("$anchor.friend:{friend=Person.load($anchor.friend);friend.$$anchor=\"friend\";};", init); -}; - -EntityDeclarationTest.prototype.testMultipleEntities = function(){ - expectAsserts(3); - var expect = ['Person', 'Book']; - var i=0; - var datastore = {entity:function(name, init){ - assertEquals(expect[i], name); - i++; - return function (){ return {}; }; - }}; - var scope = new Scope(); - var init = scope.entity('friend=Person;book=Book;', datastore); - assertEquals("$anchor.friend:{friend=Person.load($anchor.friend);friend.$$anchor=\"friend\";};" + - "$anchor.book:{book=Book.load($anchor.book);book.$$anchor=\"book\";};", - init); -}; diff --git a/test/ModelTest.js b/test/ModelTest.js deleted file mode 100644 index dbd97778..00000000 --- a/test/ModelTest.js +++ /dev/null @@ -1,84 +0,0 @@ -ModelTest = TestCase('ModelTest'); - -ModelTest.prototype.testLoadSaveOperations = function(){ - var m1 = new DataStore().entity('A')(); - m1.a = 1; - - var m2 = {b:1}; - - m1.$loadFrom(m2); - - assertTrue(!m1.a); - assertEquals(m1.b, 1); -}; - -ModelTest.prototype.testLoadfromDoesNotClobberFunctions = function(){ - var m1 = new DataStore().entity('A')(); - m1.id = function(){return 'OK';}; - m1.$loadFrom({id:null}); - assertEquals(m1.id(), 'OK'); - - m1.b = 'OK'; - m1.$loadFrom({b:function(){}}); - assertEquals(m1.b, 'OK'); -}; - -ModelTest.prototype.testDataStoreDoesNotGetClobbered = function(){ - var ds = new DataStore(); - var m = ds.entity('A')(); - assertTrue(m.$$entity.datastore === ds); - m.$loadFrom({}); - assertTrue(m.$$entity.datastore === ds); -}; - -ModelTest.prototype.testManagedModelDelegatesMethodsToDataStore = function(){ - expectAsserts(7); - var datastore = new DataStore(); - var model = datastore.entity("A", {a:1})(); - var fn = {}; - datastore.save = function(instance, callback) { - assertTrue(model === instance); - assertTrue(callback === fn); - }; - datastore.remove = function(instance, callback) { - assertTrue(model === instance); - assertTrue(callback === fn); - }; - datastore.load = function(instance, id, callback) { - assertTrue(model === instance); - assertTrue(id === "123"); - assertTrue(callback === fn); - }; - model.$save(fn); - model.$delete(fn); - model.$loadById("123", fn); -}; - -ModelTest.prototype.testManagedModelCanBeForcedToFlush = function(){ - expectAsserts(6); - var datastore = new DataStore(); - var model = datastore.entity("A", {a:1})(); - - datastore.save = function(instance, callback) { - assertTrue(model === instance); - assertTrue(callback === undefined); - }; - datastore.remove = function(instance, callback) { - assertTrue(model === instance); - assertTrue(callback === undefined); - }; - datastore.flush = function(){ - assertTrue(true); - }; - model.$save(true); - model.$delete(true); -}; - - -ModelTest.prototype.testItShouldMakeDeepCopyOfInitialValues = function (){ - var initial = {a:[]}; - var entity = new DataStore().entity("A", initial); - var model = entity(); - model.a.push(1); - assertEquals(0, entity().a.length); -}; diff --git a/test/ScopeSpec.js b/test/ScopeSpec.js index 0a0b4241..cfae42a8 100644 --- a/test/ScopeSpec.js +++ b/test/ScopeSpec.js @@ -1,13 +1,13 @@ describe('scope/model', function(){ it('should create a scope with parent', function(){ - var model = scope({name:'Misko'}); + var model = createScope({name:'Misko'}); expect(model.name).toEqual('Misko'); }); it('should have $get/set$/parent$', function(){ var parent = {}; - var model = scope(parent); + var model = createScope(parent); model.$set('name', 'adam'); expect(model.name).toEqual('adam'); expect(model.$get('name')).toEqual('adam'); @@ -16,7 +16,7 @@ describe('scope/model', function(){ //$eval it('should eval function with correct this and pass arguments', function(){ - var model = scope(); + var model = createScope(); model.$eval(function(name){ this.name = name; }, 'works'); @@ -24,14 +24,14 @@ describe('scope/model', function(){ }); it('should eval expression with correct this', function(){ - var model = scope(); + var model = createScope(); model.$eval('name="works"'); expect(model.name).toEqual('works'); }); //$onEval it('should watch an expression for change', function(){ - var model = scope(); + var model = createScope(); model.oldValue = ""; var count = 0; model.name = 'adam'; @@ -48,7 +48,7 @@ describe('scope/model', function(){ }); it('should eval with no arguments', function(){ - var model = scope(); + var model = createScope(); var count = 0; model.$onEval(function(){count++;}); model.$eval(); @@ -57,7 +57,7 @@ describe('scope/model', function(){ //$bind it('should curry a function with respect to scope', function(){ - var model = scope(); + var model = createScope(); model.name = 'misko'; expect(model.$bind(function(){return this.name;})()).toEqual('misko'); }); @@ -70,7 +70,7 @@ describe('scope/model', function(){ Printer.prototype.print = function(){ this.printed = true; }; - var model = scope({ name: 'parent' }, Printer, 'hp'); + var model = createScope({ name: 'parent' }, Printer, 'hp'); expect(model.brand).toEqual('hp'); model.print(); expect(model.printed).toEqual(true); diff --git a/test/ScopeTest.js b/test/ScopeTest.js deleted file mode 100644 index 24febf19..00000000 --- a/test/ScopeTest.js +++ /dev/null @@ -1,145 +0,0 @@ -ScopeTest = TestCase('ScopeTest'); - -ScopeTest.prototype.testGetScopeRetrieval = function(){ - var scope = {}; - var form = jQuery(""); - form.data('scope', scope); - var c = form.find('c'); - assertTrue(scope === c.scope()); -}; - -ScopeTest.prototype.testGetScopeRetrievalIntermediateNode = function(){ - var scope = {}; - var form = jQuery(""); - form.find("b").data('scope', scope); - var b = form.find('b'); - assertTrue(scope === b.scope()); -}; - -ScopeTest.prototype.testNoScopeDoesNotCauseInfiniteRecursion = function(){ - var form = jQuery(""); - var c = form.find('c'); - assertTrue(!c.scope()); -}; - -ScopeTest.prototype.testScopeEval = function(){ - var scope = new Scope({b:345}); - assertEquals(scope.eval('b = 123'), 123); - assertEquals(scope.get('b'), 123); -}; - -ScopeTest.prototype.testScopeFromPrototype = function(){ - var scope = new Scope({b:123}); - scope.eval('a = b'); - scope.eval('b = 456'); - assertEquals(scope.get('a'), 123); - assertEquals(scope.get('b'), 456); -}; - -ScopeTest.prototype.testSetScopeGet = function(){ - var scope = new Scope(); - assertEquals(987, scope.set('a', 987)); - assertEquals(scope.get('a'), 987); - assertEquals(scope.eval('a'), 987); -}; - -ScopeTest.prototype.testGetChain = function(){ - var scope = new Scope({a:{b:987}}); - assertEquals(scope.get('a.b'), 987); - assertEquals(scope.eval('a.b'), 987); -}; - -ScopeTest.prototype.testGetUndefinedChain = function(){ - var scope = new Scope(); - assertEquals(typeof scope.get('a.b'), 'undefined'); -}; - -ScopeTest.prototype.testSetChain = function(){ - var scope = new Scope({a:{}}); - scope.set('a.b', 987); - assertEquals(scope.get('a.b'), 987); - assertEquals(scope.eval('a.b'), 987); -}; - -ScopeTest.prototype.testSetGetOnChain = function(){ - var scope = new Scope(); - scope.set('a.b', 987); - assertEquals(scope.get('a.b'), 987); - assertEquals(scope.eval('a.b'), 987); -}; - -ScopeTest.prototype.testGlobalFunctionAccess =function(){ - window['scopeAddTest'] = function (a, b) {return a+b;}; - var scope = new Scope({window:window}); - assertEquals(scope.eval('window.scopeAddTest(1,2)'), 3); - - scope.set('add', function (a, b) {return a+b;}); - assertEquals(scope.eval('add(1,2)'), 3); - - scope.set('math.add', function (a, b) {return a+b;}); - assertEquals(scope.eval('math.add(1,2)'), 3); -}; - -ScopeTest.prototype.testValidationEval = function(){ - expectAsserts(4); - var scope = new Scope(); - scope.set("name", "misko"); - angular.validator.testValidator = function(value, expect){ - assertEquals("misko", this.name); - return value == expect ? null : "Error text"; - }; - - assertEquals("Error text", scope.validate("testValidator:'abc'", 'x')); - assertEquals(null, scope.validate("testValidator:'abc'", 'abc')); - - delete angular.validator['testValidator']; -}; - -ScopeTest.prototype.testCallingNonExistantMethodShouldProduceFriendlyException = function() { - expectAsserts(1); - var scope = new Scope({obj:{}}); - try { - scope.eval("obj.iDontExist()"); - fail(); - } catch (e) { - assertEquals("Expression 'obj.iDontExist' is not a function.", e); - } -}; - -ScopeTest.prototype.testAccessingWithInvalidPathShouldThrowError = function() { - var scope = new Scope(); - try { - scope.get('a.{{b}}'); - fail(); - } catch (e) { - assertEquals("Expression 'a.{{b}}' is not a valid expression for accesing variables.", e); - } -}; - -ScopeTest.prototype.testItShouldHave$parent = function() { - var parent = new Scope({}, "ROOT"); - var child = new Scope(parent.state); - assertSame("parent", child.state.$parent, parent.state); - assertSame("root", child.state.$root, parent.state); -}; - -ScopeTest.prototype.testItShouldHave$root = function() { - var scope = new Scope({}, "ROOT"); - assertSame(scope.state.$root, scope.state); -}; - -ScopeTest.prototype.testItShouldBuildPathOnUndefined = function(){ - var scope = new Scope({}, "ROOT"); - scope.setEval("a.$b.c", 1); - assertJsonEquals({$b:{c:1}}, scope.get("a")); -}; - -ScopeTest.prototype.testItShouldMapUnderscoreFunctions = function(){ - var scope = new Scope({}, "ROOT"); - scope.set("a", [1,2,3]); - assertEquals('function', typeof scope.get("a.$size")); - scope.eval("a.$includeIf(4,true)"); - assertEquals(4, scope.get("a.$size")()); - assertEquals(4, scope.eval("a.$size()")); - assertEquals('undefined', typeof scope.get("a.dontExist")); -}; diff --git a/test/ServerTest.js b/test/ServerTest.js deleted file mode 100644 index 02fab84c..00000000 --- a/test/ServerTest.js +++ /dev/null @@ -1,42 +0,0 @@ -ServerTest = TestCase("ServerTest"); -ServerTest.prototype.testBreakLargeRequestIntoPackets = function() { - var log = ""; - var server = new Server("http://server", function(url){ - log += "|" + url; - }); - server.maxSize = 30; - server.uuid = "uuid"; - server.request("POST", "/data/database", {}, function(code, r){ - assertEquals(200, code); - assertEquals("response", r); - }); - angularCallbacks.uuid0("response"); - assertEquals( - "|http://server/$/uuid0/2/1?h=eyJtIjoiUE9TVCIsInAiOnt9LCJ1Ij" + - "|http://server/$/uuid0/2/2?h=oiL2RhdGEvZGF0YWJhc2UifQ==", - log); -}; - -ServerTest.prototype.testItShouldEncodeUsingUrlRules = function() { - var server = new Server("http://server"); - assertEquals("fn5-fn5-", server.base64url("~~~~~~")); - assertEquals("fn5_fn5_", server.base64url("~~\u007f~~\u007f")); -}; - -FrameServerTest = TestCase("FrameServerTest"); - -FrameServerTest.prototype = { - testRead:function(){ - var window = {name:'$DATASET:"MyData"'}; - var server = new FrameServer(window); - server.read(); - assertEquals("MyData", server.data); - }, - testWrite:function(){ - var window = {}; - var server = new FrameServer(window); - server.data = "TestData"; - server.write(); - assertEquals('$DATASET:"TestData"', window.name); - } -}; diff --git a/test/UsersTest.js b/test/UsersTest.js deleted file mode 100644 index f0ff545a..00000000 --- a/test/UsersTest.js +++ /dev/null @@ -1,26 +0,0 @@ -// Copyright (C) 2008,2009 BRAT Tech LLC - -UsersTest = TestCase("UsersTest"); - -UsersTest.prototype = { - setUp:function(){}, - - tearDown:function(){}, - - testItShouldFetchCurrentUser:function(){ - expectAsserts(5); - var user; - var users = new Users({request:function(method, url, request, callback){ - assertEquals("GET", method); - assertEquals("/account.json", url); - assertEquals("{}", toJson(request)); - callback(200, {$status_code:200, user:{name:'misko'}}); - }}); - users.fetchCurrentUser(function(u){ - user = u; - assertEquals("misko", u.name); - assertEquals("misko", users.current.name); - }); - } - -}; diff --git a/test/delete/ScopeTest.js b/test/delete/ScopeTest.js new file mode 100644 index 00000000..24febf19 --- /dev/null +++ b/test/delete/ScopeTest.js @@ -0,0 +1,145 @@ +ScopeTest = TestCase('ScopeTest'); + +ScopeTest.prototype.testGetScopeRetrieval = function(){ + var scope = {}; + var form = jQuery(""); + form.data('scope', scope); + var c = form.find('c'); + assertTrue(scope === c.scope()); +}; + +ScopeTest.prototype.testGetScopeRetrievalIntermediateNode = function(){ + var scope = {}; + var form = jQuery(""); + form.find("b").data('scope', scope); + var b = form.find('b'); + assertTrue(scope === b.scope()); +}; + +ScopeTest.prototype.testNoScopeDoesNotCauseInfiniteRecursion = function(){ + var form = jQuery(""); + var c = form.find('c'); + assertTrue(!c.scope()); +}; + +ScopeTest.prototype.testScopeEval = function(){ + var scope = new Scope({b:345}); + assertEquals(scope.eval('b = 123'), 123); + assertEquals(scope.get('b'), 123); +}; + +ScopeTest.prototype.testScopeFromPrototype = function(){ + var scope = new Scope({b:123}); + scope.eval('a = b'); + scope.eval('b = 456'); + assertEquals(scope.get('a'), 123); + assertEquals(scope.get('b'), 456); +}; + +ScopeTest.prototype.testSetScopeGet = function(){ + var scope = new Scope(); + assertEquals(987, scope.set('a', 987)); + assertEquals(scope.get('a'), 987); + assertEquals(scope.eval('a'), 987); +}; + +ScopeTest.prototype.testGetChain = function(){ + var scope = new Scope({a:{b:987}}); + assertEquals(scope.get('a.b'), 987); + assertEquals(scope.eval('a.b'), 987); +}; + +ScopeTest.prototype.testGetUndefinedChain = function(){ + var scope = new Scope(); + assertEquals(typeof scope.get('a.b'), 'undefined'); +}; + +ScopeTest.prototype.testSetChain = function(){ + var scope = new Scope({a:{}}); + scope.set('a.b', 987); + assertEquals(scope.get('a.b'), 987); + assertEquals(scope.eval('a.b'), 987); +}; + +ScopeTest.prototype.testSetGetOnChain = function(){ + var scope = new Scope(); + scope.set('a.b', 987); + assertEquals(scope.get('a.b'), 987); + assertEquals(scope.eval('a.b'), 987); +}; + +ScopeTest.prototype.testGlobalFunctionAccess =function(){ + window['scopeAddTest'] = function (a, b) {return a+b;}; + var scope = new Scope({window:window}); + assertEquals(scope.eval('window.scopeAddTest(1,2)'), 3); + + scope.set('add', function (a, b) {return a+b;}); + assertEquals(scope.eval('add(1,2)'), 3); + + scope.set('math.add', function (a, b) {return a+b;}); + assertEquals(scope.eval('math.add(1,2)'), 3); +}; + +ScopeTest.prototype.testValidationEval = function(){ + expectAsserts(4); + var scope = new Scope(); + scope.set("name", "misko"); + angular.validator.testValidator = function(value, expect){ + assertEquals("misko", this.name); + return value == expect ? null : "Error text"; + }; + + assertEquals("Error text", scope.validate("testValidator:'abc'", 'x')); + assertEquals(null, scope.validate("testValidator:'abc'", 'abc')); + + delete angular.validator['testValidator']; +}; + +ScopeTest.prototype.testCallingNonExistantMethodShouldProduceFriendlyException = function() { + expectAsserts(1); + var scope = new Scope({obj:{}}); + try { + scope.eval("obj.iDontExist()"); + fail(); + } catch (e) { + assertEquals("Expression 'obj.iDontExist' is not a function.", e); + } +}; + +ScopeTest.prototype.testAccessingWithInvalidPathShouldThrowError = function() { + var scope = new Scope(); + try { + scope.get('a.{{b}}'); + fail(); + } catch (e) { + assertEquals("Expression 'a.{{b}}' is not a valid expression for accesing variables.", e); + } +}; + +ScopeTest.prototype.testItShouldHave$parent = function() { + var parent = new Scope({}, "ROOT"); + var child = new Scope(parent.state); + assertSame("parent", child.state.$parent, parent.state); + assertSame("root", child.state.$root, parent.state); +}; + +ScopeTest.prototype.testItShouldHave$root = function() { + var scope = new Scope({}, "ROOT"); + assertSame(scope.state.$root, scope.state); +}; + +ScopeTest.prototype.testItShouldBuildPathOnUndefined = function(){ + var scope = new Scope({}, "ROOT"); + scope.setEval("a.$b.c", 1); + assertJsonEquals({$b:{c:1}}, scope.get("a")); +}; + +ScopeTest.prototype.testItShouldMapUnderscoreFunctions = function(){ + var scope = new Scope({}, "ROOT"); + scope.set("a", [1,2,3]); + assertEquals('function', typeof scope.get("a.$size")); + scope.eval("a.$includeIf(4,true)"); + assertEquals(4, scope.get("a.$size")()); + assertEquals(4, scope.eval("a.$size()")); + assertEquals('undefined', typeof scope.get("a.dontExist")); +}; diff --git a/test/moveToAngularCom/Base64Test.js b/test/moveToAngularCom/Base64Test.js new file mode 100644 index 00000000..a9353186 --- /dev/null +++ b/test/moveToAngularCom/Base64Test.js @@ -0,0 +1,5 @@ +Base64Test = TestCase('Base64Test'); + +Base64Test.prototype.testEncodeDecode = function(){ + assertEquals(Base64.decode(Base64.encode('hello')), 'hello'); +}; diff --git a/test/moveToAngularCom/DataStoreTest.js b/test/moveToAngularCom/DataStoreTest.js new file mode 100644 index 00000000..87c5be2e --- /dev/null +++ b/test/moveToAngularCom/DataStoreTest.js @@ -0,0 +1,616 @@ +DataStoreTest = TestCase('DataStoreTest'); + +DataStoreTest.prototype.testSavePostsToServer = function(){ + expectAsserts(10); + var response; + var post = function(data, callback){ + var method = data[0][0]; + var posted = data[0][2]; + assertEquals("POST", method); + assertEquals("abc", posted.$entity); + assertEquals("123", posted.$id); + assertEquals("1", posted.$version); + assertFalse('function' == typeof posted.save); + response = fromJson(toJson(posted)); + response.$entity = "abc"; + response.$id = "123"; + response.$version = "2"; + callback(200, [response]); + }; + var datastore = new DataStore(post); + var model = datastore.entity('abc', {name: "value"})(); + model.$id = "123"; + model.$version = "1"; + + datastore.save(model, function(obj){ + assertTrue(obj === model); + assertEquals(obj.$entity, "abc"); + assertEquals(obj.$id, "123"); + assertEquals(obj.$version, "2"); + assertEquals(obj.name, "value"); + obj.after = true; + }); + datastore.flush(); +}; + +DataStoreTest.prototype.testLoadGetsFromServer = function(){ + expectAsserts(12); + var post = function(data, callback){ + var method = data[0][0]; + var path = data[0][1]; + assertEquals("GET", method); + assertEquals("abc/1", path); + response = [{$entity:'abc', $id:'1', $version:'2', key:"value"}]; + callback(200, response); + }; + var datastore = new DataStore(post); + + var model = datastore.entity("abc", {merge:true})(); + assertEquals(datastore.load(model, '1', function(obj){ + assertEquals(obj.$entity, "abc"); + assertEquals(obj.$id, "1"); + assertEquals(obj.$version, "2"); + assertEquals(obj.key, "value"); + }), model); + datastore.flush(); + assertEquals(model.$entity, "abc"); + assertEquals(model.$id, "1"); + assertEquals(model.$version, "2"); + assertEquals(model.key, "value"); + assertEquals(model.merge, true); +}; + +DataStoreTest.prototype.testRemove = function(){ + expectAsserts(8); + var response; + var post = function(data, callback){ + var method = data[0][0]; + var posted = data[0][2]; + assertEquals("DELETE", method); + assertEquals("abc", posted.$entity); + assertEquals("123", posted.$id); + assertEquals("1", posted.$version); + assertFalse('function' == typeof posted.save); + response = fromJson(toJson(posted)); + response.$entity = "abc"; + response.$id = "123"; + response.$version = "2"; + callback(200, [response]); + }; + var model; + var datastore = new DataStore(post); + model = datastore.entity('abc', {name: "value"})(); + model.$id = "123"; + model.$version = "1"; + + datastore.remove(model, function(obj){ + assertEquals(obj.$id, "123"); + assertEquals(obj.$version, "2"); + assertEquals(obj.name, "value"); + obj.after = true; + }); + datastore.flush(); + +}; + + +DataStoreTest.prototype.test401ResponseDoesNotCallCallback = function(){ + expectAsserts(1); + var post = function(data, callback) { + callback(200, {$status_code: 401}); + }; + + var datastore = new DataStore(post, {login:function(){ + assertTrue(true); + }}); + + var onLoadAll = function(){ + assertTrue(false, "onLoadAll should not be called when response is status 401"); + }; + datastore.bulkRequest.push({}); + datastore.flush(); + datastore.loadAll({type: "A"}, onLoadAll); +}; + +DataStoreTest.prototype.test403ResponseDoesNotCallCallback = function(){ + expectAsserts(1); + var post = function(data, callback) { + callback(200, [{$status_code: 403}]); + }; + + var datastore = new DataStore(post, {notAuthorized:function(){ + assertTrue(true); + }}); + + var onLoadAll = function(){ + assertTrue(false, "onLoadAll should not be called when response is status 403"); + }; + datastore.bulkRequest.push({}); + datastore.flush(); + datastore.loadAll({type: "A"}, onLoadAll); +}; + +DataStoreTest.prototype.testLoadCalledWithoutIdShouldBeNoop = function(){ + expectAsserts(2); + var post = function(url, callback){ + assertTrue(false); + }; + var datastore = new DataStore(post); + var model = datastore.entity("abc")(); + assertEquals(datastore.load(model, undefined), model); + assertEquals(model.$entity, "abc"); +}; + +DataStoreTest.prototype.testEntityFactory = function(){ + var ds = new DataStore(); + var Recipe = ds.entity("Recipe", {a:1, b:2}); + assertEquals(Recipe.title, "Recipe"); + assertEquals(Recipe.defaults.a, 1); + assertEquals(Recipe.defaults.b, 2); + + var recipe = Recipe(); + assertEquals(recipe.$entity, "Recipe"); + assertEquals(recipe.a, 1); + assertEquals(recipe.b, 2); + + recipe = new Recipe(); + assertEquals(recipe.$entity, "Recipe"); + assertEquals(recipe.a, 1); + assertEquals(recipe.b, 2); +}; + +DataStoreTest.prototype.testEntityFactoryNoDefaults = function(){ + var ds = new DataStore(); + var Recipe = ds.entity("Recipe"); + assertEquals(Recipe.title, "Recipe"); + + recipe = new Recipe(); + assertEquals(recipe.$entity, "Recipe"); +}; + +DataStoreTest.prototype.testEntityFactoryWithInitialValues = function(){ + var ds = new DataStore(); + var Recipe = ds.entity("Recipe"); + + var recipe = Recipe({name: "name"}); + assertEquals("name", recipe.name); +}; + +DataStoreTest.prototype.testEntityLoad = function(){ + var ds = new DataStore(); + var Recipe = ds.entity("Recipe", {a:1, b:2}); + ds.load = function(instance, id, callback){ + callback.apply(instance); + return instance; + }; + var instance = null; + var recipe2 = Recipe.load("ID", function(){ + instance = this; + }); + assertTrue(recipe2 === instance); +}; + +DataStoreTest.prototype.testSaveScope = function(){ + var ds = new DataStore(); + var log = ""; + var Person = ds.entity("Person"); + var person1 = Person({name:"A", $entity:"Person", $id:"1", $version:"1"}, ds); + person1.$$anchor = "A"; + var person2 = Person({name:"B", $entity:"Person", $id:"2", $version:"2"}, ds); + person2.$$anchor = "B"; + var anchor = {}; + ds.anchor = anchor; + ds._jsonRequest = function(request, callback){ + log += "save(" + request[2].$id + ");"; + callback({$id:request[2].$id}); + }; + ds.saveScope({person1:person1, person2:person2, + ignoreMe:{name: "ignore", save:function(callback){callback();}}}, function(){ + log += "done();"; + }); + assertEquals("save(1);save(2);done();", log); + assertEquals(1, anchor.A); + assertEquals(2, anchor.B); +}; + +DataStoreTest.prototype.testEntityLoadAllRows = function(){ + var ds = new DataStore(); + var Recipe = ds.entity("Recipe"); + var list = []; + ds.loadAll = function(entity, callback){ + assertTrue(Recipe === entity); + callback.apply(list); + return list; + }; + var items = Recipe.all(function(){ + assertTrue(list === this); + }); + assertTrue(items === list); +}; + +DataStoreTest.prototype.testLoadAll = function(){ + expectAsserts(8); + var post = function(data, callback){ + assertEquals("GET", data[0][0]); + assertEquals("A", data[0][1]); + callback(200, [[{$entity:'A', $id:'1'},{$entity:'A', $id:'2'}]]); + }; + var datastore = new DataStore(post); + var list = datastore.entity("A").all(function(){ + assertTrue(true); + }); + datastore.flush(); + assertEquals(list.length, 2); + assertEquals(list[0].$entity, "A"); + assertEquals(list[0].$id, "1"); + assertEquals(list[1].$entity, "A"); + assertEquals(list[1].$id, "2"); +}; + +DataStoreTest.prototype.testQuery = function(){ + expectAsserts(5); + var post = function(data, callback) { + assertEquals("GET", data[0][0]); + assertEquals("Employee/managerId=123abc", data[0][1]); + callback(200, [[{$entity:"Employee", $id: "456", managerId: "123ABC"}]]); + + }; + var datastore = new DataStore(post); + var Employee = datastore.entity("Employee"); + var list = Employee.query('managerId', "123abc", function(){ + assertTrue(true); + }); + datastore.flush(); + assertJsonEquals([[{$entity:"Employee", $id: "456", managerId: "123ABC"}]], datastore._cache.$collections); + assertEquals(list[0].$id, "456"); +}; + +DataStoreTest.prototype.testLoadingDocumentRefreshesExistingArrays = function() { + expectAsserts(12); + var post; + var datastore = new DataStore(function(r, c){post(r,c);}); + var Book = datastore.entity('Book'); + post = function(req, callback) { + callback(200, [[{$id:1, $entity:"Book", name:"Moby"}, + {$id:2, $entity:"Book", name:"Dick"}]]); + }; + var allBooks = Book.all(); + datastore.flush(); + var queryBooks = Book.query("a", "b"); + datastore.flush(); + assertEquals("Moby", allBooks[0].name); + assertEquals("Dick", allBooks[1].name); + assertEquals("Moby", queryBooks[0].name); + assertEquals("Dick", queryBooks[1].name); + + post = function(req, callback) { + assertEquals('[["GET","Book/1"]]', toJson(req)); + callback(200, [{$id:1, $entity:"Book", name:"Moby Dick"}]); + }; + var book = Book.load(1); + datastore.flush(); + assertEquals("Moby Dick", book.name); + assertEquals("Moby Dick", allBooks[0].name); + assertEquals("Moby Dick", queryBooks[0].name); + + post = function(req, callback) { + assertEquals('POST', req[0][0]); + callback(200, [{$id:1, $entity:"Book", name:"The Big Fish"}]); + }; + book.$save(); + datastore.flush(); + assertEquals("The Big Fish", book.name); + assertEquals("The Big Fish", allBooks[0].name); + assertEquals("The Big Fish", queryBooks[0].name); +}; + +DataStoreTest.prototype.testEntityProperties = function() { + expectAsserts(2); + var datastore = new DataStore(); + var callback = {}; + + datastore._jsonRequest = function(request, callbackFn) { + assertJsonEquals(["GET", "Cheese/$properties"], request); + assertEquals(callback, callbackFn); + }; + + var Cheese = datastore.entity("Cheese"); + Cheese.properties(callback); + +}; + +DataStoreTest.prototype.testLoadInstanceIsNotFromCache = function() { + var post; + var datastore = new DataStore(function(r, c){post(r,c);}); + var Book = datastore.entity('Book'); + + post = function(req, callback) { + assertEquals('[["GET","Book/1"]]', toJson(req)); + callback(200, [{$id:1, $entity:"Book", name:"Moby Dick"}]); + }; + var book = Book.load(1); + datastore.flush(); + assertEquals("Moby Dick", book.name); + assertFalse(book === datastore._cache['Book/1']); +}; + +DataStoreTest.prototype.testLoadStarsIsNewDocument = function() { + var datastore = new DataStore(); + var Book = datastore.entity('Book'); + var book = Book.load('*'); + assertEquals('Book', book.$entity); +}; + +DataStoreTest.prototype.testUndefinedEntityReturnsNullValueObject = function() { + var datastore = new DataStore(); + var Entity = datastore.entity(undefined); + var all = Entity.all(); + assertEquals(0, all.length); +}; + +DataStoreTest.prototype.testFetchEntities = function(){ + expectAsserts(6); + var post = function(data, callback){ + assertJsonEquals(["GET", "$entities"], data[0]); + callback(200, [{A:0, B:0}]); + }; + var datastore = new DataStore(post); + var entities = datastore.entities(function(){ + assertTrue(true); + }); + datastore.flush(); + assertJsonEquals([], datastore.bulkRequest); + assertEquals(2, entities.length); + assertEquals("A", entities[0].title); + assertEquals("B", entities[1].title); +}; + +DataStoreTest.prototype.testItShouldMigrateSchema = function() { + var datastore = new DataStore(); + var Entity = datastore.entity("Entity", {a:[], user:{name:"Misko", email:""}}); + var doc = Entity().$loadFrom({b:'abc', user:{email:"misko@hevery.com"}}); + assertFalse( + toJson({a:[], b:'abc', user:{name:"Misko", email:"misko@hevery.com"}}) == + toJson(doc)); + doc.$migrate(); + assertEquals( + toJson({a:[], b:'abc', user:{name:"Misko", email:"misko@hevery.com"}}), + toJson(doc)); +}; + +DataStoreTest.prototype.testItShouldCollectRequestsForBulk = function() { + var ds = new DataStore(); + var Book = ds.entity("Book"); + var Library = ds.entity("Library"); + Book.all(); + Library.load("123"); + assertEquals(2, ds.bulkRequest.length); + assertJsonEquals(["GET", "Book"], ds.bulkRequest[0]); + assertJsonEquals(["GET", "Library/123"], ds.bulkRequest[1]); +}; + +DataStoreTest.prototype.testEmptyFlushShouldDoNothing = function () { + var ds = new DataStore(function(){ + fail("expecting noop"); + }); + ds.flush(); +}; + +DataStoreTest.prototype.testFlushShouldCallAllCallbacks = function() { + var log = ""; + function post(request, callback){ + log += 'BulkRequest:' + toJson(request) + ';'; + callback(200, [[{$id:'ABC'}], {$id:'XYZ'}]); + } + var ds = new DataStore(post); + var Book = ds.entity("Book"); + var Library = ds.entity("Library"); + Book.all(function(instance){ + log += toJson(instance) + ';'; + }); + Library.load("123", function(instance){ + log += toJson(instance) + ';'; + }); + assertEquals("", log); + ds.flush(); + assertJsonEquals([], ds.bulkRequest); + assertEquals('BulkRequest:[["GET","Book"],["GET","Library/123"]];[{"$id":"ABC"}];{"$id":"XYZ"};', log); +}; + +DataStoreTest.prototype.testSaveOnNotLoggedInRetriesAfterLoggin = function(){ + var log = ""; + var book; + var ds = new DataStore(null, {login:function(c){c();}}); + ds.post = function (request, callback){ + assertJsonEquals([["POST", "", book]], request); + ds.post = function(request, callback){ + assertJsonEquals([["POST", "", book]], request); + ds.post = function(){fail("too much recursion");}; + callback(200, [{saved:"ok"}]); + }; + callback(200, {$status_code:401}); + }; + book = ds.entity("Book")({name:"misko"}); + book.$save(); + ds.flush(); + assertJsonEquals({saved:"ok"}, book); +}; + +DataStoreTest.prototype.testItShouldRemoveItemFromCollectionWhenDeleted = function() { + expectAsserts(6); + var ds = new DataStore(); + ds.post = function(request, callback){ + assertJsonEquals([["GET", "Book"]], request); + callback(200, [[{name:"Moby Dick", $id:123, $entity:'Book'}]]); + }; + var Book = ds.entity("Book"); + var books = Book.all(); + ds.flush(); + assertJsonEquals([[{name:"Moby Dick", $id:123, $entity:'Book'}]], ds._cache.$collections); + assertDefined(ds._cache['Book/123']); + var book = Book({$id:123}); + ds.post = function(request, callback){ + assertJsonEquals([["DELETE", "", book]], request); + callback(200, [book]); + }; + ds.remove(book); + ds.flush(); + assertUndefined(ds._cache['Book/123']); + assertJsonEquals([[]],ds._cache.$collections); +}; + +DataStoreTest.prototype.testItShouldAddToAll = function() { + expectAsserts(8); + var ds = new DataStore(); + ds.post = function(request, callback){ + assertJsonEquals([["GET", "Book"]], request); + callback(200, [[]]); + }; + var Book = ds.entity("Book"); + var books = Book.all(); + assertEquals(0, books.length); + ds.flush(); + var moby = Book({name:'moby'}); + moby.$save(); + ds.post = function(request, callback){ + assertJsonEquals([["POST", "", moby]], request); + moby.$id = '123'; + callback(200, [moby]); + }; + ds.flush(); + assertEquals(1, books.length); + assertEquals(moby, books[0]); + + moby.$save(); + ds.flush(); + assertEquals(1, books.length); + assertEquals(moby, books[0]); +}; + +DataStoreTest.prototype.testItShouldReturnCreatedDocumentCountByUser = function(){ + expectAsserts(2); + var datastore = new DataStore( + function(request, callback){ + assertJsonEquals([["GET", "$users"]], request); + callback(200, [{misko:1, adam:1}]); + }); + var users = datastore.documentCountsByUser(); + assertJsonEquals({misko:1, adam:1}, users); +}; + + +DataStoreTest.prototype.testItShouldReturnDocumentIdsForUeserByEntity = function(){ + expectAsserts(2); + var datastore = new DataStore( + function(request, callback){ + assertJsonEquals([["GET", "$users/misko@hevery.com"]], request); + callback(200, [{Book:["1"], Library:["2"]}]); + }); + var users = datastore.userDocumentIdsByEntity("misko@hevery.com"); + assertJsonEquals({Book:["1"], Library:["2"]}, users); +}; + +DataStoreTest.prototype.testItShouldReturnNewInstanceOn404 = function(){ + expectAsserts(7); + var log = ""; + var datastore = new DataStore( + function(request, callback){ + assertJsonEquals([["GET", "User/misko"]], request); + callback(200, [{$status_code:404}]); + }); + var User = datastore.entity("User", {admin:false}); + var user = User.loadOrCreate('misko', function(i){log+="cb "+i.$id+";";}); + datastore.flush(); + assertEquals("misko", user.$id); + assertEquals("User", user.$entity); + assertEquals(false, user.admin); + assertEquals("undefined", typeof user.$secret); + assertEquals("undefined", typeof user.$version); + assertEquals("cb misko;", log); +}; + +DataStoreTest.prototype.testItShouldReturnNewInstanceOn404 = function(){ + var log = ""; + var datastore = new DataStore( + function(request, callback){ + assertJsonEquals([["GET", "User/misko"],["GET", "User/adam"]], request); + callback(200, [{$id:'misko'},{$id:'adam'}]); + }); + var User = datastore.entity("User"); + var users = User.loadMany(['misko', 'adam'], function(i){log+="cb "+toJson(i)+";";}); + datastore.flush(); + assertEquals("misko", users[0].$id); + assertEquals("adam", users[1].$id); + assertEquals('cb [{"$id":"misko"},{"$id":"adam"}];', log); +}; + +DataStoreTest.prototype.testItShouldCreateJoinAndQuery = function() { + var datastore = new DataStore(); + var Invoice = datastore.entity("Invoice"); + var Customer = datastore.entity("Customer"); + var InvoiceWithCustomer = datastore.join({ + invoice:{join:Invoice}, + customer:{join:Customer, on:"invoice.customer"} + }); + var invoiceWithCustomer = InvoiceWithCustomer.query("invoice.month", 1); + assertEquals([], invoiceWithCustomer); + assertJsonEquals([["GET", "Invoice/month=1"]], datastore.bulkRequest); + var request = datastore.bulkRequest.shift(); + request.$$callback([{$id:1, customer:1},{$id:2, customer:1},{$id:3, customer:3}]); + assertJsonEquals([["GET","Customer/1"],["GET","Customer/3"]], datastore.bulkRequest); + datastore.bulkRequest.shift().$$callback({$id:1}); + datastore.bulkRequest.shift().$$callback({$id:3}); + assertJsonEquals([ + {invoice:{$id:1,customer:1},customer:{$id:1}}, + {invoice:{$id:2,customer:1},customer:{$id:1}}, + {invoice:{$id:3,customer:3},customer:{$id:3}}], invoiceWithCustomer); +}; + +DataStoreTest.prototype.testItShouldThrowIfMoreThanOneEntityIsPrimary = function() { + var datastore = new DataStore(); + var Invoice = datastore.entity("Invoice"); + var Customer = datastore.entity("Customer"); + assertThrows("Exactly one entity needs to be primary.", function(){ + datastore.join({ + invoice:{join:Invoice}, + customer:{join:Customer} + }); + }); +}; + +DataStoreTest.prototype.testItShouldThrowIfLoopInReferences = function() { + var datastore = new DataStore(); + var Invoice = datastore.entity("Invoice"); + var Customer = datastore.entity("Customer"); + assertThrows("Infinite loop in join: invoice -> customer", function(){ + datastore.join({ + invoice:{join:Invoice, on:"customer.invoice"}, + customer:{join:Customer, on:"invoice.customer"} + }); + }); +}; + +DataStoreTest.prototype.testItShouldThrowIfReferenceToNonExistantJoin = function() { + var datastore = new DataStore(); + var Invoice = datastore.entity("Invoice"); + var Customer = datastore.entity("Customer"); + assertThrows("Named entity 'x' is undefined.", function(){ + datastore.join({ + invoice:{join:Invoice, on:"x.invoice"}, + customer:{join:Customer, on:"invoice.customer"} + }); + }); +}; + +DataStoreTest.prototype.testItShouldThrowIfQueryOnNonPrimary = function() { + var datastore = new DataStore(); + var Invoice = datastore.entity("Invoice"); + var Customer = datastore.entity("Customer"); + var InvoiceWithCustomer = datastore.join({ + invoice:{join:Invoice}, + customer:{join:Customer, on:"invoice.customer"} + }); + assertThrows("Named entity 'customer' is not a primary entity.", function(){ + InvoiceWithCustomer.query("customer.month", 1); + }); +}; diff --git a/test/moveToAngularCom/EntityDeclarationTest.js b/test/moveToAngularCom/EntityDeclarationTest.js new file mode 100644 index 00000000..28986ea8 --- /dev/null +++ b/test/moveToAngularCom/EntityDeclarationTest.js @@ -0,0 +1,50 @@ +EntityDeclarationTest = TestCase('EntityDeclarationTest'); + +EntityDeclarationTest.prototype.testEntityTypeOnly = function(){ + expectAsserts(2); + var datastore = {entity:function(name){ + assertEquals("Person", name); + }}; + var scope = new Scope(); + var init = scope.entity("Person", datastore); + assertEquals("", init); +}; + +EntityDeclarationTest.prototype.testWithDefaults = function(){ + expectAsserts(4); + var datastore = {entity:function(name, init){ + assertEquals("Person", name); + assertEquals("=a:", init.a); + assertEquals(0, init.b.length); + }}; + var scope = new Scope(); + var init = scope.entity('Person:{a:"=a:", b:[]}', datastore); + assertEquals("", init); +}; + +EntityDeclarationTest.prototype.testWithName = function(){ + expectAsserts(2); + var datastore = {entity:function(name, init){ + assertEquals("Person", name); + return function (){ return {}; }; + }}; + var scope = new Scope(); + var init = scope.entity('friend=Person', datastore); + assertEquals("$anchor.friend:{friend=Person.load($anchor.friend);friend.$$anchor=\"friend\";};", init); +}; + +EntityDeclarationTest.prototype.testMultipleEntities = function(){ + expectAsserts(3); + var expect = ['Person', 'Book']; + var i=0; + var datastore = {entity:function(name, init){ + assertEquals(expect[i], name); + i++; + return function (){ return {}; }; + }}; + var scope = new Scope(); + var init = scope.entity('friend=Person;book=Book;', datastore); + assertEquals("$anchor.friend:{friend=Person.load($anchor.friend);friend.$$anchor=\"friend\";};" + + "$anchor.book:{book=Book.load($anchor.book);book.$$anchor=\"book\";};", + init); +}; diff --git a/test/moveToAngularCom/ModelTest.js b/test/moveToAngularCom/ModelTest.js new file mode 100644 index 00000000..dbd97778 --- /dev/null +++ b/test/moveToAngularCom/ModelTest.js @@ -0,0 +1,84 @@ +ModelTest = TestCase('ModelTest'); + +ModelTest.prototype.testLoadSaveOperations = function(){ + var m1 = new DataStore().entity('A')(); + m1.a = 1; + + var m2 = {b:1}; + + m1.$loadFrom(m2); + + assertTrue(!m1.a); + assertEquals(m1.b, 1); +}; + +ModelTest.prototype.testLoadfromDoesNotClobberFunctions = function(){ + var m1 = new DataStore().entity('A')(); + m1.id = function(){return 'OK';}; + m1.$loadFrom({id:null}); + assertEquals(m1.id(), 'OK'); + + m1.b = 'OK'; + m1.$loadFrom({b:function(){}}); + assertEquals(m1.b, 'OK'); +}; + +ModelTest.prototype.testDataStoreDoesNotGetClobbered = function(){ + var ds = new DataStore(); + var m = ds.entity('A')(); + assertTrue(m.$$entity.datastore === ds); + m.$loadFrom({}); + assertTrue(m.$$entity.datastore === ds); +}; + +ModelTest.prototype.testManagedModelDelegatesMethodsToDataStore = function(){ + expectAsserts(7); + var datastore = new DataStore(); + var model = datastore.entity("A", {a:1})(); + var fn = {}; + datastore.save = function(instance, callback) { + assertTrue(model === instance); + assertTrue(callback === fn); + }; + datastore.remove = function(instance, callback) { + assertTrue(model === instance); + assertTrue(callback === fn); + }; + datastore.load = function(instance, id, callback) { + assertTrue(model === instance); + assertTrue(id === "123"); + assertTrue(callback === fn); + }; + model.$save(fn); + model.$delete(fn); + model.$loadById("123", fn); +}; + +ModelTest.prototype.testManagedModelCanBeForcedToFlush = function(){ + expectAsserts(6); + var datastore = new DataStore(); + var model = datastore.entity("A", {a:1})(); + + datastore.save = function(instance, callback) { + assertTrue(model === instance); + assertTrue(callback === undefined); + }; + datastore.remove = function(instance, callback) { + assertTrue(model === instance); + assertTrue(callback === undefined); + }; + datastore.flush = function(){ + assertTrue(true); + }; + model.$save(true); + model.$delete(true); +}; + + +ModelTest.prototype.testItShouldMakeDeepCopyOfInitialValues = function (){ + var initial = {a:[]}; + var entity = new DataStore().entity("A", initial); + var model = entity(); + model.a.push(1); + assertEquals(0, entity().a.length); +}; diff --git a/test/moveToAngularCom/ServerTest.js b/test/moveToAngularCom/ServerTest.js new file mode 100644 index 00000000..02fab84c --- /dev/null +++ b/test/moveToAngularCom/ServerTest.js @@ -0,0 +1,42 @@ +ServerTest = TestCase("ServerTest"); +ServerTest.prototype.testBreakLargeRequestIntoPackets = function() { + var log = ""; + var server = new Server("http://server", function(url){ + log += "|" + url; + }); + server.maxSize = 30; + server.uuid = "uuid"; + server.request("POST", "/data/database", {}, function(code, r){ + assertEquals(200, code); + assertEquals("response", r); + }); + angularCallbacks.uuid0("response"); + assertEquals( + "|http://server/$/uuid0/2/1?h=eyJtIjoiUE9TVCIsInAiOnt9LCJ1Ij" + + "|http://server/$/uuid0/2/2?h=oiL2RhdGEvZGF0YWJhc2UifQ==", + log); +}; + +ServerTest.prototype.testItShouldEncodeUsingUrlRules = function() { + var server = new Server("http://server"); + assertEquals("fn5-fn5-", server.base64url("~~~~~~")); + assertEquals("fn5_fn5_", server.base64url("~~\u007f~~\u007f")); +}; + +FrameServerTest = TestCase("FrameServerTest"); + +FrameServerTest.prototype = { + testRead:function(){ + var window = {name:'$DATASET:"MyData"'}; + var server = new FrameServer(window); + server.read(); + assertEquals("MyData", server.data); + }, + testWrite:function(){ + var window = {}; + var server = new FrameServer(window); + server.data = "TestData"; + server.write(); + assertEquals('$DATASET:"TestData"', window.name); + } +}; diff --git a/test/moveToAngularCom/UsersTest.js b/test/moveToAngularCom/UsersTest.js new file mode 100644 index 00000000..f0ff545a --- /dev/null +++ b/test/moveToAngularCom/UsersTest.js @@ -0,0 +1,26 @@ +// Copyright (C) 2008,2009 BRAT Tech LLC + +UsersTest = TestCase("UsersTest"); + +UsersTest.prototype = { + setUp:function(){}, + + tearDown:function(){}, + + testItShouldFetchCurrentUser:function(){ + expectAsserts(5); + var user; + var users = new Users({request:function(method, url, request, callback){ + assertEquals("GET", method); + assertEquals("/account.json", url); + assertEquals("{}", toJson(request)); + callback(200, {$status_code:200, user:{name:'misko'}}); + }}); + users.fetchCurrentUser(function(u){ + user = u; + assertEquals("misko", u.name); + assertEquals("misko", users.current.name); + }); + } + +}; -- cgit v1.2.3 From e55c97debaa0ef8487ece219b6eadbc147ece1f9 Mon Sep 17 00:00:00 2001 From: Misko Hevery Date: Mon, 29 Mar 2010 20:25:42 -0700 Subject: dissabled a lot of tests, and made the core test set pass. --- test/AngularSpec.js | 6 +- test/ApiTest.js | 16 +- test/BinderTest.js | 797 +++++++++++++++++++-------------------------- test/ConsoleTest.js | 12 +- test/FileControllerTest.js | 12 +- test/FiltersTest.js | 40 +-- test/ParserTest.js | 326 +++++++++--------- test/ResourceSpec.js | 2 +- test/ScenarioSpec.js | 62 ++-- test/ValidatorsTest.js | 22 +- test/WidgetsTest.js | 268 --------------- test/delete/WidgetsTest.js | 268 +++++++++++++++ test/directivesSpec.js | 12 +- test/markupSpec.js | 97 +++++- test/testabilityPatch.js | 33 +- test/widgetsSpec.js | 2 +- 16 files changed, 948 insertions(+), 1027 deletions(-) delete mode 100644 test/WidgetsTest.js create mode 100644 test/delete/WidgetsTest.js (limited to 'test') diff --git a/test/AngularSpec.js b/test/AngularSpec.js index 043f7bf3..60079c47 100644 --- a/test/AngularSpec.js +++ b/test/AngularSpec.js @@ -1,10 +1,10 @@ describe('Angular', function(){ - it('should fire on updateEvents', function(){ + xit('should fire on updateEvents', function(){ var onUpdateView = jasmine.createSpy(); var scope = angular.compile("
                ", { onUpdateView: onUpdateView }); expect(onUpdateView).wasNotCalled(); - scope.init(); - scope.updateView(); + scope.$init(); + scope.$eval(); expect(onUpdateView).wasCalled(); }); }); diff --git a/test/ApiTest.js b/test/ApiTest.js index fc9190ed..19860822 100644 --- a/test/ApiTest.js +++ b/test/ApiTest.js @@ -10,7 +10,7 @@ ApiTest.prototype.testItShouldReturnTypeOf = function (){ assertEquals("element", angular.Object.typeOf(document.body)); assertEquals("function", angular.Object.typeOf(function(){})); }; - + ApiTest.prototype.testItShouldReturnSize = function(){ assertEquals(0, angular.Collection.size({})); assertEquals(1, angular.Collection.size({a:"b"})); @@ -24,18 +24,18 @@ ApiTest.prototype.testIncludeIf = function() { angular.Array.includeIf(array, obj, true); angular.Array.includeIf(array, obj, true); - assertTrue(_.include(array, obj)); + assertTrue(includes(array, obj)); assertEquals(1, array.length); angular.Array.includeIf(array, obj, false); - assertFalse(_.include(array, obj)); + assertFalse(includes(array, obj)); assertEquals(0, array.length); angular.Array.includeIf(array, obj, 'x'); - assertTrue(_.include(array, obj)); + assertTrue(includes(array, obj)); assertEquals(1, array.length); angular.Array.includeIf(array, obj, ''); - assertFalse(_.include(array, obj)); + assertFalse(includes(array, obj)); assertEquals(0, array.length); }; @@ -187,11 +187,11 @@ ApiTest.prototype.testItShouldSortArrayInReverse = function() { }; ApiTest.prototype.testItShouldSortArrayByPredicate = function() { - assertJsonEquals([{a:2, b:1},{a:15, b:1}], + assertJsonEquals([{a:2, b:1},{a:15, b:1}], angular.Array.orderBy([{a:15, b:1},{a:2, b:1}], ['a', 'b'])); - assertJsonEquals([{a:2, b:1},{a:15, b:1}], + assertJsonEquals([{a:2, b:1},{a:15, b:1}], angular.Array.orderBy([{a:15, b:1},{a:2, b:1}], ['b', 'a'])); - assertJsonEquals([{a:15, b:1},{a:2, b:1}], + assertJsonEquals([{a:15, b:1},{a:2, b:1}], angular.Array.orderBy([{a:15, b:1},{a:2, b:1}], ['+b', '-a'])); }; diff --git a/test/BinderTest.js b/test/BinderTest.js index e37026e7..cc101f4d 100644 --- a/test/BinderTest.js +++ b/test/BinderTest.js @@ -1,289 +1,162 @@ BinderTest = TestCase('BinderTest'); -function compile(content, initialScope, config) { - var h = html(content); - config = config || {autoSubmit:true}; - var scope = new Scope($.extend({$invalidWidgets:[]}, initialScope), "ROOT"); - h.data('scope', scope); - var datastore = new DataStore(); - var binder = new Binder(h[0], new WidgetFactory(), datastore, new MockLocation(), config); - scope.set("$updateView", _(binder.updateView).bind(binder)); - scope.set("$anchor", binder.anchor); - binder.entity(scope); - binder.compile(); - return {node:h, binder:binder, scope:scope, datastore:datastore}; -} - -function compileToHtml(content) { - return compile(content).node.sortedHtml(); -} - -BinderTest.prototype.testParseTextWithNoBindings = function(){ - var parts = Binder.parseBindings("a"); - assertEquals(parts.length, 1); - assertEquals(parts[0], "a"); - assertTrue(!Binder.binding(parts[0])); -}; - -BinderTest.prototype.testParseEmptyText = function(){ - var parts = Binder.parseBindings(""); - assertEquals(parts.length, 1); - assertEquals(parts[0], ""); - assertTrue(!Binder.binding(parts[0])); -}; - -BinderTest.prototype.testParseInnerBinding = function(){ - var parts = Binder.parseBindings("a{{b}}c"); - assertEquals(parts.length, 3); - assertEquals(parts[0], "a"); - assertTrue(!Binder.binding(parts[0])); - assertEquals(parts[1], "{{b}}"); - assertEquals(Binder.binding(parts[1]), "b"); - assertEquals(parts[2], "c"); - assertTrue(!Binder.binding(parts[2])); -}; - -BinderTest.prototype.testParseEndingBinding = function(){ - var parts = Binder.parseBindings("a{{b}}"); - assertEquals(parts.length, 2); - assertEquals(parts[0], "a"); - assertTrue(!Binder.binding(parts[0])); - assertEquals(parts[1], "{{b}}"); - assertEquals(Binder.binding(parts[1]), "b"); -}; - -BinderTest.prototype.testParseBeggingBinding = function(){ - var parts = Binder.parseBindings("{{b}}c"); - assertEquals(parts.length, 2); - assertEquals(parts[0], "{{b}}"); - assertEquals(Binder.binding(parts[0]), "b"); - assertEquals(parts[1], "c"); - assertTrue(!Binder.binding(parts[1])); -}; - -BinderTest.prototype.testParseLoanBinding = function(){ - var parts = Binder.parseBindings("{{b}}"); - assertEquals(parts.length, 1); - assertEquals(parts[0], "{{b}}"); - assertEquals(Binder.binding(parts[0]), "b"); -}; - -BinderTest.prototype.testParseTwoBindings = function(){ - var parts = Binder.parseBindings("{{b}}{{c}}"); - assertEquals(parts.length, 2); - assertEquals(parts[0], "{{b}}"); - assertEquals(Binder.binding(parts[0]), "b"); - assertEquals(parts[1], "{{c}}"); - assertEquals(Binder.binding(parts[1]), "c"); -}; - -BinderTest.prototype.testParseTwoBindingsWithTextInMiddle = function(){ - var parts = Binder.parseBindings("{{b}}x{{c}}"); - assertEquals(parts.length, 3); - assertEquals(parts[0], "{{b}}"); - assertEquals(Binder.binding(parts[0]), "b"); - assertEquals(parts[1], "x"); - assertTrue(!Binder.binding(parts[1])); - assertEquals(parts[2], "{{c}}"); - assertEquals(Binder.binding(parts[2]), "c"); -}; - -BinderTest.prototype.testParseMultiline = function(){ - var parts = Binder.parseBindings('"X\nY{{A\nB}}C\nD"'); - assertTrue(!!Binder.binding('{{A\nB}}')); - assertEquals(parts.length, 3); - assertEquals(parts[0], '"X\nY'); - assertEquals(parts[1], '{{A\nB}}'); - assertEquals(parts[2], 'C\nD"'); -}; - -BinderTest.prototype.testHasBinding = function(){ - assertTrue(Binder.hasBinding("{{a}}")); - assertTrue(!Binder.hasBinding("a")); - assertTrue(Binder.hasBinding("{{b}}x{{c}}")); +BinderTest.prototype.setUp = function(){ + var self = this; + this.compile = function(html, initialScope, config) { + var compiler = new Compiler(angularTextMarkup, angularAttrMarkup, angularDirective, angularWidget); + var element = self.element = jqLite(html); + var scope = compiler.compile(element)(element); + extend(scope, initialScope); + scope.$init(); + return {node:element, scope:scope}; + }; + this.compileToHtml = function (content) { + return sortedHtml(this.compile(content).node); + }; }; - BinderTest.prototype.tearDown = function(){ - jQuery("*", document).die(); - jQuery(document).unbind(); + if (this.element) this.element.remove(); }; + BinderTest.prototype.testChangingTextfieldUpdatesModel = function(){ - var state = compile('', {model:{}}); - state.binder.updateView(); - assertEquals('abc', state.scope.get('model').price); + var state = this.compile('', {model:{}}); + state.scope.$eval(); + assertEquals('abc', state.scope.model.price); }; BinderTest.prototype.testChangingTextareaUpdatesModel = function(){ - var c = compile(''); - c.binder.updateView(); - assertEquals(c.scope.get('model').note, 'abc'); + var c = this.compile(''); + c.scope.$eval(); + assertEquals(c.scope.model.note, 'abc'); }; BinderTest.prototype.testChangingRadioUpdatesModel = function(){ - var c = compile('' + + var c = this.compile('' + ''); - c.binder.updateView(); - assertEquals(c.scope.get('model').price, 'A'); + c.scope.$eval(); + assertEquals(c.scope.model.price, 'A'); }; BinderTest.prototype.testChangingCheckboxUpdatesModel = function(){ - var form = compile(''); - form.scope.set('model', {}); - form.binder.updateView(); - assertEquals(true, form.scope.get('model').price); + var form = this.compile(''); + assertEquals(true, form.scope.model.price); }; BinderTest.prototype.testBindUpdate = function() { - var c = compile('
                '); - c.binder.updateView(); - assertEquals(123, c.scope.get('a')); + var c = this.compile('
                '); + assertEquals(123, c.scope.$get('a')); }; BinderTest.prototype.testChangingSelectNonSelectedUpdatesModel = function(){ - var form = compile(''); - form.scope.set('model', {}); - form.binder.updateView(); - assertEquals('A', form.scope.get('model').price); + var form = this.compile(''); + assertEquals('A', form.scope.model.price); }; BinderTest.prototype.testChangingMultiselectUpdatesModel = function(){ - var form = compile('' + '' + '' + '' + ''); - form.scope.set("Invoice", {}); - form.binder.updateView(); - assertJsonEquals(["A", "B"], form.scope.get('Invoice').options); + assertJsonEquals(["A", "B"], form.scope.$get('Invoice').options); }; BinderTest.prototype.testChangingSelectSelectedUpdatesModel = function(){ - var form = compile(''); - form.scope.set('model', {}); - form.binder.updateView(); - assertEquals(form.scope.get('model').price, 'b'); + var form = this.compile(''); + assertEquals(form.scope.model.price, 'b'); }; BinderTest.prototype.testExecuteInitialization = function() { - var form = html('
                '); - var scope = new Scope(); - form.data('scope', scope); - var binder = new Binder(form.get(0)); - binder.executeInit(); - assertEquals(scope.get('a'), 123); + var c = this.compile('
                '); + assertEquals(c.scope.$get('a'), 123); }; BinderTest.prototype.testExecuteInitializationStatements = function() { - var form = html('
                '); - var scope = new Scope(); - form.data('scope', scope); - var binder = new Binder(form.get(0)); - binder.executeInit(); - assertEquals(scope.get('a'), 123); - assertEquals(scope.get('b'), 345); + var c = this.compile('
                '); + assertEquals(c.scope.$get('a'), 123); + assertEquals(c.scope.$get('b'), 345); }; BinderTest.prototype.testApplyTextBindings = function(){ - var form = compile('
                x
                '); - form.scope.set('model', {a:123}); - form.binder.compile(); - form.binder.updateView(); + var form = this.compile('
                x
                '); + form.scope.$set('model', {a:123}); + form.scope.$eval(); assertEquals('123', form.node.text()); }; BinderTest.prototype.testReplaceBindingInTextWithSpan = function() { - assertEquals(compileToHtml("a{{b}}c"), 'ac'); - assertEquals(compileToHtml("{{b}}"), ''); -}; - -BinderTest.prototype.testReplaceBindingCreatesCorrectNumberOfWidgets = function() { - var h = html("space{{a}}{{a}}a{{a}}{{a}}"); - h.data('scope', new Scope()); - var binder = new Binder(h.get(0), new WidgetFactory()); - binder.compile(); - - assertEquals(4, h.scope().widgets.length); + assertEquals(this.compileToHtml("a{{b}}c"), 'ac'); + assertEquals(this.compileToHtml("{{b}}"), ''); }; -BinderTest.prototype.testBindingSpaceConfusesIE = function() { - if (!msie) return; +BinderTest.prototype.XtestBindingSpaceConfusesIE = function() { + //if (!msie) return; var span = document.createElement("span"); span.innerHTML = ' '; var nbsp = span.firstChild.nodeValue; assertEquals( ''+nbsp+'', - compileToHtml("{{a}} {{b}}")); + this.compileToHtml("{{a}} {{b}}")); assertEquals( ''+nbsp+'x '+nbsp+'(', - compileToHtml("{{A}} x {{B}} ({{C}})")); + this.compileToHtml("{{A}} x {{B}} ({{C}})")); }; BinderTest.prototype.testBindingOfAttributes = function() { - var form = html(""); - form.data('scope', new Scope()); - var binder = new Binder(form.get(0)); - binder.compile(); - var attrbinding = form.find("a").attr("ng-bind-attr"); + var c = this.compile(""); + var attrbinding = c.node.attr("ng-bind-attr"); var bindings = fromJson(attrbinding); assertEquals("http://s/a{{b}}c", decodeURI(bindings.href)); assertTrue(!bindings.foo); }; BinderTest.prototype.testMarkMultipleAttributes = function() { - var form = html(""); - form.data('scope', new Scope()); - var binder = new Binder(form.get(0)); - binder.compile(); - var attrbinding = form.find("a").attr("ng-bind-attr"); + var c = this.compile(''); + var attrbinding = c.node.attr("ng-bind-attr"); var bindings = fromJson(attrbinding); - assertEquals(decodeURI(bindings.href), "http://s/a{{b}}c"); assertEquals(bindings.foo, "{{d}}"); + assertEquals(decodeURI(bindings.href), "http://s/a{{b}}c"); }; BinderTest.prototype.testAttributesNoneBound = function() { - var form = html(""); - form.data('scope', new Scope()); - var binder = new Binder(form.get(0)); - binder.compile(); - var a = form.find("a"); - assertEquals(a.get(0).nodeName, "A"); + var c = this.compile(""); + var a = c.node; + assertEquals(a[0].nodeName, "A"); assertTrue(!a.attr("ng-bind-attr")); }; BinderTest.prototype.testExistingAttrbindingIsAppended = function() { - var form = html(""); - form.data('scope', new Scope()); - var binder = new Binder(form.get(0)); - binder.compile(); - var a = form.find("a"); + var c = this.compile(""); + var a = c.node; assertEquals('{"b":"{{def}}","href":"http://s/{{abc}}"}', a.attr('ng-bind-attr')); }; BinderTest.prototype.testAttributesAreEvaluated = function(){ - var c = compile(''); + var c = this.compile(''); var binder = c.binder, form = c.node; - c.scope.eval('a=1;b=2'); - binder.updateView(); - var a = form.find("a"); + c.scope.$eval('a=1;b=2'); + c.scope.$eval(); + var a = c.node; assertEquals(a.attr('a'), 'a'); assertEquals(a.attr('b'), 'a+b=3'); }; -BinderTest.prototype.testInputsAreUpdated = function(){ +BinderTest.prototype.XtestInputsAreUpdated = function(){ var a = - compile('' + - '' + - '' + - '' + - '' + - '' + - ''); - var binder = a.binder, form = a.node; - a.scope.set('A', {text:"t1", textarea:"t2", radio:"r", checkbox:"c", select:"S"}); - binder.compile(); - binder.updateView(); + this.compile('
                ' + + '' + + '' + + '' + + '' + + '' + + '' + + '' + + '
                '); + var form = a.node; + a.scope.$set('A', {text:"t1", textarea:"t2", radio:"r", checkbox:"c", select:"S"}); + a.scope.$eval(); assertEquals(form.find("input[type=text]").attr('value'), 't1'); assertEquals(form.find("textarea").attr('value'), 't2'); assertTrue(form.find("input[name=A.radio]").attr('checked')); @@ -294,37 +167,37 @@ BinderTest.prototype.testInputsAreUpdated = function(){ assertEquals(form.find("option[selected]").text(), 'b'); }; -BinderTest.prototype.testInputTypeButtonActionExecutesInScope = function(){ +BinderTest.prototype.xtestInputTypeButtonActionExecutesInScope = function(){ var savedCalled = false; - var c = compile(''); - c.scope.set("person.save", function(){ + var c = this.compile(''); + c.scope.$set("person.save", function(){ savedCalled = true; }); - c.node.find("#apply").click(); + c.node.click(); assertTrue(savedCalled); }; BinderTest.prototype.testInputTypeButtonActionExecutesInScope = function(){ expectAsserts(1); - var c = compile(''); - c.scope.set("action", function(){ + var c = this.compile(''); + c.scope.$set("action", function(){ assertTrue(true); }); - c.node.find("#apply").click(); + c.node.click(); }; BinderTest.prototype.testButtonElementActionExecutesInScope = function(){ var savedCalled = false; - var c = compile(''); - c.scope.set("person.save", function(){ + var c = this.compile(''); + c.scope.$set("person.save", function(){ savedCalled = true; }); - c.node.find("#apply").click(); + c.node.click(); assertTrue(savedCalled); }; -BinderTest.prototype.testParseEmptyAnchor = function(){ - var binder = compile("
                ").binder; +BinderTest.prototype.XtestParseEmptyAnchor = function(){ + var binder = this.compile("
                ").binder; var location = binder.location; var anchor = binder.anchor; location.url = "a#x=1"; @@ -337,8 +210,8 @@ BinderTest.prototype.testParseEmptyAnchor = function(){ assertEquals('undefined', typeof (anchor[""])); }; -BinderTest.prototype.testParseAnchor = function(){ - var binder = compile("
                ").binder; +BinderTest.prototype.XtestParseAnchor = function(){ + var binder = this.compile("
                ").binder; var location = binder.location; location.url = "a#x=1"; binder.parseAnchor(); @@ -351,8 +224,8 @@ BinderTest.prototype.testParseAnchor = function(){ assertTrue(!binder.anchor.x); }; -BinderTest.prototype.testWriteAnchor = function(){ - var binder = compile("
                ").binder; +BinderTest.prototype.XtestWriteAnchor = function(){ + var binder = this.compile("
                ").binder; binder.location.set('a'); binder.anchor.a = 'b'; binder.anchor.c = ' '; @@ -361,120 +234,116 @@ BinderTest.prototype.testWriteAnchor = function(){ assertEquals(binder.location.get(), "a#a=b&c=%20&d"); }; -BinderTest.prototype.testWriteAnchorAsPartOfTheUpdateView = function(){ - var binder = compile("
                ").binder; +BinderTest.prototype.XtestWriteAnchorAsPartOfTheUpdateView = function(){ + var binder = this.compile("
                ").binder; binder.location.set('a'); binder.anchor.a = 'b'; binder.updateView(); assertEquals(binder.location.get(), "a#a=b"); }; -BinderTest.prototype.testRepeaterUpdateBindings = function(){ - var a = compile('
                '); +BinderTest.prototype.XtestRepeaterUpdateBindings = function(){ + var a = this.compile('
                '); var form = a.node; var items = [{a:"A"}, {a:"B"}]; var initialDataCount = _(jQuery.cache).size(); assertTrue("" + initialDataCount, initialDataCount > 0); - a.scope.set('model', {items:items}); + a.scope.$set('model', {items:items}); - a.binder.updateView(); + a.scope.$eval(); assertEquals('
                  ' + '<#comment>' + '
                • A
                • ' + '
                • B
                • ' + - '
                ', form.sortedHtml()); + '
              ', sortedHtml(form)); items.unshift({a:'C'}); - a.binder.updateView(); + a.scope.$eval(); assertEquals('
                ' + '<#comment>' + '
              • C
              • ' + '
              • A
              • ' + '
              • B
              • ' + - '
              ', form.sortedHtml()); + '
            ', sortedHtml(form)); items.shift(); - a.binder.updateView(); + a.scope.$eval(); assertEquals('
              ' + '<#comment>' + '
            • A
            • ' + '
            • B
            • ' + - '
            ', form.sortedHtml()); + '
          ', sortedHtml(form)); items.shift(); items.shift(); - a.binder.updateView(); + a.scope.$eval(); var currentDataCount = _(jQuery.cache).size(); assertEquals("I have leaked " + (currentDataCount - initialDataCount), initialDataCount, currentDataCount); }; -BinderTest.prototype.testRepeaterContentDoesNotBind = function(){ - var a = compile('
          '); - a.scope.set('model', {items:[{a:"A"}]}); - a.binder.updateView(); +BinderTest.prototype.XtestRepeaterContentDoesNotBind = function(){ + var a = this.compile('
          '); + a.scope.$set('model', {items:[{a:"A"}]}); + a.scope.$eval(); assertEquals('
            ' + '<#comment>' + '
          • A
          • ' + - '
          ', a.node.sortedHtml()); + '', sortedHtml(a.node)); }; -BinderTest.prototype.testShouldBindActionsOnRepeaterClone = function(){ - var c = compile('link'); +BinderTest.prototype.XtestShouldBindActionsOnRepeaterClone = function(){ + var c = this.compile('link'); jQuery(c).die(); - c.scope.set('result.value', false); - c.scope.set('items', ['abc', 'xyz']); + c.scope.$set('result.value', false); + c.scope.$set('items', ['abc', 'xyz']); c.scope.updateView(); assertEquals(2, c.node.find("a").size()); c.node.find("a:last").click(); - assertEquals('xyz', c.scope.get('result.value')); + assertEquals('xyz', c.scope.$get('result.value')); }; -BinderTest.prototype.testRepeaterInputContentDoesNotBind = function(){ - var form = - html('
          • ' + - '
          '); - var binder = new Binder(form.get(0), null, new MockLocation()); - var items = [{a:"A"}]; - form.data('scope', new Scope({model:{items:items}})); - - assertEquals(form.find(":input").attr("value"), "OLD"); +BinderTest.prototype.XtestRepeaterInputContentDoesNotBind = function(){ + var c = compil('
          • ' + + '
          '); + c.scope.items = [{a:"A"}]; + assertEquals(c.node.find(":input").attr("value"), "OLD"); }; -BinderTest.prototype.testExpandEntityTag = function(){ +BinderTest.prototype.XtestExpandEntityTag = function(){ assertEquals( '
          ', - compileToHtml('
          ')); + this.compileToHtml('
          ')); }; -BinderTest.prototype.testExpandEntityTagWithDefaults = function(){ +BinderTest.prototype.XtestExpandEntityTagWithDefaults = function(){ assertEquals( '
          ', - compileToHtml('
          ')); + this.compileToHtml('
          ')); }; -BinderTest.prototype.testExpandEntityTagWithName = function(){ - var c = compile('
          '); +BinderTest.prototype.XtestExpandEntityTagWithName = function(){ + var c = this.compile('
          '); assertEquals( '
          ', - c.node.sortedHtml()); - assertEquals("Person", c.scope.get("friend.$entity")); - assertEquals("friend", c.scope.get("friend.$$anchor")); + sortedHtml(c.node)); + assertEquals("Person", c.scope.$get("friend.$entity")); + assertEquals("friend", c.scope.$get("friend.$$anchor")); }; -BinderTest.prototype.testExpandSubmitButtonToAction = function(){ - var html = compileToHtml(''); +BinderTest.prototype.XtestExpandSubmitButtonToAction = function(){ + var html = this.compileToHtml(''); assertTrue(html, html.indexOf('ng-action="$save()"') > 0 ); assertTrue(html, html.indexOf('ng-bind-attr="{"disabled":"{{$invalidWidgets}}"}"') > 0 ); }; -BinderTest.prototype.testDoNotOverwriteCustomAction = function(){ - var html = compileToHtml(''); +BinderTest.prototype.XtestDoNotOverwriteCustomAction = function(){ + var html = this.compileToHtml(''); assertTrue(html.indexOf('action="foo();"') > 0 ); }; -BinderTest.prototype.testReplaceFileUploadWithSwf = function(){ +BinderTest.prototype.XtestReplaceFileUploadWithSwf = function(){ expectAsserts(1); var form = jQuery("body").append('
          '); form.data('scope', new Scope()); @@ -488,12 +357,12 @@ BinderTest.prototype.testReplaceFileUploadWithSwf = function(){ jQuery("#testTag").remove(); }; -BinderTest.prototype.testRepeaterAdd = function(){ - var c = compile('
          '); +BinderTest.prototype.XtestRepeaterAdd = function(){ + var c = this.compile('
          '); var doc = c.node; - c.scope.set('items', [{x:'a'}, {x:'b'}]); + c.scope.$set('items', [{x:'a'}, {x:'b'}]); c.binder.compile(); - c.binder.updateView(); + c.scope.$eval(); assertEquals('a', doc.find(':input')[0].value); assertEquals('b', doc.find(':input')[1].value); @@ -503,73 +372,73 @@ BinderTest.prototype.testRepeaterAdd = function(){ assertEquals(doc.scope().get('items')[0].x, 'ABC'); }; -BinderTest.prototype.testItShouldRemoveExtraChildrenWhenIteratingOverHash = function(){ - var c = compile('
          {{i}}
          '); +BinderTest.prototype.XtestItShouldRemoveExtraChildrenWhenIteratingOverHash = function(){ + var c = this.compile('
          {{i}}
          '); var items = {}; - c.scope.set("items", items); + c.scope.$set("items", items); - c.binder.updateView(); + c.scope.$eval(); expect(c.node.find("div").size()).toEqual(0); items.name = "misko"; - c.binder.updateView(); + c.scope.$eval(); expect(c.node.find("div").size()).toEqual(1); delete items.name; - c.binder.updateView(); + c.scope.$eval(); expect(c.node.find("div").size()).toEqual(0); }; -BinderTest.prototype.testIfTextBindingThrowsErrorDecorateTheSpan = function(){ - var a = compile('
          {{error.throw()}}
          '); +BinderTest.prototype.XtestIfTextBindingThrowsErrorDecorateTheSpan = function(){ + var a = this.compile('
          {{error.throw()}}
          '); var doc = a.node.find('div'); - a.scope.set('error.throw', function(){throw "ErrorMsg1";}); - a.binder.updateView(); + a.scope.$set('error.throw', function(){throw "ErrorMsg1";}); + a.scope.$eval(); var span = doc.find('span'); assertTrue(span.hasClass('ng-exception')); assertEquals('ErrorMsg1', fromJson(span.text())); assertEquals('"ErrorMsg1"', span.attr('ng-error')); - a.scope.set('error.throw', function(){throw "MyError";}); - a.binder.updateView(); + a.scope.$set('error.throw', function(){throw "MyError";}); + a.scope.$eval(); span = doc.find('span'); assertTrue(span.hasClass('ng-exception')); assertTrue(span.text(), span.text().match('MyError') !== null); assertEquals('"MyError"', span.attr('ng-error')); - a.scope.set('error.throw', function(){return "ok";}); - a.binder.updateView(); + a.scope.$set('error.throw', function(){return "ok";}); + a.scope.$eval(); assertFalse(span.hasClass('ng-exception')); assertEquals('ok', span.text()); assertEquals(null, span.attr('ng-error')); }; -BinderTest.prototype.testIfAttrBindingThrowsErrorDecorateTheSpan = function(){ - var a = compile('
          '); +BinderTest.prototype.XtestIfAttrBindingThrowsErrorDecorateTheSpan = function(){ + var a = this.compile('
          '); var doc = a.node.find("div"); - a.scope.set('error.throw', function(){throw "ErrorMsg";}); - a.binder.updateView(); + a.scope.$set('error.throw', function(){throw "ErrorMsg";}); + a.scope.$eval(); assertTrue('ng-exception', doc.hasClass('ng-exception')); assertEquals('before ["ErrorMsg"] after', doc.attr('attr')); assertEquals('"ErrorMsg"', doc.attr('ng-error')); - a.scope.set('error.throw', function(){ return 'X';}); - a.binder.updateView(); + a.scope.$set('error.throw', function(){ return 'X';}); + a.scope.$eval(); assertFalse('!ng-exception', doc.hasClass('ng-exception')); assertEquals('before X after', doc.attr('attr')); assertEquals(null, doc.attr('ng-error')); }; -BinderTest.prototype.testNestedRepeater = function() { - var a = compile('
          ' + +BinderTest.prototype.XtestNestedRepeater = function() { + var a = this.compile('
          ' + '
            ' + '
            '); - a.scope.set('model', [{name:'a', item:['a1', 'a2']}, {name:'b', item:['b1', 'b2']}]); - a.binder.updateView(); + a.scope.$set('model', [{name:'a', item:['a1', 'a2']}, {name:'b', item:['b1', 'b2']}]); + a.scope.$eval(); assertEquals( //'<#comment>'+ @@ -582,124 +451,124 @@ BinderTest.prototype.testNestedRepeater = function() { '<#comment>'+ '
              '+ '
                '+ - '
                ', a.node.sortedHtml()); + '
                ', sortedHtml(a.node)); }; -BinderTest.prototype.testRadioButtonGetsPrefixed = function () { - var a = compile(''); - a.scope.set('model', ['a1', 'a2']); - a.binder.updateView(); +BinderTest.prototype.XtestRadioButtonGetsPrefixed = function () { + var a = this.compile(''); + a.scope.$set('model', ['a1', 'a2']); + a.scope.$eval(); assertEquals( //'<#comment>'+ ''+ '', - a.node.sortedHtml()); + sortedHtml(a.node)); }; -BinderTest.prototype.testHideBindingExpression = function() { - var a = compile('
                '); +BinderTest.prototype.XtestHideBindingExpression = function() { + var a = this.compile('
                '); - a.scope.set('hidden', 3); - a.binder.updateView(); + a.scope.$set('hidden', 3); + a.scope.$eval(); assertHidden(a.node.children()); - a.scope.set('hidden', 2); - a.binder.updateView(); + a.scope.$set('hidden', 2); + a.scope.$eval(); assertVisible(a.node.children()); }; -BinderTest.prototype.testHideBinding = function() { - var c = compile('
                '); +BinderTest.prototype.XtestHideBinding = function() { + var c = this.compile('
                '); - c.scope.set('hidden', 'true'); - c.binder.updateView(); + c.scope.$set('hidden', 'true'); + c.scope.$eval(); assertHidden(c.node.children()); - c.scope.set('hidden', 'false'); - c.binder.updateView(); + c.scope.$set('hidden', 'false'); + c.scope.$eval(); assertVisible(c.node.children()); - c.scope.set('hidden', ''); - c.binder.updateView(); + c.scope.$set('hidden', ''); + c.scope.$eval(); assertVisible(c.node.children()); }; -BinderTest.prototype.testShowBinding = function() { - var c = compile('
                '); +BinderTest.prototype.XtestShowBinding = function() { + var c = this.compile('
                '); - c.scope.set('show', 'true'); - c.binder.updateView(); + c.scope.$set('show', 'true'); + c.scope.$eval(); assertVisible(c.node.children()); - c.scope.set('show', 'false'); - c.binder.updateView(); + c.scope.$set('show', 'false'); + c.scope.$eval(); assertHidden(c.node.children()); - c.scope.set('show', ''); - c.binder.updateView(); + c.scope.$set('show', ''); + c.scope.$eval(); assertHidden(c.node.children()); }; -BinderTest.prototype.testBindClassUndefined = function() { - var doc = compile('
                '); - doc.binder.updateView(); +BinderTest.prototype.XtestBindClassUndefined = function() { + var doc = this.compile('
                '); + doc.scope.$eval(); assertEquals( '
                ', - doc.node.sortedHtml()); + sortedHtml(doc.node)); }; -BinderTest.prototype.testBindClass = function() { - var c = compile('
                '); +BinderTest.prototype.XtestBindClass = function() { + var c = this.compile('
                '); - c.scope.set('class', 'testClass'); - c.binder.updateView(); + c.scope.$set('class', 'testClass'); + c.scope.$eval(); - assertEquals(c.node.sortedHtml(), + assertEquals(sortedHtml(c.node), '
                '); - c.scope.set('class', ['a', 'b']); - c.binder.updateView(); + c.scope.$set('class', ['a', 'b']); + c.scope.$eval(); - assertEquals(c.node.sortedHtml(), + assertEquals(sortedHtml(c.node), '
                '); }; -BinderTest.prototype.testBindClassEvenOdd = function() { - var x = compile('
                '); - x.binder.updateView(); +BinderTest.prototype.XtestBindClassEvenOdd = function() { + var x = this.compile('
                '); + x.scope.$eval(); assertEquals( '
                ' + '
                ', - x.node.sortedHtml()); + sortedHtml(x.node)); }; -BinderTest.prototype.testBindStyle = function() { - var c = compile('
                '); +BinderTest.prototype.XtestBindStyle = function() { + var c = this.compile('
                '); c.scope.eval('style={color:"red"}'); - c.binder.updateView(); + c.scope.$eval(); assertEquals("red", c.node.find('div').css('color')); c.scope.eval('style={}'); - c.binder.updateView(); + c.scope.$eval(); - assertEquals(c.node.sortedHtml(), '
                '); + assertEquals(sortedHtml(c.node), '
                '); }; -BinderTest.prototype.testActionOnAHrefThrowsError = function(){ +BinderTest.prototype.XtestActionOnAHrefThrowsError = function(){ var model = {books:[]}; - var state = compile('Add Phone', model); + var state = this.compile('Add Phone', model); var input = state.node.find('a'); input.click(); assertEquals('abc', fromJson(input.attr('ng-error')).a); @@ -710,61 +579,61 @@ BinderTest.prototype.testActionOnAHrefThrowsError = function(){ assertFalse('error class should be cleared', input.hasClass('ng-exception')); }; -BinderTest.prototype.testShoulIgnoreVbNonBindable = function(){ - var c = compile("{{a}}" + +BinderTest.prototype.XtestShoulIgnoreVbNonBindable = function(){ + var c = this.compile("{{a}}" + "
                {{a}}
                " + "
                {{b}}
                " + "
                {{c}}
                "); - c.scope.set('a', 123); + c.scope.$set('a', 123); c.scope.updateView(); assertEquals('123{{a}}{{b}}{{c}}', c.node.text()); }; -BinderTest.prototype.testOptionShouldUpdateParentToGetProperBinding = function() { - var c = compile(''); - c.scope.set('s', 1); - c.binder.updateView(); +BinderTest.prototype.XtestOptionShouldUpdateParentToGetProperBinding = function() { + var c = this.compile(''); + c.scope.$set('s', 1); + c.scope.$eval(); assertEquals(1, c.node.find('select')[0].selectedIndex); }; -BinderTest.prototype.testRepeaterShouldBindInputsDefaults = function () { - var c = compile(''); - c.scope.set('items', [{}, {name:'misko'}]); - c.binder.updateView(); +BinderTest.prototype.XtestRepeaterShouldBindInputsDefaults = function () { + var c = this.compile(''); + c.scope.$set('items', [{}, {name:'misko'}]); + c.scope.$eval(); assertEquals("123", c.scope.eval('items[0].name')); assertEquals("misko", c.scope.eval('items[1].name')); }; -BinderTest.prototype.testRepeaterShouldCreateArray = function () { - var c = compile(''); - c.binder.updateView(); +BinderTest.prototype.XtestRepeaterShouldCreateArray = function () { + var c = this.compile(''); + c.scope.$eval(); - assertEquals(0, c.scope.get('items').length); + assertEquals(0, c.scope.$get('items').length); }; -BinderTest.prototype.testShouldTemplateBindPreElements = function () { - var c = compile('
                Hello {{name}}!
                '); - c.scope.set("name", "World"); - c.binder.updateView(); +BinderTest.prototype.XtestShouldTemplateBindPreElements = function () { + var c = this.compile('
                Hello {{name}}!
                '); + c.scope.$set("name", "World"); + c.scope.$eval(); - assertEquals('
                Hello World!
                ', c.node.sortedHtml()); + assertEquals('
                Hello World!
                ', sortedHtml(c.node)); }; -BinderTest.prototype.testDissableAutoSubmit = function() { - var c = compile('', null, {autoSubmit:true}); +BinderTest.prototype.XtestDissableAutoSubmit = function() { + var c = this.compile('', null, {autoSubmit:true}); assertEquals( '', - c.node.sortedHtml()); + sortedHtml(c.node)); - c = compile('', null, {autoSubmit:false}); + c = this.compile('', null, {autoSubmit:false}); assertEquals( '', - c.node.sortedHtml()); + sortedHtml(c.node)); }; -BinderTest.prototype.testSettingAnchorToNullOrUndefinedRemovesTheAnchorFromURL = function() { - var c = compile(''); +BinderTest.prototype.XtestSettingAnchorToNullOrUndefinedRemovesTheAnchorFromURL = function() { + var c = this.compile(''); c.binder.location.set("http://server/#a=1&b=2"); c.binder.parseAnchor(); assertEquals('1', c.binder.anchor.a); @@ -776,12 +645,12 @@ BinderTest.prototype.testSettingAnchorToNullOrUndefinedRemovesTheAnchorFromURL = assertEquals('http://server/#', c.binder.location.get()); }; -BinderTest.prototype.testFillInOptionValueWhenMissing = function() { - var c = compile( +BinderTest.prototype.XtestFillInOptionValueWhenMissing = function() { + var c = this.compile( ''); - c.scope.set('a', 'A'); - c.scope.set('b', 'B'); - c.binder.updateView(); + c.scope.$set('a', 'A'); + c.scope.$set('b', 'B'); + c.scope.$eval(); expect(c.node.find("option:first").attr('value')).toEqual('A'); expect(c.node.find("option:first").text()).toEqual('A'); @@ -793,52 +662,52 @@ BinderTest.prototype.testFillInOptionValueWhenMissing = function() { expect(c.node.find("option:last").text()).toEqual('C'); }; -BinderTest.prototype.testValidateForm = function() { - var c = compile('' + +BinderTest.prototype.XtestValidateForm = function() { + var c = this.compile('' + '
                '); var items = [{}, {}]; - c.scope.set("items", items); - c.binder.updateView(); - assertEquals(3, c.scope.get("$invalidWidgets.length")); + c.scope.$set("items", items); + c.scope.$eval(); + assertEquals(3, c.scope.$get("$invalidWidgets.length")); - c.scope.set('name', ''); - c.binder.updateView(); - assertEquals(3, c.scope.get("$invalidWidgets.length")); + c.scope.$set('name', ''); + c.scope.$eval(); + assertEquals(3, c.scope.$get("$invalidWidgets.length")); - c.scope.set('name', ' '); - c.binder.updateView(); - assertEquals(3, c.scope.get("$invalidWidgets.length")); + c.scope.$set('name', ' '); + c.scope.$eval(); + assertEquals(3, c.scope.$get("$invalidWidgets.length")); - c.scope.set('name', 'abc'); - c.binder.updateView(); - assertEquals(2, c.scope.get("$invalidWidgets.length")); + c.scope.$set('name', 'abc'); + c.scope.$eval(); + assertEquals(2, c.scope.$get("$invalidWidgets.length")); items[0].name = 'abc'; - c.binder.updateView(); - assertEquals(1, c.scope.get("$invalidWidgets.length")); + c.scope.$eval(); + assertEquals(1, c.scope.$get("$invalidWidgets.length")); items[1].name = 'abc'; - c.binder.updateView(); - assertEquals(0, c.scope.get("$invalidWidgets.length")); + c.scope.$eval(); + assertEquals(0, c.scope.$get("$invalidWidgets.length")); }; -BinderTest.prototype.testValidateOnlyVisibleItems = function(){ - var c = compile(''); - c.scope.set("show", true); - c.binder.updateView(); - assertEquals(2, c.scope.get("$invalidWidgets.length")); +BinderTest.prototype.XtestValidateOnlyVisibleItems = function(){ + var c = this.compile(''); + c.scope.$set("show", true); + c.scope.$eval(); + assertEquals(2, c.scope.$get("$invalidWidgets.length")); - c.scope.set("show", false); - c.binder.updateView(); - assertEquals(1, c.scope.get("$invalidWidgets.length")); + c.scope.$set("show", false); + c.scope.$eval(); + assertEquals(1, c.scope.$get("$invalidWidgets.length")); }; -BinderTest.prototype.testDeleteAttributeIfEvaluatesFalse = function() { - var c = compile( +BinderTest.prototype.XtestDeleteAttributeIfEvaluatesFalse = function() { + var c = this.compile( '' + '' + ''); - c.binder.updateView(); + c.scope.$eval(); var html = c.node.html(); assertEquals(html + 0, 1, c.node.find("input[name='a0']:disabled").size()); assertEquals(html + 1, 1, c.node.find("input[name='b0']:disabled").size()); @@ -849,52 +718,52 @@ BinderTest.prototype.testDeleteAttributeIfEvaluatesFalse = function() { assertEquals(html + 5, 0, c.node.find("input[name='c1']:disabled").size()); }; -BinderTest.prototype.testRepeaterErrorShouldBePlacedOnInstanceNotOnTemplateComment = function () { - var c = compile( +BinderTest.prototype.XtestRepeaterErrorShouldBePlacedOnInstanceNotOnTemplateComment = function () { + var c = this.compile( ''); - c.binder.updateView(); + c.scope.$eval(); assertTrue(c.node.find("input").hasClass("ng-exception")); }; BinderTest.prototype.XtestItShouldApplyAttirbutesBeforeTheWidgetsAreMaterialized = function() { - var c = compile( + var c = this.compile( ''); - c.scope.set('person', {a:'misko', b:'adam'}); - c.binder.updateView(); + c.scope.$set('person', {a:'misko', b:'adam'}); + c.scope.$eval(); assertEquals("", c.node.html()); }; -BinderTest.prototype.testItShouldCallListenersWhenAnchorChanges = function() { +BinderTest.prototype.XtestItShouldCallListenersWhenAnchorChanges = function() { var log = ""; - var c = compile('
                '); - c.scope.set("count", 0); + var c = this.compile('
                '); + c.scope.$set("count", 0); c.scope.addWatchListener("$anchor.counter", function(newValue, oldValue){ log += oldValue + "->" + newValue + ";"; }); - assertEquals(0, c.scope.get("count")); + assertEquals(0, c.scope.$get("count")); c.binder.location.url = "#counter=1"; c.binder.onUrlChange(); - assertEquals(1, c.scope.get("count")); + assertEquals(1, c.scope.$get("count")); c.binder.location.url = "#counter=1"; c.binder.onUrlChange(); - assertEquals(1, c.scope.get("count")); + assertEquals(1, c.scope.$get("count")); c.binder.location.url = "#counter=2"; c.binder.onUrlChange(); - assertEquals(2, c.scope.get("count")); + assertEquals(2, c.scope.$get("count")); c.binder.location.url = "#counter=2"; c.binder.onUrlChange(); - assertEquals(2, c.scope.get("count")); + assertEquals(2, c.scope.$get("count")); c.binder.location.url = "#"; c.binder.onUrlChange(); assertEquals("undefined->1;1->2;2->undefined;", log); - assertEquals(3, c.scope.get("count")); + assertEquals(3, c.scope.$get("count")); }; -BinderTest.prototype.testParseQueryString = function(){ +BinderTest.prototype.XtestParseQueryString = function(){ var binder = new Binder(); assertJsonEquals({"a":"1"}, binder.parseQueryString("a=1")); assertJsonEquals({"a":"1", "b":"two"}, binder.parseQueryString("a=1&b=two")); @@ -907,9 +776,9 @@ BinderTest.prototype.testParseQueryString = function(){ }; -BinderTest.prototype.testSetBinderAnchorTriggersListeners = function(){ +BinderTest.prototype.XtestSetBinderAnchorTriggersListeners = function(){ expectAsserts(2); - var doc = compile("
                "); + var doc = this.compile("
                "); doc.scope.addWatchListener("$anchor.name", function(newVal, oldVal) { assertEquals("new", newVal); @@ -920,97 +789,97 @@ BinderTest.prototype.testSetBinderAnchorTriggersListeners = function(){ doc.binder.onUrlChange("http://base#name=new"); }; -BinderTest.prototype.testItShouldDisplayErrorWhenActionIsSyntacticlyIncorect = function(){ - var c = compile( +BinderTest.prototype.XtestItShouldDisplayErrorWhenActionIsSyntacticlyIncorect = function(){ + var c = this.compile( '' + ''); c.node.find("input").click(); - assertEquals("ABC", c.scope.get('greeting')); + assertEquals("ABC", c.scope.$get('greeting')); assertTrue(c.node.find(":input:last").hasClass("ng-exception")); }; -BinderTest.prototype.testItShouldSelectTheCorrectRadioBox = function() { - var c = compile( +BinderTest.prototype.XtestItShouldSelectTheCorrectRadioBox = function() { + var c = this.compile( '' + ''); c.node.find("input[value=female]").click(); - assertEquals("female", c.scope.get("sex")); + assertEquals("female", c.scope.$get("sex")); assertEquals(1, c.node.find("input:checked").size()); assertEquals("female", c.node.find("input:checked").attr("value")); c.node.find("input[value=male]").click(); - assertEquals("male", c.scope.get("sex")); + assertEquals("male", c.scope.$get("sex")); assertEquals(1, c.node.find("input:checked").size()); assertEquals("male", c.node.find("input:checked").attr("value")); }; -BinderTest.prototype.testItShouldListenOnRightScope = function() { - var c = compile( +BinderTest.prototype.XtestItShouldListenOnRightScope = function() { + var c = this.compile( '
                ' + '
                '); c.binder.executeInit(); - c.binder.updateView(); - assertEquals(0, c.scope.get("counter")); - assertEquals(0, c.scope.get("gCounter")); + c.scope.$eval(); + assertEquals(0, c.scope.$get("counter")); + assertEquals(0, c.scope.$get("gCounter")); - c.scope.set("w", "something"); - c.binder.updateView(); - assertEquals(1, c.scope.get("counter")); - assertEquals(7, c.scope.get("gCounter")); + c.scope.$set("w", "something"); + c.scope.$eval(); + assertEquals(1, c.scope.$get("counter")); + assertEquals(7, c.scope.$get("gCounter")); }; -BinderTest.prototype.testItShouldRepeatOnHashes = function() { - var x = compile('
                '); - x.binder.updateView(); +BinderTest.prototype.XtestItShouldRepeatOnHashes = function() { + var x = this.compile('
                '); + x.scope.$eval(); assertEquals( '
                a0
                ' + '
                b1
                ', - x.node.sortedHtml()); + sortedHtml(x.node)); }; -BinderTest.prototype.testItShouldFireChangeListenersBeforeUpdate = function(){ - var x = compile('
                '); - x.scope.set("name", ""); - x.scope.set("watched", "change"); +BinderTest.prototype.XtestItShouldFireChangeListenersBeforeUpdate = function(){ + var x = this.compile('
                '); + x.scope.$set("name", ""); + x.scope.$set("watched", "change"); x.scope.watch("watched:name=123"); x.scope.updateView(); - assertEquals(123, x.scope.get("name")); + assertEquals(123, x.scope.$get("name")); assertEquals( '
                123
                ', - x.node.sortedHtml()); + sortedHtml(x.node)); }; -BinderTest.prototype.testItShouldHandleMultilineBindings = function(){ - var x = compile('
                {{\n 1 \n + \n 2 \n}}
                '); +BinderTest.prototype.XtestItShouldHandleMultilineBindings = function(){ + var x = this.compile('
                {{\n 1 \n + \n 2 \n}}
                '); x.scope.updateView(); assertEquals("3", x.node.text()); }; -BinderTest.prototype.testItBindHiddenInputFields = function(){ - var x = compile(''); +BinderTest.prototype.XtestItBindHiddenInputFields = function(){ + var x = this.compile(''); x.scope.updateView(); - assertEquals("abc", x.scope.get("myName")); + assertEquals("abc", x.scope.$get("myName")); }; -BinderTest.prototype.testItShouldRenderMultiRootHtmlInBinding = function() { - var x = compile('
                before {{a|html}}after
                '); - x.scope.set("a", "acd"); - x.binder.updateView(); +BinderTest.prototype.XtestItShouldRenderMultiRootHtmlInBinding = function() { + var x = this.compile('
                before {{a|html}}after
                '); + x.scope.$set("a", "acd"); + x.scope.$eval(); assertEquals( '
                before acdafter
                ', - x.node.sortedHtml()); + sortedHtml(x.node)); }; -BinderTest.prototype.testItShouldUseFormaterForText = function() { - var x = compile(''); - x.binder.updateView(); - assertEquals(['a','b'], x.scope.get('a')); +BinderTest.prototype.XtestItShouldUseFormaterForText = function() { + var x = this.compile(''); + x.scope.$eval(); + assertEquals(['a','b'], x.scope.$get('a')); var input = x.node.find('input'); input[0].value = ' x,,yz'; input.change(); - assertEquals(['x','yz'], x.scope.get('a')); - x.scope.set('a', [1 ,2, 3]); - x.binder.updateView(); + assertEquals(['x','yz'], x.scope.$get('a')); + x.scope.$set('a', [1 ,2, 3]); + x.scope.$eval(); assertEquals('1, 2, 3', input[0].value); }; diff --git a/test/ConsoleTest.js b/test/ConsoleTest.js index f659752f..9adb50f8 100644 --- a/test/ConsoleTest.js +++ b/test/ConsoleTest.js @@ -1,12 +1,12 @@ ConsoleTest = TestCase('ConsoleTest'); -ConsoleTest.prototype.testConsoleWrite = function(){ - consoleNode = $("
                ")[0]; +ConsoleTest.prototype.XtestConsoleWrite = function(){ + var consoleNode = jqLite("
                ")[0]; consoleLog("error", ["Hello", "world"]); - assertEquals($(consoleNode)[0].nodeName, 'DIV'); - assertEquals($(consoleNode).text(), 'Hello world'); - assertEquals($('div', consoleNode)[0].className, 'error'); + assertEquals(jqLite(consoleNode)[0].nodeName, 'DIV'); + assertEquals(jqLite(consoleNode).text(), 'Hello world'); + assertEquals(jqLite(consoleNode.childNodes[0])[0].className, 'error'); consoleLog("error",["Bye"]); assertEquals($(consoleNode).text(), 'Hello worldBye'); consoleNode = null; -}; \ No newline at end of file +}; diff --git a/test/FileControllerTest.js b/test/FileControllerTest.js index 454e7624..75c924e6 100644 --- a/test/FileControllerTest.js +++ b/test/FileControllerTest.js @@ -1,6 +1,6 @@ FileControllerTest = TestCase('FileControllerTest'); -FileControllerTest.prototype.testOnSelectUpdateView = function(){ +FileControllerTest.prototype.XtestOnSelectUpdateView = function(){ var view = jQuery(''); var swf = {}; var controller = new FileController(view, null, swf); @@ -10,7 +10,7 @@ FileControllerTest.prototype.testOnSelectUpdateView = function(){ assertEquals(view.find('span').text(), "9 bytes"); }; -FileControllerTest.prototype.testUpdateModelView = function(){ +FileControllerTest.prototype.XtestUpdateModelView = function(){ var view = FileController.template(''); var input = $(''); var controller; @@ -31,7 +31,7 @@ FileControllerTest.prototype.testUpdateModelView = function(){ assertEquals(view.find('span').text(), "123 bytes"); }; -FileControllerTest.prototype.testFileUpload = function(){ +FileControllerTest.prototype.XtestFileUpload = function(){ expectAsserts(1); var swf = {}; var controller = new FileController(null, null, swf, "http://server_base"); @@ -42,7 +42,7 @@ FileControllerTest.prototype.testFileUpload = function(){ controller.upload(); }; -FileControllerTest.prototype.testFileUploadNoFileIsNoop = function(){ +FileControllerTest.prototype.XtestFileUploadNoFileIsNoop = function(){ expectAsserts(0); var swf = {uploadFile:function(path){ fail(); @@ -51,7 +51,7 @@ FileControllerTest.prototype.testFileUploadNoFileIsNoop = function(){ controller.upload("basePath", null); }; -FileControllerTest.prototype.testRemoveAttachment = function(){ +FileControllerTest.prototype.XtestRemoveAttachment = function(){ var doc = FileController.template(); var input = $(''); var scope = new Scope(); @@ -74,7 +74,7 @@ FileControllerTest.prototype.testRemoveAttachment = function(){ assertEquals(123, scope.get('file.size')); }; -FileControllerTest.prototype.testShouldEmptyOutOnUndefined = function () { +FileControllerTest.prototype.XtestShouldEmptyOutOnUndefined = function () { var view = FileController.template('hello'); var controller = new FileController(view, 'abc', null, null); diff --git a/test/FiltersTest.js b/test/FiltersTest.js index 9552c820..15a2ebc3 100644 --- a/test/FiltersTest.js +++ b/test/FiltersTest.js @@ -1,6 +1,6 @@ FiltersTest = TestCase('FiltersTest'); -FiltersTest.prototype.testCurrency = function(){ +FiltersTest.prototype.XtestCurrency = function(){ var html = $(''); var context = {$element:html[0]}; var currency = bind(context, angular.filter.currency); @@ -13,7 +13,7 @@ FiltersTest.prototype.testCurrency = function(){ assertEquals(html.hasClass('ng-format-negative'), false); }; -FiltersTest.prototype.testFilterThisIsContext = function(){ +FiltersTest.prototype.XtestFilterThisIsContext = function(){ expectAsserts(2); var scope = new Scope(); Scope.expressionCache = {}; @@ -27,7 +27,7 @@ FiltersTest.prototype.testFilterThisIsContext = function(){ delete angular.filter['testFn']; }; -FiltersTest.prototype.testNumberFormat = function(){ +FiltersTest.prototype.XtestNumberFormat = function(){ var context = {jqElement:$('')}; var number = bind(context, angular.filter.number); @@ -40,11 +40,11 @@ FiltersTest.prototype.testNumberFormat = function(){ assertEquals("", number(1/0)); }; -FiltersTest.prototype.testJson = function () { +FiltersTest.prototype.XtestJson = function () { assertEquals(toJson({a:"b"}, true), angular.filter.json({a:"b"})); }; -FiltersTest.prototype.testPackageTracking = function () { +FiltersTest.prototype.XtestPackageTracking = function () { var assert = function(title, trackingNo) { var val = angular.filter.trackPackage(trackingNo, title); assertNotNull("Did Not Match: " + trackingNo, val); @@ -72,7 +72,7 @@ FiltersTest.prototype.testPackageTracking = function () { assert('USPS', '9102801438635051633253'); }; -FiltersTest.prototype.testLink = function() { +FiltersTest.prototype.XtestLink = function() { var assert = function(text, url, obj){ var val = angular.filter.link(obj); assertEquals(angular.filter.Meta.TAG, val.TAG); @@ -83,14 +83,14 @@ FiltersTest.prototype.testLink = function() { assert("a@b.com", "mailto:a@b.com", "a@b.com"); }; -FiltersTest.prototype.testBytes = function(){ +FiltersTest.prototype.XtestBytes = function(){ var controller = new FileController(); assertEquals(angular.filter.bytes(123), '123 bytes'); assertEquals(angular.filter.bytes(1234), '1.2 KB'); assertEquals(angular.filter.bytes(1234567), '1.1 MB'); }; -FiltersTest.prototype.testImage = function(){ +FiltersTest.prototype.XtestImage = function(){ assertEquals(null, angular.filter.image()); assertEquals(null, angular.filter.image({})); assertEquals(null, angular.filter.image("")); @@ -103,7 +103,7 @@ FiltersTest.prototype.testImage = function(){ angular.filter.image({url:"abc"}, 10, 20).html); }; -FiltersTest.prototype.testQRcode = function() { +FiltersTest.prototype.XtestQRcode = function() { assertEquals( '', angular.filter.qrcode('Hello world').html); @@ -112,17 +112,17 @@ FiltersTest.prototype.testQRcode = function() { angular.filter.qrcode('http://server?a&b=c', 100).html); }; -FiltersTest.prototype.testLowercase = function() { +FiltersTest.prototype.XtestLowercase = function() { assertEquals('abc', angular.filter.lowercase('AbC')); assertEquals(null, angular.filter.lowercase(null)); }; -FiltersTest.prototype.testUppercase = function() { +FiltersTest.prototype.XtestUppercase = function() { assertEquals('ABC', angular.filter.uppercase('AbC')); assertEquals(null, angular.filter.uppercase(null)); }; -FiltersTest.prototype.testLineCount = function() { +FiltersTest.prototype.XtestLineCount = function() { assertEquals(1, angular.filter.linecount(null)); assertEquals(1, angular.filter.linecount('')); assertEquals(1, angular.filter.linecount('a')); @@ -130,35 +130,35 @@ FiltersTest.prototype.testLineCount = function() { assertEquals(3, angular.filter.linecount('a\nb\nc')); }; -FiltersTest.prototype.testIf = function() { +FiltersTest.prototype.XtestIf = function() { assertEquals('A', angular.filter['if']('A', true)); assertEquals(undefined, angular.filter['if']('A', false)); }; -FiltersTest.prototype.testUnless = function() { +FiltersTest.prototype.XtestUnless = function() { assertEquals('A', angular.filter.unless('A', false)); assertEquals(undefined, angular.filter.unless('A', true)); }; -FiltersTest.prototype.testGoogleChartApiEncode = function() { +FiltersTest.prototype.XtestGoogleChartApiEncode = function() { assertEquals( '', angular.filter.googleChartApi.encode({cht:"qr", chl:"Hello world"}).html); }; -FiltersTest.prototype.testHtml = function() { +FiltersTest.prototype.XtestHtml = function() { assertEquals( "acd", angular.filter.html("acd").html); assertTrue(angular.filter.html("acd") instanceof angular.filter.Meta); }; -FiltersTest.prototype.testLinky = function() { +FiltersTest.prototype.XtestLinky = function() { var linky = angular.filter.linky; assertEquals( - 'http://ab ' + - '(http://a) ' + - '<http://a> \n ' + + 'http://ab ' + + '(http://a) ' + + '<http://a> \n ' + 'http://1.2/v:~-123. c', linky("http://ab (http://a) \n http://1.2/v:~-123. c").html); assertTrue(linky("a") instanceof angular.filter.Meta); diff --git a/test/ParserTest.js b/test/ParserTest.js index d3813812..639e919f 100644 --- a/test/ParserTest.js +++ b/test/ParserTest.js @@ -150,41 +150,41 @@ LexerTest.prototype.testStatements = function(){ ParserTest = TestCase('ParserTest'); ParserTest.prototype.testExpressions = function(){ - var scope = new Scope(); - assertEquals(scope.eval("-1"), -1); - assertEquals(scope.eval("1 + 2.5"), 3.5); - assertEquals(scope.eval("1 + -2.5"), -1.5); - assertEquals(scope.eval("1+2*3/4"), 1+2*3/4); - assertEquals(scope.eval("0--1+1.5"), 0- -1 + 1.5); - assertEquals(scope.eval("-0--1++2*-3/-4"), -0- -1+ +2*-3/-4); - assertEquals(scope.eval("1/2*3"), 1/2*3); + var scope = createScope(); + assertEquals(scope.$eval("-1"), -1); + assertEquals(scope.$eval("1 + 2.5"), 3.5); + assertEquals(scope.$eval("1 + -2.5"), -1.5); + assertEquals(scope.$eval("1+2*3/4"), 1+2*3/4); + assertEquals(scope.$eval("0--1+1.5"), 0- -1 + 1.5); + assertEquals(scope.$eval("-0--1++2*-3/-4"), -0- -1+ +2*-3/-4); + assertEquals(scope.$eval("1/2*3"), 1/2*3); }; ParserTest.prototype.testComparison = function(){ - var scope = new Scope(); - assertEquals(scope.eval("false"), false); - assertEquals(scope.eval("!true"), false); - assertEquals(scope.eval("1==1"), true); - assertEquals(scope.eval("1!=2"), true); - assertEquals(scope.eval("1<2"), true); - assertEquals(scope.eval("1<=1"), true); - assertEquals(scope.eval("1>2"), 1>2); - assertEquals(scope.eval("2>=1"), 2>=1); + var scope = createScope(); + assertEquals(scope.$eval("false"), false); + assertEquals(scope.$eval("!true"), false); + assertEquals(scope.$eval("1==1"), true); + assertEquals(scope.$eval("1!=2"), true); + assertEquals(scope.$eval("1<2"), true); + assertEquals(scope.$eval("1<=1"), true); + assertEquals(scope.$eval("1>2"), 1>2); + assertEquals(scope.$eval("2>=1"), 2>=1); - assertEquals(true==2<3, scope.eval("true==2<3")); + assertEquals(true==2<3, scope.$eval("true==2<3")); }; ParserTest.prototype.testLogical = function(){ - var scope = new Scope(); - assertEquals(scope.eval("0&&2"), 0&&2); - assertEquals(scope.eval("0||2"), 0||2); - assertEquals(scope.eval("0||1&&2"), 0||1&&2); + var scope = createScope(); + assertEquals(scope.$eval("0&&2"), 0&&2); + assertEquals(scope.$eval("0||2"), 0||2); + assertEquals(scope.$eval("0||1&&2"), 0||1&&2); }; ParserTest.prototype.testString = function(){ - var scope = new Scope(); - assertEquals(scope.eval("'a' + 'b c'"), "ab c"); + var scope = createScope(); + assertEquals(scope.$eval("'a' + 'b c'"), "ab c"); }; ParserTest.prototype.testFilters = function(){ @@ -195,123 +195,123 @@ ParserTest.prototype.testFilters = function(){ angular.filter.upper = {_case:function(input) { return input.toUpperCase(); }}; - var scope = new Scope(); + var scope = createScope(); try { - scope.eval("1|nonExistant"); + scope.$eval("1|nonExistant"); fail(); } catch (e) { assertEquals(e, "Function 'nonExistant' at column '3' in '1|nonExistant' is not defined."); } - scope.set('offset', 3); - assertEquals(scope.eval("'abcd'|upper._case"), "ABCD"); - assertEquals(scope.eval("'abcd'|substring:1:offset"), "bc"); - assertEquals(scope.eval("'abcd'|substring:1:3|upper._case"), "BC"); + scope.$set('offset', 3); + assertEquals(scope.$eval("'abcd'|upper._case"), "ABCD"); + assertEquals(scope.$eval("'abcd'|substring:1:offset"), "bc"); + assertEquals(scope.$eval("'abcd'|substring:1:3|upper._case"), "BC"); }; ParserTest.prototype.testScopeAccess = function(){ - var scope = new Scope(); - scope.set('a', 123); - scope.set('b.c', 456); - assertEquals(scope.eval("a", scope), 123); - assertEquals(scope.eval("b.c", scope), 456); - assertEquals(scope.eval("x.y.z", scope), undefined); + var scope = createScope(); + scope.$set('a', 123); + scope.$set('b.c', 456); + assertEquals(scope.$eval("a", scope), 123); + assertEquals(scope.$eval("b.c", scope), 456); + assertEquals(scope.$eval("x.y.z", scope), undefined); }; ParserTest.prototype.testGrouping = function(){ - var scope = new Scope(); - assertEquals(scope.eval("(1+2)*3"), (1+2)*3); + var scope = createScope(); + assertEquals(scope.$eval("(1+2)*3"), (1+2)*3); }; ParserTest.prototype.testAssignments = function(){ - var scope = new Scope(); - assertEquals(scope.eval("a=12"), 12); - assertEquals(scope.get("a"), 12); + var scope = createScope(); + assertEquals(scope.$eval("a=12"), 12); + assertEquals(scope.$get("a"), 12); - scope = new Scope(); - assertEquals(scope.eval("x.y.z=123;"), 123); - assertEquals(scope.get("x.y.z"), 123); + scope = createScope(); + assertEquals(scope.$eval("x.y.z=123;"), 123); + assertEquals(scope.$get("x.y.z"), 123); - assertEquals(234, scope.eval("a=123; b=234")); - assertEquals(123, scope.get("a")); - assertEquals(234, scope.get("b")); + assertEquals(234, scope.$eval("a=123; b=234")); + assertEquals(123, scope.$get("a")); + assertEquals(234, scope.$get("b")); }; ParserTest.prototype.testFunctionCallsNoArgs = function(){ - var scope = new Scope(); - scope.set('const', function(a,b){return 123;}); - assertEquals(scope.eval("const()"), 123); + var scope = createScope(); + scope.$set('const', function(a,b){return 123;}); + assertEquals(scope.$eval("const()"), 123); }; ParserTest.prototype.testFunctionCalls = function(){ - var scope = new Scope(); - scope.set('add', function(a,b){ + var scope = createScope(); + scope.$set('add', function(a,b){ return a+b; }); - assertEquals(3, scope.eval("add(1,2)")); + assertEquals(3, scope.$eval("add(1,2)")); }; ParserTest.prototype.testCalculationBug = function(){ - var scope = new Scope(); - scope.set('taxRate', 8); - scope.set('subTotal', 100); - assertEquals(scope.eval("taxRate / 100 * subTotal"), 8); - assertEquals(scope.eval("subTotal * taxRate / 100"), 8); + var scope = createScope(); + scope.$set('taxRate', 8); + scope.$set('subTotal', 100); + assertEquals(scope.$eval("taxRate / 100 * subTotal"), 8); + assertEquals(scope.$eval("subTotal * taxRate / 100"), 8); }; ParserTest.prototype.testArray = function(){ - var scope = new Scope(); - assertEquals(scope.eval("[]").length, 0); - assertEquals(scope.eval("[1, 2]").length, 2); - assertEquals(scope.eval("[1, 2]")[0], 1); - assertEquals(scope.eval("[1, 2]")[1], 2); + var scope = createScope(); + assertEquals(scope.$eval("[]").length, 0); + assertEquals(scope.$eval("[1, 2]").length, 2); + assertEquals(scope.$eval("[1, 2]")[0], 1); + assertEquals(scope.$eval("[1, 2]")[1], 2); }; ParserTest.prototype.testArrayAccess = function(){ - var scope = new Scope(); - assertEquals(scope.eval("[1][0]"), 1); - assertEquals(scope.eval("[[1]][0][0]"), 1); - assertEquals(scope.eval("[].length"), 0); - assertEquals(scope.eval("[1, 2].length"), 2); + var scope = createScope(); + assertEquals(scope.$eval("[1][0]"), 1); + assertEquals(scope.$eval("[[1]][0][0]"), 1); + assertEquals(scope.$eval("[].length"), 0); + assertEquals(scope.$eval("[1, 2].length"), 2); }; ParserTest.prototype.testObject = function(){ - var scope = new Scope(); - assertEquals(toJson(scope.eval("{}")), "{}"); - assertEquals(toJson(scope.eval("{a:'b'}")), '{"a":"b"}'); - assertEquals(toJson(scope.eval("{'a':'b'}")), '{"a":"b"}'); - assertEquals(toJson(scope.eval("{\"a\":'b'}")), '{"a":"b"}'); + var scope = createScope(); + assertEquals(toJson(scope.$eval("{}")), "{}"); + assertEquals(toJson(scope.$eval("{a:'b'}")), '{"a":"b"}'); + assertEquals(toJson(scope.$eval("{'a':'b'}")), '{"a":"b"}'); + assertEquals(toJson(scope.$eval("{\"a\":'b'}")), '{"a":"b"}'); }; ParserTest.prototype.testObjectAccess = function(){ - var scope = new Scope(); - assertEquals("WC", scope.eval("{false:'WC', true:'CC'}[false]")); + var scope = createScope(); + assertEquals("WC", scope.$eval("{false:'WC', true:'CC'}[false]")); }; ParserTest.prototype.testJSON = function(){ - var scope = new Scope(); - assertEquals(toJson(scope.eval("[{}]")), "[{}]"); - assertEquals(toJson(scope.eval("[{a:[]}, {b:1}]")), '[{"a":[]},{"b":1}]'); + var scope = createScope(); + assertEquals(toJson(scope.$eval("[{}]")), "[{}]"); + assertEquals(toJson(scope.$eval("[{a:[]}, {b:1}]")), '[{"a":[]},{"b":1}]'); }; ParserTest.prototype.testMultippleStatements = function(){ - var scope = new Scope(); - assertEquals(scope.eval("a=1;b=3;a+b"), 4); - assertEquals(scope.eval(";;1;;"), 1); + var scope = createScope(); + assertEquals(scope.$eval("a=1;b=3;a+b"), 4); + assertEquals(scope.$eval(";;1;;"), 1); }; ParserTest.prototype.testParseThrow = function(){ expectAsserts(1); - var scope = new Scope(); - scope.set('e', 'abc'); + var scope = createScope(); + scope.$set('e', 'abc'); try { - scope.eval("throw e"); + scope.$eval("throw e"); } catch(e) { assertEquals(e, 'abc'); } }; ParserTest.prototype.testMethodsGetDispatchedWithCorrectThis = function(){ - var scope = new Scope(); + var scope = createScope(); var C = function (){ this.a=123; }; @@ -319,11 +319,11 @@ ParserTest.prototype.testMethodsGetDispatchedWithCorrectThis = function(){ return this.a; }; - scope.set("obj", new C()); - assertEquals(123, scope.eval("obj.getA()")); + scope.$set("obj", new C()); + assertEquals(123, scope.$eval("obj.getA()")); }; ParserTest.prototype.testMethodsArgumentsGetCorrectThis = function(){ - var scope = new Scope(); + var scope = createScope(); var C = function (){ this.a=123; }; @@ -334,89 +334,89 @@ ParserTest.prototype.testMethodsArgumentsGetCorrectThis = function(){ return this.a; }; - scope.set("obj", new C()); - assertEquals(246, scope.eval("obj.sum(obj.getA())")); + scope.$set("obj", new C()); + assertEquals(246, scope.$eval("obj.sum(obj.getA())")); }; ParserTest.prototype.testObjectPointsToScopeValue = function(){ - var scope = new Scope(); - scope.set('a', "abc"); - assertEquals("abc", scope.eval("{a:a}").a); + var scope = createScope(); + scope.$set('a', "abc"); + assertEquals("abc", scope.$eval("{a:a}").a); }; ParserTest.prototype.testFieldAccess = function(){ - var scope = new Scope(); + var scope = createScope(); var fn = function(){ return {name:'misko'}; }; - scope.set('a', fn); - assertEquals("misko", scope.eval("a().name")); + scope.$set('a', fn); + assertEquals("misko", scope.$eval("a().name")); }; ParserTest.prototype.testArrayIndexBug = function () { - var scope = new Scope(); - scope.set('items', [{}, {name:'misko'}]); + var scope = createScope(); + scope.$set('items', [{}, {name:'misko'}]); - assertEquals("misko", scope.eval('items[1].name')); + assertEquals("misko", scope.$eval('items[1].name')); }; ParserTest.prototype.testArrayAssignment = function () { - var scope = new Scope(); - scope.set('items', []); + var scope = createScope(); + scope.$set('items', []); - assertEquals("abc", scope.eval('items[1] = "abc"')); - assertEquals("abc", scope.eval('items[1]')); + assertEquals("abc", scope.$eval('items[1] = "abc"')); + assertEquals("abc", scope.$eval('items[1]')); // Dont know how to make this work.... -// assertEquals("moby", scope.eval('books[1] = "moby"')); -// assertEquals("moby", scope.eval('books[1]')); +// assertEquals("moby", scope.$eval('books[1] = "moby"')); +// assertEquals("moby", scope.$eval('books[1]')); }; ParserTest.prototype.testFiltersCanBeGrouped = function () { - var scope = new Scope({name:'MISKO'}); - assertEquals('misko', scope.eval('n = (name|lowercase)')); - assertEquals('misko', scope.eval('n')); + var scope = createScope({name:'MISKO'}); + assertEquals('misko', scope.$eval('n = (name|lowercase)')); + assertEquals('misko', scope.$eval('n')); }; ParserTest.prototype.testFiltersCanBeGrouped = function () { - var scope = new Scope({name:'MISKO'}); - assertEquals('misko', scope.eval('n = (name|lowercase)')); - assertEquals('misko', scope.eval('n')); + var scope = createScope({name:'MISKO'}); + assertEquals('misko', scope.$eval('n = (name|lowercase)')); + assertEquals('misko', scope.$eval('n')); }; ParserTest.prototype.testRemainder = function () { - var scope = new Scope(); - assertEquals(1, scope.eval('1%2')); + var scope = createScope(); + assertEquals(1, scope.$eval('1%2')); }; ParserTest.prototype.testSumOfUndefinedIsNotUndefined = function () { - var scope = new Scope(); - assertEquals(1, scope.eval('1+undefined')); - assertEquals(1, scope.eval('undefined+1')); + var scope = createScope(); + assertEquals(1, scope.$eval('1+undefined')); + assertEquals(1, scope.$eval('undefined+1')); }; ParserTest.prototype.testMissingThrowsError = function() { - var scope = new Scope(); + var scope = createScope(); try { - scope.eval('[].count('); + scope.$eval('[].count('); fail(); } catch (e) { assertEquals('Unexpected end of expression: [].count(', e); } }; -ParserTest.prototype.testItShouldParseOnChangeIntoHashSet = function () { - var scope = new Scope({count:0}); +ParserTest.prototype.XtestItShouldParseOnChangeIntoHashSet = function () { + var scope = createScope({count:0}); scope.watch("$anchor.a:count=count+1;$anchor.a:count=count+20;b:count=count+300"); scope.watchListeners["$anchor.a"].listeners[0](); - assertEquals(1, scope.get("count")); + assertEquals(1, scope.$get("count")); scope.watchListeners["$anchor.a"].listeners[1](); - assertEquals(21, scope.get("count")); + assertEquals(21, scope.$get("count")); scope.watchListeners["b"].listeners[0]({scope:scope}); - assertEquals(321, scope.get("count")); + assertEquals(321, scope.$get("count")); }; -ParserTest.prototype.testItShouldParseOnChangeBlockIntoHashSet = function () { - var scope = new Scope({count:0}); +ParserTest.prototype.XtestItShouldParseOnChangeBlockIntoHashSet = function () { + var scope = createScope({count:0}); var listeners = {a:[], b:[]}; scope.watch("a:{count=count+1;count=count+20;};b:count=count+300", function(n, fn){listeners[n].push(fn);}); @@ -424,82 +424,82 @@ ParserTest.prototype.testItShouldParseOnChangeBlockIntoHashSet = function () { assertEquals(1, scope.watchListeners.a.listeners.length); assertEquals(1, scope.watchListeners.b.listeners.length); scope.watchListeners["a"].listeners[0](); - assertEquals(21, scope.get("count")); + assertEquals(21, scope.$get("count")); scope.watchListeners["b"].listeners[0](); - assertEquals(321, scope.get("count")); + assertEquals(321, scope.$get("count")); }; -ParserTest.prototype.testItShouldParseEmptyOnChangeAsNoop = function () { - var scope = new Scope(); +ParserTest.prototype.XtestItShouldParseEmptyOnChangeAsNoop = function () { + var scope = createScope(); scope.watch("", function(){fail();}); }; ParserTest.prototype.testItShouldCreateClosureFunctionWithNoArguments = function () { - var scope = new Scope(); - var fn = scope.eval("{:value}"); - scope.set("value", 1); + var scope = createScope(); + var fn = scope.$eval("{:value}"); + scope.$set("value", 1); assertEquals(1, fn()); - scope.set("value", 2); + scope.$set("value", 2); assertEquals(2, fn()); - fn = scope.eval("{():value}"); + fn = scope.$eval("{():value}"); assertEquals(2, fn()); }; ParserTest.prototype.testItShouldCreateClosureFunctionWithArguments = function () { - var scope = new Scope(); - var fn = scope.eval("{(a):value+a}"); - scope.set("value", 1); + var scope = createScope(); + scope.$set("value", 1); + var fn = scope.$eval("{(a):value+a}"); assertEquals(11, fn(10)); - scope.set("value", 2); + scope.$set("value", 2); assertEquals(12, fn(10)); - fn = scope.eval("{(a,b):value+a+b}"); + fn = scope.$eval("{(a,b):value+a+b}"); assertEquals(112, fn(10, 100)); }; ParserTest.prototype.testItShouldHaveDefaultArugument = function(){ - var scope = new Scope(); - var fn = scope.eval("{:$*2}"); + var scope = createScope(); + var fn = scope.$eval("{:$*2}"); assertEquals(4, fn(2)); }; -ParserTest.prototype.testReturnFunctionsAreNotBound = function(){ - var scope = new Scope(); +ParserTest.prototype.XtestReturnFunctionsAreNotBound = function(){ + var scope = createScope(); scope.entity("Group", new DataStore()); - var Group = scope.get("Group"); - assertEquals("eval Group", "function", typeof scope.eval("Group")); + var Group = scope.$get("Group"); + assertEquals("eval Group", "function", typeof scope.$eval("Group")); assertEquals("direct Group", "function", typeof Group); - assertEquals("eval Group.all", "function", typeof scope.eval("Group.query")); + assertEquals("eval Group.all", "function", typeof scope.$eval("Group.query")); assertEquals("direct Group.all", "function", typeof Group.query); }; ParserTest.prototype.testDoubleNegationBug = function (){ - var scope = new Scope(); - assertEquals(true, scope.eval('true')); - assertEquals(false, scope.eval('!true')); - assertEquals(true, scope.eval('!!true')); - assertEquals('a', scope.eval('{true:"a", false:"b"}[!!true]')); + var scope = createScope(); + assertEquals(true, scope.$eval('true')); + assertEquals(false, scope.$eval('!true')); + assertEquals(true, scope.$eval('!!true')); + assertEquals('a', scope.$eval('{true:"a", false:"b"}[!!true]')); }; ParserTest.prototype.testNegationBug = function () { - var scope = new Scope(); - assertEquals(!false || true, scope.eval("!false || true")); - assertEquals(!11 == 10, scope.eval("!11 == 10")); - assertEquals(12/6/2, scope.eval("12/6/2")); + var scope = createScope(); + assertEquals(!false || true, scope.$eval("!false || true")); + assertEquals(!11 == 10, scope.$eval("!11 == 10")); + assertEquals(12/6/2, scope.$eval("12/6/2")); }; ParserTest.prototype.testBugStringConfusesParser = function() { - var scope = new Scope(); - assertEquals('!', scope.eval('suffix = "!"')); + var scope = createScope(); + assertEquals('!', scope.$eval('suffix = "!"')); }; ParserTest.prototype.testParsingBug = function () { - var scope = new Scope(); - assertEquals({a: "-"}, scope.eval("{a:'-'}")); + var scope = createScope(); + assertEquals({a: "-"}, scope.$eval("{a:'-'}")); }; ParserTest.prototype.testUndefined = function () { - var scope = new Scope(); - assertEquals(undefined, scope.eval("undefined")); - assertEquals(undefined, scope.eval("a=undefined")); - assertEquals(undefined, scope.get("a")); + var scope = createScope(); + assertEquals(undefined, scope.$eval("undefined")); + assertEquals(undefined, scope.$eval("a=undefined")); + assertEquals(undefined, scope.$get("a")); }; diff --git a/test/ResourceSpec.js b/test/ResourceSpec.js index 0c7af00a..91900a91 100644 --- a/test/ResourceSpec.js +++ b/test/ResourceSpec.js @@ -61,7 +61,7 @@ describe("resource", function() { beforeEach(function(){ xhr = new MockXHR(); - resource = new ResourceFactory(_(xhr.method).bind(xhr)); + resource = new ResourceFactory(bind(xhr, xhr.method)); CreditCard = resource.route('/CreditCard/:id:verb', {id:'@id.key'}, { charge:{ method:'POST', diff --git a/test/ScenarioSpec.js b/test/ScenarioSpec.js index 690ce464..9603a28e 100644 --- a/test/ScenarioSpec.js +++ b/test/ScenarioSpec.js @@ -1,50 +1,46 @@ describe("ScenarioSpec: Compilation", function(){ it("should compile dom node and return scope", function(){ - var node = $('
                {{b=a+1}}
                ')[0]; + var node = jqLite('
                {{b=a+1}}
                ')[0]; var scope = angular.compile(node); - scope.init(); - expect(scope.get('a')).toEqual(1); - expect(scope.get('b')).toEqual(2); + 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'); + var scope = angular.compile(jqLite('
                {{a=123}}
                ')).$init(); + expect(jqLite(scope.$element).text()).toEqual('123'); }); it("should compile text node and return scope", function(){ - var scope = angular.compile('
                {{a=123}}
                ').init(); - expect($(scope.element).text()).toEqual('123'); + var scope = angular.compile('
                {{a=123}}
                ').$init(); + expect(jqLite(scope.$element).text()).toEqual('123'); }); }); describe("ScenarioSpec: Scope", function(){ - it("should have set, get, eval, init, updateView methods", function(){ - var scope = angular.compile('
                {{a}}
                ').init(); - scope.eval("$invalidWidgets.push({})"); - expect(scope.set("a", 2)).toEqual(2); - expect(scope.get("a")).toEqual(2); - expect(scope.eval("a=3")).toEqual(3); - scope.updateView(); - expect(scope.eval("$invalidWidgets")).toEqual([]); - expect($(scope.element).text()).toEqual('3'); - }); - - it("should have config", function(){ - expect(angular.compile('
                ', {a:'b'}).config.a).toEqual('b'); + xit("should have set, get, eval, $init, updateView methods", function(){ + var scope = angular.compile('
                {{a}}
                ').$init(); + scope.$eval("$invalidWidgets.push({})"); + expect(scope.$set("a", 2)).toEqual(2); + expect(scope.$get("a")).toEqual(2); + expect(scope.$eval("a=3")).toEqual(3); + scope.$eval(); + expect(scope.$eval("$invalidWidgets")).toEqual([]); + expect(jqLite(scope.$element).text()).toEqual('3'); }); - - it("should have $ objects", function(){ + + xit("should have $ objects", function(){ var scope = angular.compile('
                ', {a:"b"}); - expect(scope.get('$anchor')).toBeDefined(); - expect(scope.get('$updateView')).toBeDefined(); - expect(scope.get('$config')).toBeDefined(); - expect(scope.get('$config.a')).toEqual("b"); - expect(scope.get('$datastore')).toBeDefined(); + expect(scope.$get('$anchor')).toBeDefined(); + expect(scope.$get('$eval')).toBeDefined(); + expect(scope.$get('$config')).toBeDefined(); + expect(scope.$get('$config.a')).toEqual("b"); + expect(scope.$get('$datastore')).toBeDefined(); }); }); -describe("ScenarioSpec: configuration", function(){ +xdescribe("ScenarioSpec: configuration", function(){ it("should take location object", function(){ var url = "http://server/#book=moby"; var onUrlChange; @@ -54,15 +50,15 @@ describe("ScenarioSpec: configuration", function(){ get:function(){return url;} }; var scope = angular.compile("
                {{$anchor}}
                ", {location:location}); - var $anchor = scope.get('$anchor'); + var $anchor = scope.$get('$anchor'); expect($anchor.book).toBeUndefined(); expect(onUrlChange).toBeUndefined(); - scope.init(); + scope.$init(); expect($anchor.book).toEqual('moby'); expect(onUrlChange).toBeDefined(); url = "http://server/#book=none"; - onUrlChange(); + onUrlChange(); expect($anchor.book).toEqual('none'); }); }); diff --git a/test/ValidatorsTest.js b/test/ValidatorsTest.js index 6b61c273..971ff0bb 100644 --- a/test/ValidatorsTest.js +++ b/test/ValidatorsTest.js @@ -1,6 +1,6 @@ ValidatorTest = TestCase('ValidatorTest'); -ValidatorTest.prototype.testItShouldHaveThisSet = function() { +ValidatorTest.prototype.XtestItShouldHaveThisSet = function() { expectAsserts(5); var self; angular.validator.myValidator = function(first, last){ @@ -9,9 +9,9 @@ ValidatorTest.prototype.testItShouldHaveThisSet = function() { self = this; }; var c = compile(''); - c.scope.set('name', 'misko'); - c.scope.set('state', 'abc'); - c.binder.updateView(); + c.scope.$set('name', 'misko'); + c.scope.$set('state', 'abc'); + c.scope.$eval(); assertEquals('abc', self.state); assertEquals('misko', self.name); assertEquals('name', self.$element.name); @@ -91,19 +91,19 @@ describe('Validator:asynchronous', function(){ value = null; fn = null; self = { - $element:$('')[0], + $element:jqLite('')[0], $invalidWidgets:[], $updateView: noop }; }); - it('should make a request and show spinner', function(){ + xit('should make a request and show spinner', function(){ var x = compile(''); var asyncFn = function(v,f){value=v; fn=f;}; var input = x.node.find(":input"); - x.scope.set("asyncFn", asyncFn); - x.scope.set("name", "misko"); - x.binder.updateView(); + x.scope.$set("asyncFn", asyncFn); + x.scope.$set("name", "misko"); + x.scope.$eval(); expect(value).toEqual('misko'); expect(input.hasClass('ng-input-indicator-wait')).toBeTruthy(); fn("myError"); @@ -130,9 +130,9 @@ describe('Validator:asynchronous', function(){ asynchronous.call(self, "second", function(v,f){value=v; secondCb=f;}); firstCb(); - expect($(self.$element).hasClass('ng-input-indicator-wait')).toBeTruthy(); + expect(jqLite(self.$element).hasClass('ng-input-indicator-wait')).toBeTruthy(); secondCb(); - expect($(self.$element).hasClass('ng-input-indicator-wait')).toBeFalsy(); + expect(jqLite(self.$element).hasClass('ng-input-indicator-wait')).toBeFalsy(); }); }); diff --git a/test/WidgetsTest.js b/test/WidgetsTest.js deleted file mode 100644 index 313d7372..00000000 --- a/test/WidgetsTest.js +++ /dev/null @@ -1,268 +0,0 @@ -WidgetTest = TestCase('WidgetTest'); - -WidgetTest.prototype.testRequired = function () { - var view = $(''); - var scope = new Scope({$invalidWidgets:[]}); - var cntl = new TextController(view[0], 'a', angularFormatter.noop); - cntl.updateView(scope); - assertTrue(view.hasClass('ng-validation-error')); - assertEquals("Required Value", view.attr('ng-error')); - scope.set('a', 'A'); - cntl.updateView(scope); - assertFalse(view.hasClass('ng-validation-error')); - assertEquals("undefined", typeof view.attr('ng-error')); -}; - -WidgetTest.prototype.testValidator = function () { - var view = $(''); - var scope = new Scope({$invalidWidgets:[]}); - var cntl = new TextController(view[0], 'a', angularFormatter.noop); - angular.validator.testValidator = function(value, expect){ - return value == expect ? false : "Error text"; - }; - - scope.set('a', ''); - cntl.updateView(scope); - assertEquals(view.hasClass('ng-validation-error'), false); - assertEquals(null, view.attr('ng-error')); - - scope.set('a', 'X'); - cntl.updateView(scope); - assertEquals(view.hasClass('ng-validation-error'), true); - assertEquals(view.attr('ng-error'), "Error text"); - assertEquals("Error text", view.attr('ng-error')); - - scope.set('a', 'ABC'); - cntl.updateView(scope); - assertEquals(view.hasClass('ng-validation-error'), false); - assertEquals(view.attr('ng-error'), null); - assertEquals(null, view.attr('ng-error')); - - delete angular.validator['testValidator']; -}; - -WidgetTest.prototype.testRequiredValidator = function () { - var view = $(''); - var scope = new Scope({$invalidWidgets:[]}); - var cntl = new TextController(view[0], 'a', angularFormatter.noop); - angular.validator.testValidator = function(value, expect){ - return value == expect ? null : "Error text"; - }; - - scope.set('a', ''); - cntl.updateView(scope); - assertEquals(view.hasClass('ng-validation-error'), true); - assertEquals("Required Value", view.attr('ng-error')); - - scope.set('a', 'X'); - cntl.updateView(scope); - assertEquals(view.hasClass('ng-validation-error'), true); - assertEquals("Error text", view.attr('ng-error')); - - scope.set('a', 'ABC'); - cntl.updateView(scope); - assertEquals(view.hasClass('ng-validation-error'), false); - assertEquals(null, view.attr('ng-error')); - - delete angular.validator['testValidator']; -}; - -TextControllerTest = TestCase("TextControllerTest"); - -TextControllerTest.prototype.testDatePicker = function() { - var input = $(''); - input.data('scope', new Scope()); - var body = $(document.body); - body.append(input); - var binder = new Binder(input[0], new WidgetFactory()); - assertTrue('before', input.data('datepicker') === undefined); - binder.compile(); - assertTrue('after', input.data('datepicker') !== null); - assertTrue(body.html(), input.hasClass('hasDatepicker')); -}; - -RepeaterUpdaterTest = TestCase("RepeaterUpdaterTest"); - -RepeaterUpdaterTest.prototype.testRemoveThenAdd = function() { - var view = $("
                "); - var template = function () { - return $("
              • "); - }; - var repeater = new RepeaterUpdater(view.find("span"), "a in b", template, ""); - var scope = new Scope(); - scope.set('b', [1,2]); - - repeater.updateView(scope); - - scope.set('b', []); - repeater.updateView(scope); - - scope.set('b', [1]); - repeater.updateView(scope); - assertEquals(1, view.find("li").size()); -}; - -RepeaterUpdaterTest.prototype.testShouldBindWidgetOnRepeaterClone = function(){ - //fail(); -}; - -RepeaterUpdaterTest.prototype.testShouldThrowInformativeSyntaxError= function(){ - expectAsserts(1); - try { - var repeater = new RepeaterUpdater(null, "a=b"); - } catch (e) { - assertEquals("Expected ng-repeat in form of 'item in collection' but got 'a=b'.", e); - } -}; - -SelectControllerTest = TestCase("SelectControllerTest"); - -SelectControllerTest.prototype.testShouldUpdateModelNullOnNothingSelected = function(){ - var scope = new Scope(); - var view = {selectedIndex:-1, options:[]}; - var cntl = new SelectController(view, 'abc'); - cntl.updateModel(scope); - assertNull(scope.get('abc')); -}; - -SelectControllerTest.prototype.testShouldUpdateModelWhenNothingSelected = function(){ - var scope = new Scope(); - var view = {value:'123'}; - var cntl = new SelectController(view, 'abc'); - cntl.updateView(scope); - assertEquals("123", scope.get('abc')); -}; - -BindUpdaterTest = TestCase("BindUpdaterTest"); - -BindUpdaterTest.prototype.testShouldDisplayNothingForUndefined = function () { - var view = $(''); - var controller = new BindUpdater(view[0], "{{a}}"); - var scope = new Scope(); - - scope.set('a', undefined); - controller.updateView(scope); - assertEquals("", view.text()); - - scope.set('a', null); - controller.updateView(scope); - assertEquals("", view.text()); -}; - -BindUpdaterTest.prototype.testShouldDisplayJsonForNonStrings = function () { - var view = $(''); - var controller = new BindUpdater(view[0], "{{obj}}"); - - controller.updateView(new Scope({obj:[]})); - assertEquals("[]", view.text()); - - controller.updateView(new Scope({obj:{text:'abc'}})); - assertEquals('abc', fromJson(view.text()).text); -}; - - -BindUpdaterTest.prototype.testShouldInsertHtmlNode = function () { - var view = $(''); - var controller = new BindUpdater(view[0], "&{{obj}}"); - var scope = new Scope(); - - scope.set("obj", $('
                myDiv
                ')[0]); - controller.updateView(scope); - assertEquals("&myDiv", view.text()); -}; - - -BindUpdaterTest.prototype.testShouldDisplayTextMethod = function () { - var view = $('
                '); - var controller = new BindUpdater(view[0], "{{obj}}"); - var scope = new Scope(); - - scope.set("obj", new angular.filter.Meta({text:function(){return "abc";}})); - controller.updateView(scope); - assertEquals("abc", view.text()); - - scope.set("obj", new angular.filter.Meta({text:"123"})); - controller.updateView(scope); - assertEquals("123", view.text()); - - scope.set("obj", {text:"123"}); - controller.updateView(scope); - assertEquals("123", fromJson(view.text()).text); -}; - -BindUpdaterTest.prototype.testShouldDisplayHtmlMethod = function () { - var view = $('
                '); - var controller = new BindUpdater(view[0], "{{obj}}"); - var scope = new Scope(); - - scope.set("obj", new angular.filter.Meta({html:function(){return "a
                b
                c";}})); - controller.updateView(scope); - assertEquals("abc", view.text()); - - scope.set("obj", new angular.filter.Meta({html:"1
                2
                3"})); - controller.updateView(scope); - assertEquals("123", view.text()); - - scope.set("obj", {html:"123"}); - controller.updateView(scope); - assertEquals("123", fromJson(view.text()).html); -}; - -BindUpdaterTest.prototype.testUdateBoolean = function() { - var view = $('
                '); - var controller = new BindUpdater(view[0], "{{true}}, {{false}}"); - controller.updateView(new Scope()); - assertEquals('true, false', view.text()); -}; - -BindAttrUpdaterTest = TestCase("BindAttrUpdaterTest"); - -BindAttrUpdaterTest.prototype.testShouldLoadBlankImageWhenBindingIsUndefined = function () { - var view = $(''); - var controller = new BindAttrUpdater(view[0], {src: '{{imageUrl}}'}); - - var scope = new Scope(); - scope.set('imageUrl', undefined); - scope.set('$config.blankImage', 'http://server/blank.gif'); - - controller.updateView(scope); - assertEquals("http://server/blank.gif", view.attr('src')); -}; - -RepeaterUpdaterTest.prototype.testShouldNotDieWhenRepeatExpressionIsNull = function() { - var rep = new RepeaterUpdater(null, "$item in items", null, null); - var scope = new Scope(); - scope.set('items', undefined); - rep.updateView(scope); -}; - -RepeaterUpdaterTest.prototype.testShouldIterateOverKeys = function() { - var rep = new RepeaterUpdater(null, "($k,_v) in items", null, null); - assertEquals("items", rep.iteratorExp); - assertEquals("_v", rep.valueExp); - assertEquals("$k", rep.keyExp); -}; - -EvalUpdaterTest = TestCase("EvalUpdaterTest"); -EvalUpdaterTest.prototype.testEvalThrowsException = function(){ - var view = $('
                '); - var eval = new EvalUpdater(view[0], 'undefined()'); - - eval.updateView(new Scope()); - assertTrue(!!view.attr('ng-error')); - assertTrue(view.hasClass('ng-exception')); - - eval.exp = "1"; - eval.updateView(new Scope()); - assertFalse(!!view.attr('ng-error')); - assertFalse(view.hasClass('ng-exception')); -}; - -RadioControllerTest = TestCase("RadioController"); -RadioControllerTest.prototype.testItShouldTreatTrueStringAsBoolean = function () { - var view = $(''); - var radio = new RadioController(view[0], 'select'); - var scope = new Scope({select:true}); - radio.updateView(scope); - assertTrue(view[0].checked); -}; diff --git a/test/delete/WidgetsTest.js b/test/delete/WidgetsTest.js new file mode 100644 index 00000000..313d7372 --- /dev/null +++ b/test/delete/WidgetsTest.js @@ -0,0 +1,268 @@ +WidgetTest = TestCase('WidgetTest'); + +WidgetTest.prototype.testRequired = function () { + var view = $(''); + var scope = new Scope({$invalidWidgets:[]}); + var cntl = new TextController(view[0], 'a', angularFormatter.noop); + cntl.updateView(scope); + assertTrue(view.hasClass('ng-validation-error')); + assertEquals("Required Value", view.attr('ng-error')); + scope.set('a', 'A'); + cntl.updateView(scope); + assertFalse(view.hasClass('ng-validation-error')); + assertEquals("undefined", typeof view.attr('ng-error')); +}; + +WidgetTest.prototype.testValidator = function () { + var view = $(''); + var scope = new Scope({$invalidWidgets:[]}); + var cntl = new TextController(view[0], 'a', angularFormatter.noop); + angular.validator.testValidator = function(value, expect){ + return value == expect ? false : "Error text"; + }; + + scope.set('a', ''); + cntl.updateView(scope); + assertEquals(view.hasClass('ng-validation-error'), false); + assertEquals(null, view.attr('ng-error')); + + scope.set('a', 'X'); + cntl.updateView(scope); + assertEquals(view.hasClass('ng-validation-error'), true); + assertEquals(view.attr('ng-error'), "Error text"); + assertEquals("Error text", view.attr('ng-error')); + + scope.set('a', 'ABC'); + cntl.updateView(scope); + assertEquals(view.hasClass('ng-validation-error'), false); + assertEquals(view.attr('ng-error'), null); + assertEquals(null, view.attr('ng-error')); + + delete angular.validator['testValidator']; +}; + +WidgetTest.prototype.testRequiredValidator = function () { + var view = $(''); + var scope = new Scope({$invalidWidgets:[]}); + var cntl = new TextController(view[0], 'a', angularFormatter.noop); + angular.validator.testValidator = function(value, expect){ + return value == expect ? null : "Error text"; + }; + + scope.set('a', ''); + cntl.updateView(scope); + assertEquals(view.hasClass('ng-validation-error'), true); + assertEquals("Required Value", view.attr('ng-error')); + + scope.set('a', 'X'); + cntl.updateView(scope); + assertEquals(view.hasClass('ng-validation-error'), true); + assertEquals("Error text", view.attr('ng-error')); + + scope.set('a', 'ABC'); + cntl.updateView(scope); + assertEquals(view.hasClass('ng-validation-error'), false); + assertEquals(null, view.attr('ng-error')); + + delete angular.validator['testValidator']; +}; + +TextControllerTest = TestCase("TextControllerTest"); + +TextControllerTest.prototype.testDatePicker = function() { + var input = $(''); + input.data('scope', new Scope()); + var body = $(document.body); + body.append(input); + var binder = new Binder(input[0], new WidgetFactory()); + assertTrue('before', input.data('datepicker') === undefined); + binder.compile(); + assertTrue('after', input.data('datepicker') !== null); + assertTrue(body.html(), input.hasClass('hasDatepicker')); +}; + +RepeaterUpdaterTest = TestCase("RepeaterUpdaterTest"); + +RepeaterUpdaterTest.prototype.testRemoveThenAdd = function() { + var view = $("
                "); + var template = function () { + return $("
              • "); + }; + var repeater = new RepeaterUpdater(view.find("span"), "a in b", template, ""); + var scope = new Scope(); + scope.set('b', [1,2]); + + repeater.updateView(scope); + + scope.set('b', []); + repeater.updateView(scope); + + scope.set('b', [1]); + repeater.updateView(scope); + assertEquals(1, view.find("li").size()); +}; + +RepeaterUpdaterTest.prototype.testShouldBindWidgetOnRepeaterClone = function(){ + //fail(); +}; + +RepeaterUpdaterTest.prototype.testShouldThrowInformativeSyntaxError= function(){ + expectAsserts(1); + try { + var repeater = new RepeaterUpdater(null, "a=b"); + } catch (e) { + assertEquals("Expected ng-repeat in form of 'item in collection' but got 'a=b'.", e); + } +}; + +SelectControllerTest = TestCase("SelectControllerTest"); + +SelectControllerTest.prototype.testShouldUpdateModelNullOnNothingSelected = function(){ + var scope = new Scope(); + var view = {selectedIndex:-1, options:[]}; + var cntl = new SelectController(view, 'abc'); + cntl.updateModel(scope); + assertNull(scope.get('abc')); +}; + +SelectControllerTest.prototype.testShouldUpdateModelWhenNothingSelected = function(){ + var scope = new Scope(); + var view = {value:'123'}; + var cntl = new SelectController(view, 'abc'); + cntl.updateView(scope); + assertEquals("123", scope.get('abc')); +}; + +BindUpdaterTest = TestCase("BindUpdaterTest"); + +BindUpdaterTest.prototype.testShouldDisplayNothingForUndefined = function () { + var view = $(''); + var controller = new BindUpdater(view[0], "{{a}}"); + var scope = new Scope(); + + scope.set('a', undefined); + controller.updateView(scope); + assertEquals("", view.text()); + + scope.set('a', null); + controller.updateView(scope); + assertEquals("", view.text()); +}; + +BindUpdaterTest.prototype.testShouldDisplayJsonForNonStrings = function () { + var view = $(''); + var controller = new BindUpdater(view[0], "{{obj}}"); + + controller.updateView(new Scope({obj:[]})); + assertEquals("[]", view.text()); + + controller.updateView(new Scope({obj:{text:'abc'}})); + assertEquals('abc', fromJson(view.text()).text); +}; + + +BindUpdaterTest.prototype.testShouldInsertHtmlNode = function () { + var view = $(''); + var controller = new BindUpdater(view[0], "&{{obj}}"); + var scope = new Scope(); + + scope.set("obj", $('
                myDiv
                ')[0]); + controller.updateView(scope); + assertEquals("&myDiv", view.text()); +}; + + +BindUpdaterTest.prototype.testShouldDisplayTextMethod = function () { + var view = $('
                '); + var controller = new BindUpdater(view[0], "{{obj}}"); + var scope = new Scope(); + + scope.set("obj", new angular.filter.Meta({text:function(){return "abc";}})); + controller.updateView(scope); + assertEquals("abc", view.text()); + + scope.set("obj", new angular.filter.Meta({text:"123"})); + controller.updateView(scope); + assertEquals("123", view.text()); + + scope.set("obj", {text:"123"}); + controller.updateView(scope); + assertEquals("123", fromJson(view.text()).text); +}; + +BindUpdaterTest.prototype.testShouldDisplayHtmlMethod = function () { + var view = $('
                '); + var controller = new BindUpdater(view[0], "{{obj}}"); + var scope = new Scope(); + + scope.set("obj", new angular.filter.Meta({html:function(){return "a
                b
                c";}})); + controller.updateView(scope); + assertEquals("abc", view.text()); + + scope.set("obj", new angular.filter.Meta({html:"1
                2
                3"})); + controller.updateView(scope); + assertEquals("123", view.text()); + + scope.set("obj", {html:"123"}); + controller.updateView(scope); + assertEquals("123", fromJson(view.text()).html); +}; + +BindUpdaterTest.prototype.testUdateBoolean = function() { + var view = $('
                '); + var controller = new BindUpdater(view[0], "{{true}}, {{false}}"); + controller.updateView(new Scope()); + assertEquals('true, false', view.text()); +}; + +BindAttrUpdaterTest = TestCase("BindAttrUpdaterTest"); + +BindAttrUpdaterTest.prototype.testShouldLoadBlankImageWhenBindingIsUndefined = function () { + var view = $(''); + var controller = new BindAttrUpdater(view[0], {src: '{{imageUrl}}'}); + + var scope = new Scope(); + scope.set('imageUrl', undefined); + scope.set('$config.blankImage', 'http://server/blank.gif'); + + controller.updateView(scope); + assertEquals("http://server/blank.gif", view.attr('src')); +}; + +RepeaterUpdaterTest.prototype.testShouldNotDieWhenRepeatExpressionIsNull = function() { + var rep = new RepeaterUpdater(null, "$item in items", null, null); + var scope = new Scope(); + scope.set('items', undefined); + rep.updateView(scope); +}; + +RepeaterUpdaterTest.prototype.testShouldIterateOverKeys = function() { + var rep = new RepeaterUpdater(null, "($k,_v) in items", null, null); + assertEquals("items", rep.iteratorExp); + assertEquals("_v", rep.valueExp); + assertEquals("$k", rep.keyExp); +}; + +EvalUpdaterTest = TestCase("EvalUpdaterTest"); +EvalUpdaterTest.prototype.testEvalThrowsException = function(){ + var view = $('
                '); + var eval = new EvalUpdater(view[0], 'undefined()'); + + eval.updateView(new Scope()); + assertTrue(!!view.attr('ng-error')); + assertTrue(view.hasClass('ng-exception')); + + eval.exp = "1"; + eval.updateView(new Scope()); + assertFalse(!!view.attr('ng-error')); + assertFalse(view.hasClass('ng-exception')); +}; + +RadioControllerTest = TestCase("RadioController"); +RadioControllerTest.prototype.testItShouldTreatTrueStringAsBoolean = function () { + var view = $(''); + var radio = new RadioController(view[0], 'select'); + var scope = new Scope({select:true}); + radio.updateView(scope); + assertTrue(view[0].checked); +}; diff --git a/test/directivesSpec.js b/test/directivesSpec.js index 4ef57dce..343698af 100644 --- a/test/directivesSpec.js +++ b/test/directivesSpec.js @@ -14,7 +14,7 @@ describe("directives", function(){ afterEach(function() { model.$element.remove(); - expect(_(jqCache).size()).toEqual(0); + expect(size(jqCache)).toEqual(0); }); it("should ng-init", function() { @@ -24,8 +24,6 @@ describe("directives", function(){ it("should ng-eval", function() { var scope = compile('
                '); - expect(scope.a).toEqual(0); - scope.$eval(); expect(scope.a).toEqual(1); scope.$eval(); expect(scope.a).toEqual(2); @@ -41,7 +39,6 @@ describe("directives", function(){ it('should ng-bind-template', function() { var scope = compile('
                '); - expect(element.text()).toEqual(''); scope.$set('name', 'Misko'); scope.$eval(); expect(element.text()).toEqual('Hello Misko!'); @@ -49,9 +46,6 @@ describe("directives", function(){ it('should ng-bind-attr', function(){ var scope = compile(''); - expect(element.attr('src')).toEqual(null); - expect(element.attr('alt')).toEqual(null); - scope.$eval(); expect(element.attr('src')).toEqual('mysrc'); expect(element.attr('alt')).toEqual('myalt'); }); @@ -126,8 +120,8 @@ describe("directives", function(){ it('should ng-class odd/even', function(){ var scope = compile('
                  • '); scope.$eval(); - var e1 = jQuery(element.parent()[0]).find('li:first'); - var e2 = jQuery(element.parent()[0]).find('li:last'); + var e1 = jqLite(element[0].childNodes[1]); + var e2 = jqLite(element[0].childNodes[2]); expect(e1.hasClass('existing')).toBeTruthy(); expect(e1.hasClass('even')).toBeTruthy(); expect(e2.hasClass('existing')).toBeTruthy(); diff --git a/test/markupSpec.js b/test/markupSpec.js index c83f27ff..2ddefe47 100644 --- a/test/markupSpec.js +++ b/test/markupSpec.js @@ -14,10 +14,8 @@ describe("markups", function(){ }); afterEach(function(){ - if (element) { - element.remove(); - } - expect(_(jqCache).size()).toEqual(0); + if (element) element.remove(); + expect(size(jqCache)).toEqual(0); }); it('should translate {{}} in text', function(){ @@ -30,7 +28,7 @@ describe("markups", function(){ it('should translate {{}} in terminal nodes', function(){ compile(''); - expect(element.html()).toEqual(''); + expect(element.html()).toEqual(''); scope.$set('name', 'Misko'); scope.$eval(); expect(element.html()).toEqual(''); @@ -38,7 +36,6 @@ describe("markups", function(){ it('should translate {{}} in attributes', function(){ compile(''); - expect(element.attr('src')).toEqual(); expect(element.attr('ng-bind-attr')).toEqual('{"src":"http://server/{{path}}.png"}'); scope.$set('path', 'a/b'); scope.$eval(); @@ -51,3 +48,91 @@ describe("markups", function(){ }); }); + + +var BindingMarkupTest = TestCase("BindingMarkupTest"); + +BindingMarkupTest.prototype.testParseTextWithNoBindings = function(){ + var parts = parseBindings("a"); + assertEquals(parts.length, 1); + assertEquals(parts[0], "a"); + assertTrue(!binding(parts[0])); +}; + +BindingMarkupTest.prototype.testParseEmptyText = function(){ + var parts = parseBindings(""); + assertEquals(parts.length, 1); + assertEquals(parts[0], ""); + assertTrue(!binding(parts[0])); +}; + +BindingMarkupTest.prototype.testParseInnerBinding = function(){ + var parts = parseBindings("a{{b}}c"); + assertEquals(parts.length, 3); + assertEquals(parts[0], "a"); + assertTrue(!binding(parts[0])); + assertEquals(parts[1], "{{b}}"); + assertEquals(binding(parts[1]), "b"); + assertEquals(parts[2], "c"); + assertTrue(!binding(parts[2])); +}; + +BindingMarkupTest.prototype.testParseEndingBinding = function(){ + var parts = parseBindings("a{{b}}"); + assertEquals(parts.length, 2); + assertEquals(parts[0], "a"); + assertTrue(!binding(parts[0])); + assertEquals(parts[1], "{{b}}"); + assertEquals(binding(parts[1]), "b"); +}; + +BindingMarkupTest.prototype.testParseBeggingBinding = function(){ + var parts = parseBindings("{{b}}c"); + assertEquals(parts.length, 2); + assertEquals(parts[0], "{{b}}"); + assertEquals(binding(parts[0]), "b"); + assertEquals(parts[1], "c"); + assertTrue(!binding(parts[1])); +}; + +BindingMarkupTest.prototype.testParseLoanBinding = function(){ + var parts = parseBindings("{{b}}"); + assertEquals(parts.length, 1); + assertEquals(parts[0], "{{b}}"); + assertEquals(binding(parts[0]), "b"); +}; + +BindingMarkupTest.prototype.testParseTwoBindings = function(){ + var parts = parseBindings("{{b}}{{c}}"); + assertEquals(parts.length, 2); + assertEquals(parts[0], "{{b}}"); + assertEquals(binding(parts[0]), "b"); + assertEquals(parts[1], "{{c}}"); + assertEquals(binding(parts[1]), "c"); +}; + +BindingMarkupTest.prototype.testParseTwoBindingsWithTextInMiddle = function(){ + var parts = parseBindings("{{b}}x{{c}}"); + assertEquals(parts.length, 3); + assertEquals(parts[0], "{{b}}"); + assertEquals(binding(parts[0]), "b"); + assertEquals(parts[1], "x"); + assertTrue(!binding(parts[1])); + assertEquals(parts[2], "{{c}}"); + assertEquals(binding(parts[2]), "c"); +}; + +BindingMarkupTest.prototype.testParseMultiline = function(){ + var parts = parseBindings('"X\nY{{A\nB}}C\nD"'); + assertTrue(!!binding('{{A\nB}}')); + assertEquals(parts.length, 3); + assertEquals(parts[0], '"X\nY'); + assertEquals(parts[1], '{{A\nB}}'); + assertEquals(parts[2], 'C\nD"'); +}; + +BindingMarkupTest.prototype.testHasBinding = function(){ + assertTrue(hasBindings("{{a}}")); + assertTrue(!hasBindings("a")); + assertTrue(hasBindings("{{b}}x{{c}}")); +}; diff --git a/test/testabilityPatch.js b/test/testabilityPatch.js index e7ebb386..7c16828d 100644 --- a/test/testabilityPatch.js +++ b/test/testabilityPatch.js @@ -1,16 +1,5 @@ -HIDDEN = jQuery.browser.msie ? - '' : - jQuery.browser.safari ? - ' style="display: none; "' : - ' style="display: none;"'; - -msie = jQuery.browser.msie; -//alert = function(msg) {jstestdriver.console.log("ALERT: " + msg);}; - -function noop(){} - jstd = jstestdriver; -dump = _(jstd.console.log).bind(jstd.console); +dump = bind(jstd.console, jstd.console.log); function nakedExpect(obj) { return expect(angular.fromJson(angular.toJson(obj))); @@ -48,10 +37,9 @@ MockLocation.prototype.set = function(url){ this.url = url; }; -jQuery.fn.sortedHtml = function() { +function sortedHtml(element) { var html = ""; - var toString = function(index, node) { - node = node || this; + (function toString(node) { if (node.nodeName == "#text") { html += escapeHtml(node.nodeValue); } else { @@ -82,25 +70,14 @@ jQuery.fn.sortedHtml = function() { html += '>'; var children = node.childNodes; for(var j=0; j'; } - }; - this.children().each(toString); + })(element[0]); return html; }; -function encode64(obj){ - return Base64.encode(toJson(obj)); -} - -function decode64(base64){ - return fromJson(Base64.decode(base64)); -} - -configureJQueryPlugins(); - function isVisible(node) { var display = $(node).css('display'); if (display == 'block') display = ""; diff --git a/test/widgetsSpec.js b/test/widgetsSpec.js index d6c44f68..dd65b5bd 100644 --- a/test/widgetsSpec.js +++ b/test/widgetsSpec.js @@ -15,7 +15,7 @@ describe("input widget", function(){ afterEach(function(){ if (element) element.remove(); - expect(_(jqCache).size()).toEqual(0); + expect(size(jqCache)).toEqual(0); }); it('should input-text auto init and handle keyup/change events', function(){ -- cgit v1.2.3 From cc6def854f2c77d0a7fea177df0dca858b8cd943 Mon Sep 17 00:00:00 2001 From: Misko Hevery Date: Mon, 29 Mar 2010 21:36:34 -0700 Subject: reenabled more tests --- test/ValidatorsTest.js | 27 +++++++++++++++++++-------- test/widgetsSpec.js | 4 +++- 2 files changed, 22 insertions(+), 9 deletions(-) (limited to 'test') diff --git a/test/ValidatorsTest.js b/test/ValidatorsTest.js index 971ff0bb..37be526d 100644 --- a/test/ValidatorsTest.js +++ b/test/ValidatorsTest.js @@ -91,24 +91,35 @@ describe('Validator:asynchronous', function(){ value = null; fn = null; self = { - $element:jqLite('')[0], + $element:jqLite(''), $invalidWidgets:[], $updateView: noop }; }); - xit('should make a request and show spinner', function(){ - var x = compile(''); - var asyncFn = function(v,f){value=v; fn=f;}; - var input = x.node.find(":input"); - x.scope.$set("asyncFn", asyncFn); - x.scope.$set("name", "misko"); - x.scope.$eval(); + afterEach(function(){ + if (self.$element) self.$element.remove(); + var oldCache = jqCache; + jqCache = {}; + expect(size(oldCache)).toEqual(0); + }); + + it('should make a request and show spinner', function(){ + var value, fn; + var scope = angular.compile(''); + scope.$init(); + var input = scope.$element; + scope.asyncFn = function(v,f){ + value=v; fn=f; + }; + scope.name = "misko"; + scope.$eval(); expect(value).toEqual('misko'); expect(input.hasClass('ng-input-indicator-wait')).toBeTruthy(); fn("myError"); expect(input.hasClass('ng-input-indicator-wait')).toBeFalsy(); expect(input.attr('ng-error')).toEqual("myError"); + scope.$element.remove(); }); it("should not make second request to same value", function(){ diff --git a/test/widgetsSpec.js b/test/widgetsSpec.js index dd65b5bd..152b01f3 100644 --- a/test/widgetsSpec.js +++ b/test/widgetsSpec.js @@ -15,7 +15,9 @@ describe("input widget", function(){ afterEach(function(){ if (element) element.remove(); - expect(size(jqCache)).toEqual(0); + var oldCache = jqCache; + jqCache = {}; + expect(size(oldCache)).toEqual(0); }); it('should input-text auto init and handle keyup/change events', function(){ -- cgit v1.2.3 From d2d356918bd1c0c76673d22ff85c617fbd85d40e Mon Sep 17 00:00:00 2001 From: Misko Hevery Date: Mon, 29 Mar 2010 21:49:12 -0700 Subject: reenabled more tests --- test/BinderTest.js | 153 ++++++++++++++++++++++------------------------------- test/ScopeSpec.js | 4 +- 2 files changed, 66 insertions(+), 91 deletions(-) (limited to 'test') diff --git a/test/BinderTest.js b/test/BinderTest.js index cc101f4d..c21420af 100644 --- a/test/BinderTest.js +++ b/test/BinderTest.js @@ -19,7 +19,6 @@ BinderTest.prototype.tearDown = function(){ if (this.element) this.element.remove(); }; - BinderTest.prototype.testChangingTextfieldUpdatesModel = function(){ var state = this.compile('', {model:{}}); state.scope.$eval(); @@ -91,7 +90,7 @@ BinderTest.prototype.testReplaceBindingInTextWithSpan = function() { assertEquals(this.compileToHtml("{{b}}"), ''); }; -BinderTest.prototype.XtestBindingSpaceConfusesIE = function() { +BinderTest.prototype.testBindingSpaceConfusesIE = function() { //if (!msie) return; var span = document.createElement("span"); span.innerHTML = ' '; @@ -143,31 +142,7 @@ BinderTest.prototype.testAttributesAreEvaluated = function(){ assertEquals(a.attr('b'), 'a+b=3'); }; -BinderTest.prototype.XtestInputsAreUpdated = function(){ - var a = - this.compile('
                    ' + - '' + - '' + - '' + - '' + - '' + - '' + - '' + - '
                    '); - var form = a.node; - a.scope.$set('A', {text:"t1", textarea:"t2", radio:"r", checkbox:"c", select:"S"}); - a.scope.$eval(); - assertEquals(form.find("input[type=text]").attr('value'), 't1'); - assertEquals(form.find("textarea").attr('value'), 't2'); - assertTrue(form.find("input[name=A.radio]").attr('checked')); - assertTrue(!form.find("input[name=A.radioOff]").attr('checked')); - assertTrue(form.find("input[name=A.checkbox]").attr('checked')); - assertTrue(!form.find("input[name=A.checkboxOff]").attr('checked')); - assertEquals(form.find("select").attr('value'), 'S'); - assertEquals(form.find("option[selected]").text(), 'b'); -}; - -BinderTest.prototype.xtestInputTypeButtonActionExecutesInScope = function(){ +BinderTest.prototype.testInputTypeButtonActionExecutesInScope = function(){ var savedCalled = false; var c = this.compile(''); c.scope.$set("person.save", function(){ @@ -177,7 +152,7 @@ BinderTest.prototype.xtestInputTypeButtonActionExecutesInScope = function(){ assertTrue(savedCalled); }; -BinderTest.prototype.testInputTypeButtonActionExecutesInScope = function(){ +BinderTest.prototype.testInputTypeButtonActionExecutesInScope2 = function(){ expectAsserts(1); var c = this.compile(''); c.scope.$set("action", function(){ @@ -196,7 +171,7 @@ BinderTest.prototype.testButtonElementActionExecutesInScope = function(){ assertTrue(savedCalled); }; -BinderTest.prototype.XtestParseEmptyAnchor = function(){ +BinderTest.prototype.testParseEmptyAnchor = function(){ var binder = this.compile("
                    ").binder; var location = binder.location; var anchor = binder.anchor; @@ -210,7 +185,7 @@ BinderTest.prototype.XtestParseEmptyAnchor = function(){ assertEquals('undefined', typeof (anchor[""])); }; -BinderTest.prototype.XtestParseAnchor = function(){ +BinderTest.prototype.testParseAnchor = function(){ var binder = this.compile("
                    ").binder; var location = binder.location; location.url = "a#x=1"; @@ -224,7 +199,7 @@ BinderTest.prototype.XtestParseAnchor = function(){ assertTrue(!binder.anchor.x); }; -BinderTest.prototype.XtestWriteAnchor = function(){ +BinderTest.prototype.testWriteAnchor = function(){ var binder = this.compile("
                    ").binder; binder.location.set('a'); binder.anchor.a = 'b'; @@ -234,7 +209,7 @@ BinderTest.prototype.XtestWriteAnchor = function(){ assertEquals(binder.location.get(), "a#a=b&c=%20&d"); }; -BinderTest.prototype.XtestWriteAnchorAsPartOfTheUpdateView = function(){ +BinderTest.prototype.testWriteAnchorAsPartOfTheUpdateView = function(){ var binder = this.compile("
                    ").binder; binder.location.set('a'); binder.anchor.a = 'b'; @@ -242,7 +217,7 @@ BinderTest.prototype.XtestWriteAnchorAsPartOfTheUpdateView = function(){ assertEquals(binder.location.get(), "a#a=b"); }; -BinderTest.prototype.XtestRepeaterUpdateBindings = function(){ +BinderTest.prototype.testRepeaterUpdateBindings = function(){ var a = this.compile('
                    '); var form = a.node; var items = [{a:"A"}, {a:"B"}]; @@ -281,7 +256,7 @@ BinderTest.prototype.XtestRepeaterUpdateBindings = function(){ assertEquals("I have leaked " + (currentDataCount - initialDataCount), initialDataCount, currentDataCount); }; -BinderTest.prototype.XtestRepeaterContentDoesNotBind = function(){ +BinderTest.prototype.testRepeaterContentDoesNotBind = function(){ var a = this.compile('
                    '); a.scope.$set('model', {items:[{a:"A"}]}); a.scope.$eval(); @@ -291,12 +266,12 @@ BinderTest.prototype.XtestRepeaterContentDoesNotBind = function(){ '
                  ', sortedHtml(a.node)); }; -BinderTest.prototype.XtestShouldBindActionsOnRepeaterClone = function(){ +BinderTest.prototype.testShouldBindActionsOnRepeaterClone = function(){ var c = this.compile('link'); jQuery(c).die(); c.scope.$set('result.value', false); c.scope.$set('items', ['abc', 'xyz']); - c.scope.updateView(); + c.scope.$eval(); assertEquals(2, c.node.find("a").size()); c.node.find("a:last").click(); assertEquals('xyz', c.scope.$get('result.value')); @@ -304,26 +279,26 @@ BinderTest.prototype.XtestShouldBindActionsOnRepeaterClone = function(){ -BinderTest.prototype.XtestRepeaterInputContentDoesNotBind = function(){ +BinderTest.prototype.testRepeaterInputContentDoesNotBind = function(){ var c = compil('
                  • ' + '
                  '); c.scope.items = [{a:"A"}]; assertEquals(c.node.find(":input").attr("value"), "OLD"); }; -BinderTest.prototype.XtestExpandEntityTag = function(){ +BinderTest.prototype.testExpandEntityTag = function(){ assertEquals( '
                  ', this.compileToHtml('
                  ')); }; -BinderTest.prototype.XtestExpandEntityTagWithDefaults = function(){ +BinderTest.prototype.testExpandEntityTagWithDefaults = function(){ assertEquals( '
                  ', this.compileToHtml('
                  ')); }; -BinderTest.prototype.XtestExpandEntityTagWithName = function(){ +BinderTest.prototype.testExpandEntityTagWithName = function(){ var c = this.compile('
                  '); assertEquals( '
                  ', @@ -332,18 +307,18 @@ BinderTest.prototype.XtestExpandEntityTagWithName = function(){ assertEquals("friend", c.scope.$get("friend.$$anchor")); }; -BinderTest.prototype.XtestExpandSubmitButtonToAction = function(){ +BinderTest.prototype.testExpandSubmitButtonToAction = function(){ var html = this.compileToHtml(''); assertTrue(html, html.indexOf('ng-action="$save()"') > 0 ); assertTrue(html, html.indexOf('ng-bind-attr="{"disabled":"{{$invalidWidgets}}"}"') > 0 ); }; -BinderTest.prototype.XtestDoNotOverwriteCustomAction = function(){ +BinderTest.prototype.testDoNotOverwriteCustomAction = function(){ var html = this.compileToHtml(''); assertTrue(html.indexOf('action="foo();"') > 0 ); }; -BinderTest.prototype.XtestReplaceFileUploadWithSwf = function(){ +BinderTest.prototype.testReplaceFileUploadWithSwf = function(){ expectAsserts(1); var form = jQuery("body").append('
                  '); form.data('scope', new Scope()); @@ -357,7 +332,7 @@ BinderTest.prototype.XtestReplaceFileUploadWithSwf = function(){ jQuery("#testTag").remove(); }; -BinderTest.prototype.XtestRepeaterAdd = function(){ +BinderTest.prototype.testRepeaterAdd = function(){ var c = this.compile('
                  '); var doc = c.node; c.scope.$set('items', [{x:'a'}, {x:'b'}]); @@ -372,7 +347,7 @@ BinderTest.prototype.XtestRepeaterAdd = function(){ assertEquals(doc.scope().get('items')[0].x, 'ABC'); }; -BinderTest.prototype.XtestItShouldRemoveExtraChildrenWhenIteratingOverHash = function(){ +BinderTest.prototype.testItShouldRemoveExtraChildrenWhenIteratingOverHash = function(){ var c = this.compile('
                  {{i}}
                  '); var items = {}; c.scope.$set("items", items); @@ -389,7 +364,7 @@ BinderTest.prototype.XtestItShouldRemoveExtraChildrenWhenIteratingOverHash = fun expect(c.node.find("div").size()).toEqual(0); }; -BinderTest.prototype.XtestIfTextBindingThrowsErrorDecorateTheSpan = function(){ +BinderTest.prototype.testIfTextBindingThrowsErrorDecorateTheSpan = function(){ var a = this.compile('
                  {{error.throw()}}
                  '); var doc = a.node.find('div'); @@ -414,7 +389,7 @@ BinderTest.prototype.XtestIfTextBindingThrowsErrorDecorateTheSpan = function(){ assertEquals(null, span.attr('ng-error')); }; -BinderTest.prototype.XtestIfAttrBindingThrowsErrorDecorateTheSpan = function(){ +BinderTest.prototype.testIfAttrBindingThrowsErrorDecorateTheSpan = function(){ var a = this.compile('
                  '); var doc = a.node.find("div"); @@ -432,7 +407,7 @@ BinderTest.prototype.XtestIfAttrBindingThrowsErrorDecorateTheSpan = function(){ }; -BinderTest.prototype.XtestNestedRepeater = function() { +BinderTest.prototype.testNestedRepeater = function() { var a = this.compile('
                  ' + '
                    ' + '
                    '); @@ -454,7 +429,7 @@ BinderTest.prototype.XtestNestedRepeater = function() { '
                    ', sortedHtml(a.node)); }; -BinderTest.prototype.XtestRadioButtonGetsPrefixed = function () { +BinderTest.prototype.testRadioButtonGetsPrefixed = function () { var a = this.compile(''); a.scope.$set('model', ['a1', 'a2']); a.scope.$eval(); @@ -466,7 +441,7 @@ BinderTest.prototype.XtestRadioButtonGetsPrefixed = function () { sortedHtml(a.node)); }; -BinderTest.prototype.XtestHideBindingExpression = function() { +BinderTest.prototype.testHideBindingExpression = function() { var a = this.compile('
                    '); a.scope.$set('hidden', 3); @@ -480,7 +455,7 @@ BinderTest.prototype.XtestHideBindingExpression = function() { assertVisible(a.node.children()); }; -BinderTest.prototype.XtestHideBinding = function() { +BinderTest.prototype.testHideBinding = function() { var c = this.compile('
                    '); c.scope.$set('hidden', 'true'); @@ -499,7 +474,7 @@ BinderTest.prototype.XtestHideBinding = function() { assertVisible(c.node.children()); }; -BinderTest.prototype.XtestShowBinding = function() { +BinderTest.prototype.testShowBinding = function() { var c = this.compile('
                    '); c.scope.$set('show', 'true'); @@ -518,7 +493,7 @@ BinderTest.prototype.XtestShowBinding = function() { assertHidden(c.node.children()); }; -BinderTest.prototype.XtestBindClassUndefined = function() { +BinderTest.prototype.testBindClassUndefined = function() { var doc = this.compile('
                    '); doc.scope.$eval(); @@ -527,7 +502,7 @@ BinderTest.prototype.XtestBindClassUndefined = function() { sortedHtml(doc.node)); }; -BinderTest.prototype.XtestBindClass = function() { +BinderTest.prototype.testBindClass = function() { var c = this.compile('
                    '); c.scope.$set('class', 'testClass'); @@ -543,7 +518,7 @@ BinderTest.prototype.XtestBindClass = function() { '
                    '); }; -BinderTest.prototype.XtestBindClassEvenOdd = function() { +BinderTest.prototype.testBindClassEvenOdd = function() { var x = this.compile('
                    '); x.scope.$eval(); assertEquals( @@ -552,7 +527,7 @@ BinderTest.prototype.XtestBindClassEvenOdd = function() { sortedHtml(x.node)); }; -BinderTest.prototype.XtestBindStyle = function() { +BinderTest.prototype.testBindStyle = function() { var c = this.compile('
                    '); c.scope.eval('style={color:"red"}'); @@ -566,7 +541,7 @@ BinderTest.prototype.XtestBindStyle = function() { assertEquals(sortedHtml(c.node), '
                    '); }; -BinderTest.prototype.XtestActionOnAHrefThrowsError = function(){ +BinderTest.prototype.testActionOnAHrefThrowsError = function(){ var model = {books:[]}; var state = this.compile('Add Phone', model); var input = state.node.find('a'); @@ -579,24 +554,24 @@ BinderTest.prototype.XtestActionOnAHrefThrowsError = function(){ assertFalse('error class should be cleared', input.hasClass('ng-exception')); }; -BinderTest.prototype.XtestShoulIgnoreVbNonBindable = function(){ +BinderTest.prototype.testShoulIgnoreVbNonBindable = function(){ var c = this.compile("{{a}}" + "
                    {{a}}
                    " + "
                    {{b}}
                    " + "
                    {{c}}
                    "); c.scope.$set('a', 123); - c.scope.updateView(); + c.scope.$eval(); assertEquals('123{{a}}{{b}}{{c}}', c.node.text()); }; -BinderTest.prototype.XtestOptionShouldUpdateParentToGetProperBinding = function() { +BinderTest.prototype.testOptionShouldUpdateParentToGetProperBinding = function() { var c = this.compile(''); c.scope.$set('s', 1); c.scope.$eval(); assertEquals(1, c.node.find('select')[0].selectedIndex); }; -BinderTest.prototype.XtestRepeaterShouldBindInputsDefaults = function () { +BinderTest.prototype.testRepeaterShouldBindInputsDefaults = function () { var c = this.compile(''); c.scope.$set('items', [{}, {name:'misko'}]); c.scope.$eval(); @@ -605,14 +580,14 @@ BinderTest.prototype.XtestRepeaterShouldBindInputsDefaults = function () { assertEquals("misko", c.scope.eval('items[1].name')); }; -BinderTest.prototype.XtestRepeaterShouldCreateArray = function () { +BinderTest.prototype.testRepeaterShouldCreateArray = function () { var c = this.compile(''); c.scope.$eval(); assertEquals(0, c.scope.$get('items').length); }; -BinderTest.prototype.XtestShouldTemplateBindPreElements = function () { +BinderTest.prototype.testShouldTemplateBindPreElements = function () { var c = this.compile('
                    Hello {{name}}!
                    '); c.scope.$set("name", "World"); c.scope.$eval(); @@ -620,7 +595,7 @@ BinderTest.prototype.XtestShouldTemplateBindPreElements = function () { assertEquals('
                    Hello World!
                    ', sortedHtml(c.node)); }; -BinderTest.prototype.XtestDissableAutoSubmit = function() { +BinderTest.prototype.testDissableAutoSubmit = function() { var c = this.compile('', null, {autoSubmit:true}); assertEquals( '', @@ -632,7 +607,7 @@ BinderTest.prototype.XtestDissableAutoSubmit = function() { sortedHtml(c.node)); }; -BinderTest.prototype.XtestSettingAnchorToNullOrUndefinedRemovesTheAnchorFromURL = function() { +BinderTest.prototype.testSettingAnchorToNullOrUndefinedRemovesTheAnchorFromURL = function() { var c = this.compile(''); c.binder.location.set("http://server/#a=1&b=2"); c.binder.parseAnchor(); @@ -645,7 +620,7 @@ BinderTest.prototype.XtestSettingAnchorToNullOrUndefinedRemovesTheAnchorFromURL assertEquals('http://server/#', c.binder.location.get()); }; -BinderTest.prototype.XtestFillInOptionValueWhenMissing = function() { +BinderTest.prototype.testFillInOptionValueWhenMissing = function() { var c = this.compile( ''); c.scope.$set('a', 'A'); @@ -662,7 +637,7 @@ BinderTest.prototype.XtestFillInOptionValueWhenMissing = function() { expect(c.node.find("option:last").text()).toEqual('C'); }; -BinderTest.prototype.XtestValidateForm = function() { +BinderTest.prototype.testValidateForm = function() { var c = this.compile('' + '
                    '); var items = [{}, {}]; @@ -691,7 +666,7 @@ BinderTest.prototype.XtestValidateForm = function() { assertEquals(0, c.scope.$get("$invalidWidgets.length")); }; -BinderTest.prototype.XtestValidateOnlyVisibleItems = function(){ +BinderTest.prototype.testValidateOnlyVisibleItems = function(){ var c = this.compile(''); c.scope.$set("show", true); c.scope.$eval(); @@ -702,7 +677,7 @@ BinderTest.prototype.XtestValidateOnlyVisibleItems = function(){ assertEquals(1, c.scope.$get("$invalidWidgets.length")); }; -BinderTest.prototype.XtestDeleteAttributeIfEvaluatesFalse = function() { +BinderTest.prototype.testDeleteAttributeIfEvaluatesFalse = function() { var c = this.compile( '' + '' + @@ -718,14 +693,14 @@ BinderTest.prototype.XtestDeleteAttributeIfEvaluatesFalse = function() { assertEquals(html + 5, 0, c.node.find("input[name='c1']:disabled").size()); }; -BinderTest.prototype.XtestRepeaterErrorShouldBePlacedOnInstanceNotOnTemplateComment = function () { +BinderTest.prototype.testRepeaterErrorShouldBePlacedOnInstanceNotOnTemplateComment = function () { var c = this.compile( ''); c.scope.$eval(); assertTrue(c.node.find("input").hasClass("ng-exception")); }; -BinderTest.prototype.XtestItShouldApplyAttirbutesBeforeTheWidgetsAreMaterialized = function() { +BinderTest.prototype.testItShouldApplyAttirbutesBeforeTheWidgetsAreMaterialized = function() { var c = this.compile( ''); c.scope.$set('person', {a:'misko', b:'adam'}); @@ -733,7 +708,7 @@ BinderTest.prototype.XtestItShouldApplyAttirbutesBeforeTheWidgetsAreMaterialized assertEquals("", c.node.html()); }; -BinderTest.prototype.XtestItShouldCallListenersWhenAnchorChanges = function() { +BinderTest.prototype.testItShouldCallListenersWhenAnchorChanges = function() { var log = ""; var c = this.compile('
                    '); c.scope.$set("count", 0); @@ -763,7 +738,7 @@ BinderTest.prototype.XtestItShouldCallListenersWhenAnchorChanges = function() { assertEquals(3, c.scope.$get("count")); }; -BinderTest.prototype.XtestParseQueryString = function(){ +BinderTest.prototype.testParseQueryString = function(){ var binder = new Binder(); assertJsonEquals({"a":"1"}, binder.parseQueryString("a=1")); assertJsonEquals({"a":"1", "b":"two"}, binder.parseQueryString("a=1&b=two")); @@ -776,7 +751,7 @@ BinderTest.prototype.XtestParseQueryString = function(){ }; -BinderTest.prototype.XtestSetBinderAnchorTriggersListeners = function(){ +BinderTest.prototype.testSetBinderAnchorTriggersListeners = function(){ expectAsserts(2); var doc = this.compile("
                    "); @@ -789,7 +764,7 @@ BinderTest.prototype.XtestSetBinderAnchorTriggersListeners = function(){ doc.binder.onUrlChange("http://base#name=new"); }; -BinderTest.prototype.XtestItShouldDisplayErrorWhenActionIsSyntacticlyIncorect = function(){ +BinderTest.prototype.testItShouldDisplayErrorWhenActionIsSyntacticlyIncorect = function(){ var c = this.compile( '' + ''); @@ -798,7 +773,7 @@ BinderTest.prototype.XtestItShouldDisplayErrorWhenActionIsSyntacticlyIncorect = assertTrue(c.node.find(":input:last").hasClass("ng-exception")); }; -BinderTest.prototype.XtestItShouldSelectTheCorrectRadioBox = function() { +BinderTest.prototype.testItShouldSelectTheCorrectRadioBox = function() { var c = this.compile( '' + ''); @@ -814,7 +789,7 @@ BinderTest.prototype.XtestItShouldSelectTheCorrectRadioBox = function() { assertEquals("male", c.node.find("input:checked").attr("value")); }; -BinderTest.prototype.XtestItShouldListenOnRightScope = function() { +BinderTest.prototype.testItShouldListenOnRightScope = function() { var c = this.compile( '
                    ' + '
                    '); @@ -829,7 +804,7 @@ BinderTest.prototype.XtestItShouldListenOnRightScope = function() { assertEquals(7, c.scope.$get("gCounter")); }; -BinderTest.prototype.XtestItShouldRepeatOnHashes = function() { +BinderTest.prototype.testItShouldRepeatOnHashes = function() { var x = this.compile('
                    '); x.scope.$eval(); assertEquals( @@ -838,31 +813,31 @@ BinderTest.prototype.XtestItShouldRepeatOnHashes = function() { sortedHtml(x.node)); }; -BinderTest.prototype.XtestItShouldFireChangeListenersBeforeUpdate = function(){ +BinderTest.prototype.testItShouldFireChangeListenersBeforeUpdate = function(){ var x = this.compile('
                    '); x.scope.$set("name", ""); + x.scope.$watch("watched", "name=123"); x.scope.$set("watched", "change"); - x.scope.watch("watched:name=123"); - x.scope.updateView(); + x.scope.$eval(); assertEquals(123, x.scope.$get("name")); assertEquals( '
                    123
                    ', sortedHtml(x.node)); }; -BinderTest.prototype.XtestItShouldHandleMultilineBindings = function(){ +BinderTest.prototype.testItShouldHandleMultilineBindings = function(){ var x = this.compile('
                    {{\n 1 \n + \n 2 \n}}
                    '); - x.scope.updateView(); + x.scope.$eval(); assertEquals("3", x.node.text()); }; -BinderTest.prototype.XtestItBindHiddenInputFields = function(){ +BinderTest.prototype.testItBindHiddenInputFields = function(){ var x = this.compile(''); - x.scope.updateView(); + x.scope.$eval(); assertEquals("abc", x.scope.$get("myName")); }; -BinderTest.prototype.XtestItShouldRenderMultiRootHtmlInBinding = function() { +BinderTest.prototype.xtestItShouldRenderMultiRootHtmlInBinding = function() { var x = this.compile('
                    before {{a|html}}after
                    '); x.scope.$set("a", "acd"); x.scope.$eval(); @@ -871,13 +846,13 @@ BinderTest.prototype.XtestItShouldRenderMultiRootHtmlInBinding = function() { sortedHtml(x.node)); }; -BinderTest.prototype.XtestItShouldUseFormaterForText = function() { +BinderTest.prototype.testItShouldUseFormaterForText = function() { var x = this.compile(''); x.scope.$eval(); assertEquals(['a','b'], x.scope.$get('a')); - var input = x.node.find('input'); + var input = x.node; input[0].value = ' x,,yz'; - input.change(); + input.trigger('change'); assertEquals(['x','yz'], x.scope.$get('a')); x.scope.$set('a', [1 ,2, 3]); x.scope.$eval(); diff --git a/test/ScopeSpec.js b/test/ScopeSpec.js index cfae42a8..1e50b275 100644 --- a/test/ScopeSpec.js +++ b/test/ScopeSpec.js @@ -29,7 +29,7 @@ describe('scope/model', function(){ expect(model.name).toEqual('works'); }); - //$onEval + //$watch it('should watch an expression for change', function(){ var model = createScope(); model.oldValue = ""; @@ -42,7 +42,7 @@ describe('scope/model', function(){ }); model.name = 'misko'; model.$eval(); - expect(count).toEqual(1); + expect(count).toEqual(2); // since watches trigger $eval expect(model.newValue).toEqual('misko'); expect(model.oldValue).toEqual('adam'); }); -- cgit v1.2.3 From a7d62dcb5533ceb9a7ae47ee27e2054400a0196b Mon Sep 17 00:00:00 2001 From: Misko Hevery Date: Tue, 30 Mar 2010 14:55:04 -0700 Subject: more tests fixed --- test/BinderTest.js | 134 +++++++++++++++++++++++++++-------------------- test/ScenarioSpec.js | 4 +- test/ScopeSpec.js | 8 +-- test/directivesSpec.js | 5 ++ test/testabilityPatch.js | 4 ++ test/widgetsSpec.js | 8 ++- 6 files changed, 96 insertions(+), 67 deletions(-) (limited to 'test') diff --git a/test/BinderTest.js b/test/BinderTest.js index c21420af..e6c8147a 100644 --- a/test/BinderTest.js +++ b/test/BinderTest.js @@ -16,7 +16,7 @@ BinderTest.prototype.setUp = function(){ }; BinderTest.prototype.tearDown = function(){ - if (this.element) this.element.remove(); + if (this.element && this.element.dealoc) this.element.dealoc(); }; BinderTest.prototype.testChangingTextfieldUpdatesModel = function(){ @@ -543,22 +543,26 @@ BinderTest.prototype.testBindStyle = function() { BinderTest.prototype.testActionOnAHrefThrowsError = function(){ var model = {books:[]}; - var state = this.compile('Add Phone', model); - var input = state.node.find('a'); + var c = this.compile('Add Phone', model); + c.scope.action = function(){ + throw {a:'abc', b:2}; + }; + var input = c.node; input.click(); - assertEquals('abc', fromJson(input.attr('ng-error')).a); + assertEquals({a:"abc", b:2}, fromJson(input.attr('ng-error'))); assertTrue("should have an error class", input.hasClass('ng-exception')); - input.attr('ng-action', '0'); + c.scope.action = noop; input.click(); + dump(input.attr('ng-error')); assertFalse('error class should be cleared', input.hasClass('ng-exception')); }; BinderTest.prototype.testShoulIgnoreVbNonBindable = function(){ - var c = this.compile("{{a}}" + + var c = this.compile("
                    {{a}}" + "
                    {{a}}
                    " + "
                    {{b}}
                    " + - "
                    {{c}}
                    "); + "
                    {{c}}
                    "); c.scope.$set('a', 123); c.scope.$eval(); assertEquals('123{{a}}{{b}}{{c}}', c.node.text()); @@ -568,16 +572,16 @@ BinderTest.prototype.testOptionShouldUpdateParentToGetProperBinding = function() var c = this.compile(''); c.scope.$set('s', 1); c.scope.$eval(); - assertEquals(1, c.node.find('select')[0].selectedIndex); + assertEquals(1, c.node[0].selectedIndex); }; BinderTest.prototype.testRepeaterShouldBindInputsDefaults = function () { - var c = this.compile(''); + var c = this.compile('
                    '); c.scope.$set('items', [{}, {name:'misko'}]); c.scope.$eval(); - assertEquals("123", c.scope.eval('items[0].name')); - assertEquals("misko", c.scope.eval('items[1].name')); + assertEquals("123", c.scope.$eval('items[0].name')); + assertEquals("misko", c.scope.$eval('items[1].name')); }; BinderTest.prototype.testRepeaterShouldCreateArray = function () { @@ -595,7 +599,7 @@ BinderTest.prototype.testShouldTemplateBindPreElements = function () { assertEquals('
                    Hello World!
                    ', sortedHtml(c.node)); }; -BinderTest.prototype.testDissableAutoSubmit = function() { +BinderTest.prototype.XtestDissableAutoSubmit = function() { var c = this.compile('', null, {autoSubmit:true}); assertEquals( '', @@ -607,7 +611,7 @@ BinderTest.prototype.testDissableAutoSubmit = function() { sortedHtml(c.node)); }; -BinderTest.prototype.testSettingAnchorToNullOrUndefinedRemovesTheAnchorFromURL = function() { +BinderTest.prototype.XtestSettingAnchorToNullOrUndefinedRemovesTheAnchorFromURL = function() { var c = this.compile(''); c.binder.location.set("http://server/#a=1&b=2"); c.binder.parseAnchor(); @@ -626,18 +630,21 @@ BinderTest.prototype.testFillInOptionValueWhenMissing = function() { c.scope.$set('a', 'A'); c.scope.$set('b', 'B'); c.scope.$eval(); + var optionA = childNode(c.node, 0); + var optionB = childNode(c.node, 1); + var optionC = childNode(c.node, 2); - expect(c.node.find("option:first").attr('value')).toEqual('A'); - expect(c.node.find("option:first").text()).toEqual('A'); + expect(optionA.attr('value')).toEqual('A'); + expect(optionA.text()).toEqual('A'); - expect(c.node.find("option:nth-child(2)").attr('value')).toEqual(''); - expect(c.node.find("option:nth-child(2)").text()).toEqual('B'); + expect(optionB.attr('value')).toEqual(''); + expect(optionB.text()).toEqual('B'); - expect(c.node.find("option:last").attr('value')).toEqual('C'); - expect(c.node.find("option:last").text()).toEqual('C'); + expect(optionC.attr('value')).toEqual('C'); + expect(optionC.text()).toEqual('C'); }; -BinderTest.prototype.testValidateForm = function() { +BinderTest.prototype.XtestValidateForm = function() { var c = this.compile('' + '
                    '); var items = [{}, {}]; @@ -666,7 +673,7 @@ BinderTest.prototype.testValidateForm = function() { assertEquals(0, c.scope.$get("$invalidWidgets.length")); }; -BinderTest.prototype.testValidateOnlyVisibleItems = function(){ +BinderTest.prototype.XtestValidateOnlyVisibleItems = function(){ var c = this.compile(''); c.scope.$set("show", true); c.scope.$eval(); @@ -678,29 +685,32 @@ BinderTest.prototype.testValidateOnlyVisibleItems = function(){ }; BinderTest.prototype.testDeleteAttributeIfEvaluatesFalse = function() { - var c = this.compile( + var c = this.compile('
                    ' + '' + '' + - ''); + '
                    '); c.scope.$eval(); - var html = c.node.html(); - assertEquals(html + 0, 1, c.node.find("input[name='a0']:disabled").size()); - assertEquals(html + 1, 1, c.node.find("input[name='b0']:disabled").size()); - assertEquals(html + 2, 1, c.node.find("input[name='c0']:disabled").size()); + function assertChild(index, disabled) { + var child = childNode(c.node, index); + assertEquals(sortedHtml(child), disabled, !!child.attr('disabled')); + } - assertEquals(html + 3, 0, c.node.find("input[name='a1']:disabled").size()); - assertEquals(html + 4, 0, c.node.find("input[name='b1']:disabled").size()); - assertEquals(html + 5, 0, c.node.find("input[name='c1']:disabled").size()); + assertChild(0, true); + assertChild(1, false); + assertChild(2, true); + assertChild(3, false); + assertChild(4, true); + assertChild(5, false); }; BinderTest.prototype.testRepeaterErrorShouldBePlacedOnInstanceNotOnTemplateComment = function () { var c = this.compile( ''); c.scope.$eval(); - assertTrue(c.node.find("input").hasClass("ng-exception")); + assertTrue(c.node.hasClass("ng-exception")); }; -BinderTest.prototype.testItShouldApplyAttirbutesBeforeTheWidgetsAreMaterialized = function() { +BinderTest.prototype.testItShouldApplyAttributesBeforeTheWidgetsAreMaterialized = function() { var c = this.compile( ''); c.scope.$set('person', {a:'misko', b:'adam'}); @@ -708,11 +718,11 @@ BinderTest.prototype.testItShouldApplyAttirbutesBeforeTheWidgetsAreMaterialized assertEquals("", c.node.html()); }; -BinderTest.prototype.testItShouldCallListenersWhenAnchorChanges = function() { +BinderTest.prototype.XtestItShouldCallListenersWhenAnchorChanges = function() { var log = ""; var c = this.compile('
                    '); c.scope.$set("count", 0); - c.scope.addWatchListener("$anchor.counter", function(newValue, oldValue){ + c.scope.$watch("$anchor.counter", function(newValue, oldValue){ log += oldValue + "->" + newValue + ";"; }); assertEquals(0, c.scope.$get("count")); @@ -738,7 +748,7 @@ BinderTest.prototype.testItShouldCallListenersWhenAnchorChanges = function() { assertEquals(3, c.scope.$get("count")); }; -BinderTest.prototype.testParseQueryString = function(){ +BinderTest.prototype.XtestParseQueryString = function(){ var binder = new Binder(); assertJsonEquals({"a":"1"}, binder.parseQueryString("a=1")); assertJsonEquals({"a":"1", "b":"two"}, binder.parseQueryString("a=1&b=two")); @@ -751,49 +761,57 @@ BinderTest.prototype.testParseQueryString = function(){ }; -BinderTest.prototype.testSetBinderAnchorTriggersListeners = function(){ +BinderTest.prototype.XtestSetBinderAnchorTriggersListeners = function(){ expectAsserts(2); var doc = this.compile("
                    "); - doc.scope.addWatchListener("$anchor.name", function(newVal, oldVal) { + doc.scope.$watch("$anchor.name", function(newVal, oldVal) { assertEquals("new", newVal); assertEquals(undefined, oldVal); }); - doc.binder.anchor.name = "new"; + doc.$anchor.name = "new"; doc.binder.onUrlChange("http://base#name=new"); }; BinderTest.prototype.testItShouldDisplayErrorWhenActionIsSyntacticlyIncorect = function(){ - var c = this.compile( + var c = this.compile('
                    ' + '' + - ''); - c.node.find("input").click(); + '
                    '); + var first = jqLite(c.node[0].childNodes[0]); + var second = jqLite(c.node[0].childNodes[1]); + + first.click(); assertEquals("ABC", c.scope.$get('greeting')); - assertTrue(c.node.find(":input:last").hasClass("ng-exception")); + + second.click(); + assertTrue(second.hasClass("ng-exception")); }; BinderTest.prototype.testItShouldSelectTheCorrectRadioBox = function() { - var c = this.compile( + var c = this.compile('
                    ' + '' + - ''); + '
                    '); + var female = jqLite(c.node[0].childNodes[0]); + var male = jqLite(c.node[0].childNodes[1]); - c.node.find("input[value=female]").click(); + female.click(); assertEquals("female", c.scope.$get("sex")); - assertEquals(1, c.node.find("input:checked").size()); - assertEquals("female", c.node.find("input:checked").attr("value")); + assertEquals(true, female[0].checked); + assertEquals(false, male[0].checked); + assertEquals("female", female.val()); - c.node.find("input[value=male]").click(); + male.click(); assertEquals("male", c.scope.$get("sex")); - assertEquals(1, c.node.find("input:checked").size()); - assertEquals("male", c.node.find("input:checked").attr("value")); + assertEquals(false, female[0].checked); + assertEquals(true, male[0].checked); + assertEquals("male", male.val()); }; BinderTest.prototype.testItShouldListenOnRightScope = function() { var c = this.compile( - '
                    ' + - '
                    '); - c.binder.executeInit(); + '
                      ' + + '
                    '); c.scope.$eval(); assertEquals(0, c.scope.$get("counter")); assertEquals(0, c.scope.$get("gCounter")); @@ -805,11 +823,13 @@ BinderTest.prototype.testItShouldListenOnRightScope = function() { }; BinderTest.prototype.testItShouldRepeatOnHashes = function() { - var x = this.compile('
                    '); + var x = this.compile('
                    '); x.scope.$eval(); - assertEquals( - '
                    a0
                    ' + - '
                    b1
                    ', + assertEquals('
                      ' + + '<#comment>' + + '
                    • a0
                    • ' + + '
                    • b1
                    • ' + + '
                    ', sortedHtml(x.node)); }; diff --git a/test/ScenarioSpec.js b/test/ScenarioSpec.js index 9603a28e..5b88a175 100644 --- a/test/ScenarioSpec.js +++ b/test/ScenarioSpec.js @@ -3,8 +3,8 @@ describe("ScenarioSpec: Compilation", function(){ var node = jqLite('
                    {{b=a+1}}
                    ')[0]; var scope = angular.compile(node); scope.$init(); - expect(scope.$get('a')).toEqual(1); - expect(scope.$get('b')).toEqual(2); + expect(scope.a).toEqual(1); + expect(scope.b).toEqual(2); }); it("should compile jQuery node and return scope", function(){ diff --git a/test/ScopeSpec.js b/test/ScopeSpec.js index 1e50b275..7e1a899f 100644 --- a/test/ScopeSpec.js +++ b/test/ScopeSpec.js @@ -33,16 +33,18 @@ describe('scope/model', function(){ it('should watch an expression for change', function(){ var model = createScope(); model.oldValue = ""; - var count = 0; + var nameCount = 0, evalCount = 0; model.name = 'adam'; - model.$watch('name', function(){ count ++; }); + model.$watch('name', function(){ nameCount ++; }); model.$watch(function(){return model.name;}, function(newValue, oldValue){ this.newValue = newValue; this.oldValue = oldValue; }); + model.$onEval(function(){evalCount ++;}); model.name = 'misko'; model.$eval(); - expect(count).toEqual(2); // since watches trigger $eval + expect(nameCount).toEqual(1); + expect(evalCount).toEqual(1); expect(model.newValue).toEqual('misko'); expect(model.oldValue).toEqual('adam'); }); diff --git a/test/directivesSpec.js b/test/directivesSpec.js index 343698af..4eef1ac3 100644 --- a/test/directivesSpec.js +++ b/test/directivesSpec.js @@ -80,6 +80,11 @@ describe("directives", function(){ expect(element.text()).toEqual('misko:swe;shyam:set;'); }); + it('should set ng-repeat to [] if undefinde', function(){ + var scope = compile('
                    '); + expect(scope.items).toEqual([]); + }); + it('should error on wrong parsing of ng-repeat', function(){ var scope = compile('
                    '); var log = ""; diff --git a/test/testabilityPatch.js b/test/testabilityPatch.js index 7c16828d..312b1e42 100644 --- a/test/testabilityPatch.js +++ b/test/testabilityPatch.js @@ -37,6 +37,10 @@ MockLocation.prototype.set = function(url){ this.url = url; }; +function childNode(element, index) { + return jqLite(element[0].childNodes[index]); +} + function sortedHtml(element) { var html = ""; (function toString(node) { diff --git a/test/widgetsSpec.js b/test/widgetsSpec.js index 152b01f3..d041220b 100644 --- a/test/widgetsSpec.js +++ b/test/widgetsSpec.js @@ -14,10 +14,8 @@ describe("input widget", function(){ }); afterEach(function(){ - if (element) element.remove(); - var oldCache = jqCache; - jqCache = {}; - expect(size(oldCache)).toEqual(0); + if (element && element.dealoc) element.dealoc(); + expect(size(jqCache)).toEqual(0); }); it('should input-text auto init and handle keyup/change events', function(){ @@ -179,7 +177,7 @@ describe("input widget", function(){ }); it('should report error on assignment error', function(){ - compile(''); + compile(''); expect(element.hasClass('ng-exception')).toBeTruthy(); }); -- cgit v1.2.3 From b5b8f63e1ebc75d09c6faf8dbad6497880deed47 Mon Sep 17 00:00:00 2001 From: Misko Hevery Date: Tue, 30 Mar 2010 15:39:51 -0700 Subject: more tests passing --- test/BinderTest.js | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) (limited to 'test') diff --git a/test/BinderTest.js b/test/BinderTest.js index e6c8147a..e99f37e2 100644 --- a/test/BinderTest.js +++ b/test/BinderTest.js @@ -552,10 +552,11 @@ BinderTest.prototype.testActionOnAHrefThrowsError = function(){ assertEquals({a:"abc", b:2}, fromJson(input.attr('ng-error'))); assertTrue("should have an error class", input.hasClass('ng-exception')); - c.scope.action = noop; - input.click(); - dump(input.attr('ng-error')); - assertFalse('error class should be cleared', input.hasClass('ng-exception')); + // TODO: I think that exception should never get cleared so this portion of test makes no sense +// c.scope.action = noop; +// input.click(); +// dump(input.attr('ng-error')); +// assertFalse('error class should be cleared', input.hasClass('ng-exception')); }; BinderTest.prototype.testShoulIgnoreVbNonBindable = function(){ -- cgit v1.2.3 From 35a91085004e31f786df1e0011bc26ed0142ab4d Mon Sep 17 00:00:00 2001 From: Misko Hevery Date: Wed, 31 Mar 2010 13:57:25 -0700 Subject: all tests green, some dissabled --- test/BinderTest.js | 182 +++++++++++++------------------------- test/directivesSpec.js | 8 +- test/markupSpec.js | 8 +- test/moveToAngularCom/MiscTest.js | 35 ++++++++ test/testabilityPatch.js | 6 +- test/widgetsSpec.js | 18 ++-- 6 files changed, 117 insertions(+), 140 deletions(-) create mode 100644 test/moveToAngularCom/MiscTest.js (limited to 'test') diff --git a/test/BinderTest.js b/test/BinderTest.js index e99f37e2..4d996a8e 100644 --- a/test/BinderTest.js +++ b/test/BinderTest.js @@ -39,7 +39,7 @@ BinderTest.prototype.testChangingRadioUpdatesModel = function(){ }; BinderTest.prototype.testChangingCheckboxUpdatesModel = function(){ - var form = this.compile(''); + var form = this.compile(''); assertEquals(true, form.scope.model.price); }; @@ -91,7 +91,7 @@ BinderTest.prototype.testReplaceBindingInTextWithSpan = function() { }; BinderTest.prototype.testBindingSpaceConfusesIE = function() { - //if (!msie) return; + if (!msie) return; var span = document.createElement("span"); span.innerHTML = ' '; var nbsp = span.firstChild.nodeValue; @@ -144,7 +144,7 @@ BinderTest.prototype.testAttributesAreEvaluated = function(){ BinderTest.prototype.testInputTypeButtonActionExecutesInScope = function(){ var savedCalled = false; - var c = this.compile(''); + var c = this.compile(''); c.scope.$set("person.save", function(){ savedCalled = true; }); @@ -153,17 +153,19 @@ BinderTest.prototype.testInputTypeButtonActionExecutesInScope = function(){ }; BinderTest.prototype.testInputTypeButtonActionExecutesInScope2 = function(){ - expectAsserts(1); - var c = this.compile(''); + var log = ""; + var c = this.compile(''); c.scope.$set("action", function(){ - assertTrue(true); + log += 'click;'; }); + expect(log).toEqual(''); c.node.click(); + expect(log).toEqual('click;'); }; BinderTest.prototype.testButtonElementActionExecutesInScope = function(){ var savedCalled = false; - var c = this.compile(''); + var c = this.compile(''); c.scope.$set("person.save", function(){ savedCalled = true; }); @@ -171,7 +173,7 @@ BinderTest.prototype.testButtonElementActionExecutesInScope = function(){ assertTrue(savedCalled); }; -BinderTest.prototype.testParseEmptyAnchor = function(){ +BinderTest.prototype.XtestParseEmptyAnchor = function(){ var binder = this.compile("
                    ").binder; var location = binder.location; var anchor = binder.anchor; @@ -185,7 +187,7 @@ BinderTest.prototype.testParseEmptyAnchor = function(){ assertEquals('undefined', typeof (anchor[""])); }; -BinderTest.prototype.testParseAnchor = function(){ +BinderTest.prototype.XtestParseAnchor = function(){ var binder = this.compile("
                    ").binder; var location = binder.location; location.url = "a#x=1"; @@ -199,7 +201,7 @@ BinderTest.prototype.testParseAnchor = function(){ assertTrue(!binder.anchor.x); }; -BinderTest.prototype.testWriteAnchor = function(){ +BinderTest.prototype.XtestWriteAnchor = function(){ var binder = this.compile("
                    ").binder; binder.location.set('a'); binder.anchor.a = 'b'; @@ -209,7 +211,7 @@ BinderTest.prototype.testWriteAnchor = function(){ assertEquals(binder.location.get(), "a#a=b&c=%20&d"); }; -BinderTest.prototype.testWriteAnchorAsPartOfTheUpdateView = function(){ +BinderTest.prototype.XtestWriteAnchorAsPartOfTheUpdateView = function(){ var binder = this.compile("
                    ").binder; binder.location.set('a'); binder.anchor.a = 'b'; @@ -221,8 +223,6 @@ BinderTest.prototype.testRepeaterUpdateBindings = function(){ var a = this.compile('
                    '); var form = a.node; var items = [{a:"A"}, {a:"B"}]; - var initialDataCount = _(jQuery.cache).size(); - assertTrue("" + initialDataCount, initialDataCount > 0); a.scope.$set('model', {items:items}); a.scope.$eval(); @@ -252,8 +252,6 @@ BinderTest.prototype.testRepeaterUpdateBindings = function(){ items.shift(); items.shift(); a.scope.$eval(); - var currentDataCount = _(jQuery.cache).size(); - assertEquals("I have leaked " + (currentDataCount - initialDataCount), initialDataCount, currentDataCount); }; BinderTest.prototype.testRepeaterContentDoesNotBind = function(){ @@ -266,118 +264,63 @@ BinderTest.prototype.testRepeaterContentDoesNotBind = function(){ '
                  ', sortedHtml(a.node)); }; -BinderTest.prototype.testShouldBindActionsOnRepeaterClone = function(){ - var c = this.compile('link'); - jQuery(c).die(); - c.scope.$set('result.value', false); - c.scope.$set('items', ['abc', 'xyz']); - c.scope.$eval(); - assertEquals(2, c.node.find("a").size()); - c.node.find("a:last").click(); - assertEquals('xyz', c.scope.$get('result.value')); -}; - - - -BinderTest.prototype.testRepeaterInputContentDoesNotBind = function(){ - var c = compil('
                  • ' + - '
                  '); - c.scope.items = [{a:"A"}]; - assertEquals(c.node.find(":input").attr("value"), "OLD"); -}; - BinderTest.prototype.testExpandEntityTag = function(){ assertEquals( '
                  ', this.compileToHtml('
                  ')); }; -BinderTest.prototype.testExpandEntityTagWithDefaults = function(){ - assertEquals( - '
                  ', - this.compileToHtml('
                  ')); -}; - -BinderTest.prototype.testExpandEntityTagWithName = function(){ - var c = this.compile('
                  '); - assertEquals( - '
                  ', - sortedHtml(c.node)); - assertEquals("Person", c.scope.$get("friend.$entity")); - assertEquals("friend", c.scope.$get("friend.$$anchor")); -}; - -BinderTest.prototype.testExpandSubmitButtonToAction = function(){ - var html = this.compileToHtml(''); - assertTrue(html, html.indexOf('ng-action="$save()"') > 0 ); - assertTrue(html, html.indexOf('ng-bind-attr="{"disabled":"{{$invalidWidgets}}"}"') > 0 ); -}; - BinderTest.prototype.testDoNotOverwriteCustomAction = function(){ var html = this.compileToHtml(''); assertTrue(html.indexOf('action="foo();"') > 0 ); }; -BinderTest.prototype.testReplaceFileUploadWithSwf = function(){ - expectAsserts(1); - var form = jQuery("body").append('
                  '); - form.data('scope', new Scope()); - var factory = {}; - var binder = new Binder(form.get(0), factory, new MockLocation()); - factory.createController = function(node){ - assertEquals(node.attr('type'), 'file'); - return {updateModel:function(){}}; - }; - binder.compile(); - jQuery("#testTag").remove(); -}; - BinderTest.prototype.testRepeaterAdd = function(){ var c = this.compile('
                  '); var doc = c.node; c.scope.$set('items', [{x:'a'}, {x:'b'}]); - c.binder.compile(); c.scope.$eval(); - assertEquals('a', doc.find(':input')[0].value); - assertEquals('b', doc.find(':input')[1].value); + var first = childNode(c.node, 1); + var second = childNode(c.node, 2); + assertEquals('a', first.val()); + assertEquals('b', second.val()); - var first = doc.find('[ng-repeat-index="0"]'); - first[0].value = 'ABC'; + first.val('ABC'); first.trigger('keyup'); - assertEquals(doc.scope().get('items')[0].x, 'ABC'); + assertEquals(c.scope.items[0].x, 'ABC'); }; BinderTest.prototype.testItShouldRemoveExtraChildrenWhenIteratingOverHash = function(){ - var c = this.compile('
                  {{i}}
                  '); + var c = this.compile('
                  {{i}}
                  '); var items = {}; c.scope.$set("items", items); c.scope.$eval(); - expect(c.node.find("div").size()).toEqual(0); + expect(c.node[0].childNodes.length - 1).toEqual(0); items.name = "misko"; c.scope.$eval(); - expect(c.node.find("div").size()).toEqual(1); + expect(c.node[0].childNodes.length - 1).toEqual(1); delete items.name; c.scope.$eval(); - expect(c.node.find("div").size()).toEqual(0); + expect(c.node[0].childNodes.length - 1).toEqual(0); }; BinderTest.prototype.testIfTextBindingThrowsErrorDecorateTheSpan = function(){ var a = this.compile('
                  {{error.throw()}}
                  '); - var doc = a.node.find('div'); + var doc = a.node; a.scope.$set('error.throw', function(){throw "ErrorMsg1";}); a.scope.$eval(); - var span = doc.find('span'); + var span = childNode(doc, 0); assertTrue(span.hasClass('ng-exception')); assertEquals('ErrorMsg1', fromJson(span.text())); assertEquals('"ErrorMsg1"', span.attr('ng-error')); a.scope.$set('error.throw', function(){throw "MyError";}); a.scope.$eval(); - span = doc.find('span'); + span = childNode(doc, 0); assertTrue(span.hasClass('ng-exception')); assertTrue(span.text(), span.text().match('MyError') !== null); assertEquals('"MyError"', span.attr('ng-error')); @@ -389,15 +332,15 @@ BinderTest.prototype.testIfTextBindingThrowsErrorDecorateTheSpan = function(){ assertEquals(null, span.attr('ng-error')); }; -BinderTest.prototype.testIfAttrBindingThrowsErrorDecorateTheSpan = function(){ +BinderTest.prototype.testIfAttrBindingThrowsErrorDecorateTheAttribute = function(){ var a = this.compile('
                  '); - var doc = a.node.find("div"); + var doc = a.node; a.scope.$set('error.throw', function(){throw "ErrorMsg";}); a.scope.$eval(); assertTrue('ng-exception', doc.hasClass('ng-exception')); - assertEquals('before ["ErrorMsg"] after', doc.attr('attr')); assertEquals('"ErrorMsg"', doc.attr('ng-error')); + assertEquals('before "ErrorMsg" after', doc.attr('attr')); a.scope.$set('error.throw', function(){ return 'X';}); a.scope.$eval(); @@ -408,15 +351,15 @@ BinderTest.prototype.testIfAttrBindingThrowsErrorDecorateTheSpan = function(){ }; BinderTest.prototype.testNestedRepeater = function() { - var a = this.compile('
                  ' + + var a = this.compile('
                  ' + '
                    ' + - '
                    '); + '
                    '); a.scope.$set('model', [{name:'a', item:['a1', 'a2']}, {name:'b', item:['b1', 'b2']}]); a.scope.$eval(); - assertEquals( - //'<#comment>'+ + assertEquals('
                    '+ + '<#comment>'+ '
                    '+ '<#comment>'+ '
                      '+ @@ -426,18 +369,18 @@ BinderTest.prototype.testNestedRepeater = function() { '<#comment>'+ '
                        '+ '
                          '+ - '
                          ', sortedHtml(a.node)); + '
                          ', sortedHtml(a.node)); }; -BinderTest.prototype.testRadioButtonGetsPrefixed = function () { - var a = this.compile(''); +BinderTest.prototype.XtestRadioButtonGetsPrefixed = function () { + var a = this.compile('
                          '); a.scope.$set('model', ['a1', 'a2']); a.scope.$eval(); - assertEquals( - //'<#comment>'+ + assertEquals('
                          ' + + '<#comment>'+ ''+ - '', + '
                          ', sortedHtml(a.node)); }; @@ -447,12 +390,12 @@ BinderTest.prototype.testHideBindingExpression = function() { a.scope.$set('hidden', 3); a.scope.$eval(); - assertHidden(a.node.children()); + assertHidden(a.node); a.scope.$set('hidden', 2); a.scope.$eval(); - assertVisible(a.node.children()); + assertVisible(a.node); }; BinderTest.prototype.testHideBinding = function() { @@ -461,17 +404,17 @@ BinderTest.prototype.testHideBinding = function() { c.scope.$set('hidden', 'true'); c.scope.$eval(); - assertHidden(c.node.children()); + assertHidden(c.node); c.scope.$set('hidden', 'false'); c.scope.$eval(); - assertVisible(c.node.children()); + assertVisible(c.node); c.scope.$set('hidden', ''); c.scope.$eval(); - assertVisible(c.node.children()); + assertVisible(c.node); }; BinderTest.prototype.testShowBinding = function() { @@ -480,17 +423,17 @@ BinderTest.prototype.testShowBinding = function() { c.scope.$set('show', 'true'); c.scope.$eval(); - assertVisible(c.node.children()); + assertVisible(c.node); c.scope.$set('show', 'false'); c.scope.$eval(); - assertHidden(c.node.children()); + assertHidden(c.node); c.scope.$set('show', ''); c.scope.$eval(); - assertHidden(c.node.children()); + assertHidden(c.node); }; BinderTest.prototype.testBindClassUndefined = function() { @@ -498,7 +441,7 @@ BinderTest.prototype.testBindClassUndefined = function() { doc.scope.$eval(); assertEquals( - '
                          ', + '
                          ', sortedHtml(doc.node)); }; @@ -515,35 +458,34 @@ BinderTest.prototype.testBindClass = function() { c.scope.$eval(); assertEquals(sortedHtml(c.node), - '
                          '); + '
                          '); }; BinderTest.prototype.testBindClassEvenOdd = function() { - var x = this.compile('
                          '); + var x = this.compile('
                          '); x.scope.$eval(); assertEquals( + '
                          <#comment>' + '
                          ' + - '
                          ', + '
                          ', sortedHtml(x.node)); }; BinderTest.prototype.testBindStyle = function() { var c = this.compile('
                          '); - c.scope.eval('style={color:"red"}'); + c.scope.$eval('style={color:"red"}'); c.scope.$eval(); - assertEquals("red", c.node.find('div').css('color')); + assertEquals("red", c.node.css('color')); - c.scope.eval('style={}'); + c.scope.$eval('style={}'); c.scope.$eval(); - - assertEquals(sortedHtml(c.node), '
                          '); }; BinderTest.prototype.testActionOnAHrefThrowsError = function(){ var model = {books:[]}; - var c = this.compile('Add Phone', model); + var c = this.compile('Add Phone', model); c.scope.action = function(){ throw {a:'abc', b:2}; }; @@ -553,10 +495,10 @@ BinderTest.prototype.testActionOnAHrefThrowsError = function(){ assertTrue("should have an error class", input.hasClass('ng-exception')); // TODO: I think that exception should never get cleared so this portion of test makes no sense -// c.scope.action = noop; -// input.click(); -// dump(input.attr('ng-error')); -// assertFalse('error class should be cleared', input.hasClass('ng-exception')); + //c.scope.action = noop; + //input.click(); + //dump(input.attr('ng-error')); + //assertFalse('error class should be cleared', input.hasClass('ng-exception')); }; BinderTest.prototype.testShoulIgnoreVbNonBindable = function(){ @@ -777,8 +719,8 @@ BinderTest.prototype.XtestSetBinderAnchorTriggersListeners = function(){ BinderTest.prototype.testItShouldDisplayErrorWhenActionIsSyntacticlyIncorect = function(){ var c = this.compile('
                          ' + - '' + - '
                          '); + '' + + '
                          '); var first = jqLite(c.node[0].childNodes[0]); var second = jqLite(c.node[0].childNodes[1]); diff --git a/test/directivesSpec.js b/test/directivesSpec.js index 4eef1ac3..cfee86a0 100644 --- a/test/directivesSpec.js +++ b/test/directivesSpec.js @@ -105,8 +105,8 @@ describe("directives", function(){ expect(scope.$get('count')).toEqual(1); }); - it('should ng-action', function(){ - var scope = compile('
                          '); + it('should ng-click', function(){ + var scope = compile('
                          '); scope.$eval(); expect(scope.$get('clicked')).toBeFalsy(); @@ -128,9 +128,9 @@ describe("directives", function(){ var e1 = jqLite(element[0].childNodes[1]); var e2 = jqLite(element[0].childNodes[2]); expect(e1.hasClass('existing')).toBeTruthy(); - expect(e1.hasClass('even')).toBeTruthy(); + expect(e1.hasClass('odd')).toBeTruthy(); expect(e2.hasClass('existing')).toBeTruthy(); - expect(e2.hasClass('odd')).toBeTruthy(); + expect(e2.hasClass('even')).toBeTruthy(); }); it('should ng-style', function(){ diff --git a/test/markupSpec.js b/test/markupSpec.js index 2ddefe47..e416b8ea 100644 --- a/test/markupSpec.js +++ b/test/markupSpec.js @@ -20,18 +20,18 @@ describe("markups", function(){ it('should translate {{}} in text', function(){ compile('
                          hello {{name}}!
                          '); - expect(element.html()).toEqual('hello !'); + expect(sortedHtml(element)).toEqual('
                          hello !
                          '); scope.$set('name', 'Misko'); scope.$eval(); - expect(element.html()).toEqual('hello Misko!'); + expect(sortedHtml(element)).toEqual('
                          hello Misko!
                          '); }); it('should translate {{}} in terminal nodes', function(){ compile(''); - expect(element.html()).toEqual(''); + expect(sortedHtml(element)).toEqual(''); scope.$set('name', 'Misko'); scope.$eval(); - expect(element.html()).toEqual(''); + expect(sortedHtml(element)).toEqual(''); }); it('should translate {{}} in attributes', function(){ diff --git a/test/moveToAngularCom/MiscTest.js b/test/moveToAngularCom/MiscTest.js new file mode 100644 index 00000000..db6e8563 --- /dev/null +++ b/test/moveToAngularCom/MiscTest.js @@ -0,0 +1,35 @@ +BinderTest.prototype.testExpandEntityTagWithName = function(){ + var c = this.compile('
                          '); + assertEquals( + '
                          ', + sortedHtml(c.node)); + assertEquals("Person", c.scope.$get("friend.$entity")); + assertEquals("friend", c.scope.$get("friend.$$anchor")); +}; + +BinderTest.prototype.XtestExpandSubmitButtonToAction = function(){ + var html = this.compileToHtml(''); + assertTrue(html, html.indexOf('ng-action="$save()"') > 0 ); + assertTrue(html, html.indexOf('ng-bind-attr="{"disabled":"{{$invalidWidgets}}"}"') > 0 ); +}; + +BinderTest.prototype.XtestReplaceFileUploadWithSwf = function(){ + expectAsserts(1); + var form = jQuery("body").append('
                          '); + form.data('scope', new Scope()); + var factory = {}; + var binder = new Binder(form.get(0), factory, new MockLocation()); + factory.createController = function(node){ + assertEquals(node.attr('type'), 'file'); + return {updateModel:function(){}}; + }; + binder.compile(); + jQuery("#testTag").remove(); +}; + +BinderTest.prototype.testExpandEntityTagWithDefaults = function(){ + assertEquals( + '
                          ', + this.compileToHtml('
                          ')); +}; + diff --git a/test/testabilityPatch.js b/test/testabilityPatch.js index 312b1e42..86d139cf 100644 --- a/test/testabilityPatch.js +++ b/test/testabilityPatch.js @@ -83,18 +83,18 @@ function sortedHtml(element) { }; function isVisible(node) { - var display = $(node).css('display'); + var display = node.css('display'); if (display == 'block') display = ""; return display != 'none'; } function assertHidden(node) { var display = node.css('display'); - assertFalse("Node should be hidden but vas visible: " + node.sortedHtml(), isVisible(node)); + assertFalse("Node should be hidden but vas visible: " + sortedHtml(node), isVisible(node)); } function assertVisible(node) { - assertTrue("Node should be visible but vas hidden: " + node.sortedHtml(), isVisible(node)); + assertTrue("Node should be visible but vas hidden: " + sortedHtml(node), isVisible(node)); } function assertJsonEquals(expected, actual) { diff --git a/test/widgetsSpec.js b/test/widgetsSpec.js index d041220b..6123e229 100644 --- a/test/widgetsSpec.js +++ b/test/widgetsSpec.js @@ -19,7 +19,7 @@ describe("input widget", function(){ }); it('should input-text auto init and handle keyup/change events', function(){ - compile(''); + compile(''); expect(scope.$get('name')).toEqual("Misko"); expect(scope.$get('count')).toEqual(0); @@ -100,20 +100,20 @@ describe("input widget", function(){ expect(scope.$get('name')).toEqual('Kai'); }); - it('should call ng-action on button click', function(){ - compile(''); + it('should call ng-change on button click', function(){ + compile(''); element.click(); expect(scope.$get('clicked')).toEqual(true); }); it('should support button alias', function(){ - compile(''); + compile(''); element.click(); expect(scope.$get('clicked')).toEqual(true); }); it('should type="checkbox"', function(){ - compile(''); + compile(''); expect(scope.$get('checkbox')).toEqual(true); element.click(); expect(scope.$get('checkbox')).toEqual(false); @@ -124,8 +124,8 @@ describe("input widget", function(){ it('should type="radio"', function(){ compile('
                          ' + - '' + - '' + + '' + + '' + '
                          '); var a = element[0].childNodes[0]; var b = element[0].childNodes[1]; @@ -181,8 +181,8 @@ describe("input widget", function(){ expect(element.hasClass('ng-exception')).toBeTruthy(); }); - it('should report error on ng-action exception', function(){ - compile(''); + it('should report error on ng-change exception', function(){ + compile(''); element.click(); expect(element.hasClass('ng-exception')).toBeTruthy(); }); -- cgit v1.2.3 From 861bac1d2808b15abb867e761ded8144bf5f7e94 Mon Sep 17 00:00:00 2001 From: Misko Hevery Date: Wed, 31 Mar 2010 17:56:16 -0700 Subject: started to add services --- test/AngularTest.js | 44 -------------------------------------------- test/BinderTest.js | 38 ++++++++++++++++++++------------------ test/ScopeSpec.js | 44 ++++++++++++++++++++++++++++++++++++++++---- test/UrlWatcherTest.js | 25 +++++++++++++++++++++++++ test/servicesSpec.js | 27 +++++++++++++++++++++++++++ 5 files changed, 112 insertions(+), 66 deletions(-) delete mode 100644 test/AngularTest.js create mode 100644 test/UrlWatcherTest.js create mode 100644 test/servicesSpec.js (limited to 'test') diff --git a/test/AngularTest.js b/test/AngularTest.js deleted file mode 100644 index 8db723e5..00000000 --- a/test/AngularTest.js +++ /dev/null @@ -1,44 +0,0 @@ -AngularTest = TestCase('AngularTest'); - -UrlWatcherTest = TestCase('UrlWatcherTest'); - -UrlWatcherTest.prototype.testUrlWatcher = function () { - expectAsserts(2); - var location = {href:"http://server", hash:""}; - var watcher = new UrlWatcher(location); - watcher.delay = 1; - watcher.listener = function(url){ - assertEquals('http://getangular.test', url); - }; - watcher.setTimeout = function(fn, delay){ - assertEquals(1, delay); - location.href = "http://getangular.test"; - watcher.setTimeout = function(fn, delay) { - }; - fn(); - }; - watcher.watch(); -}; - -UrlWatcherTest.prototype.testItShouldFireOnUpdateEventWhenSpecialURLSet = function(){ - expectAsserts(2); - var location = {href:"http://server", hash:"#$iframe_notify=1234"}; - var watcher = new UrlWatcher(location); - angular.callbacks._iframe_notify_1234 = function () { - assertEquals("undefined", typeof angularCallbacks._iframe_notify_1234); - assertEquals("http://server2#", location.href); - }; - watcher.delay = 1; - watcher.expectedUrl = "http://server2"; - watcher.setTimeout = function(fn, delay){ - watcher.setTimeout = function(fn, delay) {}; - fn(); - }; - watcher.watch(); -}; - -FunctionTest = TestCase("FunctionTest"); - -FunctionTest.prototype.testEscapeHtml = function () { - assertEquals("<div>&amp;</div>", escapeHtml('
                          &
                          ')); -}; diff --git a/test/BinderTest.js b/test/BinderTest.js index 4d996a8e..67800e62 100644 --- a/test/BinderTest.js +++ b/test/BinderTest.js @@ -201,24 +201,6 @@ BinderTest.prototype.XtestParseAnchor = function(){ assertTrue(!binder.anchor.x); }; -BinderTest.prototype.XtestWriteAnchor = function(){ - var binder = this.compile("
                          ").binder; - binder.location.set('a'); - binder.anchor.a = 'b'; - binder.anchor.c = ' '; - binder.anchor.d = true; - binder.updateAnchor(); - assertEquals(binder.location.get(), "a#a=b&c=%20&d"); -}; - -BinderTest.prototype.XtestWriteAnchorAsPartOfTheUpdateView = function(){ - var binder = this.compile("
                          ").binder; - binder.location.set('a'); - binder.anchor.a = 'b'; - binder.updateView(); - assertEquals(binder.location.get(), "a#a=b"); -}; - BinderTest.prototype.testRepeaterUpdateBindings = function(){ var a = this.compile('
                          '); var form = a.node; @@ -821,3 +803,23 @@ BinderTest.prototype.testItShouldUseFormaterForText = function() { x.scope.$eval(); assertEquals('1, 2, 3', input[0].value); }; + +BinderTest.prototype.XtestWriteAnchor = function(){ + var binder = this.compile("
                          ").binder; + binder.location.set('a'); + binder.anchor.a = 'b'; + binder.anchor.c = ' '; + binder.anchor.d = true; + binder.updateAnchor(); + assertEquals(binder.location.get(), "a#a=b&c=%20&d"); +}; + +BinderTest.prototype.XtestWriteAnchorAsPartOfTheUpdateView = function(){ + var binder = this.compile("
                          ").binder; + binder.location.set('a'); + binder.anchor.a = 'b'; + binder.updateView(); + assertEquals(binder.location.get(), "a#a=b"); +}; + + diff --git a/test/ScopeSpec.js b/test/ScopeSpec.js index 7e1a899f..8d2a0ed4 100644 --- a/test/ScopeSpec.js +++ b/test/ScopeSpec.js @@ -11,7 +11,8 @@ describe('scope/model', function(){ model.$set('name', 'adam'); expect(model.name).toEqual('adam'); expect(model.$get('name')).toEqual('adam'); - expect(model.$parent).toEqual(parent); + expect(model.$parent).toEqual(model); + expect(model.$root).toEqual(model); }); //$eval @@ -78,15 +79,50 @@ describe('scope/model', function(){ expect(model.printed).toEqual(true); }); - - //$tryEval it('should report error on element', function(){ - + var scope = createScope(); + scope.$tryEval('throw "myerror";', function(error){ + scope.error = error; + }); + expect(scope.error).toEqual('myerror'); }); it('should report error on visible element', function(){ + var element = jqLite('
                          '); + var scope = createScope(); + scope.$tryEval('throw "myError"', element); + expect(element.attr('ng-error')).toEqual('"myError"'); // errors are jsonified + expect(element.hasClass('ng-exception')).toBeTruthy(); + }); + + // $onEval + + it("should eval using priority", function(){ + var scope = createScope(); + scope.log = ""; + scope.$onEval('log = log + "middle;"'); + scope.$onEval(-1, 'log = log + "first;"'); + scope.$onEval(1, 'log = log + "last;"'); + scope.$eval(); + expect(scope.log).toEqual('first;middle;last;'); + }); + + // Services are initialized + it("should inject services", function(){ + var scope = createScope(serviceAdapter({ + $window: function(){ + return window; + } + })); + expect(scope.$window).toEqual(window); + }); + it("should have $root and $parent", function(){ + var parent = createScope(); + var scope = createScope(parent); + expect(scope.$root).toEqual(parent); + expect(scope.$parent).toEqual(parent); }); }); diff --git a/test/UrlWatcherTest.js b/test/UrlWatcherTest.js new file mode 100644 index 00000000..6080ca62 --- /dev/null +++ b/test/UrlWatcherTest.js @@ -0,0 +1,25 @@ +UrlWatcherTest = TestCase('UrlWatcherTest'); + +UrlWatcherTest.prototype.testUrlWatcher = function () { + expectAsserts(2); + var location = {href:"http://server", hash:""}; + var watcher = new UrlWatcher(location); + watcher.delay = 1; + watcher.watch(function(url){ + assertEquals('http://getangular.test', url); + }); + watcher.setTimeout = function(fn, delay){ + assertEquals(1, delay); + location.href = "http://getangular.test"; + watcher.setTimeout = function(fn, delay) { + }; + fn(); + }; + watcher.start(); +}; + +FunctionTest = TestCase("FunctionTest"); + +FunctionTest.prototype.testEscapeHtml = function () { + assertEquals("<div>&amp;</div>", escapeHtml('
                          &
                          ')); +}; diff --git a/test/servicesSpec.js b/test/servicesSpec.js new file mode 100644 index 00000000..5a6bcedc --- /dev/null +++ b/test/servicesSpec.js @@ -0,0 +1,27 @@ +describe("services", function(){ + var scope; + + beforeEach(function(){ + scope = createScope({ + $config: { + 'location': {'get':noop, 'set':noop, 'watch':noop} + } + }, serviceAdapter(angularService)); + }); + + it("should inject $window", function(){ + expect(scope.$window).toEqual(window); + }); + + it("should inject $anchor", function(){ + scope.$anchor('#path?key=value'); + expect(scope.$anchor.path).toEqual("path"); + expect(scope.$anchor.param).toEqual({key:'value'}); + + scope.$anchor.path = 'page=http://path'; + scope.$anchor.param = {k:'a=b'}; + + expect(scope.$anchor()).toEqual('page=http://path?k=a%3Db'); + + }); +}); -- cgit v1.2.3 From 11a6431f8926c557f3c58408dacc98466e76cde1 Mon Sep 17 00:00:00 2001 From: Misko Hevery Date: Wed, 31 Mar 2010 17:56:16 -0700 Subject: started to add services --- test/AngularTest.js | 44 -------------------------------------------- test/BinderTest.js | 38 ++++++++++++++++++++------------------ test/ScopeSpec.js | 44 ++++++++++++++++++++++++++++++++++++++++---- test/UrlWatcherTest.js | 25 +++++++++++++++++++++++++ test/servicesSpec.js | 27 +++++++++++++++++++++++++++ 5 files changed, 112 insertions(+), 66 deletions(-) delete mode 100644 test/AngularTest.js create mode 100644 test/UrlWatcherTest.js create mode 100644 test/servicesSpec.js (limited to 'test') diff --git a/test/AngularTest.js b/test/AngularTest.js deleted file mode 100644 index 8db723e5..00000000 --- a/test/AngularTest.js +++ /dev/null @@ -1,44 +0,0 @@ -AngularTest = TestCase('AngularTest'); - -UrlWatcherTest = TestCase('UrlWatcherTest'); - -UrlWatcherTest.prototype.testUrlWatcher = function () { - expectAsserts(2); - var location = {href:"http://server", hash:""}; - var watcher = new UrlWatcher(location); - watcher.delay = 1; - watcher.listener = function(url){ - assertEquals('http://getangular.test', url); - }; - watcher.setTimeout = function(fn, delay){ - assertEquals(1, delay); - location.href = "http://getangular.test"; - watcher.setTimeout = function(fn, delay) { - }; - fn(); - }; - watcher.watch(); -}; - -UrlWatcherTest.prototype.testItShouldFireOnUpdateEventWhenSpecialURLSet = function(){ - expectAsserts(2); - var location = {href:"http://server", hash:"#$iframe_notify=1234"}; - var watcher = new UrlWatcher(location); - angular.callbacks._iframe_notify_1234 = function () { - assertEquals("undefined", typeof angularCallbacks._iframe_notify_1234); - assertEquals("http://server2#", location.href); - }; - watcher.delay = 1; - watcher.expectedUrl = "http://server2"; - watcher.setTimeout = function(fn, delay){ - watcher.setTimeout = function(fn, delay) {}; - fn(); - }; - watcher.watch(); -}; - -FunctionTest = TestCase("FunctionTest"); - -FunctionTest.prototype.testEscapeHtml = function () { - assertEquals("<div>&amp;</div>", escapeHtml('
                          &
                          ')); -}; diff --git a/test/BinderTest.js b/test/BinderTest.js index 4d996a8e..67800e62 100644 --- a/test/BinderTest.js +++ b/test/BinderTest.js @@ -201,24 +201,6 @@ BinderTest.prototype.XtestParseAnchor = function(){ assertTrue(!binder.anchor.x); }; -BinderTest.prototype.XtestWriteAnchor = function(){ - var binder = this.compile("
                          ").binder; - binder.location.set('a'); - binder.anchor.a = 'b'; - binder.anchor.c = ' '; - binder.anchor.d = true; - binder.updateAnchor(); - assertEquals(binder.location.get(), "a#a=b&c=%20&d"); -}; - -BinderTest.prototype.XtestWriteAnchorAsPartOfTheUpdateView = function(){ - var binder = this.compile("
                          ").binder; - binder.location.set('a'); - binder.anchor.a = 'b'; - binder.updateView(); - assertEquals(binder.location.get(), "a#a=b"); -}; - BinderTest.prototype.testRepeaterUpdateBindings = function(){ var a = this.compile('
                          '); var form = a.node; @@ -821,3 +803,23 @@ BinderTest.prototype.testItShouldUseFormaterForText = function() { x.scope.$eval(); assertEquals('1, 2, 3', input[0].value); }; + +BinderTest.prototype.XtestWriteAnchor = function(){ + var binder = this.compile("
                          ").binder; + binder.location.set('a'); + binder.anchor.a = 'b'; + binder.anchor.c = ' '; + binder.anchor.d = true; + binder.updateAnchor(); + assertEquals(binder.location.get(), "a#a=b&c=%20&d"); +}; + +BinderTest.prototype.XtestWriteAnchorAsPartOfTheUpdateView = function(){ + var binder = this.compile("
                          ").binder; + binder.location.set('a'); + binder.anchor.a = 'b'; + binder.updateView(); + assertEquals(binder.location.get(), "a#a=b"); +}; + + diff --git a/test/ScopeSpec.js b/test/ScopeSpec.js index 7e1a899f..8d2a0ed4 100644 --- a/test/ScopeSpec.js +++ b/test/ScopeSpec.js @@ -11,7 +11,8 @@ describe('scope/model', function(){ model.$set('name', 'adam'); expect(model.name).toEqual('adam'); expect(model.$get('name')).toEqual('adam'); - expect(model.$parent).toEqual(parent); + expect(model.$parent).toEqual(model); + expect(model.$root).toEqual(model); }); //$eval @@ -78,15 +79,50 @@ describe('scope/model', function(){ expect(model.printed).toEqual(true); }); - - //$tryEval it('should report error on element', function(){ - + var scope = createScope(); + scope.$tryEval('throw "myerror";', function(error){ + scope.error = error; + }); + expect(scope.error).toEqual('myerror'); }); it('should report error on visible element', function(){ + var element = jqLite('
                          '); + var scope = createScope(); + scope.$tryEval('throw "myError"', element); + expect(element.attr('ng-error')).toEqual('"myError"'); // errors are jsonified + expect(element.hasClass('ng-exception')).toBeTruthy(); + }); + + // $onEval + + it("should eval using priority", function(){ + var scope = createScope(); + scope.log = ""; + scope.$onEval('log = log + "middle;"'); + scope.$onEval(-1, 'log = log + "first;"'); + scope.$onEval(1, 'log = log + "last;"'); + scope.$eval(); + expect(scope.log).toEqual('first;middle;last;'); + }); + + // Services are initialized + it("should inject services", function(){ + var scope = createScope(serviceAdapter({ + $window: function(){ + return window; + } + })); + expect(scope.$window).toEqual(window); + }); + it("should have $root and $parent", function(){ + var parent = createScope(); + var scope = createScope(parent); + expect(scope.$root).toEqual(parent); + expect(scope.$parent).toEqual(parent); }); }); diff --git a/test/UrlWatcherTest.js b/test/UrlWatcherTest.js new file mode 100644 index 00000000..6080ca62 --- /dev/null +++ b/test/UrlWatcherTest.js @@ -0,0 +1,25 @@ +UrlWatcherTest = TestCase('UrlWatcherTest'); + +UrlWatcherTest.prototype.testUrlWatcher = function () { + expectAsserts(2); + var location = {href:"http://server", hash:""}; + var watcher = new UrlWatcher(location); + watcher.delay = 1; + watcher.watch(function(url){ + assertEquals('http://getangular.test', url); + }); + watcher.setTimeout = function(fn, delay){ + assertEquals(1, delay); + location.href = "http://getangular.test"; + watcher.setTimeout = function(fn, delay) { + }; + fn(); + }; + watcher.start(); +}; + +FunctionTest = TestCase("FunctionTest"); + +FunctionTest.prototype.testEscapeHtml = function () { + assertEquals("<div>&amp;</div>", escapeHtml('
                          &
                          ')); +}; diff --git a/test/servicesSpec.js b/test/servicesSpec.js new file mode 100644 index 00000000..5a6bcedc --- /dev/null +++ b/test/servicesSpec.js @@ -0,0 +1,27 @@ +describe("services", function(){ + var scope; + + beforeEach(function(){ + scope = createScope({ + $config: { + 'location': {'get':noop, 'set':noop, 'watch':noop} + } + }, serviceAdapter(angularService)); + }); + + it("should inject $window", function(){ + expect(scope.$window).toEqual(window); + }); + + it("should inject $anchor", function(){ + scope.$anchor('#path?key=value'); + expect(scope.$anchor.path).toEqual("path"); + expect(scope.$anchor.param).toEqual({key:'value'}); + + scope.$anchor.path = 'page=http://path'; + scope.$anchor.param = {k:'a=b'}; + + expect(scope.$anchor()).toEqual('page=http://path?k=a%3Db'); + + }); +}); -- cgit v1.2.3 From 85f13d602e31424b2e2d18172872f14a24c31135 Mon Sep 17 00:00:00 2001 From: Misko Hevery Date: Thu, 1 Apr 2010 14:10:28 -0700 Subject: work on $location and autobind --- test/BinderTest.js | 4 ++-- test/servicesSpec.js | 15 +++++++++++---- 2 files changed, 13 insertions(+), 6 deletions(-) (limited to 'test') diff --git a/test/BinderTest.js b/test/BinderTest.js index 67800e62..9c5c5dc6 100644 --- a/test/BinderTest.js +++ b/test/BinderTest.js @@ -721,13 +721,13 @@ BinderTest.prototype.testItShouldSelectTheCorrectRadioBox = function() { var male = jqLite(c.node[0].childNodes[1]); female.click(); - assertEquals("female", c.scope.$get("sex")); + assertEquals("female", c.scope.sex); assertEquals(true, female[0].checked); assertEquals(false, male[0].checked); assertEquals("female", female.val()); male.click(); - assertEquals("male", c.scope.$get("sex")); + assertEquals("male", c.scope.sex); assertEquals(false, female[0].checked); assertEquals(true, male[0].checked); assertEquals("male", male.val()); diff --git a/test/servicesSpec.js b/test/servicesSpec.js index 5a6bcedc..88cbc947 100644 --- a/test/servicesSpec.js +++ b/test/servicesSpec.js @@ -13,10 +13,17 @@ describe("services", function(){ expect(scope.$window).toEqual(window); }); - it("should inject $anchor", function(){ - scope.$anchor('#path?key=value'); - expect(scope.$anchor.path).toEqual("path"); - expect(scope.$anchor.param).toEqual({key:'value'}); + it("should inject $location", function(){ + scope.$location('http://host:1234/p/a/t/h?query=value#path?key=value'); + expect(scope.$location.href).toEqual("http://host:123/p/a/t/h?query=value#path?key=value"); + expect(scope.$location.protocol).toEqual("http"); + expect(scope.$location.host).toEqual("host"); + expect(scope.$location.port).toEqual("1234"); + expect(scope.$location.path).toEqual("/p/a/t/h"); + 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.$anchor.path = 'page=http://path'; scope.$anchor.param = {k:'a=b'}; -- cgit v1.2.3 From d717020911a350a5ea3c0a985c57d56c8fcad607 Mon Sep 17 00:00:00 2001 From: Misko Hevery Date: Fri, 2 Apr 2010 11:10:36 -0700 Subject: widgets now work properly --- test/servicesSpec.js | 28 +++++++++++++++++++++------- test/widgetsSpec.js | 10 +++++----- 2 files changed, 26 insertions(+), 12 deletions(-) (limited to 'test') diff --git a/test/servicesSpec.js b/test/servicesSpec.js index 88cbc947..dec4550f 100644 --- a/test/servicesSpec.js +++ b/test/servicesSpec.js @@ -14,21 +14,35 @@ describe("services", function(){ }); it("should inject $location", function(){ - scope.$location('http://host:1234/p/a/t/h?query=value#path?key=value'); - expect(scope.$location.href).toEqual("http://host:123/p/a/t/h?query=value#path?key=value"); + scope.$location('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("1234"); - expect(scope.$location.path).toEqual("/p/a/t/h"); + 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.$anchor.path = 'page=http://path'; - scope.$anchor.param = {k:'a=b'}; + scope.$location.hashPath = 'page=http://path'; + scope.$location.hashSearch = {k:'a=b'}; - expect(scope.$anchor()).toEqual('page=http://path?k=a%3Db'); + expect(scope.$location()).toEqual('http://host:123/p/a/t/h.html?query=value#path?key=valuepage=http://path?k=a%3Db'); + }); + + it('should parse file://', function(){ + scope.$location('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()).toEqual('file:///Users/Shared/misko/work/angular.js/scenario/widgets.html'); }); }); diff --git a/test/widgetsSpec.js b/test/widgetsSpec.js index 6123e229..6c47e5dd 100644 --- a/test/widgetsSpec.js +++ b/test/widgetsSpec.js @@ -114,23 +114,23 @@ describe("input widget", function(){ it('should type="checkbox"', function(){ compile(''); - expect(scope.$get('checkbox')).toEqual(true); + expect(scope.checkbox).toEqual(true); element.click(); - expect(scope.$get('checkbox')).toEqual(false); - expect(scope.$get('action')).toEqual(true); + expect(scope.checkbox).toEqual(false); + expect(scope.action).toEqual(true); element.click(); - expect(scope.$get('checkbox')).toEqual(true); + expect(scope.checkbox).toEqual(true); }); it('should type="radio"', function(){ compile('
                          ' + '' + '' + + '' + '
                          '); var a = element[0].childNodes[0]; var b = element[0].childNodes[1]; expect(scope.chose).toEqual('B'); - expect(scope.clicked).not.toBeDefined(); scope.chose = 'A'; scope.$eval(); expect(a.checked).toEqual(true); -- cgit v1.2.3 From 35ca4fcb9c49e505e28669e951e01ddedb01d7db Mon Sep 17 00:00:00 2001 From: Misko Hevery Date: Fri, 2 Apr 2010 11:49:48 -0700 Subject: radio now works with repeaters --- test/widgetsSpec.js | 1 + 1 file changed, 1 insertion(+) (limited to 'test') diff --git a/test/widgetsSpec.js b/test/widgetsSpec.js index 6c47e5dd..a4afa21c 100644 --- a/test/widgetsSpec.js +++ b/test/widgetsSpec.js @@ -130,6 +130,7 @@ describe("input widget", function(){ '
                          '); var a = element[0].childNodes[0]; var b = element[0].childNodes[1]; + expect(b.name.split('@')[1]).toEqual('chose'); expect(scope.chose).toEqual('B'); scope.chose = 'A'; scope.$eval(); -- cgit v1.2.3 From a80a61839a66d244c8bb14bbe2975746e02516c8 Mon Sep 17 00:00:00 2001 From: Misko Hevery Date: Sat, 3 Apr 2010 17:04:36 -0700 Subject: injection is now working --- test/BinderTest.js | 5 ++-- test/BrowserTest.js | 25 +++++++++++++++++++ test/CompilerSpec.js | 62 ++++++++++++++++++------------------------------ test/FormattersTest.js | 22 ++++++++--------- test/ParserTest.js | 2 +- test/ScopeSpec.js | 57 +++++++++++++++++++++++++------------------- test/UrlWatcherTest.js | 25 ------------------- test/servicesSpec.js | 17 +++++++++---- test/testabilityPatch.js | 30 ++++++++++++++++------- 9 files changed, 128 insertions(+), 117 deletions(-) create mode 100644 test/BrowserTest.js delete mode 100644 test/UrlWatcherTest.js (limited to 'test') diff --git a/test/BinderTest.js b/test/BinderTest.js index 9c5c5dc6..fa3127d7 100644 --- a/test/BinderTest.js +++ b/test/BinderTest.js @@ -19,6 +19,7 @@ BinderTest.prototype.tearDown = function(){ if (this.element && this.element.dealoc) this.element.dealoc(); }; + BinderTest.prototype.testChangingTextfieldUpdatesModel = function(){ var state = this.compile('', {model:{}}); state.scope.$eval(); @@ -707,7 +708,7 @@ BinderTest.prototype.testItShouldDisplayErrorWhenActionIsSyntacticlyIncorect = f var second = jqLite(c.node[0].childNodes[1]); first.click(); - assertEquals("ABC", c.scope.$get('greeting')); + assertEquals("ABC", c.scope.greeting); second.click(); assertTrue(second.hasClass("ng-exception")); @@ -821,5 +822,3 @@ BinderTest.prototype.XtestWriteAnchorAsPartOfTheUpdateView = function(){ binder.updateView(); assertEquals(binder.location.get(), "a#a=b"); }; - - diff --git a/test/BrowserTest.js b/test/BrowserTest.js new file mode 100644 index 00000000..2e630172 --- /dev/null +++ b/test/BrowserTest.js @@ -0,0 +1,25 @@ +BrowserTest = TestCase('BrowserTest'); + +BrowserTest.prototype.testUrlWatcher = function () { + expectAsserts(2); + var location = {href:"http://server", hash:""}; + var watcher = new Browser(location); + watcher.delay = 1; + watcher.watchUrl(function(url){ + assertEquals('http://getangular.test', url); + }); + watcher.setTimeout = function(fn, delay){ + assertEquals(1, delay); + location.href = "http://getangular.test"; + watcher.setTimeout = function(fn, delay) { + }; + fn(); + }; + watcher.startUrlWatcher(); +}; + +FunctionTest = TestCase("FunctionTest"); + +FunctionTest.prototype.testEscapeHtml = function () { + assertEquals("<div>&amp;</div>", escapeHtml('
                          &
                          ')); +}; diff --git a/test/CompilerSpec.js b/test/CompilerSpec.js index 59b7ab6b..9922070f 100644 --- a/test/CompilerSpec.js +++ b/test/CompilerSpec.js @@ -1,8 +1,4 @@ -xdescribe('compiler', function(){ - function element(html) { - return jQuery(html)[0]; - } - +describe('compiler', function(){ var compiler, textMarkup, directives, widgets, compile, log; beforeEach(function(){ @@ -29,25 +25,25 @@ xdescribe('compiler', function(){ widgets = {}; compiler = new Compiler(textMarkup, attrMarkup, directives, widgets); compile = function(html){ - var e = element("
                          " + html + "
                          "); - var view = compiler.compile(e)(e); - view.init(); - return view.scope; + var e = jqLite("
                          " + html + "
                          "); + var scope = compiler.compile(e)(e); + scope.$init(); + return scope; }; }); it('should recognize a directive', function(){ - var e = element('
                          '); + var e = jqLite('
                          '); directives.directive = function(expression, element){ log += "found"; expect(expression).toEqual("expr"); - expect(element[0]).toEqual(e); + expect(element).toEqual(e); return function initFn() { log += ":init"; }; }; var template = compiler.compile(e); - var init = template(e).init; + var init = template(e).$init; expect(log).toEqual("found"); init(); expect(log).toEqual("found:init"); @@ -61,13 +57,13 @@ xdescribe('compiler', function(){ it('should watch scope', function(){ var scope = compile(''); expect(log).toEqual(""); - scope.updateView(); - scope.set('name', 'misko'); - scope.updateView(); - scope.updateView(); - scope.set('name', 'adam'); - scope.updateView(); - scope.updateView(); + scope.$eval(); + scope.$set('name', 'misko'); + scope.$eval(); + scope.$eval(); + scope.$set('name', 'adam'); + scope.$eval(); + scope.$eval(); expect(log).toEqual(":misko:adam"); }); @@ -83,29 +79,17 @@ xdescribe('compiler', function(){ element.removeAttr("duplicate"); var template = this.compile(element); return function(marker) { - this.$addEval(function() { + this.$onEval(function() { marker.after(template(element.clone()).element); }); }; }; var scope = compile('beforexafter'); - expect($(scope.element).html()).toEqual('beforeafter'); - scope.updateView(); - expect($(scope.element).html()).toEqual('beforexafter'); - scope.updateView(); - expect($(scope.element).html()).toEqual('beforexxafter'); - }); - - it('should allow for exculsive tags which suppress others', function(){ - directives.exclusive = function(){ - return function() { - log += ('exclusive'); - }; - }; - directives.exclusive.exclusive = true; - - compile(''); - expect(log).toEqual('exclusive'); + expect(sortedHtml(scope.$element)).toEqual('
                          before<#comment>after
                          '); + scope.$eval(); + expect(sortedHtml(scope.$element)).toEqual('
                          before<#comment>after
                          '); + scope.$eval(); + expect(sortedHtml(scope.$element)).toEqual('
                          before<#comment>after
                          '); }); it('should process markup before directives', function(){ @@ -117,7 +101,7 @@ xdescribe('compiler', function(){ } }); var scope = compile('beforemiddleafter'); - expect(scope.element.innerHTML).toEqual('beforereplacedafter'); + expect(scope.$element[0].innerHTML).toEqual('beforereplacedafter'); expect(log).toEqual("hello middle"); }); @@ -129,7 +113,7 @@ xdescribe('compiler', function(){ }; }; var scope = compile('push me'); - expect(scope.element.innerHTML).toEqual('
                          button
                          '); + expect(scope.$element[0].innerHTML).toEqual('
                          button
                          '); expect(log).toEqual('init'); }); diff --git a/test/FormattersTest.js b/test/FormattersTest.js index 59f12c1f..b520faf9 100644 --- a/test/FormattersTest.js +++ b/test/FormattersTest.js @@ -4,7 +4,7 @@ TestCase("formatterTest", { assertEquals("xyz", angular.formatter.noop.parse("xyz")); assertEquals(null, angular.formatter.noop.parse(null)); }, - + testList: function() { assertEquals('a, b', angular.formatter.list.format(['a', 'b'])); assertEquals('', angular.formatter.list.format([])); @@ -12,26 +12,26 @@ TestCase("formatterTest", { assertEquals([], angular.formatter.list.parse("")); assertEquals([], angular.formatter.list.parse(null)); }, - + testBoolean: function() { - assertEquals('true', angular.formatter.boolean.format(true)); - assertEquals('false', angular.formatter.boolean.format(false)); - assertEquals(true, angular.formatter.boolean.parse("true")); - assertEquals(false, angular.formatter.boolean.parse("")); - assertEquals(false, angular.formatter.boolean.parse("false")); - assertEquals(null, angular.formatter.boolean.parse(null)); + assertEquals('true', angular.formatter['boolean'].format(true)); + assertEquals('false', angular.formatter['boolean'].format(false)); + assertEquals(true, angular.formatter['boolean'].parse("true")); + assertEquals(false, angular.formatter['boolean'].parse("")); + assertEquals(false, angular.formatter['boolean'].parse("false")); + assertEquals(null, angular.formatter['boolean'].parse(null)); }, - + testNumber: function() { assertEquals('1', angular.formatter.number.format(1)); assertEquals(1, angular.formatter.number.format('1')); }, - + testTrim: function() { assertEquals('', angular.formatter.trim.format(null)); assertEquals('', angular.formatter.trim.format("")); assertEquals('a', angular.formatter.trim.format(" a ")); assertEquals('a', angular.formatter.trim.parse(' a ')); } - + }); diff --git a/test/ParserTest.js b/test/ParserTest.js index 639e919f..6170dd4a 100644 --- a/test/ParserTest.js +++ b/test/ParserTest.js @@ -171,7 +171,7 @@ ParserTest.prototype.testComparison = function(){ assertEquals(scope.$eval("1>2"), 1>2); assertEquals(scope.$eval("2>=1"), 2>=1); - assertEquals(true==2<3, scope.$eval("true==2<3")); + assertEquals(true === 2<3, scope.$eval("true==2<3")); }; diff --git a/test/ScopeSpec.js b/test/ScopeSpec.js index 8d2a0ed4..a7322cae 100644 --- a/test/ScopeSpec.js +++ b/test/ScopeSpec.js @@ -65,20 +65,6 @@ describe('scope/model', function(){ expect(model.$bind(function(){return this.name;})()).toEqual('misko'); }); - //$behavior - it('should behave as class', function(){ - function Printer(brand){ - this.brand = brand; - }; - Printer.prototype.print = function(){ - this.printed = true; - }; - var model = createScope({ name: 'parent' }, Printer, 'hp'); - expect(model.brand).toEqual('hp'); - model.print(); - expect(model.printed).toEqual(true); - }); - //$tryEval it('should report error on element', function(){ var scope = createScope(); @@ -108,16 +94,6 @@ describe('scope/model', function(){ expect(scope.log).toEqual('first;middle;last;'); }); - // Services are initialized - it("should inject services", function(){ - var scope = createScope(serviceAdapter({ - $window: function(){ - return window; - } - })); - expect(scope.$window).toEqual(window); - }); - it("should have $root and $parent", function(){ var parent = createScope(); var scope = createScope(parent); @@ -125,4 +101,37 @@ describe('scope/model', function(){ expect(scope.$parent).toEqual(parent); }); + // Service injection + it('should inject services', function(){ + var scope = createScope(null, { + service:function(){ + return "ABC"; + } + }); + expect(scope.service).toEqual("ABC"); + }); + + it('should inject arugments', function(){ + var scope = createScope(null, { + name:function(){ + return "misko"; + }, + greet: extend(function(name) { + return 'hello ' + name; + }, {inject:['name']}) + }); + expect(scope.greet).toEqual("hello misko"); + }); + + it('should throw error on missing dependency', function(){ + try { + createScope(null, { + greet: extend(function(name) { + }, {inject:['name']}) + }); + } catch(e) { + expect(e).toEqual("Don't know how to inject 'name'."); + } + }); + }); diff --git a/test/UrlWatcherTest.js b/test/UrlWatcherTest.js deleted file mode 100644 index 6080ca62..00000000 --- a/test/UrlWatcherTest.js +++ /dev/null @@ -1,25 +0,0 @@ -UrlWatcherTest = TestCase('UrlWatcherTest'); - -UrlWatcherTest.prototype.testUrlWatcher = function () { - expectAsserts(2); - var location = {href:"http://server", hash:""}; - var watcher = new UrlWatcher(location); - watcher.delay = 1; - watcher.watch(function(url){ - assertEquals('http://getangular.test', url); - }); - watcher.setTimeout = function(fn, delay){ - assertEquals(1, delay); - location.href = "http://getangular.test"; - watcher.setTimeout = function(fn, delay) { - }; - fn(); - }; - watcher.start(); -}; - -FunctionTest = TestCase("FunctionTest"); - -FunctionTest.prototype.testEscapeHtml = function () { - assertEquals("<div>&amp;</div>", escapeHtml('
                          &
                          ')); -}; diff --git a/test/servicesSpec.js b/test/servicesSpec.js index b92975d0..49000af4 100644 --- a/test/servicesSpec.js +++ b/test/servicesSpec.js @@ -2,11 +2,7 @@ describe("services", function(){ var scope; beforeEach(function(){ - scope = createScope({ - $config: { - 'location': {'get':noop, 'set':noop, 'watch':noop} - } - }, serviceAdapter(angularService)); + scope = createScope(null, angularService, {}); }); it("should inject $window", function(){ @@ -46,4 +42,15 @@ describe("services", function(){ expect(scope.$location()).toEqual('file:///Users/Shared/misko/work/angular.js/scenario/widgets.html'); }); + xit('should add stylesheets', function(){ + scope.$document = { + getElementsByTagName: function(name){ + expect(name).toEqual('LINK'); + return []; + } + }; + scope.$document.addStyleSheet('css/angular.css'); + + }); + }); diff --git a/test/testabilityPatch.js b/test/testabilityPatch.js index 86d139cf..752f8ef2 100644 --- a/test/testabilityPatch.js +++ b/test/testabilityPatch.js @@ -3,7 +3,7 @@ dump = bind(jstd.console, jstd.console.log); function nakedExpect(obj) { return expect(angular.fromJson(angular.toJson(obj))); -}; +} swfobject = { createSwf:function() { @@ -27,15 +27,27 @@ function report(reportTest){ }); } -MockLocation = function() { +function MockBrowser() { this.url = "http://server"; + this.watches = []; +} +MockBrowser.prototype = { + getUrl: function(){ + return this.url; + }, + + setUrl: function(url){ + this.url = url; + }, + + watchUrl: function(fn) { + this.watches.push(fn); + } }; -MockLocation.prototype.get = function(){ - return this.url; -}; -MockLocation.prototype.set = function(url){ - this.url = url; -}; + +angularService('$browser', function(){ + return new MockBrowser(); +}); function childNode(element, index) { return jqLite(element[0].childNodes[index]); @@ -80,7 +92,7 @@ function sortedHtml(element) { } })(element[0]); return html; -}; +} function isVisible(node) { var display = node.css('display'); -- cgit v1.2.3 From 5dcf9bb4feb144b3a54a43524210dd7d0bb4213e Mon Sep 17 00:00:00 2001 From: Misko Hevery Date: Sat, 3 Apr 2010 20:19:55 -0700 Subject: browser is now injectable into the system --- test/servicesSpec.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'test') diff --git a/test/servicesSpec.js b/test/servicesSpec.js index 49000af4..193351d1 100644 --- a/test/servicesSpec.js +++ b/test/servicesSpec.js @@ -24,7 +24,7 @@ describe("services", function(){ scope.$location.hashPath = 'page=http://path'; scope.$location.hashSearch = {k:'a=b'}; - expect(scope.$location()).toEqual('http://host:123/p/a/t/h.html?query=value#path?key=valuepage=http://path?k=a%3Db'); + expect(scope.$location()).toEqual('http://host:123/p/a/t/h.html?query=value#page=http://path?k=a%3Db'); }); it('should parse file://', function(){ @@ -39,7 +39,7 @@ describe("services", function(){ expect(scope.$location.hashPath).toEqual(''); expect(scope.$location.hashSearch).toEqual({}); - expect(scope.$location()).toEqual('file:///Users/Shared/misko/work/angular.js/scenario/widgets.html'); + expect(scope.$location()).toEqual('file:///Users/Shared/misko/work/angular.js/scenario/widgets.html#'); }); xit('should add stylesheets', function(){ -- cgit v1.2.3 From 7a4b48020688060debe9cb0f9c17615d7585cbe7 Mon Sep 17 00:00:00 2001 From: Misko Hevery Date: Mon, 5 Apr 2010 11:46:53 -0700 Subject: added ng:switch widget --- test/BinderTest.js | 15 --------------- test/ScenarioSpec.js | 12 ++++++------ test/ScopeSpec.js | 2 +- test/ValidatorsTest.js | 2 +- test/angular-mocks.js | 26 ++++++++++++++++++++++++++ test/servicesSpec.js | 8 ++++---- test/testabilityPatch.js | 40 ---------------------------------------- test/widgetsSpec.js | 16 ++++++++++++++++ 8 files changed, 54 insertions(+), 67 deletions(-) create mode 100644 test/angular-mocks.js (limited to 'test') diff --git a/test/BinderTest.js b/test/BinderTest.js index fa3127d7..660ad78c 100644 --- a/test/BinderTest.js +++ b/test/BinderTest.js @@ -629,21 +629,6 @@ BinderTest.prototype.testDeleteAttributeIfEvaluatesFalse = function() { assertChild(5, false); }; -BinderTest.prototype.testRepeaterErrorShouldBePlacedOnInstanceNotOnTemplateComment = function () { - var c = this.compile( - ''); - c.scope.$eval(); - assertTrue(c.node.hasClass("ng-exception")); -}; - -BinderTest.prototype.testItShouldApplyAttributesBeforeTheWidgetsAreMaterialized = function() { - var c = this.compile( - ''); - c.scope.$set('person', {a:'misko', b:'adam'}); - c.scope.$eval(); - assertEquals("", c.node.html()); -}; - BinderTest.prototype.XtestItShouldCallListenersWhenAnchorChanges = function() { var log = ""; var c = this.compile('
                          '); diff --git a/test/ScenarioSpec.js b/test/ScenarioSpec.js index 5b88a175..ff3a55b5 100644 --- a/test/ScenarioSpec.js +++ b/test/ScenarioSpec.js @@ -1,26 +1,26 @@ describe("ScenarioSpec: Compilation", function(){ it("should compile dom node and return scope", function(){ var node = jqLite('
                          {{b=a+1}}
                          ')[0]; - var scope = angular.compile(node); + var scope = compile(node); scope.$init(); expect(scope.a).toEqual(1); expect(scope.b).toEqual(2); }); it("should compile jQuery node and return scope", function(){ - var scope = angular.compile(jqLite('
                          {{a=123}}
                          ')).$init(); + var scope = compile(jqLite('
                          {{a=123}}
                          ')).$init(); expect(jqLite(scope.$element).text()).toEqual('123'); }); it("should compile text node and return scope", function(){ - var scope = angular.compile('
                          {{a=123}}
                          ').$init(); + var scope = compile('
                          {{a=123}}
                          ').$init(); expect(jqLite(scope.$element).text()).toEqual('123'); }); }); describe("ScenarioSpec: Scope", function(){ xit("should have set, get, eval, $init, updateView methods", function(){ - var scope = angular.compile('
                          {{a}}
                          ').$init(); + var scope = compile('
                          {{a}}
                          ').$init(); scope.$eval("$invalidWidgets.push({})"); expect(scope.$set("a", 2)).toEqual(2); expect(scope.$get("a")).toEqual(2); @@ -31,7 +31,7 @@ describe("ScenarioSpec: Scope", function(){ }); xit("should have $ objects", function(){ - var scope = angular.compile('
                          ', {a:"b"}); + var scope = compile('
                          ', {a:"b"}); expect(scope.$get('$anchor')).toBeDefined(); expect(scope.$get('$eval')).toBeDefined(); expect(scope.$get('$config')).toBeDefined(); @@ -49,7 +49,7 @@ xdescribe("ScenarioSpec: configuration", function(){ set:function(u){url = u;}, get:function(){return url;} }; - var scope = angular.compile("
                          {{$anchor}}
                          ", {location:location}); + var scope = compile("
                          {{$anchor}}
                          ", {location:location}); var $anchor = scope.$get('$anchor'); expect($anchor.book).toBeUndefined(); expect(onUrlChange).toBeUndefined(); diff --git a/test/ScopeSpec.js b/test/ScopeSpec.js index a7322cae..09f4d875 100644 --- a/test/ScopeSpec.js +++ b/test/ScopeSpec.js @@ -44,7 +44,7 @@ describe('scope/model', function(){ model.$onEval(function(){evalCount ++;}); model.name = 'misko'; model.$eval(); - expect(nameCount).toEqual(1); + expect(nameCount).toEqual(2); expect(evalCount).toEqual(1); expect(model.newValue).toEqual('misko'); expect(model.oldValue).toEqual('adam'); diff --git a/test/ValidatorsTest.js b/test/ValidatorsTest.js index 37be526d..d7da28cd 100644 --- a/test/ValidatorsTest.js +++ b/test/ValidatorsTest.js @@ -106,7 +106,7 @@ describe('Validator:asynchronous', function(){ it('should make a request and show spinner', function(){ var value, fn; - var scope = angular.compile(''); + var scope = compile(''); scope.$init(); var input = scope.$element; scope.asyncFn = function(v,f){ diff --git a/test/angular-mocks.js b/test/angular-mocks.js new file mode 100644 index 00000000..ab3638b1 --- /dev/null +++ b/test/angular-mocks.js @@ -0,0 +1,26 @@ + +function MockBrowser() { + this.url = "http://server"; + this.watches = []; +} +MockBrowser.prototype = { + xhr: function(method, url, callback) { + + }, + + getUrl: function(){ + return this.url; + }, + + setUrl: function(url){ + this.url = url; + }, + + watchUrl: function(fn) { + this.watches.push(fn); + } +}; + +angular.service('$browser', function(){ + return new MockBrowser(); +}); diff --git a/test/servicesSpec.js b/test/servicesSpec.js index 193351d1..43511853 100644 --- a/test/servicesSpec.js +++ b/test/servicesSpec.js @@ -10,7 +10,7 @@ describe("services", function(){ }); it("should inject $location", function(){ - scope.$location('http://host:123/p/a/t/h.html?query=value#path?key=value'); + 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"); @@ -24,11 +24,11 @@ describe("services", function(){ scope.$location.hashPath = 'page=http://path'; scope.$location.hashSearch = {k:'a=b'}; - expect(scope.$location()).toEqual('http://host:123/p/a/t/h.html?query=value#page=http://path?k=a%3Db'); + 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('file:///Users/Shared/misko/work/angular.js/scenario/widgets.html'); + 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(""); @@ -39,7 +39,7 @@ describe("services", function(){ expect(scope.$location.hashPath).toEqual(''); expect(scope.$location.hashSearch).toEqual({}); - expect(scope.$location()).toEqual('file:///Users/Shared/misko/work/angular.js/scenario/widgets.html#'); + expect(scope.$location.toString()).toEqual('file:///Users/Shared/misko/work/angular.js/scenario/widgets.html#'); }); xit('should add stylesheets', function(){ diff --git a/test/testabilityPatch.js b/test/testabilityPatch.js index 752f8ef2..b2ee5526 100644 --- a/test/testabilityPatch.js +++ b/test/testabilityPatch.js @@ -5,46 +5,6 @@ function nakedExpect(obj) { return expect(angular.fromJson(angular.toJson(obj))); } -swfobject = { - createSwf:function() { - fail("must mock out swfobject.createSwf in test."); - } -}; - -function html(content) { - return jQuery("
                          ").html(content); -} - -function report(reportTest){ - $("#tests").children().each(function(i){ - var success = this.className == "pass"; - var strong = this.firstChild; - var msg = strong.firstChild.nodeValue; - var parts = msg.split(" module: "); - var module = parts[0]; - var name = parts[1].replace(/ *$/, ""); - reportTest(success, module, name, this.nodeValue); - }); -} - -function MockBrowser() { - this.url = "http://server"; - this.watches = []; -} -MockBrowser.prototype = { - getUrl: function(){ - return this.url; - }, - - setUrl: function(url){ - this.url = url; - }, - - watchUrl: function(fn) { - this.watches.push(fn); - } -}; - angularService('$browser', function(){ return new MockBrowser(); }); diff --git a/test/widgetsSpec.js b/test/widgetsSpec.js index a4afa21c..63c18700 100644 --- a/test/widgetsSpec.js +++ b/test/widgetsSpec.js @@ -188,5 +188,21 @@ describe("input widget", function(){ expect(element.hasClass('ng-exception')).toBeTruthy(); }); + it('should switch on value change', function(){ + compile('
                          first
                          second
                          '); + expect(element.html()).toEqual(''); + scope.select = 1; + scope.$eval(); + expect(element.text()).toEqual('first'); + scope.select = 2; + scope.$eval(); + expect(element.text()).toEqual('second'); + }); +}); +describe('ng:include', function(){ + it('should include on external file', function() { + var element = jqLite(''); + var scope = compile(element).$init(); + }); }); -- cgit v1.2.3 From 1c670b2a7c3f6153ea2e5047722f7151b9795b33 Mon Sep 17 00:00:00 2001 From: Misko Hevery Date: Mon, 5 Apr 2010 14:09:25 -0700 Subject: added ng:include --- test/angular-mocks.js | 34 +++++++++++++++++++++++++++++----- test/directivesSpec.js | 2 +- test/testabilityPatch.js | 22 ++++++++++++++++++---- test/widgetsSpec.js | 7 ++++++- 4 files changed, 54 insertions(+), 11 deletions(-) (limited to 'test') diff --git a/test/angular-mocks.js b/test/angular-mocks.js index ab3638b1..9c93f87f 100644 --- a/test/angular-mocks.js +++ b/test/angular-mocks.js @@ -1,12 +1,36 @@ function MockBrowser() { - this.url = "http://server"; - this.watches = []; + var self = this, expectations = {}, requests = []; + self.url = "http://server"; + self.watches = []; + + self.xhr = function(method, url, callback) { + var expect = expectations[method] || {}; + var response = expect[url]; + if (!response) { + throw "Unexepected request for mothod '" + method + "' and url '" + url + "'."; + } + requests.push(function(){ + callback(200, response); + }); + }; + self.xhr.expectations = expectations; + self.xhr.requests = requests; + self.xhr.expect = function(method, url) { + var expect = expectations[method] || (expectations[method] = {}); + return { + respond: function(response) { + expect[url] = response; + } + }; + }; + self.xhr.flush = function() { + while(requests.length) { + requests.pop()(); + } + }; } MockBrowser.prototype = { - xhr: function(method, url, callback) { - - }, getUrl: function(){ return this.url; diff --git a/test/directivesSpec.js b/test/directivesSpec.js index cfee86a0..06a3a2dd 100644 --- a/test/directivesSpec.js +++ b/test/directivesSpec.js @@ -13,7 +13,7 @@ describe("directives", function(){ }); afterEach(function() { - model.$element.remove(); + if (model && model.$element) model.$element.remove(); expect(size(jqCache)).toEqual(0); }); diff --git a/test/testabilityPatch.js b/test/testabilityPatch.js index b2ee5526..dc67ddec 100644 --- a/test/testabilityPatch.js +++ b/test/testabilityPatch.js @@ -5,14 +5,28 @@ function nakedExpect(obj) { return expect(angular.fromJson(angular.toJson(obj))); } -angularService('$browser', function(){ - return new MockBrowser(); -}); - function childNode(element, index) { return jqLite(element[0].childNodes[index]); } +extend(angular, { + 'element': jqLite, + 'compile': compile, + 'scope': createScope, + 'copy': copy, + 'extend': extend, + 'foreach': foreach, + 'noop':noop, + 'identity':identity, + 'isUndefined': isUndefined, + 'isDefined': isDefined, + 'isString': isString, + 'isFunction': isFunction, + 'isNumber': isNumber, + 'isArray': isArray +}); + + function sortedHtml(element) { var html = ""; (function toString(node) { diff --git a/test/widgetsSpec.js b/test/widgetsSpec.js index 63c18700..1669aa68 100644 --- a/test/widgetsSpec.js +++ b/test/widgetsSpec.js @@ -203,6 +203,11 @@ describe("input widget", function(){ describe('ng:include', function(){ it('should include on external file', function() { var element = jqLite(''); - var scope = compile(element).$init(); + var scope = compile(element); + scope.$browser.xhr.expect('GET', 'myUrl').respond('hello'); + scope.$init(); + expect(sortedHtml(element)).toEqual(''); + scope.$browser.xhr.flush(); + expect(sortedHtml(element)).toEqual('hello'); }); }); -- cgit v1.2.3 From 2107eafcde390eebbf59e829194626c488de9e29 Mon Sep 17 00:00:00 2001 From: Misko Hevery Date: Mon, 5 Apr 2010 20:53:33 -0700 Subject: added hover service --- test/BrowserTest.js | 2 +- test/angular-mocks.js | 5 ++++- 2 files changed, 5 insertions(+), 2 deletions(-) (limited to 'test') diff --git a/test/BrowserTest.js b/test/BrowserTest.js index 2e630172..5254840a 100644 --- a/test/BrowserTest.js +++ b/test/BrowserTest.js @@ -3,7 +3,7 @@ BrowserTest = TestCase('BrowserTest'); BrowserTest.prototype.testUrlWatcher = function () { expectAsserts(2); var location = {href:"http://server", hash:""}; - var watcher = new Browser(location); + var watcher = new Browser(location, {}); watcher.delay = 1; watcher.watchUrl(function(url){ assertEquals('http://getangular.test', url); diff --git a/test/angular-mocks.js b/test/angular-mocks.js index 9c93f87f..e10ad4e2 100644 --- a/test/angular-mocks.js +++ b/test/angular-mocks.js @@ -8,7 +8,7 @@ function MockBrowser() { var expect = expectations[method] || {}; var response = expect[url]; if (!response) { - throw "Unexepected request for mothod '" + method + "' and url '" + url + "'."; + throw "Unexepected request for method '" + method + "' and url '" + url + "'."; } requests.push(function(){ callback(200, response); @@ -32,6 +32,9 @@ function MockBrowser() { } MockBrowser.prototype = { + hover: function(onHover) { + }, + getUrl: function(){ return this.url; }, -- cgit v1.2.3 From e6460685869e16b5016de975fd0ba15a7e436951 Mon Sep 17 00:00:00 2001 From: Misko Hevery Date: Mon, 5 Apr 2010 21:26:52 -0700 Subject: added ng-controller directive --- test/directivesSpec.js | 15 +++++++++++++++ 1 file changed, 15 insertions(+) (limited to 'test') diff --git a/test/directivesSpec.js b/test/directivesSpec.js index 06a3a2dd..0a7e3c18 100644 --- a/test/directivesSpec.js +++ b/test/directivesSpec.js @@ -156,4 +156,19 @@ describe("directives", function(){ scope.$eval(); expect(element.css('display')).toEqual(''); }); + + it('should ng-controller', function(){ + window.Greeter = function(){ + this.greeting = 'hello'; + }; + window.Greeter.prototype = { + greet: function(name) { + return this.greeting + ' ' + name; + } + }; + var scope = compile('
                          '); + expect(scope.greeting).toEqual('hello'); + expect(scope.greet('misko')).toEqual('hello misko'); + delete window.Greeter; + }); }); -- cgit v1.2.3 From ee327a1f4f75f57c2a2c6166520c092d4942ffe0 Mon Sep 17 00:00:00 2001 From: Misko Hevery Date: Tue, 6 Apr 2010 14:04:08 -0700 Subject: few fixes to make tests pass with jquery --- test/BinderTest.js | 4 ++-- test/CompilerSpec.js | 4 ++-- test/directivesSpec.js | 8 ++++---- test/testabilityPatch.js | 6 ++++++ test/widgetsSpec.js | 6 +++--- 5 files changed, 17 insertions(+), 11 deletions(-) (limited to 'test') diff --git a/test/BinderTest.js b/test/BinderTest.js index 660ad78c..c792f10b 100644 --- a/test/BinderTest.js +++ b/test/BinderTest.js @@ -706,13 +706,13 @@ BinderTest.prototype.testItShouldSelectTheCorrectRadioBox = function() { var female = jqLite(c.node[0].childNodes[0]); var male = jqLite(c.node[0].childNodes[1]); - female.click(); + trigger(female, 'click'); assertEquals("female", c.scope.sex); assertEquals(true, female[0].checked); assertEquals(false, male[0].checked); assertEquals("female", female.val()); - male.click(); + trigger(male, 'click'); assertEquals("male", c.scope.sex); assertEquals(false, female[0].checked); assertEquals(true, male[0].checked); diff --git a/test/CompilerSpec.js b/test/CompilerSpec.js index 9922070f..b9529e6e 100644 --- a/test/CompilerSpec.js +++ b/test/CompilerSpec.js @@ -72,7 +72,7 @@ describe('compiler', function(){ var scope = compile(''); expect(log).toEqual("hello misko"); }); - + it('should allow creation of templates', function(){ directives.duplicate = function(expr, element){ element.replaceWith(document.createComment("marker")); @@ -97,7 +97,7 @@ describe('compiler', function(){ if (text == 'middle') { expect(textNode.text()).toEqual(text); parentNode.attr('hello', text); - textNode.text('replaced'); + textNode[0].textContent = 'replaced'; } }); var scope = compile('beforemiddleafter'); diff --git a/test/directivesSpec.js b/test/directivesSpec.js index 0a7e3c18..7504bf6b 100644 --- a/test/directivesSpec.js +++ b/test/directivesSpec.js @@ -142,19 +142,19 @@ describe("directives", function(){ it('should ng-show', function(){ var scope = compile('
                          '); scope.$eval(); - expect(element.css('display')).toEqual(''); + expect(isVisible(element)).toEqual(true); scope.$set('hide', true); scope.$eval(); - expect(element.css('display')).toEqual('none'); + expect(isVisible(element)).toEqual(false); }); it('should ng-hide', function(){ var scope = compile('
                          '); scope.$eval(); - expect(element.css('display')).toEqual('none'); + expect(isVisible(element)).toEqual(false); scope.$set('show', true); scope.$eval(); - expect(element.css('display')).toEqual(''); + expect(isVisible(element)).toEqual(true); }); it('should ng-controller', function(){ diff --git a/test/testabilityPatch.js b/test/testabilityPatch.js index dc67ddec..475784ad 100644 --- a/test/testabilityPatch.js +++ b/test/testabilityPatch.js @@ -27,6 +27,12 @@ extend(angular, { }); +function trigger(element, type) { + var evnt = document.createEvent('MouseEvent'); + evnt.initMouseEvent(type, true, true, window, 0, 0, 0, 0, 0, false, false, false, false, 0, null); + (element[0] || element).dispatchEvent(evnt); +} + function sortedHtml(element) { var html = ""; (function toString(node) { diff --git a/test/widgetsSpec.js b/test/widgetsSpec.js index 1669aa68..a68176e7 100644 --- a/test/widgetsSpec.js +++ b/test/widgetsSpec.js @@ -115,10 +115,10 @@ describe("input widget", function(){ it('should type="checkbox"', function(){ compile(''); expect(scope.checkbox).toEqual(true); - element.click(); + trigger(element, 'click'); expect(scope.checkbox).toEqual(false); expect(scope.action).toEqual(true); - element.click(); + trigger(element, 'click'); expect(scope.checkbox).toEqual(true); }); @@ -142,7 +142,7 @@ describe("input widget", function(){ expect(b.checked).toEqual(true); expect(scope.clicked).not.toBeDefined(); - jqLite(a).click(); + trigger(a, 'click'); expect(scope.chose).toEqual('A'); expect(scope.clicked).toEqual(1); }); -- cgit v1.2.3 From 0df93fd49c1687b2eddaa79faa1c0adbef82bf72 Mon Sep 17 00:00:00 2001 From: Misko Hevery Date: Wed, 7 Apr 2010 10:17:15 -0700 Subject: clean up, fixes for app --- test/directivesSpec.js | 7 +++++-- test/widgetsSpec.js | 33 ++++++++++++++++++++++++++++----- 2 files changed, 33 insertions(+), 7 deletions(-) (limited to 'test') diff --git a/test/directivesSpec.js b/test/directivesSpec.js index 0a7e3c18..74aa942b 100644 --- a/test/directivesSpec.js +++ b/test/directivesSpec.js @@ -162,13 +162,16 @@ describe("directives", function(){ this.greeting = 'hello'; }; window.Greeter.prototype = { + init: function(){ + this.suffix = '!'; + }, greet: function(name) { - return this.greeting + ' ' + name; + return this.greeting + ' ' + name + this.suffix; } }; var scope = compile('
                          '); expect(scope.greeting).toEqual('hello'); - expect(scope.greet('misko')).toEqual('hello misko'); + expect(scope.greet('misko')).toEqual('hello misko!'); delete window.Greeter; }); }); diff --git a/test/widgetsSpec.js b/test/widgetsSpec.js index 1669aa68..312a7f2b 100644 --- a/test/widgetsSpec.js +++ b/test/widgetsSpec.js @@ -189,14 +189,36 @@ describe("input widget", function(){ }); it('should switch on value change', function(){ - compile('
                          first
                          second
                          '); + compile('
                          first:{{name}}
                          second:{{name}}
                          '); expect(element.html()).toEqual(''); scope.select = 1; scope.$eval(); - expect(element.text()).toEqual('first'); + expect(element.text()).toEqual('first:'); + scope.name="shyam"; + scope.$eval(); + expect(element.text()).toEqual('first:shyam'); scope.select = 2; scope.$eval(); - expect(element.text()).toEqual('second'); + scope.name = 'misko'; + scope.$eval(); + expect(element.text()).toEqual('second:misko'); + }); +}); + +describe('ng:switch', function(){ + it("should match urls", function(){ + var scope = compile('
                          {{name}}
                          '); + scope.url = '/Book/Moby'; + scope.$init(); + expect(scope.$element.text()).toEqual('Moby'); + }); + + it('should call init on switch', function(){ + var scope = compile('
                          {{name}}
                          '); + scope.url = 'a'; + scope.$init(); + expect(scope.name).toEqual(undefined); + expect(scope.$element.text()).toEqual('works'); }); }); @@ -204,10 +226,11 @@ describe('ng:include', function(){ it('should include on external file', function() { var element = jqLite(''); var scope = compile(element); - scope.$browser.xhr.expect('GET', 'myUrl').respond('hello'); + scope.$browser.xhr.expect('GET', 'myUrl').respond('{{1+2}}'); scope.$init(); expect(sortedHtml(element)).toEqual(''); scope.$browser.xhr.flush(); - expect(sortedHtml(element)).toEqual('hello'); + expect(element.text()).toEqual('3'); }); }); + -- cgit v1.2.3 From 29309e0e5a5f5eafd0f948100417d63127d3332d Mon Sep 17 00:00:00 2001 From: Misko Hevery Date: Wed, 7 Apr 2010 10:35:54 -0700 Subject: jstd failing test case for cory --- test/widgetsSpec.js | 1 + 1 file changed, 1 insertion(+) (limited to 'test') diff --git a/test/widgetsSpec.js b/test/widgetsSpec.js index 93c7adda..88ca3f87 100644 --- a/test/widgetsSpec.js +++ b/test/widgetsSpec.js @@ -210,6 +210,7 @@ describe('ng:switch', function(){ var scope = compile('
                          {{name}}
                          '); scope.url = '/Book/Moby'; scope.$init(); +// jstestdriver.console.log('text'); expect(scope.$element.text()).toEqual('Moby'); }); -- cgit v1.2.3 From 6ea1ac7b05a4079bcda0356e095703d36ccdf6b3 Mon Sep 17 00:00:00 2001 From: Misko Hevery Date: Wed, 7 Apr 2010 14:13:10 -0700 Subject: added $invalidWidget service --- test/servicesSpec.js | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) (limited to 'test') diff --git a/test/servicesSpec.js b/test/servicesSpec.js index 43511853..b7dfe4c8 100644 --- a/test/servicesSpec.js +++ b/test/servicesSpec.js @@ -54,3 +54,23 @@ describe("services", function(){ }); }); + +describe("service $invalidWidgets", function(){ + var scope; + beforeEach(function(){ + scope = null; + }); + afterEach(function(){ + if (scope && scope.$element) + scope.$element.remove(); + }); + + it("should count number of invalid widgets", function(){ + var scope = compile('').$init(); + expect(scope.$invalidWidgets.length).toEqual(1); + scope.price = 123; + scope.$eval(); + expect(scope.$invalidWidgets.length).toEqual(0); + scope.$element.remove(); + }); +}); -- cgit v1.2.3 From a8aa5af413c068608aa28ef0d48cef1d5ad66485 Mon Sep 17 00:00:00 2001 From: Misko Hevery Date: Wed, 7 Apr 2010 16:36:33 -0700 Subject: fixed filter this --- test/FiltersTest.js | 13 +++++-------- 1 file changed, 5 insertions(+), 8 deletions(-) (limited to 'test') diff --git a/test/FiltersTest.js b/test/FiltersTest.js index 15a2ebc3..fd5c9976 100644 --- a/test/FiltersTest.js +++ b/test/FiltersTest.js @@ -13,17 +13,14 @@ FiltersTest.prototype.XtestCurrency = function(){ assertEquals(html.hasClass('ng-format-negative'), false); }; -FiltersTest.prototype.XtestFilterThisIsContext = function(){ - expectAsserts(2); - var scope = new Scope(); - Scope.expressionCache = {}; - scope.set('name', 'misko'); - var context = {$element:123}; +FiltersTest.prototype.testFilterThisIsContext = function(){ + expectAsserts(1); + var scope = createScope(); + scope.name = 'misko'; angular.filter.testFn = function () { - assertEquals('Context not equal', 123, this.$element); assertEquals('scope not equal', 'misko', this.name); }; - scope.eval("0|testFn", context); + scope.$eval("0|testFn"); delete angular.filter['testFn']; }; -- cgit v1.2.3 From e0ad7dfcd47196d0aa9271e84b2c4ac26cfda3f4 Mon Sep 17 00:00:00 2001 From: Misko Hevery Date: Wed, 7 Apr 2010 17:24:24 -0700 Subject: seperatio validation and exception handling --- test/BinderTest.js | 12 ++++++------ test/ScopeSpec.js | 2 +- test/ValidatorsTest.js | 2 +- test/directivesSpec.js | 2 +- test/widgetsSpec.js | 14 +++++++------- 5 files changed, 16 insertions(+), 16 deletions(-) (limited to 'test') diff --git a/test/BinderTest.js b/test/BinderTest.js index c792f10b..270fd1c7 100644 --- a/test/BinderTest.js +++ b/test/BinderTest.js @@ -299,20 +299,20 @@ BinderTest.prototype.testIfTextBindingThrowsErrorDecorateTheSpan = function(){ var span = childNode(doc, 0); assertTrue(span.hasClass('ng-exception')); assertEquals('ErrorMsg1', fromJson(span.text())); - assertEquals('"ErrorMsg1"', span.attr('ng-error')); + assertEquals('"ErrorMsg1"', span.attr('ng-exception')); a.scope.$set('error.throw', function(){throw "MyError";}); a.scope.$eval(); span = childNode(doc, 0); assertTrue(span.hasClass('ng-exception')); assertTrue(span.text(), span.text().match('MyError') !== null); - assertEquals('"MyError"', span.attr('ng-error')); + assertEquals('"MyError"', span.attr('ng-exception')); a.scope.$set('error.throw', function(){return "ok";}); a.scope.$eval(); assertFalse(span.hasClass('ng-exception')); assertEquals('ok', span.text()); - assertEquals(null, span.attr('ng-error')); + assertEquals(null, span.attr('ng-exception')); }; BinderTest.prototype.testIfAttrBindingThrowsErrorDecorateTheAttribute = function(){ @@ -322,14 +322,14 @@ BinderTest.prototype.testIfAttrBindingThrowsErrorDecorateTheAttribute = function a.scope.$set('error.throw', function(){throw "ErrorMsg";}); a.scope.$eval(); assertTrue('ng-exception', doc.hasClass('ng-exception')); - assertEquals('"ErrorMsg"', doc.attr('ng-error')); + assertEquals('"ErrorMsg"', doc.attr('ng-exception')); assertEquals('before "ErrorMsg" after', doc.attr('attr')); a.scope.$set('error.throw', function(){ return 'X';}); a.scope.$eval(); assertFalse('!ng-exception', doc.hasClass('ng-exception')); assertEquals('before X after', doc.attr('attr')); - assertEquals(null, doc.attr('ng-error')); + assertEquals(null, doc.attr('ng-exception')); }; @@ -474,7 +474,7 @@ BinderTest.prototype.testActionOnAHrefThrowsError = function(){ }; var input = c.node; input.click(); - assertEquals({a:"abc", b:2}, fromJson(input.attr('ng-error'))); + assertEquals({a:"abc", b:2}, fromJson(input.attr('ng-exception'))); assertTrue("should have an error class", input.hasClass('ng-exception')); // TODO: I think that exception should never get cleared so this portion of test makes no sense diff --git a/test/ScopeSpec.js b/test/ScopeSpec.js index 09f4d875..0665968b 100644 --- a/test/ScopeSpec.js +++ b/test/ScopeSpec.js @@ -78,7 +78,7 @@ describe('scope/model', function(){ var element = jqLite('
                          '); var scope = createScope(); scope.$tryEval('throw "myError"', element); - expect(element.attr('ng-error')).toEqual('"myError"'); // errors are jsonified + expect(element.attr('ng-exception')).toEqual('"myError"'); // errors are jsonified expect(element.hasClass('ng-exception')).toBeTruthy(); }); diff --git a/test/ValidatorsTest.js b/test/ValidatorsTest.js index d7da28cd..4dfe6892 100644 --- a/test/ValidatorsTest.js +++ b/test/ValidatorsTest.js @@ -118,7 +118,7 @@ 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-error')).toEqual("myError"); + expect(input.attr('ng-validation-error')).toEqual("myError"); scope.$element.remove(); }); diff --git a/test/directivesSpec.js b/test/directivesSpec.js index ea442d16..a92e98ee 100644 --- a/test/directivesSpec.js +++ b/test/directivesSpec.js @@ -88,7 +88,7 @@ describe("directives", function(){ it('should error on wrong parsing of ng-repeat', function(){ var scope = compile('
                          '); var log = ""; - log += element.attr('ng-error') + ';'; + log += element.attr('ng-exception') + ';'; log += element.hasClass('ng-exception') + ';'; expect(log).toEqual("\"Expected ng-repeat in form of 'item in collection' but got 'i dont parse'.\";true;"); }); diff --git a/test/widgetsSpec.js b/test/widgetsSpec.js index 88ca3f87..b48656f9 100644 --- a/test/widgetsSpec.js +++ b/test/widgetsSpec.js @@ -54,36 +54,36 @@ describe("input widget", function(){ it("should process ng-validation", function(){ compile(''); expect(element.hasClass('ng-validation-error')).toBeTruthy(); - expect(element.attr('ng-error')).toEqual('Not a number'); + expect(element.attr('ng-validation-error')).toEqual('Not a number'); scope.$set('price', '123'); scope.$eval(); expect(element.hasClass('ng-validation-error')).toBeFalsy(); - expect(element.attr('ng-error')).toBeFalsy(); + expect(element.attr('ng-validation-error')).toBeFalsy(); element.val('x'); element.trigger('keyup'); expect(element.hasClass('ng-validation-error')).toBeTruthy(); - expect(element.attr('ng-error')).toEqual('Not a number'); + expect(element.attr('ng-validation-error')).toEqual('Not a number'); }); it("should process ng-required", function(){ compile(''); expect(element.hasClass('ng-validation-error')).toBeTruthy(); - expect(element.attr('ng-error')).toEqual('Required'); + expect(element.attr('ng-validation-error')).toEqual('Required'); scope.$set('price', 'xxx'); scope.$eval(); expect(element.hasClass('ng-validation-error')).toBeFalsy(); - expect(element.attr('ng-error')).toBeFalsy(); + expect(element.attr('ng-validation-error')).toBeFalsy(); element.val(''); element.trigger('keyup'); expect(element.hasClass('ng-validation-error')).toBeTruthy(); - expect(element.attr('ng-error')).toEqual('Required'); + expect(element.attr('ng-validation-error')).toEqual('Required'); }); - it("should process ng-required", function() { + it("should process ng-required2", function() { compile(''); expect(scope.$get('name')).toEqual("Misko"); -- cgit v1.2.3 From c4ef1f2fdd73bdaeda879e596d3d96e4e68cb6fd Mon Sep 17 00:00:00 2001 From: Misko Hevery Date: Thu, 8 Apr 2010 13:43:40 -0700 Subject: tests failing jstd to show cory --- test/BinderTest.js | 155 ++-------------------------- test/ConsoleTest.js | 2 +- test/FileControllerTest.js | 98 ------------------ test/FiltersTest.js | 45 ++++---- test/ParserTest.js | 40 ------- test/ScenarioSpec.js | 37 +++---- test/ValidatorsTest.js | 26 ++--- test/angular-mocks.js | 6 ++ test/directivesSpec.js | 10 +- test/moveToAngularCom/FileControllerTest.js | 98 ++++++++++++++++++ test/moveToAngularCom/MiscTest.js | 4 +- test/moveToAngularCom/miscTest.js | 62 +++++++++++ test/servicesSpec.js | 4 +- test/testabilityPatch.js | 7 +- 14 files changed, 235 insertions(+), 359 deletions(-) delete mode 100644 test/FileControllerTest.js create mode 100644 test/moveToAngularCom/FileControllerTest.js create mode 100644 test/moveToAngularCom/miscTest.js (limited to 'test') diff --git a/test/BinderTest.js b/test/BinderTest.js index 270fd1c7..e72afa9f 100644 --- a/test/BinderTest.js +++ b/test/BinderTest.js @@ -174,34 +174,6 @@ BinderTest.prototype.testButtonElementActionExecutesInScope = function(){ assertTrue(savedCalled); }; -BinderTest.prototype.XtestParseEmptyAnchor = function(){ - var binder = this.compile("
                          ").binder; - var location = binder.location; - var anchor = binder.anchor; - location.url = "a#x=1"; - binder.parseAnchor(); - assertEquals(1, binder.anchor.x); - 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.XtestParseAnchor = function(){ - var binder = this.compile("
                          ").binder; - var location = binder.location; - location.url = "a#x=1"; - binder.parseAnchor(); - assertEquals(binder.anchor.x, "1"); - location.url = "a#a=b&c=%20&d"; - binder.parseAnchor(); - assertEquals(binder.anchor.a, 'b'); - assertEquals(binder.anchor.c, ' '); - assertTrue(binder.anchor.d !== null); - assertTrue(!binder.anchor.x); -}; - BinderTest.prototype.testRepeaterUpdateBindings = function(){ var a = this.compile('
                          '); var form = a.node; @@ -355,18 +327,6 @@ BinderTest.prototype.testNestedRepeater = function() { '
                          ', sortedHtml(a.node)); }; -BinderTest.prototype.XtestRadioButtonGetsPrefixed = function () { - var a = this.compile('
                          '); - a.scope.$set('model', ['a1', 'a2']); - a.scope.$eval(); - - assertEquals('
                          ' + - '<#comment>'+ - ''+ - '
                          ', - sortedHtml(a.node)); -}; - BinderTest.prototype.testHideBindingExpression = function() { var a = this.compile('
                          '); @@ -525,31 +485,6 @@ BinderTest.prototype.testShouldTemplateBindPreElements = function () { assertEquals('
                          Hello World!
                          ', sortedHtml(c.node)); }; -BinderTest.prototype.XtestDissableAutoSubmit = function() { - var c = this.compile('', null, {autoSubmit:true}); - assertEquals( - '', - sortedHtml(c.node)); - - c = this.compile('', null, {autoSubmit:false}); - assertEquals( - '', - sortedHtml(c.node)); -}; - -BinderTest.prototype.XtestSettingAnchorToNullOrUndefinedRemovesTheAnchorFromURL = function() { - var c = this.compile(''); - 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); - - c.binder.anchor.a = null; - c.binder.anchor.b = null; - c.binder.updateAnchor(); - assertEquals('http://server/#', c.binder.location.get()); -}; - BinderTest.prototype.testFillInOptionValueWhenMissing = function() { var c = this.compile( ''); @@ -570,9 +505,11 @@ BinderTest.prototype.testFillInOptionValueWhenMissing = function() { expect(optionC.text()).toEqual('C'); }; -BinderTest.prototype.XtestValidateForm = function() { - var c = this.compile('' + - '
                          '); +BinderTest.prototype.testValidateForm = function() { + var doc = jqLite(document.body); + doc.append('
                          ' + + '
                          '); + var c = this.compile(doc); var items = [{}, {}]; c.scope.$set("items", items); c.scope.$eval(); @@ -599,8 +536,9 @@ BinderTest.prototype.XtestValidateForm = function() { assertEquals(0, c.scope.$get("$invalidWidgets.length")); }; -BinderTest.prototype.XtestValidateOnlyVisibleItems = function(){ - var c = this.compile(''); +BinderTest.prototype.testValidateOnlyVisibleItems = function(){ + var c = this.compile('
                          '); + jqLite(document.body).append(c.node); c.scope.$set("show", true); c.scope.$eval(); assertEquals(2, c.scope.$get("$invalidWidgets.length")); @@ -629,62 +567,6 @@ BinderTest.prototype.testDeleteAttributeIfEvaluatesFalse = function() { assertChild(5, false); }; -BinderTest.prototype.XtestItShouldCallListenersWhenAnchorChanges = function() { - var log = ""; - var c = this.compile('
                          '); - c.scope.$set("count", 0); - c.scope.$watch("$anchor.counter", function(newValue, oldValue){ - log += oldValue + "->" + newValue + ";"; - }); - assertEquals(0, c.scope.$get("count")); - c.binder.location.url = "#counter=1"; - c.binder.onUrlChange(); - assertEquals(1, c.scope.$get("count")); - - c.binder.location.url = "#counter=1"; - c.binder.onUrlChange(); - assertEquals(1, c.scope.$get("count")); - - c.binder.location.url = "#counter=2"; - c.binder.onUrlChange(); - assertEquals(2, c.scope.$get("count")); - - c.binder.location.url = "#counter=2"; - c.binder.onUrlChange(); - assertEquals(2, c.scope.$get("count")); - - c.binder.location.url = "#"; - c.binder.onUrlChange(); - assertEquals("undefined->1;1->2;2->undefined;", log); - assertEquals(3, c.scope.$get("count")); -}; - -BinderTest.prototype.XtestParseQueryString = function(){ - var binder = new Binder(); - assertJsonEquals({"a":"1"}, binder.parseQueryString("a=1")); - assertJsonEquals({"a":"1", "b":"two"}, binder.parseQueryString("a=1&b=two")); - assertJsonEquals({}, binder.parseQueryString("")); - - assertJsonEquals({"a":"1", "b":""}, binder.parseQueryString("a=1&b=")); - assertJsonEquals({"a":"1", "b":""}, binder.parseQueryString("a=1&b")); - assertJsonEquals({"a":"1", "b":" 2 "}, binder.parseQueryString("a=1&b=%202%20")); - assertJsonEquals({"a a":"1", "b":"2"}, binder.parseQueryString("a%20a=1&b=2")); - -}; - -BinderTest.prototype.XtestSetBinderAnchorTriggersListeners = function(){ - expectAsserts(2); - var doc = this.compile("
                          "); - - doc.scope.$watch("$anchor.name", function(newVal, oldVal) { - assertEquals("new", newVal); - assertEquals(undefined, oldVal); - }); - - doc.$anchor.name = "new"; - doc.binder.onUrlChange("http://base#name=new"); -}; - BinderTest.prototype.testItShouldDisplayErrorWhenActionIsSyntacticlyIncorect = function(){ var c = this.compile('
                          ' + '' + @@ -768,9 +650,9 @@ BinderTest.prototype.testItBindHiddenInputFields = function(){ assertEquals("abc", x.scope.$get("myName")); }; -BinderTest.prototype.xtestItShouldRenderMultiRootHtmlInBinding = function() { +BinderTest.prototype.XtestItShouldRenderMultiRootHtmlInBinding = function() { var x = this.compile('
                          before {{a|html}}after
                          '); - x.scope.$set("a", "acd"); + x.scope.a = "acd"; x.scope.$eval(); assertEquals( '
                          before acdafter
                          ', @@ -790,20 +672,3 @@ BinderTest.prototype.testItShouldUseFormaterForText = function() { assertEquals('1, 2, 3', input[0].value); }; -BinderTest.prototype.XtestWriteAnchor = function(){ - var binder = this.compile("
                          ").binder; - binder.location.set('a'); - binder.anchor.a = 'b'; - binder.anchor.c = ' '; - binder.anchor.d = true; - binder.updateAnchor(); - assertEquals(binder.location.get(), "a#a=b&c=%20&d"); -}; - -BinderTest.prototype.XtestWriteAnchorAsPartOfTheUpdateView = function(){ - var binder = this.compile("
                          ").binder; - binder.location.set('a'); - binder.anchor.a = 'b'; - binder.updateView(); - assertEquals(binder.location.get(), "a#a=b"); -}; diff --git a/test/ConsoleTest.js b/test/ConsoleTest.js index 9adb50f8..3e09267b 100644 --- a/test/ConsoleTest.js +++ b/test/ConsoleTest.js @@ -7,6 +7,6 @@ ConsoleTest.prototype.XtestConsoleWrite = function(){ assertEquals(jqLite(consoleNode).text(), 'Hello world'); assertEquals(jqLite(consoleNode.childNodes[0])[0].className, 'error'); consoleLog("error",["Bye"]); - assertEquals($(consoleNode).text(), 'Hello worldBye'); + assertEquals(jqLite(consoleNode).text(), 'Hello worldBye'); consoleNode = null; }; diff --git a/test/FileControllerTest.js b/test/FileControllerTest.js deleted file mode 100644 index 75c924e6..00000000 --- a/test/FileControllerTest.js +++ /dev/null @@ -1,98 +0,0 @@ -FileControllerTest = TestCase('FileControllerTest'); - -FileControllerTest.prototype.XtestOnSelectUpdateView = function(){ - var view = jQuery(''); - var swf = {}; - var controller = new FileController(view, null, swf); - swf.uploadFile = function(path){}; - controller.select('A', 9, '9 bytes'); - assertEquals(view.find('a').text(), "A"); - assertEquals(view.find('span').text(), "9 bytes"); -}; - -FileControllerTest.prototype.XtestUpdateModelView = function(){ - var view = FileController.template(''); - var input = $(''); - var controller; - var scope = new Scope({value:{}, $binder:{updateView:function(){ - controller.updateView(scope); - }}}); - view.data('scope', scope); - controller = new FileController(view, 'value.input', null, "http://server_base"); - var value = '{"text":"A", "size":123, "id":"890"}'; - controller.uploadCompleteData(value); - controller.updateView(scope); - assertEquals(scope.get('value.input.text'), 'A'); - assertEquals(scope.get('value.input.size'), 123); - assertEquals(scope.get('value.input.id'), '890'); - assertEquals(scope.get('value.input.url'), 'http://server_base/_attachments/890/A'); - assertEquals(view.find('a').text(), "A"); - assertEquals(view.find('a').attr('href'), "http://server_base/_attachments/890/A"); - assertEquals(view.find('span').text(), "123 bytes"); -}; - -FileControllerTest.prototype.XtestFileUpload = function(){ - expectAsserts(1); - var swf = {}; - var controller = new FileController(null, null, swf, "http://server_base"); - swf.uploadFile = function(path){ - assertEquals("http://server_base/_attachments", path); - }; - controller.name = "Name"; - controller.upload(); -}; - -FileControllerTest.prototype.XtestFileUploadNoFileIsNoop = function(){ - expectAsserts(0); - var swf = {uploadFile:function(path){ - fail(); - }}; - var controller = new FileController(null, swf); - controller.upload("basePath", null); -}; - -FileControllerTest.prototype.XtestRemoveAttachment = function(){ - var doc = FileController.template(); - var input = $(''); - var scope = new Scope(); - input.data('scope', scope); - var controller = new FileController(doc, 'file', null, null); - controller.updateView(scope); - assertEquals(false, doc.find('input').attr('checked')); - - scope.set('file', {url:'url', size:123}); - controller.updateView(scope); - assertEquals(true, doc.find('input').attr('checked')); - - doc.find('input').attr('checked', false); - controller.updateModel(scope); - assertNull(scope.get('file')); - - doc.find('input').attr('checked', true); - controller.updateModel(scope); - assertEquals('url', scope.get('file.url')); - assertEquals(123, scope.get('file.size')); -}; - -FileControllerTest.prototype.XtestShouldEmptyOutOnUndefined = function () { - var view = FileController.template('hello'); - var controller = new FileController(view, 'abc', null, null); - - var scope = new Scope(); - scope.set('abc', {text: 'myname', url: 'myurl', size: 1234}); - - controller.updateView(scope); - assertEquals("myurl", view.find('a').attr('href')); - assertEquals("myname", view.find('a').text()); - assertEquals(true, view.find('input').is(':checked')); - assertEquals("1.2 KB", view.find('span').text()); - - scope.set('abc', undefined); - controller.updateView(scope); - assertEquals("myurl", view.find('a').attr('href')); - assertEquals("myname", view.find('a').text()); - assertEquals(false, view.find('input').is(':checked')); - assertEquals("1.2 KB", view.find('span').text()); -}; - - diff --git a/test/FiltersTest.js b/test/FiltersTest.js index fd5c9976..504dad02 100644 --- a/test/FiltersTest.js +++ b/test/FiltersTest.js @@ -1,8 +1,8 @@ FiltersTest = TestCase('FiltersTest'); -FiltersTest.prototype.XtestCurrency = function(){ - var html = $(''); - var context = {$element:html[0]}; +FiltersTest.prototype.testCurrency = function(){ + var html = jqLite(''); + var context = {$element:html}; var currency = bind(context, angular.filter.currency); assertEquals(currency(0), '$0.00'); @@ -24,8 +24,8 @@ FiltersTest.prototype.testFilterThisIsContext = function(){ delete angular.filter['testFn']; }; -FiltersTest.prototype.XtestNumberFormat = function(){ - var context = {jqElement:$('')}; +FiltersTest.prototype.testNumberFormat = function(){ + var context = {jqElement:jqLite('')}; var number = bind(context, angular.filter.number); assertEquals('0', number(0, 0)); @@ -37,11 +37,11 @@ FiltersTest.prototype.XtestNumberFormat = function(){ assertEquals("", number(1/0)); }; -FiltersTest.prototype.XtestJson = function () { - assertEquals(toJson({a:"b"}, true), angular.filter.json({a:"b"})); +FiltersTest.prototype.testJson = function () { + assertEquals(toJson({a:"b"}, true), angular.filter.json.call({$element:jqLite('
                          ')}, {a:"b"})); }; -FiltersTest.prototype.XtestPackageTracking = function () { +FiltersTest.prototype.testPackageTracking = function () { var assert = function(title, trackingNo) { var val = angular.filter.trackPackage(trackingNo, title); assertNotNull("Did Not Match: " + trackingNo, val); @@ -69,7 +69,7 @@ FiltersTest.prototype.XtestPackageTracking = function () { assert('USPS', '9102801438635051633253'); }; -FiltersTest.prototype.XtestLink = function() { +FiltersTest.prototype.testLink = function() { var assert = function(text, url, obj){ var val = angular.filter.link(obj); assertEquals(angular.filter.Meta.TAG, val.TAG); @@ -80,14 +80,7 @@ FiltersTest.prototype.XtestLink = function() { assert("a@b.com", "mailto:a@b.com", "a@b.com"); }; -FiltersTest.prototype.XtestBytes = function(){ - var controller = new FileController(); - assertEquals(angular.filter.bytes(123), '123 bytes'); - assertEquals(angular.filter.bytes(1234), '1.2 KB'); - assertEquals(angular.filter.bytes(1234567), '1.1 MB'); -}; - -FiltersTest.prototype.XtestImage = function(){ +FiltersTest.prototype.testImage = function(){ assertEquals(null, angular.filter.image()); assertEquals(null, angular.filter.image({})); assertEquals(null, angular.filter.image("")); @@ -100,7 +93,7 @@ FiltersTest.prototype.XtestImage = function(){ angular.filter.image({url:"abc"}, 10, 20).html); }; -FiltersTest.prototype.XtestQRcode = function() { +FiltersTest.prototype.testQRcode = function() { assertEquals( '', angular.filter.qrcode('Hello world').html); @@ -109,17 +102,17 @@ FiltersTest.prototype.XtestQRcode = function() { angular.filter.qrcode('http://server?a&b=c', 100).html); }; -FiltersTest.prototype.XtestLowercase = function() { +FiltersTest.prototype.testLowercase = function() { assertEquals('abc', angular.filter.lowercase('AbC')); assertEquals(null, angular.filter.lowercase(null)); }; -FiltersTest.prototype.XtestUppercase = function() { +FiltersTest.prototype.testUppercase = function() { assertEquals('ABC', angular.filter.uppercase('AbC')); assertEquals(null, angular.filter.uppercase(null)); }; -FiltersTest.prototype.XtestLineCount = function() { +FiltersTest.prototype.testLineCount = function() { assertEquals(1, angular.filter.linecount(null)); assertEquals(1, angular.filter.linecount('')); assertEquals(1, angular.filter.linecount('a')); @@ -127,30 +120,30 @@ FiltersTest.prototype.XtestLineCount = function() { assertEquals(3, angular.filter.linecount('a\nb\nc')); }; -FiltersTest.prototype.XtestIf = function() { +FiltersTest.prototype.testIf = function() { assertEquals('A', angular.filter['if']('A', true)); assertEquals(undefined, angular.filter['if']('A', false)); }; -FiltersTest.prototype.XtestUnless = function() { +FiltersTest.prototype.testUnless = function() { assertEquals('A', angular.filter.unless('A', false)); assertEquals(undefined, angular.filter.unless('A', true)); }; -FiltersTest.prototype.XtestGoogleChartApiEncode = function() { +FiltersTest.prototype.testGoogleChartApiEncode = function() { assertEquals( '', angular.filter.googleChartApi.encode({cht:"qr", chl:"Hello world"}).html); }; -FiltersTest.prototype.XtestHtml = function() { +FiltersTest.prototype.testHtml = function() { assertEquals( "acd", angular.filter.html("acd").html); assertTrue(angular.filter.html("acd") instanceof angular.filter.Meta); }; -FiltersTest.prototype.XtestLinky = function() { +FiltersTest.prototype.testLinky = function() { var linky = angular.filter.linky; assertEquals( '
                          http://ab ' + diff --git a/test/ParserTest.js b/test/ParserTest.js index 6170dd4a..7ba65f18 100644 --- a/test/ParserTest.js +++ b/test/ParserTest.js @@ -404,36 +404,6 @@ ParserTest.prototype.testMissingThrowsError = function() { } }; -ParserTest.prototype.XtestItShouldParseOnChangeIntoHashSet = function () { - var scope = createScope({count:0}); - scope.watch("$anchor.a:count=count+1;$anchor.a:count=count+20;b:count=count+300"); - - scope.watchListeners["$anchor.a"].listeners[0](); - assertEquals(1, scope.$get("count")); - scope.watchListeners["$anchor.a"].listeners[1](); - assertEquals(21, scope.$get("count")); - scope.watchListeners["b"].listeners[0]({scope:scope}); - assertEquals(321, scope.$get("count")); -}; -ParserTest.prototype.XtestItShouldParseOnChangeBlockIntoHashSet = function () { - var scope = createScope({count:0}); - var listeners = {a:[], b:[]}; - scope.watch("a:{count=count+1;count=count+20;};b:count=count+300", - function(n, fn){listeners[n].push(fn);}); - - assertEquals(1, scope.watchListeners.a.listeners.length); - assertEquals(1, scope.watchListeners.b.listeners.length); - scope.watchListeners["a"].listeners[0](); - assertEquals(21, scope.$get("count")); - scope.watchListeners["b"].listeners[0](); - assertEquals(321, scope.$get("count")); -}; - -ParserTest.prototype.XtestItShouldParseEmptyOnChangeAsNoop = function () { - var scope = createScope(); - scope.watch("", function(){fail();}); -}; - ParserTest.prototype.testItShouldCreateClosureFunctionWithNoArguments = function () { var scope = createScope(); var fn = scope.$eval("{:value}"); @@ -462,16 +432,6 @@ ParserTest.prototype.testItShouldHaveDefaultArugument = function(){ assertEquals(4, fn(2)); }; -ParserTest.prototype.XtestReturnFunctionsAreNotBound = function(){ - var scope = createScope(); - scope.entity("Group", new DataStore()); - var Group = scope.$get("Group"); - assertEquals("eval Group", "function", typeof scope.$eval("Group")); - assertEquals("direct Group", "function", typeof Group); - assertEquals("eval Group.all", "function", typeof scope.$eval("Group.query")); - assertEquals("direct Group.all", "function", typeof Group.query); -}; - ParserTest.prototype.testDoubleNegationBug = function (){ var scope = createScope(); assertEquals(true, scope.$eval('true')); diff --git a/test/ScenarioSpec.js b/test/ScenarioSpec.js index ff3a55b5..9afe8e95 100644 --- a/test/ScenarioSpec.js +++ b/test/ScenarioSpec.js @@ -19,46 +19,33 @@ describe("ScenarioSpec: Compilation", function(){ }); describe("ScenarioSpec: Scope", function(){ - xit("should have set, get, eval, $init, updateView methods", function(){ + it("should have set, get, eval, $init, updateView methods", function(){ var scope = compile('
                          {{a}}
                          ').$init(); scope.$eval("$invalidWidgets.push({})"); expect(scope.$set("a", 2)).toEqual(2); expect(scope.$get("a")).toEqual(2); expect(scope.$eval("a=3")).toEqual(3); scope.$eval(); - expect(scope.$eval("$invalidWidgets")).toEqual([]); expect(jqLite(scope.$element).text()).toEqual('3'); }); - xit("should have $ objects", function(){ - var scope = compile('
                          ', {a:"b"}); - expect(scope.$get('$anchor')).toBeDefined(); + it("should have $ objects", function(){ + var scope = compile('
                          ', {$config: {a:"b"}}); + expect(scope.$get('$location')).toBeDefined(); expect(scope.$get('$eval')).toBeDefined(); expect(scope.$get('$config')).toBeDefined(); expect(scope.$get('$config.a')).toEqual("b"); - expect(scope.$get('$datastore')).toBeDefined(); }); }); -xdescribe("ScenarioSpec: configuration", function(){ +describe("ScenarioSpec: configuration", function(){ it("should take location object", function(){ - var url = "http://server/#book=moby"; - var onUrlChange; - var location = { - listen:function(fn){onUrlChange=fn;}, - set:function(u){url = u;}, - get:function(){return url;} - }; - var scope = compile("
                          {{$anchor}}
                          ", {location:location}); - var $anchor = scope.$get('$anchor'); - expect($anchor.book).toBeUndefined(); - expect(onUrlChange).toBeUndefined(); - scope.$init(); - expect($anchor.book).toEqual('moby'); - expect(onUrlChange).toBeDefined(); - - url = "http://server/#book=none"; - onUrlChange(); - expect($anchor.book).toEqual('none'); + var url = "http://server/#?book=moby"; + var scope = compile("
                          {{$location}}
                          "); + var $location = scope.$get('$location'); + expect($location.hashSearch.book).toBeUndefined(); + scope.$browser.setUrl(url); + scope.$browser.fireUrlWatchers(); + expect($location.hashSearch.book).toEqual('moby'); }); }); diff --git a/test/ValidatorsTest.js b/test/ValidatorsTest.js index 4dfe6892..2b2f6753 100644 --- a/test/ValidatorsTest.js +++ b/test/ValidatorsTest.js @@ -1,20 +1,20 @@ ValidatorTest = TestCase('ValidatorTest'); -ValidatorTest.prototype.XtestItShouldHaveThisSet = function() { - expectAsserts(5); - var self; +ValidatorTest.prototype.testItShouldHaveThisSet = function() { + var validator = {}; angular.validator.myValidator = function(first, last){ - assertEquals('misko', first); - assertEquals('hevery', last); - self = this; + validator.first = first; + validator.last = last; + validator._this = this; }; - var c = compile(''); - c.scope.$set('name', 'misko'); - c.scope.$set('state', 'abc'); - c.scope.$eval(); - assertEquals('abc', self.state); - assertEquals('misko', self.name); - assertEquals('name', self.$element.name); + var scope = compile(''); + scope.name = 'misko'; + scope.$init(); + assertEquals('misko', validator.first); + assertEquals('hevery', validator.last); + assertSame(scope, validator._this); + delete angular.validator.myValidator; + scope.$element.remove(); }; ValidatorTest.prototype.testRegexp = function() { diff --git a/test/angular-mocks.js b/test/angular-mocks.js index e10ad4e2..88552aad 100644 --- a/test/angular-mocks.js +++ b/test/angular-mocks.js @@ -45,6 +45,12 @@ MockBrowser.prototype = { watchUrl: function(fn) { this.watches.push(fn); + }, + + fireUrlWatchers: function() { + for(var i=0; i
                          '); + jqLite(document.body).append(scope.$element); scope.$eval(); - expect(isVisible(element)).toEqual(true); + expect(isVisible(scope.$element)).toEqual(true); scope.$set('hide', true); scope.$eval(); - expect(isVisible(element)).toEqual(false); + expect(isVisible(scope.$element)).toEqual(false); }); it('should ng-hide', function(){ var scope = compile('
                          '); + jqLite(document.body).append(scope.$element); scope.$eval(); - expect(isVisible(element)).toEqual(false); + expect(isVisible(scope.$element)).toEqual(false); scope.$set('show', true); scope.$eval(); - expect(isVisible(element)).toEqual(true); + expect(isVisible(scope.$element)).toEqual(true); }); it('should ng-controller', function(){ diff --git a/test/moveToAngularCom/FileControllerTest.js b/test/moveToAngularCom/FileControllerTest.js new file mode 100644 index 00000000..75c924e6 --- /dev/null +++ b/test/moveToAngularCom/FileControllerTest.js @@ -0,0 +1,98 @@ +FileControllerTest = TestCase('FileControllerTest'); + +FileControllerTest.prototype.XtestOnSelectUpdateView = function(){ + var view = jQuery(''); + var swf = {}; + var controller = new FileController(view, null, swf); + swf.uploadFile = function(path){}; + controller.select('A', 9, '9 bytes'); + assertEquals(view.find('a').text(), "A"); + assertEquals(view.find('span').text(), "9 bytes"); +}; + +FileControllerTest.prototype.XtestUpdateModelView = function(){ + var view = FileController.template(''); + var input = $(''); + var controller; + var scope = new Scope({value:{}, $binder:{updateView:function(){ + controller.updateView(scope); + }}}); + view.data('scope', scope); + controller = new FileController(view, 'value.input', null, "http://server_base"); + var value = '{"text":"A", "size":123, "id":"890"}'; + controller.uploadCompleteData(value); + controller.updateView(scope); + assertEquals(scope.get('value.input.text'), 'A'); + assertEquals(scope.get('value.input.size'), 123); + assertEquals(scope.get('value.input.id'), '890'); + assertEquals(scope.get('value.input.url'), 'http://server_base/_attachments/890/A'); + assertEquals(view.find('a').text(), "A"); + assertEquals(view.find('a').attr('href'), "http://server_base/_attachments/890/A"); + assertEquals(view.find('span').text(), "123 bytes"); +}; + +FileControllerTest.prototype.XtestFileUpload = function(){ + expectAsserts(1); + var swf = {}; + var controller = new FileController(null, null, swf, "http://server_base"); + swf.uploadFile = function(path){ + assertEquals("http://server_base/_attachments", path); + }; + controller.name = "Name"; + controller.upload(); +}; + +FileControllerTest.prototype.XtestFileUploadNoFileIsNoop = function(){ + expectAsserts(0); + var swf = {uploadFile:function(path){ + fail(); + }}; + var controller = new FileController(null, swf); + controller.upload("basePath", null); +}; + +FileControllerTest.prototype.XtestRemoveAttachment = function(){ + var doc = FileController.template(); + var input = $(''); + var scope = new Scope(); + input.data('scope', scope); + var controller = new FileController(doc, 'file', null, null); + controller.updateView(scope); + assertEquals(false, doc.find('input').attr('checked')); + + scope.set('file', {url:'url', size:123}); + controller.updateView(scope); + assertEquals(true, doc.find('input').attr('checked')); + + doc.find('input').attr('checked', false); + controller.updateModel(scope); + assertNull(scope.get('file')); + + doc.find('input').attr('checked', true); + controller.updateModel(scope); + assertEquals('url', scope.get('file.url')); + assertEquals(123, scope.get('file.size')); +}; + +FileControllerTest.prototype.XtestShouldEmptyOutOnUndefined = function () { + var view = FileController.template('hello'); + var controller = new FileController(view, 'abc', null, null); + + var scope = new Scope(); + scope.set('abc', {text: 'myname', url: 'myurl', size: 1234}); + + controller.updateView(scope); + assertEquals("myurl", view.find('a').attr('href')); + assertEquals("myname", view.find('a').text()); + assertEquals(true, view.find('input').is(':checked')); + assertEquals("1.2 KB", view.find('span').text()); + + scope.set('abc', undefined); + controller.updateView(scope); + assertEquals("myurl", view.find('a').attr('href')); + assertEquals("myname", view.find('a').text()); + assertEquals(false, view.find('input').is(':checked')); + assertEquals("1.2 KB", view.find('span').text()); +}; + + diff --git a/test/moveToAngularCom/MiscTest.js b/test/moveToAngularCom/MiscTest.js index db6e8563..aa0e1186 100644 --- a/test/moveToAngularCom/MiscTest.js +++ b/test/moveToAngularCom/MiscTest.js @@ -7,13 +7,13 @@ BinderTest.prototype.testExpandEntityTagWithName = function(){ assertEquals("friend", c.scope.$get("friend.$$anchor")); }; -BinderTest.prototype.XtestExpandSubmitButtonToAction = function(){ +BinderTest.prototype.testExpandSubmitButtonToAction = function(){ var html = this.compileToHtml(''); assertTrue(html, html.indexOf('ng-action="$save()"') > 0 ); assertTrue(html, html.indexOf('ng-bind-attr="{"disabled":"{{$invalidWidgets}}"}"') > 0 ); }; -BinderTest.prototype.XtestReplaceFileUploadWithSwf = function(){ +BinderTest.prototype.testReplaceFileUploadWithSwf = function(){ expectAsserts(1); var form = jQuery("body").append('
                          '); form.data('scope', new Scope()); diff --git a/test/moveToAngularCom/miscTest.js b/test/moveToAngularCom/miscTest.js new file mode 100644 index 00000000..a986f259 --- /dev/null +++ b/test/moveToAngularCom/miscTest.js @@ -0,0 +1,62 @@ +ParserTest.prototype.testReturnFunctionsAreNotBound = function(){ + var scope = createScope(); + scope.entity("Group", new DataStore()); + var Group = scope.$get("Group"); + assertEquals("eval Group", "function", typeof scope.$eval("Group")); + assertEquals("direct Group", "function", typeof Group); + assertEquals("eval Group.all", "function", typeof scope.$eval("Group.query")); + assertEquals("direct Group.all", "function", typeof Group.query); +}; + +ParserTest.prototype.XtestItShouldParseEmptyOnChangeAsNoop = function () { + var scope = createScope(); + scope.watch("", function(){fail();}); +}; + + +ParserTest.prototype.XtestItShouldParseOnChangeIntoHashSet = function () { + var scope = createScope({count:0}); + scope.watch("$anchor.a:count=count+1;$anchor.a:count=count+20;b:count=count+300"); + + scope.watchListeners["$anchor.a"].listeners[0](); + assertEquals(1, scope.$get("count")); + scope.watchListeners["$anchor.a"].listeners[1](); + assertEquals(21, scope.$get("count")); + scope.watchListeners["b"].listeners[0]({scope:scope}); + assertEquals(321, scope.$get("count")); +}; +ParserTest.prototype.XtestItShouldParseOnChangeBlockIntoHashSet = function () { + var scope = createScope({count:0}); + var listeners = {a:[], b:[]}; + scope.watch("a:{count=count+1;count=count+20;};b:count=count+300", + function(n, fn){listeners[n].push(fn);}); + + assertEquals(1, scope.watchListeners.a.listeners.length); + assertEquals(1, scope.watchListeners.b.listeners.length); + scope.watchListeners["a"].listeners[0](); + assertEquals(21, scope.$get("count")); + scope.watchListeners["b"].listeners[0](); + assertEquals(321, scope.$get("count")); +}; + +FiltersTest.prototype.testBytes = function(){ + var controller = new FileController(); + assertEquals(angular.filter.bytes(123), '123 bytes'); + assertEquals(angular.filter.bytes(1234), '1.2 KB'); + assertEquals(angular.filter.bytes(1234567), '1.1 MB'); +}; + +BinderTest.prototype.testDissableAutoSubmit = function() { + var c = this.compile('', null, {autoSubmit:true}); + assertEquals( + '', + sortedHtml(c.node)); + + c = this.compile('', null, {autoSubmit:false}); + assertEquals( + '', + sortedHtml(c.node)); +}; + + + diff --git a/test/servicesSpec.js b/test/servicesSpec.js index b7dfe4c8..a3841c2f 100644 --- a/test/servicesSpec.js +++ b/test/servicesSpec.js @@ -66,7 +66,9 @@ describe("service $invalidWidgets", function(){ }); it("should count number of invalid widgets", function(){ - var scope = compile('').$init(); + var doc = jqLite(window.document.body); + doc.append(''); + var scope = compile(doc).$init(); expect(scope.$invalidWidgets.length).toEqual(1); scope.price = 123; scope.$eval(); diff --git a/test/testabilityPatch.js b/test/testabilityPatch.js index 475784ad..5955e9a6 100644 --- a/test/testabilityPatch.js +++ b/test/testabilityPatch.js @@ -74,19 +74,18 @@ function sortedHtml(element) { return html; } -function isVisible(node) { +function isCssVisible(node) { var display = node.css('display'); if (display == 'block') display = ""; return display != 'none'; } function assertHidden(node) { - var display = node.css('display'); - assertFalse("Node should be hidden but vas visible: " + sortedHtml(node), isVisible(node)); + assertFalse("Node should be hidden but vas visible: " + sortedHtml(node), isCssVisible(node)); } function assertVisible(node) { - assertTrue("Node should be visible but vas hidden: " + sortedHtml(node), isVisible(node)); + assertTrue("Node should be visible but vas hidden: " + sortedHtml(node), isCssVisible(node)); } function assertJsonEquals(expected, actual) { -- cgit v1.2.3 From 41a5c408c242269bf31bc0b774c7304fdf7c2f1c Mon Sep 17 00:00:00 2001 From: Misko Hevery Date: Thu, 8 Apr 2010 15:05:05 -0700 Subject: tests pass jstd has issues --- test/BinderTest.js | 6 ++---- test/directivesSpec.js | 10 ++++------ test/servicesSpec.js | 4 +--- 3 files changed, 7 insertions(+), 13 deletions(-) (limited to 'test') diff --git a/test/BinderTest.js b/test/BinderTest.js index e72afa9f..ec0c1cb4 100644 --- a/test/BinderTest.js +++ b/test/BinderTest.js @@ -506,10 +506,8 @@ BinderTest.prototype.testFillInOptionValueWhenMissing = function() { }; BinderTest.prototype.testValidateForm = function() { - var doc = jqLite(document.body); - doc.append('
                          ' + + var c = this.compile('
                          ' + '
                          '); - var c = this.compile(doc); var items = [{}, {}]; c.scope.$set("items", items); c.scope.$eval(); @@ -545,7 +543,7 @@ BinderTest.prototype.testValidateOnlyVisibleItems = function(){ c.scope.$set("show", false); c.scope.$eval(); - assertEquals(1, c.scope.$get("$invalidWidgets.length")); + assertEquals(1, c.scope.$invalidWidgets.visible()); }; BinderTest.prototype.testDeleteAttributeIfEvaluatesFalse = function() { diff --git a/test/directivesSpec.js b/test/directivesSpec.js index 0af61997..1def9584 100644 --- a/test/directivesSpec.js +++ b/test/directivesSpec.js @@ -141,22 +141,20 @@ describe("directives", function(){ it('should ng-show', function(){ var scope = compile('
                          '); - jqLite(document.body).append(scope.$element); scope.$eval(); - expect(isVisible(scope.$element)).toEqual(true); + expect(isCssVisible(scope.$element)).toEqual(true); scope.$set('hide', true); scope.$eval(); - expect(isVisible(scope.$element)).toEqual(false); + expect(isCssVisible(scope.$element)).toEqual(false); }); it('should ng-hide', function(){ var scope = compile('
                          '); - jqLite(document.body).append(scope.$element); scope.$eval(); - expect(isVisible(scope.$element)).toEqual(false); + expect(isCssVisible(scope.$element)).toEqual(false); scope.$set('show', true); scope.$eval(); - expect(isVisible(scope.$element)).toEqual(true); + expect(isCssVisible(scope.$element)).toEqual(true); }); it('should ng-controller', function(){ diff --git a/test/servicesSpec.js b/test/servicesSpec.js index a3841c2f..b7dfe4c8 100644 --- a/test/servicesSpec.js +++ b/test/servicesSpec.js @@ -66,9 +66,7 @@ describe("service $invalidWidgets", function(){ }); it("should count number of invalid widgets", function(){ - var doc = jqLite(window.document.body); - doc.append(''); - var scope = compile(doc).$init(); + var scope = compile('').$init(); expect(scope.$invalidWidgets.length).toEqual(1); scope.price = 123; scope.$eval(); -- cgit v1.2.3 From 843bd355d25ebf2369aec79f98cb6704d38497e9 Mon Sep 17 00:00:00 2001 From: Misko Hevery Date: Fri, 9 Apr 2010 16:20:15 -0700 Subject: various bug fixes --- test/ApiTest.js | 4 ++++ test/ValidatorsTest.js | 2 +- test/markupSpec.js | 5 +++++ test/servicesSpec.js | 14 ++++++++++++++ test/widgetsSpec.js | 9 +++++++-- 5 files changed, 31 insertions(+), 3 deletions(-) (limited to 'test') diff --git a/test/ApiTest.js b/test/ApiTest.js index 19860822..5d85987b 100644 --- a/test/ApiTest.js +++ b/test/ApiTest.js @@ -250,3 +250,7 @@ ApiTest.prototype.testStringFromUTC = function(){ assertEquals("2003-09-10T13:02:03Z", angular.Date.toString(date)); assertEquals("str", angular.String.toDate("str")); }; + +ApiTest.prototype.testObjectShouldHaveExtend = function(){ + assertEquals(angular.Object.extend, extend); +}; diff --git a/test/ValidatorsTest.js b/test/ValidatorsTest.js index 2b2f6753..17c67d38 100644 --- a/test/ValidatorsTest.js +++ b/test/ValidatorsTest.js @@ -12,7 +12,7 @@ ValidatorTest.prototype.testItShouldHaveThisSet = function() { scope.$init(); assertEquals('misko', validator.first); assertEquals('hevery', validator.last); - assertSame(scope, validator._this); + assertSame(scope, validator._this.__proto__); delete angular.validator.myValidator; scope.$element.remove(); }; diff --git a/test/markupSpec.js b/test/markupSpec.js index e416b8ea..a1112490 100644 --- a/test/markupSpec.js +++ b/test/markupSpec.js @@ -47,6 +47,11 @@ describe("markups", function(){ expect(element.html()).toEqual(''); }); + it('should process all bindings when we have leading space', function(){ + compile('
                          {{a}}
                          {{b}}
                          '); + expect(sortedHtml(scope.$element)).toEqual('

                          '); + }); + }); diff --git a/test/servicesSpec.js b/test/servicesSpec.js index b7dfe4c8..91cc1f0e 100644 --- a/test/servicesSpec.js +++ b/test/servicesSpec.js @@ -42,6 +42,20 @@ describe("services", function(){ 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){ diff --git a/test/widgetsSpec.js b/test/widgetsSpec.js index b48656f9..c6158c37 100644 --- a/test/widgetsSpec.js +++ b/test/widgetsSpec.js @@ -207,13 +207,18 @@ describe("input widget", function(){ describe('ng:switch', function(){ it("should match urls", function(){ - var scope = compile('
                          {{name}}
                          '); + var scope = compile('
                          {{params.name}}
                          '); scope.url = '/Book/Moby'; scope.$init(); -// jstestdriver.console.log('text'); expect(scope.$element.text()).toEqual('Moby'); }); + it("should match sandwich ids", function(){ + var scope = {}; + var match = angular.widget['NG:SWITCH'].route.call(scope, '/a/123/b', '/a/:id'); + expect(match).toBeFalsy(); + }); + it('should call init on switch', function(){ var scope = compile('
                          {{name}}
                          '); scope.url = 'a'; -- cgit v1.2.3 From 2637d4e90c8a43436d21a4b9e790b00ae461c438 Mon Sep 17 00:00:00 2001 From: Misko Hevery Date: Mon, 12 Apr 2010 14:28:15 -0700 Subject: removed Meta and allowed binding of HTML --- test/FiltersTest.js | 42 ++++++++++++++++++------------------------ test/directivesSpec.js | 7 +++++++ test/testabilityPatch.js | 16 ++++++++++++++-- 3 files changed, 39 insertions(+), 26 deletions(-) (limited to 'test') diff --git a/test/FiltersTest.js b/test/FiltersTest.js index 504dad02..ad38b94d 100644 --- a/test/FiltersTest.js +++ b/test/FiltersTest.js @@ -45,11 +45,8 @@ FiltersTest.prototype.testPackageTracking = function () { var assert = function(title, trackingNo) { var val = angular.filter.trackPackage(trackingNo, title); assertNotNull("Did Not Match: " + trackingNo, val); - assertEquals(angular.filter.Meta.TAG, val.TAG); - assertEquals(title + ": " + trim(trackingNo), val.text); - assertNotNull(val.url); - assertEquals(trim(trackingNo), val.trackingNo); - assertEquals('' + val.text + '', val.html); + assertEquals(title + ": " + trim(trackingNo), val.text()); + assertNotNull(val.attr('href')); }; assert('UPS', ' 1Z 999 999 99 9999 999 9 '); assert('UPS', '1ZW5w5220379084747'); @@ -72,8 +69,7 @@ FiltersTest.prototype.testPackageTracking = function () { FiltersTest.prototype.testLink = function() { var assert = function(text, url, obj){ var val = angular.filter.link(obj); - assertEquals(angular.filter.Meta.TAG, val.TAG); - assertEquals('' + text + '', val.html); + assertEquals('' + text + '', sortedHtml(val)); }; assert("url", "url", "url"); assert("hello", "url", {text:"hello", url:"url"}); @@ -84,22 +80,22 @@ FiltersTest.prototype.testImage = function(){ assertEquals(null, angular.filter.image()); assertEquals(null, angular.filter.image({})); assertEquals(null, angular.filter.image("")); - assertEquals('', angular.filter.image({url:"abc"}).html); + assertEquals('', sortedHtml(angular.filter.image({url:"abc"}))); assertEquals( - '', - angular.filter.image({url:"abc"}, 10).html); + '', + sortedHtml(angular.filter.image({url:"abc"}, 10))); assertEquals( - '', - angular.filter.image({url:"abc"}, 10, 20).html); + '', + sortedHtml(angular.filter.image({url:"abc"}, 10, 20))); }; FiltersTest.prototype.testQRcode = function() { assertEquals( - '', - angular.filter.qrcode('Hello world').html); + '', + sortedHtml(angular.filter.qrcode('Hello world'))); assertEquals( - '', - angular.filter.qrcode('http://server?a&b=c', 100).html); + '', + sortedHtml(angular.filter.qrcode('http://server?a&b=c', 100))); }; FiltersTest.prototype.testLowercase = function() { @@ -132,15 +128,14 @@ FiltersTest.prototype.testUnless = function() { FiltersTest.prototype.testGoogleChartApiEncode = function() { assertEquals( - '', - angular.filter.googleChartApi.encode({cht:"qr", chl:"Hello world"}).html); + '', + sortedHtml(angular.filter.googleChartApi.encode({cht:"qr", chl:"Hello world"}))); }; FiltersTest.prototype.testHtml = function() { - assertEquals( - "acd", - angular.filter.html("acd").html); - assertTrue(angular.filter.html("acd") instanceof angular.filter.Meta); + var div = jqLite('
                          '); + div.append(angular.filter.html("acd")); + assertEquals("acd", div.html()); }; FiltersTest.prototype.testLinky = function() { @@ -150,8 +145,7 @@ FiltersTest.prototype.testLinky = function() { '(http://a) ' + '<http://a> \n ' + 'http://1.2/v:~-123. c', - linky("http://ab (http://a) \n http://1.2/v:~-123. c").html); - assertTrue(linky("a") instanceof angular.filter.Meta); + sortedHtml(linky("http://ab (http://a) \n http://1.2/v:~-123. c"))); assertEquals(undefined, linky(undefined)); }; diff --git a/test/directivesSpec.js b/test/directivesSpec.js index 1def9584..300602fe 100644 --- a/test/directivesSpec.js +++ b/test/directivesSpec.js @@ -37,6 +37,13 @@ describe("directives", function(){ expect(element.text()).toEqual('misko'); }); + it('should ng-bind html', function() { + var scope = compile('
                          '); + scope.html = '
                          hello
                          '; + scope.$eval(); + expect(element.html()).toEqual('
                          hello
                          '); + }); + it('should ng-bind-template', function() { var scope = compile('
                          '); scope.$set('name', 'Misko'); diff --git a/test/testabilityPatch.js b/test/testabilityPatch.js index 5955e9a6..dfa14b97 100644 --- a/test/testabilityPatch.js +++ b/test/testabilityPatch.js @@ -35,7 +35,7 @@ function trigger(element, type) { function sortedHtml(element) { var html = ""; - (function toString(node) { + foreach(element, function toString(node) { if (node.nodeName == "#text") { html += escapeHtml(node.nodeValue); } else { @@ -56,6 +56,7 @@ function sortedHtml(element) { attr.name !='size' && attr.name !='start' && attr.name !='tabIndex' && + attr.name !='style' && attr.name.substr(0, 6) != 'jQuery') { // in IE we need to check for all of these. attrs.push(' ' + attr.name + '="' + attr.value + '"'); @@ -63,6 +64,17 @@ function sortedHtml(element) { } attrs.sort(); html += attrs.join(''); + var style = []; + for(var name in node.style) { + var value = node.style[name]; + if (value && isString(value) && (name != 1*name) && (name != 'cssText')) { + style.push(name + ': ' + value + ';'); + } + } + style.sort(); + if (style.length) { + html += ' style="' + style.join(' ') + '"'; + } html += '>'; var children = node.childNodes; for(var j=0; j'; } - })(element[0]); + }); return html; } -- cgit v1.2.3 From 713307b6505a56ca7b5423b36e297070d756ff15 Mon Sep 17 00:00:00 2001 From: Misko Hevery Date: Mon, 12 Apr 2010 16:24:28 -0700 Subject: added ng-eval-order attribute --- test/ApiTest.js | 2 +- test/CompilerSpec.js | 2 +- test/ValidatorsTest.js | 8 ++++++-- test/directivesSpec.js | 14 ++++++++++++++ 4 files changed, 22 insertions(+), 4 deletions(-) (limited to 'test') diff --git a/test/ApiTest.js b/test/ApiTest.js index 5d85987b..4035cdbb 100644 --- a/test/ApiTest.js +++ b/test/ApiTest.js @@ -252,5 +252,5 @@ ApiTest.prototype.testStringFromUTC = function(){ }; ApiTest.prototype.testObjectShouldHaveExtend = function(){ - assertEquals(angular.Object.extend, extend); + assertEquals({a:1, b:2}, angular.Object.extend({a:1}, {b:2})); }; diff --git a/test/CompilerSpec.js b/test/CompilerSpec.js index b9529e6e..fe61c520 100644 --- a/test/CompilerSpec.js +++ b/test/CompilerSpec.js @@ -72,7 +72,7 @@ describe('compiler', function(){ var scope = compile(''); expect(log).toEqual("hello misko"); }); - + it('should allow creation of templates', function(){ directives.duplicate = function(expr, element){ element.replaceWith(document.createComment("marker")); diff --git a/test/ValidatorsTest.js b/test/ValidatorsTest.js index 17c67d38..49416ae4 100644 --- a/test/ValidatorsTest.js +++ b/test/ValidatorsTest.js @@ -88,11 +88,15 @@ describe('Validator:asynchronous', function(){ var value, fn; beforeEach(function(){ + var invalidWidgets = []; + invalidWidgets.markInvalid = function(element){ + invalidWidgets.push(element); + }; value = null; fn = null; self = { $element:jqLite(''), - $invalidWidgets:[], + $invalidWidgets:invalidWidgets, $updateView: noop }; }); @@ -125,7 +129,7 @@ describe('Validator:asynchronous', function(){ 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).toEqual([self.$element]); + expect(self.$invalidWidgets[0][0]).toEqual(self.$element[0]); var spy = jasmine.createSpy(); asynchronous.call(self, "kai", spy); diff --git a/test/directivesSpec.js b/test/directivesSpec.js index 300602fe..76a12616 100644 --- a/test/directivesSpec.js +++ b/test/directivesSpec.js @@ -181,4 +181,18 @@ describe("directives", function(){ expect(scope.greet('misko')).toEqual('hello misko!'); delete window.Greeter; }); + + it('should eval things according to ng-eval-order', function(){ + var scope = compile( + '
                          ' + + '{{log = log + \'e\'}}' + + '' + + '{{log = log + \'b\'}}' + + '' + + '' + + '' + + '
                          '); + expect(scope.log).toEqual('abcde'); + }); + }); -- cgit v1.2.3 From 7c49b255483c0381c23de41d108800f93ebc1979 Mon Sep 17 00:00:00 2001 From: Misko Hevery Date: Mon, 12 Apr 2010 19:05:39 -0700 Subject: $invalid widget clear on switch change --- test/servicesSpec.js | 13 ++++++++++++- test/widgetsSpec.js | 5 +++++ 2 files changed, 17 insertions(+), 1 deletion(-) (limited to 'test') diff --git a/test/servicesSpec.js b/test/servicesSpec.js index 91cc1f0e..618d9a15 100644 --- a/test/servicesSpec.js +++ b/test/servicesSpec.js @@ -80,11 +80,22 @@ describe("service $invalidWidgets", function(){ }); it("should count number of invalid widgets", function(){ - var scope = compile('').$init(); + var scope = compile('').$init(); expect(scope.$invalidWidgets.length).toEqual(1); scope.price = 123; scope.$eval(); expect(scope.$invalidWidgets.length).toEqual(0); scope.$element.remove(); + scope.price = 'abc'; + scope.$eval(); + expect(scope.$invalidWidgets.length).toEqual(1); + + jqLite(document.body).append(scope.$element); + scope.$invalidWidgets.clearOrphans(); + expect(scope.$invalidWidgets.length).toEqual(1); + + jqLite(document.body).html(''); + scope.$invalidWidgets.clearOrphans(); + expect(scope.$invalidWidgets.length).toEqual(0); }); }); diff --git a/test/widgetsSpec.js b/test/widgetsSpec.js index c6158c37..c64f03ca 100644 --- a/test/widgetsSpec.js +++ b/test/widgetsSpec.js @@ -221,10 +221,15 @@ describe('ng:switch', function(){ it('should call init on switch', function(){ var scope = compile('
                          {{name}}
                          '); + var cleared = false; scope.url = 'a'; + scope.$invalidWidgets = {clearOrphans: function(){ + cleared = true; + }}; scope.$init(); expect(scope.name).toEqual(undefined); expect(scope.$element.text()).toEqual('works'); + expect(cleared).toEqual(true); }); }); -- cgit v1.2.3 From e8ac57caae624dca6509ce1619ae254ffd1fe0f4 Mon Sep 17 00:00:00 2001 From: Misko Hevery Date: Mon, 12 Apr 2010 19:16:30 -0700 Subject: tests pass on chrome --- test/testabilityPatch.js | 16 ++++++---------- 1 file changed, 6 insertions(+), 10 deletions(-) (limited to 'test') diff --git a/test/testabilityPatch.js b/test/testabilityPatch.js index dfa14b97..0c08e39e 100644 --- a/test/testabilityPatch.js +++ b/test/testabilityPatch.js @@ -64,16 +64,12 @@ function sortedHtml(element) { } attrs.sort(); html += attrs.join(''); - var style = []; - for(var name in node.style) { - var value = node.style[name]; - if (value && isString(value) && (name != 1*name) && (name != 'cssText')) { - style.push(name + ': ' + value + ';'); - } - } - style.sort(); - if (style.length) { - html += ' style="' + style.join(' ') + '"'; + if (node.style && node.style.cssText) { + var style = node.style.cssText.split('; '); + style.sort(); + if (style[0] == '') + style.shift(); + html += ' style="' + style.join('; ') + ';"'; } html += '>'; var children = node.childNodes; -- cgit v1.2.3 From cd03fe92a5dbd2aba516b64fc8067c5fba1e4a81 Mon Sep 17 00:00:00 2001 From: Misko Hevery Date: Tue, 13 Apr 2010 14:25:12 -0700 Subject: checkbox widget fix --- test/widgetsSpec.js | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) (limited to 'test') diff --git a/test/widgetsSpec.js b/test/widgetsSpec.js index c64f03ca..04b8b1ec 100644 --- a/test/widgetsSpec.js +++ b/test/widgetsSpec.js @@ -6,9 +6,10 @@ describe("input widget", function(){ scope = null; element = null; var compiler = new Compiler(angularTextMarkup, angularAttrMarkup, angularDirective, angularWidget); - compile = function(html) { + compile = function(html, before) { element = jqLite(html); scope = compiler.compile(element)(element); + (before||noop)(); scope.$init(); }; }); @@ -51,6 +52,14 @@ describe("input widget", function(){ expect(scope.$get('list')).toEqual(['1', '2', '3']); }); + it("should process ng-format for booleans", function(){ + compile('', function(){ + scope.name = false; + }); + expect(scope.name).toEqual(false); + expect(scope.$element[0].checked).toEqual(false); + }); + it("should process ng-validation", function(){ compile(''); expect(element.hasClass('ng-validation-error')).toBeTruthy(); -- cgit v1.2.3 From 70e401ef100614295fc808e32f0142f07c315461 Mon Sep 17 00:00:00 2001 From: Misko Hevery Date: Thu, 15 Apr 2010 14:17:33 -0700 Subject: added $route service --- test/ScopeSpec.js | 10 ++++++++++ test/angular-mocks.js | 23 +++++++++++++++++++++++ test/servicesSpec.js | 38 ++++++++++++++++++++++++++++++++++++++ test/testabilityPatch.js | 27 ++++++++++++++++++++++----- 4 files changed, 93 insertions(+), 5 deletions(-) (limited to 'test') diff --git a/test/ScopeSpec.js b/test/ScopeSpec.js index 0665968b..23638b27 100644 --- a/test/ScopeSpec.js +++ b/test/ScopeSpec.js @@ -82,6 +82,16 @@ describe('scope/model', function(){ expect(element.hasClass('ng-exception')).toBeTruthy(); }); + it('should report error on $excetionHandler', function(){ + var element = jqLite('
                          '); + var scope = createScope(); + scope.$exceptionHandler = function(e){ + this.error = e; + }; + scope.$tryEval('throw "myError"'); + expect(scope.error).toEqual("myError"); + }); + // $onEval it("should eval using priority", function(){ diff --git a/test/angular-mocks.js b/test/angular-mocks.js index 88552aad..3e272313 100644 --- a/test/angular-mocks.js +++ b/test/angular-mocks.js @@ -1,3 +1,26 @@ +/** + * The MIT License + * + * Copyright (c) 2010 Adam Abrons and Misko Hevery http://getangular.com + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + * THE SOFTWARE. + */ function MockBrowser() { var self = this, expectations = {}, requests = []; diff --git a/test/servicesSpec.js b/test/servicesSpec.js index 618d9a15..715a232e 100644 --- a/test/servicesSpec.js +++ b/test/servicesSpec.js @@ -99,3 +99,41 @@ describe("service $invalidWidgets", function(){ expect(scope.$invalidWidgets.length).toEqual(0); }); }); + +describe("service $route", function(){ + it('should route and fire change event', function(){ + var log = ''; + function BookChapter() { + this.log = ''; + } + BookChapter.prototype.init = function(){ + log += 'init();'; + }; + var scope = compile('
                          ').$init(); + scope.$route.when('/Book/:book/Chapter/:chapter', {controller: BookChapter, template:'Chapter.html'}); + scope.$route.when('/Blank'); + scope.$route.onChange(function(){ + log += 'onChange();'; + }); + scope.$location.parse('http://server#/Book/Moby/Chapter/Intro?p=123'); + scope.$eval(); + expect(log).toEqual('onChange();init();'); + expect(scope.$route.current.params).toEqual({book:'Moby', chapter:'Intro', p:'123'}); + expect(scope.$route.current.scope.log).toEqual(''); + var lastId = scope.$route.current.scope.$id; + + log = ''; + scope.$location.parse('http://server#/Blank?ignore'); + scope.$eval(); + expect(log).toEqual('onChange();'); + expect(scope.$route.current.params).toEqual({ignore:true}); + expect(scope.$route.current.scope.$id).not.toEqual(lastId); + + log = ''; + scope.$location.parse('http://server#/NONE'); + scope.$eval(); + expect(log).toEqual('onChange();'); + expect(scope.$route.current).toEqual(null); + + }); +}); diff --git a/test/testabilityPatch.js b/test/testabilityPatch.js index 0c08e39e..89e7d9ea 100644 --- a/test/testabilityPatch.js +++ b/test/testabilityPatch.js @@ -64,12 +64,29 @@ function sortedHtml(element) { } attrs.sort(); html += attrs.join(''); - if (node.style && node.style.cssText) { - var style = node.style.cssText.split('; '); + if (node.style) { + var style = []; + if (node.style.cssText) { + foreach(node.style.cssText.split(';'), function(value){ + value = trim(value); + if (value) { + style.push(value); + } + }); + } + for(var css in node.style){ + var value = node.style[css]; + if (isString(value) && isString(css) && css != 'cssText' && value && (1*css != css)) { + var text = css + ': ' + node.style[css]; + if (indexOf(style, text) == -1) { + style.push(text); + } + } + }; style.sort(); - if (style[0] == '') - style.shift(); - html += ' style="' + style.join('; ') + ';"'; + if (style.length) { + html += ' style="' + style.join('; ') + ';"'; + } } html += '>'; var children = node.childNodes; -- cgit v1.2.3 From deb86fe357a901889bc4289087f0b9e69cb8a302 Mon Sep 17 00:00:00 2001 From: Misko Hevery Date: Fri, 16 Apr 2010 14:01:29 -0700 Subject: lots of small fixes --- test/ValidatorsTest.js | 34 +++++++++++---- test/directivesSpec.js | 16 +++++++ test/servicesSpec.js | 113 ++++++++++++++++++++++++++++--------------------- test/widgetsSpec.js | 22 ++++++++-- 4 files changed, 124 insertions(+), 61 deletions(-) (limited to 'test') 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(''), $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(''); + 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('
                          '); + 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('
                          '); 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('
                          '); + 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(''); + expect(element.hasClass('ng-validation-error')).toBeFalsy(); + expect(element.attr('ng-validation-error')).toBeFalsy(); + }); + + it("should ignore readonly widgets", function(){ + compile(''); + expect(element.hasClass('ng-validation-error')).toBeFalsy(); + expect(element.attr('ng-validation-error')).toBeFalsy(); + }); + it("should process ng-required", function(){ compile(''); 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(''); + var element = jqLite(''); 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(''); scope.$browser.xhr.flush(); - expect(element.text()).toEqual('3'); + expect(element.text()).toEqual('misko'); }); }); -- cgit v1.2.3 From 6470b48ce022885551e83c9f5fd8a90fbc6ff80e Mon Sep 17 00:00:00 2001 From: Misko Hevery Date: Fri, 16 Apr 2010 17:03:06 -0700 Subject: validation issues fixed --- test/widgetsSpec.js | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) (limited to 'test') diff --git a/test/widgetsSpec.js b/test/widgetsSpec.js index ae6a17df..ecc00d05 100644 --- a/test/widgetsSpec.js +++ b/test/widgetsSpec.js @@ -60,7 +60,7 @@ describe("input widget", function(){ expect(scope.$element[0].checked).toEqual(false); }); - it("should process ng-validation", function(){ + it("should process ng-validate", function(){ compile(''); expect(element.hasClass('ng-validation-error')).toBeTruthy(); expect(element.attr('ng-validation-error')).toEqual('Not a number'); @@ -76,6 +76,19 @@ describe("input widget", function(){ expect(element.attr('ng-validation-error')).toEqual('Not a number'); }); + it("should not call validator if undefinde/empty", function(){ + var lastValue = "NOT_CALLED"; + angularValidator.myValidator = function(value){lastValue = value;}; + compile(''); + expect(lastValue).toEqual("NOT_CALLED"); + + scope.url = 'http://server'; + scope.$eval(); + expect(lastValue).toEqual("http://server"); + + delete angularValidator.myValidator; + }); + it("should ignore disabled widgets", function(){ compile(''); expect(element.hasClass('ng-validation-error')).toBeFalsy(); -- cgit v1.2.3 From 8e1b670d5b262f70fdbf4c4b01d3109d54a12ac5 Mon Sep 17 00:00:00 2001 From: Misko Hevery Date: Mon, 19 Apr 2010 12:54:39 -0700 Subject: fix ie bug with .text() on jqlite --- test/moveToAngularCom/miscTest.js | 79 +++++++++++++-------------------------- 1 file changed, 26 insertions(+), 53 deletions(-) (limited to 'test') diff --git a/test/moveToAngularCom/miscTest.js b/test/moveToAngularCom/miscTest.js index a986f259..aa0e1186 100644 --- a/test/moveToAngularCom/miscTest.js +++ b/test/moveToAngularCom/miscTest.js @@ -1,62 +1,35 @@ -ParserTest.prototype.testReturnFunctionsAreNotBound = function(){ - var scope = createScope(); - scope.entity("Group", new DataStore()); - var Group = scope.$get("Group"); - assertEquals("eval Group", "function", typeof scope.$eval("Group")); - assertEquals("direct Group", "function", typeof Group); - assertEquals("eval Group.all", "function", typeof scope.$eval("Group.query")); - assertEquals("direct Group.all", "function", typeof Group.query); -}; - -ParserTest.prototype.XtestItShouldParseEmptyOnChangeAsNoop = function () { - var scope = createScope(); - scope.watch("", function(){fail();}); -}; - - -ParserTest.prototype.XtestItShouldParseOnChangeIntoHashSet = function () { - var scope = createScope({count:0}); - scope.watch("$anchor.a:count=count+1;$anchor.a:count=count+20;b:count=count+300"); - - scope.watchListeners["$anchor.a"].listeners[0](); - assertEquals(1, scope.$get("count")); - scope.watchListeners["$anchor.a"].listeners[1](); - assertEquals(21, scope.$get("count")); - scope.watchListeners["b"].listeners[0]({scope:scope}); - assertEquals(321, scope.$get("count")); +BinderTest.prototype.testExpandEntityTagWithName = function(){ + var c = this.compile('
                          '); + assertEquals( + '
                          ', + sortedHtml(c.node)); + assertEquals("Person", c.scope.$get("friend.$entity")); + assertEquals("friend", c.scope.$get("friend.$$anchor")); }; -ParserTest.prototype.XtestItShouldParseOnChangeBlockIntoHashSet = function () { - var scope = createScope({count:0}); - var listeners = {a:[], b:[]}; - scope.watch("a:{count=count+1;count=count+20;};b:count=count+300", - function(n, fn){listeners[n].push(fn);}); - assertEquals(1, scope.watchListeners.a.listeners.length); - assertEquals(1, scope.watchListeners.b.listeners.length); - scope.watchListeners["a"].listeners[0](); - assertEquals(21, scope.$get("count")); - scope.watchListeners["b"].listeners[0](); - assertEquals(321, scope.$get("count")); +BinderTest.prototype.testExpandSubmitButtonToAction = function(){ + var html = this.compileToHtml(''); + assertTrue(html, html.indexOf('ng-action="$save()"') > 0 ); + assertTrue(html, html.indexOf('ng-bind-attr="{"disabled":"{{$invalidWidgets}}"}"') > 0 ); }; -FiltersTest.prototype.testBytes = function(){ - var controller = new FileController(); - assertEquals(angular.filter.bytes(123), '123 bytes'); - assertEquals(angular.filter.bytes(1234), '1.2 KB'); - assertEquals(angular.filter.bytes(1234567), '1.1 MB'); +BinderTest.prototype.testReplaceFileUploadWithSwf = function(){ + expectAsserts(1); + var form = jQuery("body").append('
                          '); + form.data('scope', new Scope()); + var factory = {}; + var binder = new Binder(form.get(0), factory, new MockLocation()); + factory.createController = function(node){ + assertEquals(node.attr('type'), 'file'); + return {updateModel:function(){}}; + }; + binder.compile(); + jQuery("#testTag").remove(); }; -BinderTest.prototype.testDissableAutoSubmit = function() { - var c = this.compile('', null, {autoSubmit:true}); - assertEquals( - '', - sortedHtml(c.node)); - - c = this.compile('', null, {autoSubmit:false}); +BinderTest.prototype.testExpandEntityTagWithDefaults = function(){ assertEquals( - '', - sortedHtml(c.node)); + '
                          ', + this.compileToHtml('
                          ')); }; - - -- cgit v1.2.3 From 618a2b423d826ab8366a6907e71a4af0e76d6211 Mon Sep 17 00:00:00 2001 From: Misko Hevery Date: Mon, 19 Apr 2010 14:36:41 -0700 Subject: ie fixes --- test/testabilityPatch.js | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) (limited to 'test') diff --git a/test/testabilityPatch.js b/test/testabilityPatch.js index 89e7d9ea..055c2f77 100644 --- a/test/testabilityPatch.js +++ b/test/testabilityPatch.js @@ -77,8 +77,9 @@ function sortedHtml(element) { for(var css in node.style){ var value = node.style[css]; if (isString(value) && isString(css) && css != 'cssText' && value && (1*css != css)) { - var text = css + ': ' + node.style[css]; - if (indexOf(style, text) == -1) { + var value = node.style[css]; + var text = css + ': ' + value; + if (value != 'false' && indexOf(style, text) == -1) { style.push(text); } } -- cgit v1.2.3 From 9f9bdcf3d16de651f85ccfe9e079cb57baca9eb7 Mon Sep 17 00:00:00 2001 From: Misko Hevery Date: Mon, 19 Apr 2010 14:41:36 -0700 Subject: lint --- test/testabilityPatch.js | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) (limited to 'test') diff --git a/test/testabilityPatch.js b/test/testabilityPatch.js index 055c2f77..21443fa5 100644 --- a/test/testabilityPatch.js +++ b/test/testabilityPatch.js @@ -77,13 +77,12 @@ function sortedHtml(element) { for(var css in node.style){ var value = node.style[css]; if (isString(value) && isString(css) && css != 'cssText' && value && (1*css != css)) { - var value = node.style[css]; var text = css + ': ' + value; if (value != 'false' && indexOf(style, text) == -1) { style.push(text); } } - }; + } style.sort(); if (style.length) { html += ' style="' + style.join('; ') + ';"'; -- cgit v1.2.3 From 259c2bba4bf1fc4f0d4cf5bcda4ffef0fb5a615a Mon Sep 17 00:00:00 2001 From: Misko Hevery Date: Mon, 19 Apr 2010 17:02:46 -0700 Subject: last failing ie test remaining --- test/BinderTest.js | 12 +++++++----- test/testabilityPatch.js | 6 ------ 2 files changed, 7 insertions(+), 11 deletions(-) (limited to 'test') diff --git a/test/BinderTest.js b/test/BinderTest.js index ec0c1cb4..50e1683a 100644 --- a/test/BinderTest.js +++ b/test/BinderTest.js @@ -16,7 +16,9 @@ BinderTest.prototype.setUp = function(){ }; BinderTest.prototype.tearDown = function(){ - if (this.element && this.element.dealoc) this.element.dealoc(); + if (this.element && this.element.dealoc) { + this.element.dealoc(); + } }; @@ -100,8 +102,8 @@ BinderTest.prototype.testBindingSpaceConfusesIE = function() { ''+nbsp+'', this.compileToHtml("{{a}} {{b}}")); assertEquals( - ''+nbsp+'x '+nbsp+'(', - this.compileToHtml("{{A}} x {{B}} ({{C}})")); + ''+nbsp+'x '+nbsp+'()', + this.compileToHtml("{{A}} x {{B}} ({{C}})")); }; BinderTest.prototype.testBindingOfAttributes = function() { @@ -586,13 +588,13 @@ BinderTest.prototype.testItShouldSelectTheCorrectRadioBox = function() { var female = jqLite(c.node[0].childNodes[0]); var male = jqLite(c.node[0].childNodes[1]); - trigger(female, 'click'); + female.trigger('click'); assertEquals("female", c.scope.sex); assertEquals(true, female[0].checked); assertEquals(false, male[0].checked); assertEquals("female", female.val()); - trigger(male, 'click'); + male.trigger('click'); assertEquals("male", c.scope.sex); assertEquals(false, female[0].checked); assertEquals(true, male[0].checked); diff --git a/test/testabilityPatch.js b/test/testabilityPatch.js index 21443fa5..17341575 100644 --- a/test/testabilityPatch.js +++ b/test/testabilityPatch.js @@ -27,12 +27,6 @@ extend(angular, { }); -function trigger(element, type) { - var evnt = document.createEvent('MouseEvent'); - evnt.initMouseEvent(type, true, true, window, 0, 0, 0, 0, 0, false, false, false, false, 0, null); - (element[0] || element).dispatchEvent(evnt); -} - function sortedHtml(element) { var html = ""; foreach(element, function toString(node) { -- cgit v1.2.3 From 22d93e0a3bc2a6dc0f64c63c68bc8f8489ea9068 Mon Sep 17 00:00:00 2001 From: Misko Hevery Date: Tue, 20 Apr 2010 18:14:13 -0700 Subject: fixes to enable ie --- test/BinderTest.js | 14 +++++++------- test/CompilerSpec.js | 9 +++++---- test/directivesSpec.js | 2 +- test/widgetsSpec.js | 12 ++++++------ 4 files changed, 19 insertions(+), 18 deletions(-) (limited to 'test') diff --git a/test/BinderTest.js b/test/BinderTest.js index 50e1683a..31b2698d 100644 --- a/test/BinderTest.js +++ b/test/BinderTest.js @@ -151,7 +151,7 @@ BinderTest.prototype.testInputTypeButtonActionExecutesInScope = function(){ c.scope.$set("person.save", function(){ savedCalled = true; }); - c.node.click(); + c.node.trigger('click'); assertTrue(savedCalled); }; @@ -162,7 +162,7 @@ BinderTest.prototype.testInputTypeButtonActionExecutesInScope2 = function(){ log += 'click;'; }); expect(log).toEqual(''); - c.node.click(); + c.node.trigger('click'); expect(log).toEqual('click;'); }; @@ -172,7 +172,7 @@ BinderTest.prototype.testButtonElementActionExecutesInScope = function(){ c.scope.$set("person.save", function(){ savedCalled = true; }); - c.node.click(); + c.node.trigger('click'); assertTrue(savedCalled); }; @@ -435,13 +435,13 @@ BinderTest.prototype.testActionOnAHrefThrowsError = function(){ throw {a:'abc', b:2}; }; var input = c.node; - input.click(); + input.trigger('click'); assertEquals({a:"abc", b:2}, fromJson(input.attr('ng-exception'))); assertTrue("should have an error class", input.hasClass('ng-exception')); // TODO: I think that exception should never get cleared so this portion of test makes no sense //c.scope.action = noop; - //input.click(); + //input.trigger('click'); //dump(input.attr('ng-error')); //assertFalse('error class should be cleared', input.hasClass('ng-exception')); }; @@ -574,10 +574,10 @@ BinderTest.prototype.testItShouldDisplayErrorWhenActionIsSyntacticlyIncorect = f var first = jqLite(c.node[0].childNodes[0]); var second = jqLite(c.node[0].childNodes[1]); - first.click(); + first.trigger('click'); assertEquals("ABC", c.scope.greeting); - second.click(); + second.trigger('click'); assertTrue(second.hasClass("ng-exception")); }; diff --git a/test/CompilerSpec.js b/test/CompilerSpec.js index fe61c520..e50f6ae7 100644 --- a/test/CompilerSpec.js +++ b/test/CompilerSpec.js @@ -75,21 +75,22 @@ describe('compiler', function(){ it('should allow creation of templates', function(){ directives.duplicate = function(expr, element){ + var parent = element.parent(); element.replaceWith(document.createComment("marker")); element.removeAttr("duplicate"); var template = this.compile(element); return function(marker) { this.$onEval(function() { - marker.after(template(element.clone()).element); + marker.after(template(element.clone()).$element); }); }; }; var scope = compile('beforexafter'); - expect(sortedHtml(scope.$element)).toEqual('
                          before<#comment>after
                          '); + expect(sortedHtml(scope.$element)).toEqual('
                          before<#comment>xafter
                          '); scope.$eval(); - expect(sortedHtml(scope.$element)).toEqual('
                          before<#comment>after
                          '); + expect(sortedHtml(scope.$element)).toEqual('
                          before<#comment>xxafter
                          '); scope.$eval(); - expect(sortedHtml(scope.$element)).toEqual('
                          before<#comment>after
                          '); + expect(sortedHtml(scope.$element)).toEqual('
                          before<#comment>xxxafter
                          '); }); it('should process markup before directives', function(){ diff --git a/test/directivesSpec.js b/test/directivesSpec.js index 1ddd7477..f7024bdb 100644 --- a/test/directivesSpec.js +++ b/test/directivesSpec.js @@ -133,7 +133,7 @@ describe("directives", function(){ scope.$eval(); expect(scope.$get('clicked')).toBeFalsy(); - element.click(); + element.trigger('click'); expect(scope.$get('clicked')).toEqual(true); }); diff --git a/test/widgetsSpec.js b/test/widgetsSpec.js index ecc00d05..2cfe216c 100644 --- a/test/widgetsSpec.js +++ b/test/widgetsSpec.js @@ -136,23 +136,23 @@ describe("input widget", function(){ it('should call ng-change on button click', function(){ compile(''); - element.click(); + element.trigger('click'); expect(scope.$get('clicked')).toEqual(true); }); it('should support button alias', function(){ compile(''); - element.click(); + element.trigger('click'); expect(scope.$get('clicked')).toEqual(true); }); it('should type="checkbox"', function(){ compile(''); expect(scope.checkbox).toEqual(true); - trigger(element, 'click'); + element.trigger('click'); expect(scope.checkbox).toEqual(false); expect(scope.action).toEqual(true); - trigger(element, 'click'); + element.trigger('click'); expect(scope.checkbox).toEqual(true); }); @@ -176,7 +176,7 @@ describe("input widget", function(){ expect(b.checked).toEqual(true); expect(scope.clicked).not.toBeDefined(); - trigger(a, 'click'); + jqLite(a).trigger('click'); expect(scope.chose).toEqual('A'); expect(scope.clicked).toEqual(1); }); @@ -218,7 +218,7 @@ describe("input widget", function(){ it('should report error on ng-change exception', function(){ compile(''); - element.click(); + element.trigger('click'); expect(element.hasClass('ng-exception')).toBeTruthy(); }); -- cgit v1.2.3 From e78405f6ed82fcd2e9a1cdffb7f1103d52752623 Mon Sep 17 00:00:00 2001 From: Misko Hevery Date: Wed, 21 Apr 2010 12:50:05 -0700 Subject: more if tests pass --- test/FiltersTest.js | 6 +- test/ValidatorsTest.js | 2 +- test/directivesSpec.js | 38 ++-- test/markupSpec.js | 7 +- test/testabilityPatch.js | 10 +- test/widgetsSpec.js | 447 ++++++++++++++++++++++++----------------------- 6 files changed, 260 insertions(+), 250 deletions(-) (limited to 'test') diff --git a/test/FiltersTest.js b/test/FiltersTest.js index ad38b94d..0fd80056 100644 --- a/test/FiltersTest.js +++ b/test/FiltersTest.js @@ -135,7 +135,7 @@ FiltersTest.prototype.testGoogleChartApiEncode = function() { FiltersTest.prototype.testHtml = function() { var div = jqLite('
                          '); div.append(angular.filter.html("acd")); - assertEquals("acd", div.html()); + assertEquals("acd", lowercase(div.html())); }; FiltersTest.prototype.testLinky = function() { @@ -143,9 +143,9 @@ FiltersTest.prototype.testLinky = function() { assertEquals( 'http://ab ' + '(http://a) ' + - '<http://a> \n ' + + '<http://a> ' + 'http://1.2/v:~-123. c', - sortedHtml(linky("http://ab (http://a) \n http://1.2/v:~-123. c"))); + sortedHtml(linky("http://ab (http://a) http://1.2/v:~-123. c"))); assertEquals(undefined, linky(undefined)); }; diff --git a/test/ValidatorsTest.js b/test/ValidatorsTest.js index b2403eab..573c340d 100644 --- a/test/ValidatorsTest.js +++ b/test/ValidatorsTest.js @@ -12,7 +12,7 @@ ValidatorTest.prototype.testItShouldHaveThisSet = function() { scope.$init(); assertEquals('misko', validator.first); assertEquals('hevery', validator.last); - assertSame(scope, validator._this.__proto__); + expect(validator._this.$id).toEqual(scope.$id); delete angular.validator.myValidator; scope.$element.remove(); }; diff --git a/test/directivesSpec.js b/test/directivesSpec.js index f7024bdb..d012fdd0 100644 --- a/test/directivesSpec.js +++ b/test/directivesSpec.js @@ -41,7 +41,7 @@ describe("directives", function(){ var scope = compile('
                          '); scope.html = '
                          hello
                          '; scope.$eval(); - expect(element.html()).toEqual('
                          hello
                          '); + expect(lowercase(element.html())).toEqual('
                          hello
                          '); }); it('should ng-bind-template', function() { @@ -58,7 +58,7 @@ describe("directives", function(){ }); it('should remove special attributes on false', function(){ - var scope = compile('
                          '); + var scope = compile('
                          '); expect(scope.$element.attr('disabled')).toEqual(null); expect(scope.$element.attr('readonly')).toEqual(null); expect(scope.$element.attr('checked')).toEqual(null); @@ -180,22 +180,24 @@ describe("directives", function(){ expect(isCssVisible(scope.$element)).toEqual(true); }); - it('should ng-controller', function(){ - window.Greeter = function(){ - this.greeting = 'hello'; - }; - window.Greeter.prototype = { - init: function(){ - this.suffix = '!'; - }, - greet: function(name) { - return this.greeting + ' ' + name + this.suffix; - } - }; - var scope = compile('
                          '); - expect(scope.greeting).toEqual('hello'); - expect(scope.greet('misko')).toEqual('hello misko!'); - delete window.Greeter; + describe('ng-controller', function(){ + it('should bind', function(){ + window.Greeter = function(){ + this.greeting = 'hello'; + }; + window.Greeter.prototype = { + init: function(){ + this.suffix = '!'; + }, + greet: function(name) { + return this.greeting + ' ' + name + this.suffix; + } + }; + var scope = compile('
                          '); + expect(scope.greeting).toEqual('hello'); + expect(scope.greet('misko')).toEqual('hello misko!'); + window.Greeter = undefined; + }); }); it('should eval things according to ng-eval-order', function(){ diff --git a/test/markupSpec.js b/test/markupSpec.js index a1112490..cfc0f899 100644 --- a/test/markupSpec.js +++ b/test/markupSpec.js @@ -43,13 +43,14 @@ describe("markups", function(){ }); it('should populate value attribute on OPTION', function(){ - compile(''); - expect(element.html()).toEqual(''); + compile(''); + expect(sortedHtml(element)).toEqual(''); }); it('should process all bindings when we have leading space', function(){ compile(' {{a}}
                          {{b}}
                          '); - expect(sortedHtml(scope.$element)).toEqual('

                          '); + var space = msie ? '' + NBSP + '': ' '; + expect(sortedHtml(scope.$element)).toEqual('' + space + '

                          '); }); }); diff --git a/test/testabilityPatch.js b/test/testabilityPatch.js index 17341575..a2d67923 100644 --- a/test/testabilityPatch.js +++ b/test/testabilityPatch.js @@ -1,6 +1,8 @@ jstd = jstestdriver; dump = bind(jstd.console, jstd.console.log); +var NBSP = jqLite(' ').text(); + function nakedExpect(obj) { return expect(angular.fromJson(angular.toJson(obj))); } @@ -46,6 +48,7 @@ function sortedHtml(element) { attr.value !='inherit' && attr.value !='0' && attr.name !='loop' && + attr.name !='complete' && attr.name !='maxLength' && attr.name !='size' && attr.name !='start' && @@ -53,7 +56,8 @@ function sortedHtml(element) { attr.name !='style' && attr.name.substr(0, 6) != 'jQuery') { // in IE we need to check for all of these. - attrs.push(' ' + attr.name + '="' + attr.value + '"'); + if (!/ng-\d+/.exec(attr.name)) + attrs.push(' ' + attr.name + '="' + attr.value + '"'); } } attrs.sort(); @@ -64,14 +68,14 @@ function sortedHtml(element) { foreach(node.style.cssText.split(';'), function(value){ value = trim(value); if (value) { - style.push(value); + style.push(lowercase(value)); } }); } for(var css in node.style){ var value = node.style[css]; if (isString(value) && isString(css) && css != 'cssText' && value && (1*css != css)) { - var text = css + ': ' + value; + var text = lowercase(css + ': ' + value); if (value != 'false' && indexOf(style, text) == -1) { style.push(text); } diff --git a/test/widgetsSpec.js b/test/widgetsSpec.js index 2cfe216c..c6c57557 100644 --- a/test/widgetsSpec.js +++ b/test/widgetsSpec.js @@ -1,5 +1,4 @@ -describe("input widget", function(){ - +describe("widget", function(){ var compile, element, scope; beforeEach(function() { @@ -19,265 +18,269 @@ describe("input widget", function(){ expect(size(jqCache)).toEqual(0); }); - it('should input-text auto init and handle keyup/change events', function(){ - compile(''); - expect(scope.$get('name')).toEqual("Misko"); - expect(scope.$get('count')).toEqual(0); + describe("input", function(){ - scope.$set('name', 'Adam'); - scope.$eval(); - expect(element.val()).toEqual("Adam"); + it('should input-text auto init and handle keyup/change events', function(){ + compile(''); + expect(scope.$get('name')).toEqual("Misko"); + expect(scope.$get('count')).toEqual(0); - element.val('Shyam'); - element.trigger('keyup'); - expect(scope.$get('name')).toEqual('Shyam'); - expect(scope.$get('count')).toEqual(1); + scope.$set('name', 'Adam'); + scope.$eval(); + expect(element.val()).toEqual("Adam"); - element.val('Kai'); - element.trigger('change'); - expect(scope.$get('name')).toEqual('Kai'); - expect(scope.$get('count')).toEqual(2); - }); + element.val('Shyam'); + element.trigger('keyup'); + expect(scope.$get('name')).toEqual('Shyam'); + expect(scope.$get('count')).toEqual(1); - it("should process ng-format", function(){ - compile(''); - expect(scope.$get('list')).toEqual(['a', 'b', 'c']); + element.val('Kai'); + element.trigger('change'); + expect(scope.$get('name')).toEqual('Kai'); + expect(scope.$get('count')).toEqual(2); + }); - scope.$set('list', ['x', 'y', 'z']); - scope.$eval(); - expect(element.val()).toEqual("x, y, z"); + it("should process ng-format", function(){ + compile(''); + expect(scope.$get('list')).toEqual(['a', 'b', 'c']); - element.val('1, 2, 3'); - element.trigger('keyup'); - expect(scope.$get('list')).toEqual(['1', '2', '3']); - }); + scope.$set('list', ['x', 'y', 'z']); + scope.$eval(); + expect(element.val()).toEqual("x, y, z"); - it("should process ng-format for booleans", function(){ - compile('', function(){ - scope.name = false; + element.val('1, 2, 3'); + element.trigger('keyup'); + expect(scope.$get('list')).toEqual(['1', '2', '3']); }); - expect(scope.name).toEqual(false); - expect(scope.$element[0].checked).toEqual(false); - }); - it("should process ng-validate", function(){ - compile(''); - expect(element.hasClass('ng-validation-error')).toBeTruthy(); - expect(element.attr('ng-validation-error')).toEqual('Not a number'); + it("should process ng-format for booleans", function(){ + compile('', function(){ + scope.name = false; + }); + expect(scope.name).toEqual(false); + expect(scope.$element[0].checked).toEqual(false); + }); - scope.$set('price', '123'); - scope.$eval(); - expect(element.hasClass('ng-validation-error')).toBeFalsy(); - expect(element.attr('ng-validation-error')).toBeFalsy(); + it("should process ng-validate", function(){ + compile(''); + expect(element.hasClass('ng-validation-error')).toBeTruthy(); + expect(element.attr('ng-validation-error')).toEqual('Not a number'); - element.val('x'); - element.trigger('keyup'); - expect(element.hasClass('ng-validation-error')).toBeTruthy(); - expect(element.attr('ng-validation-error')).toEqual('Not a number'); - }); + scope.$set('price', '123'); + scope.$eval(); + expect(element.hasClass('ng-validation-error')).toBeFalsy(); + expect(element.attr('ng-validation-error')).toBeFalsy(); - it("should not call validator if undefinde/empty", function(){ - var lastValue = "NOT_CALLED"; - angularValidator.myValidator = function(value){lastValue = value;}; - compile(''); - expect(lastValue).toEqual("NOT_CALLED"); + element.val('x'); + element.trigger('keyup'); + expect(element.hasClass('ng-validation-error')).toBeTruthy(); + expect(element.attr('ng-validation-error')).toEqual('Not a number'); + }); - scope.url = 'http://server'; - scope.$eval(); - expect(lastValue).toEqual("http://server"); + it("should not call validator if undefinde/empty", function(){ + var lastValue = "NOT_CALLED"; + angularValidator.myValidator = function(value){lastValue = value;}; + compile(''); + expect(lastValue).toEqual("NOT_CALLED"); - delete angularValidator.myValidator; - }); + scope.url = 'http://server'; + scope.$eval(); + expect(lastValue).toEqual("http://server"); - it("should ignore disabled widgets", function(){ - compile(''); - expect(element.hasClass('ng-validation-error')).toBeFalsy(); - expect(element.attr('ng-validation-error')).toBeFalsy(); - }); + delete angularValidator.myValidator; + }); - it("should ignore readonly widgets", function(){ - compile(''); - expect(element.hasClass('ng-validation-error')).toBeFalsy(); - expect(element.attr('ng-validation-error')).toBeFalsy(); - }); + it("should ignore disabled widgets", function(){ + compile(''); + expect(element.hasClass('ng-validation-error')).toBeFalsy(); + expect(element.attr('ng-validation-error')).toBeFalsy(); + }); - it("should process ng-required", function(){ - compile(''); - expect(element.hasClass('ng-validation-error')).toBeTruthy(); - expect(element.attr('ng-validation-error')).toEqual('Required'); + it("should ignore readonly widgets", function(){ + compile(''); + expect(element.hasClass('ng-validation-error')).toBeFalsy(); + expect(element.attr('ng-validation-error')).toBeFalsy(); + }); - scope.$set('price', 'xxx'); - scope.$eval(); - expect(element.hasClass('ng-validation-error')).toBeFalsy(); - expect(element.attr('ng-validation-error')).toBeFalsy(); + it("should process ng-required", function(){ + compile(''); + expect(element.hasClass('ng-validation-error')).toBeTruthy(); + expect(element.attr('ng-validation-error')).toEqual('Required'); - element.val(''); - element.trigger('keyup'); - expect(element.hasClass('ng-validation-error')).toBeTruthy(); - expect(element.attr('ng-validation-error')).toEqual('Required'); - }); + scope.$set('price', 'xxx'); + scope.$eval(); + expect(element.hasClass('ng-validation-error')).toBeFalsy(); + expect(element.attr('ng-validation-error')).toBeFalsy(); - it("should process ng-required2", function() { - compile(''); - expect(scope.$get('name')).toEqual("Misko"); + element.val(''); + element.trigger('keyup'); + expect(element.hasClass('ng-validation-error')).toBeTruthy(); + expect(element.attr('ng-validation-error')).toEqual('Required'); + }); - scope.$set('name', 'Adam'); - scope.$eval(); - expect(element.val()).toEqual("Adam"); + it("should process ng-required2", function() { + compile(''); + expect(scope.$get('name')).toEqual("Misko"); - element.val('Shyam'); - element.trigger('keyup'); - expect(scope.$get('name')).toEqual('Shyam'); + scope.$set('name', 'Adam'); + scope.$eval(); + expect(element.val()).toEqual("Adam"); - element.val('Kai'); - element.trigger('change'); - expect(scope.$get('name')).toEqual('Kai'); - }); + element.val('Shyam'); + element.trigger('keyup'); + expect(scope.$get('name')).toEqual('Shyam'); - it('should call ng-change on button click', function(){ - compile(''); - element.trigger('click'); - expect(scope.$get('clicked')).toEqual(true); - }); + element.val('Kai'); + element.trigger('change'); + expect(scope.$get('name')).toEqual('Kai'); + }); - it('should support button alias', function(){ - compile(''); - element.trigger('click'); - expect(scope.$get('clicked')).toEqual(true); - }); + it('should call ng-change on button click', function(){ + compile(''); + element.trigger('click'); + expect(scope.$get('clicked')).toEqual(true); + }); - it('should type="checkbox"', function(){ - compile(''); - expect(scope.checkbox).toEqual(true); - element.trigger('click'); - expect(scope.checkbox).toEqual(false); - expect(scope.action).toEqual(true); - element.trigger('click'); - expect(scope.checkbox).toEqual(true); - }); + it('should support button alias', function(){ + compile(''); + element.trigger('click'); + expect(scope.$get('clicked')).toEqual(true); + }); - it('should type="radio"', function(){ - compile('
                          ' + - '' + - '' + - '' + - '
                          '); - var a = element[0].childNodes[0]; - var b = element[0].childNodes[1]; - expect(b.name.split('@')[1]).toEqual('chose'); - expect(scope.chose).toEqual('B'); - scope.chose = 'A'; - scope.$eval(); - expect(a.checked).toEqual(true); - - scope.chose = 'B'; - scope.$eval(); - expect(a.checked).toEqual(false); - expect(b.checked).toEqual(true); - expect(scope.clicked).not.toBeDefined(); - - jqLite(a).trigger('click'); - expect(scope.chose).toEqual('A'); - expect(scope.clicked).toEqual(1); - }); + it('should support type="checkbox"', function(){ + compile(''); + expect(scope.checkbox).toEqual(true); + element.trigger('click'); + expect(scope.checkbox).toEqual(false); + expect(scope.action).toEqual(true); + element.trigger('click'); + expect(scope.checkbox).toEqual(true); + }); - it('should type="select-one"', function(){ - compile( - ''); - expect(scope.selection).toEqual('B'); - scope.selection = 'A'; - scope.$eval(); - expect(scope.selection).toEqual('A'); - expect(element[0].childNodes[0].selected).toEqual(true); - }); + it('should support type="radio"', function(){ + compile('
                          ' + + '' + + '' + + '' + + '
                          '); + var a = element[0].childNodes[0]; + var b = element[0].childNodes[1]; + expect(b.name.split('@')[1]).toEqual('chose'); + expect(scope.chose).toEqual('B'); + scope.chose = 'A'; + scope.$eval(); + expect(a.checked).toEqual(true); + + scope.chose = 'B'; + scope.$eval(); + expect(a.checked).toEqual(false); + expect(b.checked).toEqual(true); + expect(scope.clicked).not.toBeDefined(); + + jqLite(a).trigger('click'); + expect(scope.chose).toEqual('A'); + expect(scope.clicked).toEqual(1); + }); - it('should type="select-multiple"', function(){ - compile( - ''); - expect(scope.selection).toEqual(['B']); - scope.selection = ['A']; - scope.$eval(); - expect(element[0].childNodes[0].selected).toEqual(true); - }); + it('should support type="select-one"', function(){ + compile( + ''); + expect(scope.selection).toEqual('B'); + scope.selection = 'A'; + scope.$eval(); + expect(scope.selection).toEqual('A'); + expect(element[0].childNodes[0].selected).toEqual(true); + }); - it('should report error on missing field', function(){ - compile(''); - expect(element.hasClass('ng-exception')).toBeTruthy(); - }); + it('should support type="select-multiple"', function(){ + compile( + ''); + expect(scope.selection).toEqual(['B']); + scope.selection = ['A']; + scope.$eval(); + expect(element[0].childNodes[0].selected).toEqual(true); + }); - it('should report error on assignment error', function(){ - compile(''); - expect(element.hasClass('ng-exception')).toBeTruthy(); - }); + it('should report error on missing field', function(){ + compile(''); + expect(element.hasClass('ng-exception')).toBeTruthy(); + }); - it('should report error on ng-change exception', function(){ - compile(''); - element.trigger('click'); - expect(element.hasClass('ng-exception')).toBeTruthy(); - }); + it('should report error on assignment error', function(){ + compile(''); + expect(element.hasClass('ng-exception')).toBeTruthy(); + }); - it('should switch on value change', function(){ - compile('
                          first:{{name}}
                          second:{{name}}
                          '); - expect(element.html()).toEqual(''); - scope.select = 1; - scope.$eval(); - expect(element.text()).toEqual('first:'); - scope.name="shyam"; - scope.$eval(); - expect(element.text()).toEqual('first:shyam'); - scope.select = 2; - scope.$eval(); - scope.name = 'misko'; - scope.$eval(); - expect(element.text()).toEqual('second:misko'); + it('should report error on ng-change exception', function(){ + compile(''); + element.trigger('click'); + expect(element.hasClass('ng-exception')).toBeTruthy(); + }); }); -}); -describe('ng:switch', function(){ - it("should match urls", function(){ - var scope = compile('
                          {{params.name}}
                          '); - scope.url = '/Book/Moby'; - scope.$init(); - expect(scope.$element.text()).toEqual('Moby'); - }); + describe('ng:switch', function(){ + it('should switch on value change', function(){ + compile('
                          first:{{name}}
                          second:{{name}}
                          '); + expect(element.html()).toEqual(''); + scope.select = 1; + scope.$eval(); + expect(element.text()).toEqual('first:'); + scope.name="shyam"; + scope.$eval(); + expect(element.text()).toEqual('first:shyam'); + scope.select = 2; + scope.$eval(); + expect(element.text()).toEqual('second:shyam'); + scope.name = 'misko'; + scope.$eval(); + expect(element.text()).toEqual('second:misko'); + }); - it("should match sandwich ids", function(){ - var scope = {}; - var match = angular.widget['NG:SWITCH'].route.call(scope, '/a/123/b', '/a/:id'); - expect(match).toBeFalsy(); - }); + it("should match urls", function(){ + var scope = angular.compile('
                          {{params.name}}
                          '); + scope.url = '/Book/Moby'; + scope.$init(); + expect(scope.$element.text()).toEqual('Moby'); + }); + + it("should match sandwich ids", function(){ + var scope = {}; + var match = angular.widget['NG:SWITCH'].route.call(scope, '/a/123/b', '/a/:id'); + expect(match).toBeFalsy(); + }); - it('should call init on switch', function(){ - var scope = compile('
                          {{name}}
                          '); - var cleared = false; - scope.url = 'a'; - scope.$invalidWidgets = {clearOrphans: function(){ - cleared = true; - }}; - scope.$init(); - expect(scope.name).toEqual(undefined); - expect(scope.$element.text()).toEqual('works'); - expect(cleared).toEqual(true); + it('should call init on switch', function(){ + var scope = angular.compile('
                          {{name}}
                          '); + var cleared = false; + scope.url = 'a'; + scope.$invalidWidgets = {clearOrphans: function(){ + cleared = true; + }}; + scope.$init(); + expect(scope.name).toEqual(undefined); + expect(scope.$element.text()).toEqual('works'); + expect(cleared).toEqual(true); + }); }); -}); -describe('ng:include', function(){ - it('should include on external file', function() { - var element = jqLite(''); - var scope = compile(element); - scope.childScope = createScope(); - scope.childScope.name = 'misko'; - scope.url = 'myUrl'; - scope.$browser.xhr.expect('GET', 'myUrl').respond('{{name}}'); - scope.$init(); - scope.$browser.xhr.flush(); - expect(element.text()).toEqual('misko'); + describe('ng:include', function(){ + it('should include on external file', function() { + var element = jqLite(''); + var scope = angular.compile(element); + scope.childScope = createScope(); + scope.childScope.name = 'misko'; + scope.url = 'myUrl'; + scope.$browser.xhr.expect('GET', 'myUrl').respond('{{name}}'); + scope.$init(); + scope.$browser.xhr.flush(); + expect(element.text()).toEqual('misko'); + }); }); }); -- cgit v1.2.3 From 4aaec251dfebd01729c0726f07fc113b97679219 Mon Sep 17 00:00:00 2001 From: Misko Hevery Date: Wed, 21 Apr 2010 13:29:49 -0700 Subject: all tests pass on IE --- test/CompilerSpec.js | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'test') diff --git a/test/CompilerSpec.js b/test/CompilerSpec.js index e50f6ae7..a212634a 100644 --- a/test/CompilerSpec.js +++ b/test/CompilerSpec.js @@ -98,11 +98,11 @@ describe('compiler', function(){ if (text == 'middle') { expect(textNode.text()).toEqual(text); parentNode.attr('hello', text); - textNode[0].textContent = 'replaced'; + textNode[0].nodeValue = 'replaced'; } }); var scope = compile('beforemiddleafter'); - expect(scope.$element[0].innerHTML).toEqual('beforereplacedafter'); + expect(lowercase(scope.$element[0].innerHTML)).toEqual('beforereplacedafter'); expect(log).toEqual("hello middle"); }); @@ -114,7 +114,7 @@ describe('compiler', function(){ }; }; var scope = compile('push me'); - expect(scope.$element[0].innerHTML).toEqual('
                          button
                          '); + expect(lowercase(scope.$element[0].innerHTML)).toEqual('
                          button
                          '); expect(log).toEqual('init'); }); -- cgit v1.2.3 From 8b29156a2ddcc738f9b0cf8dfc48a8648474884d Mon Sep 17 00:00:00 2001 From: Misko Hevery Date: Wed, 21 Apr 2010 14:29:05 -0700 Subject: ie6 now passes --- test/FiltersTest.js | 18 +++++++++--------- test/directivesSpec.js | 4 ++-- test/markupSpec.js | 26 +++++++++++++++----------- 3 files changed, 26 insertions(+), 22 deletions(-) (limited to 'test') diff --git a/test/FiltersTest.js b/test/FiltersTest.js index 0fd80056..a71d30e2 100644 --- a/test/FiltersTest.js +++ b/test/FiltersTest.js @@ -80,13 +80,13 @@ FiltersTest.prototype.testImage = function(){ assertEquals(null, angular.filter.image()); assertEquals(null, angular.filter.image({})); assertEquals(null, angular.filter.image("")); - assertEquals('', sortedHtml(angular.filter.image({url:"abc"}))); + assertEquals('', sortedHtml(angular.filter.image({url:"http://localhost/abc"}))); assertEquals( - '', - sortedHtml(angular.filter.image({url:"abc"}, 10))); + '', + sortedHtml(angular.filter.image({url:"http://localhost/abc"}, 10))); assertEquals( - '', - sortedHtml(angular.filter.image({url:"abc"}, 10, 20))); + '', + sortedHtml(angular.filter.image({url:"http://localhost/abc"}, 10, 20))); }; FiltersTest.prototype.testQRcode = function() { @@ -141,11 +141,11 @@ FiltersTest.prototype.testHtml = function() { FiltersTest.prototype.testLinky = function() { var linky = angular.filter.linky; assertEquals( - 'http://ab ' + - '(http://a) ' + - '<http://a> ' + + 'http://ab/ ' + + '(http://a/) ' + + '<http://a/> ' + 'http://1.2/v:~-123. c', - sortedHtml(linky("http://ab (http://a) http://1.2/v:~-123. c"))); + sortedHtml(linky("http://ab/ (http://a/) http://1.2/v:~-123. c"))); assertEquals(undefined, linky(undefined)); }; diff --git a/test/directivesSpec.js b/test/directivesSpec.js index d012fdd0..71402af7 100644 --- a/test/directivesSpec.js +++ b/test/directivesSpec.js @@ -52,8 +52,8 @@ describe("directives", function(){ }); it('should ng-bind-attr', function(){ - var scope = compile(''); - expect(element.attr('src')).toEqual('mysrc'); + var scope = compile(''); + expect(element.attr('src')).toEqual('http://localhost/mysrc'); expect(element.attr('alt')).toEqual('myalt'); }); diff --git a/test/markupSpec.js b/test/markupSpec.js index cfc0f899..5e3b829a 100644 --- a/test/markupSpec.js +++ b/test/markupSpec.js @@ -27,11 +27,11 @@ describe("markups", function(){ }); it('should translate {{}} in terminal nodes', function(){ - compile(''); - expect(sortedHtml(element)).toEqual(''); + compile(''); + expect(sortedHtml(element)).toEqual(''); scope.$set('name', 'Misko'); scope.$eval(); - expect(sortedHtml(element)).toEqual(''); + expect(sortedHtml(element)).toEqual(''); }); it('should translate {{}} in attributes', function(){ @@ -43,14 +43,18 @@ describe("markups", function(){ }); it('should populate value attribute on OPTION', function(){ - compile(''); - expect(sortedHtml(element)).toEqual(''); + compile(''); + expect(sortedHtml(element)).toEqual(''); }); it('should process all bindings when we have leading space', function(){ - compile(' {{a}}
                          {{b}}
                          '); - var space = msie ? '' + NBSP + '': ' '; - expect(sortedHtml(scope.$element)).toEqual('' + space + '

                          '); + var e = jqLite(' {{a}}
                          {{b}}
                          '); + if (sortedHtml(e).indexOf('{{') != 0) { + // can only run this test if browser respects leading spaces + compile(e); + var space = msie ? '' + NBSP + '': ' '; + expect(sortedHtml(scope.$element)).toEqual('' + space + '

                          '); + } }); }); @@ -138,7 +142,7 @@ BindingMarkupTest.prototype.testParseMultiline = function(){ }; BindingMarkupTest.prototype.testHasBinding = function(){ - assertTrue(hasBindings("{{a}}")); - assertTrue(!hasBindings("a")); - assertTrue(hasBindings("{{b}}x{{c}}")); + assertTrue(hasBindings(parseBindings("{{a}}"))); + assertTrue(!hasBindings(parseBindings("a"))); + assertTrue(hasBindings(parseBindings("{{b}}x{{c}}"))); }; -- cgit v1.2.3 From d7416c4c823b9e74d0c725cffb6f333be9432fba Mon Sep 17 00:00:00 2001 From: Misko Hevery Date: Wed, 21 Apr 2010 14:51:39 -0700 Subject: ie6 and ie8 pass --- test/markupSpec.js | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) (limited to 'test') diff --git a/test/markupSpec.js b/test/markupSpec.js index 5e3b829a..b2d04fcd 100644 --- a/test/markupSpec.js +++ b/test/markupSpec.js @@ -27,11 +27,11 @@ describe("markups", function(){ }); it('should translate {{}} in terminal nodes', function(){ - compile(''); - expect(sortedHtml(element)).toEqual(''); + compile(''); + expect(sortedHtml(element).replace(' selected="true"', '')).toEqual(''); scope.$set('name', 'Misko'); scope.$eval(); - expect(sortedHtml(element)).toEqual(''); + expect(sortedHtml(element).replace(' selected="true"', '')).toEqual(''); }); it('should translate {{}} in attributes', function(){ @@ -43,8 +43,8 @@ describe("markups", function(){ }); it('should populate value attribute on OPTION', function(){ - compile(''); - expect(sortedHtml(element)).toEqual(''); + compile(''); + expect(sortedHtml(element).replace(' selected="true"', '')).toEqual(''); }); it('should process all bindings when we have leading space', function(){ -- cgit v1.2.3 From 2a9669e1d853d4e18d2eb1f07e84ee5baec838c2 Mon Sep 17 00:00:00 2001 From: Misko Hevery Date: Thu, 22 Apr 2010 15:50:20 -0700 Subject: working on jQuery passing tests --- test/testabilityPatch.js | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) (limited to 'test') diff --git a/test/testabilityPatch.js b/test/testabilityPatch.js index a2d67923..e5eef63e 100644 --- a/test/testabilityPatch.js +++ b/test/testabilityPatch.js @@ -1,7 +1,11 @@ jstd = jstestdriver; dump = bind(jstd.console, jstd.console.log); -var NBSP = jqLite(' ').text(); +var NBSP = (function(){ + var div = document.createElement('div'); + div.innerHtml = ' '; + return msie ? div.innerText : div.textContent; +})(); function nakedExpect(obj) { return expect(angular.fromJson(angular.toJson(obj))); @@ -82,6 +86,12 @@ function sortedHtml(element) { } } style.sort(); + var tmp = style; + style = []; + foreach(tmp, function(value){ + if (!value.match(/^max[^\-]/)) + style.push(value); + }); if (style.length) { html += ' style="' + style.join('; ') + ';"'; } -- cgit v1.2.3 From fe434307d15d697a5ffade51bad068f6443965b2 Mon Sep 17 00:00:00 2001 From: Misko Hevery Date: Thu, 22 Apr 2010 17:11:56 -0700 Subject: tests work under jquery and without --- test/BinderTest.js | 4 ++-- test/FiltersTest.js | 8 ++++---- test/testabilityPatch.js | 9 +++++++++ test/widgetsSpec.js | 12 ++++++------ 4 files changed, 21 insertions(+), 12 deletions(-) (limited to 'test') diff --git a/test/BinderTest.js b/test/BinderTest.js index 31b2698d..76561dc3 100644 --- a/test/BinderTest.js +++ b/test/BinderTest.js @@ -588,13 +588,13 @@ BinderTest.prototype.testItShouldSelectTheCorrectRadioBox = function() { var female = jqLite(c.node[0].childNodes[0]); var male = jqLite(c.node[0].childNodes[1]); - female.trigger('click'); + click(female); assertEquals("female", c.scope.sex); assertEquals(true, female[0].checked); assertEquals(false, male[0].checked); assertEquals("female", female.val()); - male.trigger('click'); + click(male); assertEquals("male", c.scope.sex); assertEquals(false, female[0].checked); assertEquals(true, male[0].checked); diff --git a/test/FiltersTest.js b/test/FiltersTest.js index a71d30e2..5642f635 100644 --- a/test/FiltersTest.js +++ b/test/FiltersTest.js @@ -133,9 +133,9 @@ FiltersTest.prototype.testGoogleChartApiEncode = function() { }; FiltersTest.prototype.testHtml = function() { - var div = jqLite('
                          '); - div.append(angular.filter.html("acd")); - assertEquals("acd", lowercase(div.html())); + var html = angular.filter.html("acd"); + expect(html instanceof HTML).toBeTruthy(); + expect(html.html).toEqual("acd"); }; FiltersTest.prototype.testLinky = function() { @@ -145,7 +145,7 @@ FiltersTest.prototype.testLinky = function() { '(http://a/) ' + '<http://a/> ' + 'http://1.2/v:~-123. c', - sortedHtml(linky("http://ab/ (http://a/) http://1.2/v:~-123. c"))); + linky("http://ab/ (http://a/) http://1.2/v:~-123. c").html); assertEquals(undefined, linky(undefined)); }; diff --git a/test/testabilityPatch.js b/test/testabilityPatch.js index e5eef63e..b05770c7 100644 --- a/test/testabilityPatch.js +++ b/test/testabilityPatch.js @@ -148,3 +148,12 @@ function assertThrows(error, fn){ log = noop; error = noop; + +function click(element) { + element = jqLite(element); + if ( (msie || jqLite == window.jQuery) && + nodeName(element) == 'INPUT' && (lowercase(element.attr('type')) == 'radio' || lowercase(element.attr('type')) == 'checkbox')) { + element[0].checked = ! element[0].checked; + } + element.trigger('click'); +} diff --git a/test/widgetsSpec.js b/test/widgetsSpec.js index c6c57557..3aa5e250 100644 --- a/test/widgetsSpec.js +++ b/test/widgetsSpec.js @@ -137,23 +137,23 @@ describe("widget", function(){ it('should call ng-change on button click', function(){ compile(''); - element.trigger('click'); + click(element); expect(scope.$get('clicked')).toEqual(true); }); it('should support button alias', function(){ compile(''); - element.trigger('click'); + click(element); expect(scope.$get('clicked')).toEqual(true); }); it('should support type="checkbox"', function(){ compile(''); expect(scope.checkbox).toEqual(true); - element.trigger('click'); + click(element); expect(scope.checkbox).toEqual(false); expect(scope.action).toEqual(true); - element.trigger('click'); + click(element); expect(scope.checkbox).toEqual(true); }); @@ -177,7 +177,7 @@ describe("widget", function(){ expect(b.checked).toEqual(true); expect(scope.clicked).not.toBeDefined(); - jqLite(a).trigger('click'); + click(a); expect(scope.chose).toEqual('A'); expect(scope.clicked).toEqual(1); }); @@ -219,7 +219,7 @@ describe("widget", function(){ it('should report error on ng-change exception', function(){ compile(''); - element.trigger('click'); + click(element); expect(element.hasClass('ng-exception')).toBeTruthy(); }); }); -- cgit v1.2.3 From 7ef5e055afec5ad7f279bcc4bd70b9f069d87a95 Mon Sep 17 00:00:00 2001 From: Misko Hevery Date: Thu, 22 Apr 2010 21:04:20 -0700 Subject: fix CI Build --- test/BinderTest.js | 4 +++- test/markupSpec.js | 10 ---------- test/testabilityPatch.js | 6 ------ 3 files changed, 3 insertions(+), 17 deletions(-) (limited to 'test') diff --git a/test/BinderTest.js b/test/BinderTest.js index 76561dc3..ecdd506f 100644 --- a/test/BinderTest.js +++ b/test/BinderTest.js @@ -436,7 +436,9 @@ BinderTest.prototype.testActionOnAHrefThrowsError = function(){ }; var input = c.node; input.trigger('click'); - assertEquals({a:"abc", b:2}, fromJson(input.attr('ng-exception'))); + var error = fromJson(input.attr('ng-exception')); + assertEquals("abc", error.a); + assertEquals(2, error.b); assertTrue("should have an error class", input.hasClass('ng-exception')); // TODO: I think that exception should never get cleared so this portion of test makes no sense diff --git a/test/markupSpec.js b/test/markupSpec.js index b2d04fcd..8358b673 100644 --- a/test/markupSpec.js +++ b/test/markupSpec.js @@ -47,16 +47,6 @@ describe("markups", function(){ expect(sortedHtml(element).replace(' selected="true"', '')).toEqual(''); }); - it('should process all bindings when we have leading space', function(){ - var e = jqLite(' {{a}}
                          {{b}}
                          '); - if (sortedHtml(e).indexOf('{{') != 0) { - // can only run this test if browser respects leading spaces - compile(e); - var space = msie ? '' + NBSP + '': ' '; - expect(sortedHtml(scope.$element)).toEqual('' + space + '

                          '); - } - }); - }); diff --git a/test/testabilityPatch.js b/test/testabilityPatch.js index b05770c7..1e6ed970 100644 --- a/test/testabilityPatch.js +++ b/test/testabilityPatch.js @@ -1,12 +1,6 @@ jstd = jstestdriver; dump = bind(jstd.console, jstd.console.log); -var NBSP = (function(){ - var div = document.createElement('div'); - div.innerHtml = ' '; - return msie ? div.innerText : div.textContent; -})(); - function nakedExpect(obj) { return expect(angular.fromJson(angular.toJson(obj))); } -- cgit v1.2.3 From 5fdb117b32b72a908a3938bee8f1bce9854a0004 Mon Sep 17 00:00:00 2001 From: Misko Hevery Date: Thu, 22 Apr 2010 22:09:17 -0700 Subject: clean up failing test with jquery --- test/FiltersTest.js | 19 +++++-------------- test/directivesSpec.js | 15 ++++++++------- test/testabilityPatch.js | 4 ++-- test/widgetsSpec.js | 2 +- 4 files changed, 16 insertions(+), 24 deletions(-) (limited to 'test') diff --git a/test/FiltersTest.js b/test/FiltersTest.js index 5642f635..f839bb51 100644 --- a/test/FiltersTest.js +++ b/test/FiltersTest.js @@ -80,22 +80,13 @@ FiltersTest.prototype.testImage = function(){ assertEquals(null, angular.filter.image()); assertEquals(null, angular.filter.image({})); assertEquals(null, angular.filter.image("")); - assertEquals('', sortedHtml(angular.filter.image({url:"http://localhost/abc"}))); - assertEquals( - '', - sortedHtml(angular.filter.image({url:"http://localhost/abc"}, 10))); - assertEquals( - '', - sortedHtml(angular.filter.image({url:"http://localhost/abc"}, 10, 20))); + assertEquals('http://localhost/abc', angular.filter.image({url:"http://localhost/abc"}).attr('src')); }; FiltersTest.prototype.testQRcode = function() { assertEquals( - '', - sortedHtml(angular.filter.qrcode('Hello world'))); - assertEquals( - '', - sortedHtml(angular.filter.qrcode('http://server?a&b=c', 100))); + 'http://chart.apis.google.com/chart?chl=Hello%20world&chs=200x200&cht=qr', + angular.filter.qrcode('Hello world').attr('src')); }; FiltersTest.prototype.testLowercase = function() { @@ -128,8 +119,8 @@ FiltersTest.prototype.testUnless = function() { FiltersTest.prototype.testGoogleChartApiEncode = function() { assertEquals( - '', - sortedHtml(angular.filter.googleChartApi.encode({cht:"qr", chl:"Hello world"}))); + 'http://chart.apis.google.com/chart?chl=Hello world&chs=200x200&cht=qr', + angular.filter.googleChartApi.encode({cht:"qr", chl:"Hello world"}).attr('src')); }; FiltersTest.prototype.testHtml = function() { diff --git a/test/directivesSpec.js b/test/directivesSpec.js index 71402af7..eb8a9785 100644 --- a/test/directivesSpec.js +++ b/test/directivesSpec.js @@ -58,19 +58,20 @@ describe("directives", function(){ }); it('should remove special attributes on false', function(){ - var scope = compile('
                          '); - expect(scope.$element.attr('disabled')).toEqual(null); - expect(scope.$element.attr('readonly')).toEqual(null); - expect(scope.$element.attr('checked')).toEqual(null); + var scope = compile(''); + var input = scope.$element[0]; + expect(input.disabled).toEqual(false); + expect(input.readOnly).toEqual(false); + expect(input.checked).toEqual(false); 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); + expect(input.disabled).toEqual(true); + expect(input.readOnly).toEqual(true); + expect(input.checked).toEqual(true); }); it('should ng-non-bindable', function(){ diff --git a/test/testabilityPatch.js b/test/testabilityPatch.js index 1e6ed970..ff537a09 100644 --- a/test/testabilityPatch.js +++ b/test/testabilityPatch.js @@ -145,9 +145,9 @@ error = noop; function click(element) { element = jqLite(element); - if ( (msie || jqLite == window.jQuery) && + if ( msie && nodeName(element) == 'INPUT' && (lowercase(element.attr('type')) == 'radio' || lowercase(element.attr('type')) == 'checkbox')) { element[0].checked = ! element[0].checked; } - element.trigger('click'); + JQLite.prototype.trigger.call(element, 'click'); } diff --git a/test/widgetsSpec.js b/test/widgetsSpec.js index 3aa5e250..5b1e7b8e 100644 --- a/test/widgetsSpec.js +++ b/test/widgetsSpec.js @@ -160,7 +160,7 @@ describe("widget", function(){ it('should support type="radio"', function(){ compile('
                          ' + '' + - '' + + '' + '' + '
                          '); var a = element[0].childNodes[0]; -- cgit v1.2.3 From c29dc1a940950b558eae92ba976e2c2c5aceab58 Mon Sep 17 00:00:00 2001 From: Misko Hevery Date: Thu, 22 Apr 2010 22:48:48 -0700 Subject: fixed wrong tests which did not have matched tags --- test/widgetsSpec.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'test') diff --git a/test/widgetsSpec.js b/test/widgetsSpec.js index 5b1e7b8e..b38ca2a1 100644 --- a/test/widgetsSpec.js +++ b/test/widgetsSpec.js @@ -243,7 +243,7 @@ describe("widget", function(){ }); it("should match urls", function(){ - var scope = angular.compile('
                          {{params.name}}
                          '); + var scope = angular.compile('
                          {{params.name}}
                          '); scope.url = '/Book/Moby'; scope.$init(); expect(scope.$element.text()).toEqual('Moby'); @@ -256,7 +256,7 @@ describe("widget", function(){ }); it('should call init on switch', function(){ - var scope = angular.compile('
                          {{name}}
                          '); + var scope = angular.compile('
                          {{name}}
                          '); var cleared = false; scope.url = 'a'; scope.$invalidWidgets = {clearOrphans: function(){ -- cgit v1.2.3 From 02fa10f93ce5a75dd925f13ec7456802a6e120e4 Mon Sep 17 00:00:00 2001 From: Misko Hevery Date: Mon, 26 Apr 2010 11:57:33 -0700 Subject: allow the widget to change structure of the DOM and have the compiler follow the replaced element. --- test/CompilerSpec.js | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) (limited to 'test') diff --git a/test/CompilerSpec.js b/test/CompilerSpec.js index a212634a..2e1ae4ae 100644 --- a/test/CompilerSpec.js +++ b/test/CompilerSpec.js @@ -108,7 +108,7 @@ describe('compiler', function(){ it('should replace widgets', function(){ widgets['NG:BUTTON'] = function(element) { - element.replaceWith('
                          button
                          ', element); + element.replaceWith('
                          button
                          '); return function(element) { log += 'init'; }; @@ -118,4 +118,20 @@ describe('compiler', function(){ expect(log).toEqual('init'); }); + it('should use the replaced element after calling widget', function(){ + widgets['H1'] = function(element) { + var span = angular.element('{{1+2}}'); + element.replaceWith(span); + this.descend(true); + this.directives(true); + return noop; + }; + textMarkup.push(function(text, textNode, parent){ + if (text == '{{1+2}}') + textNode.text('3'); + }); + var scope = compile('

                          ignore me

                          '); + expect(scope.$element.text()).toEqual('3'); + }); + }); -- cgit v1.2.3 From b275403465cdc581804bc74bf12e243edd642a42 Mon Sep 17 00:00:00 2001 From: Misko Hevery Date: Mon, 26 Apr 2010 17:02:27 -0700 Subject: fix ie for jquery --- test/CompilerSpec.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'test') diff --git a/test/CompilerSpec.js b/test/CompilerSpec.js index 2e1ae4ae..da354ea5 100644 --- a/test/CompilerSpec.js +++ b/test/CompilerSpec.js @@ -128,7 +128,7 @@ describe('compiler', function(){ }; textMarkup.push(function(text, textNode, parent){ if (text == '{{1+2}}') - textNode.text('3'); + parent.text('3'); }); var scope = compile('

                          ignore me

                          '); expect(scope.$element.text()).toEqual('3'); -- cgit v1.2.3 From fce48eb60a47be87a3d95e0750e54c19c2a346d0 Mon Sep 17 00:00:00 2001 From: Misko Hevery Date: Tue, 27 Apr 2010 11:18:08 -0700 Subject: resources now use browser mock --- test/ResourceSpec.js | 13 +++++++------ test/angular-mocks.js | 20 +++++++++++++++++--- test/testabilityPatch.js | 9 +++++---- 3 files changed, 29 insertions(+), 13 deletions(-) (limited to 'test') diff --git a/test/ResourceSpec.js b/test/ResourceSpec.js index 91900a91..08ca86b3 100644 --- a/test/ResourceSpec.js +++ b/test/ResourceSpec.js @@ -60,8 +60,9 @@ describe("resource", function() { var xhr, resource, CreditCard, callback; beforeEach(function(){ - xhr = new MockXHR(); - resource = new ResourceFactory(bind(xhr, xhr.method)); + var browser = new MockBrowser(); + xhr = browser.xhr; + resource = new ResourceFactory(xhr); CreditCard = resource.route('/CreditCard/:id:verb', {id:'@id.key'}, { charge:{ method:'POST', @@ -95,7 +96,7 @@ describe("resource", function() { }); it("should create resource", function(){ - xhr.expectPOST('/CreditCard').data({name:'misko'}).respond({id:123, name:'misko'}); + xhr.expectPOST('/CreditCard', {name:'misko'}).respond({id:123, name:'misko'}); var cc = CreditCard.save({name:'misko'}, callback); nakedExpect(cc).toEqual({name:'misko'}); @@ -117,7 +118,7 @@ describe("resource", function() { }); it("should update resource", function(){ - xhr.expectPOST('/CreditCard/123').data({id:{key:123}, name:'misko'}).respond({id:{key:123}, name:'rama'}); + xhr.expectPOST('/CreditCard/123', {id:{key:123}, name:'misko'}).respond({id:{key:123}, name:'rama'}); var cc = CreditCard.save({id:{key:123}, name:'misko'}, callback); nakedExpect(cc).toEqual({id:{key:123}, name:'misko'}); @@ -148,13 +149,13 @@ describe("resource", function() { }); it('should post charge verb', function(){ - xhr.expectPOST('/CreditCard/123!charge?amount=10').data({auth:'abc'}).respond({success:'ok'}); + xhr.expectPOST('/CreditCard/123!charge?amount=10', {auth:'abc'}).respond({success:'ok'}); CreditCard.charge({id:123, amount:10},{auth:'abc'}, callback); }); it('should create on save', function(){ - xhr.expectPOST('/CreditCard').data({name:'misko'}).respond({id:123}); + xhr.expectPOST('/CreditCard', {name:'misko'}).respond({id:123}); var cc = new CreditCard(); expect(cc.$get).not.toBeDefined(); expect(cc.$query).not.toBeDefined(); diff --git a/test/angular-mocks.js b/test/angular-mocks.js index 3e272313..715b4d75 100644 --- a/test/angular-mocks.js +++ b/test/angular-mocks.js @@ -23,11 +23,19 @@ */ function MockBrowser() { - var self = this, expectations = {}, requests = []; + var self = this, + expectations = {}, + requests = []; self.url = "http://server"; self.watches = []; - self.xhr = function(method, url, callback) { + self.xhr = function(method, url, data, callback) { + if (isFunction(data)) { + callback = data; + data = null; + } + if (data && isObject(data)) data = angular.toJson(data); + if (data && isString(data)) url += "|" + data; var expect = expectations[method] || {}; var response = expect[url]; if (!response) { @@ -39,7 +47,9 @@ function MockBrowser() { }; self.xhr.expectations = expectations; self.xhr.requests = requests; - self.xhr.expect = function(method, url) { + self.xhr.expect = function(method, url, data) { + if (data && isObject(data)) data = angular.toJson(data); + if (data && isString(data)) url += "|" + data; var expect = expectations[method] || (expectations[method] = {}); return { respond: function(response) { @@ -47,6 +57,10 @@ function MockBrowser() { } }; }; + self.xhr.expectGET = angular.bind(self, self.xhr.expect, 'GET'); + self.xhr.expectPOST = angular.bind(self, self.xhr.expect, 'POST'); + self.xhr.expectDELETE = angular.bind(self, self.xhr.expect, 'DELETE'); + self.xhr.expectPUT = angular.bind(self, self.xhr.expect, 'PUT'); self.xhr.flush = function() { while(requests.length) { requests.pop()(); diff --git a/test/testabilityPatch.js b/test/testabilityPatch.js index ff537a09..572e6a36 100644 --- a/test/testabilityPatch.js +++ b/test/testabilityPatch.js @@ -10,20 +10,21 @@ function childNode(element, index) { } extend(angular, { - 'element': jqLite, + 'bind': bind, 'compile': compile, - 'scope': createScope, 'copy': copy, + 'element': jqLite, 'extend': extend, 'foreach': foreach, - 'noop':noop, 'identity':identity, 'isUndefined': isUndefined, 'isDefined': isDefined, 'isString': isString, 'isFunction': isFunction, 'isNumber': isNumber, - 'isArray': isArray + 'isArray': isArray, + 'noop':noop, + 'scope': createScope }); -- cgit v1.2.3 From 913729ee0120cc72e13b18d826c6da0fe2b98bf7 Mon Sep 17 00:00:00 2001 From: Misko Hevery Date: Thu, 29 Apr 2010 10:55:22 -0700 Subject: fix isssue where the jasmine currentSpec does not get updated and hence everything runs as last spec context. --- test/ResourceSpec.js | 58 ---------------------- test/servicesSpec.js | 136 +++++++++++++++++++++++++++------------------------ 2 files changed, 72 insertions(+), 122 deletions(-) (limited to 'test') diff --git a/test/ResourceSpec.js b/test/ResourceSpec.js index 08ca86b3..f2a0ff41 100644 --- a/test/ResourceSpec.js +++ b/test/ResourceSpec.js @@ -1,61 +1,3 @@ -function MockXHR(){ - this.expectations = { - 'GET': {}, - 'POST': {}, - 'DELETE': {} - }; - this.queue = []; -} -MockXHR.prototype = { - method: function(verb, url, data, callback) { - if (verb == 'POST') - url += '|' + angular.toJson(data); - var response = this.expectations[verb][url]; - if (!response) - throw "No expectation for " + verb + " on '" + url + "'."; - this.queue.push(function(){ - callback(response); - }); - }, - - expectGET: function(url) { - var self = this; - return { - respond: function(response){ - self.expectations.GET[url] = response; - } - }; - }, - - expectDELETE: function(url) { - var self = this; - return { - respond: function(response){ - self.expectations.DELETE[url] = response; - } - }; - }, - - expectPOST: function(url) { - var self = this; - return { - data: function(data){ - return { - respond: function(response){ - self.expectations.POST[url + '|' + angular.toJson(data)] = response; - } - }; - } - }; - }, - - flush: function(){ - while(this.queue.length) { - this.queue.shift()(); - } - } -}; - describe("resource", function() { var xhr, resource, CreditCard, callback; diff --git a/test/servicesSpec.js b/test/servicesSpec.js index f917f968..a7391f34 100644 --- a/test/servicesSpec.js +++ b/test/servicesSpec.js @@ -1,10 +1,17 @@ -describe("services", function(){ +describe("service", function(){ var scope; beforeEach(function(){ scope = createScope(null, angularService, {}); }); + afterEach(function(){ + if (scope && scope.$element) + scope.$element.remove(); + }); + + + it("should inject $window", function(){ expect(scope.$window).toEqual(window); }); @@ -82,75 +89,76 @@ describe("services", function(){ }); }); -}); -describe("service $invalidWidgets", function(){ - var scope; - beforeEach(function(){ - scope = null; - }); - afterEach(function(){ - if (scope && scope.$element) + describe("$invalidWidgets", function(){ + it("should count number of invalid widgets", function(){ + var scope = compile('').$init(); + expect(scope.$invalidWidgets.length).toEqual(1); + scope.price = 123; + scope.$eval(); + expect(scope.$invalidWidgets.length).toEqual(0); scope.$element.remove(); + scope.price = 'abc'; + scope.$eval(); + expect(scope.$invalidWidgets.length).toEqual(1); + + jqLite(document.body).append(scope.$element); + scope.$invalidWidgets.clearOrphans(); + expect(scope.$invalidWidgets.length).toEqual(1); + + jqLite(document.body).html(''); + scope.$invalidWidgets.clearOrphans(); + expect(scope.$invalidWidgets.length).toEqual(0); + }); }); - it("should count number of invalid widgets", function(){ - var scope = compile('').$init(); - expect(scope.$invalidWidgets.length).toEqual(1); - scope.price = 123; - scope.$eval(); - expect(scope.$invalidWidgets.length).toEqual(0); - scope.$element.remove(); - scope.price = 'abc'; - scope.$eval(); - expect(scope.$invalidWidgets.length).toEqual(1); - - jqLite(document.body).append(scope.$element); - scope.$invalidWidgets.clearOrphans(); - expect(scope.$invalidWidgets.length).toEqual(1); - - jqLite(document.body).html(''); - scope.$invalidWidgets.clearOrphans(); - expect(scope.$invalidWidgets.length).toEqual(0); + + describe("$route", function(){ + it('should route and fire change event', function(){ + var log = ''; + function BookChapter() { + this.log = ''; + } + BookChapter.prototype.init = function(){ + log += 'init();'; + }; + var scope = compile('
                          ').$init(); + scope.$route.when('/Book/:book/Chapter/:chapter', {controller: BookChapter, template:'Chapter.html'}); + scope.$route.when('/Blank'); + scope.$route.onChange(function(){ + log += 'onChange();'; + }); + scope.$location.parse('http://server#/Book/Moby/Chapter/Intro?p=123'); + scope.$eval(); + expect(log).toEqual('onChange();init();'); + expect(scope.$route.current.params).toEqual({book:'Moby', chapter:'Intro', p:'123'}); + expect(scope.$route.current.scope.log).toEqual(''); + var lastId = scope.$route.current.scope.$id; + + log = ''; + scope.$location.parse('http://server#/Blank?ignore'); + scope.$eval(); + expect(log).toEqual('onChange();'); + expect(scope.$route.current.params).toEqual({ignore:true}); + expect(scope.$route.current.scope.$id).not.toEqual(lastId); + + log = ''; + scope.$location.parse('http://server#/NONE'); + scope.$eval(); + 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'); + }); }); -}); -describe("service $route", function(){ - it('should route and fire change event', function(){ - var log = ''; - function BookChapter() { - this.log = ''; - } - BookChapter.prototype.init = function(){ - log += 'init();'; - }; - var scope = compile('
                          ').$init(); - scope.$route.when('/Book/:book/Chapter/:chapter', {controller: BookChapter, template:'Chapter.html'}); - scope.$route.when('/Blank'); - scope.$route.onChange(function(){ - log += 'onChange();'; + describe('$resource', function(){ + it('should publish to root scope', function(){ + expect(scope.$resource).toBeTruthy(); }); - scope.$location.parse('http://server#/Book/Moby/Chapter/Intro?p=123'); - scope.$eval(); - expect(log).toEqual('onChange();init();'); - expect(scope.$route.current.params).toEqual({book:'Moby', chapter:'Intro', p:'123'}); - expect(scope.$route.current.scope.log).toEqual(''); - var lastId = scope.$route.current.scope.$id; - - log = ''; - scope.$location.parse('http://server#/Blank?ignore'); - scope.$eval(); - expect(log).toEqual('onChange();'); - expect(scope.$route.current.params).toEqual({ignore:true}); - expect(scope.$route.current.scope.$id).not.toEqual(lastId); - - log = ''; - scope.$location.parse('http://server#/NONE'); - scope.$eval(); - 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'); }); + }); + + -- cgit v1.2.3 From c7913a4b7a3f5ffb0ea6bb1e636ac9d4a0e75c32 Mon Sep 17 00:00:00 2001 From: Misko Hevery Date: Thu, 29 Apr 2010 17:28:33 -0700 Subject: added $xhr service with bulk and cache, hooked up $resource --- test/ResourceSpec.js | 9 ++++++ test/servicesSpec.js | 82 ++++++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 91 insertions(+) (limited to 'test') diff --git a/test/ResourceSpec.js b/test/ResourceSpec.js index f2a0ff41..f0bb6770 100644 --- a/test/ResourceSpec.js +++ b/test/ResourceSpec.js @@ -120,4 +120,13 @@ describe("resource", function() { nakedExpect(visa).toEqual({id:123}); }); + it('should excersize full stack', function(){ + var scope = angular.compile('
                          '); + var Person = scope.$resource('/Person/:id'); + scope.$browser.xhr.expectGET('/Person/123').respond('\n{\nname:\n"misko"\n}\n'); + var person = Person.get({id:123}); + scope.$browser.xhr.flush(); + expect(person.name).toEqual('misko'); + }); + }); diff --git a/test/servicesSpec.js b/test/servicesSpec.js index a7391f34..f15d6ad7 100644 --- a/test/servicesSpec.js +++ b/test/servicesSpec.js @@ -159,6 +159,88 @@ describe("service", function(){ }); }); + describe('$xhr', function(){ + var log, xhr; + function callback(code, response) { + expect(code).toEqual(200); + log = log + toJson(response) + ';'; + }; + + beforeEach(function(){ + log = ''; + xhr = scope.$browser.xhr; + }); + + it('should forward the request to $browser and decode JSON', function(){ + xhr.expectGET('/reqGET').respond('first'); + xhr.expectGET('/reqGETjson').respond('["second"]'); + xhr.expectPOST('/reqPOST', {post:'data'}).respond('third'); + + scope.$xhr('GET', '/reqGET', null, callback); + scope.$xhr('GET', '/reqGETjson', null, callback); + scope.$xhr('POST', '/reqPOST', {post:'data'}, callback); + + xhr.flush(); + + expect(log).toEqual('"third";["second"];"first";'); + }); + + describe('bulk', function(){ + it('should collect requests', function(){ + scope.$xhr.bulk.url = "/"; + scope.$xhr.bulk('GET', '/req1', null, callback); + scope.$xhr.bulk('POST', '/req2', {post:'data'}, callback); + + xhr.expectPOST('/', { + requests:[{method:'GET', url:'/req1', data: null}, + {method:'POST', url:'/req2', data:{post:'data'} }] + }).respond([ + {status:200, response:'first'}, + {status:200, response:'second'} + ]); + scope.$xhr.bulk.flush(function(){ log += 'DONE';}); + xhr.flush(); + expect(log).toEqual('"first";"second";DONE'); + }); + }); + + describe('cache', function(){ + var cache; + beforeEach(function(){ cache = scope.$xhr.cache; }); + it('should cache requests', function(){ + xhr.expectGET('/url').respond('first'); + cache('GET', '/url', null, callback); + xhr.flush(); + xhr.expectGET('/url').respond('ERROR'); + cache('GET', '/url', null, callback); + xhr.flush(); + expect(log).toEqual('"first";"first";'); + }); + + it('should serve requests from cache', function(){ + cache.data.url = {value:'123'}; + cache('GET', 'url', null, callback); + expect(log).toEqual('"123";'); + }); + + it('should keep track of in flight requests and request only once', function(){ + cache.delegate = scope.$xhr.bulk; + xhr.expectPOST('/bulk', { + requests:[{method:'GET', url:'/url', data: null}] + }).respond([ + {status:200, response:'123'}, + ]); + cache('GET', '/url', null, callback); + cache('GET', '/url', null, callback); + cache.delegate.flush(); + xhr.flush(); + expect(log).toEqual('"123";"123";'); + }); + }); + + }); + + }); -- cgit v1.2.3 From 549ff73a9b66e718383c79ccd7c28e4f9b25632d Mon Sep 17 00:00:00 2001 From: Misko Hevery Date: Fri, 30 Apr 2010 10:27:41 -0700 Subject: clear cache on non-get --- test/servicesSpec.js | 8 ++++++++ 1 file changed, 8 insertions(+) (limited to 'test') diff --git a/test/servicesSpec.js b/test/servicesSpec.js index f15d6ad7..112fc374 100644 --- a/test/servicesSpec.js +++ b/test/servicesSpec.js @@ -207,6 +207,7 @@ describe("service", function(){ describe('cache', function(){ var cache; beforeEach(function(){ cache = scope.$xhr.cache; }); + it('should cache requests', function(){ xhr.expectGET('/url').respond('first'); cache('GET', '/url', null, callback); @@ -236,6 +237,13 @@ describe("service", function(){ xhr.flush(); expect(log).toEqual('"123";"123";'); }); + + it('should clear cache on non GET', function(){ + xhr.expectPOST('abc', {}).respond({}); + cache.data.url = {value:123}; + cache('POST', 'abc', {}); + expect(cache.data.url).toBeUndefined(); + }); }); }); -- cgit v1.2.3 From ac1d02d0658cb74ae3822e364f84809d78cda335 Mon Sep 17 00:00:00 2001 From: Misko Hevery Date: Fri, 30 Apr 2010 12:22:07 -0700 Subject: make xhr post optional --- test/widgetsSpec.js | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) (limited to 'test') diff --git a/test/widgetsSpec.js b/test/widgetsSpec.js index b38ca2a1..c9665f1e 100644 --- a/test/widgetsSpec.js +++ b/test/widgetsSpec.js @@ -276,9 +276,8 @@ describe("widget", function(){ scope.childScope = createScope(); scope.childScope.name = 'misko'; scope.url = 'myUrl'; - scope.$browser.xhr.expect('GET', 'myUrl').respond('{{name}}'); + scope.$xhr.cache.data.myUrl = {value:'{{name}}'}; scope.$init(); - scope.$browser.xhr.flush(); expect(element.text()).toEqual('misko'); }); }); -- cgit v1.2.3 From 038a743e6f49c347a38edc0e54dcbb175905a475 Mon Sep 17 00:00:00 2001 From: Misko Hevery Date: Fri, 7 May 2010 12:09:14 -0700 Subject: xhr bulk fixes --- test/AngularSpec.js | 8 ++++++++ test/JsonTest.js | 10 +++++++--- test/ResourceSpec.js | 9 +++++++++ test/angular-mocks.js | 11 ++++++----- test/servicesSpec.js | 9 +++++++-- test/testabilityPatch.js | 1 + 6 files changed, 38 insertions(+), 10 deletions(-) (limited to 'test') diff --git a/test/AngularSpec.js b/test/AngularSpec.js index 60079c47..de724f03 100644 --- a/test/AngularSpec.js +++ b/test/AngularSpec.js @@ -41,4 +41,12 @@ describe("copy", function(){ assertEquals(src.a, dst.a); assertNotSame(src.a, dst.a); }); + + it("should copy primitives", function(){ + expect(copy(null)).toEqual(null); + expect(copy('')).toEqual(''); + expect(copy(123)).toEqual(123); + expect(copy([{key:null}])).toEqual([{key:null}]); + }); + }); diff --git a/test/JsonTest.js b/test/JsonTest.js index 9b275248..1ed56da8 100644 --- a/test/JsonTest.js +++ b/test/JsonTest.js @@ -63,9 +63,9 @@ JsonTest.prototype.testItShouldEscapeUnicode = function () { JsonTest.prototype.testItShouldUTCDates = function() { var date = angular.String.toDate("2009-10-09T01:02:03Z"); - assertEquals('"2009-10-09T01:02:03Z"', toJson(date)); - assertEquals(date.getTime(), - fromJson('"2009-10-09T01:02:03Z"').getTime()); + assertEquals('"2009-10-09T01:02:03Z"', toJson(date)); + assertEquals(date.getTime(), + fromJson('"2009-10-09T01:02:03Z"').getTime()); }; JsonTest.prototype.testItShouldPreventRecursion = function () { @@ -78,3 +78,7 @@ JsonTest.prototype.testItShouldSerializeSameObjectsMultipleTimes = function () { var obj = {a:'b'}; assertEquals('{"A":{"a":"b"},"B":{"a":"b"}}', angular.toJson({A:obj, B:obj})); }; + +JsonTest.prototype.testItShouldNotSerializeUndefinedValues = function () { + assertEquals('{}', angular.toJson({A:undefined})); +}; diff --git a/test/ResourceSpec.js b/test/ResourceSpec.js index f0bb6770..d2d52d47 100644 --- a/test/ResourceSpec.js +++ b/test/ResourceSpec.js @@ -81,6 +81,15 @@ describe("resource", function() { expect(callback).wasCalledWith(ccs); }); + it("should have all arguments optional", function(){ + xhr.expectGET('/CreditCard').respond([{id:1}]); + var log = ''; + var ccs = CreditCard.query(function(){ log += 'cb;'; }); + xhr.flush(); + nakedExpect(ccs).toEqual([{id:1}]); + expect(log).toEqual('cb;'); + }); + it('should delete resource', function(){ xhr.expectDELETE("/CreditCard/123").respond({}); diff --git a/test/angular-mocks.js b/test/angular-mocks.js index 715b4d75..6ae91596 100644 --- a/test/angular-mocks.js +++ b/test/angular-mocks.js @@ -26,16 +26,17 @@ function MockBrowser() { var self = this, expectations = {}, requests = []; + this.isMock = true; self.url = "http://server"; self.watches = []; self.xhr = function(method, url, data, callback) { - if (isFunction(data)) { + if (angular.isFunction(data)) { callback = data; data = null; } - if (data && isObject(data)) data = angular.toJson(data); - if (data && isString(data)) url += "|" + data; + if (data && angular.isObject(data)) data = angular.toJson(data); + if (data && angular.isString(data)) url += "|" + data; var expect = expectations[method] || {}; var response = expect[url]; if (!response) { @@ -48,8 +49,8 @@ function MockBrowser() { self.xhr.expectations = expectations; self.xhr.requests = requests; self.xhr.expect = function(method, url, data) { - if (data && isObject(data)) data = angular.toJson(data); - if (data && isString(data)) url += "|" + data; + if (data && angular.isObject(data)) data = angular.toJson(data); + if (data && angular.isString(data)) url += "|" + data; var expect = expectations[method] || (expectations[method] = {}); return { respond: function(response) { diff --git a/test/servicesSpec.js b/test/servicesSpec.js index 112fc374..794d1120 100644 --- a/test/servicesSpec.js +++ b/test/servicesSpec.js @@ -149,6 +149,7 @@ describe("service", function(){ expect(scope.$route.current).toEqual(null); scope.$route.when('/NONE', {template:'instant update'}); + scope.$eval(); expect(scope.$route.current.template).toEqual('instant update'); }); }); @@ -187,7 +188,7 @@ describe("service", function(){ describe('bulk', function(){ it('should collect requests', function(){ - scope.$xhr.bulk.url = "/"; + scope.$xhr.bulk.urls["/"] = {match:/.*/}; scope.$xhr.bulk('GET', '/req1', null, callback); scope.$xhr.bulk('POST', '/req2', {post:'data'}, callback); @@ -225,7 +226,11 @@ describe("service", function(){ }); it('should keep track of in flight requests and request only once', function(){ - cache.delegate = scope.$xhr.bulk; + scope.$xhr.bulk.urls['/bulk'] = { + match:function(url){ + return url == '/url'; + } + }; xhr.expectPOST('/bulk', { requests:[{method:'GET', url:'/url', data: null}] }).respond([ diff --git a/test/testabilityPatch.js b/test/testabilityPatch.js index 572e6a36..4d129f60 100644 --- a/test/testabilityPatch.js +++ b/test/testabilityPatch.js @@ -19,6 +19,7 @@ extend(angular, { 'identity':identity, 'isUndefined': isUndefined, 'isDefined': isDefined, + 'isObject': isObject, 'isString': isString, 'isFunction': isFunction, 'isNumber': isNumber, -- cgit v1.2.3 From 0305b6746e2c50960b042c5d687794e030930f8b Mon Sep 17 00:00:00 2001 From: Misko Hevery Date: Fri, 7 May 2010 13:43:54 -0700 Subject: change everything over to jasmine --- test/directivesSpec.js | 9 +++++++++ 1 file changed, 9 insertions(+) (limited to 'test') diff --git a/test/directivesSpec.js b/test/directivesSpec.js index eb8a9785..42869a05 100644 --- a/test/directivesSpec.js +++ b/test/directivesSpec.js @@ -44,6 +44,15 @@ describe("directives", function(){ expect(lowercase(element.html())).toEqual('
                          hello
                          '); }); + it('should ng-bind element', function() { + angularFilter.myElement = function() { + return jqLite('hello'); + }; + var scope = compile('
                          '); + scope.$eval(); + expect(lowercase(element.html())).toEqual('hello'); + }); + it('should ng-bind-template', function() { var scope = compile('
                          '); scope.$set('name', 'Misko'); -- cgit v1.2.3 From 4542716370ac52f385795f509436104a2a3501d2 Mon Sep 17 00:00:00 2001 From: Misko Hevery Date: Mon, 10 May 2010 10:36:02 -0700 Subject: lint --- test/servicesSpec.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'test') diff --git a/test/servicesSpec.js b/test/servicesSpec.js index 112fc374..7b17e150 100644 --- a/test/servicesSpec.js +++ b/test/servicesSpec.js @@ -164,7 +164,7 @@ describe("service", function(){ function callback(code, response) { expect(code).toEqual(200); log = log + toJson(response) + ';'; - }; + } beforeEach(function(){ log = ''; @@ -229,7 +229,7 @@ describe("service", function(){ xhr.expectPOST('/bulk', { requests:[{method:'GET', url:'/url', data: null}] }).respond([ - {status:200, response:'123'}, + {status:200, response:'123'} ]); cache('GET', '/url', null, callback); cache('GET', '/url', null, callback); -- cgit v1.2.3 From 5dda723185a9037b7e92828d32430c21838ee216 Mon Sep 17 00:00:00 2001 From: Misko Hevery Date: Mon, 10 May 2010 20:24:20 -0700 Subject: improved handling of text fields when formater fails to prevent clobering of field --- test/testabilityPatch.js | 25 +++++++ test/widgetsSpec.js | 169 +++++++++++++++++++++++++++++------------------ 2 files changed, 130 insertions(+), 64 deletions(-) (limited to 'test') diff --git a/test/testabilityPatch.js b/test/testabilityPatch.js index 4d129f60..d621b1f1 100644 --- a/test/testabilityPatch.js +++ b/test/testabilityPatch.js @@ -1,6 +1,31 @@ jstd = jstestdriver; dump = bind(jstd.console, jstd.console.log); +beforeEach(function(){ + this.addMatchers({ + toBeInvalid: function(){ + var element = jqLite(this.actual); + var hasClass = element.hasClass('ng-validation-error'); + var validationError = element.attr('ng-validation-error'); + this.message = function(){ + if (!hasClass) + return "Expected class 'ng-validation-error' not found."; + return "Expected an error message, but none was found."; + }; + return hasClass && validationError; + }, + + toBeValid: function(){ + var element = jqLite(this.actual); + var hasClass = element.hasClass('ng-validation-error'); + this.message = function(){ + return "Expected to not have class 'ng-validation-error' but found."; + }; + return !hasClass; + } + }); +}); + function nakedExpect(obj) { return expect(angular.fromJson(angular.toJson(obj))); } diff --git a/test/widgetsSpec.js b/test/widgetsSpec.js index c9665f1e..b365175d 100644 --- a/test/widgetsSpec.js +++ b/test/widgetsSpec.js @@ -20,74 +20,115 @@ describe("widget", function(){ describe("input", function(){ - it('should input-text auto init and handle keyup/change events', function(){ - compile(''); - expect(scope.$get('name')).toEqual("Misko"); - expect(scope.$get('count')).toEqual(0); - - scope.$set('name', 'Adam'); - scope.$eval(); - expect(element.val()).toEqual("Adam"); - - element.val('Shyam'); - element.trigger('keyup'); - expect(scope.$get('name')).toEqual('Shyam'); - expect(scope.$get('count')).toEqual(1); - - element.val('Kai'); - element.trigger('change'); - expect(scope.$get('name')).toEqual('Kai'); - expect(scope.$get('count')).toEqual(2); - }); - - it("should process ng-format", function(){ - compile(''); - expect(scope.$get('list')).toEqual(['a', 'b', 'c']); - - scope.$set('list', ['x', 'y', 'z']); - scope.$eval(); - expect(element.val()).toEqual("x, y, z"); - - element.val('1, 2, 3'); - element.trigger('keyup'); - expect(scope.$get('list')).toEqual(['1', '2', '3']); - }); - - it("should process ng-format for booleans", function(){ - compile('', function(){ - scope.name = false; + describe("text", function(){ + it('should input-text auto init and handle keyup/change events', function(){ + compile(''); + expect(scope.$get('name')).toEqual("Misko"); + expect(scope.$get('count')).toEqual(0); + + scope.$set('name', 'Adam'); + scope.$eval(); + expect(element.val()).toEqual("Adam"); + + element.val('Shyam'); + element.trigger('keyup'); + expect(scope.$get('name')).toEqual('Shyam'); + expect(scope.$get('count')).toEqual(1); + + element.val('Kai'); + element.trigger('change'); + expect(scope.$get('name')).toEqual('Kai'); + expect(scope.$get('count')).toEqual(2); }); - expect(scope.name).toEqual(false); - expect(scope.$element[0].checked).toEqual(false); - }); - it("should process ng-validate", function(){ - compile(''); - expect(element.hasClass('ng-validation-error')).toBeTruthy(); - expect(element.attr('ng-validation-error')).toEqual('Not a number'); - - scope.$set('price', '123'); - scope.$eval(); - expect(element.hasClass('ng-validation-error')).toBeFalsy(); - expect(element.attr('ng-validation-error')).toBeFalsy(); + describe("ng-format", function(){ + + it("should farmat text", function(){ + compile(''); + expect(scope.$get('list')).toEqual(['a', 'b', 'c']); + + scope.$set('list', ['x', 'y', 'z']); + scope.$eval(); + expect(element.val()).toEqual("x, y, z"); + + element.val('1, 2, 3'); + element.trigger('keyup'); + expect(scope.$get('list')).toEqual(['1', '2', '3']); + }); + + it("should format booleans", function(){ + compile('', function(){ + scope.name = false; + }); + expect(scope.name).toEqual(false); + expect(scope.$element[0].checked).toEqual(false); + }); + + it("should come up blank if null", function(){ + compile('', function(){ + scope.age = null; + }); + expect(scope.age).toBeNull(); + expect(scope.$element[0].value).toEqual(''); + }); + + it("should show incorect text while number does not parse", function(){ + compile(''); + scope.age = 123; + scope.$eval(); + scope.$element.val('123X'); + scope.$element.trigger('change'); + expect(scope.$element.val()).toEqual('123X'); + expect(scope.age).toEqual(123); + expect(scope.$element).toBeInvalid(); + }); + + it("should clober incorect text if model changes", function(){ + compile(''); + scope.age = 456; + scope.$eval(); + expect(scope.$element.val()).toEqual('456'); + }); + + it("should come up blank when no value specifiend", function(){ + compile(''); + scope.$eval(); + expect(scope.$element.val()).toEqual(''); + expect(scope.age).toEqual(null); + }); - element.val('x'); - element.trigger('keyup'); - expect(element.hasClass('ng-validation-error')).toBeTruthy(); - expect(element.attr('ng-validation-error')).toEqual('Not a number'); - }); - - it("should not call validator if undefinde/empty", function(){ - var lastValue = "NOT_CALLED"; - angularValidator.myValidator = function(value){lastValue = value;}; - compile(''); - expect(lastValue).toEqual("NOT_CALLED"); - - scope.url = 'http://server'; - scope.$eval(); - expect(lastValue).toEqual("http://server"); + }); - delete angularValidator.myValidator; + describe("ng-validate", function(){ + it("should process ng-validate", function(){ + compile(''); + expect(element.hasClass('ng-validation-error')).toBeTruthy(); + expect(element.attr('ng-validation-error')).toEqual('Not a number'); + + scope.$set('price', '123'); + scope.$eval(); + expect(element.hasClass('ng-validation-error')).toBeFalsy(); + expect(element.attr('ng-validation-error')).toBeFalsy(); + + element.val('x'); + element.trigger('keyup'); + expect(element.hasClass('ng-validation-error')).toBeTruthy(); + expect(element.attr('ng-validation-error')).toEqual('Not a number'); + }); + + it("should not call validator if undefinde/empty", function(){ + var lastValue = "NOT_CALLED"; + angularValidator.myValidator = function(value){lastValue = value;}; + compile(''); + expect(lastValue).toEqual("NOT_CALLED"); + + scope.url = 'http://server'; + scope.$eval(); + expect(lastValue).toEqual("http://server"); + + delete angularValidator.myValidator; + }); + }); }); it("should ignore disabled widgets", function(){ -- cgit v1.2.3 From d5ba889f63d3ce8abe49c24695f5f5c964b40264 Mon Sep 17 00:00:00 2001 From: Misko Hevery Date: Wed, 12 May 2010 15:25:16 -0700 Subject: fixes issues where the field clobbers itself --- test/widgetsSpec.js | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) (limited to 'test') diff --git a/test/widgetsSpec.js b/test/widgetsSpec.js index b365175d..9df024cb 100644 --- a/test/widgetsSpec.js +++ b/test/widgetsSpec.js @@ -90,6 +90,30 @@ describe("widget", function(){ expect(scope.$element.val()).toEqual('456'); }); + it("should not clober text if model changes doe to itself", function(){ + compile(''); + + scope.$element.val('a '); + scope.$element.trigger('change'); + expect(scope.$element.val()).toEqual('a '); + expect(scope.list).toEqual(['a']); + + scope.$element.val('a ,'); + scope.$element.trigger('change'); + expect(scope.$element.val()).toEqual('a ,'); + expect(scope.list).toEqual(['a']); + + scope.$element.val('a , '); + scope.$element.trigger('change'); + expect(scope.$element.val()).toEqual('a , '); + expect(scope.list).toEqual(['a']); + + scope.$element.val('a , b'); + scope.$element.trigger('change'); + expect(scope.$element.val()).toEqual('a , b'); + expect(scope.list).toEqual(['a', 'b']); + }); + it("should come up blank when no value specifiend", function(){ compile(''); scope.$eval(); -- cgit v1.2.3 From 4b9b9e98300b9554faf0c960674eb75750227404 Mon Sep 17 00:00:00 2001 From: Misko Hevery Date: Thu, 13 May 2010 12:03:10 -0700 Subject: fix incorect parsing of url if it contains dash - character --- test/servicesSpec.js | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) (limited to 'test') diff --git a/test/servicesSpec.js b/test/servicesSpec.js index de2d2b2b..17f71bdc 100644 --- a/test/servicesSpec.js +++ b/test/servicesSpec.js @@ -88,6 +88,14 @@ describe("service", function(){ expect(log).toEqual('/abc;'); }); + it("should parse url which contains - in host", function(){ + scope.$location.parse('http://a-b1.c-d.09/path'); + expect(scope.$location.href).toEqual('http://a-b1.c-d.09/path'); + expect(scope.$location.protocol).toEqual('http'); + expect(scope.$location.host).toEqual('a-b1.c-d.09'); + expect(scope.$location.path).toEqual('/path'); + }); + }); describe("$invalidWidgets", function(){ @@ -255,5 +263,3 @@ describe("service", function(){ }); - - -- cgit v1.2.3 From 22d1464d7abc284dd56d6beaf47e8d85088e01c5 Mon Sep 17 00:00:00 2001 From: Misko Hevery Date: Thu, 13 May 2010 13:57:39 -0700 Subject: fixed issue with radio view clobering model if radio was checked. --- test/ScopeSpec.js | 213 ++++++++++++++++++++++++++++------------------------ test/widgetsSpec.js | 70 +++++++++++------ 2 files changed, 162 insertions(+), 121 deletions(-) (limited to 'test') diff --git a/test/ScopeSpec.js b/test/ScopeSpec.js index 23638b27..a3b6d9ae 100644 --- a/test/ScopeSpec.js +++ b/test/ScopeSpec.js @@ -15,133 +15,146 @@ describe('scope/model', function(){ expect(model.$root).toEqual(model); }); - //$eval - it('should eval function with correct this and pass arguments', function(){ - var model = createScope(); - model.$eval(function(name){ - this.name = name; - }, 'works'); - expect(model.name).toEqual('works'); - }); + describe('$eval', function(){ + it('should eval function with correct this and pass arguments', function(){ + var model = createScope(); + model.$eval(function(name){ + this.name = name; + }, 'works'); + expect(model.name).toEqual('works'); + }); - it('should eval expression with correct this', function(){ - var model = createScope(); - model.$eval('name="works"'); - expect(model.name).toEqual('works'); - }); + it('should eval expression with correct this', function(){ + var model = createScope(); + model.$eval('name="works"'); + expect(model.name).toEqual('works'); + }); - //$watch - it('should watch an expression for change', function(){ - var model = createScope(); - model.oldValue = ""; - var nameCount = 0, evalCount = 0; - model.name = 'adam'; - model.$watch('name', function(){ nameCount ++; }); - model.$watch(function(){return model.name;}, function(newValue, oldValue){ - this.newValue = newValue; - this.oldValue = oldValue; + it('should do nothing on empty string and not update view', function(){ + var model = createScope(); + var onEval = jasmine.createSpy('onEval'); + model.$onEval(onEval); + model.$eval(''); + expect(onEval).wasNotCalled(); }); - model.$onEval(function(){evalCount ++;}); - model.name = 'misko'; - model.$eval(); - expect(nameCount).toEqual(2); - expect(evalCount).toEqual(1); - expect(model.newValue).toEqual('misko'); - expect(model.oldValue).toEqual('adam'); }); - it('should eval with no arguments', function(){ - var model = createScope(); - var count = 0; - model.$onEval(function(){count++;}); - model.$eval(); - expect(count).toEqual(1); - }); + describe('$watch', function(){ + it('should watch an expression for change', function(){ + var model = createScope(); + model.oldValue = ""; + var nameCount = 0, evalCount = 0; + model.name = 'adam'; + model.$watch('name', function(){ nameCount ++; }); + model.$watch(function(){return model.name;}, function(newValue, oldValue){ + this.newValue = newValue; + this.oldValue = oldValue; + }); + model.$onEval(function(){evalCount ++;}); + model.name = 'misko'; + model.$eval(); + expect(nameCount).toEqual(2); + expect(evalCount).toEqual(1); + expect(model.newValue).toEqual('misko'); + expect(model.oldValue).toEqual('adam'); + }); - //$bind - it('should curry a function with respect to scope', function(){ - var model = createScope(); - model.name = 'misko'; - expect(model.$bind(function(){return this.name;})()).toEqual('misko'); + it('should eval with no arguments', function(){ + var model = createScope(); + var count = 0; + model.$onEval(function(){count++;}); + model.$eval(); + expect(count).toEqual(1); + }); }); - //$tryEval - it('should report error on element', function(){ - var scope = createScope(); - scope.$tryEval('throw "myerror";', function(error){ - scope.error = error; + describe('$bind', function(){ + it('should curry a function with respect to scope', function(){ + var model = createScope(); + model.name = 'misko'; + expect(model.$bind(function(){return this.name;})()).toEqual('misko'); }); - expect(scope.error).toEqual('myerror'); }); - it('should report error on visible element', function(){ - var element = jqLite('
                          '); - var scope = createScope(); - scope.$tryEval('throw "myError"', element); - expect(element.attr('ng-exception')).toEqual('"myError"'); // errors are jsonified - expect(element.hasClass('ng-exception')).toBeTruthy(); - }); + describe('$tryEval', function(){ + it('should report error on element', function(){ + var scope = createScope(); + scope.$tryEval('throw "myerror";', function(error){ + scope.error = error; + }); + expect(scope.error).toEqual('myerror'); + }); - it('should report error on $excetionHandler', function(){ - var element = jqLite('
                          '); - var scope = createScope(); - scope.$exceptionHandler = function(e){ - this.error = e; - }; - scope.$tryEval('throw "myError"'); - expect(scope.error).toEqual("myError"); + it('should report error on visible element', function(){ + var element = jqLite('
                          '); + var scope = createScope(); + scope.$tryEval('throw "myError"', element); + expect(element.attr('ng-exception')).toEqual('"myError"'); // errors are jsonified + expect(element.hasClass('ng-exception')).toBeTruthy(); + }); + + it('should report error on $excetionHandler', function(){ + var element = jqLite('
                          '); + var scope = createScope(); + scope.$exceptionHandler = function(e){ + this.error = e; + }; + scope.$tryEval('throw "myError"'); + expect(scope.error).toEqual("myError"); + }); }); // $onEval + describe('$onEval', function(){ + it("should eval using priority", function(){ + var scope = createScope(); + scope.log = ""; + scope.$onEval('log = log + "middle;"'); + scope.$onEval(-1, 'log = log + "first;"'); + scope.$onEval(1, 'log = log + "last;"'); + scope.$eval(); + expect(scope.log).toEqual('first;middle;last;'); + }); - it("should eval using priority", function(){ - var scope = createScope(); - scope.log = ""; - scope.$onEval('log = log + "middle;"'); - scope.$onEval(-1, 'log = log + "first;"'); - scope.$onEval(1, 'log = log + "last;"'); - scope.$eval(); - expect(scope.log).toEqual('first;middle;last;'); - }); - - it("should have $root and $parent", function(){ - var parent = createScope(); - var scope = createScope(parent); - expect(scope.$root).toEqual(parent); - expect(scope.$parent).toEqual(parent); + it("should have $root and $parent", function(){ + var parent = createScope(); + var scope = createScope(parent); + expect(scope.$root).toEqual(parent); + expect(scope.$parent).toEqual(parent); + }); }); - // Service injection - it('should inject services', function(){ - var scope = createScope(null, { - service:function(){ + describe('service injection', function(){ + it('should inject services', function(){ + var scope = createScope(null, { + service:function(){ return "ABC"; } + }); + expect(scope.service).toEqual("ABC"); }); - expect(scope.service).toEqual("ABC"); - }); - it('should inject arugments', function(){ - var scope = createScope(null, { - name:function(){ + it('should inject arugments', function(){ + var scope = createScope(null, { + name:function(){ return "misko"; }, greet: extend(function(name) { return 'hello ' + name; }, {inject:['name']}) - }); - expect(scope.greet).toEqual("hello misko"); - }); - - it('should throw error on missing dependency', function(){ - try { - createScope(null, { - greet: extend(function(name) { - }, {inject:['name']}) }); - } catch(e) { - expect(e).toEqual("Don't know how to inject 'name'."); - } - }); + expect(scope.greet).toEqual("hello misko"); + }); + it('should throw error on missing dependency', function(){ + try { + createScope(null, { + greet: extend(function(name) { + }, {inject:['name']}) + }); + } catch(e) { + expect(e).toEqual("Don't know how to inject 'name'."); + } + }); + }); }); diff --git a/test/widgetsSpec.js b/test/widgetsSpec.js index 9df024cb..ecea6223 100644 --- a/test/widgetsSpec.js +++ b/test/widgetsSpec.js @@ -8,7 +8,7 @@ describe("widget", function(){ compile = function(html, before) { element = jqLite(html); scope = compiler.compile(element)(element); - (before||noop)(); + (before||noop).apply(scope); scope.$init(); }; }); @@ -222,29 +222,57 @@ describe("widget", function(){ expect(scope.checkbox).toEqual(true); }); - it('should support type="radio"', function(){ - compile('
                          ' + - '' + - '' + - '' + + describe('radio', function(){ + + it('should support type="radio"', function(){ + compile('
                          ' + + '' + + '' + + '' + '
                          '); - var a = element[0].childNodes[0]; - var b = element[0].childNodes[1]; - expect(b.name.split('@')[1]).toEqual('chose'); - expect(scope.chose).toEqual('B'); - scope.chose = 'A'; - scope.$eval(); - expect(a.checked).toEqual(true); + var a = element[0].childNodes[0]; + var b = element[0].childNodes[1]; + expect(b.name.split('@')[1]).toEqual('chose'); + expect(scope.chose).toEqual('B'); + scope.chose = 'A'; + scope.$eval(); + expect(a.checked).toEqual(true); - scope.chose = 'B'; - scope.$eval(); - expect(a.checked).toEqual(false); - expect(b.checked).toEqual(true); - expect(scope.clicked).not.toBeDefined(); + scope.chose = 'B'; + scope.$eval(); + expect(a.checked).toEqual(false); + expect(b.checked).toEqual(true); + expect(scope.clicked).not.toBeDefined(); + + click(a); + expect(scope.chose).toEqual('A'); + expect(scope.clicked).toEqual(1); + }); + + it('should honor model over html checked keyword after', function(){ + compile('
                          ' + + '' + + '' + + '' + + '
                          ', function(){ + this.choose = 'C'; + }); + + expect(scope.choose).toEqual('C'); + }); + + it('should honor model over html checked keyword before', function(){ + compile('
                          ' + + '' + + '' + + '' + + '
                          ', function(){ + this.choose = 'A'; + }); + + expect(scope.choose).toEqual('A'); + }); - click(a); - expect(scope.chose).toEqual('A'); - expect(scope.clicked).toEqual(1); }); it('should support type="select-one"', function(){ -- cgit v1.2.3 From 1bdcf72e456c74256b14f98b26e969b9de637614 Mon Sep 17 00:00:00 2001 From: Misko Hevery Date: Thu, 13 May 2010 16:40:41 -0700 Subject: put formatters back. --- test/widgetsSpec.js | 64 ++++++++++++++++++++++++++++++++++++++--------------- 1 file changed, 46 insertions(+), 18 deletions(-) (limited to 'test') diff --git a/test/widgetsSpec.js b/test/widgetsSpec.js index ecea6223..17120682 100644 --- a/test/widgetsSpec.js +++ b/test/widgetsSpec.js @@ -56,14 +56,6 @@ describe("widget", function(){ expect(scope.$get('list')).toEqual(['1', '2', '3']); }); - it("should format booleans", function(){ - compile('', function(){ - scope.name = false; - }); - expect(scope.name).toEqual(false); - expect(scope.$element[0].checked).toEqual(false); - }); - it("should come up blank if null", function(){ compile('', function(){ scope.age = null; @@ -123,6 +115,52 @@ describe("widget", function(){ }); + describe("checkbox", function(){ + it("should format booleans", function(){ + compile('', function(){ + scope.name = false; + }); + expect(scope.name).toEqual(false); + expect(scope.$element[0].checked).toEqual(false); + }); + + it('should support type="checkbox"', function(){ + compile(''); + expect(scope.checkbox).toEqual(true); + click(element); + expect(scope.checkbox).toEqual(false); + expect(scope.action).toEqual(true); + click(element); + expect(scope.checkbox).toEqual(true); + }); + + it("should use ng-format", function(){ + angularFormatter('testFormat', { + parse: function(value){ + return value ? "Worked" : "Failed"; + }, + + format: function(value) { + if (value == undefined) return value; + return value == "Worked"; + } + + }); + compile(''); + expect(scope.state).toEqual("Worked"); + expect(scope.$element[0].checked).toEqual(true); + + click(scope.$element); + expect(scope.state).toEqual("Failed"); + expect(scope.$element[0].checked).toEqual(false); + + scope.state = "Worked"; + scope.$eval(); + expect(scope.state).toEqual("Worked"); + expect(scope.$element[0].checked).toEqual(true); + }); + }); + describe("ng-validate", function(){ it("should process ng-validate", function(){ compile(''); @@ -212,16 +250,6 @@ describe("widget", function(){ expect(scope.$get('clicked')).toEqual(true); }); - it('should support type="checkbox"', function(){ - compile(''); - expect(scope.checkbox).toEqual(true); - click(element); - expect(scope.checkbox).toEqual(false); - expect(scope.action).toEqual(true); - click(element); - expect(scope.checkbox).toEqual(true); - }); - describe('radio', function(){ it('should support type="radio"', function(){ -- cgit v1.2.3 From 0f73084e9d21cea99f0535e6ca30a1341b7047dc Mon Sep 17 00:00:00 2001 From: Misko Hevery Date: Wed, 19 May 2010 11:51:17 -0700 Subject: added error handler to xhr requests --- test/ResourceSpec.js | 15 +++++++++++++++ test/angular-mocks.js | 10 +++++++--- test/servicesSpec.js | 43 +++++++++++++++++++++++++++++++++++++++++-- 3 files changed, 63 insertions(+), 5 deletions(-) (limited to 'test') diff --git a/test/ResourceSpec.js b/test/ResourceSpec.js index d2d52d47..2f285bcf 100644 --- a/test/ResourceSpec.js +++ b/test/ResourceSpec.js @@ -138,4 +138,19 @@ describe("resource", function() { expect(person.name).toEqual('misko'); }); + describe('failure mode', function(){ + it('should report error when non 200', function(){ + xhr.expectGET('/CreditCard/123').respond(500, "Server Error"); + var cc = CreditCard.get({id:123}); + try { + xhr.flush(); + fail('expected exception, non thrown'); + } catch (e) { + expect(e.status).toEqual(500); + expect(e.response).toEqual('Server Error'); + expect(e.message).toEqual('500: Server Error'); + } + }); + }); + }); diff --git a/test/angular-mocks.js b/test/angular-mocks.js index 6ae91596..c5784ac9 100644 --- a/test/angular-mocks.js +++ b/test/angular-mocks.js @@ -43,7 +43,7 @@ function MockBrowser() { throw "Unexepected request for method '" + method + "' and url '" + url + "'."; } requests.push(function(){ - callback(200, response); + callback(response.code, response.response); }); }; self.xhr.expectations = expectations; @@ -53,8 +53,12 @@ function MockBrowser() { if (data && angular.isString(data)) url += "|" + data; var expect = expectations[method] || (expectations[method] = {}); return { - respond: function(response) { - expect[url] = response; + respond: function(code, response) { + if (!isNumber(code)) { + response = code; + code = 200; + } + expect[url] = {code:code, response:response}; } }; }; diff --git a/test/servicesSpec.js b/test/servicesSpec.js index 17f71bdc..4e144dd1 100644 --- a/test/servicesSpec.js +++ b/test/servicesSpec.js @@ -1,8 +1,11 @@ describe("service", function(){ - var scope; + var scope, xhrErrorHandler; beforeEach(function(){ - scope = createScope(null, angularService, {}); + xhrErrorHandler = jasmine.createSpy('$xhr.error'); + scope = createScope(null, angularService, { + '$xhr.error': xhrErrorHandler + }); }); afterEach(function(){ @@ -194,6 +197,17 @@ describe("service", function(){ expect(log).toEqual('"third";["second"];"first";'); }); + it('should handle non 200 status codes by forwarding to error handler', function(){ + xhr.expectPOST('/req', 'MyData').respond(500, 'MyError'); + scope.$xhr('POST', '/req', 'MyData', callback); + xhr.flush(); + var cb = xhrErrorHandler.mostRecentCall.args[0].callback; + expect(typeof cb).toEqual('function'); + expect(xhrErrorHandler).wasCalledWith( + {url:'/req', method:'POST', data:'MyData', callback:cb}, + {status:500, body:'MyError'}); + }); + describe('bulk', function(){ it('should collect requests', function(){ scope.$xhr.bulk.urls["/"] = {match:/.*/}; @@ -211,6 +225,31 @@ describe("service", function(){ xhr.flush(); expect(log).toEqual('"first";"second";DONE'); }); + + it('should handle non 200 status code by forwarding to error handler', function(){ + scope.$xhr.bulk.urls['/'] = {match:/.*/}; + scope.$xhr.bulk('GET', '/req1', null, callback); + scope.$xhr.bulk('POST', '/req2', {post:'data'}, callback); + + xhr.expectPOST('/', { + requests:[{method:'GET', url:'/req1', data: null}, + {method:'POST', url:'/req2', data:{post:'data'} }] + }).respond([ + {status:404, response:'NotFound'}, + {status:200, response:'second'} + ]); + scope.$xhr.bulk.flush(function(){ log += 'DONE';}); + xhr.flush(); + + expect(xhrErrorHandler).wasCalled(); + var cb = xhrErrorHandler.mostRecentCall.args[0].callback; + expect(typeof cb).toEqual('function'); + expect(xhrErrorHandler).wasCalledWith( + {url:'/req1', method:'GET', data:null, callback:cb}, + {status:404, body:'NotFound'}); + + expect(log).toEqual('"second";DONE'); + }); }); describe('cache', function(){ -- cgit v1.2.3 From 31b35b141f52e6f5d3805d6ca4f2702aee05d61d Mon Sep 17 00:00:00 2001 From: Misko Hevery Date: Wed, 19 May 2010 12:00:44 -0700 Subject: added exception handling to $xhr --- test/servicesSpec.js | 27 +++++++++++++++++++-------- 1 file changed, 19 insertions(+), 8 deletions(-) (limited to 'test') diff --git a/test/servicesSpec.js b/test/servicesSpec.js index 4e144dd1..60b465d2 100644 --- a/test/servicesSpec.js +++ b/test/servicesSpec.js @@ -1,10 +1,12 @@ describe("service", function(){ - var scope, xhrErrorHandler; + var scope, $xhrError, $log; beforeEach(function(){ - xhrErrorHandler = jasmine.createSpy('$xhr.error'); + $xhrError = jasmine.createSpy('$xhr.error'); + $log = {}; scope = createScope(null, angularService, { - '$xhr.error': xhrErrorHandler + '$xhr.error': $xhrError, + '$log': $log }); }); @@ -201,13 +203,22 @@ describe("service", function(){ xhr.expectPOST('/req', 'MyData').respond(500, 'MyError'); scope.$xhr('POST', '/req', 'MyData', callback); xhr.flush(); - var cb = xhrErrorHandler.mostRecentCall.args[0].callback; + var cb = $xhrError.mostRecentCall.args[0].callback; expect(typeof cb).toEqual('function'); - expect(xhrErrorHandler).wasCalledWith( + expect($xhrError).wasCalledWith( {url:'/req', method:'POST', data:'MyData', callback:cb}, {status:500, body:'MyError'}); }); + it('should handle exceptions in callback', function(){ + $log.error = jasmine.createSpy('$log.error'); + xhr.expectGET('/reqGET').respond('first'); + scope.$xhr('GET', '/reqGET', null, function(){ throw "MyException"; }); + xhr.flush(); + + expect($log.error).wasCalledWith("MyException"); + }); + describe('bulk', function(){ it('should collect requests', function(){ scope.$xhr.bulk.urls["/"] = {match:/.*/}; @@ -241,10 +252,10 @@ describe("service", function(){ scope.$xhr.bulk.flush(function(){ log += 'DONE';}); xhr.flush(); - expect(xhrErrorHandler).wasCalled(); - var cb = xhrErrorHandler.mostRecentCall.args[0].callback; + expect($xhrError).wasCalled(); + var cb = $xhrError.mostRecentCall.args[0].callback; expect(typeof cb).toEqual('function'); - expect(xhrErrorHandler).wasCalledWith( + expect($xhrError).wasCalledWith( {url:'/req1', method:'GET', data:null, callback:cb}, {status:404, body:'NotFound'}); -- cgit v1.2.3 From 80e12276f423a0dcb486b1191857db96a0ba0a93 Mon Sep 17 00:00:00 2001 From: Misko Hevery Date: Wed, 19 May 2010 13:24:20 -0700 Subject: added $log to console connection --- test/servicesSpec.js | 31 +++++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) (limited to 'test') diff --git a/test/servicesSpec.js b/test/servicesSpec.js index 60b465d2..45993490 100644 --- a/test/servicesSpec.js +++ b/test/servicesSpec.js @@ -31,6 +31,37 @@ describe("service", function(){ scope.$document.addStyleSheet('css/angular.css'); }); + describe("$log", function(){ + it('should use console if present', function(){ + function log(){}; + function warn(){}; + function info(){}; + function error(){}; + var scope = createScope(null, angularService, {$window: {console:{log:log, warn:warn, info:info, error:error}}}); + expect(scope.$log.log).toEqual(log); + expect(scope.$log.warn).toEqual(warn); + expect(scope.$log.info).toEqual(info); + expect(scope.$log.error).toEqual(error); + }); + + it('should use console.log if other not present', function(){ + function log(){}; + var scope = createScope(null, angularService, {$window: {console:{log:log}}}); + expect(scope.$log.log).toEqual(log); + expect(scope.$log.warn).toEqual(log); + expect(scope.$log.info).toEqual(log); + expect(scope.$log.error).toEqual(log); + }); + + it('should use noop if no console', function(){ + var scope = createScope(null, angularService, {$window: {}}); + expect(scope.$log.log).toEqual(noop); + expect(scope.$log.warn).toEqual(noop); + expect(scope.$log.info).toEqual(noop); + expect(scope.$log.error).toEqual(noop); + }); + }); + describe("$location", function(){ it("should inject $location", function(){ scope.$location.parse('http://host:123/p/a/t/h.html?query=value#path?key=value'); -- cgit v1.2.3 From 80bd0c273b20b6fde25bb38c7639821cd205f69b Mon Sep 17 00:00:00 2001 From: Misko Hevery Date: Wed, 19 May 2010 16:00:20 -0700 Subject: fixed isNumber to angular.isNumber for mocks outside of angular --- test/angular-mocks.js | 2 +- test/servicesSpec.js | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) (limited to 'test') diff --git a/test/angular-mocks.js b/test/angular-mocks.js index c5784ac9..8838b2cd 100644 --- a/test/angular-mocks.js +++ b/test/angular-mocks.js @@ -54,7 +54,7 @@ function MockBrowser() { var expect = expectations[method] || (expectations[method] = {}); return { respond: function(code, response) { - if (!isNumber(code)) { + if (!angular.isNumber(code)) { response = code; code = 200; } diff --git a/test/servicesSpec.js b/test/servicesSpec.js index 45993490..c2c13461 100644 --- a/test/servicesSpec.js +++ b/test/servicesSpec.js @@ -288,7 +288,7 @@ describe("service", function(){ expect(typeof cb).toEqual('function'); expect($xhrError).wasCalledWith( {url:'/req1', method:'GET', data:null, callback:cb}, - {status:404, body:'NotFound'}); + {status:404, response:'NotFound'}); expect(log).toEqual('"second";DONE'); }); -- cgit v1.2.3 From 5215e2095cfd42a0363eb02eded34e03fa2b0cd3 Mon Sep 17 00:00:00 2001 From: Misko Hevery Date: Thu, 20 May 2010 15:55:41 -0700 Subject: basic end to end runner --- test/scenario/RunnerSpec.js | 105 ++++++++++++++++++++++++++++++++++++++++++++ test/scenario/StepsTest.js | 7 --- 2 files changed, 105 insertions(+), 7 deletions(-) create mode 100644 test/scenario/RunnerSpec.js delete mode 100644 test/scenario/StepsTest.js (limited to 'test') diff --git a/test/scenario/RunnerSpec.js b/test/scenario/RunnerSpec.js new file mode 100644 index 00000000..bd7c0599 --- /dev/null +++ b/test/scenario/RunnerSpec.js @@ -0,0 +1,105 @@ +describe('Runner', function(){ + var scenario, runner, log, Describe, It, $scenario; + + function logger(text) { + return function(){log += text;}; + } + + beforeEach(function(){ + log = ''; + scenario = {}; + runner = new angular.scenario.Runner(scenario); + Describe = scenario.describe; + It = scenario.it; + $scenario = scenario.$scenario; + }); + + describe('describe', function(){ + it('should consume the describe functions', function(){ + Describe('describe name', logger('body')); + + expect(log).toEqual('body'); + }); + + describe('it', function(){ + it('should consume it', function(){ + Describe('describe name', function(){ + It('should text', logger('body')); + }); + expect(log).toEqual('body'); + var spec = $scenario.specs['describe name: it should text']; + expect(spec.steps).toEqual([]); + expect(spec.name).toEqual('describe name: it should text'); + }); + }); + }); + + describe('steps building', function(){ + it('should queue steps', function(){ + function step(){}; + Describe('name', function(){ + It('should', function(){ + $scenario.addStep('stepname', step); + }); + }); + expect($scenario.specs['name: it should'].steps).toEqual([{name:'stepname', fn:step}]); + }); + }); + + describe('execution', function(){ + it('should execute the queued steps', function(){ + var next, firstThis, secondThis, doneThis, spec; + $scenario.specs['spec'] = { + steps: [ + {name:'step1', fn: function(done) { + next = done; + log += 'first;'; + firstThis = this; + }}, + {name:'step2', fn:function(done){ + next = done; + log += 'second;'; + secondThis = this; + }} + ] + }; + + spec = $scenario.execute('spec', function(done){ + log += 'done;'; + doneThis = this; + }); + expect(log).toEqual('first;'); + next(); + expect(log).toEqual('first;second;'); + next(); + expect(log).toEqual('first;second;done;'); + expect(spec).not.toEqual(window); + expect(spec).toEqual(firstThis); + expect(spec).toEqual(secondThis); + expect(spec).toEqual(doneThis); + + expect(spec.result.failed).toEqual(false); + expect(spec.result.finished).toEqual(true); + expect(spec.result.error).toBeUndefined(); + expect(spec.result.passed).toEqual(true); + }); + + it('should handle exceptions in a step', function(){ + $scenario.specs['spec'] = { + steps: [ + {name:'error', fn:function(done) { + throw "MyError"; + }} + ] + }; + + var spec = $scenario.execute('spec'); + + expect(spec.result.passed).toEqual(false); + expect(spec.result.failed).toEqual(true); + expect(spec.result.finished).toEqual(true); + expect(spec.result.error).toEqual("MyError"); + }); + }); + +}); \ No newline at end of file diff --git a/test/scenario/StepsTest.js b/test/scenario/StepsTest.js deleted file mode 100644 index 32ef637d..00000000 --- a/test/scenario/StepsTest.js +++ /dev/null @@ -1,7 +0,0 @@ -StepsTest = TestCase("StepsTest"); - -StepsTest.prototype.testGivenDataset=function(){ - var self = {frame:{}, dataset:[]}; - angular.scenario.GIVEN.dataset.call(self); - assertEquals('$DATASET:{"dataset":[]}', self.frame.name); -}; -- cgit v1.2.3 From e3368e12a6207706d8a08b18f9958db3b86ca4e5 Mon Sep 17 00:00:00 2001 From: Misko Hevery Date: Thu, 20 May 2010 16:55:47 -0700 Subject: semi working state --- test/scenario/RunnerSpec.js | 3 +++ 1 file changed, 3 insertions(+) (limited to 'test') diff --git a/test/scenario/RunnerSpec.js b/test/scenario/RunnerSpec.js index bd7c0599..2883ab7c 100644 --- a/test/scenario/RunnerSpec.js +++ b/test/scenario/RunnerSpec.js @@ -31,6 +31,9 @@ describe('Runner', function(){ expect(spec.steps).toEqual([]); expect(spec.name).toEqual('describe name: it should text'); }); + + it('should camplain on duplicate it', angular.noop); + }); }); -- cgit v1.2.3 From f6c67e28c94033edf6a16eb6508de54679cb49db Mon Sep 17 00:00:00 2001 From: Andres Ornelas Mesta Date: Mon, 24 May 2010 13:54:32 -0700 Subject: happy --- test/jquery_alias.js | 1 + test/jquery_remove.js | 1 + test/scenario/RunnerSpec.js | 34 +++++++++++++++++++++++++++++++--- 3 files changed, 33 insertions(+), 3 deletions(-) create mode 100644 test/jquery_alias.js create mode 100644 test/jquery_remove.js (limited to 'test') diff --git a/test/jquery_alias.js b/test/jquery_alias.js new file mode 100644 index 00000000..4b3fad00 --- /dev/null +++ b/test/jquery_alias.js @@ -0,0 +1 @@ +var _jQuery = jQuery; \ No newline at end of file diff --git a/test/jquery_remove.js b/test/jquery_remove.js new file mode 100644 index 00000000..5283c340 --- /dev/null +++ b/test/jquery_remove.js @@ -0,0 +1 @@ +var _jQuery = jQuery.noConflict(true); \ No newline at end of file diff --git a/test/scenario/RunnerSpec.js b/test/scenario/RunnerSpec.js index 2883ab7c..702e1ab5 100644 --- a/test/scenario/RunnerSpec.js +++ b/test/scenario/RunnerSpec.js @@ -1,14 +1,18 @@ describe('Runner', function(){ - var scenario, runner, log, Describe, It, $scenario; + var scenario, runner, log, Describe, It, $scenario, body; function logger(text) { - return function(){log += text;}; + return function(done){ + log += text; + (done||noop)(); + }; } beforeEach(function(){ log = ''; scenario = {}; - runner = new angular.scenario.Runner(scenario); + body = _jQuery('
                          '); + runner = new angular.scenario.Runner(scenario, _jQuery); Describe = scenario.describe; It = scenario.it; $scenario = scenario.$scenario; @@ -105,4 +109,28 @@ describe('Runner', function(){ }); }); + describe('run', function(){ + var next; + it('should execute all specs', function(){ + Describe('d1', function(){ + It('it1', function(){ $scenario.addStep('s1', logger('s1,')); }); + It('it2', function(){ + $scenario.addStep('s2', logger('s2,')); + $scenario.addStep('s2.2', function(done){ next = done; }); + }); + }); + Describe('d2', function(){ + It('it3', function(){ $scenario.addStep('s3', logger('s3,')); }); + It('it4', function(){ $scenario.addStep('s4', logger('s4,')); }); + }); + + $scenario.run(body); + + expect(log).toEqual('s1,s2,'); + next(); + expect(log).toEqual('s1,s2,s3,s4,'); + + }); + }); + }); \ No newline at end of file -- cgit v1.2.3 From 3fab5d9879272b9f991a67c8135754f00c055834 Mon Sep 17 00:00:00 2001 From: Andres Ornelas Date: Mon, 24 May 2010 15:25:30 -0700 Subject: added error handling on scenario definition --- test/scenario/RunnerSpec.js | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) (limited to 'test') diff --git a/test/scenario/RunnerSpec.js b/test/scenario/RunnerSpec.js index 702e1ab5..35d74f51 100644 --- a/test/scenario/RunnerSpec.js +++ b/test/scenario/RunnerSpec.js @@ -37,7 +37,23 @@ describe('Runner', function(){ }); it('should camplain on duplicate it', angular.noop); - + it('should create a failing step if there is a javascript error', function(){ + var spec; + Describe('D1', function(){ + It('I1', function(){ + spec = $scenario.currentSpec; + throw {message: 'blah'}; + }); + }); + var step = spec.steps[0]; + expect(step.name).toEqual('blah'); + try { + step.fn(); + fail(); + } catch (e) { + expect(e.message).toEqual('blah'); + }; + }); }); }); -- cgit v1.2.3 From 55c0767f16e60e77e9d1b4d46698ddbf343ed8b1 Mon Sep 17 00:00:00 2001 From: Andres Ornelas Date: Mon, 24 May 2010 17:48:17 -0700 Subject: added dsl tests and select method --- test/scenario/DSLSpec.js | 40 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 40 insertions(+) create mode 100644 test/scenario/DSLSpec.js (limited to 'test') diff --git a/test/scenario/DSLSpec.js b/test/scenario/DSLSpec.js new file mode 100644 index 00000000..3c16876d --- /dev/null +++ b/test/scenario/DSLSpec.js @@ -0,0 +1,40 @@ +describe("DSL", function() { + + var lastStep, executeStep, lastDocument; + + beforeEach(function() { + lastStep = null; + $scenario = { + addStep: function(name, stepFunction) { + lastStep = { name:name, fn: stepFunction}; + } + }; + executeStep = function(step, html, callback) { + lastDocument =_jQuery('
                          ' + html + '
                          '); + var specThis = { + testWindow: window, + testDocument: lastDocument + }; + step.fn.call(specThis, callback || noop); + }; + }); + + describe("input", function() { + + var input = angular.scenario.dsl.input; + it('should enter', function() { + input('name').enter('John'); + expect(lastStep.name).toEqual("Set input text of 'name' to 'John'"); + executeStep(lastStep, ''); + expect(lastDocument.find('input').val()).toEqual('John'); + }); + + it('should select', function() { + input('gender').select('female'); + expect(lastStep.name).toEqual("Select radio 'gender' to 'female'"); + executeStep(lastStep, '' + + ''); + expect(lastDocument.find(':radio:checked').val()).toEqual('female'); + }); + }); +}); \ No newline at end of file -- cgit v1.2.3 From 4fec828cf6ce896452945c1dd8aa2db61e2bc746 Mon Sep 17 00:00:00 2001 From: Andres Ornelas Date: Tue, 25 May 2010 09:52:52 -0700 Subject: appended lastDocument to the document.body --- test/scenario/DSLSpec.js | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) (limited to 'test') diff --git a/test/scenario/DSLSpec.js b/test/scenario/DSLSpec.js index 3c16876d..bed1f008 100644 --- a/test/scenario/DSLSpec.js +++ b/test/scenario/DSLSpec.js @@ -11,6 +11,7 @@ describe("DSL", function() { }; executeStep = function(step, html, callback) { lastDocument =_jQuery('
                          ' + html + '
                          '); + _jQuery(document.body).append(lastDocument); var specThis = { testWindow: window, testDocument: lastDocument @@ -32,8 +33,10 @@ describe("DSL", function() { it('should select', function() { input('gender').select('female'); expect(lastStep.name).toEqual("Select radio 'gender' to 'female'"); - executeStep(lastStep, '' + + executeStep(lastStep, + '' + ''); + expect(lastDocument.find(':radio:checked').length).toEqual(1); expect(lastDocument.find(':radio:checked').val()).toEqual('female'); }); }); -- cgit v1.2.3 From aedf12f25e42877a302a99d906e6397bde01dcce Mon Sep 17 00:00:00 2001 From: Andres Ornelas Date: Wed, 26 May 2010 15:21:58 -0700 Subject: added outstanding request queue --- test/BrowserSpecs.js | 48 ++++++++++++++++++++++++++++++++++++++++++++++++ test/BrowserTest.js | 25 ------------------------- 2 files changed, 48 insertions(+), 25 deletions(-) create mode 100644 test/BrowserSpecs.js delete mode 100644 test/BrowserTest.js (limited to 'test') diff --git a/test/BrowserSpecs.js b/test/BrowserSpecs.js new file mode 100644 index 00000000..3ce158b4 --- /dev/null +++ b/test/BrowserSpecs.js @@ -0,0 +1,48 @@ +describe('browser', function(){ + + var browser, location; + + beforeEach(function(){ + location = {href:"http://server", hash:""}; + browser = new Browser(location, {}); + browser.setTimeout = noop; + }); + + it('should watch url', function(){ + browser.delay = 1; + expectAsserts(2); + browser.watchUrl(function(url){ + assertEquals('http://getangular.test', url); + }); + browser.setTimeout = function(fn, delay){ + assertEquals(1, delay); + location.href = "http://getangular.test"; + browser.setTimeout = function(fn, delay) {}; + fn(); + }; + browser.startUrlWatcher(); + }); + + describe('outstading requests', function(){ + it('should process callbacks immedietly with no outstanding requests', function(){ + var callback = jasmine.createSpy('callback'); + browser.notifyWhenNoOutstandingRequests(callback); + expect(callback).wasCalled(); + }); + + it('should queue callbacks with outstanding requests', function(){ + var callback = jasmine.createSpy('callback'); + browser.outstandingRequests.count = 1; + browser.notifyWhenNoOutstandingRequests(callback); + expect(callback).not.wasCalled(); + + browser.processRequestCallbacks(); + expect(callback).not.wasCalled(); + + browser.outstandingRequests.count = 0; + browser.processRequestCallbacks(); + expect(callback).wasCalled(); + }); + }); + +}); diff --git a/test/BrowserTest.js b/test/BrowserTest.js deleted file mode 100644 index 5254840a..00000000 --- a/test/BrowserTest.js +++ /dev/null @@ -1,25 +0,0 @@ -BrowserTest = TestCase('BrowserTest'); - -BrowserTest.prototype.testUrlWatcher = function () { - expectAsserts(2); - var location = {href:"http://server", hash:""}; - var watcher = new Browser(location, {}); - watcher.delay = 1; - watcher.watchUrl(function(url){ - assertEquals('http://getangular.test', url); - }); - watcher.setTimeout = function(fn, delay){ - assertEquals(1, delay); - location.href = "http://getangular.test"; - watcher.setTimeout = function(fn, delay) { - }; - fn(); - }; - watcher.startUrlWatcher(); -}; - -FunctionTest = TestCase("FunctionTest"); - -FunctionTest.prototype.testEscapeHtml = function () { - assertEquals("<div>&amp;</div>", escapeHtml('
                          &
                          ')); -}; -- cgit v1.2.3 From 2e33e89a77d115ff17f5841ec328b1c1e4228161 Mon Sep 17 00:00:00 2001 From: Misko Hevery Date: Sun, 30 May 2010 19:42:21 -0700 Subject: added compiled getterFN for better performance --- test/ScopeSpec.js | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) (limited to 'test') diff --git a/test/ScopeSpec.js b/test/ScopeSpec.js index a3b6d9ae..d93400e5 100644 --- a/test/ScopeSpec.js +++ b/test/ScopeSpec.js @@ -157,4 +157,25 @@ describe('scope/model', function(){ } }); }); + + describe('getterFn', function(){ + it('should get chain', function(){ + expect(getterFn('a.b')(undefined)).toEqual(undefined); + expect(getterFn('a.b')({})).toEqual(undefined); + expect(getterFn('a.b')({a:null})).toEqual(undefined); + expect(getterFn('a.b')({a:{}})).toEqual(undefined); + expect(getterFn('a.b')({a:{b:null}})).toEqual(null); + expect(getterFn('a.b')({a:{b:0}})).toEqual(0); + expect(getterFn('a.b')({a:{b:'abc'}})).toEqual('abc'); + }); + + it('should map type method on top of expression', function(){ + expect(getterFn('a.$filter')({a:[]})('')).toEqual([]); + }); + + it('should bind function this', function(){ + expect(getterFn('a')({a:function($){return this.b + $;}, b:1})(2)).toEqual(3); + + }); + }); }); -- cgit v1.2.3 From 3245209bdb9e656622756220c5bbeb80d3ae2eac Mon Sep 17 00:00:00 2001 From: Shyam Seshadri Date: Wed, 2 Jun 2010 17:13:10 -0700 Subject: Add ability to add conditions to ng-required --- test/widgetsSpec.js | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) (limited to 'test') diff --git a/test/widgetsSpec.js b/test/widgetsSpec.js index 17120682..dc6050b8 100644 --- a/test/widgetsSpec.js +++ b/test/widgetsSpec.js @@ -221,6 +221,29 @@ describe("widget", function(){ expect(element.attr('ng-validation-error')).toEqual('Required'); }); + it('should allow conditions on ng-required', function() { + compile(''); + scope.$set('ineedz', false); + scope.$eval(); + expect(element.hasClass('ng-validation-error')).toBeFalsy(); + expect(element.attr('ng-validation-error')).toBeFalsy(); + + scope.$set('price', 'xxx'); + scope.$eval(); + expect(element.hasClass('ng-validation-error')).toBeFalsy(); + expect(element.attr('ng-validation-error')).toBeFalsy(); + + scope.$set('ineedz', true); + scope.$eval(); + expect(element.hasClass('ng-validation-error')).toBeFalsy(); + expect(element.attr('ng-validation-error')).toBeFalsy(); + + element.val(''); + element.trigger('keyup'); + expect(element.hasClass('ng-validation-error')).toBeTruthy(); + expect(element.attr('ng-validation-error')).toEqual('Required'); + }); + it("should process ng-required2", function() { compile(''); expect(scope.$get('name')).toEqual("Misko"); -- cgit v1.2.3 From 36b58b235eeca4e9580162a697d8a96c41263ebc Mon Sep 17 00:00:00 2001 From: Shyam Seshadri Date: Thu, 3 Jun 2010 11:03:11 -0700 Subject: fix some lint issues --- test/widgetsSpec.js | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) (limited to 'test') diff --git a/test/widgetsSpec.js b/test/widgetsSpec.js index dc6050b8..40f52b8e 100644 --- a/test/widgetsSpec.js +++ b/test/widgetsSpec.js @@ -233,15 +233,16 @@ describe("widget", function(){ expect(element.hasClass('ng-validation-error')).toBeFalsy(); expect(element.attr('ng-validation-error')).toBeFalsy(); + scope.$set('price', ''); scope.$set('ineedz', true); scope.$eval(); - expect(element.hasClass('ng-validation-error')).toBeFalsy(); - expect(element.attr('ng-validation-error')).toBeFalsy(); - - element.val(''); - element.trigger('keyup'); expect(element.hasClass('ng-validation-error')).toBeTruthy(); expect(element.attr('ng-validation-error')).toEqual('Required'); + + element.val('abc'); + element.trigger('keyup'); + expect(element.hasClass('ng-validation-error')).toBeFalsy(); + expect(element.attr('ng-validation-error')).toBeFalsy(); }); it("should process ng-required2", function() { -- cgit v1.2.3 From fe03ea0d1f8814817bee5a35d745db16858eb490 Mon Sep 17 00:00:00 2001 From: Andres Ornelas Date: Wed, 9 Jun 2010 12:35:40 -0700 Subject: add repeater DSL and fix typo --- test/scenario/DSLSpec.js | 14 +++++++++++++- test/scenario/RunnerSpec.js | 2 +- 2 files changed, 14 insertions(+), 2 deletions(-) (limited to 'test') diff --git a/test/scenario/DSLSpec.js b/test/scenario/DSLSpec.js index bed1f008..0cce7b75 100644 --- a/test/scenario/DSLSpec.js +++ b/test/scenario/DSLSpec.js @@ -40,4 +40,16 @@ describe("DSL", function() { expect(lastDocument.find(':radio:checked').val()).toEqual('female'); }); }); -}); \ No newline at end of file + + describe('expect', function() { + var dslExpect = angular.scenario.dsl.expect; + describe('repeater', function() { + it('should check the count of repeated elements', function() { + dslExpect.repeater('.repeater-row').count.toEqual(2); + expect(lastStep.name).toEqual("Expect to see 2 items repeated with selector '.repeater-row'"); + var html = "
                          a
                          b
                          "; + executeStep(lastStep, html); + }); + }); + }); +}); diff --git a/test/scenario/RunnerSpec.js b/test/scenario/RunnerSpec.js index 35d74f51..030bdc06 100644 --- a/test/scenario/RunnerSpec.js +++ b/test/scenario/RunnerSpec.js @@ -36,7 +36,7 @@ describe('Runner', function(){ expect(spec.name).toEqual('describe name: it should text'); }); - it('should camplain on duplicate it', angular.noop); + it('should complain on duplicate it', angular.noop); it('should create a failing step if there is a javascript error', function(){ var spec; Describe('D1', function(){ -- cgit v1.2.3 From f6a405c283ba1f2e0037e0bedb52e5cee618d4ff Mon Sep 17 00:00:00 2001 From: Andres Ornelas Date: Wed, 9 Jun 2010 13:30:54 -0700 Subject: change repeater count expectation wording --- test/scenario/DSLSpec.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'test') diff --git a/test/scenario/DSLSpec.js b/test/scenario/DSLSpec.js index 0cce7b75..5aac9752 100644 --- a/test/scenario/DSLSpec.js +++ b/test/scenario/DSLSpec.js @@ -46,7 +46,7 @@ describe("DSL", function() { describe('repeater', function() { it('should check the count of repeated elements', function() { dslExpect.repeater('.repeater-row').count.toEqual(2); - expect(lastStep.name).toEqual("Expect to see 2 items repeated with selector '.repeater-row'"); + expect(lastStep.name).toEqual("Expect that there are 2 items in Repeater with selector '.repeater-row'"); var html = "
                          a
                          b
                          "; executeStep(lastStep, html); }); -- cgit v1.2.3 From 85fac4d78c131771d7fdd46d6ccd44bae92419cd Mon Sep 17 00:00:00 2001 From: Andres Ornelas Date: Wed, 9 Jun 2010 14:12:54 -0700 Subject: add beforeEach and afterEach to scenario DSL --- test/scenario/RunnerSpec.js | 40 +++++++++++++++++++++++++++++++++++++++- 1 file changed, 39 insertions(+), 1 deletion(-) (limited to 'test') diff --git a/test/scenario/RunnerSpec.js b/test/scenario/RunnerSpec.js index 030bdc06..ca6e8eb2 100644 --- a/test/scenario/RunnerSpec.js +++ b/test/scenario/RunnerSpec.js @@ -14,6 +14,8 @@ describe('Runner', function(){ body = _jQuery('
                          '); runner = new angular.scenario.Runner(scenario, _jQuery); Describe = scenario.describe; + BeforeEach = scenario.beforeEach; + AfterEach = scenario.afterEach; It = scenario.it; $scenario = scenario.$scenario; }); @@ -36,7 +38,10 @@ describe('Runner', function(){ expect(spec.name).toEqual('describe name: it should text'); }); - it('should complain on duplicate it', angular.noop); + it('should complain on duplicate it', function() { + // WRITE ME!!!! + }); + it('should create a failing step if there is a javascript error', function(){ var spec; Describe('D1', function(){ @@ -55,6 +60,39 @@ describe('Runner', function(){ }; }); }); + + describe('beforeEach', function() { + it('should execute beforeEach before every it', function() { + Describe('describe name', function(){ + BeforeEach(logger('before;')); + It('should text', logger('body;')); + It('should text2', logger('body2;')); + }); + expect(log).toEqual('before;body;before;body2;'); + }); + }); + describe('afterEach', function() { + it('should execute afterEach after every it', function() { + Describe('describe name', function(){ + AfterEach(logger('after;')); + It('should text', logger('body;')); + It('should text2', logger('body2;')); + }); + expect(log).toEqual('body;after;body2;after;'); + }); + + it('should always execute afterEach after every it', function() { + Describe('describe name', function(){ + AfterEach(logger('after;')); + It('should text', function() { + log = 'body;'; + throw "MyError"; + }); + It('should text2', logger('body2;')); + }); + expect(log).toEqual('body;after;body2;after;'); + }); + }); }); describe('steps building', function(){ -- cgit v1.2.3 From 769b26b79eb26076c218cb5b57179ee98424bbd7 Mon Sep 17 00:00:00 2001 From: Shyam Seshadri Date: Wed, 16 Jun 2010 10:32:56 -0700 Subject: Fix bug with validator not triggering when attributes are bound and fix some typos. Add test for bug --- test/widgetsSpec.js | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) (limited to 'test') diff --git a/test/widgetsSpec.js b/test/widgetsSpec.js index 40f52b8e..a053090e 100644 --- a/test/widgetsSpec.js +++ b/test/widgetsSpec.js @@ -43,7 +43,7 @@ describe("widget", function(){ describe("ng-format", function(){ - it("should farmat text", function(){ + it("should format text", function(){ compile(''); expect(scope.$get('list')).toEqual(['a', 'b', 'c']); @@ -178,7 +178,18 @@ describe("widget", function(){ expect(element.attr('ng-validation-error')).toEqual('Not a number'); }); - it("should not call validator if undefinde/empty", function(){ + it('should not blow up for validation with bound attributes', function() { + compile(''); + expect(element.hasClass('ng-validation-error')).toBeTruthy(); + expect(element.attr('ng-validation-error')).toEqual('Required'); + + scope.$set('price', '123'); + scope.$eval(); + expect(element.hasClass('ng-validation-error')).toBeFalsy(); + expect(element.attr('ng-validation-error')).toBeFalsy(); + }); + + it("should not call validator if undefined/empty", function(){ var lastValue = "NOT_CALLED"; angularValidator.myValidator = function(value){lastValue = value;}; compile(''); -- cgit v1.2.3