Skip to content

Commit

Permalink
Reworked/refactored EditResourceTest
Browse files Browse the repository at this point in the history
Signed-off-by: Oleksii Korniienko <[email protected]>
  • Loading branch information
olkornii committed May 9, 2024
1 parent 9e335a9 commit aaf172a
Showing 1 changed file with 19 additions and 21 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -17,37 +17,29 @@
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;

/**
* @author [email protected]
*/
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();

EditorsSplittersFixture editorSplitter = robot.find(EditorsSplittersFixture.class);
String editorTitle = selectedResource.getText();

ComponentFixture textFixture = editorSplitter.getEditorTextFixture();
List<RemoteText> 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
Expand All @@ -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<RemoteText> 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;
}
Expand All @@ -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<RemoteText> 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
}
}

0 comments on commit aaf172a

Please sign in to comment.