You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@wicket.apache.org by Nick Pratt <nb...@gmail.com> on 2014/03/13 19:06:29 UTC

Testing Form with AjaxSubmitLink

How do you submit a form via WicketTester and an AjaxSubmitLink?


*HomePage.java:*

public class HomePage extends WebPage
{
 private static final long serialVersionUID = 1L;

private String email;

public HomePage( final PageParameters parameters )
 {
super( parameters );

Form form = new Form( "form" );
 add( form );

form.add( new EmailTextField( "email", new PropertyModel(this, "email") ) );
 form.add( new AjaxSubmitLink("submit")
{
@Override
 protected void onSubmit( AjaxRequestTarget target, Form<?> form )
{
int i = 0;
 }
});
}
}

*HomePage.html*

<!DOCTYPE html>
<html xmlns:wicket="http://wicket.apache.org">
<body>

<form wicket:id="form">
 <input type="email" wicket:id="email" placeholder="Email">
<button type="submit" wicket:id="submit">Sign Up</button>
 </form>

</body>
</html>

*Unit Test:*

@Test
 public void testPanel() throws Exception
{
WicketTester tester = new WicketTester();
 tester.startPage( HomePage.class );

FormTester formTester = tester.newFormTester( "form" );
 formTester.setValue( "email", "test@test.com" );
formTester.submit( "submit" );
 }

Re: Testing Form with AjaxSubmitLink

Posted by Martin Grigorov <mg...@apache.org>.
There is something similar already
- org.apache.wicket.util.tester.FormTester#submitLink
But it doesn't support Ajax at the moment.

Feel free to send a PR (preferably with a test case)

Martin Grigorov
Wicket Training and Consulting


On Thu, Mar 13, 2014 at 9:53 PM, Nick Pratt <nb...@gmail.com> wrote:

> Any reason that the FormTester.submit() couldn't be modified to check the
> type of the form submitter, and invoke the correct code accordingly?
>
> N
>
>
> On Thu, Mar 13, 2014 at 3:28 PM, Martin Grigorov <mgrigorov@apache.org
> >wrote:
>
> > Hi,
> >
> > See the javadoc of
> >
> org.apache.wicket.util.tester.BaseWicketTester#clickLink(java.lang.String,
> > boolean)
> >
> > Martin Grigorov
> > Wicket Training and Consulting
> >
> >
> > On Thu, Mar 13, 2014 at 8:06 PM, Nick Pratt <nb...@gmail.com> wrote:
> >
> > > How do you submit a form via WicketTester and an AjaxSubmitLink?
> > >
> > >
> > > *HomePage.java:*
> > >
> > > public class HomePage extends WebPage
> > > {
> > >  private static final long serialVersionUID = 1L;
> > >
> > > private String email;
> > >
> > > public HomePage( final PageParameters parameters )
> > >  {
> > > super( parameters );
> > >
> > > Form form = new Form( "form" );
> > >  add( form );
> > >
> > > form.add( new EmailTextField( "email", new PropertyModel(this,
> "email") )
> > > );
> > >  form.add( new AjaxSubmitLink("submit")
> > > {
> > > @Override
> > >  protected void onSubmit( AjaxRequestTarget target, Form<?> form )
> > > {
> > > int i = 0;
> > >  }
> > > });
> > > }
> > > }
> > >
> > > *HomePage.html*
> > >
> > > <!DOCTYPE html>
> > > <html xmlns:wicket="http://wicket.apache.org">
> > > <body>
> > >
> > > <form wicket:id="form">
> > >  <input type="email" wicket:id="email" placeholder="Email">
> > > <button type="submit" wicket:id="submit">Sign Up</button>
> > >  </form>
> > >
> > > </body>
> > > </html>
> > >
> > > *Unit Test:*
> > >
> > > @Test
> > >  public void testPanel() throws Exception
> > > {
> > > WicketTester tester = new WicketTester();
> > >  tester.startPage( HomePage.class );
> > >
> > > FormTester formTester = tester.newFormTester( "form" );
> > >  formTester.setValue( "email", "test@test.com" );
> > > formTester.submit( "submit" );
> > >  }
> > >
> >
>

Re: Testing Form with AjaxSubmitLink

Posted by Nick Pratt <nb...@gmail.com>.
Any reason that the FormTester.submit() couldn't be modified to check the
type of the form submitter, and invoke the correct code accordingly?

