package pt.fccn.mobile.arquivo.tests.replay.options;

import static org.openqa.selenium.support.ui.ExpectedConditions.or;
import static org.openqa.selenium.support.ui.ExpectedConditions.urlToBe;
import static org.openqa.selenium.support.ui.ExpectedConditions.visibilityOfElementLocated;

import org.junit.Test;
import org.openqa.selenium.By;
import org.openqa.selenium.support.ui.ExpectedConditions;
import org.openqa.selenium.support.ui.WebDriverWait;

import pt.fccn.arquivo.selenium.Retry;
import pt.fccn.arquivo.selenium.WebDriverTestBaseParalell;

/**
 *
 * @author Ivo Branco <ivo.branco@fccn.pt>
 *
 */
public class ReplayReconstructTest extends WebDriverTestBaseParalell {

	private static final String WAYBACK_EXAMPLE = "/wayback/19961013145650/http://www.fccn.pt/";
	private static final String MEMENTO_TIMETRAVEL = "https://timetravel.mementoweb.org/reconstruct/http://www.fccn.pt/";

	public ReplayReconstructTest(String os, String version, String browser, String deviceName,
			String deviceOrientation) {
		super(os, version, browser, deviceName, deviceOrientation);
	}

	@Test
	@Retry
	public void replayReconstructTest() {
		driver.get(this.testURL + WAYBACK_EXAMPLE);

		run("Open replay right menu", () -> waitUntilElementIsVisibleAndGet(By.id("replayMenuButton")).click());

		run("Click reconstruct link", () -> waitUntilElementIsVisibleAndGet(By.id("a_reconstruct")).click());

		run("Click cancel reconstruct", () -> waitUntilElementIsVisibleAndGet(By.id("cancelPopup")).click());

		run("Check if cancel button really closes confirm reconstruct modal box", () -> {
			new WebDriverWait(driver, 20).until(ExpectedConditions.invisibilityOfElementLocated(By.id("cancelPopup")));
			new WebDriverWait(driver, 20)
					.until(ExpectedConditions.invisibilityOfElementLocated(By.id("uglipop_popbox")));
		});

		run("Click again on reconstruct link", () -> waitUntilElementIsVisibleAndGet(By.id("a_reconstruct")).click());

		run("Confirm go to reconstruct page", () -> waitUntilElementIsVisibleAndGet(By.id("completePage")).click());

		run("Check on memento timetravel page", () -> new WebDriverWait(driver, 200)
				.until(or(visibilityOfElementLocated(By.id("scatterinfo")), urlToBe(MEMENTO_TIMETRAVEL))));
	}

}

@@ -769,16 +769,18 @@
 n.pt/%22;%0A
+//
 %09private
@@ -890,16 +890,16 @@
 n.pt/%22;%0A
-
 %0A%09public
@@ -1319,32 +1319,181 @@
 ct link%22, () -%3E 
+%7B%0A%09%09%09By reconstructBy = By.id(%22a_reconstruct%22);%0A%09%09%09driver.executeScript(%22arguments%5B0%5D.scrollIntoView(true);%22, driver.findElement(reconstructBy));%0A%09%09%09
 waitUntilElement
@@ -1504,33 +1504,24 @@
 sibleAndGet(
-By.id(%22a_
 reconstruct%22
@@ -1511,34 +1511,34 @@
 dGet(reconstruct
-%22)
+By
 ).click());%0A%0A%09%09r
@@ -1522,32 +1522,37 @@
 tructBy).click()
+;%0A%09%09%7D
 );%0A%0A%09%09run(%22Click
@@ -2184,32 +2184,34 @@
 e%22)).click());%0A%0A
+//
 %09%09run(%22Check on 
@@ -2231,25 +2231,31 @@
 ravel page%22,
- 
+%0A//%09%09%09%09
 () -%3E new We
@@ -2282,73 +2282,15 @@
 200)
-%0A%09%09%09%09
 .until(
-or(visibilityOfElementLocated(By.id(%22scatterinfo%22)), 
 urlT
@@ -2314,17 +2314,16 @@
 RAVEL)))
-)
 ;%0A%09%7D%0A%0A%7D%0A

Fix reconstruct link no visible when trying to click, but remove memento timetravel check.