From richfaces-svn-commits at lists.jboss.org Sun Nov 6 20:17:14 2011 Content-Type: multipart/mixed; boundary="===============6830635097147821977==" MIME-Version: 1.0 From: richfaces-svn-commits at lists.jboss.org To: richfaces-svn-commits at lists.jboss.org Subject: [richfaces-svn-commits] JBoss Rich Faces SVN: r22879 - modules/tests/metamer/trunk/ftest-source/src/main/java/org/richfaces/tests/metamer/ftest/richAutocomplete. Date: Sun, 06 Nov 2011 20:17:13 -0500 Message-ID: <201111070117.pA71HDFJ030960@svn01.web.mwc.hst.phx2.redhat.com> --===============6830635097147821977== Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Author: jjamrich Date: 2011-11-06 20:17:13 -0500 (Sun, 06 Nov 2011) New Revision: 22879 Added: modules/tests/metamer/trunk/ftest-source/src/main/java/org/richfaces/tes= ts/metamer/ftest/richAutocomplete/TestAutocompleteFormatting.java Log: RFPL-1545: add test for autocomplete with @fetchValue Added: modules/tests/metamer/trunk/ftest-source/src/main/java/org/richfaces= /tests/metamer/ftest/richAutocomplete/TestAutocompleteFormatting.java =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D --- modules/tests/metamer/trunk/ftest-source/src/main/java/org/richfaces/te= sts/metamer/ftest/richAutocomplete/TestAutocompleteFormatting.java = (rev 0) +++ modules/tests/metamer/trunk/ftest-source/src/main/java/org/richfaces/te= sts/metamer/ftest/richAutocomplete/TestAutocompleteFormatting.java 2011-11-= 07 01:17:13 UTC (rev 22879) @@ -0,0 +1,177 @@ +/*************************************************************************= ****** + * 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.richAutocomplete; + +import static org.jboss.test.selenium.RequestTypeModelGuard.guardXhr; +import static org.testng.Assert.assertEquals; +import static org.testng.Assert.assertTrue; +import static org.testng.Assert.assertFalse; + +import java.net.URL; +import java.util.LinkedList; +import java.util.List; + +import javax.validation.constraints.AssertFalse; + +import org.jboss.test.selenium.utils.URLUtils; +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; + +/** + * Test for example with formatted suggestions on page faces/components/ri= chAutocomplete/autocomplete.xhtml = + * + * @author Jan Jamrich + * + * @version $Revision$ + */ +public class TestAutocompleteFormatting extends AbstractMetamerTest { + = + AutocompleteAttributes attributes =3D new AutocompleteAttributes(); + Autocomplete autocomplete =3D new Autocomplete(); + StringBuilder partialInput; + = + List capitals =3D Model.unmarshallCapitals(); + = + @Inject + @Use(booleans =3D { true, false }) + Boolean autofill; + + @Inject + @Use(booleans =3D { true, false }) + Boolean selectFirst; + + @Override + public URL getTestUrl() { + return URLUtils.buildUrl(contextPath, "faces/components/richAutoco= mplete/fetchValueAttr.xhtml"); + } + = + @BeforeMethod + public void prepareProperties() { + attributes.setAutofill(autofill); + attributes.setSelectFirst(selectFirst); + if (autofill =3D=3D null) { + autofill =3D false; + } + if (selectFirst =3D=3D null) { + selectFirst =3D false; + } + autocomplete.clearInputValue(); + } + + /** + * This should test combination of @var and @fetchValue attributes of = autocomplete + */ + @Test + public void testFormatting() { + assertFalse(autocomplete.isCompletionVisible()); + typePrefix("ala"); + assertTrue(autocomplete.isCompletionVisible()); + confirm(); + assertFalse(autocomplete.isCompletionVisible()); + assertTrue(autocomplete.getInputText().toLowerCase().startsWith(ge= tExpectedStateForPrefix().toLowerCase())); + } + = + public void typePrefix(String wholeInput) { + partialInput =3D new StringBuilder(autocomplete.getInputText()); + + for (int i =3D 0; i < wholeInput.length(); i++) { + String chr =3D String.valueOf(wholeInput.charAt(i)); + + guardXhr(autocomplete).typeKeys(chr); + partialInput.append(chr); + + assertEquals(autocomplete.getInputText(), getExpectedStateForP= refix()); + assertEquals(autocomplete.getSelectedOptionIndex(), getExpecte= dSelectedOptionIndex()); + } + } + = + public String getExpectedStateForPrefix() { + if (selectFirst && autofill && partialInput.length() > 0) { + return getStatesByPrefix(partialInput.toString()).get(0).toLow= erCase(); + } + + return partialInput.toString(); + } + = + public String getExpectedCompletionForPrefix() { + if (selectFirst && autofill && partialInput.length() > 0) { + return getCompletionByPrefix(partialInput.toString()).get(0).t= oLowerCase(); + } + + return partialInput.toString(); + } + = + public List getStatesByPrefix(String prefix) { + List states =3D new LinkedList(); + + for (Capital cap : capitals) { + if (cap.getState().toLowerCase().startsWith(prefix)) { + states.add(cap.getState()); + } + } + + return states; + } + = + public List getCompletionByPrefix(String prefix) { + List states =3D new LinkedList(); + + for (Capital cap : capitals) { + if (cap.getState().toLowerCase().startsWith(prefix)) { + states.add(cap.getState() + " [" + cap.getName() + "]"); + } + } + + return states; + } + = + public int getExpectedSelectedOptionIndex() { + return (selectFirst && partialInput.length() > 0) ? 0 : -1; + } + = + public void confirm() { + autocomplete.confirmByKeys(); + autocomplete.waitForCompletionVisible(); + } + + public Boolean getAutofill() { + return autofill; + } + + public void setAutofill(Boolean autofill) { + this.autofill =3D autofill; + } + + public Boolean getSelectFirst() { + return selectFirst; + } + + public void setSelectFirst(Boolean selectFirst) { + this.selectFirst =3D selectFirst; + } +} --===============6830635097147821977==--