66/*eslint max-nested-callbacks: 0*/
77/*jscs:disable requireCamelCaseOrUpperCaseIdentifiers*/
88define ( [
9+ 'jquery' ,
910 'mageUtils' ,
11+ 'underscore' ,
1012 'Magento_Ui/js/grid/data-storage'
11- ] , function ( utils , DataStorage ) {
13+ ] , function ( $ , utils , _ , DataStorage ) {
1214 'use strict' ;
1315
1416 describe ( 'Magento_Ui/js/grid/data-storage' , function ( ) {
@@ -322,7 +324,12 @@ define([
322324
323325 describe ( '"updateData" method' , function ( ) {
324326 var model = new DataStorage ( {
325- dataScope : 'magento'
327+ dataScope : 'magento' ,
328+ requestConfig : {
329+ url : 'magento.com' ,
330+ method : 'GET' ,
331+ dataType : 'json'
332+ }
326333 } ) ;
327334
328335 it ( 'Check for defined ' , function ( ) {
@@ -345,6 +352,83 @@ define([
345352 } ) ;
346353 } ) ;
347354
355+ describe ( '"requestData" method' , function ( ) {
356+ var model = new DataStorage ( {
357+ dataScope : 'magento'
358+ } ) ;
359+
360+ it ( 'Check for defined' , function ( ) {
361+ expect ( model . hasOwnProperty ( 'requestData' ) ) . toBeDefined ( ) ;
362+ } ) ;
363+
364+ it ( 'Check method type' , function ( ) {
365+ var type = typeof model . requestData ;
366+
367+ expect ( type ) . toEqual ( 'function' ) ;
368+ } ) ;
369+
370+ it ( 'Check Ajax request' , function ( ) {
371+ var params = {
372+ namespace : 'magento' ,
373+ search : '' ,
374+ filters : {
375+ store_id : 0
376+ } ,
377+ sorting : { } ,
378+ paging : { }
379+ } ,
380+ query = utils . copy ( params ) ;
381+
382+ spyOn ( model , 'onRequestComplete' ) ;
383+ spyOn ( $ , 'ajax' ) . and . callFake ( function ( ) {
384+ return {
385+ /**
386+ * Success result for ajax request
387+ */
388+ done : function ( ) {
389+ model . onRequestComplete ( model , query ) ;
390+ }
391+ } ;
392+ } ) ;
393+ model . requestData ( params ) ;
394+ expect ( $ . ajax ) . toHaveBeenCalled ( ) ;
395+ expect ( model . onRequestComplete ) . toHaveBeenCalled ( ) ;
396+ } ) ;
397+ } ) ;
398+
399+ describe ( '"getRequest" method' , function ( ) {
400+ var model = new DataStorage ( {
401+ dataScope : 'magento'
402+ } ) ;
403+
404+ it ( 'Check for defined' , function ( ) {
405+ expect ( model . hasOwnProperty ( 'getRequest' ) ) . toBeDefined ( ) ;
406+ } ) ;
407+
408+ it ( 'Check method' , function ( ) {
409+ var type = typeof model . getRequest ;
410+
411+ expect ( type ) . toEqual ( 'function' ) ;
412+ } ) ;
413+
414+ it ( 'check "getRequest" has been executed' , function ( ) {
415+ var params = {
416+ namespace : 'magento' ,
417+ search : '' ,
418+ sorting : { } ,
419+ paging : { }
420+ } ;
421+
422+ model . _requests . push ( {
423+ ids : [ '1' ] ,
424+ params : params ,
425+ totalRecords : 1 ,
426+ errorMessage : ''
427+ } ) ;
428+ expect ( model . getRequest ( params ) ) . toBeTruthy ( ) ;
429+ } ) ;
430+ } ) ;
431+
348432 describe ( '"getRequestData" method' , function ( ) {
349433 var model = new DataStorage ( {
350434 dataScope : 'magento'
@@ -367,6 +451,45 @@ define([
367451
368452 expect ( model . getRequestData ( request ) ) . toBeTruthy ( ) ;
369453 } ) ;
454+
455+ it ( 'check "getByIds" has been executed' , function ( ) {
456+ var request = {
457+ ids : [ 1 , 2 , 3 ]
458+ } ;
459+
460+ spyOn ( model , 'getByIds' ) ;
461+ model . getRequestData ( request ) ;
462+ expect ( model . getByIds ) . toHaveBeenCalled ( ) ;
463+ } ) ;
464+
465+ it ( 'check "delay" function has been executed' , function ( ) {
466+ var request = {
467+ ids : [ 1 , 2 , 3 ] ,
468+ totalRecords : 3 ,
469+ errorMessage : ''
470+ } ;
471+
472+ spyOn ( _ , 'delay' ) ;
473+ model . getRequestData ( request ) ;
474+ expect ( _ . delay ) . toHaveBeenCalled ( ) ;
475+ } ) ;
476+
477+ it ( 'check "delay" function has not been executed' , function ( ) {
478+ var request = {
479+ ids : [ 1 , 2 , 3 ] ,
480+ totalRecords : 3 ,
481+ errorMessage : ''
482+ } ;
483+
484+ model = new DataStorage ( {
485+ dataScope : 'magento' ,
486+ cachedRequestDelay : 0
487+ } ) ;
488+
489+ spyOn ( _ , 'delay' ) ;
490+ model . getRequestData ( request ) ;
491+ expect ( _ . delay ) . not . toHaveBeenCalled ( ) ;
492+ } ) ;
370493 } ) ;
371494
372495 describe ( '"cacheRequest" method' , function ( ) {
@@ -531,7 +654,9 @@ define([
531654 paging : { }
532655 } ;
533656
534- model . wasRequested ( params ) ;
657+ spyOn ( model , 'getRequest' ) . and . callFake ( function ( ) {
658+ return false ;
659+ } ) ;
535660 expect ( model . wasRequested ( params ) ) . toBeFalsy ( ) ;
536661 } ) ;
537662 } ) ;
@@ -558,7 +683,7 @@ define([
558683 entity_id : '1'
559684 } ]
560685 } ,
561- params = {
686+ params = {
562687 namespace : 'magento' ,
563688 search : '' ,
564689 sorting : { } ,
0 commit comments