Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

UI test to check for relevant completion options in bootstrap.properties and server.env #1205

Merged
merged 11 commits into from
Jan 13, 2025
Original file line number Diff line number Diff line change
@@ -12,12 +12,17 @@
import com.automation.remarks.junit5.Video;
anusreelakshmi934 marked this conversation as resolved.
Show resolved Hide resolved
import com.intellij.remoterobot.RemoteRobot;
import com.intellij.remoterobot.fixtures.JTreeFixture;
import com.intellij.remoterobot.utils.Keyboard;
import io.openliberty.tools.intellij.it.fixtures.ProjectFrameFixture;
import org.junit.jupiter.api.*;

import java.nio.file.Path;
import java.nio.file.Paths;
import java.time.Duration;
import java.util.Map;

import static java.awt.event.KeyEvent.VK_CONTROL;
import static java.awt.event.KeyEvent.VK_SPACE;

import static com.intellij.remoterobot.utils.RepeatUtilsKt.waitForIgnoringError;

@@ -331,6 +336,26 @@ public void testInsertLibertyConfigIntoBootstrapPropsForMixOfCases() {
}
}

/**
* Test to Ensure that relevant completion values (e.g., SIMPLE, ADVANCED)
* are displayed and prioritized at the top of the list in server.env.
*/
@Test
@Video
public void testCompletionValuesInServerEnv() {
runCompletionTest("server.env", "WLP_LOGGING_CONSOLE_FORMAT=", new String[]{"DEV", "JSON", "SIMPLE", "TBASIC"}, 4);
}

/**
* Test to Ensure that relevant completion values (e.g., AUDIT, ERROR)
* are displayed and prioritized at the top of the list in bootstrap.properties
*/
@Test
@Video
public void testCompletionValuesInBootstrapProperties() {
runCompletionTest("bootstrap.properties", "com.ibm.ws.logging.console.log.level=", new String[]{"AUDIT", "ERROR", "INFO", "OFF", "WARNING"}, 5);
}

/**
* Tests liberty-ls Hover support in server.env for a
* Liberty Server Config setting
@@ -499,6 +524,50 @@ public void testDiagnosticInBootstrapProperties() {
}
}

/**
* Helper method to test completion values in a specified file.
*
* @param fileName the name of the file to focus on
* @param propertyKeySnippet the property key snippet to type
* @param expectedCompletionValues the expected completion values
anusreelakshmi934 marked this conversation as resolved.
Show resolved Hide resolved
* @param maxPosition the maximum position for the completion values
*/
private void runCompletionTest(String fileName, String propertyKeySnippet, String[] expectedCompletionValues, int maxPosition) {
Keyboard keyboard = new Keyboard(remoteRobot);

// Get focus on the specified file tab prior to copy
UIBotTestUtils.clickOnFileTab(remoteRobot, fileName);

// Save the current file content
UIBotTestUtils.copyWindowContent(remoteRobot);

// Delete the current file content
UIBotTestUtils.clearWindowContent(remoteRobot);

// Type the property key
keyboard.enterText(propertyKeySnippet);

// Trigger code completion
keyboard.hotKey(VK_CONTROL, VK_SPACE);

try {
// Check if the expected value appears in the top of the completion pop-up
Map<String, Integer> textPositions = ProjectFrameFixture.findAllTextPositions(remoteRobot);

// Verify each expected value's position
for (String expectedValue : expectedCompletionValues) {
Integer position = textPositions.get(expectedValue);
Assertions.assertNotNull(position,
"Text '" + expectedValue + "' did not appear in the completion suggestion pop-up window.");
Assertions.assertTrue(position >= 0 && position < maxPosition,
"Text '" + expectedValue + "' is at position " + position + " and is not in the top " + maxPosition + ".");
}
} finally {
// Replace the file content with the original content
UIBotTestUtils.pasteOnActiveWindow(remoteRobot);
}
}

/**
* Prepares the environment to run the tests.
*
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*******************************************************************************
* Copyright (c) 2023, 2024 IBM Corporation.
* Copyright (c) 2023, 2025 IBM Corporation.
*
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License v. 2.0 which is available at
@@ -12,6 +12,7 @@
import com.intellij.remoterobot.RemoteRobot;
import com.intellij.remoterobot.data.RemoteComponent;
anusreelakshmi934 marked this conversation as resolved.
Show resolved Hide resolved
import com.intellij.remoterobot.fixtures.*;
import com.intellij.remoterobot.fixtures.dataExtractor.RemoteText;
import com.intellij.remoterobot.search.locators.Locator;
import com.intellij.remoterobot.utils.RepeatUtilsKt;
import com.intellij.remoterobot.utils.WaitForConditionTimeoutException;
@@ -20,7 +21,9 @@
import org.jetbrains.annotations.NotNull;

import java.time.Duration;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import static com.intellij.remoterobot.search.locators.Locators.byXpath;

@@ -329,6 +332,26 @@ public ContainerFixture getLookupList() {
return find(ContainerFixture.class, byXpath("//div[@class='HeavyWeightWindow']//div[@class='LookupList']"), Duration.ofSeconds(10));
}

/**
* Retrieves a map of text and their positions from the completion suggestion pop-up in IntelliJ IDEA.
*
* @return a map where keys are suggestion texts and values are their positions.
*/

public static Map<String, Integer> findAllTextPositions(RemoteRobot remoteRobot) {

ProjectFrameFixture projectFrame = remoteRobot.find(ProjectFrameFixture.class, Duration.ofSeconds(10));
// Wait for the completion suggestion pop-up window to display the expected values
ComponentFixture completionPopupWindow = projectFrame.getLookupList();
List<RemoteText> allData = completionPopupWindow.getData().getAll();
Map<String, Integer> textPositionMap = new HashMap<>();
// Populate the map with text and their respective positions
for (int i = 0; i < allData.size(); i++) {
textPositionMap.put(allData.get(i).getText(), i);
}
return textPositionMap; // Return the map with all text positions
}

/**
* Returns the ContainerFixture object associated with the MyList class in a HeavyWeightWindow (List window).
*