/**
 * License Agreement.
 *
 *  JBoss RichFaces - Ajax4jsf Component Library
 *
 * Copyright (C) 2007  Exadel, Inc.
 *
 * This library is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Lesser General Public
 * License version 2.1 as published by the Free Software Foundation.
 *
 * This library is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public
 * License along with this library; if not, write to the Free Software
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301  USA
 */

package org.richfaces.testng;

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

public class SimpleTogglePanelTest extends SeleniumTestBase {

    @Test
    public void _testSimpleTogglePanelComponent(Template template) {
        renderPage(template);
        String parentId = getParentId() + "_form:";
        String inputId = parentId + "_value";
        String outputId = parentId + "_value2";

        String ajaxHeader = parentId + "panel1_header";
        String serverHeader = parentId + "panel2_header";
        String clientHeader = parentId + "panel3_header";

        String ajaxBody = parentId + "panel1_body";
        String serverBody = parentId + "panel2_body";
        String clientBody = parentId + "panel3_body";

        writeStatus("Click on client simple toggle panel. It should be opened.");
        clickById(clientHeader);
        Assert.assertTrue(isVisibleById(clientBody));
        writeStatus("Click on client simple toggle panel again. It should be closed.");
        clickById(clientHeader);
        Assert.assertFalse(isVisibleById(clientBody));

        writeStatus("Click on ajax simple toggle panel. It should be opened.");
        clickById(ajaxHeader);
        waitForAjaxCompletion();
        AssertValueEquals(inputId, "panel1");
        AssertTextEquals(outputId, "1");
        Assert.assertTrue(isVisibleById(ajaxBody));

        writeStatus("Click on ajax simple toggle panel again. It should be closed.");
        clickById(ajaxHeader);
        waitForAjaxCompletion();
        AssertValueEquals(inputId, "panel1");
        AssertTextEquals(outputId, "2");
        Assert.assertFalse(isVisibleById(ajaxBody));

        writeStatus("Click on server simple toggle panel. It should be opened.");
        clickCommandAndWait(serverHeader);
        AssertValueEquals(inputId, "panel2");
        AssertTextEquals(outputId, "3");
        Assert.assertTrue(isVisibleById(serverBody));

        writeStatus("Click on server simple toggle panel. It should be closed.");
        clickCommandAndWait(serverHeader);
        AssertValueEquals(inputId, "panel2");
        AssertTextEquals(outputId, "4");
        Assert.assertFalse(isVisibleById(serverBody));
    }

    public String getTestUrl() {
        return "pages/simpleTogglePanel/simpleTogglePanel.xhtml";
    }

}
