@@ -14,43 +14,41 @@ beforeAll(() => {
1414beforeEach ( ( ) => {
1515 getDeps = function ( options = { } ) {
1616 const activedTabsHistory = new ( ActivedTabsHistory ) ( ) , optionsManager = new ( OptionManager ) ( { options } ) ;
17- BaseApi . call ( this , helper ) ;
18- Tabs . call ( this ) ;
17+ BaseApi . call ( this , {
18+ helper,
19+ initialState : optionsManager . initialState
20+ } ) ;
21+ Tabs . call ( this , { initialTabs : optionsManager . initialTabs , } ) ;
1922 Pub_Sub . call ( this ) ;
2023 return { activedTabsHistory, helper, optionsManager } ;
2124 } ;
22- obj = new ( apiConstructor ) ( getDeps , { options : { } } ) ;
25+ obj = new ( apiConstructor ) ( getDeps , {
26+ options : {
27+ tabs : [ {
28+ id : 'tab1' ,
29+ title : 'tabTitle1'
30+ } , {
31+ id : 'tab2' ,
32+ title : 'tabTitle2'
33+ } ] ,
34+ selectedTabID : 'tab1'
35+ }
36+ } ) ;
2337} ) ;
2438afterEach ( ( ) => {
2539 getDeps = null ;
2640 obj = null ;
2741} ) ;
28- describe ( 'Api.prototype.getInitialState : ' , ( ) => {
29- test ( 'it should call _addTab internally per each tabData option' , ( ) => {
30- const obj = new ( apiConstructor ) ( getDeps , {
31- options : {
32- tabs : [
33- { id : '1' , title : 'tab1' } ,
34- { id : '2' , title : 'tab2' } ,
35- { id : '3' , title : 'tab3' }
36- ]
37- }
38- } ) ;
39- obj . _addTab = jest . fn ( ( ) => ( { id : '2' } ) ) ;
40- obj . getInitialState ( ) ;
41- expect ( obj . _addTab . mock . calls . length === 3 ) . toBe ( true ) ;
42- } ) ;
43- } ) ;
4442describe ( 'Api.prototype.open : ' , ( ) => {
45- test ( 'it should call _addTab internally' , ( ) => {
43+ test ( 'it should call optionsManager.validateTabData internally' , ( ) => {
4644 Object . assign ( obj , {
47- _addTab : jest . fn ( ( ) => ( { id : '2' } ) ) ,
4845 _getFlushEffectsPromise : jest . fn ( ( ) => Promise ) ,
4946 _open : jest . fn ( ( ) => { } )
5047 } ) ;
48+ obj . optionsManager . validateTabData = jest . fn ( data => data ) ;
5149 obj . open ( { id : '2' } ) ;
52- expect ( obj . _addTab . mock . calls . length === 1 ) . toBe ( true ) ;
53- expect ( obj . _addTab ) . toHaveBeenCalledBefore ( obj . _getFlushEffectsPromise ) ;
50+ expect ( obj . optionsManager . validateTabData . mock . calls . length === 1 ) . toBe ( true ) ;
51+ expect ( obj . optionsManager . validateTabData ) . toHaveBeenCalledBefore ( obj . _getFlushEffectsPromise ) ;
5452 expect ( obj . _getFlushEffectsPromise ) . toHaveBeenCalledBefore ( obj . _open ) ;
5553 } ) ;
5654 test ( 'it throws an error if is called with falsy value of id parameter' , ( ) => {
@@ -394,4 +392,48 @@ describe('Api.prototype.eventHandlerFactory : ', () => {
394392 expect ( beforeClose . mock . calls [ 0 ] [ 1 ] ) . toBe ( id ) ;
395393 }
396394 } ) ;
395+ } ) ;
396+ describe ( 'Api.prototype.getCopyPerviouseData' , ( ) => {
397+ test ( 'In the onLoad event, return data is equal to getInitialState() and getCopyData()' , ( ) => {
398+ expect . assertions ( 3 ) ;
399+ const _state = { selectedTabID : 'tab1' , openTabIDs : [ 'tab1' , 'tab2' ] } ;
400+ obj . setOption ( 'onLoad' , function ( ) {
401+ const perviousData = this . getCopyPerviousData ( ) ;
402+ const data = this . getCopyData ( ) ;
403+ expect ( perviousData ) . toEqual ( _state ) ;
404+ expect ( perviousData ) . toEqual ( data ) ;
405+ expect ( perviousData !== null ) . toBe ( true ) ;
406+ } ) ;
407+ obj . updateStateRef ( _state , ( ) => { } ) ;
408+ obj . trigger ( 'onLoad' , obj . userProxy ) ;
409+ } ) ;
410+ } ) ;
411+ describe ( 'Api.prototype.getCopyPerviousData' , ( ) => {
412+ test ( 'returned data should be equal to optionsManager.initialState in onLoad event' , ( ) => {
413+ expect . assertions ( 2 ) ;
414+ obj . setOption ( 'onLoad' , function ( ) {
415+ const perviousData = this . getCopyPerviousData ( ) ;
416+ const data = this . getCopyData ( ) ;
417+ expect ( perviousData ) . toEqual ( obj . optionsManager . initialState ) ;
418+ expect ( perviousData ) . not . toEqual ( data ) ;
419+ } ) ;
420+ obj . updateState ( { selectedTabID : 'tab1' , openTabIDs : [ 'tab1' , 'tab2' ] } ) ;
421+ obj . trigger ( 'onLoad' , obj . userProxy ) ;
422+ } ) ;
423+ test ( 'returned data should be equal to currentData in onLoad event' , ( ) => {
424+ expect . assertions ( 1 ) ;
425+ obj . setOption ( 'onLoad' , function ( ) {
426+ expect ( this . getCopyPerviousData ( ) ) . toEqual ( this . getCopyData ( ) ) ;
427+ } ) ;
428+ obj . updateStateRef ( { selectedTabID : 'tab1' , openTabIDs : [ 'tab1' , 'tab2' ] } , ( ) => { } ) ;
429+ obj . trigger ( 'onLoad' , obj . userProxy ) ;
430+ } ) ;
431+ } ) ;
432+ describe ( 'Api.prototype.setTab : ' , ( ) => {
433+ test ( 'it should call optionsManager.validateObjectiveTabData and validatePanelComponent internally' , ( ) => {
434+ obj . optionsManager . validateObjectiveTabData = jest . fn ( ( ) => obj . optionsManager ) ;
435+ obj . optionsManager . validatePanelComponent = jest . fn ( ( ) => obj . optionsManager ) ;
436+ obj . setTab ( '1' , { title : 'c' } ) ;
437+ expect ( obj . optionsManager . validateObjectiveTabData ) . toHaveBeenCalledBefore ( obj . optionsManager . validatePanelComponent ) ;
438+ } ) ;
397439} ) ;
0 commit comments