Author: lfryc(a)redhat.com
Date: 2010-11-17 06:12:28 -0500 (Wed, 17 Nov 2010)
New Revision: 20072
Added:
modules/tests/metamer/trunk/ftest-source/src/main/java/org/richfaces/tests/metamer/ftest/richAutocomplete/TestAutocompleteByKeys.java
Removed:
modules/tests/metamer/trunk/ftest-source/src/main/java/org/richfaces/tests/metamer/ftest/richAutocomplete/TestAutocomplete.java
Modified:
modules/tests/metamer/trunk/ftest-source/src/main/java/org/richfaces/tests/metamer/ftest/model/Autocomplete.java
Log:
renamed TestAutocomplete to TestAutocompleteByKeys + extended by 1 test cases to test
confirmation of autocompletion selection (RFPL-669)
Modified:
modules/tests/metamer/trunk/ftest-source/src/main/java/org/richfaces/tests/metamer/ftest/model/Autocomplete.java
===================================================================
---
modules/tests/metamer/trunk/ftest-source/src/main/java/org/richfaces/tests/metamer/ftest/model/Autocomplete.java 2010-11-17
11:11:48 UTC (rev 20071)
+++
modules/tests/metamer/trunk/ftest-source/src/main/java/org/richfaces/tests/metamer/ftest/model/Autocomplete.java 2010-11-17
11:12:28 UTC (rev 20072)
@@ -25,6 +25,7 @@
import static org.jboss.test.selenium.locator.LocatorFactory.jq;
import static org.jboss.test.selenium.javascript.JQueryScript.jqScript;
import static org.jboss.test.selenium.javascript.JQueryScript.jqObject;
+import static org.jboss.test.selenium.waiting.WaitFactory.*;
import java.awt.event.KeyEvent;
@@ -41,120 +42,129 @@
*/
public class Autocomplete implements Model {
- private static String KEY_ENTER = "13";
- private static String KEY_UP = "38";
- private static String KEY_DOWN = "40";
+ private static String KEY_ENTER = "13";
+ private static String KEY_UP = "38";
+ private static String KEY_DOWN = "40";
- AjaxSelenium selenium = AjaxSeleniumProxy.getInstance();
+ AjaxSelenium selenium = AjaxSeleniumProxy.getInstance();
- JQueryLocator input = pjq("input.rf-au-inp[id$=autocompleteInput]");
+ JQueryLocator input = pjq("input.rf-au-inp[id$=autocompleteInput]");
- JQueryLocator items = jq("div.rf-au-lst-cord[id$=autocompleteList]
div[id$=autocompleteItems]");
- JQueryLocator selection = items.getDescendant(jq("div.rf-au-sel"));
- JQueryLocator option = jq("div.rf-au-opt");
- JQueryLocator labeledOption = jq("div.rf-au-opt:contains('{0}')");
+ JQueryLocator items = jq("div.rf-au-lst-cord[id$=autocompleteList]
div[id$=autocompleteItems]");
+ JQueryLocator selection = items.getDescendant(jq("div.rf-au-sel"));
+ JQueryLocator option = jq("div.rf-au-opt");
+ JQueryLocator labeledOption = jq("div.rf-au-opt:contains('{0}')");
- public void typeKeys(String keys) {
- for (int i = 0; i < keys.length(); i++) {
- final String key = String.valueOf(keys.charAt(i));
- selenium.focus(input);
- selenium.keyPress(input, key);
- selenium.fireEvent(input, Event.KEYDOWN);
- }
- }
+ public void typeKeys(String keys) {
+ for (int i = 0; i < keys.length(); i++) {
+ final String key = String.valueOf(keys.charAt(i));
+ selenium.focus(input);
+ selenium.keyPress(input, key);
+ selenium.fireEvent(input, Event.KEYDOWN);
+ }
+ }
- public void confirmByKeys() {
- pressEnter();
- }
+ public void confirmByKeys() {
+ pressEnter();
+ }
- public void selectByKeys(String label) {
- int labeledIndex = getLabeledOptionIndex(label);
- while (getSelectedOptionIndex() < labeledIndex) {
- pressDown();
- }
- while (getSelectedOptionIndex() > labeledIndex) {
- pressUp();
- }
- }
+ public void selectByKeys(String label) {
+ int labeledIndex = getLabeledOptionIndex(label);
+ while (getSelectedOptionIndex() < labeledIndex) {
+ pressDown();
+ }
+ while (getSelectedOptionIndex() > labeledIndex) {
+ pressUp();
+ }
+ }
- public boolean isLabeledOptionAvailable(String label) {
- return selenium.isElementPresent(getLabeledOption(label));
- }
+ public boolean isLabeledOptionAvailable(String label) {
+ return selenium.isElementPresent(getLabeledOption(label));
+ }
- public int getLabeledOptionIndex(String label) {
- String index = selenium.getEval(jqScript(getLabeledOption(label),
"index()"));
- return Integer.valueOf(index);
- }
+ public int getLabeledOptionIndex(String label) {
+ String index = selenium.getEval(jqScript(getLabeledOption(label),
+ "index()"));
+ return Integer.valueOf(index);
+ }
- public int getSelectedOptionIndex() {
- JavaScript script = jqScript(option,
"index({0})").parametrize(jqObject(selection));
- String index = selenium.getEval(script);
- return Integer.valueOf(index);
- }
+ public int getSelectedOptionIndex() {
+ JavaScript script = jqScript(option, "index({0})").parametrize(
+ jqObject(selection));
+ String index = selenium.getEval(script);
+ return Integer.valueOf(index);
+ }
- public String getSelectedOptionText() {
- return selenium.getText(selection);
- }
+ public String getSelectedOptionText() {
+ return selenium.getText(selection);
+ }
- public String getInputText() {
- return selenium.getValue(input);
- }
+ public String getInputText() {
+ return selenium.getValue(input);
+ }
- private JQueryLocator getLabeledOption(String label) {
- return labeledOption.format(label);
- }
+ private JQueryLocator getLabeledOption(String label) {
+ return labeledOption.format(label);
+ }
- public void pressBackspace() {
- selenium.keyPressNative(String.valueOf(KeyEvent.VK_BACK_SPACE));
- }
+ public void pressBackspace() {
+ selenium.keyPressNative(String.valueOf(KeyEvent.VK_BACK_SPACE));
+ }
- public void pressUp() {
- selenium.keyDown(input, KEY_UP);
- }
+ public void pressUp() {
+ selenium.keyDown(input, KEY_UP);
+ }
- public void pressDown() {
- selenium.keyDown(input, KEY_DOWN);
- }
+ public void pressDown() {
+ selenium.keyDown(input, KEY_DOWN);
+ }
- public void pressEnter() {
- selenium.keyDown(input, KEY_ENTER);
- }
+ public void pressEnter() {
+ selenium.keyDown(input, KEY_ENTER);
+ }
- public void pressLeft() {
- selenium.keyPressNative(String.valueOf(KeyEvent.VK_LEFT));
- }
+ public void pressLeft() {
+ selenium.keyPressNative(String.valueOf(KeyEvent.VK_LEFT));
+ }
- public void pressRight() {
- selenium.keyPressNative(String.valueOf(KeyEvent.VK_RIGHT));
- }
+ public void pressRight() {
+ selenium.keyPressNative(String.valueOf(KeyEvent.VK_RIGHT));
+ }
- public void pressDelete() {
- selenium.keyPressNative(String.valueOf(KeyEvent.VK_DELETE));
- }
+ public void pressDelete() {
+ selenium.keyPressNative(String.valueOf(KeyEvent.VK_DELETE));
+ }
- public void textSelectionLeft(int size) {
- selenium.keyDownNative(String.valueOf(KeyEvent.VK_SHIFT));
- for (int i = 0; i < size; i++) {
- selenium.keyPressNative(String.valueOf(KeyEvent.VK_LEFT));
- }
- selenium.keyUpNative(String.valueOf(KeyEvent.VK_SHIFT));
- }
+ public void textSelectionLeft(int size) {
+ selenium.keyDownNative(String.valueOf(KeyEvent.VK_SHIFT));
+ for (int i = 0; i < size; i++) {
+ selenium.keyPressNative(String.valueOf(KeyEvent.VK_LEFT));
+ }
+ selenium.keyUpNative(String.valueOf(KeyEvent.VK_SHIFT));
+ }
- public void textSelectionRight(int size) {
- selenium.keyDownNative(String.valueOf(KeyEvent.VK_SHIFT));
- for (int i = 0; i < size; i++) {
- selenium.keyPressNative(String.valueOf(KeyEvent.VK_RIGHT));
- }
- selenium.keyUpNative(String.valueOf(KeyEvent.VK_SHIFT));
- }
+ public void textSelectionRight(int size) {
+ selenium.keyDownNative(String.valueOf(KeyEvent.VK_SHIFT));
+ for (int i = 0; i < size; i++) {
+ selenium.keyPressNative(String.valueOf(KeyEvent.VK_RIGHT));
+ }
+ selenium.keyUpNative(String.valueOf(KeyEvent.VK_SHIFT));
+ }
- public void textSelectAll() {
- selenium.keyDownNative(String.valueOf(KeyEvent.VK_CONTROL));
- selenium.keyPressNative(String.valueOf(KeyEvent.VK_A));
- selenium.keyDownNative(String.valueOf(KeyEvent.VK_CONTROL));
- }
+ public void textSelectAll() {
+ selenium.keyDownNative(String.valueOf(KeyEvent.VK_CONTROL));
+ selenium.keyPressNative(String.valueOf(KeyEvent.VK_A));
+ selenium.keyDownNative(String.valueOf(KeyEvent.VK_CONTROL));
+ }
- public boolean isCompletionVisible() {
- return selenium.isElementPresent(option);
- }
+ public boolean isCompletionVisible() {
+ if (!selenium.isElementPresent(option)) {
+ return false;
+ }
+ return selenium.isVisible(option);
+ }
+
+ public void waitForCompletionVisible() {
+ waitGui.until(elementPresent.locator(option));
+ }
}
Deleted:
modules/tests/metamer/trunk/ftest-source/src/main/java/org/richfaces/tests/metamer/ftest/richAutocomplete/TestAutocomplete.java
===================================================================
---
modules/tests/metamer/trunk/ftest-source/src/main/java/org/richfaces/tests/metamer/ftest/richAutocomplete/TestAutocomplete.java 2010-11-17
11:11:48 UTC (rev 20071)
+++
modules/tests/metamer/trunk/ftest-source/src/main/java/org/richfaces/tests/metamer/ftest/richAutocomplete/TestAutocomplete.java 2010-11-17
11:12:28 UTC (rev 20072)
@@ -1,149 +0,0 @@
-/*******************************************************************************
- * 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.richAutocomplete;
-
-import static org.jboss.test.selenium.utils.URLUtils.buildUrl;
-import static org.testng.Assert.assertEquals;
-import static org.testng.Assert.assertFalse;
-import static org.jboss.test.selenium.RequestTypeModelGuard.guardXhr;
-
-import java.net.URL;
-import java.util.LinkedList;
-import java.util.List;
-
-import javax.xml.bind.JAXBException;
-
-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.Autocomplete;
-import org.richfaces.tests.metamer.model.Capital;
-import org.testng.annotations.BeforeMethod;
-import org.testng.annotations.Test;
-
-/**
- * @author <a href="mailto:lfryc@redhat.com">Lukas Fryc</a>
- * @version $Revision$
- */
-public class TestAutocomplete extends AbstractMetamerTest {
-
- final static Boolean[] booleanValues = new Boolean[] { true, false };
-
- AutocompleteAttributes attributes = new AutocompleteAttributes();
- Autocomplete autocomplete = new Autocomplete();
-
- @Override
- public URL getTestUrl() {
- return buildUrl(contextPath,
"faces/components/richAutocomplete/autocomplete.xhtml");
- }
-
- @Inject
- @Use("booleanValues")
- Boolean autofill;
-
- @Inject
- @Use("booleanValues")
- Boolean selectFirst;
-
- List<Capital> capitals;
-
- StringBuilder partialInput;
-
- {
- try {
- capitals = Model.unmarshallCapitals();
- } catch (JAXBException e) {
- throw new IllegalStateException(e);
- }
- }
-
- @BeforeMethod
- public void prepareProperties() {
- attributes.setAutofill(autofill);
- attributes.setSelectFirst(selectFirst);
- if (autofill == null) {
- autofill = false;
- }
- if (selectFirst == null) {
- selectFirst = false;
- }
- }
-
- @Test
- public void testConditions() {
-
- assertFalse(autocomplete.isCompletionVisible());
-
- typePrefix("ala");
-
- deleteAll();
- }
-
- public void deleteAll() {
- partialInput = new StringBuilder();
-
- autocomplete.textSelectAll();
- guardXhr(autocomplete).pressBackspace();
-
- assertEquals(autocomplete.getInputText(), getExpectedStateForPrefix());
- assertEquals(autocomplete.getSelectedOptionIndex(),
getExpectedSelectedOptionIndex());
- }
-
- public void typePrefix(String wholeInput) {
- partialInput = new StringBuilder(autocomplete.getInputText());
-
- for (int i = 0; i < wholeInput.length(); i++) {
- String chr = String.valueOf(wholeInput.charAt(i));
-
- guardXhr(autocomplete).typeKeys(chr);
- partialInput.append(chr);
-
- assertEquals(autocomplete.getInputText(), getExpectedStateForPrefix());
- assertEquals(autocomplete.getSelectedOptionIndex(),
getExpectedSelectedOptionIndex());
- }
- }
-
- public String getExpectedStateForPrefix() {
- if (selectFirst && autofill && partialInput.length() > 0) {
- return getStatesByPrefix(partialInput.toString()).get(0).toLowerCase();
- }
-
- return partialInput.toString();
- }
-
- public int getExpectedSelectedOptionIndex() {
- return (selectFirst) ? 0 : -1;
- }
-
- public List<String> getStatesByPrefix(String prefix) {
- List<String> states = new LinkedList<String>();
-
- for (Capital cap : capitals) {
- if (cap.getState().toLowerCase().startsWith(prefix)) {
- states.add(cap.getState());
- }
- }
-
- return states;
- }
-}
Added:
modules/tests/metamer/trunk/ftest-source/src/main/java/org/richfaces/tests/metamer/ftest/richAutocomplete/TestAutocompleteByKeys.java
===================================================================
---
modules/tests/metamer/trunk/ftest-source/src/main/java/org/richfaces/tests/metamer/ftest/richAutocomplete/TestAutocompleteByKeys.java
(rev 0)
+++
modules/tests/metamer/trunk/ftest-source/src/main/java/org/richfaces/tests/metamer/ftest/richAutocomplete/TestAutocompleteByKeys.java 2010-11-17
11:12:28 UTC (rev 20072)
@@ -0,0 +1,169 @@
+/*******************************************************************************
+ * 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.richAutocomplete;
+
+import static org.jboss.test.selenium.RequestTypeModelGuard.guardXhr;
+import static org.jboss.test.selenium.utils.URLUtils.buildUrl;
+import static org.testng.Assert.assertEquals;
+
+import java.net.URL;
+import java.util.LinkedList;
+import java.util.List;
+
+import javax.xml.bind.JAXBException;
+
+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.Autocomplete;
+import org.richfaces.tests.metamer.model.Capital;
+import org.testng.annotations.BeforeMethod;
+import org.testng.annotations.Test;
+
+/**
+ * @author <a href="mailto:lfryc@redhat.com">Lukas Fryc</a>
+ * @version $Revision$
+ */
+public class TestAutocompleteByKeys extends AbstractMetamerTest {
+
+ AutocompleteAttributes attributes = new AutocompleteAttributes();
+ Autocomplete autocomplete = new Autocomplete();
+
+ @Override
+ public URL getTestUrl() {
+ return buildUrl(contextPath,
+ "faces/components/richAutocomplete/autocomplete.xhtml");
+ }
+
+ @Inject
+ @Use(booleans = { true, false })
+ Boolean autofill;
+
+ @Inject
+ @Use(booleans = { true, false })
+ Boolean selectFirst;
+
+ List<Capital> capitals;
+
+ StringBuilder partialInput;
+
+ {
+ try {
+ capitals = Model.unmarshallCapitals();
+ } catch (JAXBException e) {
+ throw new IllegalStateException(e);
+ }
+ }
+
+ @BeforeMethod
+ public void prepareProperties() {
+ attributes.setAutofill(autofill);
+ attributes.setSelectFirst(selectFirst);
+ if (autofill == null) {
+ autofill = false;
+ }
+ if (selectFirst == null) {
+ selectFirst = false;
+ }
+ }
+
+ @Test
+ public void testTypingPrefixAndThenConfirm() {
+ assertCompletionVisible(false);
+ typePrefix("ala");
+ assertCompletionVisible(true);
+ confirm();
+ assertCompletionVisible(false);
+ }
+
+ @Test
+ public void testTypingPrefixAndThenDeleteAll() {
+ assertCompletionVisible(false);
+ typePrefix("ala");
+ assertCompletionVisible(true);
+ deleteAll();
+ assertCompletionVisible(true);
+ }
+
+ private void assertCompletionVisible(boolean assertCompletionVisible) {
+ assertEquals(autocomplete.isCompletionVisible(),
+ assertCompletionVisible);
+ }
+
+ public void confirm() {
+ autocomplete.confirmByKeys();
+ autocomplete.waitForCompletionVisible();
+ }
+
+ public void deleteAll() {
+ partialInput = new StringBuilder();
+
+ autocomplete.textSelectAll();
+ guardXhr(autocomplete).pressBackspace();
+
+ assertEquals(autocomplete.getInputText(), getExpectedStateForPrefix());
+ assertEquals(autocomplete.getSelectedOptionIndex(),
+ getExpectedSelectedOptionIndex());
+ }
+
+ public void typePrefix(String wholeInput) {
+ partialInput = new StringBuilder(autocomplete.getInputText());
+
+ for (int i = 0; i < wholeInput.length(); i++) {
+ String chr = String.valueOf(wholeInput.charAt(i));
+
+ guardXhr(autocomplete).typeKeys(chr);
+ partialInput.append(chr);
+
+ assertEquals(autocomplete.getInputText(),
+ getExpectedStateForPrefix());
+ assertEquals(autocomplete.getSelectedOptionIndex(),
+ getExpectedSelectedOptionIndex());
+ }
+ }
+
+ public String getExpectedStateForPrefix() {
+ if (selectFirst && autofill && partialInput.length() > 0) {
+ return getStatesByPrefix(partialInput.toString()).get(0)
+ .toLowerCase();
+ }
+
+ return partialInput.toString();
+ }
+
+ public int getExpectedSelectedOptionIndex() {
+ return (selectFirst) ? 0 : -1;
+ }
+
+ public List<String> getStatesByPrefix(String prefix) {
+ List<String> states = new LinkedList<String>();
+
+ for (Capital cap : capitals) {
+ if (cap.getState().toLowerCase().startsWith(prefix)) {
+ states.add(cap.getState());
+ }
+ }
+
+ return states;
+ }
+}