Author: jjamrich
Date: 2011-06-01 11:17:43 -0400 (Wed, 01 Jun 2011)
New Revision: 22518
Modified:
modules/tests/metamer/trunk/ftest-source/src/main/java/org/richfaces/tests/metamer/ftest/richInputNumberSpinner/TestRichSpinnerWithJSR303.java
Log:
Add tests for validation on spinnig
Modified:
modules/tests/metamer/trunk/ftest-source/src/main/java/org/richfaces/tests/metamer/ftest/richInputNumberSpinner/TestRichSpinnerWithJSR303.java
===================================================================
---
modules/tests/metamer/trunk/ftest-source/src/main/java/org/richfaces/tests/metamer/ftest/richInputNumberSpinner/TestRichSpinnerWithJSR303.java 2011-05-31
15:19:04 UTC (rev 22517)
+++
modules/tests/metamer/trunk/ftest-source/src/main/java/org/richfaces/tests/metamer/ftest/richInputNumberSpinner/TestRichSpinnerWithJSR303.java 2011-06-01
15:17:43 UTC (rev 22518)
@@ -21,9 +21,11 @@
*******************************************************************************/
package org.richfaces.tests.metamer.ftest.richInputNumberSpinner;
+import static org.jboss.test.selenium.locator.LocatorFactory.jq;
+
import java.net.URL;
-
import org.jboss.test.selenium.dom.Event;
+import org.jboss.test.selenium.geometry.Point;
import org.jboss.test.selenium.locator.JQueryLocator;
import org.jboss.test.selenium.utils.URLUtils;
import org.richfaces.tests.metamer.ftest.AbstractMetamerTest;
@@ -38,13 +40,6 @@
*/
public class TestRichSpinnerWithJSR303 extends AbstractMetamerTest {
- /** Code for input validated to min value */
- public static final int MIN_ID = 1;
- /** Code for input validated to max value */
- public static final int MAX_ID = 2;
- /** Code for input validated to custom condition */
- public static final int CUSTOM_ID = 3;
-
/** Wrong value for input validated to min value */
public static final String WRONG_MIN_VAL = "1";
/** Wrong value for input validated to max value */
@@ -74,26 +69,73 @@
private JQueryLocator hCommandBtn = pjq("input[id$=:hButton]");
private JQueryLocator a4jCommandBtn = pjq("input[id$=:a4jButton]");
+ private JQueryLocator spinnerIncFormat = jq("span[id$=:input{0}]
span.rf-insp-inc");
+ private JQueryLocator spinnerDecFormat = jq("span[id$=:input{0}]
span.rf-insp-dec");
+
+ /** Codes for inputs */
+ private enum ID {
+ /** input validated to min val */
+ MIN(1),
+ /** input validated to max val */
+ MAX(2),
+ /** input validated to custom (positive) val */
+ CUSTOM(3);
+
+ private int id;
+ private ID(int i) {
+ this.id = i;
+ }
+ public int val() {
+ return id;
+ }
+ }
+
private void setAllCorrect() {
- selenium.type(inputFormat.format(MIN_ID), CORRECT_MIN_VAL);
- selenium.fireEvent(inputFormat.format(MIN_ID), Event.BLUR);
- selenium.type(inputFormat.format(MAX_ID), CORRECT_MAX_VAL);
- selenium.fireEvent(inputFormat.format(MAX_ID), Event.BLUR);
- selenium.type(inputFormat.format(CUSTOM_ID), CORRECT_CUSTOM_VAL);
- selenium.fireEvent(inputFormat.format(CUSTOM_ID), Event.BLUR);
+ selenium.type(inputFormat.format(ID.MIN.val()), CORRECT_MIN_VAL);
+ selenium.fireEvent(inputFormat.format(ID.MIN.val()), Event.BLUR);
+ selenium.type(inputFormat.format(ID.MAX.val()), CORRECT_MAX_VAL);
+ selenium.fireEvent(inputFormat.format(ID.MAX.val()), Event.BLUR);
+ selenium.type(inputFormat.format(ID.CUSTOM.val()), CORRECT_CUSTOM_VAL);
+ selenium.fireEvent(inputFormat.format(ID.CUSTOM.val()), Event.BLUR);
}
private void setAllWrong() {
- selenium.type(inputFormat.format(MIN_ID), WRONG_MIN_VAL);
- selenium.fireEvent(inputFormat.format(MIN_ID), Event.BLUR);
- selenium.type(inputFormat.format(MAX_ID), WRONG_MAX_VAL);
- selenium.fireEvent(inputFormat.format(MAX_ID), Event.BLUR);
- selenium.type(inputFormat.format(CUSTOM_ID), WRONG_CUSTOM_VAL);
- selenium.fireEvent(inputFormat.format(CUSTOM_ID), Event.BLUR);
+ selenium.type(inputFormat.format(ID.MIN.val()), WRONG_MIN_VAL);
+ selenium.fireEvent(inputFormat.format(ID.MIN.val()), Event.BLUR);
+ selenium.type(inputFormat.format(ID.MAX.val()), WRONG_MAX_VAL);
+ selenium.fireEvent(inputFormat.format(ID.MAX.val()), Event.BLUR);
+ selenium.type(inputFormat.format(ID.CUSTOM.val()), WRONG_CUSTOM_VAL);
+ selenium.fireEvent(inputFormat.format(ID.CUSTOM.val()), Event.BLUR);
// wait until validation appears on last input before go ahead (e.g. submit
form)
- waitGui.until(textEquals.locator(msgFormat.format(CUSTOM_ID)).text(MSG_CUSTOM));
+
waitGui.until(textEquals.text(MSG_CUSTOM).locator(msgFormat.format(ID.CUSTOM.val())));
}
+
+ private void spinUp(ID inputId, String toValue) {
+ int currentVal =
Integer.parseInt(selenium.getValue(inputFormat.format(inputId.val())));
+ int diff = Integer.parseInt(toValue) - currentVal;
+
+ if (diff < 0) {
+ throw new IllegalArgumentException("Cannot spin from " + currentVal
+ " to " + toValue);
+ }
+
+ for (int i = 0; i < diff; ++i) {
+ selenium.clickAt(spinnerIncFormat.format(inputId.val()), new Point(1, 1));
+ }
+ }
+
+ private void spinDown(ID inputId, String toValue) {
+ int currentVal =
Integer.parseInt(selenium.getValue(inputFormat.format(inputId.val())));
+ int diff = currentVal - Integer.parseInt(toValue);
+
+ if (diff < 0) {
+ throw new IllegalArgumentException("Cannot spin from " + currentVal
+ " to " + toValue);
+ }
+
+ for (int i = 0; i < diff; ++i) {
+ selenium.clickAt(spinnerDecFormat.format(inputId.val()), new Point(1, 1));
+ }
+ }
@Override
public URL getTestUrl() {
@@ -102,33 +144,60 @@
@Test
public void testMin() {
- selenium.type(inputFormat.format(MIN_ID), WRONG_MIN_VAL);
- selenium.fireEvent(inputFormat.format(MIN_ID), Event.BLUR);
- waitGui.until(textEquals.locator(msgFormat.format(MIN_ID)).text(MSG_MIN));
+ selenium.type(inputFormat.format(ID.MIN.val()), WRONG_MIN_VAL);
+ selenium.fireEvent(inputFormat.format(ID.MIN.val()), Event.BLUR);
+ waitGui.until(textEquals.locator(msgFormat.format(ID.MIN.val())).text(MSG_MIN));
}
@Test
+ public void testSpinToMin() {
+ selenium.type(inputFormat.format(ID.MIN.val()), CORRECT_MIN_VAL);
+ selenium.fireEvent(inputFormat.format(ID.MIN.val()), Event.BLUR);
+
+ spinDown(ID.MIN, WRONG_MIN_VAL);
+ waitGui.until(textEquals.locator(msgFormat.format(ID.MIN.val())).text(MSG_MIN));
+ }
+
+ @Test
public void testMax() {
- selenium.type(inputFormat.format(MAX_ID), WRONG_MAX_VAL);
- selenium.fireEvent(inputFormat.format(MAX_ID), Event.BLUR);
- waitGui.until(textEquals.locator(msgFormat.format(MAX_ID)).text(MSG_MAX));
+ selenium.type(inputFormat.format(ID.MAX.val()), WRONG_MAX_VAL);
+ selenium.fireEvent(inputFormat.format(ID.MAX.val()), Event.BLUR);
+ waitGui.until(textEquals.locator(msgFormat.format(ID.MAX.val())).text(MSG_MAX));
}
@Test
+ public void testSpinToMax() {
+ selenium.type(inputFormat.format(ID.MAX.val()), CORRECT_MAX_VAL);
+ selenium.fireEvent(inputFormat.format(ID.MAX.val()), Event.BLUR);
+
+ spinUp(ID.MAX, WRONG_MAX_VAL);
+ waitGui.until(textEquals.locator(msgFormat.format(ID.MAX.val())).text(MSG_MAX));
+ }
+
+ @Test
public void testCustom() {
- selenium.type(inputFormat.format(CUSTOM_ID), WRONG_CUSTOM_VAL);
- selenium.fireEvent(inputFormat.format(CUSTOM_ID), Event.BLUR);
- waitGui.until(textEquals.locator(msgFormat.format(CUSTOM_ID)).text(MSG_CUSTOM));
+ selenium.type(inputFormat.format(ID.CUSTOM.val()), WRONG_CUSTOM_VAL);
+ selenium.fireEvent(inputFormat.format(ID.CUSTOM.val()), Event.BLUR);
+
waitGui.until(textEquals.text(MSG_CUSTOM).locator(msgFormat.format(ID.CUSTOM.val())));
}
+ @Test
+ public void testSpinToNegative() {
+ selenium.type(inputFormat.format(ID.CUSTOM.val()), CORRECT_CUSTOM_VAL);
+ selenium.fireEvent(inputFormat.format(ID.CUSTOM.val()), Event.BLUR);
+
+ spinDown(ID.CUSTOM, WRONG_CUSTOM_VAL);
+
waitGui.until(textEquals.text(MSG_CUSTOM).locator(msgFormat.format(ID.CUSTOM.val())));
+ }
+
@Test
public void testAllCorrect() {
setAllCorrect();
-
waitGui.until(textEquals.locator(outputFormat.format(MIN_ID)).text(CORRECT_MIN_VAL));
- Assert.assertEquals(selenium.getText(outputFormat.format(MAX_ID)),
CORRECT_MAX_VAL);
- Assert.assertEquals(selenium.getText(outputFormat.format(CUSTOM_ID)),
CORRECT_CUSTOM_VAL);
+
waitGui.until(textEquals.text(CORRECT_MIN_VAL).locator(outputFormat.format(ID.MIN.val())));
+ Assert.assertEquals(selenium.getText(outputFormat.format(ID.MAX.val())),
CORRECT_MAX_VAL);
+ Assert.assertEquals(selenium.getText(outputFormat.format(ID.CUSTOM.val())),
CORRECT_CUSTOM_VAL);
}
@Test
@@ -139,18 +208,18 @@
selenium.click(hCommandBtn);
- waitGui.until(textEquals.locator(msgFormat.format(MIN_ID)).text(MSG_MIN));
- Assert.assertEquals(selenium.getText(msgFormat.format(MAX_ID)), MSG_MAX);
- Assert.assertEquals(selenium.getText(msgFormat.format(CUSTOM_ID)), MSG_CUSTOM);
+ waitGui.until(textEquals.locator(msgFormat.format(ID.MIN.val())).text(MSG_MIN));
+ Assert.assertEquals(selenium.getText(msgFormat.format(ID.MAX.val())), MSG_MAX);
+ Assert.assertEquals(selenium.getText(msgFormat.format(ID.CUSTOM.val())),
MSG_CUSTOM);
setAllCorrect();
setAllWrong();
selenium.click(a4jCommandBtn);
- waitGui.until(textEquals.locator(msgFormat.format(MIN_ID)).text(MSG_MIN));
- Assert.assertEquals(selenium.getText(msgFormat.format(MAX_ID)), MSG_MAX);
- Assert.assertEquals(selenium.getText(msgFormat.format(CUSTOM_ID)), MSG_CUSTOM);
+ waitGui.until(textEquals.locator(msgFormat.format(ID.MIN.val())).text(MSG_MIN));
+ Assert.assertEquals(selenium.getText(msgFormat.format(ID.MAX.val())), MSG_MAX);
+ Assert.assertEquals(selenium.getText(msgFormat.format(ID.CUSTOM.val())),
MSG_CUSTOM);
}
}