@@ -323,7 +323,7 @@ describe('context of callback options should be userProxy object : ', () => {
323323 } ;
324324 const obj = new apiConstructor ( getDeps , { options} ) ;
325325 expect ( options . onChange . mock . calls . length === 0 ) . toBe ( true ) ;
326- obj . trigger ( 'onChange' , obj . userProxy , { currentData : { } , perviousData : { } } ) ;
326+ obj . trigger ( 'onChange' , obj . userProxy , { currentData : { } , perviousData : { } , closedTabIDs : [ ] , openTabIDs : [ ] } ) ;
327327 expect ( options . onChange . mock . calls . length === 1 ) . toBe ( true ) ;
328328 } ) ;
329329} ) ;
@@ -464,3 +464,87 @@ describe('Api.prototype.setTab : ', () => {
464464 ) ;
465465 } ) ;
466466} ) ;
467+ describe ( 'Api.prototype._subscribeSelectedTabsHistory : ' , ( ) => {
468+ test ( 'it should call "on" method' , ( ) => {
469+ obj . on = jest . fn ( ( ) => { } ) ;
470+ obj . _subscribeSelectedTabsHistory ( ) ;
471+ expect ( obj . on . mock . calls . length ) . toBe ( 1 ) ;
472+ expect ( obj . on . mock . calls [ 0 ] [ 0 ] ) . toBe ( 'onChange' ) ;
473+ } ) ;
474+ test ( 'subscribed function should call activedTabsHistory.remove per each closed tabID when onChange event is triggered' , ( ) => {
475+ obj . activedTabsHistory . remove = jest . fn ( ( ) => { } ) ;
476+ const currentData = { selectedTabID : '2' , openTabIDs : [ '2' ] } ;
477+ const perviousData = { selectedTabID : '2' , openTabIDs : [ '2' ] } ;
478+ const closedTabIDs = [ '1' , '3' ] ;
479+ obj . trigger ( 'onChange' , obj . userProxy , { currentData, perviousData, closedTabIDs, openTabIDs : [ ] } ) ;
480+ expect ( obj . activedTabsHistory . remove . mock . calls . length ) . toBe ( 2 ) ;
481+ expect ( obj . activedTabsHistory . remove . mock . calls [ 0 ] [ 0 ] ) . toBe ( '1' ) ;
482+ expect ( obj . activedTabsHistory . remove . mock . calls [ 1 ] [ 0 ] ) . toBe ( '3' ) ;
483+ } ) ;
484+ test ( `when onChange event is triggered, subscribed function should call activedTabsHistory.add with
485+ previously selectedTabID as a parameter if it is open, not selected and none disable.` , ( ) => {
486+ obj . activedTabsHistory . add = jest . fn ( ( ) => { } ) ;
487+ obj . isOpen = jest . fn ( ( id ) => {
488+ if ( id === '1' || id === '2' ) return true ;
489+ return false ;
490+ } ) ;
491+ obj . isSelected = jest . fn ( ( id ) => {
492+ if ( id === '2' ) return true ;
493+ return false ;
494+ } ) ;
495+ const currentData = { selectedTabID : '2' , openTabIDs : [ '1' , '2' ] } ;
496+ const perviousData = { selectedTabID : '1' , openTabIDs : [ '1' , '2' ] } ;
497+ obj . trigger ( 'onChange' , obj . userProxy , { currentData, perviousData, closedTabIDs : [ ] , openTabIDs : [ ] } ) ;
498+ expect ( obj . activedTabsHistory . add . mock . calls . length ) . toBe ( 1 ) ;
499+ expect ( obj . activedTabsHistory . add . mock . calls [ 0 ] [ 0 ] ) . toBe ( '1' ) ;
500+ } ) ;
501+ } ) ;
502+ describe ( 'Api.prototype._getPreSelectedTabId : ' , ( ) => {
503+ test ( `it calls activeTabsHistory.popLastTabID repeatedly until it returns a tabID
504+ which is opened, not selected and none disable` , ( ) => {
505+ const obj = new apiConstructor ( getDeps , {
506+ options : {
507+ tabs : [ { id : '1' } , { id : '2' } , { id : '3' } , { id : '4' } , { id : '5' } ] ,
508+ selectedTabID : 'tab1' ,
509+ } ,
510+ } ) ;
511+ obj . stateRef = { selectedTabID : '1' , openTabIDs : [ '1' , '2' , '3' , '4' ] } ;
512+ obj . activedTabsHistory . tabsId = [ '3' , '2' , '1' , '3' , '1' , '3' , '4' , '5' ] ;
513+ obj . setTab ( '3' , { disable : true } ) . setTab ( '4' , { disable : true } ) ;
514+ const tabID = obj . _getPreSelectedTabId ( ) ;
515+ expect ( tabID ) . toBe ( '2' ) ;
516+ expect ( obj . activedTabsHistory . tabsId ) . toEqual ( [ '3' ] ) ;
517+ } ) ;
518+ test ( 'it should return an empty string if activedTabsHistory.tabsId is empty or does not contain any valid tabID' , ( ) => {
519+ obj . stateRef = { selectedTabID : 'tab1' , openTabIDs : [ 'tab1' , 'tab2' ] } ;
520+ expect ( obj . _getPreSelectedTabId ( ) ) . toBe ( '' ) ;
521+ obj . activedTabsHistory . tabsId = [ 'tab1' ] ;
522+ expect ( obj . _getPreSelectedTabId ( ) ) . toBe ( '' ) ;
523+ obj . activedTabsHistory . tabsId = [ 'tab1' , ' ' , '' , null , 'tab2' ] ;
524+ obj . setTab ( 'tab2' , { disable : true } ) ;
525+ expect ( obj . _getPreSelectedTabId ( ) ) . toBe ( '' ) ;
526+ obj . activedTabsHistory . tabsId = [ 'tab1' , 'tab2' ] ;
527+ obj . setTab ( 'tab2' , { disable : false } ) ;
528+ expect ( obj . _getPreSelectedTabId ( ) ) . toBe ( 'tab2' ) ;
529+ } ) ;
530+ } ) ;
531+ describe ( 'Api.prototype._getPreSiblingTabId : ' , ( ) => {
532+ test ( 'it should call helper.filterArrayUntilFirstValue with appropriate parameters' , ( ) => {
533+ obj . helper . filterArrayUntilFirstValue = jest . fn ( ( ) => { } ) ;
534+ obj . stateRef = { selectedTabID : '2' , openTabIDs : [ '1' , '2' , '3' ] } ;
535+ obj . _getPreSiblingTabId ( ) ;
536+ expect ( obj . helper . filterArrayUntilFirstValue . mock . calls . length ) . toBe ( 1 ) ;
537+ expect ( obj . helper . filterArrayUntilFirstValue . mock . calls [ 0 ] [ 0 ] ) . toEqual ( [ '1' ] ) ;
538+ expect ( obj . helper . filterArrayUntilFirstValue . mock . calls [ 0 ] [ 2 ] ) . toBe ( true ) ;
539+ } ) ;
540+ } ) ;
541+ describe ( 'Api.prototype._getNextSiblingTabId : ' , ( ) => {
542+ test ( 'it should call helper.filterArrayUntilFirstValue with appropriate parameters' , ( ) => {
543+ obj . helper . filterArrayUntilFirstValue = jest . fn ( ( ) => { } ) ;
544+ obj . stateRef = { selectedTabID : '2' , openTabIDs : [ '1' , '2' , '3' ] } ;
545+ obj . _getNextSiblingTabId ( ) ;
546+ expect ( obj . helper . filterArrayUntilFirstValue . mock . calls . length ) . toBe ( 1 ) ;
547+ expect ( obj . helper . filterArrayUntilFirstValue . mock . calls [ 0 ] [ 0 ] ) . toEqual ( [ '3' ] ) ;
548+ expect ( ! obj . helper . filterArrayUntilFirstValue . mock . calls [ 0 ] [ 2 ] ) . toBe ( true ) ;
549+ } ) ;
550+ } ) ;
0 commit comments