// Path: src/test/java/jigspuzzle/cucumber/RunCucumber.java
// @RunWith(Cucumber.class)
// @CucumberOptions(
//         features = "../src/test/java/jigspuzzle/cucumber/features",
//         glue = "jigspuzzle.cucumber.steps",
//         //tags = {"@test"}, // <- activate this if only scenarios with tag '@test' should be executed.
//         plugin = {"pretty", "html:../target/cucumber-html-report"}
// )
// public class RunCucumber {
// 
//     /**
//      * The timeout that is used, whn searching in a ui-element for an element to
//      * change. Thgis can e.g. be, when is will become visible or change its text
//      * because of the user input.
//      *
//      * The timeout is a valu in miliseconds.
//      */
//     public static final int TIMEOUT_UI_UPDATED = 15000;
// }


import cucumber.api.PendingException;
import cucumber.api.java.en.*;
import java.util.regex.Pattern;
import jigspuzzle.cucumber.RunCucumber;
import org.assertj.swing.core.matcher.JLabelMatcher;
import org.assertj.swing.edt.GuiActionRunner;
import org.assertj.swing.exception.ComponentLookupException;
import org.assertj.swing.fixture.DialogFixture;
import org.assertj.swing.fixture.FrameFixture;
import org.assertj.swing.timing.Condition;
import org.assertj.swing.timing.Pause;
import org.assertj.swing.timing.Timeout;
package jigspuzzle.cucumber.steps;


/**
 * Step definitions for the input with versions.
 *
 * @author RoseTec
 */
public class VersionSteps {

    private final WindowsSteps windowsSteps;

    public VersionSteps(WindowsSteps windowsSteps) {
        this.windowsSteps = windowsSteps;
    }

    // controlling versions
    @Given("^a newer version is available on the internet$")
    public void new_version_avalable() {
        throw new PendingException();
    }

    @Given("^no newer version is available on the internet$")
    public void no_new_version_avalable() {
        // do nothing here, since the one in development is always newer then the released one
        //todo: find out how to do it right
    }
    // -- controlling versions end

    // viewing version results
    @Then("^I should see, that a newer version is available$")
    public void see_new_version_avalable() {
        get_version_window().label("this-version-number").requireText(Pattern.compile("[0-9]+(\\.[0-9]+)*(-SNAPSHOT)?"));
        Pause.pause(new Condition("notify-this-is-newest-version should be visible") {
            @Override
            public boolean test() {
                return GuiActionRunner.execute(get_version_window().button("navigate-to-new-version")::isEnabled);
            }
// Path: src/test/java/jigspuzzle/cucumber/RunCucumber.java
// @RunWith(Cucumber.class)
// @CucumberOptions(
//         features = "../src/test/java/jigspuzzle/cucumber/features",
//         glue = "jigspuzzle.cucumber.steps",
//         //tags = {"@test"}, // <- activate this if only scenarios with tag '@test' should be executed.
//         plugin = {"pretty", "html:../target/cucumber-html-report"}
// )
// public class RunCucumber {
// 
//     /**
//      * The timeout that is used, whn searching in a ui-element for an element to
//      * change. Thgis can e.g. be, when is will become visible or change its text
//      * because of the user input.
//      *
//      * The timeout is a valu in miliseconds.
//      */
//     public static final int TIMEOUT_UI_UPDATED = 15000;
// }


// Path: src/test/java/jigspuzzle/cucumber/steps/VersionSteps.java
import cucumber.api.PendingException;
import cucumber.api.java.en.*;
import java.util.regex.Pattern;
import jigspuzzle.cucumber.RunCucumber;
import org.assertj.swing.core.matcher.JLabelMatcher;
import org.assertj.swing.edt.GuiActionRunner;
import org.assertj.swing.exception.ComponentLookupException;
import org.assertj.swing.fixture.DialogFixture;
import org.assertj.swing.fixture.FrameFixture;
import org.assertj.swing.timing.Condition;
import org.assertj.swing.timing.Pause;
import org.assertj.swing.timing.Timeout;

package jigspuzzle.cucumber.steps;


/**
 * Step definitions for the input with versions.
 *
 * @author RoseTec
 */
public class VersionSteps {

    private final WindowsSteps windowsSteps;

    public VersionSteps(WindowsSteps windowsSteps) {
        this.windowsSteps = windowsSteps;
    }

    // controlling versions
    @Given("^a newer version is available on the internet$")
    public void new_version_avalable() {
        throw new PendingException();
    }

    @Given("^no newer version is available on the internet$")
    public void no_new_version_avalable() {
        // do nothing here, since the one in development is always newer then the released one
        //todo: find out how to do it right
    }
    // -- controlling versions end

    // viewing version results
    @Then("^I should see, that a newer version is available$")
    public void see_new_version_avalable() {
        get_version_window().label("this-version-number").requireText(Pattern.compile("[0-9]+(\\.[0-9]+)*(-SNAPSHOT)?"));
        Pause.pause(new Condition("notify-this-is-newest-version should be visible") {
            @Override
            public boolean test() {
                return GuiActionRunner.execute(get_version_window().button("navigate-to-new-version")::isEnabled);
            }
        }, RunCucumber.TIMEOUT_UI_UPDATED);