Author: abelevich
Date: 2007-06-26 11:55:43 -0400 (Tue, 26 Jun 2007)
New Revision: 1325
Added:
trunk/sandbox/scrollable-grid/src/test/java/org/richfaces/renderkit/html/ScrollableGridRendererTest.java
Log:
test for renderer
Added:
trunk/sandbox/scrollable-grid/src/test/java/org/richfaces/renderkit/html/ScrollableGridRendererTest.java
===================================================================
---
trunk/sandbox/scrollable-grid/src/test/java/org/richfaces/renderkit/html/ScrollableGridRendererTest.java
(rev 0)
+++
trunk/sandbox/scrollable-grid/src/test/java/org/richfaces/renderkit/html/ScrollableGridRendererTest.java 2007-06-26
15:55:43 UTC (rev 1325)
@@ -0,0 +1,144 @@
+package org.richfaces.renderkit.html;
+
+import java.util.ArrayList;
+import java.util.Iterator;
+import java.util.List;
+
+import javax.faces.component.UIOutput;
+import javax.faces.component.html.HtmlOutputText;
+
+import org.ajax4jsf.ajax.repeat.ExtendedDataModel;
+import org.ajax4jsf.tests.AbstractAjax4JsfTestCase;
+import org.richfaces.component.UIScrollableGridColumn;
+import org.richfaces.component.html.HtmlScrollableGrid;
+import org.richfaces.component.html.HtmlScrollableGridColumn;
+
+import com.gargoylesoftware.htmlunit.html.HtmlElement;
+import com.gargoylesoftware.htmlunit.html.HtmlPage;
+
+/**
+ * @author Anton Belevich
+ *
+ */
+public class ScrollableGridRendererTest extends AbstractAjax4JsfTestCase{
+
+ HtmlScrollableGrid grid;
+ int columns = 7;
+
+ public ScrollableGridRendererTest(String arg0) {
+ super(arg0);
+ }
+
+ public void setUp() throws Exception {
+
+ super.setUp();
+
+ // create grid
+ grid =
(HtmlScrollableGrid)application.createComponent("org.richfaces.component.ScrollableGrid");
+ grid.setId("grid");
+ grid.setFrozenColCount(3);
+
+ // add columns
+ for (int i = 0; i < columns; i++) {
+
+ UIScrollableGridColumn column = (UIScrollableGridColumn) createComponent(
+ HtmlScrollableGridColumn.COMPONENT_TYPE,
+ HtmlScrollableGridColumn.class.getName(),
+ null, null, null);
+ UIOutput outputText = (UIOutput) createComponent(
+ HtmlOutputText.COMPONENT_TYPE, HtmlOutputText.class.getName(),
+ null, null, null);
+
+ column.getFacets().put("header", outputText);
+ column.getFacets().put("footer", outputText);
+ column.getChildren().add(outputText);
+
+ grid.getChildren().add(column);
+ grid.setFirst(0);
+ grid.setRows(40);
+ }
+
+ facesContext.getViewRoot().getChildren().add(grid);
+ }
+
+ public void tearDown() throws Exception {
+ super.tearDown();
+ grid = null;
+ }
+
+
+ public void testRenderingFrozenNormalColumns()throws Exception{
+
+ HtmlPage page = renderView();
+ assertNotNull(page);
+ HtmlElement div = page.getHtmlElementById(grid.getClientId(facesContext));
+ assertNotNull(div);
+ assertEquals("div", div.getNodeName());
+
+ String classAttr = div.getAttributeValue("class");
+ assertTrue(classAttr.contains("ClientUI_Grid"));
+
+ Iterator childIter= div.getChildElementsIterator();
+
+ for (; childIter.hasNext();) {
+
+ HtmlElement elem = (HtmlElement) childIter.next();
+ assertNotNull(elem);
+
+ boolean res = (elem.getNodeName().equals("div") ||
elem.getNodeName().equals("input"));
+ assertEquals(true, res);
+
+ if(elem.getNodeName().equals("div")){
+
+ String elemClassAttr = elem.getAttributeValue("class");
+ assertTrue(elemClassAttr.contains("ClientUI_InlineBox"));
+ boolean templates = elem.getId().equals(grid.getId()+ "_GridBodyTemplate")
|| elem.getId().equals(grid.getId()+ "_GridFooterTemplate") ||
elem.getId().equals(grid.getId()+ "_GridHeaderTemplate");
+ assertTrue(templates);
+ Iterator divIter = elem.getChildElementsIterator();
+ HtmlElement inDiv = (HtmlElement) divIter.next();
+ assertNotNull(inDiv);
+ assertEquals("div", inDiv.getNodeName());
+
+ Iterator spanIter = inDiv.getChildElementsIterator();
+
+ for (;spanIter.hasNext();) {
+
+ HtmlElement span = (HtmlElement) spanIter.next();
+ assertNotNull(span);
+ assertEquals("span", span.getNodeName());
+ elemClassAttr = span.getAttributeValue("class");
+ assertNotNull(elemClassAttr);
+
+ if(span.getId().contains("FrozenBox")){
+ assertTrue(elemClassAttr.contains("ClientUI_TmplBox
ClientUI_FrozenBox"));
+ }else if(span.getId().contains("NormalBox")){
+ assertTrue(elemClassAttr.contains("ClientUI_TmplBox
ClientUI_NormalBox"));
+ }
+
+ String id = grid.getId();
+ for (int i = 0; i < columns; i++) {
+
+ HtmlElement hcell = page.getHtmlElementById(id + ":hc_" + i);
+ assertNotNull(hcell);
+ elemClassAttr = hcell.getAttributeValue("class");
+ assertTrue(elemClassAttr.contains("ClientUI_Grid_HC Idg-header-cell"));
+
+ for (int j = 0; j < grid.getRows(); j++) {
+ HtmlElement bcell = page.getHtmlElementById(id + ":c_" + j +
"_" + i);
+ assertNotNull(bcell);
+ elemClassAttr = bcell.getAttributeValue("class");
+ assertTrue(elemClassAttr.contains("ClientUI_Grid_BC Idg-column-cell"));
+
+ }
+
+ }
+
+ }
+
+ }
+
+ }
+
+ }
+
+}
Show replies by date