1
+ describe ( 'Facets Position' , 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
+ var searchConfig = jQuery . extend ( { } , window . config ) ;
10
+ searchConfig . facetTemp = function ( ) { } ;
11
+ //initialize search
12
+ this . searchobj = new window . Unbxd . setSearch ( searchConfig ) ;
13
+
14
+ //stub search ajax call with mock response
15
+ this . stub = sinon . stub ( jQuery , 'ajax' ) . yieldsTo ( 'success' , this . searchTest ) ;
16
+ this . spyOnFacetTemp = sinon . spy ( this . searchobj . options , 'facetTemp' ) ;
17
+ done ( ) ;
18
+ } ) ;
19
+
20
+ after ( function ( ) {
21
+ this . stub . restore ( ) ;
22
+ fixture . cleanup ( ) ;
23
+ } ) ;
24
+
25
+ beforeEach ( function ( ) {
26
+ //reset filters applied
27
+ this . searchobj . clearFilters ( true ) ;
28
+ this . searchobj . callResults ( this . searchobj . paintResultSet ) ;
29
+ } ) ;
30
+
31
+ it ( 'Facets should be sorted based on position' , function ( ) {
32
+ var facetElement = jQuery ( this . searchobj . options
33
+ . facetContainerSelector + ' label' ) . first ( ) ,
34
+ sortedFacets ,
35
+ isSorted = true ;
36
+ //apply facet
37
+ facetElement . click ( ) ;
38
+ sortedFacets = this . spyOnFacetTemp . args [ 0 ] [ 0 ] . sortedFacets ;
39
+ sortedFacets . forEach ( function ( facet , index ) {
40
+ if ( index < sortedFacets . length &&
41
+ facet . position && sortedFacets [ index + 1 ] . position &&
42
+ facet . position > sortedFacets [ index + 1 ] . position ) {
43
+ isSorted = false ;
44
+ }
45
+ } ) ;
46
+ expect ( isSorted ) . to . be . true ;
47
+ } ) ;
48
+ } ) ;
0 commit comments