package org.richfaces.testng;

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

public class ToolBarTest extends SeleniumTestBase {

    private static final String TOOLBAR = "toolbar";

    private final static String RESULT_FAILED_TEXT = "No";

    private final static String RESULT_PASSED_TEXT = "Passed";

    /* Tab panel group/item separator constants */
    private final static String LINE_SEPARATOR = "line";

    private final static String DISC_SEPARATOR = "disc";

    private final static String GRID_SEPARATOR = "grid";

    private final static String SQUARE_SEPARATOR = "square";

    private final static String NONE_SEPARATOR = "none";

    @Test
    public void testToolBarComponentLayout(Template template) {
        renderPage(template);

        writeStatus("Check component layout");

        String id = getParentId() + "_form:";

        writeStatus("Switch toolbar group separator");

        clickAjaxCommandAndWait(id + "gs_" + LINE_SEPARATOR);
        clickAjaxCommandAndWait(id + "gs_" + DISC_SEPARATOR);
        clickAjaxCommandAndWait(id + "gs_" + GRID_SEPARATOR);
        clickAjaxCommandAndWait(id + "gs_" + SQUARE_SEPARATOR);
        clickAjaxCommandAndWait(id + "gs_" + NONE_SEPARATOR);

        writeStatus("Switch toolbar group item separator");

        clickAjaxCommandAndWait(id + "gis_" + LINE_SEPARATOR);
        clickAjaxCommandAndWait(id + "gis_" + DISC_SEPARATOR);
        clickAjaxCommandAndWait(id + "gis_" + GRID_SEPARATOR);
        clickAjaxCommandAndWait(id + "gis_" + SQUARE_SEPARATOR);
        clickAjaxCommandAndWait(id + "gis_" + NONE_SEPARATOR);
    }

    @Test
    public void testToolBarEvents(Template template) {
        renderPage(template);

        writeStatus("Check component event triggering");

        String toolbar = getParentId() + TOOLBAR + "_click";
        testOnclickEvent(toolbar, toolbar + "_result", RESULT_FAILED_TEXT, RESULT_PASSED_TEXT);

        toolbar = getParentId() + TOOLBAR + "_dblclick";
        testOnDblclickEvent(toolbar, toolbar + "_result", RESULT_FAILED_TEXT, RESULT_PASSED_TEXT);

        toolbar = getParentId() + TOOLBAR + "_mousedown";
        testOnmousedownEvent(toolbar, toolbar + "_result", RESULT_FAILED_TEXT, RESULT_PASSED_TEXT);

        toolbar = getParentId() + TOOLBAR + "_mousemove";
        testOnmousemoveEvent(toolbar, toolbar + "_result", RESULT_FAILED_TEXT, RESULT_PASSED_TEXT);

        toolbar = getParentId() + TOOLBAR + "_mouseout";
        testOnmouseoutEvent(toolbar, toolbar + "_result", RESULT_FAILED_TEXT, RESULT_PASSED_TEXT);

        toolbar = getParentId() + TOOLBAR + "_mouseover";
        testOnmouseoverEvent(toolbar, toolbar + "_result", RESULT_FAILED_TEXT, RESULT_PASSED_TEXT);

        toolbar = getParentId() + TOOLBAR + "_mouseup";
        testOnmouseupEvent(toolbar, toolbar + "_result", RESULT_FAILED_TEXT, RESULT_PASSED_TEXT);
    }

    @Override
    public String getTestUrl() {
        return "pages/toolBar/toolBarTest.xhtml";
    }

}
