package org.richfaces.testng;

import junit.framework.Assert;

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

public class AjaxLoadBundleTest extends SeleniumTestBase {
    private static final String URL = "pages/loadBundle/loadBundle.xhtml";

    private static final String BUTTON_ID = "b1";

    private static final String SAMPLE_MESSAGE = "Error was occured.";

    private final static String FORM_ID = "form:";

    private final static String FIRST_LINK_ID = FORM_ID + "error";

    private final static String SECOND_LINK_ID = FORM_ID + "_link";

    /**
     * @see org.richfaces.SeleniumTestBase#getTestUrl()
     */
    @Override
    public String getTestUrl() {
        return URL;
    }

    @Test
    public void testAjaxLoadBundleComponent(Template template) throws Exception {
        renderPage(template);
        writeStatus("Testing loadBundle component");
        String textId = getParentId() + FIRST_LINK_ID;
        AssertPresent(textId);
        AssertNotPresent(getParentId() + SECOND_LINK_ID);
        Assert.assertEquals(getTextById(textId), SAMPLE_MESSAGE);
    }

    @Test
    public void testAjaxReRender(Template template) throws Exception {
        renderPage(template);
        writeStatus("Testing loadBundle component after ajax rerender");
        String buttonId = getParentId() + FORM_ID + BUTTON_ID;
        clickById(buttonId);
        waitForAjaxCompletion();
        AssertPresent(getParentId() + SECOND_LINK_ID);
    }
}
