Skip to content

Commit

Permalink
Merge pull request #1205 from anusreelakshmi934/UITest-Issue852
Browse files Browse the repository at this point in the history
UI test to check for relevant completion options in bootstrap.properties and server.env
  • Loading branch information
anusreelakshmi934 authored Jan 13, 2025
2 parents 598b2b8 + 526dad5 commit 672fbcb
Show file tree
Hide file tree
Showing 2 changed files with 93 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,17 @@
import com.automation.remarks.junit5.Video;
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;

Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
* @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.
*
Expand Down
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
Expand All @@ -12,6 +12,7 @@
import com.intellij.remoterobot.RemoteRobot;
import com.intellij.remoterobot.data.RemoteComponent;
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;
Expand All @@ -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;

Expand Down Expand Up @@ -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).
*
Expand Down

0 comments on commit 672fbcb

Please sign in to comment.