N


On Thu, Mar 13, 2014 at 3:28 PM, Martin Grigorov <mg...@apache.org>wrote:

> Hi,
>
> See the javadoc of
> org.apache.wicket.util.tester.BaseWicketTester#clickLink(java.lang.String,
> boolean)
>
> Martin Grigorov
> Wicket Training and Consulting
>
>
> On Thu, Mar 13, 2014 at 8:06 PM, Nick Pratt <nb...@gmail.com> wrote:
>
> > How do you submit a form via WicketTester and an AjaxSubmitLink?
> >
> >
> > *HomePage.java:*
> >
> > public class HomePage extends WebPage
> > {
> >  private static final long serialVersionUID = 1L;
> >
> > private String email;
> >
> > public HomePage( final PageParameters parameters )
> >  {
> > super( parameters );
> >
> > Form form = new Form( "form" );
> >  add( form );
> >
> > form.add( new EmailTextField( "email", new PropertyModel(this, "email") )
> > );
> >  form.add( new AjaxSubmitLink("submit")
> > {
> > @Override
> >  protected void onSubmit( AjaxRequestTarget target, Form<?> form )
> > {
> > int i = 0;
> >  }
> > });
> > }
> > }
> >
> > *HomePage.html*
> >
> > <!DOCTYPE html>
> > <html xmlns:wicket="http://wicket.apache.org">
> > <body>
> >
> > <form wicket:id="form">
> >  <input type="email" wicket:id="email" placeholder="Email">
> > <button type="submit" wicket:id="submit">Sign Up</button>
> >  </form>
> >
> > </body>
> > </html>
> >
> > *Unit Test:*
> >
> > @Test
> >  public void testPanel() throws Exception
> > {
> > WicketTester tester = new WicketTester();
> >  tester.startPage( HomePage.class );
> >
> > FormTester formTester = tester.newFormTester( "form" );
> >  formTester.setValue( "email", "test@test.com" );
> > formTester.submit( "submit" );
> >  }
> >
>

Re: Testing Form with AjaxSubmitLink

Posted by Martin Grigorov <mg...@apache.org>.
Hi,

See the javadoc of
org.apache.wicket.util.tester.BaseWicketTester#clickLink(java.lang.String,
boolean)

Martin Grigorov
Wicket Training and Consulting


On Thu, Mar 13, 2014 at 8:06 PM, Nick Pratt <nb...@gmail.com> wrote:

> How do you submit a form via WicketTester and an AjaxSubmitLink?
>
>
> *HomePage.java:*
>
> public class HomePage extends WebPage
> {
>  private static final long serialVersionUID = 1L;
>
> private String email;
>
> public HomePage( final PageParameters parameters )
>  {
> super( parameters );
>
> Form form = new Form( "form" );
>  add( form );
>
> form.add( new EmailTextField( "email", new PropertyModel(this, "email") )
> );
>  form.add( new AjaxSubmitLink("submit")
> {
> @Override
>  protected void onSubmit( AjaxRequestTarget target, Form<?> form )
> {
> int i = 0;
>  }
> });
> }
> }
>
> *HomePage.html*
>
> <!DOCTYPE html>
> <html xmlns:wicket="http://wicket.apache.org">
> <body>
>
> <form wicket:id="form">
>  <input type="email" wicket:id="email" placeholder="Email">
> <button type="submit" wicket:id="submit">Sign Up</button>
>  </form>
>
> </body>
> </html>
>
> *Unit Test:*
>
> @Test
>  public void testPanel() throws Exception
> {
> WicketTester tester = new WicketTester();
>  tester.startPage( HomePage.class );
>
> FormTester formTester = tester.newFormTester( "form" );
>  formTester.setValue( "email", "test@test.com" );
> formTester.submit( "submit" );
>  }
>

Re: Testing Form with AjaxSubmitLink

Posted by Gabriel Landon <gl...@piti.pf>.
As Martin said you can use :
tester.clickLink("form:submit", true);

You can also use :
tester.executeAjaxEvent("form:submit", "onclick");

Regards,

Gabriel.


--
View this message in context: http://apache-wicket.1842946.n4.nabble.com/Testing-Form-with-AjaxSubmitLink-tp4664946p4664949.html
Sent from the Users forum mailing list archive at Nabble.com.

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
For additional commands, e-mail: users-help@wicket.apache.org