Author: lfryc(a)redhat.com
Date: 2011-01-14 08:52:42 -0500 (Fri, 14 Jan 2011)
New Revision: 21023
Added:
modules/tests/metamer/trunk/ftest-source/src/main/java/org/richfaces/tests/metamer/ftest/model/CollapsibleSubTable.java
modules/tests/metamer/trunk/ftest-source/src/main/java/org/richfaces/tests/metamer/ftest/model/CollapsibleSubTableToggler.java
modules/tests/metamer/trunk/ftest-source/src/main/java/org/richfaces/tests/metamer/ftest/richCollapsibleSubTable/
modules/tests/metamer/trunk/ftest-source/src/main/java/org/richfaces/tests/metamer/ftest/richCollapsibleSubTable/AbstractCollapsibleSubTableTest.java
modules/tests/metamer/trunk/ftest-source/src/main/java/org/richfaces/tests/metamer/ftest/richCollapsibleSubTable/CollapsibleSubTableAttributes.java
modules/tests/metamer/trunk/ftest-source/src/main/java/org/richfaces/tests/metamer/ftest/richCollapsibleSubTable/TestCollapsibleSubTableSimple.java
Modified:
modules/tests/metamer/trunk/ftest-source/src/main/java/org/richfaces/tests/metamer/ftest/model/DataTable.java
modules/tests/metamer/trunk/ftest-source/src/main/java/org/richfaces/tests/metamer/ftest/richCollapsibleSubTableToggler/TestCollapsibleSubTableToggler.java
Log:
rich:collapsibleSubTable - automated Simple sample (RFPL-731)
Added:
modules/tests/metamer/trunk/ftest-source/src/main/java/org/richfaces/tests/metamer/ftest/model/CollapsibleSubTable.java
===================================================================
---
modules/tests/metamer/trunk/ftest-source/src/main/java/org/richfaces/tests/metamer/ftest/model/CollapsibleSubTable.java
(rev 0)
+++
modules/tests/metamer/trunk/ftest-source/src/main/java/org/richfaces/tests/metamer/ftest/model/CollapsibleSubTable.java 2011-01-14
13:52:42 UTC (rev 21023)
@@ -0,0 +1,43 @@
+package org.richfaces.tests.metamer.ftest.model;
+
+import static org.jboss.test.selenium.locator.LocatorFactory.jq;
+
+import org.jboss.test.selenium.framework.AjaxSelenium;
+import org.jboss.test.selenium.framework.AjaxSeleniumProxy;
+import org.jboss.test.selenium.locator.JQueryLocator;
+
+public class CollapsibleSubTable extends AbstractModel<JQueryLocator> {
+
+ AjaxSelenium selenium = AjaxSeleniumProxy.getInstance();
+
+ JQueryLocator subtableRow = jq("tr[class^=rf-cst][class$=-r]");
+ JQueryLocator subtableCell = jq("td.rf-cst-c");
+
+ JQueryLocator visible = jq("{0}:visible");
+
+ public CollapsibleSubTable(JQueryLocator root) {
+ super(root);
+ }
+
+ public Iterable<JQueryLocator> getRows() {
+ return root.getLocator().getChildren(subtableRow);
+ }
+
+ public JQueryLocator getRow(int rowIndex) {
+ return root.getLocator().getChild(subtableRow).getNthOccurence(rowIndex);
+ }
+
+ public int getRowCount() {
+ return selenium.getCount(root.getLocator().getChild(subtableRow));
+ }
+
+ public boolean hasVisibleRows() {
+ JQueryLocator locator = root.getLocator().getChild(subtableRow);
+ locator = visible.format(locator.getRawLocator());
+ return selenium.isElementPresent(locator);
+ }
+
+ public JQueryLocator getCell(int column, int row) {
+ return getRow(row).getChild(subtableCell).getNthOccurence(column);
+ }
+}
Added:
modules/tests/metamer/trunk/ftest-source/src/main/java/org/richfaces/tests/metamer/ftest/model/CollapsibleSubTableToggler.java
===================================================================
---
modules/tests/metamer/trunk/ftest-source/src/main/java/org/richfaces/tests/metamer/ftest/model/CollapsibleSubTableToggler.java
(rev 0)
+++
modules/tests/metamer/trunk/ftest-source/src/main/java/org/richfaces/tests/metamer/ftest/model/CollapsibleSubTableToggler.java 2011-01-14
13:52:42 UTC (rev 21023)
@@ -0,0 +1,26 @@
+package org.richfaces.tests.metamer.ftest.model;
+
+import static org.jboss.test.selenium.locator.reference.ReferencedLocator.ref;
+
+import org.jboss.test.selenium.locator.ExtendedLocator;
+import org.jboss.test.selenium.locator.JQueryLocator;
+import org.jboss.test.selenium.locator.reference.ReferencedLocator;
+
+public class CollapsibleSubTableToggler extends AbstractModel<JQueryLocator> {
+
+ public CollapsibleSubTableToggler(JQueryLocator root) {
+ super(root);
+ }
+
+ ReferencedLocator<JQueryLocator> collapsedTogglers = ref(root, ">
span[id$=expand]");
+ ReferencedLocator<JQueryLocator> expandedTogglers = ref(root, ">
span[id$=collapse]");
+
+ public ExtendedLocator<JQueryLocator> getCollapsed() {
+ return collapsedTogglers;
+ }
+
+ public ExtendedLocator<JQueryLocator> getExpanded() {
+ return expandedTogglers;
+ }
+
+}
Modified:
modules/tests/metamer/trunk/ftest-source/src/main/java/org/richfaces/tests/metamer/ftest/model/DataTable.java
===================================================================
---
modules/tests/metamer/trunk/ftest-source/src/main/java/org/richfaces/tests/metamer/ftest/model/DataTable.java 2011-01-14
13:51:17 UTC (rev 21022)
+++
modules/tests/metamer/trunk/ftest-source/src/main/java/org/richfaces/tests/metamer/ftest/model/DataTable.java 2011-01-14
13:52:42 UTC (rev 21023)
@@ -50,7 +50,11 @@
ReferencedLocator<JQueryLocator> columnHeader = ref(thead, ">
tr.rf-dt-shdr > th.rf-dt-shdr-c");
ReferencedLocator<JQueryLocator> columnFooter = ref(root, ">
tfoot.rf-dt-tft > tr.rf-dt-sftr > td.rf-dt-sftr-c");
+
+ ReferencedLocator<JQueryLocator> subtables = ref(root, ">
tbody.rf-cst");
+ ReferencedLocator<JQueryLocator> togglers = ref(root,
"span[id$=subTableTC]");
+
public DataTable(JQueryLocator root) {
super(root);
}
@@ -103,5 +107,24 @@
public JQueryLocator getHeader() {
return tableHeader.getReferenced();
}
+
+ public CollapsibleSubTable getSubtable(int index) {
+ return new CollapsibleSubTable(subtables.getNthOccurence(index));
+ }
+ public Iterable<CollapsibleSubTable> getSubtables() {
+ return new ModelIterable<JQueryLocator,
CollapsibleSubTable>(subtables.getAllOccurrences(), CollapsibleSubTable.class);
+ }
+
+ public int getSubtableCount() {
+ return selenium.getCount(subtables);
+ }
+
+ public int getTogglerCount() {
+ return selenium.getCount(togglers);
+ }
+
+ public CollapsibleSubTableToggler getToggler(int index) {
+ return new CollapsibleSubTableToggler(togglers.getNthOccurence(index));
+ }
}
Added:
modules/tests/metamer/trunk/ftest-source/src/main/java/org/richfaces/tests/metamer/ftest/richCollapsibleSubTable/AbstractCollapsibleSubTableTest.java
===================================================================
---
modules/tests/metamer/trunk/ftest-source/src/main/java/org/richfaces/tests/metamer/ftest/richCollapsibleSubTable/AbstractCollapsibleSubTableTest.java
(rev 0)
+++
modules/tests/metamer/trunk/ftest-source/src/main/java/org/richfaces/tests/metamer/ftest/richCollapsibleSubTable/AbstractCollapsibleSubTableTest.java 2011-01-14
13:52:42 UTC (rev 21023)
@@ -0,0 +1,78 @@
+package org.richfaces.tests.metamer.ftest.richCollapsibleSubTable;
+
+import java.util.LinkedList;
+import java.util.List;
+
+import org.richfaces.tests.metamer.bean.Model;
+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.richfaces.tests.metamer.ftest.model.CollapsibleSubTable;
+import org.richfaces.tests.metamer.ftest.model.CollapsibleSubTableToggler;
+import org.richfaces.tests.metamer.ftest.model.DataTable;
+import org.richfaces.tests.metamer.model.Employee;
+import org.testng.annotations.BeforeMethod;
+
+import com.google.common.base.Predicate;
+import com.google.common.collect.Collections2;
+
+public abstract class AbstractCollapsibleSubTableTest extends AbstractMetamerTest {
+
+ private static final List<Employee> EMPLOYEES = Model.unmarshallEmployees();
+
+ CollapsibleSubTableAttributes attributes = new CollapsibleSubTableAttributes();
+ DataTable model = new DataTable(pjq("table.rf-dt"));;
+
+ @Inject
+ @Use(value = "configuration*")
+ Configuration configuration;
+ Configuration configurationMen = new Configuration(1, "Men");
+ Configuration configurationWomen = new Configuration(2, "Women");
+
+ CollapsibleSubTable subtable;
+ CollapsibleSubTableToggler toggler;
+ List<Employee> employees;
+
+ Configuration secondConfiguration;
+ CollapsibleSubTable secondSubtable;
+ CollapsibleSubTableToggler secondToggler;
+
+ @BeforeMethod
+ public void configure() {
+ if (configuration != null) {
+ subtable = configuration.subtable;
+ toggler = configuration.toggler;
+ employees = configuration.employees;
+
+ secondConfiguration = configuration.name.equals("Men") ?
configurationWomen : configurationMen;
+ secondSubtable = secondConfiguration.subtable;
+ secondToggler = secondConfiguration.toggler;
+ }
+ }
+
+ public class Configuration {
+ CollapsibleSubTable subtable;
+ CollapsibleSubTableToggler toggler;
+ List<Employee> employees;
+ String name;
+
+ public Configuration(int i, String name) {
+ this.name = name;
+ subtable = model.getSubtable(i);
+ toggler = model.getToggler(i);
+ final Employee.Sex sex = (i == 1) ? Employee.Sex.MALE : Employee.Sex.FEMALE;
+
+ employees = new LinkedList<Employee>(Collections2.filter(EMPLOYEES, new
Predicate<Employee>() {
+ @Override
+ public boolean apply(Employee input) {
+ return sex.equals(input.getSex());
+ }
+ }));
+ }
+
+ @Override
+ public String toString() {
+ return name;
+ }
+ }
+}
Added:
modules/tests/metamer/trunk/ftest-source/src/main/java/org/richfaces/tests/metamer/ftest/richCollapsibleSubTable/CollapsibleSubTableAttributes.java
===================================================================
---
modules/tests/metamer/trunk/ftest-source/src/main/java/org/richfaces/tests/metamer/ftest/richCollapsibleSubTable/CollapsibleSubTableAttributes.java
(rev 0)
+++
modules/tests/metamer/trunk/ftest-source/src/main/java/org/richfaces/tests/metamer/ftest/richCollapsibleSubTable/CollapsibleSubTableAttributes.java 2011-01-14
13:52:42 UTC (rev 21023)
@@ -0,0 +1,41 @@
+package org.richfaces.tests.metamer.ftest.richCollapsibleSubTable;
+
+import java.util.Collection;
+
+import org.richfaces.ExpandMode;
+import org.richfaces.model.SortMode;
+import org.richfaces.tests.metamer.ftest.AbstractComponentAttributes;
+
+public class CollapsibleSubTableAttributes extends AbstractComponentAttributes {
+ public void setExpandMode(ExpandMode expandMode) {
+ setProperty("expandMode", expandMode);
+ }
+
+ public void setExpanded(Boolean expanded) {
+ setProperty("expanded", expanded);
+ }
+
+ public void setFirst(Integer first) {
+ setProperty("first", first);
+ }
+
+ public void setNoDataLabel(String noDataLabel) {
+ setProperty("noDataLabel", noDataLabel);
+ }
+
+ public void setRendered(Boolean rendered) {
+ setProperty("rendered", rendered);
+ }
+
+ public void setRows(Integer rows) {
+ setProperty("rows", rows);
+ }
+
+ public void setSortMode(SortMode sortMode) {
+ setProperty("sortMode", sortMode);
+ }
+
+ public void setSortPriority(Collection<String> sortPriority) {
+ setProperty("sortPriority", sortPriority);
+ }
+}
Added:
modules/tests/metamer/trunk/ftest-source/src/main/java/org/richfaces/tests/metamer/ftest/richCollapsibleSubTable/TestCollapsibleSubTableSimple.java
===================================================================
---
modules/tests/metamer/trunk/ftest-source/src/main/java/org/richfaces/tests/metamer/ftest/richCollapsibleSubTable/TestCollapsibleSubTableSimple.java
(rev 0)
+++
modules/tests/metamer/trunk/ftest-source/src/main/java/org/richfaces/tests/metamer/ftest/richCollapsibleSubTable/TestCollapsibleSubTableSimple.java 2011-01-14
13:52:42 UTC (rev 21023)
@@ -0,0 +1,147 @@
+package org.richfaces.tests.metamer.ftest.richCollapsibleSubTable;
+
+import static org.jboss.test.selenium.guard.request.RequestTypeGuardFactory.guard;
+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 static org.testng.Assert.fail;
+
+import java.net.URL;
+import java.util.List;
+
+import org.jboss.test.selenium.request.RequestType;
+import org.richfaces.ExpandMode;
+import org.richfaces.component.UICollapsibleSubTable;
+import org.richfaces.tests.metamer.ftest.annotations.Inject;
+import org.richfaces.tests.metamer.ftest.annotations.IssueTracking;
+import org.richfaces.tests.metamer.ftest.annotations.Use;
+import org.richfaces.tests.metamer.model.Employee;
+import org.testng.annotations.Test;
+
+public class TestCollapsibleSubTableSimple extends AbstractCollapsibleSubTableTest {
+
+ @Override
+ public URL getTestUrl() {
+ return buildUrl(contextPath,
"faces/components/richCollapsibleSubTable/simple.xhtml");
+ }
+
+ @Inject
+ @Use(empty = true)
+ ExpandMode expandMode;
+
+ @Test
+ @Use(field = "expandMode", enumeration = true)
+ @IssueTracking("https://issues.jboss.org/browse/RF-10181")
+ public void testExpandMode() {
+ final RequestType requestType = getRequestTypeForExpandMode();
+
+ attributes.setExpandMode(expandMode);
+
+ assertTrue(subtable.hasVisibleRows());
+ assertTrue(secondSubtable.hasVisibleRows());
+
+ if (expandMode == ExpandMode.none) {
+ guard(selenium, requestType).click(toggler);
+ assertEquals(subtable.hasVisibleRows(), ExpandMode.none == expandMode);
+ assertTrue(secondSubtable.hasVisibleRows());
+ } else {
+ for (int i = 0; i < 2; i++) {
+ guard(selenium, requestType).click(toggler);
+ assertFalse(subtable.hasVisibleRows());
+ assertTrue(secondSubtable.hasVisibleRows());
+
+ guard(selenium, requestType).click(toggler);
+ assertTrue(subtable.hasVisibleRows());
+ assertTrue(secondSubtable.hasVisibleRows());
+ }
+ }
+ }
+
+ @Test
+ @Use(field = "configuration", empty = true)
+ public void testExpanded() {
+ attributes.setExpanded(false);
+
+ assertFalse(configurationMen.subtable.hasVisibleRows());
+ assertFalse(configurationWomen.subtable.hasVisibleRows());
+
+ selenium.click(configurationMen.toggler);
+ assertTrue(configurationMen.subtable.hasVisibleRows());
+
+ attributes.setExpanded(true);
+
+ assertTrue(configurationMen.subtable.hasVisibleRows());
+ assertTrue(configurationWomen.subtable.hasVisibleRows());
+
+ new UICollapsibleSubTable().getCaptionClass();
+ }
+
+ @Test
+ public void testFirst() {
+ attributes.setFirst(2);
+
+ List<Employee> visibleEmployees = employees.subList(2,
subtable.getRowCount());
+
+ for (int i = 0; i < visibleEmployees.size(); i++) {
+ String name = selenium.getText(subtable.getCell(1, i + 1));
+ String title = selenium.getText(subtable.getCell(2, i + 1));
+
+ assertEquals(name, visibleEmployees.get(i).getName());
+ assertEquals(title, visibleEmployees.get(i).getTitle());
+ }
+ }
+
+ @Test
+ @Use(field = "configuration", empty = true)
+ public void testRendered() {
+ attributes.setRendered(false);
+
+ assertFalse(configurationMen.subtable.hasVisibleRows());
+ assertFalse(configurationWomen.subtable.hasVisibleRows());
+
+ selenium.click(configurationMen.toggler);
+ assertFalse(configurationMen.subtable.hasVisibleRows());
+
+ attributes.setRendered(true);
+
+ assertTrue(configurationMen.subtable.hasVisibleRows());
+ assertTrue(configurationWomen.subtable.hasVisibleRows());
+ }
+
+ @Test
+ public void testRows() {
+ attributes.setRows(11);
+
+ List<Employee> visibleEmployees = employees.subList(0, 11);
+
+ assertEquals(subtable.getRowCount(), 11);
+
+ for (int i = 0; i < visibleEmployees.size(); i++) {
+ String name = selenium.getText(subtable.getCell(1, i + 1));
+ String title = selenium.getText(subtable.getCell(2, i + 1));
+
+ assertEquals(name, visibleEmployees.get(i).getName());
+ assertEquals(title, visibleEmployees.get(i).getTitle());
+ }
+ }
+
+ @Test
+ @IssueTracking("https://issues.jboss.org/browse/RF-10217")
+ @Use(field = "configuration", empty = true)
+ public void testClasses() {
+ // TODO classes are currently not working
+ fail();
+ }
+
+ private RequestType getRequestTypeForExpandMode() {
+ switch (expandMode) {
+ case ajax:
+ return RequestType.XHR;
+ case server:
+ return RequestType.HTTP;
+ default:
+ return RequestType.NONE;
+ }
+ }
+}
Modified:
modules/tests/metamer/trunk/ftest-source/src/main/java/org/richfaces/tests/metamer/ftest/richCollapsibleSubTableToggler/TestCollapsibleSubTableToggler.java
===================================================================
---
modules/tests/metamer/trunk/ftest-source/src/main/java/org/richfaces/tests/metamer/ftest/richCollapsibleSubTableToggler/TestCollapsibleSubTableToggler.java 2011-01-14
13:51:17 UTC (rev 21022)
+++
modules/tests/metamer/trunk/ftest-source/src/main/java/org/richfaces/tests/metamer/ftest/richCollapsibleSubTableToggler/TestCollapsibleSubTableToggler.java 2011-01-14
13:52:42 UTC (rev 21023)
@@ -25,8 +25,10 @@
* @author <a href="mailto:lfryc@redhat.com">Lukas Fryc</a>
* @version $Revision$
*/
+import static org.jboss.test.selenium.dom.Event.DBLCLICK;
+import static org.jboss.test.selenium.dom.Event.MOUSEDOWN;
+import static org.jboss.test.selenium.dom.Event.MOUSEUP;
import static org.jboss.test.selenium.locator.Attribute.SRC;
-import static org.jboss.test.selenium.dom.Event.*;
import static org.jboss.test.selenium.locator.LocatorFactory.jq;
import static org.jboss.test.selenium.utils.URLUtils.buildUrl;
import static org.testng.Assert.assertEquals;
@@ -41,6 +43,9 @@
import org.richfaces.tests.metamer.ftest.annotations.Inject;
import org.richfaces.tests.metamer.ftest.annotations.IssueTracking;
import org.richfaces.tests.metamer.ftest.annotations.Use;
+import org.richfaces.tests.metamer.ftest.model.CollapsibleSubTable;
+import org.richfaces.tests.metamer.ftest.model.CollapsibleSubTableToggler;
+import org.richfaces.tests.metamer.ftest.model.DataTable;
import org.testng.annotations.Test;
public class TestCollapsibleSubTableToggler extends AbstractMetamerTest {
@@ -48,27 +53,23 @@
private final static String IMAGE_URL = "/resources/images/star.png";
private final static String LABEL = "Label";
- @Override
- public URL getTestUrl() {
- return buildUrl(contextPath,
"faces/components/richCollapsibleSubTableToggler/simple.xhtml");
- }
-
- CollapsibleSubTableTogglerAttributes attributes = new
CollapsibleSubTableTogglerAttributes();
-
- JQueryLocator togglers = pjq("span[id$=richSTTControl]");
- JQueryLocator collapsedTogglers =
togglers.getChild(jq("span[id$=expand]"));
- JQueryLocator expandedTogglers =
togglers.getChild(jq("span[id$=collapse]"));
JQueryLocator link = jq("a");
JQueryLocator image = jq("img");
- JQueryLocator subtables = pjq("table.rf-dt > tbody.rf-cst");
-
@Inject
@Use(empty = true)
Event event;
Event[] events = new Event[] { DBLCLICK, MOUSEDOWN, MOUSEUP };
+ @Override
+ public URL getTestUrl() {
+ return buildUrl(contextPath,
"faces/components/richCollapsibleSubTableToggler/simple.xhtml");
+ }
+
+ CollapsibleSubTableTogglerAttributes attributes = new
CollapsibleSubTableTogglerAttributes();
+ DataTable dataTable = new DataTable(pjq("table.rf-dt"));
+
@Test
@Use(field = "event", value = "events")
public void testEvent() {
@@ -83,7 +84,7 @@
public void testRendered() {
attributes.setRendered(false);
- assertFalse(selenium.isElementPresent(togglers));
+ assertEquals(dataTable.getTogglerCount(), 0);
}
@Test
@@ -212,9 +213,9 @@
JQueryLocator expander;
JQueryLocator collapser;
- JQueryLocator togglerRoot;
+ CollapsibleSubTableToggler togglerRoot;
- JQueryLocator subtable;
+ CollapsibleSubTable subtable;
JQueryLocator togglerExpanded;
JQueryLocator togglerCollapsed;
@@ -225,10 +226,10 @@
public void testToggler() {
for (int i = 1; i <= 2; i++) {
- subtable = subtables.getNthOccurence(i);
- togglerRoot = togglers.getNthOccurence(i);
- togglerExpanded =
expandedTogglers.getNthOccurence(i).getChild(expander);
- togglerCollapsed =
collapsedTogglers.getNthOccurence(i).getChild(collapser);
+ subtable = dataTable.getSubtable(i);
+ togglerRoot = dataTable.getToggler(i);
+ togglerExpanded =
dataTable.getToggler(i).getExpanded().getChild(expander);
+ togglerCollapsed =
dataTable.getToggler(i).getCollapsed().getChild(collapser);
verifyBefore();