6
6
/*eslint max-nested-callbacks: 0*/
7
7
/*jscs:disable requireCamelCaseOrUpperCaseIdentifiers*/
8
8
define ( [
9
+ 'jquery' ,
9
10
'mageUtils' ,
11
+ 'underscore' ,
10
12
'Magento_Ui/js/grid/data-storage'
11
- ] , function ( utils , DataStorage ) {
13
+ ] , function ( $ , utils , _ , DataStorage ) {
12
14
'use strict' ;
13
15
14
16
describe ( 'Magento_Ui/js/grid/data-storage' , function ( ) {
@@ -322,7 +324,12 @@ define([
322
324
323
325
describe ( '"updateData" method' , function ( ) {
324
326
var model = new DataStorage ( {
325
- dataScope : 'magento'
327
+ dataScope : 'magento' ,
328
+ requestConfig : {
329
+ url : 'magento.com' ,
330
+ method : 'GET' ,
331
+ dataType : 'json'
332
+ }
326
333
} ) ;
327
334
328
335
it ( 'Check for defined ' , function ( ) {
@@ -345,6 +352,83 @@ define([
345
352
} ) ;
346
353
} ) ;
347
354
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
+
348
432
describe ( '"getRequestData" method' , function ( ) {
349
433
var model = new DataStorage ( {
350
434
dataScope : 'magento'
@@ -367,6 +451,45 @@ define([
367
451
368
452
expect ( model . getRequestData ( request ) ) . toBeTruthy ( ) ;
369
453
} ) ;
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
+ } ) ;
370
493
} ) ;
371
494
372
495
describe ( '"cacheRequest" method' , function ( ) {
@@ -531,7 +654,9 @@ define([
531
654
paging : { }
532
655
} ;
533
656
534
- model . wasRequested ( params ) ;
657
+ spyOn ( model , 'getRequest' ) . and . callFake ( function ( ) {
658
+ return false ;
659
+ } ) ;
535
660
expect ( model . wasRequested ( params ) ) . toBeFalsy ( ) ;
536
661
} ) ;
537
662
} ) ;
@@ -558,7 +683,7 @@ define([
558
683
entity_id : '1'
559
684
} ]
560
685
} ,
561
- params = {
686
+ params = {
562
687
namespace : 'magento' ,
563
688
search : '' ,
564
689
sorting : { } ,
0 commit comments