Skip to content

Commit a2eb665

Browse files
committed
Testcase: search Redirect
1 parent 73bfdd4 commit a2eb665

File tree

2 files changed

+45
-0
lines changed

2 files changed

+45
-0
lines changed

mock/redirect.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
{"searchMetaData":{"queryParams":{"q":"women watch"},"status":0},"redirect":{"type":"url","value":"http://www.google.co.in"}}

test/search/redirect.spec.js

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
describe('Redirect', function () {
2+
var expect = window.expect;
3+
4+
before(function(){
5+
fixture.setBase('mock');
6+
var RedirectTest = fixture.load('redirect.json');
7+
//setup document to hold search results
8+
document.body.innerHTML = __html__['index.html'];
9+
10+
//initialize search
11+
window.searchobj = new window.Unbxd.setSearch(window.config);
12+
13+
//stub search ajax call with mock response
14+
this.stub = sinon.stub(jQuery, 'ajax').yieldsTo('success',RedirectTest);
15+
16+
this.spyOnIntialResultLoad = sinon.spy(window.searchobj.options,
17+
'onIntialResultLoad');
18+
19+
//stubbing _internalPaintResultSet here to avoid page reload
20+
this.stubInternalPaintResultSet = sinon.stub(window.searchobj,
21+
'_internalPaintResultSet');
22+
this.stubInternalPaintResultSet.withArgs(RedirectTest,true).returns(false);
23+
24+
window.searchobj.callResults(window.searchobj.paintResultSet);
25+
});
26+
27+
after(function(){
28+
this.stub.restore();
29+
this.stubInternalPaintResultSet.restore();
30+
});
31+
32+
it('Should not call onIntialResultLoad',function(){
33+
expect(this.spyOnIntialResultLoad.called).to.equal(false);
34+
});
35+
36+
it('Should have redirect in response', function(){
37+
expect(this.stubInternalPaintResultSet.args[0][0]
38+
.hasOwnProperty('redirect')).to.equal(true);
39+
});
40+
41+
it('paintResultSet - Should return false',function(){
42+
expect(this.stubInternalPaintResultSet.returned(false)).to.equal(true);
43+
});
44+
});

0 commit comments

Comments
 (0)