Skip to content

Commit

Permalink
Adding Request.HMTL specs
Browse files Browse the repository at this point in the history
  • Loading branch information
fabiomcosta committed Sep 6, 2010
1 parent 1896640 commit 669e4aa
Show file tree
Hide file tree
Showing 3 changed files with 103 additions and 3 deletions.
99 changes: 99 additions & 0 deletions 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': '<body><div><span></span></div></body>', '__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('<div><span></span></div>');
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': '<tr><td>text</td></tr>', '__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('<tr><td>text</td></tr>');
});

});

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': '<option>1</option><option>2</option><option>3</option>', '__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('<option>1</option><option>2</option><option>3</option>');
expect(onCompleteArgs[3]).toBeFalsy();

var firstOption = onCompleteArgs[0][0];
expect(firstOption.tagName).toEqual('OPTION');
expect(firstOption.innerHTML).toEqual('1');
});

});


});
4 changes: 2 additions & 2 deletions 1.3client/Request/Request.js
Expand Up @@ -135,8 +135,8 @@ describe('Request', function(){
var onCompleteArgs = this.onComplete.argsForCall[0];
var rootNode = onCompleteArgs[1].documentElement;
expect(onCompleteArgs[0]).toEqual('<root>response</root>');
expect(rootNode.nodeName.toLowerCase()).toEqual('root');
expect(rootNode.firstChild.nodeValue.toLowerCase()).toEqual('response');
expect(rootNode.nodeName).toEqual('root');
expect(rootNode.firstChild.nodeValue).toEqual('response');
});

});
Expand Down
3 changes: 2 additions & 1 deletion Configuration.js
Expand Up @@ -58,7 +58,8 @@ Configuration.sets = {
'Element/Element',
'Element/NewElement',
'Element/Element.Event',
'Request/Request'
'Request/Request',
'Request/Request.HTML'
]
}
};
Expand Down

0 comments on commit 669e4aa

Please sign in to comment.