import { expect } from 'chai' ; import { each } from '@lumino/algorithm' ; import { DockPanel , TabBar , Widget } from '@lumino/widgets' ; describe ( '@lumino/widgets' , ( ) => { describe ( 'DockPanel' , ( ) => { describe ( '#constructor()' , ( ) => { it ( 'should construct a new dock panel and take no arguments' , ( ) => { let panel = new DockPanel ( ) ; expect ( panel ) . to . be . an . instanceof ( DockPanel ) ; } ) ; it ( 'should accept options' , ( ) => { let renderer = Object . create ( TabBar . defaultRenderer ) ; let panel = new DockPanel ( { tabsMovable : true , renderer , tabsConstrained : true } ) ; each ( panel . tabBars ( ) , tabBar => { expect ( tabBar . tabsMovable ) . to . equal ( true ) ; } ) ; each ( panel . tabBars ( ) , tabBar => { expect ( tabBar . renderer ) . to . equal ( renderer ) ; } ) ; } ) ; it ( 'should not have tabs constrained by default' , ( ) => { let panel = new DockPanel ( ) ; expect ( panel . tabsConstrained ) . to . equal ( false ) ; } ) ; it ( 'should add a `lm-DockPanel` class' , ( ) => { let panel = new DockPanel ( ) ; expect ( panel . hasClass ( 'lm-DockPanel' ) ) . to . equal ( true ) ; } ) ; } ) ; describe ( '#dispose()' , ( ) => { it ( 'should dispose of the resources held by the widget' , ( ) => { let panel = new DockPanel ( ) ; panel . addWidget ( new Widget ( ) ) ; panel . dispose ( ) ; expect ( panel . isDisposed ) . to . equal ( true ) ; panel . dispose ( ) ; expect ( panel . isDisposed ) . to . equal ( true ) ; } ) ; } ) ; describe ( 'hiddenMode' , ( ) => { let panel ; let widgets = [ ] ; beforeEach ( ( ) => { panel = new DockPanel ( ) ; widgets . push ( new Widget ( ) ) ; panel . addWidget ( widgets [ 0 ] ) ; widgets . push ( new Widget ( ) ) ; panel . addWidget ( widgets [ 1 ] , { mode : 'tab-after' } ) ; } ) ; afterEach ( ( ) => { panel . dispose ( ) ; } ) ; it ( "should be 'display' mode by default" , ( ) => { expect ( panel . hiddenMode ) . to . equal ( Widget . HiddenMode . Display ) ; } ) ; it ( "should switch to 'scale'" , ( ) => { widgets [ 0 ] . hiddenMode = Widget . HiddenMode . Scale ; panel . hiddenMode = Widget . HiddenMode . Scale ; expect ( widgets [ 0 ] . hiddenMode ) . to . equal ( Widget . HiddenMode . Scale ) ; expect ( widgets [ 1 ] . hiddenMode ) . to . equal ( Widget . HiddenMode . Scale ) ; } ) ; it ( "should switch to 'display'" , ( ) => { widgets [ 0 ] . hiddenMode = Widget . HiddenMode . Scale ; panel . hiddenMode = Widget . HiddenMode . Scale ; panel . hiddenMode = Widget . HiddenMode . Display ; expect ( widgets [ 0 ] . hiddenMode ) . to . equal ( Widget . HiddenMode . Display ) ; expect ( widgets [ 1 ] . hiddenMode ) . to . equal ( Widget . HiddenMode . Display ) ; } ) ; it ( "should not set 'scale' if only one widget" , ( ) => { panel . layout ! . removeWidget ( widgets [ 1 ] ) ; panel . hiddenMode = Widget . HiddenMode . Scale ; expect ( widgets [ 0 ] . hiddenMode ) . to . equal ( Widget . HiddenMode . Display ) ; } ) ; } ) ; describe ( '#tabsMovable' , ( ) => { it ( 'should get whether tabs are movable' , ( ) => { let panel = new DockPanel ( ) ; expect ( panel . tabsMovable ) . to . equal ( true ) ; } ) ; it ( 'should set tabsMovable of all tabs' , ( ) => { let panel = new DockPanel ( ) ; let w1 = new Widget ( ) ; let w2 = new Widget ( ) ; panel . addWidget ( w1 ) ; panel . addWidget ( w2 , { mode : 'split-right' , ref : w1 } ) ; each ( panel . tabBars ( ) , tabBar => { expect ( tabBar . tabsMovable ) . to . equal ( true ) ; } ) ; panel . tabsMovable = false ; each ( panel . tabBars ( ) , tabBar => { expect ( tabBar . tabsMovable ) . to . equal ( false ) ; } ) ; } ) ; } ) ; } ) ; } ) ;