WicketTester and confirmation modal

2016-01-15 Thread Marco Di Sabatino Di Diodoro

Hi all,

I'm implementing tests with WicketTester for Apache Syncope console.
How can I simulate a click on my confirmation modal?

This is my java class

public class ConfirmationModalBehavior extends Behavior {

private final String message;

public ConfirmationModalBehavior() {
this("confirmDelete");
}

public ConfirmationModalBehavior(final String msg) {
message = new ResourceModel(msg, "Are you sure?").getObject();
}

@Override
public void renderHead(final Component component, final 
IHeaderResponse response) {

super.renderHead(component, response);

response.render(JavaScriptHeaderItem.forScript("var confirm = 
false;", null));

response.render($(component).on("click",
new JavaScriptInlineFunction(""
+ "var element = $(this);"
+ "evt.preventDefault();"
+ "if(confirm == false){"
+ "evt.stopImmediatePropagation();"
+ "bootbox.confirm(\"" + message + "\", 
function(result){"

+ "if(result == true){"
+ "confirm = true;"
+ "element.click();"
+ "}"
+ "else{confirm = false;}"
+ "return true;"
+ "})} "
+ "else {confirm = false;};"
)).asDomReadyScript());
}
}

and this is the generated html






class="bootbox-close-button close" type="button" style="margin-top: 
-10px;">×
Do you really want to delete 
the selected item(s)?



data-bb-handler="cancel">Cancel
data-bb-handler="confirm">OK






Any suggestions?

Regards
M

--
Dott. Marco Di Sabatino Di Diodoro
Tel. +39 3939065570

Tirasa S.r.l.
Viale D'Annunzio 267 - 65127 Pescara
Tel +39 0859116307 / FAX +39 085973
http://www.tirasa.net

Apache Syncope PMC Member
http://people.apache.org/~mdisabatino/



Re: WicketTester and confirmation modal

2016-01-15 Thread Martin Grigorov
Hi,

You cannot test JavaScript with WicketTester.
You can set some request parameter that says "confirmed" or "denied" and
make a request to the server side where you process it.

You can use something like Selenium for testing real clicks in JavaScript.

Martin Grigorov
Wicket Training and Consulting
https://twitter.com/mtgrigorov

On Fri, Jan 15, 2016 at 11:13 AM, Marco Di Sabatino Di Diodoro <
marco.disabat...@tirasa.net> wrote:

> Hi all,
>
> I'm implementing tests with WicketTester for Apache Syncope console.
> How can I simulate a click on my confirmation modal?
>
> This is my java class
>
> public class ConfirmationModalBehavior extends Behavior {
>
> private final String message;
>
> public ConfirmationModalBehavior() {
> this("confirmDelete");
> }
>
> public ConfirmationModalBehavior(final String msg) {
> message = new ResourceModel(msg, "Are you sure?").getObject();
> }
>
> @Override
> public void renderHead(final Component component, final
> IHeaderResponse response) {
> super.renderHead(component, response);
>
> response.render(JavaScriptHeaderItem.forScript("var confirm =
> false;", null));
> response.render($(component).on("click",
> new JavaScriptInlineFunction(""
> + "var element = $(this);"
> + "evt.preventDefault();"
> + "if(confirm == false){"
> + "evt.stopImmediatePropagation();"
> + "bootbox.confirm(\"" + message + "\",
> function(result){"
> + "if(result == true){"
> + "confirm = true;"
> + "element.click();"
> + "}"
> + "else{confirm = false;}"
> + "return true;"
> + "})} "
> + "else {confirm = false;};"
> )).asDomReadyScript());
> }
> }
>
> and this is the generated html
>
> 
> 
> 
> 
>  class="bootbox-close-button close" type="button" style="margin-top:
> -10px;">×
> Do you really want to delete the
> selected item(s)?
> 
> 
>  data-bb-handler="cancel">Cancel
>  data-bb-handler="confirm">OK
> 
> 
> 
> 
>
> Any suggestions?
>
> Regards
> M
>
> --
> Dott. Marco Di Sabatino Di Diodoro
> Tel. +39 3939065570
>
> Tirasa S.r.l.
> Viale D'Annunzio 267 - 65127 Pescara
> Tel +39 0859116307 / FAX +39 085973
> http://www.tirasa.net
>
> Apache Syncope PMC Member
> http://people.apache.org/~mdisabatino/
>
>


Re: WicketTester and confirmation modal

2016-01-15 Thread Marco Di Sabatino Di Diodoro



Il 15/01/2016 13:51, Martin Grigorov ha scritto:

Hi,

You cannot test JavaScript with WicketTester.
You can set some request parameter that says "confirmed" or "denied" and
make a request to the server side where you process it.

You can use something like Selenium for testing real clicks in JavaScript.

Thanks, for your support.
I used wicketTester.getRequest().addParameter("confirm", "true");

Regards
M

Martin Grigorov
Wicket Training and Consulting
https://twitter.com/mtgrigorov

On Fri, Jan 15, 2016 at 11:13 AM, Marco Di Sabatino Di Diodoro <
marco.disabat...@tirasa.net> wrote:


Hi all,

I'm implementing tests with WicketTester for Apache Syncope console.
How can I simulate a click on my confirmation modal?

This is my java class

public class ConfirmationModalBehavior extends Behavior {

 private final String message;

 public ConfirmationModalBehavior() {
 this("confirmDelete");
 }

 public ConfirmationModalBehavior(final String msg) {
 message = new ResourceModel(msg, "Are you sure?").getObject();
 }

 @Override
 public void renderHead(final Component component, final
IHeaderResponse response) {
 super.renderHead(component, response);

 response.render(JavaScriptHeaderItem.forScript("var confirm =
false;", null));
 response.render($(component).on("click",
 new JavaScriptInlineFunction(""
 + "var element = $(this);"
 + "evt.preventDefault();"
 + "if(confirm == false){"
 + "evt.stopImmediatePropagation();"
 + "bootbox.confirm(\"" + message + "\",
function(result){"
 + "if(result == true){"
 + "confirm = true;"
 + "element.click();"
 + "}"
 + "else{confirm = false;}"
 + "return true;"
 + "})} "
 + "else {confirm = false;};"
 )).asDomReadyScript());
 }
}

and this is the generated html


 
 
 
 ×
 Do you really want to delete the
selected item(s)?
 
 
 Cancel
 OK
 
 
 


Any suggestions?

Regards
M

--
Dott. Marco Di Sabatino Di Diodoro
Tel. +39 3939065570

Tirasa S.r.l.
Viale D'Annunzio 267 - 65127 Pescara
Tel +39 0859116307 / FAX +39 085973
http://www.tirasa.net

Apache Syncope PMC Member
http://people.apache.org/~mdisabatino/




--
Dott. Marco Di Sabatino Di Diodoro
Tel. +39 3939065570

Tirasa S.r.l.
Viale D'Annunzio 267 - 65127 Pescara
Tel +39 0859116307 / FAX +39 085973
http://www.tirasa.net

Apache Syncope PMC Member
http://people.apache.org/~mdisabatino/