package be.iminds.ilabt.jfed.experimenter_gui.ui;

import be.iminds.ilabt.jfed.experimenter_gui.util.BrowserUtil;
import be.iminds.ilabt.jfed.util.JavaFXTest;
import javafx.scene.control.Hyperlink;
import javafx.scene.text.Text;
import javafx.scene.text.TextFlow;
import org.testng.Assert;
import org.testng.annotations.BeforeSuite;
import org.testng.annotations.Test;

/**
 * User: twalcari
 * Date: 9/30/2015
 * Time: 10:28
 */
public class TextFlowUtilTest extends JavaFXTest{

    @BeforeSuite
    public void setupSuite() throws InterruptedException {
        super.setupSuite();

    }

    @Test
    public void testTextWithUrlsToTextFlow() throws Exception {
        TextFlowUtil textFlowUtil = new TextFlowUtil(new BrowserUtil(() -> null));


        String input = "wow, so example: http://test.com";

        TextFlow result = textFlowUtil.textWithUrlsToTextFlow(input);

        Assert.assertEquals(result.getChildren().size(), 2);
        Assert.assertTrue(result.getChildren().get(0) instanceof Text);
        Assert.assertTrue(result.getChildren().get(1) instanceof Hyperlink);

        String input2 = "http://test.com! wow, so example: http://test.com";

        TextFlow result2 = textFlowUtil.textWithUrlsToTextFlow(input2);

        Assert.assertEquals(result2.getChildren().size(), 3);
        Assert.assertTrue(result2.getChildren().get(0) instanceof Hyperlink);
        Assert.assertTrue(result2.getChildren().get(1) instanceof Text);
        Assert.assertTrue(result2.getChildren().get(2) instanceof Hyperlink);

    }
}