@@ -624,6 +624,24 @@ define([
624
624
expect ( obj . options ) . toHaveBeenCalledWith ( [ ] ) ;
625
625
expect ( obj . processRequest ) . toHaveBeenCalledWith ( searchKey , 1 ) ;
626
626
} ) ;
627
+ it ( 'Should update cacheOptions if response was cached' , function ( ) {
628
+ var searchKey = 'cake' ,
629
+ searchResult = 'piece a cake' ;
630
+
631
+ obj . deviation = 30 ;
632
+ obj . cachedSearchResults = {
633
+ cake : {
634
+ options : [ searchResult ] ,
635
+ lastPage : 1 ,
636
+ total : 1
637
+ }
638
+ } ;
639
+
640
+ spyOn ( obj , 'options' ) ;
641
+ obj . loadOptions ( searchKey ) ;
642
+ expect ( obj . options ) . toHaveBeenCalledWith ( [ searchResult ] ) ;
643
+ expect ( obj . cacheOptions . plain ) . toContain ( searchResult ) ;
644
+ } ) ;
627
645
} ) ;
628
646
describe ( '"isSearchKeyCached" method' , function ( ) {
629
647
it ( 'Should return false if searchKey has already been cached and total covers > 1 page' , function ( ) {
@@ -672,7 +690,7 @@ define([
672
690
} ) ;
673
691
} ) ;
674
692
describe ( '"processRequest" method' , function ( ) {
675
- it ( 'Should store options successfully fetched from ajax request' , function ( ) {
693
+ it ( 'Should store options and update cache successfully after fetched from ajax request' , function ( ) {
676
694
var ajaxRequest ,
677
695
successfulAjaxResponse = {
678
696
options : {
@@ -686,14 +704,43 @@ define([
686
704
}
687
705
} ;
688
706
707
+ // place a number of options to cache prior fetch
708
+ obj . cacheOptions . plain = [ {
709
+ '2053' : {
710
+ value : '2057' ,
711
+ label : 'testProductName5a8ddfd933b5c' ,
712
+ 'is_active' : 1 ,
713
+ path : 'testSku5a8ddfd933b5c' ,
714
+ optgroup : false
715
+ } ,
716
+ '2054' : {
717
+ value : '2058' ,
718
+ label : 'testProductName5a8ddfd933b5c' ,
719
+ 'is_active' : 1 ,
720
+ path : 'testSku5a8ddfd933b5c' ,
721
+ optgroup : false
722
+ }
723
+ } ] ;
724
+
689
725
$ . ajax = jasmine . createSpy ( ) . and . callFake ( function ( request ) {
690
726
ajaxRequest = request . success . bind ( obj ) ;
691
727
} ) ;
692
728
693
729
expect ( obj . processRequest ( ) ) . toBeUndefined ( ) ;
694
730
695
731
ajaxRequest ( successfulAjaxResponse ) ;
696
- expect ( JSON . stringify ( obj . options ( ) ) ) . toEqual ( JSON . stringify ( [ successfulAjaxResponse . options [ '2053' ] ] ) ) ;
732
+
733
+ expect (
734
+ JSON . stringify ( obj . options ( ) )
735
+ ) . toEqual (
736
+ JSON . stringify ( [ successfulAjaxResponse . options [ '2053' ] ] )
737
+ ) ;
738
+
739
+ expect (
740
+ JSON . stringify ( obj . cacheOptions . plain )
741
+ ) . toEqual (
742
+ JSON . stringify ( [ successfulAjaxResponse . options [ '2053' ] ] )
743
+ ) ;
697
744
} ) ;
698
745
} ) ;
699
746
} ) ;
0 commit comments