Author: jpapouse
Date: 2011-11-18 11:14:43 -0500 (Fri, 18 Nov 2011)
New Revision: 22962
Added:
modules/tests/metamer/trunk/ftest-source/src/main/java/org/richfaces/tests/metamer/ftest/richDataScroller/TestDataScrollerAttributes.java
Modified:
modules/tests/metamer/trunk/application/src/main/webapp/components/richDataScroller/simple.xhtml
modules/tests/metamer/trunk/ftest-source/src/main/java/org/richfaces/tests/metamer/ftest/model/DataScroller.java
modules/tests/metamer/trunk/ftest-source/src/main/java/org/richfaces/tests/metamer/ftest/richDataScroller/DataScrollerAttributes.java
Log:
RFPL-1738: tests for some attributes (rich:dataScroller)
Modified:
modules/tests/metamer/trunk/application/src/main/webapp/components/richDataScroller/simple.xhtml
===================================================================
---
modules/tests/metamer/trunk/application/src/main/webapp/components/richDataScroller/simple.xhtml 2011-11-18
12:31:06 UTC (rev 22961)
+++
modules/tests/metamer/trunk/application/src/main/webapp/components/richDataScroller/simple.xhtml 2011-11-18
16:14:43 UTC (rev 22962)
@@ -51,10 +51,15 @@
for="#{richDataScrollerBean.attributes['for'].value}"
boundaryControls="#{richDataScrollerBean.attributes['boundaryControls'].value}"
+
data="#{richDataScrollerBean.attributes['data'].value}"
+
execute="#{richDataScrollerBean.attributes['execute'].value}"
fastControls="#{richDataScrollerBean.attributes['fastControls'].value}"
fastStep="#{richDataScrollerBean.attributes['fastStep'].value}"
lastPageMode="#{richDataScrollerBean.attributes['lastPageMode'].value}"
maxPages="#{richDataScrollerBean.attributes['maxPages'].value}"
+
onbegin="#{richDataScrollerBean.attributes['onbegin'].value}"
+
onbeforedomupdate="#{richDataScrollerBean.attributes['onbeforedomupdate'].value}"
+
oncomplete="#{richDataScrollerBean.attributes['oncomplete'].value}"
page="#{richDataScrollerBean.attributes['page'].value}"
render="#{richDataScrollerBean.attributes['render'].value}
#{nestedComponentId}"
renderIfSinglePage="#{richDataScrollerBean.attributes['renderIfSinglePage'].value}"
@@ -106,6 +111,9 @@
first="#{richDataScrollerBean.attributes['first'].value}"
lastPageMode="#{richDataScrollerBean.attributes['lastPageMode'].value}"
maxPages="#{richDataScrollerBean.attributes['maxPages'].value}"
+
onbegin="#{richDataScrollerBean.attributes['onbegin'].value}"
+
onbeforedomupdate="#{richDataScrollerBean.attributes['onbeforedomupdate'].value}"
+
oncomplete="#{richDataScrollerBean.attributes['oncomplete'].value}"
page="#{richDataScrollerBean.attributes['page'].value}"
render="#{richDataScrollerBean.attributes['render'].value} scroller1"
renderIfSinglePage="#{richDataScrollerBean.attributes['renderIfSinglePage'].value}"
Modified:
modules/tests/metamer/trunk/ftest-source/src/main/java/org/richfaces/tests/metamer/ftest/model/DataScroller.java
===================================================================
---
modules/tests/metamer/trunk/ftest-source/src/main/java/org/richfaces/tests/metamer/ftest/model/DataScroller.java 2011-11-18
12:31:06 UTC (rev 22961)
+++
modules/tests/metamer/trunk/ftest-source/src/main/java/org/richfaces/tests/metamer/ftest/model/DataScroller.java 2011-11-18
16:14:43 UTC (rev 22962)
@@ -35,6 +35,7 @@
* Provides DataScroller control methods.
*
* @author <a href="mailto:lfryc@redhat.com">Lukas Fryc</a>
+ * @author <a href="mailto:jpapouse@redhat.com">Jan Papousek</a>
* @version $Revision$
*/
public class DataScroller extends AbstractModel<JQueryLocator> {
@@ -49,6 +50,9 @@
ReferencedLocator<JQueryLocator> firstPageButton = ref(root, ">
.rf-ds-btn-first");
ReferencedLocator<JQueryLocator> fastRewindButton = ref(root, ">
.rf-ds-btn-fastrwd");
ReferencedLocator<JQueryLocator> fastForwardButton = ref(root, ">
.rf-ds-btn-fastfwd");
+ ReferencedLocator<JQueryLocator> nextButton = ref(root, ">
.rf-ds-btn-next");
+ ReferencedLocator<JQueryLocator> previousButton = ref(root, ">
.rf-ds-btn-prev");
+ ReferencedLocator<JQueryLocator> rewindButton = ref(root, ">
.rf-ds-btn-fastfwd");
ReferencedLocator<JQueryLocator> lastPageButton = ref(root, ">
.rf-ds-btn-last");
ReferencedLocator<JQueryLocator> firstVisiblePage = ref(root, ">
.rf-ds-nmb-btn:first");
@@ -213,14 +217,42 @@
return integer(selenium.getText(currentPage));
}
+ public boolean isFastForwardButtonPresent() {
+ return selenium.isElementPresent(fastForwardButton);
+ }
+
+ public boolean isFastRewindButtonPresent() {
+ return selenium.isElementPresent(fastRewindButton);
+ }
+
public boolean isFirstPage() {
return getCurrentPage() == 1;
}
+ public boolean isFirstPageButtonPresent() {
+ return selenium.isElementPresent(firstPageButton);
+ }
+
public boolean isLastPage() {
return getCurrentPage() == getLastVisiblePage();
}
+ public boolean isLastPageButtonPresent() {
+ return selenium.isElementPresent(lastPageButton);
+ }
+
+ public boolean isNextButtonPresent() {
+ return selenium.isElementPresent(previousButton);
+ }
+
+ public boolean isPreviousButtonPresent() {
+ return selenium.isElementPresent(previousButton);
+ }
+
+ public boolean isPresent() {
+ return selenium.isElementPresent(root.getLocator());
+ }
+
public static int integer(String string) {
return Integer.valueOf(string);
}
Modified:
modules/tests/metamer/trunk/ftest-source/src/main/java/org/richfaces/tests/metamer/ftest/richDataScroller/DataScrollerAttributes.java
===================================================================
---
modules/tests/metamer/trunk/ftest-source/src/main/java/org/richfaces/tests/metamer/ftest/richDataScroller/DataScrollerAttributes.java 2011-11-18
12:31:06 UTC (rev 22961)
+++
modules/tests/metamer/trunk/ftest-source/src/main/java/org/richfaces/tests/metamer/ftest/richDataScroller/DataScrollerAttributes.java 2011-11-18
16:14:43 UTC (rev 22962)
@@ -29,7 +29,25 @@
*/
public enum DataScrollerAttributes implements AttributeEnum {
+ boundaryControls,
+ data,
+ execute,
+ fastControls,
fastStep,
- maxPages
+ lastPageMode,
+ limitRenderer,
+ maxPages,
+ onbeforedomupdate,
+ onbegin,
+ oncomplete,
+ page,
+ render,
+ rendered,
+ renderIfSinglePage,
+ status,
+ stepControls,
+ style,
+ styleClass,
+ title
}
Added:
modules/tests/metamer/trunk/ftest-source/src/main/java/org/richfaces/tests/metamer/ftest/richDataScroller/TestDataScrollerAttributes.java
===================================================================
---
modules/tests/metamer/trunk/ftest-source/src/main/java/org/richfaces/tests/metamer/ftest/richDataScroller/TestDataScrollerAttributes.java
(rev 0)
+++
modules/tests/metamer/trunk/ftest-source/src/main/java/org/richfaces/tests/metamer/ftest/richDataScroller/TestDataScrollerAttributes.java 2011-11-18
16:14:43 UTC (rev 22962)
@@ -0,0 +1,146 @@
+/*******************************************************************************
+ * JBoss, Home of Professional Open Source
+ * Copyright 2010-2011, 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.richDataScroller;
+
+import static org.jboss.test.selenium.utils.URLUtils.buildUrl;
+
+import java.net.URL;
+import java.util.Arrays;
+
+import org.jboss.test.selenium.encapsulated.JavaScript;
+import org.richfaces.tests.metamer.ftest.AbstractMetamerTest;
+import org.richfaces.tests.metamer.ftest.attributes.Attributes;
+import org.richfaces.tests.metamer.ftest.model.DataScroller;
+import org.testng.annotations.Test;
+import static org.testng.Assert.*;
+
+/**
+ * Test the functionality of switching pages using DataScroller bound to DataTable.
+ *
+ * @author <a href="mailto:jpapouse@redhat.com">Jan Papousek</a>
+ */
+public class TestDataScrollerAttributes extends AbstractMetamerTest {
+
+ private final Attributes<DataScrollerAttributes> attributes = new
Attributes<DataScrollerAttributes>();
+ private final DataScroller scroller = PaginationTester.DATA_SCROLLER_OUTSIDE_TABLE;
+
+ @Override
+ public URL getTestUrl() {
+ return buildUrl(contextPath,
"faces/components/richDataScroller/simple.xhtml");
+ }
+
+ @Test
+ public void testBoundaryControls() {
+ // init - show
+ assertTrue(getScroller().isFirstPageButtonPresent(), "The first button
should be present.");
+ assertTrue(getScroller().isLastPageButtonPresent(), "The last button should
be present.");
+ // hide
+ getAttributes().set(DataScrollerAttributes.boundaryControls, "hide");
+ assertFalse(getScroller().isFirstPageButtonPresent(), "The first button
shouldn't be present.");
+ assertFalse(getScroller().isLastPageButtonPresent(), "The last button
shouldn't be present.");
+ }
+
+ @Test
+ public void testEvents() throws InterruptedException {
+ // set event attributes
+ getAttributes().set(DataScrollerAttributes.onbeforedomupdate, "metamerEvents
+= \"beforedomupdate \"");
+ getAttributes().set(DataScrollerAttributes.onbegin, "metamerEvents +=
\"begin \"");
+ getAttributes().set(DataScrollerAttributes.oncomplete, "metamerEvents +=
\"complete \"");
+ // reset events
+ selenium.getEval(new JavaScript("window.metamerEvents =
\"\";"));
+ // action
+ retrieveRequestTime.initializeValue();
+ getScroller().clickFastForward();
+ waitGui.waitForChange(retrieveRequestTime);
+ // check events
+ String[] events = selenium.getEval(new
JavaScript("window.metamerEvents")).split(" ");
+ assertEquals(events.length, 3, "3 events should be fired, found events are
" + Arrays.toString(events) + ".");
+ assertEquals(events[0], "begin", "Attribute onbegin doesn't
work, found events are " + Arrays.toString(events) + ".");
+ assertEquals(events[1], "beforedomupdate", "Attribute
onbeforedomupdate doesn't work, found events are " + Arrays.toString(events) +
".");
+ assertEquals(events[2], "complete", "Attribute oncomplete
doesn't work, found events are " + Arrays.toString(events) + ".");
+ }
+
+ @Test
+ public void testFastControls() {
+ // init - show
+ assertTrue(getScroller().isFastForwardButtonPresent(), "The fast forward
button should be present.");
+ assertTrue(getScroller().isFastRewindButtonPresent(), "The fast rewind
button should be present.");
+ // hide
+ getAttributes().set(DataScrollerAttributes.fastControls, "hide");
+ assertFalse(getScroller().isFastForwardButtonPresent(), "The fast forward
button shouldn't be present.");
+ assertFalse(getScroller().isFastRewindButtonPresent(), "The fast rewind
button shouldn't be present.");
+ }
+
+ @Test
+ public void testFastStep() {
+ getAttributes().set(DataScrollerAttributes.fastStep, 3);
+ retrieveRequestTime.initializeValue();
+ getScroller().clickFastForward();
+ waitGui.waitForChange(retrieveRequestTime);
+ assertEquals(getScroller().getCurrentPage(), 4, "After clicking on the fast
forward button, the current page doesn't match.");
+ retrieveRequestTime.initializeValue();
+ getScroller().clickFastRewind();
+ waitGui.waitForChange(retrieveRequestTime);
+ assertEquals(getScroller().getCurrentPage(), 1, "After clicking on the fast
rewind button, the current page doesn't match.");
+ }
+
+ @Test
+ public void testMaxPages() {
+ // init - 10
+ assertEquals(getScroller().getCountOfVisiblePages(), 6 /* it means - all pages
*/, "The number of visible pages doesn't match.");
+ // smaller number
+ getAttributes().set(DataScrollerAttributes.maxPages, 3);
+ assertEquals(getScroller().getCountOfVisiblePages(), 3, "The number of
visible pages doesn't match.");
+ }
+
+ @Test
+ public void testPage() {
+ getAttributes().set(DataScrollerAttributes.page, 4);
+ assertEquals(getScroller().getCurrentPage(), 4, "The number of current page
doesn't match.");
+ }
+
+ @Test
+ public void testRendered() {
+ getAttributes().set(DataScrollerAttributes.rendered, false);
+ assertFalse(getScroller().isPresent(), "The data scroller shouldn't be
present.");
+ }
+
+ @Test
+ public void testStepControls() {
+ // init - show
+ assertTrue(getScroller().isNextButtonPresent(), "The next button should be
present.");
+ assertTrue(getScroller().isPreviousButtonPresent(), "The previous button
should be present.");
+ // hide
+ getAttributes().set(DataScrollerAttributes.stepControls, "hide");
+ assertFalse(getScroller().isNextButtonPresent(), "The next button
shouldn't be present.");
+ assertFalse(getScroller().isPreviousButtonPresent(), "The previous button
shouldn't be present.");
+ }
+
+ private Attributes<DataScrollerAttributes> getAttributes() {
+ return attributes;
+ }
+
+ private DataScroller getScroller() {
+ return scroller;
+ }
+
+}