Skip to content

Commit b1e1afb

Browse files
committed
(test): include support for navigation
1 parent 56db860 commit b1e1afb

File tree

2 files changed

+57
-0
lines changed

2 files changed

+57
-0
lines changed

karma.conf.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ module.exports = function (config) {
3434
'./unbxdSearch.js',
3535
'./app.js',
3636
'mock/*.json',
37+
'test/navigation/*.spec.js',
3738
'test/search/*.spec.js',
3839
],
3940

test/navigation/init.spec.js

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
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

Comments
 (0)