From aaf172aa2c4df6d56ed8ff16f55543a902c72174 Mon Sep 17 00:00:00 2001 From: Oleksii Korniienko Date: Thu, 9 May 2024 15:11:36 +0200 Subject: [PATCH] Reworked/refactored EditResourceTest Signed-off-by: Oleksii Korniienko --- .../kubernetes/tests/EditResourceTest.java | 40 +++++++++---------- 1 file changed, 19 insertions(+), 21 deletions(-) diff --git a/src/it/java/org/jboss/tools/intellij/kubernetes/tests/EditResourceTest.java b/src/it/java/org/jboss/tools/intellij/kubernetes/tests/EditResourceTest.java index 47624b95d..baa1f1a63 100644 --- a/src/it/java/org/jboss/tools/intellij/kubernetes/tests/EditResourceTest.java +++ b/src/it/java/org/jboss/tools/intellij/kubernetes/tests/EditResourceTest.java @@ -17,10 +17,8 @@ import org.jboss.tools.intellij.kubernetes.fixtures.mainIdeWindow.EditorsSplittersFixture; import org.jboss.tools.intellij.kubernetes.fixtures.menus.ActionToolbarMenu; -import java.awt.event.KeyEvent; import java.util.List; -import static com.intellij.remoterobot.search.locators.Locators.byXpath; import static org.junit.jupiter.api.Assertions.assertTrue; /** @@ -28,6 +26,9 @@ */ public class EditResourceTest extends AbstractKubernetesTest{ public static void editResource(RemoteRobot robot, ComponentFixture kubernetesViewTree){ + String yodaLabel = "yoda_label"; + String yodaText = "yoda_text"; + openResourceContentList(new String[]{"Nodes"}, kubernetesViewTree); RemoteText selectedResource = getResourceByIdInParent("Nodes", 0, kubernetesViewTree); selectedResource.doubleClick(); @@ -35,19 +36,10 @@ public static void editResource(RemoteRobot robot, ComponentFixture kubernetesVi EditorsSplittersFixture editorSplitter = robot.find(EditorsSplittersFixture.class); String editorTitle = selectedResource.getText(); - ComponentFixture textFixture = editorSplitter.getEditorTextFixture(); - List remote_text = textFixture.findAllText(); - int labelsId = 0; - for (RemoteText actual_remote_text : remote_text){ - if ("labels".equals(actual_remote_text.getText())){ - break; - } - labelsId++; - } - RemoteText placeForNewLabel = remote_text.get(labelsId+2); // +1 because we need the next one, +1 because between every 2 real elements is space + RemoteText placeForNewLabel = getPlaceForNewLabel(editorSplitter); placeForNewLabel.click(); - String text = " yoda_label: \"yoda_text"; + String text = " " + yodaLabel +": \"" + yodaText; Keyboard my_keyboard = new Keyboard(robot); my_keyboard.enter(); // create empty line @@ -64,11 +56,11 @@ public static void editResource(RemoteRobot robot, ComponentFixture kubernetesVi selectedResource.doubleClick(); ComponentFixture textFixtureNew = editorSplitter.getEditorTextFixture(); - scrollToVisible("yoda_label", robot); + scrollToVisible(yodaLabel, robot); List remoteTextNew = textFixtureNew.findAllText(); boolean labelExist = false; for (RemoteText actual_remote_text : remoteTextNew){ - if (actual_remote_text.getText().contains("yoda_text")){ + if (actual_remote_text.getText().contains(yodaText)){ labelExist = true; break; } @@ -77,13 +69,19 @@ public static void editResource(RemoteRobot robot, ComponentFixture kubernetesVi editorSplitter.closeEditor(editorTitle); // close editor hideClusterContent(kubernetesViewTree); - assertTrue(labelExist); + assertTrue(labelExist, "Label '" + yodaLabel + "' not found."); } - private static void scrollToVisible(String text, RemoteRobot robot) { - Keyboard myKeyboard = new Keyboard(robot); - myKeyboard.hotKey(KeyEvent.VK_CONTROL, KeyEvent.VK_F); - robot.find(ComponentFixture.class, byXpath("//div[@class='SearchTextArea']")).click(); - myKeyboard.enterText(text); + private static RemoteText getPlaceForNewLabel (EditorsSplittersFixture editorSplitter) { + ComponentFixture textFixture = editorSplitter.getEditorTextFixture(); + List remote_text = textFixture.findAllText(); + int labelsId = 0; + for (RemoteText actual_remote_text : remote_text){ + if ("labels".equals(actual_remote_text.getText())){ + break; + } + labelsId++; + } + return remote_text.get(labelsId+2); // +1 because we need the next one, +1 because between every 2 real elements is space } }