-
Notifications
You must be signed in to change notification settings - Fork 92
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1996 from WindhoverLabs/split_dock_unit_test
Split dock unit test
- Loading branch information
Showing
3 changed files
with
258 additions
and
0 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
133 changes: 133 additions & 0 deletions
133
core/ui/src/test/java/org/phoebus/ui/docking/DockPaneTestUI.java
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 |
---|---|---|
@@ -0,0 +1,133 @@ | ||
package org.phoebus.ui.docking; | ||
|
||
import java.util.Set; | ||
|
||
import org.assertj.core.api.Assertions; | ||
import org.junit.Test; | ||
import org.phoebus.security.authorization.AuthorizationService; | ||
import org.phoebus.ui.application.Messages; | ||
import org.testfx.framework.junit.ApplicationTest; | ||
|
||
import javafx.collections.ObservableList; | ||
import javafx.scene.Node; | ||
import javafx.scene.control.Control; | ||
import javafx.scene.control.Label; | ||
import javafx.scene.control.Labeled; | ||
import javafx.scene.control.MenuItem; | ||
import javafx.scene.control.SeparatorMenuItem; | ||
import javafx.scene.layout.BorderPane; | ||
import javafx.scene.paint.Color; | ||
import javafx.scene.shape.Rectangle; | ||
import javafx.stage.Stage; | ||
|
||
public class DockPaneTestUI extends ApplicationTest { | ||
private DockPane tabs = null; | ||
|
||
/** | ||
* Will be called with {@code @Before} semantics, i. e. before each test method. | ||
*/ | ||
@Override | ||
public void start(Stage stage) | ||
{ | ||
|
||
// Add dock items to the original stage | ||
final DockItem tab1 = new DockItem("Tab 1"); | ||
final BorderPane layout = new BorderPane(); | ||
layout.setTop(new Label("Top")); | ||
layout.setCenter(new Label("Tab that indicates resize behavior")); | ||
layout.setBottom(new Label("Bottom")); | ||
tab1.setContent(layout); | ||
|
||
final DockItem tab2 = new DockItem("Tab 2"); | ||
tab2.setContent(new Rectangle(500, 500, Color.RED)); | ||
|
||
// The DockPane is added to a stage by 'configuring' it. | ||
// Initial tabs can be provided right away | ||
tabs = DockStage.configureStage(stage, tab1, tab2); | ||
|
||
stage.setX(0); | ||
stage.setY(0); | ||
stage.show(); | ||
|
||
} | ||
|
||
@Test | ||
public void TestNumberOfDockItems() | ||
{ | ||
Set<Node> menu = (Set<Node>) from(rootNode(Stage.getWindows().get(0))).queryAllAs(Node.class); | ||
|
||
Node rootPane = menu.iterator().next(); | ||
|
||
Assertions.assertThat(rootPane instanceof BorderPane).isTrue(); | ||
|
||
BorderPane pane = (BorderPane) rootPane; | ||
|
||
Assertions.assertThat(pane.centerProperty().get() instanceof DockPane).isTrue(); | ||
|
||
DockPane dockPane = (DockPane) pane.centerProperty().get(); | ||
|
||
Assertions.assertThat(dockPane.getDockItems().size() == 2).isTrue(); | ||
|
||
Assertions.assertThat(dockPane.getTabs().get(0) instanceof DockItem).isTrue(); | ||
Assertions.assertThat(dockPane.getTabs().get(1) instanceof DockItem).isTrue(); | ||
|
||
SplitDockTestUI.closePane(tabs, this); | ||
Assertions.assertThat((Stage.getWindows().size() == 0)).isTrue() ; | ||
} | ||
|
||
@Test | ||
public void TestContextMenu() | ||
{ | ||
SplitDockTestUI.invokeContextMenu(tabs, this, 0); | ||
Set<Node> menu = (Set<Node>) from(rootNode(Stage.getWindows().get(0))).queryAllAs(Node.class); | ||
|
||
Node rootPane = menu.iterator().next(); | ||
|
||
BorderPane pane = (BorderPane) rootPane; | ||
|
||
DockPane dockPane = (DockPane) pane.centerProperty().get(); | ||
|
||
DockItem firstTab = (DockItem) dockPane.getDockItems().get(0); | ||
|
||
Assertions.assertThat(((Control) firstTab.getGraphic()).getContextMenu() != null).isTrue(); | ||
|
||
ObservableList<MenuItem> menuItems = from((Node)firstTab.getGraphic()).queryAs(Labeled.class).getContextMenu().getItems(); | ||
|
||
Assertions.assertThat(menuItems.get(0).getText().equals(Messages.DockInfo)).isTrue(); | ||
|
||
Assertions.assertThat(menuItems.get(1) instanceof SeparatorMenuItem).isTrue(); | ||
|
||
Assertions.assertThat(menuItems.get(2).getText().equals(Messages.DockDetach)).isTrue(); | ||
Assertions.assertThat(menuItems.get(3).getText().equals(Messages.DockSplitH)).isTrue(); | ||
Assertions.assertThat(menuItems.get(4).getText().equals(Messages.DockSplitV)).isTrue(); | ||
|
||
Assertions.assertThat(menuItems.get(5) instanceof SeparatorMenuItem).isTrue(); | ||
|
||
boolean isLockable = AuthorizationService.hasAuthorization("lock_ui"); | ||
|
||
if(isLockable) | ||
{ | ||
Assertions.assertThat(menuItems.get(6).getText().equals(Messages.NamePaneHdr)).isTrue(); | ||
Assertions.assertThat(menuItems.get(7).getText().equals(Messages.LockPane)).isTrue(); | ||
Assertions.assertThat(menuItems.get(8).getText().equals(Messages.DockClose)).isTrue(); | ||
Assertions.assertThat(menuItems.get(9).getText().equals(Messages.DockCloseOthers)).isTrue(); | ||
|
||
Assertions.assertThat(menuItems.get(10) instanceof SeparatorMenuItem).isTrue(); | ||
|
||
Assertions.assertThat(menuItems.get(11).getText().equals(Messages.DockCloseAll)).isTrue(); | ||
} | ||
else | ||
{ | ||
Assertions.assertThat(menuItems.get(6).getText().equals(Messages.DockClose)).isTrue(); | ||
Assertions.assertThat(menuItems.get(7).getText().equals(Messages.DockCloseOthers)).isTrue(); | ||
|
||
Assertions.assertThat(menuItems.get(8) instanceof SeparatorMenuItem).isTrue(); | ||
|
||
Assertions.assertThat(menuItems.get(9).getText().equals(Messages.DockCloseAll)).isTrue(); | ||
} | ||
|
||
SplitDockTestUI.closePane(tabs, this); | ||
Assertions.assertThat((Stage.getWindows().size() == 0)).isTrue(); | ||
} | ||
|
||
} |
124 changes: 124 additions & 0 deletions
124
core/ui/src/test/java/org/phoebus/ui/docking/SplitDockTestUI.java
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 |
---|---|---|
@@ -0,0 +1,124 @@ | ||
package org.phoebus.ui.docking; | ||
import java.util.Iterator; | ||
import java.util.Set; | ||
|
||
import org.assertj.core.api.Assertions; | ||
import org.junit.Test; | ||
import org.testfx.api.FxRobot; | ||
import org.testfx.framework.junit.ApplicationTest; | ||
|
||
import javafx.geometry.Bounds; | ||
import javafx.geometry.Point2D; | ||
import javafx.scene.Node; | ||
import javafx.scene.control.Label; | ||
import javafx.scene.layout.BorderPane; | ||
import javafx.scene.paint.Color; | ||
import javafx.scene.shape.Rectangle; | ||
import javafx.stage.Stage; | ||
import javafx.scene.input.MouseButton; | ||
import javafx.scene.input.KeyCode; | ||
|
||
public class SplitDockTestUI extends ApplicationTest { | ||
private DockPane tabs = null; | ||
|
||
/** | ||
* Will be called with {@code @Before} semantics, i. e. before each test method. | ||
*/ | ||
@Override | ||
public void start(Stage stage) | ||
{ | ||
|
||
// Add dock items to the original stage | ||
final DockItem tab1 = new DockItem("Tab 1"); | ||
final BorderPane layout = new BorderPane(); | ||
layout.setTop(new Label("Top")); | ||
layout.setCenter(new Label("Tab that indicates resize behavior")); | ||
layout.setBottom(new Label("Bottom")); | ||
tab1.setContent(layout); | ||
|
||
final DockItem tab2 = new DockItem("Tab 2"); | ||
tab2.setContent(new Rectangle(500, 500, Color.RED)); | ||
|
||
// The DockPane is added to a stage by 'configuring' it. | ||
// Initial tabs can be provided right away | ||
tabs = DockStage.configureStage(stage, tab1, tab2); | ||
|
||
stage.setX(0); | ||
stage.setY(0); | ||
stage.show(); | ||
} | ||
|
||
private void closePane() | ||
{ | ||
interact(()->{try { | ||
DockStage.prepareToCloseItems((Stage) tabs.getScene().getWindow()); | ||
DockStage.closeItems((Stage) tabs.getScene().getWindow()); | ||
} catch (Exception e) { | ||
// TODO Auto-generated catch block | ||
e.printStackTrace(); | ||
}}); | ||
} | ||
|
||
static void invokeContextMenu(DockPane pane, FxRobot robot, int tab) | ||
{ | ||
Object[] renderedTabs = pane.lookup(".tab-header-area").lookupAll(".tab").toArray(); | ||
Node renderedTab = (Node)renderedTabs[tab]; | ||
|
||
//Invoke the context menu on the tab | ||
Bounds tabBounds = renderedTab.getBoundsInLocal(); | ||
|
||
robot.moveTo(new Point2D(renderedTab.localToScene(tabBounds).getCenterX() , | ||
renderedTab.localToScene(tabBounds).getCenterY() )); | ||
robot.press(MouseButton.SECONDARY); | ||
} | ||
|
||
static void closePane(DockPane pane, FxRobot robot) | ||
{ | ||
robot.interact(()->{try { | ||
DockStage.prepareToCloseItems((Stage) pane.getScene().getWindow()); | ||
DockStage.closeItems((Stage) pane.getScene().getWindow()); | ||
} catch (Exception e) { | ||
// TODO Auto-generated catch block | ||
e.printStackTrace(); | ||
}}); | ||
} | ||
|
||
@Test | ||
public void TestNumberOfDockItems() | ||
{ | ||
Set<Node> menu = (Set<Node>) from(rootNode(Stage.getWindows().get(0))).queryAllAs(Node.class); | ||
|
||
Node rootPane = menu.iterator().next(); | ||
|
||
Assertions.assertThat(rootPane instanceof BorderPane).isTrue(); | ||
|
||
BorderPane pane = (BorderPane) rootPane; | ||
|
||
Assertions.assertThat(pane.centerProperty().get() instanceof DockPane).isTrue(); | ||
|
||
DockPane dockPane = (DockPane) pane.centerProperty().get(); | ||
|
||
Assertions.assertThat(dockPane.getDockItems().size() == 2).isTrue(); | ||
|
||
Assertions.assertThat(dockPane.getTabs().get(0) instanceof DockItem).isTrue(); | ||
Assertions.assertThat(dockPane.getTabs().get(1) instanceof DockItem).isTrue(); | ||
|
||
closePane(); | ||
Assertions.assertThat((Stage.getWindows().size() == 0)).isTrue(); | ||
} | ||
|
||
@Test | ||
public void TestDockSplit() throws Exception { | ||
invokeContextMenu(tabs, this, 0); | ||
|
||
// Select Split Option on ContextMenu | ||
press(KeyCode.DOWN); | ||
release(KeyCode.DOWN); | ||
press(KeyCode.DOWN); | ||
release(KeyCode.DOWN); | ||
press(KeyCode.ENTER); | ||
|
||
closePane(); | ||
Assertions.assertThat((Stage.getWindows().size() == 0)).isTrue(); | ||
} | ||
} |