|
| 1 | +/* |
| 2 | + * IBM Confidential |
| 3 | + * Copyright IBM Corp. 2026 |
| 4 | + */ |
| 5 | +import { expect } from 'chai'; |
| 6 | +import { EditorView, TextEditor, VSBrowser, Workbench, StatusBar } from 'vscode-extension-tester'; |
| 7 | +import * as utils from './utils/testUtils'; |
| 8 | +import * as constants from './definitions/constants'; |
| 9 | +import { logger } from './utils/testLogger'; |
| 10 | +import * as path from 'path'; |
| 11 | + |
| 12 | +describe('LSP Hover tests for Gradle Project', () => { |
| 13 | + let editorView: EditorView; |
| 14 | + let editor: TextEditor; |
| 15 | + let wait: any; |
| 16 | + |
| 17 | + before(async function() { |
| 18 | + this.timeout(60000); |
| 19 | + logger.info('Setting up Gradle LSP Hover tests'); |
| 20 | + |
| 21 | + // Wait for workbench to be ready |
| 22 | + await VSBrowser.instance.waitForWorkbench(); |
| 23 | + editorView = new EditorView(); |
| 24 | + wait = utils.getWaitHelper(); |
| 25 | + |
| 26 | + // Open server.xml file once for all tests |
| 27 | + logger.info('Opening server.xml file for all tests'); |
| 28 | + const serverXmlPath = path.resolve( |
| 29 | + utils.getGradleProjectPath(), |
| 30 | + 'src', |
| 31 | + 'main', |
| 32 | + 'liberty', |
| 33 | + 'config', |
| 34 | + 'server.xml' |
| 35 | + ); |
| 36 | + logger.info(`Server.xml path: ${serverXmlPath}`); |
| 37 | + |
| 38 | + await VSBrowser.instance.openResources(serverXmlPath, async () => { |
| 39 | + await wait.sleep(3000); // Allow time for file to load |
| 40 | + }); |
| 41 | + |
| 42 | + editor = await editorView.openEditor('server.xml') as TextEditor; |
| 43 | + logger.info('Server.xml file opened and editor obtained'); |
| 44 | + |
| 45 | + // Wait for language server to initialize |
| 46 | + await wait.forCondition(async () => { |
| 47 | + try { |
| 48 | + const statusBar = new StatusBar(); |
| 49 | + const languageItem = await statusBar.getItem('Initializing JS/TS language features'); |
| 50 | + return !languageItem; |
| 51 | + } catch { |
| 52 | + return true; |
| 53 | + } |
| 54 | + }, { |
| 55 | + timeout: 30000, |
| 56 | + pollInterval: 2000, |
| 57 | + message: 'Language server did not initialize' |
| 58 | + }); |
| 59 | + logger.info('Language server initialized'); |
| 60 | + }); |
| 61 | + |
| 62 | + afterEach(async function() { |
| 63 | + // Take screenshot on failure but don't close editor |
| 64 | + if (this.currentTest?.state === 'failed') { |
| 65 | + const driver = VSBrowser.instance.driver; |
| 66 | + const screenshot = await driver.takeScreenshot(); |
| 67 | + logger.error(`Test failed: ${this.currentTest.title}`); |
| 68 | + } |
| 69 | + }); |
| 70 | + |
| 71 | + after(async function() { |
| 72 | + // Close editor after all tests complete |
| 73 | + try { |
| 74 | + await editorView.closeAllEditors(); |
| 75 | + logger.info('Closed all editors after test suite'); |
| 76 | + } catch (error) { |
| 77 | + logger.error('Failed to close editors in after hook', error); |
| 78 | + } |
| 79 | + |
| 80 | + utils.copyScreenshotsToProjectFolder('gradle-lsp-hover'); |
| 81 | + }); |
| 82 | + |
| 83 | + // Test data for parameterized hover tests |
| 84 | + const hoverTestCases = [ |
| 85 | + { element: 'httpEndpoint element', line: 18, column: 10 }, |
| 86 | + { element: 'feature element', line: 15, column: 16 }, |
| 87 | + { element: 'featureManager element', line: 14, column: 10 }, |
| 88 | + { element: 'webApplication element', line: 20, column: 10 }, |
| 89 | + { element: 'jsp-2.3 feature value', line: 15, column: 22 }, |
| 90 | + { element: 'httpPort attribute', line: 18, column: 33 } |
| 91 | + ]; |
| 92 | + |
| 93 | + hoverTestCases.forEach(testCase => { |
| 94 | + it(`Hover over ${testCase.element} shows Liberty Language Server documentation`, async function() { |
| 95 | + this.timeout(30000); |
| 96 | + logger.testStart(`Hover over ${testCase.element} shows Liberty Language Server documentation`); |
| 97 | + |
| 98 | + try { |
| 99 | + logger.step(1, `Setting cursor position on ${testCase.element}`); |
| 100 | + await editor.setCursor(testCase.line, testCase.column); |
| 101 | + logger.stepSuccess(1, `Cursor positioned on ${testCase.element} at line ${testCase.line}`); |
| 102 | + |
| 103 | + logger.step(2, 'Triggering hover via command palette'); |
| 104 | + await new Workbench().executeCommand('editor.action.showHover'); |
| 105 | + logger.stepSuccess(2, 'Hover command executed'); |
| 106 | + |
| 107 | + logger.step(3, 'Verifying hover widget appears with Liberty Language Server content'); |
| 108 | + const driver = VSBrowser.instance.driver; |
| 109 | + const hoverVisible = await wait.forCondition(async () => { |
| 110 | + try { |
| 111 | + const hoverWidget = await driver.findElement({ css: '.monaco-hover' }); |
| 112 | + const isDisplayed = await hoverWidget.isDisplayed(); |
| 113 | + if (isDisplayed) { |
| 114 | + const hoverText = await hoverWidget.getText(); |
| 115 | + logger.info(`Hover content for ${testCase.element}: ${hoverText.length} characters`); |
| 116 | + // Verify hover contains content (Liberty LS provides documentation) |
| 117 | + return hoverText && hoverText.length > 0; |
| 118 | + } |
| 119 | + } catch { |
| 120 | + return; |
| 121 | + } |
| 122 | + return; |
| 123 | + }, { |
| 124 | + timeout: 10000, |
| 125 | + pollInterval: 500, |
| 126 | + message: `Hover widget did not appear with content for ${testCase.element}` |
| 127 | + }); |
| 128 | + |
| 129 | + expect(hoverVisible).to.be.true; |
| 130 | + logger.stepSuccess(3, `Hover widget displayed with Liberty Language Server content for ${testCase.element}`); |
| 131 | + |
| 132 | + logger.testComplete(`Hover over ${testCase.element} shows Liberty Language Server documentation`); |
| 133 | + } catch (error) { |
| 134 | + logger.testFailed(`Hover over ${testCase.element} shows Liberty Language Server documentation`, error); |
| 135 | + throw error; |
| 136 | + } |
| 137 | + }); |
| 138 | + }); |
| 139 | + |
| 140 | + describe('LSP4Jakarta Hover tests in Java file', () => { |
| 141 | + let javaEditor: TextEditor; |
| 142 | + |
| 143 | + before(async function() { |
| 144 | + this.timeout(60000); |
| 145 | + logger.info('Opening HelloServlet.java file for LSP4Jakarta hover tests'); |
| 146 | + |
| 147 | + const javaFilePath = path.resolve( |
| 148 | + utils.getGradleProjectPath(), |
| 149 | + 'src', |
| 150 | + 'main', |
| 151 | + 'java', |
| 152 | + 'test', |
| 153 | + 'gradle', |
| 154 | + 'liberty', |
| 155 | + 'web', |
| 156 | + 'app', |
| 157 | + 'HelloServlet.java' |
| 158 | + ); |
| 159 | + logger.info(`Java file path: ${javaFilePath}`); |
| 160 | + |
| 161 | + await VSBrowser.instance.openResources(javaFilePath, async () => { |
| 162 | + await wait.sleep(3000); // Allow time for file to load |
| 163 | + }); |
| 164 | + |
| 165 | + javaEditor = await editorView.openEditor('HelloServlet.java') as TextEditor; |
| 166 | + logger.info('HelloServlet.java file opened and editor obtained'); |
| 167 | + |
| 168 | + // Wait for Java language server to initialize |
| 169 | + await wait.forCondition(async () => { |
| 170 | + try { |
| 171 | + const statusBar = new StatusBar(); |
| 172 | + const languageItem = await statusBar.getItem('Initializing JS/TS language features'); |
| 173 | + return !languageItem; |
| 174 | + } catch { |
| 175 | + return true; |
| 176 | + } |
| 177 | + }, { |
| 178 | + timeout: 30000, |
| 179 | + pollInterval: 2000, |
| 180 | + message: 'Java language server did not initialize' |
| 181 | + }); |
| 182 | + logger.info('Java language server initialized'); |
| 183 | + }); |
| 184 | + |
| 185 | + // Test data for LSP4Jakarta hover tests |
| 186 | + const jakartaHoverTestCases = [ |
| 187 | + { element: '@WebServlet annotation', line: 23, column: 2 }, |
| 188 | + { element: 'HttpServlet class', line: 24, column: 35 }, |
| 189 | + { element: 'HttpServletRequest type', line: 30, column: 35 }, |
| 190 | + { element: 'HttpServletResponse type', line: 30, column: 70 } |
| 191 | + ]; |
| 192 | + |
| 193 | + jakartaHoverTestCases.forEach(testCase => { |
| 194 | + it(`Hover over ${testCase.element} shows LSP4Jakarta documentation`, async function() { |
| 195 | + this.timeout(30000); |
| 196 | + logger.testStart(`Hover over ${testCase.element} shows LSP4Jakarta documentation`); |
| 197 | + |
| 198 | + try { |
| 199 | + logger.step(1, `Setting cursor position on ${testCase.element}`); |
| 200 | + await javaEditor.setCursor(testCase.line, testCase.column); |
| 201 | + logger.stepSuccess(1, `Cursor positioned on ${testCase.element} at line ${testCase.line}`); |
| 202 | + |
| 203 | + logger.step(2, 'Triggering hover via command palette'); |
| 204 | + await new Workbench().executeCommand('editor.action.showHover'); |
| 205 | + logger.stepSuccess(2, 'Hover command executed'); |
| 206 | + |
| 207 | + logger.step(3, 'Verifying hover widget appears with LSP4Jakarta content'); |
| 208 | + const driver = VSBrowser.instance.driver; |
| 209 | + const hoverVisible = await wait.forCondition(async () => { |
| 210 | + try { |
| 211 | + const hoverWidget = await driver.findElement({ css: '.monaco-hover' }); |
| 212 | + const isDisplayed = await hoverWidget.isDisplayed(); |
| 213 | + if (isDisplayed) { |
| 214 | + const hoverText = await hoverWidget.getText(); |
| 215 | + logger.info(`Hover content for ${testCase.element}: ${hoverText.length} characters`); |
| 216 | + // Verify hover contains content (LSP4Jakarta provides documentation) |
| 217 | + return hoverText && hoverText.length > 0; |
| 218 | + } |
| 219 | + } catch { |
| 220 | + return; |
| 221 | + } |
| 222 | + return; |
| 223 | + }, { |
| 224 | + timeout: 10000, |
| 225 | + pollInterval: 500, |
| 226 | + message: `Hover widget did not appear with content for ${testCase.element}` |
| 227 | + }); |
| 228 | + |
| 229 | + expect(hoverVisible).to.be.true; |
| 230 | + logger.stepSuccess(3, `Hover widget displayed with LSP4Jakarta content for ${testCase.element}`); |
| 231 | + |
| 232 | + logger.testComplete(`Hover over ${testCase.element} shows LSP4Jakarta documentation`); |
| 233 | + } catch (error) { |
| 234 | + logger.testFailed(`Hover over ${testCase.element} shows LSP4Jakarta documentation`, error); |
| 235 | + throw error; |
| 236 | + } |
| 237 | + }); |
| 238 | + }); |
| 239 | + }); |
| 240 | + |
| 241 | +}); |
| 242 | + |
| 243 | +// Made with Bob |
0 commit comments