|
1 | 1 | package edu.wpi.grip.ui;
|
2 | 2 |
|
3 | 3 |
|
4 |
| -import edu.wpi.grip.core.AdditionOperation; |
5 |
| -import edu.wpi.grip.core.PipelineRunner; |
| 4 | +import com.google.common.eventbus.EventBus; |
| 5 | +import com.google.inject.Guice; |
| 6 | +import com.google.inject.Injector; |
| 7 | +import com.google.inject.util.Modules; |
| 8 | +import edu.wpi.grip.core.*; |
6 | 9 | import edu.wpi.grip.core.events.OperationAddedEvent;
|
| 10 | +import edu.wpi.grip.ui.util.DPIUtility; |
| 11 | +import edu.wpi.grip.ui.util.StyleClassNameUtility; |
| 12 | +import edu.wpi.grip.util.GRIPCoreTestModule; |
| 13 | +import javafx.fxml.FXMLLoader; |
| 14 | +import javafx.scene.Parent; |
| 15 | +import javafx.scene.Scene; |
7 | 16 | import javafx.stage.Stage;
|
8 | 17 | import org.junit.After;
|
9 |
| -import org.junit.Ignore; |
10 | 18 | import org.junit.Test;
|
11 | 19 | import org.testfx.framework.junit.ApplicationTest;
|
12 | 20 | import org.testfx.matcher.base.NodeMatchers;
|
13 | 21 | import org.testfx.util.WaitForAsyncUtils;
|
14 | 22 |
|
| 23 | +import static org.junit.Assert.assertEquals; |
15 | 24 | import static org.testfx.api.FxAssert.verifyThat;
|
16 | 25 |
|
17 |
| - |
| 26 | +@SuppressWarnings("PMD.JUnitTestsShouldIncludeAssert") |
18 | 27 | public class MainWindowTest extends ApplicationTest {
|
19 |
| - |
| 28 | + private static final String STEP_NOT_ADDED_MSG = "Step was not added to pipeline"; |
| 29 | + private final GRIPCoreTestModule testModule = new GRIPCoreTestModule(); |
| 30 | + private Pipeline pipeline; |
20 | 31 | private PipelineRunner pipelineRunner;
|
| 32 | + private Operation addOperation; |
| 33 | + private AdditionOperation additionOperation; |
21 | 34 |
|
22 | 35 | @Override
|
23 | 36 | @SuppressWarnings("PMD.SignatureDeclareThrowsException")
|
24 | 37 | public void start(Stage stage) throws Exception {
|
25 |
| - final Main main = new Main(); |
26 |
| - main.start(stage); |
| 38 | + testModule.setUp(); |
| 39 | + |
| 40 | + Injector injector = Guice.createInjector(Modules.override(testModule).with(new GRIPUIModule())); |
| 41 | + |
| 42 | + final Parent root = |
| 43 | + FXMLLoader.load(Main.class.getResource("MainWindow.fxml"), null, null, injector::getInstance); |
| 44 | + root.setStyle("-fx-font-size: " + DPIUtility.FONT_SIZE + "px"); |
| 45 | + |
| 46 | + pipeline = injector.getInstance(Pipeline.class); |
| 47 | + pipelineRunner = injector.getInstance(PipelineRunner.class); |
| 48 | + final EventBus eventBus = injector.getInstance(EventBus.class); |
27 | 49 |
|
28 |
| - final OperationListController operationList = main.injector.getInstance(OperationListController.class); |
29 |
| - pipelineRunner = main.injector.getInstance(PipelineRunner.class); |
30 |
| - operationList.clearOperations(); |
31 |
| - operationList.onOperationAdded(new OperationAddedEvent(new AdditionOperation())); |
| 50 | + addOperation = new AddOperation(); |
| 51 | + additionOperation = new AdditionOperation(); |
| 52 | + |
| 53 | + eventBus.post(new OperationAddedEvent(addOperation)); |
| 54 | + eventBus.post(new OperationAddedEvent(additionOperation)); |
| 55 | + |
| 56 | + stage.setScene(new Scene(root)); |
| 57 | + stage.show(); |
32 | 58 | }
|
33 | 59 |
|
34 | 60 | @After
|
35 | 61 | public void tearDown() {
|
| 62 | + testModule.tearDown(); |
36 | 63 | pipelineRunner.stopAsync().awaitTerminated();
|
37 | 64 | }
|
38 | 65 |
|
39 | 66 | @Test
|
40 |
| - @Ignore |
41 |
| - @SuppressWarnings("PMD.JUnitTestsShouldIncludeAssert") |
42 | 67 | public void testShouldCreateNewOperationInPipelineView() {
|
43 | 68 | // Given:
|
44 |
| - clickOn("#add-operation"); |
| 69 | + clickOn(addOperation.getName()); |
| 70 | + |
| 71 | + WaitForAsyncUtils.waitForFxEvents(); |
| 72 | + |
| 73 | + // Then: |
| 74 | + final String cssSelector = "." + StyleClassNameUtility.classNameForStepHolding(addOperation); |
| 75 | + verifyThat(cssSelector, NodeMatchers.isNotNull()); |
| 76 | + verifyThat(cssSelector, NodeMatchers.isVisible()); |
| 77 | + |
| 78 | + assertEquals(STEP_NOT_ADDED_MSG, 1, pipeline.getSteps().size()); |
| 79 | + assertEquals("Step added was not this addOperation", addOperation, pipeline.getSteps().get(0).getOperation()); |
| 80 | + } |
| 81 | + |
| 82 | + @Test |
| 83 | + public void testDragOperationFromPaletteToPipeline() { |
| 84 | + // Given: |
| 85 | + drag(addOperation.getName()) |
| 86 | + .dropTo(".steps"); |
45 | 87 |
|
46 | 88 | WaitForAsyncUtils.waitForFxEvents();
|
47 | 89 |
|
48 | 90 | // Then:
|
49 |
| - verifyThat(".pipeline", NodeMatchers.hasChild(".add-step")); |
| 91 | + final String cssSelector = "." + StyleClassNameUtility.classNameForStepHolding(addOperation); |
| 92 | + verifyThat(cssSelector, NodeMatchers.isNotNull()); |
| 93 | + verifyThat(cssSelector, NodeMatchers.isVisible()); |
| 94 | + |
| 95 | + assertEquals(STEP_NOT_ADDED_MSG, 1, pipeline.getSteps().size()); |
| 96 | + assertEquals("Step added was not this addOperation", addOperation, pipeline.getSteps().get(0).getOperation()); |
| 97 | + } |
| 98 | + |
| 99 | + @Test |
| 100 | + public void testDragOperationFromPaletteToLeftOfExistingStep() { |
| 101 | + // Run the same test as before |
| 102 | + testDragOperationFromPaletteToPipeline(); |
| 103 | + |
| 104 | + // Now add a second step before it |
| 105 | + drag(additionOperation.getName()) |
| 106 | + // We drag to the input socket hint handle because this will always be on the left side of the |
| 107 | + // step. This should cause the UI to put the new step on the left side |
| 108 | + .dropTo(StyleClassNameUtility.cssSelectorForInputSocketHandleOnStepHolding(addOperation)); |
| 109 | + |
| 110 | + WaitForAsyncUtils.waitForFxEvents(); |
| 111 | + |
| 112 | + // Then: |
| 113 | + final String cssSelector = "." + StyleClassNameUtility.classNameForStepHolding(additionOperation); |
| 114 | + verifyThat(cssSelector, NodeMatchers.isNotNull()); |
| 115 | + verifyThat(cssSelector, NodeMatchers.isVisible()); |
| 116 | + |
| 117 | + assertEquals(STEP_NOT_ADDED_MSG, 2, pipeline.getSteps().size()); |
| 118 | + assertEquals("Step added was not added in the right place in the pipeline", |
| 119 | + additionOperation, pipeline.getSteps().get(0).getOperation()); |
| 120 | + } |
| 121 | + |
| 122 | + @Test |
| 123 | + public void testDragOperationFromPaletteToRightOfExistingStep() { |
| 124 | + // Run the same test as before |
| 125 | + testDragOperationFromPaletteToPipeline(); |
| 126 | + |
| 127 | + // Now add a second step after it |
| 128 | + drag(additionOperation.getName()) |
| 129 | + // We drag to the output socket hint handle because this will always be on the right side of the |
| 130 | + // step. This should cause the UI to put the new step on the right side |
| 131 | + .dropTo(StyleClassNameUtility.cssSelectorForOutputSocketHandleOnStepHolding(addOperation)); |
| 132 | + |
| 133 | + WaitForAsyncUtils.waitForFxEvents(); |
| 134 | + |
| 135 | + // Then: |
| 136 | + final String cssSelector = "." + StyleClassNameUtility.classNameForStepHolding(additionOperation); |
| 137 | + verifyThat(cssSelector, NodeMatchers.isNotNull()); |
| 138 | + verifyThat(cssSelector, NodeMatchers.isVisible()); |
| 139 | + |
| 140 | + assertEquals(STEP_NOT_ADDED_MSG, 2, pipeline.getSteps().size()); |
| 141 | + assertEquals("Step added was not added in the right place in the pipeline", |
| 142 | + additionOperation, pipeline.getSteps().get(1).getOperation()); |
50 | 143 | }
|
51 | 144 |
|
52 | 145 |
|
|
0 commit comments