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/moveToAngularCom/FileControllerTest.js | 98 +++++++++++++++++++++++++++++ test/moveToAngularCom/MiscTest.js | 4 +- test/moveToAngularCom/miscTest.js | 62 ++++++++++++++++++ 3 files changed, 162 insertions(+), 2 deletions(-) create mode 100644 test/moveToAngularCom/FileControllerTest.js create mode 100644 test/moveToAngularCom/miscTest.js (limited to 'test/moveToAngularCom') 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)); +}; + + + -- cgit v1.2.3