package org.richfaces.testng;


import static org.testng.Assert.assertEquals;

import org.ajax4jsf.template.Template;
import org.richfaces.RichSeleniumTest;
import org.richfaces.SeleniumTestBase;
import org.testng.annotations.AfterMethod;
import org.testng.annotations.BeforeMethod;
import org.testng.annotations.Parameters;
import org.testng.annotations.Test;

public class LoadStyleTest extends SeleniumTestBase implements RichSeleniumTest {

    public LoadStyleTest() {
        super("http", "localhost", serverPort);
    }

    /**
     * This method are invoking before selenium tests started
     */
    @BeforeMethod
    @Parameters({"browser", "filterPrefix"})
    public void startSelenium(String browser, String filterPrefix) {
    	super.startSelenium(browser, filterPrefix);
    }
    
    
    @BeforeMethod
    @Parameters({"loadStyleStrategy", "loadScriptStrategy"})
    protected void loadConfiguration(String loadStyleStrategy, String loadScriptStrategy) throws Exception {
	super.loadConfiguration(loadStyleStrategy, loadScriptStrategy);
    }

    /**
     * This method are invoking after selenium tests completed
     */
    @AfterMethod(alwaysRun=true)
    public void stopSelenium() {
        super.stopSelenium();
    }

    @Test
    public void testLoadStyleComponent() throws Exception {
    	_testLoadStyleComponent(Template.SIMPLE);
        _testLoadStyleComponent(Template.DATA_TABLE);
        _testLoadStyleComponent(Template.MODAL_PANEL);
    }

    private void _testLoadStyleComponent(Template template) {
        renderPage(template);
        String divId = getParentId() + "rectangle";
        assertEquals(50, getWidthById(divId));
        assertEquals(100, getHeightById(divId));
    }

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

}
