diff options
| author | Misko Hevery | 2010-04-08 13:43:40 -0700 |
|---|---|---|
| committer | Misko Hevery | 2010-04-08 13:43:40 -0700 |
| commit | c4ef1f2fdd73bdaeda879e596d3d96e4e68cb6fd (patch) | |
| tree | 3fc1943a4599a764aef9a41d995246bb0e48f463 | |
| parent | e0ad7dfcd47196d0aa9271e84b2c4ac26cfda3f4 (diff) | |
| download | angular.js-c4ef1f2fdd73bdaeda879e596d3d96e4e68cb6fd.tar.bz2 | |
tests failing jstd to show cory
| -rw-r--r-- | jstd.log | 11 | ||||
| -rw-r--r-- | lib/jstestdriver/JsTestDriver.jar | bin | 3127185 -> 3133666 bytes | |||
| -rwxr-xr-x | server.sh | 2 | ||||
| -rw-r--r-- | src/Angular.js | 8 | ||||
| -rw-r--r-- | src/filters.js | 4 | ||||
| -rw-r--r-- | src/jqLite.js | 5 | ||||
| -rw-r--r-- | src/widgets.js | 12 | ||||
| -rw-r--r-- | test/BinderTest.js | 155 | ||||
| -rw-r--r-- | test/ConsoleTest.js | 2 | ||||
| -rw-r--r-- | test/FiltersTest.js | 45 | ||||
| -rw-r--r-- | test/ParserTest.js | 40 | ||||
| -rw-r--r-- | test/ScenarioSpec.js | 37 | ||||
| -rw-r--r-- | test/ValidatorsTest.js | 26 | ||||
| -rw-r--r-- | test/angular-mocks.js | 6 | ||||
| -rw-r--r-- | test/directivesSpec.js | 10 | ||||
| -rw-r--r-- | test/moveToAngularCom/FileControllerTest.js (renamed from test/FileControllerTest.js) | 0 | ||||
| -rw-r--r-- | test/moveToAngularCom/MiscTest.js | 4 | ||||
| -rw-r--r-- | test/moveToAngularCom/miscTest.js | 62 | ||||
| -rw-r--r-- | test/servicesSpec.js | 4 | ||||
| -rw-r--r-- | test/testabilityPatch.js | 7 |
20 files changed, 171 insertions, 269 deletions
diff --git a/jstd.log b/jstd.log new file mode 100644 index 00000000..df60db2e --- /dev/null +++ b/jstd.log @@ -0,0 +1,11 @@ +java.lang.IllegalArgumentException: /com/google/jstestdriver/javascript/mysrc: resource is null +java.lang.IllegalArgumentException: /com/google/jstestdriver/javascript/mysrc: resource is null +java.lang.IllegalArgumentException: /com/google/jstestdriver/javascript/mysrc: resource is null +java.lang.IllegalArgumentException: /com/google/jstestdriver/javascript/mysrc: resource is null +java.lang.IllegalArgumentException: /com/google/jstestdriver/javascript/mysrc: resource is null +java.lang.IllegalArgumentException: /com/google/jstestdriver/javascript/mysrc: resource is null +java.lang.IllegalArgumentException: /com/google/jstestdriver/javascript/mysrc: resource is null +java.lang.IllegalArgumentException: /com/google/jstestdriver/javascript/mysrc: resource is null +java.lang.IllegalArgumentException: /com/google/jstestdriver/javascript/mysrc: resource is null +java.lang.IllegalArgumentException: /com/google/jstestdriver/javascript/mysrc: resource is null +java.lang.IllegalArgumentException: /com/google/jstestdriver/javascript/mysrc: resource is null diff --git a/lib/jstestdriver/JsTestDriver.jar b/lib/jstestdriver/JsTestDriver.jar Binary files differindex 557d4c16..ead31593 100644 --- a/lib/jstestdriver/JsTestDriver.jar +++ b/lib/jstestdriver/JsTestDriver.jar @@ -1 +1 @@ -java -jar lib/jstestdriver/JsTestDriver.jar --port 9876 +java -jar lib/jstestdriver/JsTestDriver.jar --port 9876 --runnerMode DEBUG diff --git a/src/Angular.js b/src/Angular.js index d8b03464..7fb59f86 100644 --- a/src/Angular.js +++ b/src/Angular.js @@ -83,7 +83,7 @@ function extensionMap(angular, name) { } function jqLiteWrap(element) { - if (typeof element == 'string') { + if (isString(element)) { var div = document.createElement('div'); div.innerHTML = element; element = div.childNodes[0]; @@ -102,6 +102,12 @@ function lowercase(value){ return isString(value) ? value.toLowerCase() : value; function uppercase(value){ return isString(value) ? value.toUpperCase() : value; } function trim(value) { return isString(value) ? value.replace(/^\s*/, '').replace(/\s*$/, '') : value; } function nodeName(element) { return (element[0] || element).nodeName; } + +function isVisible(element) { + var rect = element[0].getBoundingClientRect(); + return rect.width !=0 && rect.height !=0; +} + function map(obj, iterator, context) { var results = []; foreach(obj, function(value, index, list) { diff --git a/src/filters.js b/src/filters.js index dac8d31d..0259f69c 100644 --- a/src/filters.js +++ b/src/filters.js @@ -24,7 +24,7 @@ var angularFilterGoogleChartApi; foreach({ 'currency': function(amount){ - jQuery(this.$element).toggleClass('ng-format-negative', amount < 0); + this.$element.toggleClass('ng-format-negative', amount < 0); return '$' + angularFilter['number'].apply(this, [amount, 2]); }, @@ -60,7 +60,7 @@ foreach({ }, 'json': function(object) { - jQuery(this.$element).addClass("ng-monospace"); + this.$element.addClass("ng-monospace"); return toJson(object, true); }, diff --git a/src/jqLite.js b/src/jqLite.js index e9407987..6fc16e57 100644 --- a/src/jqLite.js +++ b/src/jqLite.js @@ -140,6 +140,11 @@ JQLite.prototype = { this[0].className = trim((" " + this[0].className + " ").replace(/[\n\t]/g, " ").replace(" " + selector + " ", "")); }, + toggleClass: function(selector, condition) { + var self = this; + (condition ? self.addClass : self.removeClass).call(self, selector); + }, + addClass: function( selector ) { if (!this.hasClass(selector)) { this[0].className = trim(this[0].className + ' ' + selector); diff --git a/src/widgets.js b/src/widgets.js index e89e8ca4..faa60043 100644 --- a/src/widgets.js +++ b/src/widgets.js @@ -22,16 +22,20 @@ function valueAccessor(scope, element) { var validatorName = element.attr('ng-validate') || NOOP, validator = compileValidator(validatorName), required = element.attr('ng-required'), - lastError, + lastError, lastVisible, invalidWidgets = scope.$invalidWidgets || {markValid:noop, markInvalid:noop}; required = required || required === ''; if (!validator) throw "Validator named '" + validatorName + "' not found."; function validate(value) { - var error = required && !trim(value) ? "Required" : validator({state:scope, scope:{get:scope.$get, set:scope.$set}}, value); - if (error !== lastError) { + var error = required && !trim(value) ? + "Required" : + validator({state:scope, scope:{get:scope.$get, set:scope.$set}}, value), + visible = isVisible(element); + if (error !== lastError || visible !== lastVisible) { elementError(element, NG_VALIDATION_ERROR, error); lastError = error; - if (error) + lastVisible = visible; + if (error && visible) invalidWidgets.markInvalid(element); else invalidWidgets.markValid(element); 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("<div/>").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("<div/>").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('<ul><LI ng-repeat="item in model.items" ng-bind="item.a"/></ul>'); var form = a.node; @@ -355,18 +327,6 @@ BinderTest.prototype.testNestedRepeater = function() { '</div></div>', sortedHtml(a.node)); }; -BinderTest.prototype.XtestRadioButtonGetsPrefixed = function () { - var a = this.compile('<div><input ng-repeat="m in model" type="radio" name="m.a" value="on"/></div>'); - a.scope.$set('model', ['a1', 'a2']); - a.scope.$eval(); - - assertEquals('</div>' + - '<#comment></#comment>'+ - '<input name="0:m.a" ng-repeat-index="0" type="radio" value="on"></input>'+ - '<input name="1:m.a" ng-repeat-index="1" type="radio" value="on"></input></div>', - sortedHtml(a.node)); -}; - BinderTest.prototype.testHideBindingExpression = function() { var a = this.compile('<div ng-hide="hidden == 3"/>'); @@ -525,31 +485,6 @@ BinderTest.prototype.testShouldTemplateBindPreElements = function () { assertEquals('<pre ng-bind-template="Hello {{name}}!">Hello World!</pre>', sortedHtml(c.node)); }; -BinderTest.prototype.XtestDissableAutoSubmit = function() { - var c = this.compile('<input type="submit" value="S"/>', null, {autoSubmit:true}); - assertEquals( - '<input ng-action="$save()" ng-bind-attr="{"disabled":"{{$invalidWidgets}}"}" type="submit" value="S"></input>', - sortedHtml(c.node)); - - c = this.compile('<input type="submit" value="S"/>', null, {autoSubmit:false}); - assertEquals( - '<input type="submit" value="S"></input>', - 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( '<select><option selected="true">{{a}}</option><option value="">{{b}}</option><option>C</option></select>'); @@ -570,9 +505,11 @@ BinderTest.prototype.testFillInOptionValueWhenMissing = function() { expect(optionC.text()).toEqual('C'); }; -BinderTest.prototype.XtestValidateForm = function() { - var c = this.compile('<input name="name" ng-required>' + - '<div ng-repeat="item in items"><input name="item.name" ng-required/></div>'); +BinderTest.prototype.testValidateForm = function() { + var doc = jqLite(document.body); + doc.append('<div><input name="name" ng-required>' + + '<div ng-repeat="item in items"><input name="item.name" ng-required/></div></div>'); + 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('<input name="name" ng-required><input ng-show="show" name="name" ng-required>'); +BinderTest.prototype.testValidateOnlyVisibleItems = function(){ + var c = this.compile('<div><input name="name" ng-required><input ng-show="show" name="name" ng-required></div>'); + 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('<div ng-watch="$anchor.counter:count = count+1">'); - 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("<div/>"); - - 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('<div>' + '<input type="button" ng-click="greeting=\'ABC\'"/>' + @@ -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('<div>before {{a|html}}after</div>'); - x.scope.$set("a", "a<b>c</b>d"); + x.scope.a = "a<b>c</b>d"; x.scope.$eval(); assertEquals( '<div>before <span ng-bind="a|html">a<b>c</b>d</span>after</div>', @@ -790,20 +672,3 @@ BinderTest.prototype.testItShouldUseFormaterForText = function() { assertEquals('1, 2, 3', input[0].value); }; -BinderTest.prototype.XtestWriteAnchor = function(){ - var binder = this.compile("<div/>").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("<div/>").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/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 = $('<span/>'); - var context = {$element:html[0]}; +FiltersTest.prototype.testCurrency = function(){ + var html = jqLite('<span/>'); + 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:$('<span/>')}; +FiltersTest.prototype.testNumberFormat = function(){ + var context = {jqElement:jqLite('<span/>')}; 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('<div></div>')}, {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( '<img width="200" height="200" src="http://chart.apis.google.com/chart?chl=Hello%20world&chs=200x200&cht=qr"/>', 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( '<img width="200" height="200" src="http://chart.apis.google.com/chart?chl=Hello world&chs=200x200&cht=qr"/>', angular.filter.googleChartApi.encode({cht:"qr", chl:"Hello world"}).html); }; -FiltersTest.prototype.XtestHtml = function() { +FiltersTest.prototype.testHtml = function() { assertEquals( "a<b>c</b>d", angular.filter.html("a<b>c</b>d").html); assertTrue(angular.filter.html("a<b>c</b>d") instanceof angular.filter.Meta); }; -FiltersTest.prototype.XtestLinky = function() { +FiltersTest.prototype.testLinky = function() { var linky = angular.filter.linky; assertEquals( '<a href="http://ab">http://ab</a> ' + 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('<div>{{a}}</div>').$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('<div></div>', {a:"b"}); - expect(scope.$get('$anchor')).toBeDefined(); + it("should have $ objects", function(){ + var scope = compile('<div></div>', {$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("<div>{{$anchor}}</div>", {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("<div>{{$location}}</div>"); + 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('<input name="name" ng-validate="myValidator:\'hevery\'"/>'); - 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('<input name="name" ng-validate="myValidator:\'hevery\'"/>'); + 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<this.watches.length; i++) { + this.watches[i](this.url); + } } }; diff --git a/test/directivesSpec.js b/test/directivesSpec.js index a92e98ee..0af61997 100644 --- a/test/directivesSpec.js +++ b/test/directivesSpec.js @@ -141,20 +141,22 @@ describe("directives", function(){ it('should ng-show', function(){ var scope = compile('<div ng-hide="hide"></div>'); + 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('<div ng-show="show"></div>'); + 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/FileControllerTest.js b/test/moveToAngularCom/FileControllerTest.js index 75c924e6..75c924e6 100644 --- a/test/FileControllerTest.js +++ b/test/moveToAngularCom/FileControllerTest.js 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('<input type="submit" value="Save">'); 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('<div id="testTag"><input type="file"></div>'); 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('<input type="submit" value="S"/>', null, {autoSubmit:true}); + assertEquals( + '<input ng-action="$save()" ng-bind-attr="{"disabled":"{{$invalidWidgets}}"}" type="submit" value="S"></input>', + sortedHtml(c.node)); + + c = this.compile('<input type="submit" value="S"/>', null, {autoSubmit:false}); + assertEquals( + '<input type="submit" value="S"></input>', + 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('<input name="price" ng-required></input>').$init(); + var doc = jqLite(window.document.body); + doc.append('<input name="price" ng-required></input>'); + 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) { |
