forked from redhat-developer/intellij-kubernetes
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Reworked/refactored EditResourceTest
Signed-off-by: Oleksii Korniienko <[email protected]>
- Loading branch information
Showing
1 changed file
with
19 additions
and
21 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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 | ||
|
@@ -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; | ||
} | ||
|
@@ -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 | ||
} | ||
} |