Testing Form with AjaxSubmitLink

2014-03-13 Thread Nick Pratt
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=submitSign 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, t...@test.com );
formTester.submit( submit );
 }


Re: Testing Form with AjaxSubmitLink

2014-03-13 Thread Martin Grigorov
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 nbpr...@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=submitSign 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, t...@test.com );
 formTester.submit( submit );
  }



Re: Testing Form with AjaxSubmitLink

2014-03-13 Thread Nick Pratt
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 mgrigo...@apache.orgwrote:

 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 nbpr...@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=submitSign 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, t...@test.com );
  formTester.submit( submit );
   }
 



Re: Testing Form with AjaxSubmitLink

2014-03-13 Thread Gabriel Landon
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-unsubscr...@wicket.apache.org
For additional commands, e-mail: users-h...@wicket.apache.org



Re: Testing Form with AjaxSubmitLink

2014-03-13 Thread Martin Grigorov
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 nbpr...@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 mgrigo...@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 nbpr...@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=submitSign 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, t...@test.com );
   formTester.submit( submit );
}