package de.bmoth.app;

import javafx.fxml.FXMLLoader;
import javafx.scene.Node;
import javafx.scene.Parent;
import javafx.scene.Scene;
import javafx.stage.Stage;
import org.junit.Test;

import static org.testfx.api.FxAssert.verifyThat;
import static org.testfx.matcher.base.NodeMatchers.*;

public class AppControllerTest extends HeadlessUITest {

    @Override
    public void start(Stage stage) throws Exception {
        FXMLLoader loader = new FXMLLoader(getClass().getResource("app.fxml"));
        Parent root = loader.load();
        Scene scene = new Scene(root, 500, 300);
        AppController appController = loader.getController();
        appController.setupStage(stage);
        stage.setScene(scene);
        stage.show();
    }

    @Test
    public void clickingOptionsOpensDialog() {
        clickOn("#fileMenu");
        clickOn("#options");

        verifyThat("#minInt", isNotNull());
        clickOn("Close");
        verifyThat("#minInt", isNull());
    }

    @Test
    public void checkChangesDetected() {
        clickOn("#codeArea").write(" ");
        verifyThat("#infoArea", hasText("Unsaved changes"));
    }

    @Test
    public void clickingReplOpensRepl() throws InterruptedException {
        verifyThat("#replText", isNull());

        clickOn("#replMenu").clickOn("#openRepl");

        verifyThat("#replText", isNotNull());

        // close the repl window so that later tests are not confused
        Node repl = lookup("REPL").query();
        Stage scene = (Stage) repl.getScene().getWindow();
        interact(() -> scene.close());
    }
}

@@ -1125,32 +1125,523 @@
 nges%22));%0A    %7D%0A%0A
+    @Test%0A    public void opensUnsavedChangesWarning() %7B%0A        clickOn(%22#codeArea%22).write(%22 %22);%0A        clickOn(%22#fileMenu%22).clickOn(%22Exit%22);%0A        // the warning dialog opens, codeArea stays open%0A        verifyThat(%22Back%22, isNotNull());%0A        verifyThat(%22#codeArea%22, isNotNull());%0A%0A        // click the back button%0A        clickOn(%22Back%22);%0A        // dialog closes, were back to the code area%0A        verifyThat(%22Back%22, isNull());%0A        verifyThat(%22#codeArea%22, isNotNull());%0A    %7D%0A%0A
     @Test%0A    pu

increase code coverage