/*********************************************************************
 * Copyright (c) 2021 Red Hat, Inc.
 *
 * This program and the accompanying materials are made
 * available under the terms of the Eclipse Public License 2.0
 * which is available at https://www.eclipse.org/legal/epl-2.0/
 *
 * SPDX-License-Identifier: EPL-2.0
 **********************************************************************/ import 'reflect-metadata' ; import { DriverHelper } from '../../utils/DriverHelper' ; import { e2eContainer } from '../../inversify.config' ; import { CLASSES } from '../../inversify.types' ; import { Ide , LeftToolbarButton } from '../../pageobjects/ide/Ide' ; import { TimeoutConstants } from '../../TimeoutConstants' ; import { TestConstants } from '../../TestConstants' ; import { ProjectTree } from '../../pageobjects/ide/ProjectTree' ; import { Key , By } from 'selenium-webdriver' ; import { Editor } from '../../pageobjects/ide/Editor' ; import { TopMenu } from '../../pageobjects/ide/TopMenu' ; import { DebugView } from '../../pageobjects/ide/DebugView' ; import { Terminal } from '../../pageobjects/ide/Terminal' ; import { BrowserTabsUtil } from '../../utils/BrowserTabsUtil' ; import { WorkspaceHandlingTests } from '../../testsLibrary/WorkspaceHandlingTests' ; import { Logger } from '../../utils/Logger' ; import CheReporter from '../../driver/CheReporter' ; import { WorkspaceNameHandler } from '../../utils/WorkspaceNameHandler' ; const workspaceHandlingTests = e2eContainer . get ( CLASSES . WorkspaceHandlingTests ) ; const driverHelper = e2eContainer . get ( CLASSES . DriverHelper ) ; const ide = e2eContainer . get ( CLASSES . Ide ) ; const projectTree = e2eContainer . get ( CLASSES . ProjectTree ) ; const editor = e2eContainer . get ( CLASSES . Editor ) ; const topMenu = e2eContainer . get ( CLASSES . TopMenu ) ; const debugView = e2eContainer . get ( CLASSES . DebugView ) ; const terminal = e2eContainer . get ( CLASSES . Terminal ) ; const browserTabsUtil = e2eContainer . get ( CLASSES . BrowserTabsUtil ) ; const workspaceNameHandler = e2eContainer . get ( CLASSES . WorkspaceNameHandler ) ; const devfileUrl = 'https://raw.githubusercontent.com/eclipse/che/main/tests/e2e/files/devfiles/plugins/TypescriptNodeDebug2PluginTest.yaml' ; const factoryUrl = `${ TestConstants . TS_SELENIUM_BASE_URL }/f?url=${ devfileUrl }` ; const codeNavigationClassName = 'OpenDefinition.ts' ; const projectName = 'nodejs-web-app' ; const subRootFolder = 'app' ; const sampleBodyLocator = By . xpath ( `//body[text()='Hello World!']` ) ; const fileFolderPath = `${ projectName }` ; const debugFileFolderPath = `${ projectName }/app` ; const debugFile = 'app.js' ; const tabTitle = 'typescript-node-debug.ts' ; let workspaceName ; suite ( `The 'TypescriptPlugin and Node-debug' tests` , async ( ) => { suite ( 'Create workspace' , async ( ) => { test ( 'Create workspace using factory' , async ( ) => { await browserTabsUtil . navigateTo ( factoryUrl ) ; } ) ; test ( 'Wait until created workspace is started' , async ( ) => { await ide . waitAndSwitchToIdeFrame ( ) ; workspaceName = await workspaceNameHandler . getNameFromUrl ( ) ; CheReporter . registerRunningWorkspace ( workspaceName ) ; await ide . waitIde ( TimeoutConstants . TS_SELENIUM_START_WORKSPACE_TIMEOUT ) ; await ide . waitNotificationAndClickOnButton ( 'Do you trust the authors of' , 'Yes, I trust' , 60000 ) ; await projectTree . openProjectTreeContainer ( ) ; await projectTree . waitProjectImported ( projectName , subRootFolder ) ; } ) ; } ) ; suite ( 'The Typescript plugin test' , async ( ) => { test ( 'Open file' , async ( ) => { await projectTree . expandPathAndOpenFile ( fileFolderPath , tabTitle ) ; await editor . selectTab ( tabTitle ) ; } ) ; test ( 'Wait until JS/Typescript LS is initialised' , async ( ) => { await ide . checkLsInitializationStart ( 'Initializing' ) ; await ide . waitStatusBarTextAbsence ( 'Initializing' , 900000 ) ; } ) ; test ( 'Autocomplete' , async ( ) => { await editor . moveCursorToLineAndChar ( tabTitle , 8 , 22 ) ; await editor . pressControlSpaceCombination ( tabTitle ) ; await editor . waitSuggestionContainer ( ) ; await editor . waitSuggestion ( tabTitle , 'OpenDefinition' ) ; } ) ; test ( 'Error highlighting' , async ( ) => { const textForErrorDisplaying = '//' ; await editor . type ( tabTitle , textForErrorDisplaying , 5 ) ; await editor . waitErrorInLine ( 4 , tabTitle , TimeoutConstants . TS_ERROR_HIGHLIGHTING_TIMEOUT ) ; await editor . type ( tabTitle , Key . chord ( Key . DELETE , Key . DELETE ) , 5 ) ; await editor . waitErrorInLineDisappearance ( 4 , tabTitle ) ; } ) ; test ( 'Codenavigation' , async ( ) => { await editor . moveCursorToLineAndChar ( tabTitle , 8 , 22 ) ; await editor . performKeyCombination ( tabTitle , Key . chord ( Key . CONTROL , Key . F12 ) ) ; await editor . waitEditorAvailable ( codeNavigationClassName , 60000 ) ; } ) ; } ) ; suite ( `The 'Node-debug' plugin test` , async ( ) => { let currentWindow = '' ; let applicationPreviewWindow = '' ; test ( 'Run application in debug mode' , async ( ) => { await topMenu . runTask ( 'run the web app (debugging enabled), Global' ) ; await ide . waitNotification ( 'Process nodejs is now listening on port 3000.' ) ; currentWindow = await browserTabsUtil . getCurrentWindowHandle ( ) ; } ) ; test ( 'Open application in the new editor window' , async ( ) => { await ide . clickOnNotificationButton ( 'Process nodejs is now listening on port 3000.' , 'Open In New Tab' ) ; await browserTabsUtil . waitAndSwitchToAnotherWindow ( currentWindow , 60000 ) ; await browserTabsUtil . waitContentAvailableInTheNewTab ( sampleBodyLocator , 60000 ) ; applicationPreviewWindow = await browserTabsUtil . getCurrentWindowHandle ( ) ; } ) ; test ( 'Switch back to the IDE window' , async ( ) => { await browserTabsUtil . switchToWindow ( currentWindow ) ; await ide . waitAndSwitchToIdeFrame ( 60000 ) ; } ) ; test ( 'Activate breakpoint' , async ( ) => { await projectTree . expandPathAndOpenFile ( debugFileFolderPath , debugFile ) ; await editor . activateBreakpoint ( debugFile , 19 ) ; } ) ; test ( 'Run debug' , async ( ) => { await topMenu . selectOption ( 'View' , 'Debug' ) ; await ide . waitLeftToolbarButton ( LeftToolbarButton . Debug ) ; await debugView . clickOnDebugConfigurationDropDown ( ) ; await debugView . clickOnDebugConfigurationItem ( 'Add Configuration...' ) ; await debugView . clickOnDebugConfigurationDropDown ( ) ; await debugView . clickOnDebugConfigurationItem ( 'Attach to Remote (nodejs-web-app)' ) ; await debugView . clickOnRunDebugButton ( ) ; } ) ; test ( 'Wait debug connected' , async ( ) => { await terminal . waitTab ( 'Debug Console' , 60000 ) ; await driverHelper . wait ( 10000 ) ; } ) ; test ( 'Refresh application sample window' , async ( ) => { await browserTabsUtil . switchToWindow ( applicationPreviewWindow ) ; await browserTabsUtil . waitContentAvailableInTheNewTab ( sampleBodyLocator , 60000 ) ; await browserTabsUtil . refreshForDebug ( ) ; } ) ; test ( 'Check breakpoint stopped' , async ( ) => { await browserTabsUtil . switchToWindow ( currentWindow ) ; await ide . waitAndSwitchToIdeFrame ( 60000 ) ; await editor . waitStoppedDebugBreakpoint ( debugFile , 19 , 60000 ) ; } ) ; } ) ; suite ( 'Stopping and deleting the workspace' , async ( ) => { test ( 'Stop and remove workspace' , async ( ) => { if ( TestConstants . TS_DELETE_PLUGINS_TEST_WORKSPACE === 'true' ) { await workspaceHandlingTests . stopAndRemoveWorkspace ( workspaceName ) ; return ; } Logger . info ( `As far as the "TS_DELETE_PLUGINS_TEST_WORKSPACE" value is "false the workspace deletion is skipped"` ) ; } ) ; } ) ; } ) ;