Author: lfryc(a)redhat.com
Date: 2011-01-23 15:30:31 -0500 (Sun, 23 Jan 2011)
New Revision: 21161
Added:
modules/tests/metamer/trunk/ftest-source/src/main/java/org/richfaces/tests/metamer/ftest/richTree/TestTreeSelection.java
Modified:
modules/tests/metamer/trunk/application/src/main/webapp/components/richTree/simple.xhtml
modules/tests/metamer/trunk/ftest-source/src/main/java/org/richfaces/tests/metamer/ftest/richTree/AbstractTreeNodeModel.java
modules/tests/metamer/trunk/ftest-source/src/main/java/org/richfaces/tests/metamer/ftest/richTree/TestTreeToggling.java
modules/tests/metamer/trunk/ftest-source/src/main/java/org/richfaces/tests/metamer/ftest/richTree/TreeNodeModel.java
Log:
rich:tree - automated Simple sample - selection capabilities (RFPL-935)
Modified:
modules/tests/metamer/trunk/application/src/main/webapp/components/richTree/simple.xhtml
===================================================================
---
modules/tests/metamer/trunk/application/src/main/webapp/components/richTree/simple.xhtml 2011-01-23
20:29:41 UTC (rev 21160)
+++
modules/tests/metamer/trunk/application/src/main/webapp/components/richTree/simple.xhtml 2011-01-23
20:30:31 UTC (rev 21161)
@@ -221,30 +221,30 @@
</h:selectBooleanCheckbox>
<h:outputLabel value="Selection:" />
- <h:outputText value="#{richTreeBean.selection}" />
+ <h:outputText id="selection"
value="#{richTreeBean.selection}" />
<h:outputLabel value="Selection Change Event:"
rendered="#{not empty richTreeListenerBean.treeSelectionChangeEvent}" />
<h:panelGrid columns="2" rendered="#{not empty
richTreeListenerBean.treeSelectionChangeEvent}">
<h:outputLabel value="Client ID:" />
- <h:outputText
value="#{richTreeListenerBean.treeSelectionChangeEvent.component.id}" />
+ <h:outputText id="selectionEventClientId"
value="#{richTreeListenerBean.treeSelectionChangeEvent.component.id}" />
<h:outputLabel value="New Selection:" />
- <h:outputText
value="#{richTreeListenerBean.treeSelectionChangeEvent.newSelection}" />
+ <h:outputText id="selectionEventNewSelection"
value="#{richTreeListenerBean.treeSelectionChangeEvent.newSelection}" />
<h:outputLabel value="Old Selection:" />
- <h:outputText
value="#{richTreeListenerBean.treeSelectionChangeEvent.oldSelection}" />
+ <h:outputText id="selectionEventOldSelection"
value="#{richTreeListenerBean.treeSelectionChangeEvent.oldSelection}" />
</h:panelGrid>
<h:outputLabel value="Tree Toggle Event:" rendered="#{not
empty richTreeListenerBean.treeToggleEvent}" />
<h:panelGrid columns="2" rendered="#{not empty
richTreeListenerBean.treeToggleEvent}">
<h:outputLabel value="Client ID:" />
- <h:outputText
value="#{richTreeListenerBean.treeToggleEvent.component.id}" />
+ <h:outputText id="toggleEventClientId"
value="#{richTreeListenerBean.treeToggleEvent.component.id}" />
<h:outputLabel value="Collapsed:" />
- <h:outputText
value="#{richTreeListenerBean.treeToggleEvent.collapsed}" />
+ <h:outputText id="toggleEventCollapsed"
value="#{richTreeListenerBean.treeToggleEvent.collapsed}" />
<h:outputLabel value="Expanded:" />
- <h:outputText
value="#{richTreeListenerBean.treeToggleEvent.expanded}" />
+ <h:outputText id="toggleEventExpanded"
value="#{richTreeListenerBean.treeToggleEvent.expanded}" />
</h:panelGrid>
</h:panelGrid>
</a4j:outputPanel>
Modified:
modules/tests/metamer/trunk/ftest-source/src/main/java/org/richfaces/tests/metamer/ftest/richTree/AbstractTreeNodeModel.java
===================================================================
---
modules/tests/metamer/trunk/ftest-source/src/main/java/org/richfaces/tests/metamer/ftest/richTree/AbstractTreeNodeModel.java 2011-01-23
20:29:41 UTC (rev 21160)
+++
modules/tests/metamer/trunk/ftest-source/src/main/java/org/richfaces/tests/metamer/ftest/richTree/AbstractTreeNodeModel.java 2011-01-23
20:30:31 UTC (rev 21161)
@@ -47,10 +47,12 @@
static JQueryLocator treeNode = jq("div.rf-tr-nd");
static JQueryLocator treeNodeExpanded = jq("div.rf-tr-nd-exp");
static JQueryLocator treeNodeCollapsed = jq("div.rf-tr-nd-colps");
+ static JQueryLocator treeNodeSelected = jq("div.rf-tr-nd:has(> .rf-trn >
.rf-trn-sel)");
ReferencedLocator<JQueryLocator> nodes = ref(root, "> " +
treeNode.getRawLocator());
ReferencedLocator<JQueryLocator> nodesCollapsed = ref(root, "> " +
treeNodeCollapsed.getRawLocator());
ReferencedLocator<JQueryLocator> nodesExpanded = ref(root, "> " +
treeNodeExpanded.getRawLocator());
+ ReferencedLocator<JQueryLocator> anyNodesSelected = ref(root,
treeNodeSelected.getRawLocator());
public Iterable<TreeNodeModel> getNodes() {
Iterable<TreeNodeModel> result = new ModelIterable<JQueryLocator,
TreeNodeModel>(nodes.getAllOccurrences(),
@@ -76,6 +78,13 @@
new Object[] { tree });
return result;
}
+
+ public Iterable<TreeNodeModel> getAnySelectedNodes() {
+ Iterable<TreeNodeModel> result = new ModelIterable<JQueryLocator,
TreeNodeModel>(
+ anyNodesSelected.getAllOccurrences(), TreeNodeModel.class, new Class[] {
TreeModel.class },
+ new Object[] { tree });
+ return result;
+ }
public int getExpandedNodesCount() {
return selenium.getCount(nodesExpanded);
@@ -84,4 +93,8 @@
public int getCollapsedNodesCount() {
return selenium.getCount(nodesCollapsed);
}
+
+ public int getAnySelectedNodesCount() {
+ return selenium.getCount(anyNodesSelected);
+ }
}
Added:
modules/tests/metamer/trunk/ftest-source/src/main/java/org/richfaces/tests/metamer/ftest/richTree/TestTreeSelection.java
===================================================================
---
modules/tests/metamer/trunk/ftest-source/src/main/java/org/richfaces/tests/metamer/ftest/richTree/TestTreeSelection.java
(rev 0)
+++
modules/tests/metamer/trunk/ftest-source/src/main/java/org/richfaces/tests/metamer/ftest/richTree/TestTreeSelection.java 2011-01-23
20:30:31 UTC (rev 21161)
@@ -0,0 +1,168 @@
+/*******************************************************************************
+ * JBoss, Home of Professional Open Source
+ * Copyright 2010, Red Hat, Inc. and individual contributors
+ * by the @authors tag. See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software 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 software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site:
http://www.fsf.org.
+ *******************************************************************************/
+package org.richfaces.tests.metamer.ftest.richTree;
+
+import static org.jboss.test.selenium.guard.request.RequestTypeGuardFactory.guardXhr;
+import static org.jboss.test.selenium.locator.LocatorFactory.jq;
+import static org.jboss.test.selenium.utils.URLUtils.buildUrl;
+import static org.testng.Assert.assertEquals;
+import static org.testng.Assert.assertFalse;
+import static org.testng.Assert.assertTrue;
+
+import java.net.URL;
+import java.util.regex.Matcher;
+import java.util.regex.Pattern;
+
+import org.apache.commons.lang.StringUtils;
+import org.jboss.test.selenium.locator.JQueryLocator;
+import org.richfaces.component.SwitchType;
+import org.richfaces.tests.metamer.ftest.AbstractMetamerTest;
+import org.richfaces.tests.metamer.ftest.annotations.Inject;
+import org.richfaces.tests.metamer.ftest.annotations.Use;
+import org.testng.annotations.BeforeMethod;
+import org.testng.annotations.Test;
+
+/**
+ * @author <a href="mailto:lfryc@redhat.com">Lukas Fryc</a>
+ * @version $Revision$
+ */
+public class TestTreeSelection extends AbstractMetamerTest {
+
+ Integer[][] SUBNODE_SELECTION_PATHS = new Integer[][] { { 2, 3 }, { 3, 4 }, { 4, 1, 1
}, { 4 }, { 4, 1 }, { 1, 5 },
+ { 2, 3, 3 } };
+
+ @Override
+ public URL getTestUrl() {
+ return buildUrl(contextPath,
"faces/components/richTree/simple.xhtml");
+ }
+
+ private TreeAttributes treeAttributes = new
TreeAttributes(jq("span[id*=attributes]"));
+ private TreeModel tree = new TreeModel(pjq("div.rf-tr[id$=richTree]"));
+ private TreeNodeModel treeNode;
+
+ @Inject
+ @Use(value = "selectionTypes")
+ SwitchType selectionType = SwitchType.ajax;
+ SwitchType[] selectionTypes = new SwitchType[] { SwitchType.ajax, SwitchType.client
};
+ SwitchType[] eventEnabledSelectionTypes = new SwitchType[] { SwitchType.ajax };
+
+ JQueryLocator expandAll = jq("input:submit[id$=expandAll]");
+ JQueryLocator selection = jq("span[id$=selection]");
+ JQueryLocator clientId = jq("span[id$=selectionEventClientId]");
+ JQueryLocator newSelection = jq("span[id$=selectionEventNewSelection]");
+ JQueryLocator oldSelection = jq("span[id$=selectionEventOldSelection]");
+
+ @BeforeMethod
+ public void testInitialize() {
+ treeAttributes.setSelectionType(selectionType);
+ tree.setSelectionType(selectionType);
+ }
+
+ @Test
+ public void testTopLevelSelection() {
+ assertEquals(tree.getAnySelectedNodesCount(), 0);
+
+ for (TreeNodeModel treeNode : tree.getNodes()) {
+ assertFalse(treeNode.isSelected());
+ assertTrue(treeNode.isCollapsed());
+ treeNode.select();
+ assertTrue(treeNode.isSelected());
+ assertTrue(treeNode.isCollapsed());
+
+ assertEquals(tree.getAnySelectedNodesCount(), 1);
+ }
+ }
+
+ @Test
+ public void testSubNodesSelection() {
+ guardXhr(selenium).click(expandAll);
+ assertEquals(tree.getAnySelectedNodesCount(), 0);
+
+ for (Integer[] path : SUBNODE_SELECTION_PATHS) {
+ treeNode = null;
+ for (int index : path) {
+ treeNode = (treeNode == null) ? tree.getNode(index) :
treeNode.getNode(index);
+ }
+ assertFalse(treeNode.isSelected());
+ treeNode.select();
+ assertTrue(treeNode.isSelected());
+ assertEquals(tree.getAnySelectedNodesCount(), 1);
+ }
+ }
+
+ @Test
+ @Use(field = "selectionType", value =
"eventEnabledSelectionTypes")
+ public void testSubNodesSelectionEvents() {
+ guardXhr(selenium).click(expandAll);
+
+ Integer[] old = null;
+ for (Integer[] path : SUBNODE_SELECTION_PATHS) {
+ treeNode = null;
+ for (int index : path) {
+ treeNode = (treeNode == null) ? tree.getNode(index) :
treeNode.getNode(index);
+ }
+ treeNode.select();
+ assertEquals(getClientId(), "richTree");
+ assertEquals(getSelection(), path);
+ assertEquals(getNewSelection(), path);
+ if (old != null) {
+ assertEquals(getOldSelection(), old);
+ } else {
+ assertEquals(selenium.getText(oldSelection), "[]");
+ }
+ old = getNewSelection();
+ }
+ }
+
+ private Integer[] getSelection() {
+ String string = selenium.getText(selection);
+ return getIntsFromString(string);
+ }
+
+ private Integer[] getNewSelection() {
+ String string = selenium.getText(newSelection);
+ return getIntsFromString(string);
+ }
+
+ private Integer[] getOldSelection() {
+ String string = selenium.getText(oldSelection);
+ return getIntsFromString(string);
+ }
+
+ private String getClientId() {
+ return selenium.getText(clientId);
+ }
+
+ private Integer[] getIntsFromString(String string) {
+ Pattern pattern = Pattern.compile(".*\\[((?:(?:\\d+)(?:, )?)+)\\].*");
+ Matcher matcher = pattern.matcher(string);
+ if (matcher.find()) {
+ String[] strings = StringUtils.split(matcher.group(1), ", ");
+ Integer[] numbers = new Integer[strings.length];
+ for (int i = 0; i < strings.length; i++) {
+ numbers[i] = Integer.valueOf(strings[i]) + 1;
+ }
+ return numbers;
+ }
+ throw new IllegalStateException("pattern does not match");
+ }
+}
Modified:
modules/tests/metamer/trunk/ftest-source/src/main/java/org/richfaces/tests/metamer/ftest/richTree/TestTreeToggling.java
===================================================================
---
modules/tests/metamer/trunk/ftest-source/src/main/java/org/richfaces/tests/metamer/ftest/richTree/TestTreeToggling.java 2011-01-23
20:29:41 UTC (rev 21160)
+++
modules/tests/metamer/trunk/ftest-source/src/main/java/org/richfaces/tests/metamer/ftest/richTree/TestTreeToggling.java 2011-01-23
20:30:31 UTC (rev 21161)
@@ -94,7 +94,6 @@
}
@Test
- @IssueTracking("https://issues.jboss.org/browse/RF-10264")
public void testDeepExpansion() {
for (int[] path : PATHS) {
for (int d = 1; d <= path.length; d++) {
Modified:
modules/tests/metamer/trunk/ftest-source/src/main/java/org/richfaces/tests/metamer/ftest/richTree/TreeNodeModel.java
===================================================================
---
modules/tests/metamer/trunk/ftest-source/src/main/java/org/richfaces/tests/metamer/ftest/richTree/TreeNodeModel.java 2011-01-23
20:29:41 UTC (rev 21160)
+++
modules/tests/metamer/trunk/ftest-source/src/main/java/org/richfaces/tests/metamer/ftest/richTree/TreeNodeModel.java 2011-01-23
20:30:31 UTC (rev 21161)
@@ -22,10 +22,8 @@
package org.richfaces.tests.metamer.ftest.richTree;
import static org.jboss.test.selenium.guard.request.RequestTypeGuardFactory.guard;
-import static org.jboss.test.selenium.guard.request.RequestTypeGuardFactory.guardXhr;
import static org.jboss.test.selenium.locator.reference.ReferencedLocator.ref;
-import org.jboss.test.selenium.dom.Event;
import org.jboss.test.selenium.framework.AjaxSelenium;
import org.jboss.test.selenium.framework.AjaxSeleniumProxy;
import org.jboss.test.selenium.geometry.Point;
@@ -33,10 +31,7 @@
import org.jboss.test.selenium.locator.JQueryLocator;
import org.jboss.test.selenium.locator.reference.ReferencedLocator;
import org.jboss.test.selenium.request.RequestType;
-import org.junit.Assert;
import org.richfaces.component.SwitchType;
-import org.richfaces.tests.metamer.ftest.model.AbstractModel;
-import org.richfaces.tests.metamer.ftest.model.ModelIterable;
/**
* @author <a href="mailto:lfryc@redhat.com">Lukas Fryc</a>
@@ -46,8 +41,6 @@
private AjaxSelenium selenium = AjaxSeleniumProxy.getInstance();
- private ReferencedLocator<JQueryLocator> subnodes = ref(root,
TreeModel.treeNode.getRawLocator());
-
private String classNodeExpanded = "rf-tr-nd-exp";
private String classNodeLeaf = "rf-tr-nd-lf";
private String classNodeCollapsed = "rf-tr-nd-colps";
@@ -81,7 +74,7 @@
}
public boolean isSelected() {
- return selenium.belongsClass(root.getLocator(), classSelected);
+ return selenium.belongsClass(content, classSelected);
}
public boolean isExpanded() {
@@ -105,7 +98,7 @@
}
public void select() {
- guardXhr(selenium).clickAt(getLabel(), new Point(0,0));
+ guard(selenium, getRequestType(tree.getSelectionType())).clickAt(getLabel(), new
Point(0,0));
}
private RequestType getRequestType(SwitchType switchType) {