Skip to content

Commit 1dc86a0

Browse files
committed
Update hover tests to verify descriptions
1 parent 99584b4 commit 1dc86a0

3 files changed

Lines changed: 54 additions & 34 deletions

File tree

src/test/GradleTestLSPHover.ts

Lines changed: 22 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -83,12 +83,12 @@ describe('LSP Hover tests for Gradle Project', () => {
8383

8484
// Test data for parameterized hover tests
8585
const hoverTestCases = [
86-
{ element: 'httpEndpoint element', line: 18, column: 10 },
87-
{ element: 'feature element', line: 15, column: 16 },
88-
{ element: 'featureManager element', line: 14, column: 10 },
89-
{ element: 'webApplication element', line: 20, column: 10 },
90-
{ element: 'jsp-2.3 feature value', line: 15, column: 22 },
91-
{ element: 'httpPort attribute', line: 18, column: 33 }
86+
{ element: 'httpEndpoint element', line: 18, column: 10, expectedDoc: 'Configuration properties for an HTTP endpoint.' },
87+
{ element: 'feature element', line: 15, column: 16, expectedDoc: 'Specifies a feature to be used when the server runs.' },
88+
{ element: 'featureManager element', line: 14, column: 10, expectedDoc: 'Defines how the server loads features.' },
89+
{ element: 'webApplication element', line: 20, column: 10, expectedDoc: 'Defines the properties of a web application.' },
90+
{ element: 'jsp-2.3 feature value', line: 15, column: 22, expectedDoc: 'This feature enables support for Java Server Pages (JSPs) that are written to the JSP 2.3 specification.' },
91+
{ element: 'httpPort attribute', line: 18, column: 33, expectedDoc: 'The port used for client HTTP requests. Use -1 to disable this port.' }
9292
];
9393

9494
hoverTestCases.forEach(testCase => {
@@ -107,11 +107,15 @@ describe('LSP Hover tests for Gradle Project', () => {
107107

108108
logger.step(3, 'Verifying hover widget appears with Liberty Language Server content');
109109
const driver = VSBrowser.instance.driver;
110-
const hoverVisible = await utils.waitForHoverWidget(driver, testCase.element, 15000);
110+
const hoverText = await utils.waitForHoverWidget(driver, testCase.element, 15000);
111111

112-
expect(hoverVisible).to.be.true;
112+
expect(hoverText).to.not.be.empty;
113113
logger.stepSuccess(3, `Hover widget displayed with Liberty Language Server content for ${testCase.element}`);
114114

115+
logger.step(4, 'Verifying hover contains expected documentation');
116+
expect(hoverText).to.include(testCase.expectedDoc);
117+
logger.stepSuccess(4, `Hover text contains expected documentation: "${testCase.expectedDoc}"`);
118+
115119
logger.testComplete(`Hover over ${testCase.element} shows Liberty Language Server documentation`);
116120
} catch (error) {
117121
logger.testFailed(`Hover over ${testCase.element} shows Liberty Language Server documentation`, error);
@@ -168,10 +172,10 @@ describe('LSP Hover tests for Gradle Project', () => {
168172

169173
// Test data for LSP4Jakarta hover tests
170174
const jakartaHoverTestCases = [
171-
{ element: '@WebServlet annotation', line: 23, column: 2 },
172-
{ element: 'HttpServlet class', line: 24, column: 35 },
173-
{ element: 'HttpServletRequest type', line: 30, column: 35 },
174-
{ element: 'HttpServletResponse type', line: 30, column: 70 }
175+
{ element: '@WebServlet annotation', line: 23, column: 2, expectedDoc: 'Annotation used to declare a servlet.' },
176+
{ element: 'HttpServlet class', line: 24, column: 35, expectedDoc: 'Provides an abstract class to be subclassed to create an HTTP servlet suitable for a Web site.' },
177+
{ element: 'HttpServletRequest type', line: 30, column: 35, expectedDoc: 'Extends the javax.servlet.ServletRequest interface to provide request information for HTTP servlets.' },
178+
{ element: 'HttpServletResponse type', line: 30, column: 70, expectedDoc: 'Extends the ServletResponse interface to provide HTTP-specific functionality in sending a response.' }
175179
];
176180

177181
jakartaHoverTestCases.forEach(testCase => {
@@ -190,11 +194,15 @@ describe('LSP Hover tests for Gradle Project', () => {
190194

191195
logger.step(3, 'Verifying hover widget appears with LSP4Jakarta content');
192196
const driver = VSBrowser.instance.driver;
193-
const hoverVisible = await utils.waitForHoverWidget(driver, testCase.element, 15000);
197+
const hoverText = await utils.waitForHoverWidget(driver, testCase.element, 15000);
194198

195-
expect(hoverVisible).to.be.true;
199+
expect(hoverText).to.not.be.empty;
196200
logger.stepSuccess(3, `Hover widget displayed with LSP4Jakarta content for ${testCase.element}`);
197201

202+
logger.step(4, 'Verifying hover contains expected documentation');
203+
expect(hoverText).to.include(testCase.expectedDoc);
204+
logger.stepSuccess(4, `Hover text contains expected documentation: "${testCase.expectedDoc}"`);
205+
198206
logger.testComplete(`Hover over ${testCase.element} shows LSP4Jakarta documentation`);
199207
} catch (error) {
200208
logger.testFailed(`Hover over ${testCase.element} shows LSP4Jakarta documentation`, error);

src/test/MavenTestLSPHover.ts

Lines changed: 22 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -83,12 +83,12 @@ describe('LSP Hover tests for Maven Project', () => {
8383

8484
// Test data for parameterized hover tests
8585
const hoverTestCases = [
86-
{ element: 'httpEndpoint element', line: 19, column: 10 },
87-
{ element: 'feature element', line: 16, column: 16 },
88-
{ element: 'featureManager element', line: 15, column: 10 },
89-
{ element: 'webApplication element', line: 21, column: 10 },
90-
{ element: 'jsp-2.3 feature value', line: 16, column: 22 },
91-
{ element: 'httpPort attribute', line: 19, column: 33 }
86+
{ element: 'httpEndpoint element', line: 19, column: 10, expectedDoc: 'Configuration properties for an HTTP endpoint.' },
87+
{ element: 'feature element', line: 16, column: 16, expectedDoc: 'Specifies a feature to be used when the server runs.' },
88+
{ element: 'featureManager element', line: 15, column: 10, expectedDoc: 'Defines how the server loads features.' },
89+
{ element: 'webApplication element', line: 21, column: 10, expectedDoc: 'Defines the properties of a web application.' },
90+
{ element: 'jsp-2.3 feature value', line: 16, column: 22, expectedDoc: 'This feature enables support for Java Server Pages (JSPs) that are written to the JSP 2.3 specification.' },
91+
{ element: 'httpPort attribute', line: 19, column: 33, expectedDoc: 'The port used for client HTTP requests. Use -1 to disable this port.' }
9292
];
9393

9494
hoverTestCases.forEach(testCase => {
@@ -107,11 +107,15 @@ describe('LSP Hover tests for Maven Project', () => {
107107

108108
logger.step(3, 'Verifying hover widget appears with Liberty Language Server content');
109109
const driver = VSBrowser.instance.driver;
110-
const hoverVisible = await utils.waitForHoverWidget(driver, testCase.element, 15000);
110+
const hoverText = await utils.waitForHoverWidget(driver, testCase.element, 15000);
111111

112-
expect(hoverVisible).to.be.true;
112+
expect(hoverText).to.not.be.empty;
113113
logger.stepSuccess(3, `Hover widget displayed with Liberty Language Server content for ${testCase.element}`);
114114

115+
logger.step(4, 'Verifying hover contains expected documentation');
116+
expect(hoverText).to.include(testCase.expectedDoc);
117+
logger.stepSuccess(4, `Hover text contains expected documentation: "${testCase.expectedDoc}"`);
118+
115119
logger.testComplete(`Hover over ${testCase.element} shows Liberty Language Server documentation`);
116120
} catch (error) {
117121
logger.testFailed(`Hover over ${testCase.element} shows Liberty Language Server documentation`, error);
@@ -168,10 +172,10 @@ describe('LSP Hover tests for Maven Project', () => {
168172

169173
// Test data for LSP4Jakarta hover tests
170174
const jakartaHoverTestCases = [
171-
{ element: '@WebServlet annotation', line: 23, column: 2 },
172-
{ element: 'HttpServlet class', line: 24, column: 35 },
173-
{ element: 'HttpServletRequest type', line: 30, column: 35 },
174-
{ element: 'HttpServletResponse type', line: 30, column: 70 }
175+
{ element: '@WebServlet annotation', line: 23, column: 2, expectedDoc: 'Annotation used to declare a servlet.' },
176+
{ element: 'HttpServlet class', line: 24, column: 35, expectedDoc: 'Provides an abstract class to be subclassed to create an HTTP servlet suitable for a Web site.' },
177+
{ element: 'HttpServletRequest type', line: 30, column: 35, expectedDoc: 'Extends the javax.servlet.ServletRequest interface to provide request information for HTTP servlets.' },
178+
{ element: 'HttpServletResponse type', line: 30, column: 70, expectedDoc: 'Extends the ServletResponse interface to provide HTTP-specific functionality in sending a response.' }
175179
];
176180

177181
jakartaHoverTestCases.forEach(testCase => {
@@ -190,11 +194,15 @@ describe('LSP Hover tests for Maven Project', () => {
190194

191195
logger.step(3, 'Verifying hover widget appears with LSP4Jakarta content');
192196
const driver = VSBrowser.instance.driver;
193-
const hoverVisible = await utils.waitForHoverWidget(driver, testCase.element, 15000);
197+
const hoverText = await utils.waitForHoverWidget(driver, testCase.element, 15000);
194198

195-
expect(hoverVisible).to.be.true;
199+
expect(hoverText).to.not.be.empty;
196200
logger.stepSuccess(3, `Hover widget displayed with LSP4Jakarta content for ${testCase.element}`);
197201

202+
logger.step(4, 'Verifying hover contains expected documentation');
203+
expect(hoverText).to.include(testCase.expectedDoc);
204+
logger.stepSuccess(4, `Hover text contains expected documentation: "${testCase.expectedDoc}"`);
205+
198206
logger.testComplete(`Hover over ${testCase.element} shows LSP4Jakarta documentation`);
199207
} catch (error) {
200208
logger.testFailed(`Hover over ${testCase.element} shows LSP4Jakarta documentation`, error);

src/test/utils/testUtils.ts

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -101,34 +101,38 @@ export async function waitForLanguageServerInit(
101101
* @param driver The WebDriver instance
102102
* @param elementDescription Description of the element being hovered (for logging)
103103
* @param timeout Timeout in milliseconds (default: 15000)
104-
* @returns true if hover widget appeared with content
104+
* @returns The hover text content if widget appeared with content, empty string otherwise
105105
*/
106106
export async function waitForHoverWidget(
107107
driver: any,
108108
elementDescription: string,
109109
timeout: number = 15000
110-
): Promise<boolean> {
110+
): Promise<string> {
111111
const wait = getWaitHelper();
112112

113-
return await wait.forCondition(async () => {
113+
const result = await wait.forCondition(async () => {
114114
try {
115115
const hoverWidget = await driver.findElement({ css: '.monaco-hover' });
116116
const isDisplayed = await hoverWidget.isDisplayed();
117117
if (isDisplayed) {
118118
const hoverText = await hoverWidget.getText();
119119
logger.info(`Hover content for ${elementDescription}: ${hoverText.length} characters`);
120120
// Verify hover contains content (language server provides documentation)
121-
return hoverText && hoverText.length > 0;
121+
if (hoverText && hoverText.length > 0) {
122+
return hoverText;
123+
}
122124
}
123125
} catch {
124-
return false;
126+
return undefined;
125127
}
126-
return false;
128+
return undefined;
127129
}, {
128130
timeout: timeout,
129131
pollInterval: 500,
130132
message: `Hover widget did not appear with content for ${elementDescription}`
131133
});
134+
135+
return result || '';
132136
}
133137

134138
/**

0 commit comments

Comments
 (0)