package org.richfaces.renderkit;

import java.util.ArrayList;
import java.util.List;

import javax.faces.component.UISelectItem;
import javax.faces.component.UISelectItems;
import javax.faces.model.SelectItem;

import org.ajax4jsf.tests.AbstractAjax4JsfTestCase;
import org.richfaces.component.UIInplaceSelect;
import org.richfaces.renderkit.html.InplaceSelectRenderer;

import com.gargoylesoftware.htmlunit.html.HtmlElement;
import com.gargoylesoftware.htmlunit.html.HtmlPage;

public class InplaceSelectRenderTest extends AbstractAjax4JsfTestCase {
	
	private UIInplaceSelect iselect;
	private InplaceSelectRenderer  renderer;
	List selectItems = new ArrayList();

	public InplaceSelectRenderTest(String name) {
		super(name);
	}

	public void setUp() throws Exception {
		super.setUp();
		renderer = new InplaceSelectRenderer();
	    iselect = (UIInplaceSelect)application.createComponent("org.richfaces.InplaceSelect");
	    iselect.setValue("New York");
	    selectItems.add(new SelectItem("Kansas City"));
		selectItems.add(new SelectItem("Las Vegas"));
		selectItems.add(new SelectItem("Oklahoma City"));
		selectItems.add(new SelectItem("New Jersey"));
		selectItems.add(new SelectItem("Detroit"));
			    
		UISelectItem item1 = new UISelectItem();
		item1.setValue(new SelectItem("Toronto"));
			
		UISelectItem item2 = new UISelectItem();
		item2.setValue(new SelectItem("Cleveland"));
			
		UISelectItem item3 = new UISelectItem();
		item3.setValue(new SelectItem("Indianapolis"));
			
		UISelectItem item4 = new UISelectItem();
		item4.setValue(new SelectItem("New York"));
			
	    iselect.getChildren().add(item1);
	    iselect.getChildren().add(item2);
	    iselect.getChildren().add(item3);
	    iselect.getChildren().add(item4);
	    
	    UISelectItems items = new UISelectItems();
	    items.setValue(selectItems);
	    iselect.getChildren().add(items);
		iselect.setValue("New York");
	    
	    facesContext.getViewRoot().getChildren().add(iselect);
	}
	
	public void testRender() throws Exception{
		
		HtmlPage page = renderView();
		assertNotNull(page);
		HtmlElement elem = page.getHtmlElementById(iselect.getClientId(facesContext));
		assertNotNull(elem);
		assertEquals(elem.getTagName(), "span");
	}
}
