package pt.fccn.mobile.arquivo.tests.pagesearch;

import static org.junit.Assert.assertTrue;

import org.junit.Test;
import org.openqa.selenium.By;

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

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

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

	@Test
	@Retry
	public void pageSearchTest() {
		run("Search fccn", () -> {
			driver.findElement(By.id("txtSearch")).clear();
			driver.findElement(By.id("txtSearch")).sendKeys("fccn");
			driver.findElement(By.xpath("//*[@id=\"buttonSearch\"]/button")).click();
		});

		
		waitUntilElementIsVisibleAndGet(By.id("resultados-lista"));
		
		int anchorsCount = driver.findElementsByXPath("//*[@id=\"resultados-lista\"]//*[@class=\"url\"][contains(text(),'fccn')]")
				.size();

		System.out.println("anchorsCount " + anchorsCount);
		
		long emsCount = driver.findElementsByXPath("//*[@id=\"resultados-lista\"]//em") //
				.stream() //
				.filter(em -> em.getText().toLowerCase().contains("fccn")) //
				.count();

		System.out.println("emsCount " + emsCount);

		assertTrue("At least 80 percent of results should show something related to search criteria",
				emsCount + anchorsCount >= 10);
	}

}

@@ -43,16 +43,61 @@
 earch;%0A%0A
+import static org.junit.Assert.assertEquals;%0A
 import s
@@ -927,16 +927,210 @@
 %22));%0A%09%09%0A
+%09%09appendError(() -%3E assertEquals(%22Verify if the estimated results count message is displayed on page search%22, %22548.022%22,%0A%09%09%09%09driver.findElement(By.id(%22estimated-results-value%22)).getText()));%0A%09%09%0A
 %09%09int an

Verify the estimated results count