import { Classes } from '@blueprintjs/core' ; /**
 * NOTE: Combos are events that are supposed to be sent from the main process
 * after a menu (or its associated shortcut) has been selected.
 *
 * Since we are running inside the browser (Electron testing support is coming soon,
 * see: https://www.cypress.io/blog/2019/09/26/testing-electron-js-applications-using-cypress-alpha-release/),
 * we are sending fake combo events to simulate the user selecting a menu item or pressing the associated
 * accelerator combo.
 */ describe ( 'combo hotkeys' , ( ) => { let caches ; function resetSelection ( ) { cy . window ( ) . then ( ( win ) => { win . appState . winStates [ 0 ] . views . forEach ( ( view ) => { caches = view . caches . forEach ( ( cache ) => { cache . reset ( ) ; } ) ; } ) ; } ) ; } function createStubs ( ) { cy . window ( ) . then ( ( win ) => { const { appState } = win ; const winState = appState . winStates [ 0 ] ; const view = winState . views [ 0 ] ; winState . splitView = true ; cy . stub ( appState , 'copySelectedItemsPath' ) . as ( 'copySelectedItemsPath' ) ; cy . stub ( appState , 'refreshActiveView' ) . as ( 'refreshActiveView' ) ; cy . stub ( view . caches [ 0 ] , 'openTerminal' ) . as ( 'openTerminal' ) ; cy . stub ( view , 'cycleTab' ) . as ( 'cycleTab' ) ; cy . stub ( view , 'addCache' ) . as ( 'addCache' ) ; cy . stub ( view , 'closeTab' ) . as ( 'closeTab' ) ; cy . spy ( winState , 'toggleSplitViewMode' ) . as ( 'toggleSplitViewMode' ) ; } ) ; } function getCaches ( ) { cy . window ( ) . then ( ( win ) => { caches = win . appState . winStates [ 0 ] . views [ 0 ] . caches ; } ) ; } before ( ( ) => { return cy . visit ( 'http://127.0.0.1:8080' ) ; } ) ; beforeEach ( ( ) => { createStubs ( ) ; resetSelection ( ) ; getCaches ( ) ; cy . CDAndList ( 0 , '/' ) ; cy . get ( '#view_0 [data-cy-path]' ) . invoke ( 'val' , '/' ) . focus ( ) . blur ( ) ; } ) ; it ( 'should not show toast message on copy path if no file selected' , ( ) => { cy . triggerFakeCombo ( 'CmdOrCtrl+Shift+C' ) ; cy . get ( `.${ Classes . TOAST }` ) . should ( 'not.be.visible' ) ; cy . get ( '@copySelectedItemsPath' ) . should ( 'be.calledWith' , caches [ 0 ] , false ) ; } ) ; it ( 'should copy file path to cb & show toast message if a file is selected' , ( ) => { cy . get ( '#view_0 [data-cy-file]:first' ) . click ( ) ; cy . triggerFakeCombo ( 'CmdOrCtrl+Shift+C' ) ; cy . get ( '@copySelectedItemsPath' ) . should ( 'be.calledWith' , caches [ 0 ] , false ) ; cy . get ( `.${ Classes . TOAST }` ) . should ( 'be.visible' ) . find ( 'button' ) . click ( ) ; } ) ; it ( 'should not show toast message on copy filename if no file selected' , ( ) => { cy . triggerFakeCombo ( 'CmdOrCtrl+Shift+N' ) ; cy . get ( `.${ Classes . TOAST }` ) . should ( 'not.be.visible' ) ; cy . get ( '@copySelectedItemsPath' ) . should ( 'be.calledWith' , caches [ 0 ] , true ) ; } ) ; it ( 'should copy file filename & show toast message if a file is selected' , ( ) => { cy . get ( '#view_0 [data-cy-file]:first' ) . click ( ) ; cy . triggerFakeCombo ( 'CmdOrCtrl+Shift+N' ) ; cy . get ( '@copySelectedItemsPath' ) . should ( 'be.calledWith' , caches [ 0 ] , true ) ; cy . get ( `.${ Classes . TOAST }` ) . should ( 'be.visible' ) . find ( 'button' ) . click ( ) ; } ) ; it ( 'should open shortcuts dialog' , ( ) => { cy . triggerFakeCombo ( 'CmdOrCtrl+S' ) ; cy . get ( '.shortcutsDialog' ) . should ( 'be.visible' ) ; cy . get ( `.${ Classes . DIALOG_FOOTER } .data-cy-close` ) . click ( ) ; cy . get ( '.shortcutsDialog' ) . should ( 'not.be.visible' ) ; } ) ; it ( 'should open prefs dialog' , ( ) => { cy . triggerFakeCombo ( 'CmdOrCtrl+,' ) ; cy . get ( '.data-cy-prefs-dialog' ) . should ( 'be.visible' ) ; cy . get ( `.${ Classes . DIALOG_FOOTER } .data-cy-close` ) . click ( ) ; cy . get ( '.shortcutsDialog' ) . should ( 'not.be.visible' ) ; } ) ; it ( 'should reload file view' , ( ) => { cy . triggerFakeCombo ( 'CmdOrCtrl+R' ) ; cy . get ( '@refreshActiveView' ) . should ( 'be.calledOnce' ) ; } ) ; it ( 'should open terminal' , ( ) => { cy . triggerFakeCombo ( 'CmdOrCtrl+K' ) ; cy . get ( '@openTerminal' ) . should ( 'be.calledOnce' ) ; } ) ; it ( 'should activate next tab' , ( ) => { cy . triggerFakeCombo ( 'Ctrl+Tab' ) ; cy . get ( '@cycleTab' ) . should ( 'be.calledOnce' ) . should ( 'be.calledWith' , 1 ) ; } ) ; it ( 'should activate previous tab' , ( ) => { cy . triggerFakeCombo ( 'Ctrl+Shift+Tab' ) ; cy . get ( '@cycleTab' ) . should ( 'be.calledOnce' ) . should ( 'be.calledWith' , - 1 ) ; } ) ; it ( 'should open a new tab' , ( ) => { cy . triggerFakeCombo ( 'CmdOrCtrl+T' ) ; cy . get ( '@addCache' ) . should ( 'be.calledOnce' ) ; } ) ; it ( 'should close tab' , ( ) => { cy . triggerFakeCombo ( 'CmdOrCtrl+W' ) ; cy . get ( '@closeTab' ) . should ( 'be.calledOnce' ) ; } ) ; it ( 'should toggle split view' , ( ) => { cy . get ( '#view_1' ) . should ( 'not.have.class' , 'active' ) . and ( 'be.visible' ) ; cy . get ( '#view_0' ) . should ( 'have.class' , 'active' ) . and ( 'be.visible' ) ; cy . triggerFakeCombo ( 'CmdOrCtrl+Shift+Alt+V' ) ; cy . get ( '@toggleSplitViewMode' ) . should ( 'be.calledOnce' ) ; cy . get ( '#view_0' ) . should ( 'be.visible' ) . and ( 'have.class' , 'active' ) ; cy . get ( '#view_1' ) . should ( 'not.be.visible' ) ; cy . triggerFakeCombo ( 'CmdOrCtrl+Shift+Alt+V' ) ; cy . get ( '@toggleSplitViewMode' ) . should ( 'be.calledTwice' ) ; cy . get ( '#view_0' ) . should ( 'be.visible' ) . and ( 'not.have.class' , 'active' ) ; cy . get ( '#view_1' ) . should ( 'be.visible' ) . and ( 'have.class' , 'active' ) ; } ) ; } ) ;