package net.canadensys.dataportal.occurrence;

import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertTrue;

import org.junit.Test;
import org.openqa.selenium.By;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.support.FindBy;
import org.openqa.selenium.support.PageFactory;

/**
 * Very simple and basic Integration test to make sure we can rendered some pages.
 * @author canadensys
 *
 */
public class ExplorerPageIntegrationTest extends AbstractIntegrationTest {
	
	//the footer div presence ensure the page was all rendered by Freemarker
	@FindBy(css = "div#footer")
	private WebElement footerDiv;
	
	@Test
	public void testTablePage() {
		browser.get(TESTING_SERVER_URL+"search?view=table");
		
		//bind the WebElement to the current page
		PageFactory.initElements(browser, this);
		
		WebElement resultTable = browser.findElement(By.cssSelector("table#results"));
		assertEquals("table",resultTable.getTagName());
		//make sure footer is there
		assertEquals("div",footerDiv.getTagName());
	}
	
	@Test
	public void testErrorPage() {
		browser.get(TESTING_SERVER_URL+"searchh");
		
		//bind the WebElement to the current page
		PageFactory.initElements(browser, this);
		
		WebElement h1 = browser.findElement(By.cssSelector("h1"));
		assertTrue(h1.getText().contains("404"));
		
		//make sure footer is there
		assertEquals("div",footerDiv.getTagName());
	}
	
	@Test
	public void testFrenchPageEncoding() {
		browser.get(TESTING_SERVER_URL+"search?view=table&lang=fr");
		
		//bind the WebElement to the current page
		PageFactory.initElements(browser, this);
		
		WebElement search_h3 = browser.findElement(By.cssSelector("#search h3"));
		assertEquals("Créer un nouveau filtre",search_h3.getText());
		
		//make sure footer is there
		assertEquals("div",footerDiv.getTagName());
	}
}

@@ -36,24 +36,48 @@
 ccurrence;%0A%0A
+import java.util.List;%0A%0A
 import stati
@@ -151,16 +151,60 @@
 ertTrue;
+%0Aimport static org.junit.Assert.assertFalse;
 %0A%0Aimport
@@ -1394,87 +1394,8 @@
 ));%0A
-%09%09%0A%09%09//make sure footer is there%0A%09%09assertEquals(%22div%22,footerDiv.getTagName());%0A
 %09%7D%0A%09
@@ -1818,11 +1818,777 @@
 e());%0A%09%7D
+%0A%0A%09@Test%0A%09public void testCookie() %7B%0A%09%09browser.get(TESTING_SERVER_URL+%22search?view=table%22);%0A%09%09%0A%09%09//bind the WebElement to the current page%0A%09%09PageFactory.initElements(browser, this);%0A%09%09%0A%09%09WebElement display_button = browser.findElement(By.linkText(%22Display%22));%0A%09%09display_button.click();%0A%09%09%0A%09%09WebElement toggle_scientific = browser.findElement(By.id(%22toggle-col-0%22));%0A%09%09toggle_scientific.click();%0A%09%09%0A%09%09List%3CWebElement%3E column_headers = browser.findElements(By.cssSelector(%22table#results thead tr th%22));%0A%09%09assertFalse(column_headers.get(0).isDisplayed());%0A%0A%09%09browser.navigate().refresh();%0A%09%09%0A%09%09List%3CWebElement%3E column_headers_refreshed = browser.findElements(By.cssSelector(%22table#results thead tr th%22));%0A%09%09assertFalse(column_headers_refreshed.get(0).isDisplayed());%0A%09%7D
 %0A%7D%0A

Add integration test for cookie functionality