From 669e4aaad27b9d1a69092078ca2fc8e6d468c80b Mon Sep 17 00:00:00 2001 From: "Fabio M. Costa" Date: Mon, 6 Sep 2010 00:30:49 -0300 Subject: [PATCH] Adding Request.HMTL specs --- 1.3client/Request/Request.HTML.js | 99 +++++++++++++++++++++++++++++++ 1.3client/Request/Request.js | 4 +- Configuration.js | 3 +- 3 files changed, 103 insertions(+), 3 deletions(-) create mode 100644 1.3client/Request/Request.HTML.js diff --git a/1.3client/Request/Request.HTML.js b/1.3client/Request/Request.HTML.js new file mode 100644 index 0000000..f209a91 --- /dev/null +++ b/1.3client/Request/Request.HTML.js @@ -0,0 +1,99 @@ +/* +Script: Request.HTML.js + Public Specs for Request.HTML.js 1.3 + +License: + MIT-style license. +*/ + +describe('Request.HTML', function(){ + + beforeEach(function(){ + this.spy = jasmine.createSpy(); + }); + + it('should create an ajax request and detect the correct type of the response (html)', function(){ + + runs(function(){ + this.request = new Request.HTML({ + url: '../Helpers/request.php', + onComplete: this.spy + }).send({data: { + '__response': '
', '__type': 'html' + }}); + }); + + waitsFor(800, function(){ + return this.spy.wasCalled; + }); + + runs(function(){ + var response = this.request.response; + // checks arguments order + expect(this.spy).toHaveBeenCalledWith(response.tree, response.elements, response.html, response.javascript); + var onCompleteArgs = this.spy.argsForCall[0]; + expect(onCompleteArgs[0][0].nodeName).toEqual('DIV'); + expect(onCompleteArgs[1][1].nodeName).toEqual('SPAN'); + expect(onCompleteArgs[2]).toEqual('
'); + expect(onCompleteArgs[3]).toBeFalsy(); + }); + + }); + + xit('should create an ajax request and correctly generate the tree response from a tr', function(){ + + runs(function(){ + this.request = new Request.HTML({ + url: '../Helpers/request.php', + onComplete: this.spy + }).send({data: { + '__response': 'text', '__type': 'html' + }}); + }); + + waitsFor(800, function(){ + return this.spy.wasCalled; + }); + + runs(function(){ + var onCompleteArgs = this.spy.argsForCall[0]; + + expect(onCompleteArgs[0][0].nodeName).toEqual('TR'); + expect(onCompleteArgs[1][1].nodeName).toEqual('TD'); + expect(onCompleteArgs[2]).toEqual('text'); + }); + + }); + + xit('should create an ajax request and correctly generate the tree response from options', function(){ + + runs(function(){ + this.request = new Request.HTML({ + url: '../Helpers/request.php', + onComplete: this.spy + }).send({data: { + '__response': '', '__type': 'html' + }}); + }); + + waitsFor(800, function(){ + return this.spy.wasCalled; + }); + + runs(function(){ + var onCompleteArgs = this.spy.argsForCall[0]; + + expect(onCompleteArgs[0].length).toEqual(3); + expect(onCompleteArgs[1].length).toEqual(3); + expect(onCompleteArgs[2]).toEqual(''); + expect(onCompleteArgs[3]).toBeFalsy(); + + var firstOption = onCompleteArgs[0][0]; + expect(firstOption.tagName).toEqual('OPTION'); + expect(firstOption.innerHTML).toEqual('1'); + }); + + }); + + +}); diff --git a/1.3client/Request/Request.js b/1.3client/Request/Request.js index 320658b..be10826 100644 --- a/1.3client/Request/Request.js +++ b/1.3client/Request/Request.js @@ -135,8 +135,8 @@ describe('Request', function(){ var onCompleteArgs = this.onComplete.argsForCall[0]; var rootNode = onCompleteArgs[1].documentElement; expect(onCompleteArgs[0]).toEqual('response'); - expect(rootNode.nodeName.toLowerCase()).toEqual('root'); - expect(rootNode.firstChild.nodeValue.toLowerCase()).toEqual('response'); + expect(rootNode.nodeName).toEqual('root'); + expect(rootNode.firstChild.nodeValue).toEqual('response'); }); }); diff --git a/Configuration.js b/Configuration.js index 69c3a27..5a6b8ca 100644 --- a/Configuration.js +++ b/Configuration.js @@ -58,7 +58,8 @@ Configuration.sets = { 'Element/Element', 'Element/NewElement', 'Element/Element.Event', - 'Request/Request' + 'Request/Request', + 'Request/Request.HTML' ] } };