/*
 * ModalPanelTest.java		Date created: 30.07.2008
 * Last modified by: $Author: alevkovsky $
 * $Revision: 9861 $	$Date: 2008-08-01 16:28:16 +0300 $
 */

package org.richfaces.testng;

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

/**
 * rich:modalPannel component selenium test
 * @author Alexandr Levkovsky
 *
 */
public class ModalPanelTest extends SeleniumTestBase {
    
    private final static String PANEL_ID="test_panel";
    private final static String FORM_ID="form:";
    private final static String RESET_ID="reset";
    private final static String CHANGE_RENDERED_ID="change_rendered";
    private final static String CHANGE_ATTRIBUTES_ID="change_attributes";
    private final static String HIDE_ID="hide";
    private final static String SHOW_ID="show";
    private final static String PANEL_C_DIV_ID = PANEL_ID + "CDiv";
    private final static String PANEL_CONTENT_DIV_ID = PANEL_ID + "ContentDiv";
    private final static String PANEL_CONTAINER_DIV_ID = PANEL_ID + "Container";
    
    
    /**
     * @see org.richfaces.SeleniumTestBase#getTestUrl()
     */
    @Override
    public String getTestUrl() {
	return "pages/modalPanel/modalPanelTest.xhtml";
    }

    @Test
    public void testModalPanel(Template template) throws Exception {
	renderPage(template);
	writeStatus("Testing modal panel");

	String panelId = getParentId() + FORM_ID + PANEL_CONTAINER_DIV_ID;

	AssertPresent(panelId);
	AssertNotVisible(panelId);

	clickShow();

	AssertPresent(panelId);
	AssertVisible(panelId);

	clickHide();

	AssertPresent(panelId);
	AssertNotVisible(panelId);

    }

    @Test
    public void testRenderedAttribute(Template template) throws Exception {
	renderPage(template);
	writeStatus("Testing rendered attribute");

	String panelId = getParentId() + FORM_ID + PANEL_CONTAINER_DIV_ID;

	AssertPresent(panelId);

	clickChangeRendered();

	AssertNotPresent(panelId);
	clickReset();
    }

    @Test
    public void testShowWhenRenderedAttribute(Template template) throws Exception {
	renderPage(template);
	writeStatus("Testing showWhenRendered attribute");

	String panelId = getParentId() + FORM_ID + PANEL_CONTAINER_DIV_ID;

	AssertPresent(panelId);
	AssertNotVisible(panelId);

	clickChangeAttributes();

	AssertPresent(panelId);
	AssertVisible(panelId);
	clickReset();
    }

    @Test
    public void testLayoutAttributes(Template template) throws Exception {
	renderPage(template);
	writeStatus("Testing layout attribute");

	clickShow();

	String panelContainerId = getParentId() + FORM_ID + PANEL_CONTAINER_DIV_ID;
	String panelContentId = getParentId() + FORM_ID + PANEL_CONTENT_DIV_ID;
	String panelCDivId = getParentId() + FORM_ID + PANEL_C_DIV_ID;

	AssertPresent(panelContainerId);
	AssertPresent(panelContentId);
	AssertPresent(panelCDivId);

	// test zindex attribute - should be 12
	assertStyleAttribute(panelContainerId, "z-index: 12");

	if (isFF()) {
	    // test top attribute - should be 101
	    assertStyleAttribute(panelCDivId, "top: 101");

	    // test left attribute - should be 102
	    assertStyleAttribute(panelCDivId, "left: 102");
	}

	// test width attribute - should be 103
	assertStyleAttribute(panelContentId, "width: 103");

	// test height attribute - should be 104
	assertStyleAttribute(panelContentId, "height: 104");
    }

    private void clickReset() {
	String buttonId = getParentId() + FORM_ID + RESET_ID;
	writeStatus("Click reset button");
	clickCommandAndWait(buttonId);
    }

    private void clickChangeRendered() {
	String buttonId = getParentId() + FORM_ID + CHANGE_RENDERED_ID;
	writeStatus("Click change rendered button");
	clickCommandAndWait(buttonId);
    }

    private void clickChangeAttributes() {
	String buttonId = getParentId() + FORM_ID + CHANGE_ATTRIBUTES_ID;
	writeStatus("Click change attributes button");
	clickCommandAndWait(buttonId);
    }

    private void clickShow() {
	String buttonId = getParentId() + FORM_ID + SHOW_ID;
	writeStatus("Click show button");
	clickById(buttonId);
    }

    private void clickHide() {
	String buttonId = getParentId() + FORM_ID + HIDE_ID;
	writeStatus("Click hide button");
	clickById(buttonId);
    }
    
}
