/**
 * 
 */
package org.richfaces.testng;

import org.ajax4jsf.template.Template;
import org.richfaces.SeleniumTestBase;
import org.testng.annotations.Test;

/**
 * @author Andrey
 *
 */
public class EffectTest extends SeleniumTestBase {
	
	static final String RESET_METHOD = "#{effectBean.reset}"; 
	
	@Test
	public void testRendered(Template template) {
		renderPage(template, RESET_METHOD);
		String parentId = getParentId();
		
		String controlId = parentId + "_controls:testRendered";
		clickCommandAndWait(controlId);
		
		String button2Id = parentId + "button2"; 
		String hideLink2 = "hideLink2"; 
		
		AssertVisible(button2Id);
		clickById(hideLink2);
		AssertVisible(button2Id, "Button should not be hidden in case on effect rendered = false");
	}
	
	@Test
	public void testNamedEffect(Template template) {
		renderPage(template, RESET_METHOD);
		
		String testLink = "testLink";
		AssertVisible(testLink);
		
		clickById(testLink);
		pause(200, testLink);
		assertStyleAttribute(testLink, "opacity", "Named effect does not work");
		pause(1500, testLink);
		assertStyleAttribute(testLink, "opacity: 0.1", "Opacity effect has not been completed");
	}
	
	@Test
	public void testComponentHideShow(Template template) {
		renderPage(template, RESET_METHOD);
		String parentId = getParentId();
		
		String button2Id = parentId + "button2";
		String button3Id = parentId + "button3";
		
		String hideLink2 = "hideLink2";
		String showLink2 = "showLink2";
		
		AssertVisible(button2Id);
		clickById(hideLink2);
		AssertNotVisible(button2Id, "Command Button has not been hidden by Fade effect");
		clickById(showLink2);
		AssertVisible(button2Id, "Command Button has not been appeared by Fade effect");
		
		AssertVisible(button3Id);
		clickById(button3Id);
		AssertNotVisible(button3Id, "Command Button has not been hidden by Fade effect attached to parent");
		
		pause(1500, button3Id);
		AssertVisible(button3Id, "Command Button has not been appeared after 1 second duration by Fade effect attached to parent");

	}
	
	
	@Test
	public void testFadeEffect(Template template) {
		renderPage(template, RESET_METHOD);
		String parentId = getParentId();
		
		String button1Id = "button1";
		String button2Id = parentId + "button2";
		
		String hideLink1 = "hideLink1";
		String hideLink2 = "hideLink2";
		
		AssertVisible(button1Id);
		AssertVisible(button2Id);
		
		clickById(hideLink1);
		pause(500, hideLink1);
		AssertVisible(button1Id, "Duration param of Fade effect does not work ");
		assertStyleAttribute(button1Id, "opacity", "Element has no opacity style");
		
		pause(2000, hideLink1);
		
		AssertNotVisible(button1Id, "Input button has not been hidden by Fade effect or targetId has not been resolved");
		
		clickById(hideLink2);
		AssertNotVisible(button2Id, "Command Button has not been hidden by Fade effect or targetId has not been resolved");
			
	}

	/* (non-Javadoc)
	 * @see org.richfaces.SeleniumTestBase#getTestUrl()
	 */
	@Override
	public String getTestUrl() {
		return "pages/effect/effectTest.xhtml";
	}

}
