|
| 1 | +describe('clickNScroll', function () { |
| 2 | + var expect = window.expect; |
| 3 | + fixture.setBase('mock'); |
| 4 | + var searchTest = fixture.load('searchTestResponse.json'); |
| 5 | + |
| 6 | + before(function(){ |
| 7 | + |
| 8 | + //setup document to hold search results |
| 9 | + document.body.innerHTML = __html__['index.html']; |
| 10 | + |
| 11 | + //change configuration to pagination from autoscroll |
| 12 | + window.config.isAutoScroll = false; |
| 13 | + window.config.isPagination = false; |
| 14 | + window.config.isClickNScroll = true; |
| 15 | + |
| 16 | + //initialize search |
| 17 | + window.searchobj = new window.Unbxd.setSearch(window.config); |
| 18 | + |
| 19 | + //stub search ajax call with mock response |
| 20 | + this.stub = sinon.stub(jQuery, 'ajax').yieldsTo('success',searchTest); |
| 21 | + |
| 22 | + }); |
| 23 | + |
| 24 | + after(function(){ |
| 25 | + this.stub.restore(); |
| 26 | + }); |
| 27 | + |
| 28 | + beforeEach(function(){ |
| 29 | + //reset params applied |
| 30 | + window.searchobj.reset(); |
| 31 | + window.searchobj.callResults(window.searchobj.paintResultSet); |
| 32 | + }); |
| 33 | + |
| 34 | + it('Should load Next page on clicking on clickNScrollElement',function(){ |
| 35 | + var beforeAtPage = window.searchobj.getPage(); |
| 36 | + var AfterAtPage; |
| 37 | + jQuery(window.searchobj.options.clickNScrollElementSelector).click(); |
| 38 | + AfterAtPage = window.searchobj.getPage(); |
| 39 | + expect(beforeAtPage + 1).to.be.equal(AfterAtPage); |
| 40 | + }); |
| 41 | + |
| 42 | + it('Should hide clickNScrollElement on last page', function(){ |
| 43 | + searchTest.response.start = searchTest.response.numberOfProducts - |
| 44 | + searchTest.searchMetaData.queryParams.rows; |
| 45 | + window.searchobj.setPage(window.searchobj.totalPages); |
| 46 | + window.searchobj.callResults(window.searchobj.paintResultSet); |
| 47 | + |
| 48 | + expect(jQuery(window.searchobj.options.clickNScrollElementSelector) |
| 49 | + .is(':visible')).to.be.false; |
| 50 | + }); |
| 51 | +}); |
0 commit comments