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 --- jstd.log | 11 ++ lib/jstestdriver/JsTestDriver.jar | Bin 3127185 -> 3133666 bytes server.sh | 2 +- src/Angular.js | 8 +- src/filters.js | 4 +- src/jqLite.js | 5 + src/widgets.js | 12 ++- 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 +- 21 files changed, 269 insertions(+), 367 deletions(-) create mode 100644 jstd.log delete mode 100644 test/FileControllerTest.js create mode 100644 test/moveToAngularCom/FileControllerTest.js create mode 100644 test/moveToAngularCom/miscTest.js 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 index 557d4c16..ead31593 100644 Binary files a/lib/jstestdriver/JsTestDriver.jar and b/lib/jstestdriver/JsTestDriver.jar differ diff --git a/server.sh b/server.sh index 7690cf8a..e645d686 100755 --- a/server.sh +++ b/server.sh @@ -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("
").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