|
| 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