diff options
Diffstat (limited to 'test')
29 files changed, 555 insertions, 1737 deletions
diff --git a/test/AngularSpec.js b/test/AngularSpec.js index de724f03..b4e90175 100644 --- a/test/AngularSpec.js +++ b/test/AngularSpec.js @@ -1,3 +1,7 @@ +beforeEach(function(){ + compileCache = {}; +}); + describe('Angular', function(){ xit('should fire on updateEvents', function(){ var onUpdateView = jasmine.createSpy(); @@ -50,3 +54,30 @@ describe("copy", function(){ }); }); + +describe('equals', function(){ + it('should return true if same object', function(){ + var o = {}; + expect(equals(o, o)).toEqual(true); + expect(equals(1, '1')).toEqual(true); + expect(equals(1, '2')).toEqual(false); + }); + + it('should recurse into object', function(){ + expect(equals({}, {})).toEqual(true); + expect(equals({name:'misko'}, {name:'misko'})).toEqual(true); + expect(equals({name:'misko', age:1}, {name:'misko'})).toEqual(false); + expect(equals({name:'misko'}, {name:'misko', age:1})).toEqual(false); + expect(equals({name:'misko'}, {name:'adam'})).toEqual(false); + expect(equals(['misko'], ['misko'])).toEqual(true); + expect(equals(['misko'], ['adam'])).toEqual(false); + expect(equals(['misko'], ['misko', 'adam'])).toEqual(false); + }); + + it('should ignore $ member variables', function(){ + expect(equals({name:'misko', $id:1}, {name:'misko', $id:2})).toEqual(true); + expect(equals({name:'misko'}, {name:'misko', $id:2})).toEqual(true); + expect(equals({name:'misko', $id:1}, {name:'misko'})).toEqual(true); + }); + +}); diff --git a/test/ApiTest.js b/test/ApiTest.js index 4035cdbb..9f09773d 100644 --- a/test/ApiTest.js +++ b/test/ApiTest.js @@ -18,27 +18,6 @@ ApiTest.prototype.testItShouldReturnSize = function(){ 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(includes(array, obj)); - assertEquals(1, array.length); - - angular.Array.includeIf(array, obj, false); - assertFalse(includes(array, obj)); - assertEquals(0, array.length); - - angular.Array.includeIf(array, obj, 'x'); - assertTrue(includes(array, obj)); - assertEquals(1, array.length); - angular.Array.includeIf(array, obj, ''); - assertFalse(includes(array, obj)); - assertEquals(0, array.length); -}; - ApiTest.prototype.testSum = function(){ assertEquals(3, angular.Array.sum([{a:"1"}, {a:"2"}], 'a')); }; @@ -48,13 +27,6 @@ ApiTest.prototype.testSumContainingNaN = function(){ 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); @@ -80,14 +52,6 @@ ApiTest.prototype.testRemove = function(){ 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); @@ -161,16 +125,6 @@ ApiTest.prototype.testCount = function() { 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"])); @@ -211,33 +165,6 @@ 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)); diff --git a/test/BinderTest.js b/test/BinderTest.js index 1b1201fa..f38383ae 100644 --- a/test/BinderTest.js +++ b/test/BinderTest.js @@ -407,6 +407,10 @@ BinderTest.prototype.testBindClass = function() { BinderTest.prototype.testBindClassEvenOdd = function() { var x = this.compile('<div><div ng:repeat="i in [0,1]" ng:class-even="\'e\'" ng:class-odd="\'o\'"/></div>'); x.scope.$eval(); + var d1 = jqLite(x.node[0].childNodes[1]); + var d2 = jqLite(x.node[0].childNodes[2]); + expect(d1.hasClass('o')).toBeTruthy(); + expect(d2.hasClass('e')).toBeTruthy(); assertEquals( '<div><#comment></#comment>' + '<div class="o" ng:class-even="\'e\'" ng:class-odd="\'o\'" ng:repeat-index="0"></div>' + @@ -472,13 +476,6 @@ BinderTest.prototype.testRepeaterShouldBindInputsDefaults = function () { assertEquals("misko", c.scope.$eval('items[1].name')); }; -BinderTest.prototype.testRepeaterShouldCreateArray = function () { - var c = this.compile('<input value="123" name="item.name" ng:repeat="item in items">'); - c.scope.$eval(); - - assertEquals(0, c.scope.$get('items').length); -}; - BinderTest.prototype.testShouldTemplateBindPreElements = function () { var c = this.compile('<pre>Hello {{name}}!</pre>'); c.scope.$set("name", "World"); diff --git a/test/BrowserSpecs.js b/test/BrowserSpecs.js index 3ce158b4..99632928 100644 --- a/test/BrowserSpecs.js +++ b/test/BrowserSpecs.js @@ -1,10 +1,14 @@ describe('browser', function(){ - var browser, location; + var browser, location, head; beforeEach(function(){ location = {href:"http://server", hash:""}; - browser = new Browser(location, {}); + head = { + scripts: [], + append: function(node){head.scripts.push(node);} + }; + browser = new Browser(location, jqLite(window.document), head); browser.setTimeout = noop; }); @@ -45,4 +49,22 @@ describe('browser', function(){ }); }); + describe('xhr', function(){ + describe('JSON', function(){ + it('should add script tag for request', function() { + var log = ""; + browser.xhr('JSON', 'http://example.org/path?cb=JSON_CALLBACK', function(code, data){ + log += code + ':' + data + ';'; + }); + expect(head.scripts.length).toEqual(1); + var url = head.scripts[0].src.split('?cb='); + expect(url[0]).toEqual('http://example.org/path'); + expect(typeof window[url[1]]).toEqual('function'); + window[url[1]]('data'); + expect(log).toEqual('200:data;'); + expect(typeof window[url[1]]).toEqual('undefined'); + }); + }); + }); + }); diff --git a/test/CompilerSpec.js b/test/CompilerSpec.js index da354ea5..1091337b 100644 --- a/test/CompilerSpec.js +++ b/test/CompilerSpec.js @@ -1,5 +1,5 @@ describe('compiler', function(){ - var compiler, textMarkup, directives, widgets, compile, log; + var compiler, markup, directives, widgets, compile, log; beforeEach(function(){ log = ""; @@ -20,10 +20,10 @@ describe('compiler', function(){ } }; - textMarkup = []; + markup = []; attrMarkup = []; - widgets = {}; - compiler = new Compiler(textMarkup, attrMarkup, directives, widgets); + widgets = extensionMap({}, 'widget'); + compiler = new Compiler(markup, attrMarkup, directives, widgets); compile = function(html){ var e = jqLite("<div>" + html + "</div>"); var scope = compiler.compile(e)(e); @@ -94,7 +94,7 @@ describe('compiler', function(){ }); it('should process markup before directives', function(){ - textMarkup.push(function(text, textNode, parentNode) { + markup.push(function(text, textNode, parentNode) { if (text == 'middle') { expect(textNode.text()).toEqual(text); parentNode.attr('hello', text); @@ -126,7 +126,7 @@ describe('compiler', function(){ this.directives(true); return noop; }; - textMarkup.push(function(text, textNode, parent){ + markup.push(function(text, textNode, parent){ if (text == '{{1+2}}') parent.text('3'); }); diff --git a/test/FiltersTest.js b/test/FiltersTest.js index 903a7a2f..d5484fd0 100644 --- a/test/FiltersTest.js +++ b/test/FiltersTest.js @@ -41,54 +41,6 @@ FiltersTest.prototype.testJson = function () { assertEquals(toJson({a:"b"}, true), angular.filter.json.call({$element:jqLite('<div></div>')}, {a:"b"})); }; -FiltersTest.prototype.testPackageTracking = function () { - var assert = function(title, trackingNo) { - var val = angular.filter.trackPackage(trackingNo, title); - assertNotNull("Did Not Match: " + trackingNo, val); - assertEquals(title + ": " + trim(trackingNo), val.text()); - assertNotNull(val.attr('href')); - }; - assert('UPS', ' 1Z 999 999 99 9999 999 9 '); - assert('UPS', '1ZW5w5220379084747'); - - assert('FedEx', '418822131061812'); - assert('FedEx', '9612019 5935 3267 2473 738'); - assert('FedEx', '9612019593532672473738'); - assert('FedEx', '235354667129449'); - assert('FedEx', '915368880571'); - assert('FedEx', '901712142390'); - assert('FedEx', '297391510063413'); - - assert('USPS', '9101 8052 1390 7402 4335 49'); - assert('USPS', '9101010521297963339560'); - assert('USPS', '9102901001301038667029'); - assert('USPS', '910 27974 4490 3000 8916 56'); - assert('USPS', '9102801438635051633253'); -}; - -FiltersTest.prototype.testLink = function() { - var assert = function(text, url, obj){ - var val = angular.filter.link(obj); - assertEquals('<a href="' + url + '">' + text + '</a>', sortedHtml(val)); - }; - assert("url", "url", "url"); - assert("hello", "url", {text:"hello", url:"url"}); - assert("a@b.com", "mailto:a@b.com", "a@b.com"); -}; - -FiltersTest.prototype.testImage = function(){ - assertEquals(null, angular.filter.image()); - assertEquals(null, angular.filter.image({})); - assertEquals(null, angular.filter.image("")); - assertEquals('http://localhost/abc', angular.filter.image({url:"http://localhost/abc"}).attr('src')); -}; - -FiltersTest.prototype.testQRcode = function() { - assertEquals( - 'http://chart.apis.google.com/chart?chl=Hello%20world&chs=200x200&cht=qr', - angular.filter.qrcode('Hello world').attr('src')); -}; - FiltersTest.prototype.testLowercase = function() { assertEquals('abc', angular.filter.lowercase('AbC')); assertEquals(null, angular.filter.lowercase(null)); @@ -99,30 +51,6 @@ FiltersTest.prototype.testUppercase = function() { assertEquals(null, angular.filter.uppercase(null)); }; -FiltersTest.prototype.testLineCount = function() { - assertEquals(1, angular.filter.linecount(null)); - assertEquals(1, angular.filter.linecount('')); - assertEquals(1, angular.filter.linecount('a')); - assertEquals(2, angular.filter.linecount('a\nb')); - assertEquals(3, angular.filter.linecount('a\nb\nc')); -}; - -FiltersTest.prototype.testIf = function() { - assertEquals('A', angular.filter['if']('A', true)); - assertEquals(undefined, angular.filter['if']('A', false)); -}; - -FiltersTest.prototype.testUnless = function() { - assertEquals('A', angular.filter.unless('A', false)); - assertEquals(undefined, angular.filter.unless('A', true)); -}; - -FiltersTest.prototype.testGoogleChartApiEncode = function() { - assertEquals( - '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() { var html = angular.filter.html("a<b>c</b>d"); expect(html instanceof HTML).toBeTruthy(); @@ -140,4 +68,3 @@ FiltersTest.prototype.testLinky = function() { assertEquals(undefined, linky(undefined)); }; - diff --git a/test/JsonTest.js b/test/JsonTest.js index 1ed56da8..f6da26b5 100644 --- a/test/JsonTest.js +++ b/test/JsonTest.js @@ -74,6 +74,13 @@ JsonTest.prototype.testItShouldPreventRecursion = function () { assertEquals('{"a":"b","recursion":RECURSION}', angular.toJson(obj)); }; +JsonTest.prototype.testItShouldSerializeOnlyOwnProperties = function() { + var parent = createScope(); + var child = createScope(parent); + child.c = 'c'; + expect(angular.toJson(child)).toEqual('{"c":"c"}'); +}; + JsonTest.prototype.testItShouldSerializeSameObjectsMultipleTimes = function () { var obj = {a:'b'}; assertEquals('{"A":{"a":"b"},"B":{"a":"b"}}', angular.toJson({A:obj, B:obj})); @@ -82,3 +89,7 @@ JsonTest.prototype.testItShouldSerializeSameObjectsMultipleTimes = function () { JsonTest.prototype.testItShouldNotSerializeUndefinedValues = function () { assertEquals('{}', angular.toJson({A:undefined})); }; + +JsonTest.prototype.testItShouldParseFloats = function () { + expect(fromJson("{value:2.55, name:'misko'}")).toEqual({value:2.55, name:'misko'}); +}; diff --git a/test/ParserTest.js b/test/ParserTest.js index 7ba65f18..d7fd2f94 100644 --- a/test/ParserTest.js +++ b/test/ParserTest.js @@ -147,6 +147,11 @@ LexerTest.prototype.testStatements = function(){ assertEquals(tokens[3].text, ';'); }; +LexerTest.prototype.testNumber = function(){ + var tokens = new Lexer("0.5").parse(); + expect(tokens[0].text).toEqual(0.5); +}; + ParserTest = TestCase('ParserTest'); ParserTest.prototype.testExpressions = function(){ diff --git a/test/ResourceSpec.js b/test/ResourceSpec.js index 4882e70e..546e9aec 100644 --- a/test/ResourceSpec.js +++ b/test/ResourceSpec.js @@ -28,6 +28,18 @@ describe("resource", function() { resource.route('URL').query(); }); + it('should ignore slashes of undefinend parameters', function(){ + var R = resource.route('/Path/:a/:b/:c'); + xhr.expectGET('/Path').respond({}); + xhr.expectGET('/Path/1').respond({}); + xhr.expectGET('/Path/2/3').respond({}); + xhr.expectGET('/Path/4/5/6').respond({}); + R.get({}); + R.get({a:1}); + R.get({a:2, b:3}); + R.get({a:4, b:5, c:6}); + }); + 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}); @@ -102,6 +114,13 @@ describe("resource", function() { CreditCard.charge({id:123, amount:10},{auth:'abc'}, callback); }); + it('should post charge verb on instance', function(){ + xhr.expectPOST('/CreditCard/123!charge?amount=10', {id:{key:123}, name:'misko'}).respond({success:'ok'}); + + var card = new CreditCard({id:{key:123}, name:'misko'}); + card.$charge({amount:10}, callback); + }); + it('should create on save', function(){ xhr.expectPOST('/CreditCard', {name:'misko'}).respond({id:123}); var cc = new CreditCard(); diff --git a/test/ScopeSpec.js b/test/ScopeSpec.js index d93400e5..ea63fea4 100644 --- a/test/ScopeSpec.js +++ b/test/ScopeSpec.js @@ -15,28 +15,42 @@ describe('scope/model', function(){ expect(model.$root).toEqual(model); }); + it('should return noop function when LHS is undefined', function(){ + var model = createScope(); + expect(model.$eval('x.$filter()')).toEqual(undefined); + }); + 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'); + var model; + + beforeEach(function(){model = createScope();}); + + it('should eval function with correct this', function(){ + model.$eval(function(){ + this.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 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(); }); + + it('should ignore none string/function', function(){ + model.$eval(null); + model.$eval({}); + model.$tryEval(null); + model.$tryEval({}); + }); + }); describe('$watch', function(){ diff --git a/test/angular-mocks.js b/test/angular-mocks.js index 8838b2cd..bac2e800 100644 --- a/test/angular-mocks.js +++ b/test/angular-mocks.js @@ -66,6 +66,7 @@ function MockBrowser() { 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.expectJSON = angular.bind(self, self.xhr.expect, 'JSON'); self.xhr.flush = function() { while(requests.length) { requests.pop()(); diff --git a/test/delete/ScopeTest.js b/test/delete/ScopeTest.js deleted file mode 100644 index 24febf19..00000000 --- a/test/delete/ScopeTest.js +++ /dev/null @@ -1,145 +0,0 @@ -ScopeTest = TestCase('ScopeTest'); - -ScopeTest.prototype.testGetScopeRetrieval = function(){ - var scope = {}; - var form = jQuery("<a><b><c></c></b></a>"); - form.data('scope', scope); - var c = form.find('c'); - assertTrue(scope === c.scope()); -}; - -ScopeTest.prototype.testGetScopeRetrievalIntermediateNode = function(){ - var scope = {}; - var form = jQuery("<a><b><c></c></b></a>"); - form.find("b").data('scope', scope); - var b = form.find('b'); - assertTrue(scope === b.scope()); -}; - -ScopeTest.prototype.testNoScopeDoesNotCauseInfiniteRecursion = function(){ - var form = jQuery("<a><b><c></c></b></a>"); - 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/delete/WidgetsTest.js b/test/delete/WidgetsTest.js deleted file mode 100644 index ccc87afd..00000000 --- a/test/delete/WidgetsTest.js +++ /dev/null @@ -1,268 +0,0 @@ -WidgetTest = TestCase('WidgetTest'); - -WidgetTest.prototype.testRequired = function () { - var view = $('<input name="a" ng:required>'); - 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 = $('<input name="a" ng:validate="testValidator:\'ABC\'">'); - 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 = $('<input name="a" ng:required ng:validate="testValidator:\'ABC\'">'); - 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 type="text" ng-widget="datepicker">'); - 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 = $("<div><span/></div>"); - var template = function () { - return $("<li/>"); - }; - 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 = $('<span />'); - 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 = $('<span />'); - 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 = $('<span />'); - var controller = new BindUpdater(view[0], "<fake>&{{obj}}</fake>"); - var scope = new Scope(); - - scope.set("obj", $('<div>myDiv</div>')[0]); - controller.updateView(scope); - assertEquals("<fake>&myDiv</fake>", view.text()); -}; - - -BindUpdaterTest.prototype.testShouldDisplayTextMethod = function () { - var view = $('<div />'); - 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 = $('<div />'); - var controller = new BindUpdater(view[0], "{{obj}}"); - var scope = new Scope(); - - scope.set("obj", new angular.filter.Meta({html:function(){return "a<div>b</div>c";}})); - controller.updateView(scope); - assertEquals("abc", view.text()); - - scope.set("obj", new angular.filter.Meta({html:"1<div>2</div>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 = $('<div />'); - 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 = $('<img />'); - 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 = $('<div/>'); - 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 = $('<input type="radio" name="select" value="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/directivesSpec.js b/test/directivesSpec.js index ef4814bf..f0eb5c09 100644 --- a/test/directivesSpec.js +++ b/test/directivesSpec.js @@ -29,35 +29,60 @@ describe("directives", function(){ expect(scope.a).toEqual(2); }); - it('should ng:bind', function() { - var scope = compile('<div ng:bind="a"></div>'); - expect(element.text()).toEqual(''); - scope.a = 'misko'; - scope.$eval(); - expect(element.text()).toEqual('misko'); - }); + describe('ng:bind', function(){ + it('should set text', function() { + var scope = compile('<div ng:bind="a"></div>'); + expect(element.text()).toEqual(''); + scope.a = 'misko'; + scope.$eval(); + expect(element.text()).toEqual('misko'); + }); - it('should ng:bind html', function() { - var scope = compile('<div ng:bind="html|html"></div>'); - scope.html = '<div>hello</div>'; - scope.$eval(); - expect(lowercase(element.html())).toEqual('<div>hello</div>'); - }); + it('should set html', function() { + var scope = compile('<div ng:bind="html|html"></div>'); + scope.html = '<div>hello</div>'; + scope.$eval(); + expect(lowercase(element.html())).toEqual('<div>hello</div>'); + }); + + it('should set element element', function() { + angularFilter.myElement = function() { + return jqLite('<a>hello</a>'); + }; + var scope = compile('<div ng:bind="0|myElement"></div>'); + scope.$eval(); + expect(lowercase(element.html())).toEqual('<a>hello</a>'); + }); + + it('should have $element set to current bind element', function(){ + angularFilter.myFilter = function(){ + this.$element.text('HELLO'); + }; + var scope = compile('<div>before<div ng:bind="0|myFilter"></div>after</div>'); + expect(scope.$element.text()).toEqual("beforeHELLOafter"); + }); - it('should ng:bind element', function() { - angularFilter.myElement = function() { - return jqLite('<a>hello</a>'); - }; - var scope = compile('<div ng:bind="0|myElement"></div>'); - scope.$eval(); - expect(lowercase(element.html())).toEqual('<a>hello</a>'); }); - it('should ng:bind-template', function() { - var scope = compile('<div ng:bind-template="Hello {{name}}!"></div>'); - scope.$set('name', 'Misko'); - scope.$eval(); - expect(element.text()).toEqual('Hello Misko!'); + describe('ng:bind-template', function(){ + it('should ng:bind-template', function() { + var scope = compile('<div ng:bind-template="Hello {{name}}!"></div>'); + scope.$set('name', 'Misko'); + scope.$eval(); + expect(element.text()).toEqual('Hello Misko!'); + }); + + it('should have $element set to current bind element', function(){ + var innerText = 'blank'; + angularFilter.myFilter = function(text){ + innerText = this.$element.text(); + return text; + }; + var scope = compile('<div>before<span ng:bind-template="{{\'HELLO\'|myFilter}}">INNER</span>after</div>'); + expect(scope.$element.text()).toEqual("beforeHELLOafter"); + expect(innerText).toEqual('INNER'); + }); + }); it('should ng:bind-attr', function(){ @@ -115,11 +140,6 @@ describe("directives", function(){ expect(element.text()).toEqual('misko:swe;shyam:set;'); }); - it('should set ng:repeat to [] if undefinde', function(){ - var scope = compile('<ul><li ng:repeat="item in items"></li></ul>'); - expect(scope.items).toEqual([]); - }); - it('should error on wrong parsing of ng:repeat', function(){ var scope = compile('<ul><li ng:repeat="i dont parse"></li></ul>'); var log = ""; @@ -140,13 +160,15 @@ describe("directives", function(){ expect(scope.$get('count')).toEqual(1); }); - it('should ng:click', function(){ - var scope = compile('<div ng:click="clicked = true"></div>'); - scope.$eval(); - expect(scope.$get('clicked')).toBeFalsy(); + describe('ng:click', function(){ + it('should fire event', function(){ + var scope = compile('<div ng:click="clicked = true"></div>'); + scope.$eval(); + expect(scope.$get('clicked')).toBeFalsy(); - element.trigger('click'); - expect(scope.$get('clicked')).toEqual(true); + element.trigger('click'); + expect(scope.$get('clicked')).toEqual(true); + }); }); it('should ng:class', function(){ @@ -168,16 +190,35 @@ describe("directives", function(){ expect(e2.hasClass('even')).toBeTruthy(); }); - it('should ng:style', function(){ - var scope = compile('<div ng:style="{color:\'red\'}"></div>'); - scope.$eval(); - expect(element.css('color')).toEqual('red'); + describe('ng:style', function(){ + it('should set', function(){ + var scope = compile('<div ng:style="{color:\'red\'}"></div>'); + scope.$eval(); + expect(element.css('color')).toEqual('red'); + }); + + it('should silently ignore undefined style', function() { + var scope = compile('<div ng:style="myStyle"></div>'); + scope.$eval(); + expect(element.hasClass('ng-exception')).toBeFalsy(); + }); + + it('should preserve and remove previous style', function(){ + var scope = compile('<div style="color:red;" ng:style="myStyle"></div>'); + scope.$eval(); + expect(getStyle(element)).toEqual({color:'red'}); + scope.myStyle = {color:'blue', width:'10px'}; + scope.$eval(); + expect(getStyle(element)).toEqual({color:'blue', width:'10px'}); + scope.myStyle = {}; + scope.$eval(); + expect(getStyle(element)).toEqual({color:'red'}); + }); }); it('should silently ignore undefined ng:style', function() { var scope = compile('<div ng:style="myStyle"></div>'); scope.$eval(); - dump(sortedHtml(element)); expect(element.hasClass('ng-exception')).toBeFalsy(); }); diff --git a/test/moveToAngularCom/Base64Test.js b/test/moveToAngularCom/Base64Test.js deleted file mode 100644 index a9353186..00000000 --- a/test/moveToAngularCom/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/moveToAngularCom/DataStoreTest.js b/test/moveToAngularCom/DataStoreTest.js deleted file mode 100644 index 87c5be2e..00000000 --- a/test/moveToAngularCom/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/moveToAngularCom/EntityDeclarationTest.js b/test/moveToAngularCom/EntityDeclarationTest.js deleted file mode 100644 index 28986ea8..00000000 --- a/test/moveToAngularCom/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/moveToAngularCom/FileControllerTest.js b/test/moveToAngularCom/FileControllerTest.js deleted file mode 100644 index 75c924e6..00000000 --- a/test/moveToAngularCom/FileControllerTest.js +++ /dev/null @@ -1,98 +0,0 @@ -FileControllerTest = TestCase('FileControllerTest'); - -FileControllerTest.prototype.XtestOnSelectUpdateView = function(){ - var view = jQuery('<span><a/><span/></span>'); - 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 = $('<input name="value.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 = $('<input name="file">'); - 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 deleted file mode 100644 index aa0e1186..00000000 --- a/test/moveToAngularCom/MiscTest.js +++ /dev/null @@ -1,35 +0,0 @@ -BinderTest.prototype.testExpandEntityTagWithName = function(){ - var c = this.compile('<div ng-entity="friend=Person"/>'); - assertEquals( - '<div ng-entity="friend=Person" ng-watch="$anchor.friend:{friend=Person.load($anchor.friend);friend.$$anchor=\"friend\";};"></div>', - 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('<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.testReplaceFileUploadWithSwf = function(){ - expectAsserts(1); - var form = jQuery("body").append('<div id="testTag"><input type="file"></div>'); - 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( - '<div ng-entity="Person:{a:\"a\"}" ng-watch=""></div>', - this.compileToHtml('<div ng-entity=\'Person:{a:"a"}\'/>')); -}; - diff --git a/test/moveToAngularCom/ModelTest.js b/test/moveToAngularCom/ModelTest.js deleted file mode 100644 index dbd97778..00000000 --- a/test/moveToAngularCom/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/moveToAngularCom/ServerTest.js b/test/moveToAngularCom/ServerTest.js deleted file mode 100644 index 02fab84c..00000000 --- a/test/moveToAngularCom/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/moveToAngularCom/UsersTest.js b/test/moveToAngularCom/UsersTest.js deleted file mode 100644 index f0ff545a..00000000 --- a/test/moveToAngularCom/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/scenario/DSLSpec.js b/test/scenario/DSLSpec.js index 5aac9752..f8606641 100644 --- a/test/scenario/DSLSpec.js +++ b/test/scenario/DSLSpec.js @@ -1,39 +1,39 @@ describe("DSL", function() { - var lastStep, executeStep, lastDocument; + var lastDocument, executeFuture, Expect; beforeEach(function() { - lastStep = null; - $scenario = { - addStep: function(name, stepFunction) { - lastStep = { name:name, fn: stepFunction}; - } - }; - executeStep = function(step, html, callback) { - lastDocument =_jQuery('<div>' + html + '</div>'); + setUpContext(); + executeFuture = function(future, html, callback) { + lastDocument = _jQuery('<div>' + html + '</div>'); + lastFrame = _jQuery('<iframe>' + lastDocument + '</iframe>'); _jQuery(document.body).append(lastDocument); var specThis = { testWindow: window, - testDocument: lastDocument + testDocument: lastDocument, + testFrame: lastFrame, + jQuery: _jQuery }; - step.fn.call(specThis, callback || noop); + future.behavior.call(specThis, callback || noop); }; + Expect = _window.expect; }); 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, '<input type="text" name="name" />'); + var future = input('name').enter('John'); + expect(future.name).toEqual("input 'name' enter 'John'"); + executeFuture(future, '<input type="text" name="name" />'); 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, + var future = input('gender').select('female'); + expect(future.name).toEqual("input 'gender' select 'female'"); + executeFuture(future, '<input type="radio" name="0@gender" value="male" checked/>' + '<input type="radio" name="0@gender" value="female"/>'); expect(lastDocument.find(':radio:checked').length).toEqual(1); @@ -41,15 +41,145 @@ describe("DSL", function() { }); }); - 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 that there are 2 items in Repeater with selector '.repeater-row'"); - var html = "<div class='repeater-row'>a</div><div class='repeater-row'>b</div>"; - executeStep(lastStep, html); + describe('browser', function() { + var browser = angular.scenario.dsl.browser; + it('shoud return true if location with empty hash provided is same ' + + 'as location of the page', function() { + browser.location.href = "http://server"; + expect(browser.location.toEqual("http://server")).toEqual(true); + }); + it('shoud return true if location with hash provided is same ' + + 'as location of the page', function() { + browser.location.href = "http://server"; + browser.location.hash = "hashPath"; + expect(browser.location.toEqual("http://server/#/hashPath")) + .toEqual(true); + }); + it('should return true if the location provided is the same as which ' + + 'browser navigated to', function() { + var future = browser.navigateTo("http://server/#/hashPath"); + expect(future.name).toEqual("Navigate to: http://server/#/hashPath"); + executeFuture(future, '<input type="text" name="name" />'); + expect(browser.location.toEqual("http://server/#/hashPath")) + .toEqual(true); + expect(browser.location.toEqual("http://server/")) + .toEqual(false); + + future = browser.navigateTo("http://server/"); + expect(future.name).toEqual("Navigate to: http://server/"); + executeFuture(future, '<input type="text" name="name" />'); + expect(browser.location.toEqual("http://server/")) + .toEqual(true); + }); + }); + + describe('repeater', function() { + + var repeater = angular.scenario.dsl.repeater; + var html; + beforeEach(function() { + html = "<table>" + + "<tr class='epic'>" + + "<td class='hero-name'>" + + "<span ng:bind='hero'>John Marston</span>" + + "</td>" + + "<td class='game-name'>" + + "<span ng:bind='game'>Red Dead Redemption</span>" + + "</td>" + + "</tr>" + + "<tr class='epic'>" + + "<td class='hero-name'>" + + "<span ng:bind='hero'>Nathan Drake</span>" + + "</td>" + + "<td class='game-name'>" + + "<span ng:bind='game'>Uncharted</span>" + + "</td>" + + "</tr>" + + "</table>"; + }); + it('should count', function() { + var future = repeater('.repeater-row').count(); + expect(future.name).toEqual("repeater '.repeater-row' count"); + executeFuture(future, + "<div class='repeater-row'>a</div>" + + "<div class='repeater-row'>b</div>", + function(value) { + future.fulfill(value); }); + expect(future.fulfilled).toBeTruthy(); + expect(future.value).toEqual(2); + }); + + function assertFutureState(future, expectedName, expectedValue) { + expect(future.name).toEqual(expectedName); + executeFuture(future, html, function(value) { + future.fulfill(value); + }); + expect(future.fulfilled).toBeTruthy(); + expect(future.value).toEqual(expectedValue); + } + it('should collect bindings', function() { + assertFutureState(repeater('.epic').collect('{{hero}}'), + "repeater '.epic' collect '{{hero}}'", + ['John Marston', 'Nathan Drake']); + assertFutureState(repeater('.epic').collect('{{game}}'), + "repeater '.epic' collect '{{game}}'", + ['Red Dead Redemption', 'Uncharted']); + }); + it('should collect normal selectors', function() { + assertFutureState(repeater('.epic').collect('.hero-name'), + "repeater '.epic' collect '.hero-name'", + ['John Marston', 'Nathan Drake']); + assertFutureState(repeater('.epic').collect('.game-name'), + "repeater '.epic' collect '.game-name'", + ['Red Dead Redemption', 'Uncharted']); + }); + it('should collect normal attributes', function() { + //TODO(shyamseshadri) : Left as an exercise to the user + }); + }); + + describe('element', function() { + var element = angular.scenario.dsl.element; + var html; + beforeEach(function() { + html = '<div class="container">' + + '<div class="reports-detail">' + + '<span class="desc">Description : ' + + '<span ng:bind="report.description">Details...</span>' + + '</span>' + + '<span>Date created: ' + + '<span ng:bind="report.creationDate">01/01/01</span>' + + '</span>' + + '</div>' + + '</div>'; + }); + function timeTravel(future) { + executeFuture(future, html, function(value) { future.fulfill(value); }); + expect(future.fulfilled).toBeTruthy(); + } + it('should find elements on the page and provide jquery api', function() { + var future = element('.reports-detail').text(); + expect(future.name).toEqual("Element '.reports-detail'.text()"); + timeTravel(future); + expect(future.value). + toEqual('Description : Details...Date created: 01/01/01'); +// expect(future.value.find('.desc').text()). +// toEqual('Description : Details...'); + }); + it('should find elements with angular syntax', function() { + var future = element('{{report.description}}').text(); + expect(future.name).toEqual("Element '{{report.description}}'.text()"); + timeTravel(future); + expect(future.value).toEqual('Details...'); +// expect(future.value.attr('ng:bind')).toEqual('report.description'); + }); + it('should be able to click elements', function(){ + var future = element('.link-class').click(); + expect(future.name).toEqual("Element '.link-class'.click()"); + executeFuture(future, html, function(value) { future.fulfill(value); }); + expect(future.fulfilled).toBeTruthy(); + // TODO(rajat): look for some side effect from click happening? }); }); }); diff --git a/test/scenario/MatcherSpec.js b/test/scenario/MatcherSpec.js new file mode 100644 index 00000000..2eddd2bc --- /dev/null +++ b/test/scenario/MatcherSpec.js @@ -0,0 +1,38 @@ +describe('Matcher', function () { + function executeFutures() { + for(var i in $scenario.currentSpec.futures) { + var future = $scenario.currentSpec.futures[i]; + future.behavior.call({}, function(value) { future.fulfill(value); }); + } + } + var matcher; + beforeEach(function() { + setUpContext(); + var future = $scenario.addFuture('Calculate first future', function(done) { + done(123); + }); + matcher = new Matcher(this, future); + + }); + it('should correctly match toEqual', function() { + matcher.toEqual(123); + executeFutures(); + }); + it('should throw an error when incorrect match toEqual', function() { + matcher.toEqual(456); + try { + executeFutures(); + fail(); + } catch (e) { + expect(e).toEqual('Expected 456 but was 123'); + } + }); + it('should correctly match arrays', function() { + var future = $scenario.addFuture('Calculate first future', function(done) { + done(['a', 'b']); + }); + matcher = new Matcher(this, future); + matcher.toEqual(['a', 'b']); + executeFutures(); + }); +});
\ No newline at end of file diff --git a/test/scenario/RunnerSpec.js b/test/scenario/RunnerSpec.js index bbdd9e8c..b12c43c6 100644 --- a/test/scenario/RunnerSpec.js +++ b/test/scenario/RunnerSpec.js @@ -1,40 +1,30 @@ -describe('Runner', function(){ - var scenario, runner, log, Describe, It, $scenario, body; - - function logger(text) { - return function(done){ - log += text; - (done||noop)(); - }; - } - - beforeEach(function(){ - log = ''; - scenario = {}; +describe('Runner', function() { + + var Describe, It, BeforeEach, AfterEach, body; + + beforeEach(function() { + setUpContext(); + Describe = _window.describe; + It = _window.it; + BeforeEach = _window.beforeEach; + AfterEach = _window.afterEach; body = _jQuery('<div></div>'); - runner = new angular.scenario.Runner(scenario, _jQuery); - Describe = scenario.describe; - BeforeEach = scenario.beforeEach; - AfterEach = scenario.afterEach; - It = scenario.it; - $scenario = scenario.$scenario; }); - describe('describe', function(){ - it('should consume the describe functions', function(){ + 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(){ + 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.futures).toEqual([]); expect(spec.name).toEqual('describe name: it should text'); }); @@ -42,18 +32,18 @@ describe('Runner', function(){ // WRITE ME!!!! }); - it('should create a failing step if there is a javascript error', function(){ + it('should create a failing future if there is a javascript error', function() { var spec; - Describe('D1', function(){ - It('I1', function(){ + Describe('D1', function() { + It('I1', function() { spec = $scenario.currentSpec; throw {message: 'blah'}; }); }); - var step = spec.steps[0]; - expect(step.name).toEqual('blah'); + var future = spec.futures[0]; + expect(future.name).toEqual('blah'); try { - step.fn(); + future.behavior(); fail(); } catch (e) { expect(e.message).toEqual('blah'); @@ -63,7 +53,7 @@ describe('Runner', function(){ describe('beforeEach', function() { it('should execute beforeEach before every it', function() { - Describe('describe name', function(){ + Describe('describe name', function() { BeforeEach(logger('before;')); It('should text', logger('body;')); It('should text2', logger('body2;')); @@ -73,7 +63,7 @@ describe('Runner', function(){ }); describe('afterEach', function() { it('should execute afterEach after every it', function() { - Describe('describe name', function(){ + Describe('describe name', function() { AfterEach(logger('after;')); It('should text1', logger('body1;')); It('should text2', logger('body2;')); @@ -82,7 +72,7 @@ describe('Runner', function(){ }); it('should always execute afterEach after every it', function() { - Describe('describe name', function(){ + Describe('describe name', function() { AfterEach(logger('after;')); It('should text', function() { logger('body1;')(); @@ -95,62 +85,63 @@ describe('Runner', function(){ it('should report an error if afterEach fails', function() { var next; - Describe('describe name', function(){ + Describe('describe name', function() { AfterEach(function() { - $scenario.addStep('afterEachLog', logger('after;')); - $scenario.addStep('afterEachThrow', function() { + $scenario.addFuture('afterEachLog', logger('after;')); + $scenario.addFuture('afterEachThrow', function() { throw "AfterError"; }); }); It('should text1', function() { - $scenario.addStep('step1', logger('step1;')); + $scenario.addFuture('future1', logger('future1;')); }); It('should text2', function() { - $scenario.addStep('step2', logger('step2;')); + $scenario.addFuture('future2', logger('future2;')); }); }); $scenario.run(body); - expect(log).toEqual('step1;after;step2;after;'); - expect(scenario.$testrun.results).toEqual([ + expect(log).toEqual('future1;after;future2;after;'); + expect(_window.$testrun.results).toEqual([ { name : 'describe name: it should text1', passed : false, error : 'AfterError', - steps : [ 'step1', 'afterEachLog', 'afterEachThrow' ] }, + steps : [ 'future1', 'afterEachLog', 'afterEachThrow' ] }, { name : 'describe name: it should text2', passed : false, error : 'AfterError', - steps : [ 'step2', 'afterEachLog', 'afterEachThrow' ] }]); + steps : [ 'future2', 'afterEachLog', 'afterEachThrow' ] }]); }); }); }); - describe('steps building', function(){ - it('should queue steps', function(){ - function step(){}; - Describe('name', function(){ - It('should', function(){ - $scenario.addStep('stepname', step); + describe('future building', function() { + it('should queue futures', function() { + function behavior(){}; + Describe('name', function() { + It('should', function() { + $scenario.addFuture('futureName', behavior); }); }); - expect($scenario.specs['name: it should'].steps).toEqual([{name:'stepname', fn:step}]); + expect($scenario.specs['name: it should'].futures[0].name). + toEqual('futureName'); }); }); - describe('execution', function(){ - it('should execute the queued steps', function(){ + describe('execution', function() { + it('should execute the queued futures', 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; - }} + futures: [ + new Future('future1', function(done) { + next = done; + log += 'first;'; + firstThis = this; + }), + new Future('future2', function(done) { + next = done; + log += 'second;'; + secondThis = this; + }) ] }; @@ -174,18 +165,18 @@ describe('Runner', function(){ expect(spec.result.passed).toEqual(true); }); - it('should handle exceptions in a step', function(){ + it('should handle exceptions in a future', function() { $scenario.specs['spec'] = { - steps: [ - {name: 'first step', fn: function(done) { + futures: [ + new Future('first future', function(done) { done(); - }}, - {name:'error', fn:function(done) { + }), + new Future('error', function(done) { throw "MyError"; - }}, - {name: 'should not execute', fn: function(done) { + }), + new Future('should not execute', function(done) { done(); - }} + }) ] }; @@ -195,30 +186,30 @@ describe('Runner', function(){ expect(spec.result.failed).toEqual(true); expect(spec.result.finished).toEqual(true); expect(spec.result.error).toEqual("MyError"); - expect(scenario.$testrun.results).toEqual([{ + expect(_window.$testrun.results).toEqual([{ name: 'spec', passed: false, error: 'MyError', - steps: ['first step', 'error']}]); + steps: ['first future', 'error']}]); }); }); - describe('run', function(){ + describe('run', function() { var next; beforeEach(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('d1', function() { + It('it1', function() { $scenario.addFuture('s1', logger('s1,')); }); + It('it2', function() { + $scenario.addFuture('s2', logger('s2,')); + $scenario.addFuture('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,')); }); + Describe('d2', function() { + It('it3', function() { $scenario.addFuture('s3', logger('s3,')); }); + It('it4', function() { $scenario.addFuture('s4', logger('s4,')); }); }); }); - it('should execute all specs', function(){ + it('should execute all specs', function() { $scenario.run(body); expect(log).toEqual('s1,s2,'); @@ -226,20 +217,20 @@ describe('Runner', function(){ expect(log).toEqual('s1,s2,s3,s4,'); }); it('should publish done state and results as tests are run', function() { - expect(scenario.$testrun.done).toBeFalsy(); - expect(scenario.$testrun.results).toEqual([]); + expect(_window.$testrun.done).toBeFalsy(); + expect(_window.$testrun.results).toEqual([]); $scenario.run(body); - expect(scenario.$testrun.done).toBeFalsy(); - expect(scenario.$testrun.results).toEqual([ - {name: 'd1: it it1', passed: true, steps: ['s1']} + expect(_window.$testrun.done).toBeFalsy(); + expect(_window.$testrun.results).toEqual([ + {name: 'd1: it it1', passed: true, error: undefined, steps: ['s1']} ]); next(); - expect(scenario.$testrun.done).toBeTruthy(); - expect(scenario.$testrun.results).toEqual([ - {name: 'd1: it it1', passed: true, steps: ['s1']}, - {name: 'd1: it it2', passed: true, steps: ['s2', 's2.2']}, - {name: 'd2: it it3', passed: true, steps: ['s3']}, - {name: 'd2: it it4', passed: true, steps: ['s4']} + expect(_window.$testrun.done).toBeTruthy(); + expect(_window.$testrun.results).toEqual([ + {name: 'd1: it it1', passed: true, error: undefined, steps: ['s1']}, + {name: 'd1: it it2', passed: true, error: undefined, steps: ['s2', 's2.2']}, + {name: 'd2: it it3', passed: true, error: undefined, steps: ['s3']}, + {name: 'd2: it it4', passed: true, error: undefined, steps: ['s4']} ]); }); }); diff --git a/test/scenario/TestContext.js b/test/scenario/TestContext.js new file mode 100644 index 00000000..0c8e6143 --- /dev/null +++ b/test/scenario/TestContext.js @@ -0,0 +1,15 @@ +var _window, runner, log, $scenario; + +function logger(text) { + return function(done){ + log += text; + (done||noop)(); + }; +} + +function setUpContext() { + _window = {}; + runner = new angular.scenario.Runner(_window, _jQuery); + $scenario = _window.$scenario; + log = ''; +} diff --git a/test/servicesSpec.js b/test/servicesSpec.js index 32e7812a..ffd01267 100644 --- a/test/servicesSpec.js +++ b/test/servicesSpec.js @@ -1,5 +1,5 @@ describe("service", function(){ - var scope, $xhrError, $log; + var scope, $xhrError, $log, mockServices; beforeEach(function(){ $xhrError = jasmine.createSpy('$xhr.error'); @@ -33,32 +33,45 @@ describe("service", function(){ 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); + var logger = ""; + function log(){ logger+= 'log;'; }; + function warn(){ logger+= 'warn;'; }; + function info(){ logger+= 'info;'; }; + function error(){ logger+= 'error;'; }; + var scope = createScope(null, angularService, {$window: {console:{log:log, warn:warn, info:info, error:error}}, $document:[{}]}); + scope.$log.log(); + scope.$log.warn(); + scope.$log.info(); + scope.$log.error(); + expect(logger).toEqual('log;warn;info;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); + var logger = ""; + function log(){ logger+= 'log;'; }; + var scope = createScope(null, angularService, {$window: {console:{log:log}}, $document:[{}]}); + scope.$log.log(); + scope.$log.warn(); + scope.$log.info(); + scope.$log.error(); + expect(logger).toEqual('log;log;log;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); + var scope = createScope(null, angularService, {$window: {}, $document:[{}]}); + scope.$log.log(); + scope.$log.warn(); + scope.$log.info(); + scope.$log.error(); + }); + }); + + describe("$exceptionHandler", function(){ + it('should log errors', function(){ + var error = ''; + $log.error = function(m) { error += m; }; + scope.$exceptionHandler('myError'); + expect(error).toEqual('myError'); }); }); @@ -78,7 +91,7 @@ describe("service", function(){ 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'); + expect(scope.$location.toString()).toEqual('http://host:123/p/a/t/h.html?query=value#page%3Dhttp%3A//path?k=a%3Db'); }); it('should parse file://', function(){ @@ -93,7 +106,7 @@ describe("service", function(){ 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#'); + expect(scope.$location.toString()).toEqual('file:///Users/Shared/misko/work/angular.js/scenario/widgets.html'); }); it('should update url on hash change', function(){ @@ -110,6 +123,14 @@ describe("service", function(){ expect(scope.$location.hash).toEqual('?a=b'); }); + 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'); + }); + it('should update hash before any processing', function(){ var scope = compile('<div>'); var log = ''; @@ -123,15 +144,6 @@ describe("service", function(){ scope.$eval(); 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(){ diff --git a/test/testabilityPatch.js b/test/testabilityPatch.js index b71943f6..e9a88b67 100644 --- a/test/testabilityPatch.js +++ b/test/testabilityPatch.js @@ -35,22 +35,25 @@ function childNode(element, index) { } extend(angular, { - 'bind': bind, + 'element': jqLite, 'compile': compile, + 'scope': createScope, 'copy': copy, - 'element': jqLite, 'extend': extend, + 'equals': equals, 'foreach': foreach, + 'noop':noop, + 'bind':bind, + 'toJson': toJson, + 'fromJson': fromJson, 'identity':identity, 'isUndefined': isUndefined, 'isDefined': isDefined, - 'isObject': isObject, 'isString': isString, 'isFunction': isFunction, + 'isObject': isObject, 'isNumber': isNumber, - 'isArray': isArray, - 'noop':noop, - 'scope': createScope + 'isArray': isArray }); @@ -63,6 +66,8 @@ function sortedHtml(element) { html += '<' + node.nodeName.toLowerCase(); var attributes = node.attributes || []; var attrs = []; + if (node.className) + attrs.push(' class="' + node.className + '"'); for(var i=0; i<attributes.length; i++) { var attr = attributes[i]; if(attr.name.match(/^ng:/) || @@ -76,6 +81,7 @@ function sortedHtml(element) { attr.name !='complete' && attr.name !='maxLength' && attr.name !='size' && + attr.name !='class' && attr.name !='start' && attr.name !='tabIndex' && attr.name !='style' && diff --git a/test/widgetsSpec.js b/test/widgetsSpec.js index 03f31bfe..ad98e482 100644 --- a/test/widgetsSpec.js +++ b/test/widgetsSpec.js @@ -407,7 +407,7 @@ describe("widget", function(){ it("should match sandwich ids", function(){ var scope = {}; - var match = angular.widget['NG:SWITCH'].route.call(scope, '/a/123/b', '/a/:id'); + var match = angular.widget('NG:SWITCH').route.call(scope, '/a/123/b', '/a/:id'); expect(match).toBeFalsy(); }); |
