Skip to content

Commit

Permalink
Fix focus handling by clicking - (Task #136)
Browse files Browse the repository at this point in the history
  • Loading branch information
franzTobiasDLR committed Oct 7, 2020
1 parent 5b09018 commit b6244c0
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,13 @@
*******************************************************************************/
package de.dlr.sc.virsat.cef.swtbot.test;

import static org.eclipse.swtbot.eclipse.finder.matchers.WidgetMatcherFactory.withPartName;

import org.eclipse.swtbot.eclipse.finder.waits.Conditions;
import org.eclipse.swtbot.swt.finder.widgets.SWTBotTreeItem;
import org.eclipse.ui.IEditorReference;
import org.hamcrest.Matcher;
import org.hamcrest.core.StringStartsWith;
import org.junit.Before;

import de.dlr.sc.virsat.concept.unittest.util.ConceptXmiLoader;
Expand Down Expand Up @@ -53,5 +60,19 @@ protected void openCefXPerspective() {
bot.button("Open").click();
waitForEditingDomainAndUiThread();
}

@Override
protected void waitForEditor(SWTBotTreeItem item) {
String label = item.getText();
if (label.contains("( x")) {
// tree node contains quantity... ignore it
label = label.substring(0, label.indexOf("(") - 1);
} else if (label.contains("<<")) {
// tree node contains inheritance type... ignore it
label = label.substring(0, label.indexOf("<") - 1);
}
Matcher<IEditorReference> matcher = withPartName(StringStartsWith.startsWith(label + " -> "));
bot.waitUntil(Conditions.waitForEditor(matcher));
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,11 @@
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertTrue;

import java.io.IOException;

import org.eclipse.core.runtime.CoreException;
import org.eclipse.swtbot.swt.finder.widgets.SWTBotTreeItem;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;

Expand All @@ -34,13 +38,22 @@ public void before() throws Exception {

}

@After
public void tearDown() throws CoreException, IOException {
super.tearDown();
systemItem = null;
subSystemItem = null;
equipmentItem = null;
}

@Test
public void testUseStudyTemplate() {

repositoryNavigatorItem.click();
bot.menu("Templates").menu("Create New DLR/CEF Study").click();

final int STUDY_REPOSITORY_ITEM_COUNT = 2; // apps + system
repositoryNavigatorItem.expand();
assertEquals(STUDY_REPOSITORY_ITEM_COUNT, repositoryNavigatorItem.getItems().length);

systemItem = repositoryNavigatorItem.getNode("Sys: System");
Expand All @@ -58,6 +71,7 @@ public void testUseStudyTemplate() {
final int STUDY_SUB_SYSTEM_ITEM_COUNT = 4; // documents + equipment + subsystem mass parameters + subsystem power parameters
assertEquals(STUDY_SUB_SYSTEM_ITEM_COUNT, subSystemItem.getItems().length);

subSystemItem.click();
equipmentItem = subSystemItem.getNode("Eqp: equipment ( x 1)");
assertNotNull(equipmentItem);

Expand All @@ -72,6 +86,7 @@ public void testUseSubSystemTemplate() {
//Prepare project
repositoryNavigatorItem.click();
bot.menu("Templates").menu("Create New DLR/CEF Study").click();
repositoryNavigatorItem.click();
systemItem = repositoryNavigatorItem.getNode("Sys: System");
systemItem.expand();
subSystemItem = systemItem.getNode("SubSys: subSystem");
Expand All @@ -81,8 +96,9 @@ public void testUseSubSystemTemplate() {

systemItem.click();
bot.menu("Templates").menu("Create New DLR/CEF SubSystem").click();

systemItem.expand();
assertTrue("One more element in tree", systemItem.getItems().length > PREVIOUS_SYTEM_ITEM_COUNT);
systemItem.click();
SWTBotTreeItem newSubSystem = systemItem.getNode("SubSys: subSystem");
assertNotNull(newSubSystem);
assertNotEquals("New subsystem is not the initially exisitng one", subSystemItem, newSubSystem);
Expand All @@ -95,19 +111,23 @@ public void testUseEquipmentTemplate() {
//Prepare project
repositoryNavigatorItem.click();
bot.menu("Templates").menu("Create New DLR/CEF Study").click();
repositoryNavigatorItem.click();
systemItem = repositoryNavigatorItem.getNode("Sys: System");
systemItem.expand();
subSystemItem = systemItem.getNode("SubSys: subSystem");
subSystemItem.expand();
subSystemItem.click();
equipmentItem = subSystemItem.getNode("Eqp: equipment ( x 1)");
rename(equipmentItem, "InitialEquipment");

final int PREVIOUS_SUB_SYSTEM_ITEM_COUNT = subSystemItem.getItems().length;

subSystemItem.click();
bot.menu("Templates").menu("Create New DLR/CEF Equipment").click();
subSystemItem.expand();

assertTrue("One more element in tree", subSystemItem.getItems().length > PREVIOUS_SUB_SYSTEM_ITEM_COUNT);
subSystemItem.click();
SWTBotTreeItem newEquipment = subSystemItem.getNode("Eqp: equipment ( x 1)");
assertNotNull(newEquipment);
assertNotEquals("New subsystem is not the initially exisitng one", equipmentItem, newEquipment);
Expand Down

0 comments on commit b6244c0

Please sign in to comment.