Skip to content

Instantly share code, notes, and snippets.

@lfryc
Created February 4, 2013 13:59
Show Gist options
  • Save lfryc/4706884 to your computer and use it in GitHub Desktop.
Save lfryc/4706884 to your computer and use it in GitHub Desktop.
package org.richfaces.component.autocomplete;
import static org.jboss.arquillian.graphene.Graphene.guardXhr;
import static org.junit.Assert.assertTrue;
import java.net.URL;
import javax.inject.Inject;
import org.jboss.arquillian.container.test.api.Deployment;
import org.jboss.arquillian.container.test.api.RunAsClient;
import org.jboss.arquillian.drone.api.annotation.Drone;
import org.jboss.arquillian.junit.Arquillian;
import org.jboss.arquillian.test.api.ArquillianResource;
import org.jboss.arquillian.warp.Activity;
import org.jboss.arquillian.warp.Inspection;
import org.jboss.arquillian.warp.Warp;
import org.jboss.arquillian.warp.WarpTest;
import org.jboss.arquillian.warp.jsf.AfterPhase;
import org.jboss.arquillian.warp.jsf.Phase;
import org.jboss.shrinkwrap.api.asset.EmptyAsset;
import org.jboss.shrinkwrap.api.spec.WebArchive;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.support.FindBy;
import org.richfaces.integration.InputDeployment;
import org.richfaces.shrinkwrap.descriptor.FaceletAsset;
@WarpTest
@RunAsClient
@RunWith(Arquillian.class)
public class TestAutocompleteBehaviors {
@Drone
private WebDriver browser;
@ArquillianResource
private URL contextPath;
@FindBy(id = "form:autocomplete")
private RichFacesAutocomplete<String> autocomplete;
@Deployment
public static WebArchive createDeployment() {
InputDeployment deployment = new InputDeployment(TestAutocompleteBehaviors.class);
deployment.archive().addClasses(AutocompleteBean.class).addAsWebInfResource(EmptyAsset.INSTANCE, "beans.xml");
addIndexPage(deployment);
return deployment.getFinalArchive();
}
/**
* onblur should have input value available via 'this.value' expression
*/
@Test
// RF-12114
public void testAjaxOnBlur() {
// given
browser.get(contextPath.toExternalForm());
autocomplete.type("t");
Suggestion<String> firstSuggestion = autocomplete.getFirstSuggestion();
guardXhr(autocomplete).autocompleteWithSuggestion(firstSuggestion);
Warp.initiate(new Activity() {
@Override
public void perform() {
// when
guardXhr(autocomplete).blur();
}
}).inspect(new Inspection() {
private static final long serialVersionUID = 1L;
@Inject
AutocompleteBean bean;
@AfterPhase(Phase.INVOKE_APPLICATION)
public void verify_bean_executed() {
// then
assertTrue(bean.isListenerInvoked());
}
});
}
private static void addIndexPage(InputDeployment deployment) {
FaceletAsset p = new FaceletAsset();
p.body("<h:form id='form'>");
p.body(" <r:autocomplete id='autocomplete' autocompleteList='#{autocompleteBean.suggestions}'>");
p.body(" <r:ajax event='blur' listener='#{autocompleteBean.actionListener}' />");
p.body(" </r:autocomplete>");
p.body("</h:form>");
deployment.archive().addAsWebResource(p, "index.xhtml");
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment