|
| 1 | +package org.fxmisc.richtext; |
| 2 | + |
| 3 | +import javafx.geometry.Pos; |
| 4 | +import javafx.scene.Scene; |
| 5 | +import javafx.scene.control.ContextMenu; |
| 6 | +import javafx.scene.control.MenuItem; |
| 7 | +import javafx.scene.input.MouseButton; |
| 8 | +import javafx.stage.Stage; |
| 9 | +import org.testfx.api.FxRobotInterface; |
| 10 | +import org.testfx.framework.junit.ApplicationTest; |
| 11 | +import org.testfx.service.query.PointQuery; |
| 12 | + |
| 13 | +import static org.junit.Assume.assumeTrue; |
| 14 | + |
| 15 | +/** |
| 16 | + * TestFX tests should subclass this if it needs to run tests on a simple area. Any view-related API needs to be |
| 17 | + * wrapped in a {@link #interact(Runnable)} call, but model API does not need to be wrapped in it. |
| 18 | + */ |
| 19 | +public class InlineCssTextAreaAppTest extends ApplicationTest { |
| 20 | + |
| 21 | + static { |
| 22 | + String osName = System.getProperty("os.name").toLowerCase(); |
| 23 | + |
| 24 | + isWindows = osName.startsWith("win"); |
| 25 | + isMac = osName.startsWith("mac"); |
| 26 | + isLinux = osName.startsWith("linux"); |
| 27 | + } |
| 28 | + |
| 29 | + public static final boolean isWindows; |
| 30 | + public static final boolean isMac; |
| 31 | + public static final boolean isLinux; |
| 32 | + |
| 33 | + public Stage stage; |
| 34 | + public Scene scene; |
| 35 | + public InlineCssTextArea area; |
| 36 | + public ContextMenu menu; |
| 37 | + |
| 38 | + @Override |
| 39 | + public void start(Stage stage) throws Exception { |
| 40 | + area = new InlineCssTextArea(); |
| 41 | + scene = new Scene(area); |
| 42 | + this.stage = stage; |
| 43 | + |
| 44 | + stage.setScene(scene); |
| 45 | + stage.setWidth(400); |
| 46 | + stage.setHeight(400); |
| 47 | + stage.show(); |
| 48 | + |
| 49 | + menu = new ContextMenu(new MenuItem("A menu item")); |
| 50 | + area.setContextMenu(menu); |
| 51 | + // offset needs to be 5+ to prevent test failures |
| 52 | + area.setContextMenuXOffset(30); |
| 53 | + area.setContextMenuYOffset(30); |
| 54 | + |
| 55 | + // so tests don't need to do this themselves |
| 56 | + area.requestFocus(); |
| 57 | + } |
| 58 | + |
| 59 | + public final PointQuery firstLineOfArea() { |
| 60 | + return point(area).atPosition(Pos.TOP_LEFT).atOffset(5, 5); |
| 61 | + } |
| 62 | + |
| 63 | + public final FxRobotInterface clickOnFirstLine(MouseButton... buttons) { |
| 64 | + return moveTo(firstLineOfArea()).clickOn(buttons); |
| 65 | + } |
| 66 | + |
| 67 | + public final FxRobotInterface leftClickOnFirstLine() { |
| 68 | + return clickOnFirstLine(MouseButton.PRIMARY); |
| 69 | + } |
| 70 | + |
| 71 | + public final FxRobotInterface doubleClickOnFirstLine() { |
| 72 | + return leftClickOnFirstLine().clickOn(MouseButton.PRIMARY); |
| 73 | + } |
| 74 | + |
| 75 | + public final FxRobotInterface tripleClickOnFirstLine() { |
| 76 | + return doubleClickOnFirstLine().clickOn(MouseButton.PRIMARY); |
| 77 | + } |
| 78 | + |
| 79 | + public final FxRobotInterface rightClickOnFirstLine() { |
| 80 | + return clickOnFirstLine(MouseButton.SECONDARY); |
| 81 | + } |
| 82 | + |
| 83 | + /** |
| 84 | + * If not on Windows environment, calling this in @Before method will skip the entire test suite whereas calling |
| 85 | + * this in @Test will skip just that test method |
| 86 | + */ |
| 87 | + public final void run_only_on_windows() { |
| 88 | + assumeTrue(isWindows); |
| 89 | + } |
| 90 | + |
| 91 | + /** |
| 92 | + * If not on Linux environment, calling this in @Before method will skip the entire test suite whereas calling |
| 93 | + * this in @Test will skip just that test method |
| 94 | + */ |
| 95 | + public final void run_only_on_linux() { |
| 96 | + assumeTrue(isLinux); |
| 97 | + } |
| 98 | + |
| 99 | + /** |
| 100 | + * If not on Mac environment, calling this in @Before method will skip the entire test suite whereas calling |
| 101 | + * this in @Test will skip just that test method |
| 102 | + */ |
| 103 | + public final void run_only_on_mac() { |
| 104 | + assumeTrue(isMac); |
| 105 | + } |
| 106 | + |
| 107 | + /** |
| 108 | + * If on Windows environment, calling this in @Before method will skip the entire test suite whereas calling |
| 109 | + * this in @Test will skip just that test method |
| 110 | + */ |
| 111 | + public final void skip_if_on_windows() { |
| 112 | + assumeTrue(!isWindows); |
| 113 | + } |
| 114 | + |
| 115 | + /** |
| 116 | + * If on Linux environment, calling this in @Before method will skip the entire test suite whereas calling |
| 117 | + * this in @Test will skip just that test method |
| 118 | + */ |
| 119 | + public final void skip_if_on_linux() { |
| 120 | + assumeTrue(!isLinux); |
| 121 | + } |
| 122 | + |
| 123 | + /** |
| 124 | + * If on Mac environment, calling this in @Before method will skip the entire test suite whereas calling |
| 125 | + * this in @Test will skip just that test method |
| 126 | + */ |
| 127 | + public final void skip_if_on_mac() { |
| 128 | + assumeTrue(!isMac); |
| 129 | + } |
| 130 | +} |
0 commit comments