import { TAB_ICONS } from '../support/constants' ; import { Classes } from '@blueprintjs/core' ; function matchPath ( path ) { const match = TAB_ICONS . find ( ( obj ) => obj . regex . test ( path ) ) ; return ( match && match . icon ) || 'folder-close' ; } describe ( 'tablist' , ( ) => { function createStubs ( ) { cy . window ( ) . then ( ( win ) => { const views = win . appState . winStates [ 0 ] . views ; let count = 0 ; for ( const view of views ) { for ( const cache of view . caches ) { cy . stub ( cache , 'cd' , ( path ) => { if ( path . startsWith ( '/' ) ) { return Promise . resolve ( path ) ; } else return Promise . reject ( { message : '' , code : 0 , } ) ; } ) . as ( `stub_cd${ count }` ) ; cy . spy ( cache , 'reload' ) . as ( `stub_reload${ count }` ) ; count ++ ; } } cy . stub ( win . remote . Menu , 'buildFromTemplate' ) . as ( 'stub_buildFromTemplate' ) . returns ( { popup : cy . stub ( ) . as ( 'stub_popup' ) , } ) ; } ) ; } before ( ( ) => { return cy . visit ( 'http://127.0.0.1:8080' ) ; } ) ; beforeEach ( ( ) => { createStubs ( ) ; } ) ; it ( 'tablist should have path in title' , ( ) => { cy . CDAndList ( 0 , '/' ) ; cy . get ( '#view_0 .tablist' ) . contains ( '/' ) . should ( 'have.class' , Classes . INTENT_PRIMARY ) ; } ) ; describe ( 'tablist should show tab icons for known user folders' , ( ) => { [ '/' , '/cy/downloads' , '/cy/music' , '/cy/pictures' , '/cy/desktop' , '/cy/documents' , '/cy/home' , '/cy/videos' , ] . forEach ( ( path ) => { it ( `should show icon for ${ path }` , ( ) => { const iconName = matchPath ( path ) ; cy . log ( 'iconName' , iconName ) ; cy . CDAndList ( 0 , path ) ; cy . get ( '.tablist' ) . contains ( path ) . find ( `.${ Classes . ICON }` ) . should ( 'have.attr' , 'icon' , iconName ) ; } ) ; } ) ; } ) ; it ( 'right-click on tab icon should show the folder menu' , ( ) => { cy . CDAndList ( 0 , '/' ) ; cy . get ( '#view_0 .tablist' ) . contains ( '/' ) . find ( '[icon]' ) . rightclick ( ) ; cy . get ( '@stub_buildFromTemplate' ) . should ( 'be.calledOnce' ) . and ( 'be.calledWith' , [ ] ) ; cy . get ( '@stub_popup' ) . should ( 'be.calledOnce' ) ; } ) ; it ( 'right-click on the tab should show the tab menu' , ( ) => { cy . CDAndList ( 0 , '/' ) ; cy . get ( '#view_0 .tablist' ) . contains ( '/' ) . find ( '.bp3-button-text' ) . rightclick ( 'right' ) ; cy . get ( '@stub_buildFromTemplate' ) . should ( 'be.calledOnce' ) . then ( ( stub ) => { expect ( stub . getCalls ( ) [ 0 ] . args [ 0 ] . length ) . to . equal ( 8 ) ; } ) ; } ) ; it ( 'close button should not be there with only one tab' , ( ) => { cy . get ( '#view_0 .tablist > button' ) . eq ( 0 ) . find ( '.closetab' ) . should ( 'not.exist' ) ; } ) ; it ( 'should be able to add a new tab and close a tab' , ( ) => { cy . addTab ( 0 ) ; cy . get ( '#view_0 .tablist > button.tab' ) . its ( 'length' ) . should ( 'equal' , 2 ) ; cy . get ( '#view_0 .tablist > button.tab' ) . eq ( 1 ) . find ( '.closetab' ) . click ( { force : true } ) ; cy . get ( '#view_0 .tablist > button.tab' ) . its ( 'length' ) . should ( 'equal' , 1 ) ; } ) ; it ( 'clicking on an inactive tab should activate it' , ( ) => { cy . getTab ( 0 , 0 ) . should ( 'have.class' , Classes . INTENT_PRIMARY ) ; cy . addTab ( 0 ) ; cy . getTab ( 0 , 0 ) . should ( 'not.have.class' , Classes . INTENT_PRIMARY ) ; cy . getTab ( 0 , 1 ) . should ( 'have.class' , Classes . INTENT_PRIMARY ) ; cy . getTab ( 0 , 0 ) . click ( ) . should ( 'have.class' , Classes . INTENT_PRIMARY ) ; cy . getTab ( 0 , 1 ) . should ( 'not.have.class' , Classes . INTENT_PRIMARY ) ; cy . getTab ( 0 , 1 ) . triggerHover ( ) ; } ) ; } ) ;