|
| 1 | +describe('Navigation - On Init', function () { |
| 2 | + |
| 3 | + before(function(done){ |
| 4 | + this.searchTest = fixture.load('mock/searchTestResponse.json'); |
| 5 | + |
| 6 | + //setup document to hold search results |
| 7 | + document.body.innerHTML = __html__['index.html']; |
| 8 | + |
| 9 | + //initialize search |
| 10 | + var searchConfig = jQuery.extend({}, window.config); |
| 11 | + searchConfig.type = 'category'; |
| 12 | + searchConfig.getCategoryId = function(){ |
| 13 | + return '/clothing/women/jewelry-hair/cat/cat1910053'; |
| 14 | + }; |
| 15 | + this.searchobj = new window.Unbxd.setSearch(searchConfig); |
| 16 | + |
| 17 | + //stub search ajax call with mock response |
| 18 | + this.stub = sinon.stub(jQuery, 'ajax').yieldsTo('success',this.searchTest); |
| 19 | + |
| 20 | + //spy OnIntialResultLoad, OnFacetLoad, OnPageLoad and OnNoResult |
| 21 | + this.spyOnIntialResultLoad = sinon.spy(this.searchobj.options, |
| 22 | + 'onIntialResultLoad'); |
| 23 | + this.spyOnFacetLoad = sinon.spy(this.searchobj.options, 'onFacetLoad'); |
| 24 | + this.spyOnPageLoad = sinon.spy(this.searchobj.options, 'onPageLoad'); |
| 25 | + this.spyOnNoResult = sinon.spy(this.searchobj.options, 'onNoResult'); |
| 26 | + |
| 27 | + this.searchobj.callResults(this.searchobj.paintResultSet); |
| 28 | + done(); |
| 29 | + }); |
| 30 | + |
| 31 | + after(function(){ |
| 32 | + this.stub.restore(); |
| 33 | + fixture.cleanup(); |
| 34 | + }); |
| 35 | + |
| 36 | + it('should call navigation handler', function(){ |
| 37 | + expect(this.searchobj.getHostNPath().indexOf('/category') > -1) |
| 38 | + .to.be.true; |
| 39 | + }); |
| 40 | + |
| 41 | + it('Should call onIntialResultLoad', function(){ |
| 42 | + expect(this.spyOnIntialResultLoad.called).to.equal(true); |
| 43 | + }); |
| 44 | + |
| 45 | + it('Should call onFacetLoad', function(){ |
| 46 | + expect(this.spyOnFacetLoad.called).to.equal(true); |
| 47 | + }); |
| 48 | + |
| 49 | + it('Should not call onPageLoad', function(){ |
| 50 | + expect(this.spyOnPageLoad.called).to.equal(false); |
| 51 | + }); |
| 52 | + |
| 53 | + it('Should not call onNoResult', function(){ |
| 54 | + expect(this.spyOnNoResult.called).to.equal(false); |
| 55 | + }); |
| 56 | +}); |
0 commit comments