Skip to content

Commit 71f2f48

Browse files
committed
Testcase: search Sort
1 parent a2eb665 commit 71f2f48

File tree

1 file changed

+53
-0
lines changed

1 file changed

+53
-0
lines changed

test/search/sort.spec.js

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
describe('Sort', function () {
2+
var expect = window.expect;
3+
before(function(){
4+
fixture.setBase('mock');
5+
var searchTest = fixture.load('searchTestResponse.json');
6+
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',searchTest);
15+
this.spyAddSort = sinon.spy(window.searchobj,'addSort');
16+
});
17+
18+
after(function(){
19+
this.stub.restore();
20+
});
21+
22+
beforeEach(function(){
23+
//reset filters applied
24+
window.searchobj.clearFilters(true);
25+
window.searchobj.callResults(window.searchobj.paintResultSet);
26+
});
27+
28+
it('Should call Addsort with field and value on which sort applied',
29+
function(){
30+
var field = window.searchobj.options.sortOptions[2].field;
31+
var value = window.searchobj.options.sortOptions[2].order;
32+
jQuery(window.searchobj.options.sortContainerSelector + ' select')
33+
.prop('selectedIndex',2).change();
34+
expect(this.spyAddSort.calledWith(field,value)).to.equal(true);
35+
}
36+
);
37+
38+
it('Addsort - Should add sort fields to params', function(){
39+
window.searchobj.addSort('price','asc');
40+
expect(window.searchobj.params.sort.price).to.be.equal('asc');
41+
});
42+
43+
it('Removesort - Should remove sort fields from params ', function(){
44+
window.searchobj.removeSort('price');
45+
expect(window.searchobj.params.sort.price).to.not.exist;
46+
});
47+
48+
it('resetSort - Should clear sort params ', function(){
49+
window.searchobj.addSort('price','asc');
50+
window.searchobj.resetSort();
51+
expect(window.searchobj.params.sort).to.be.empty;
52+
});
53+
});

0 commit comments

Comments
 (0)