You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@wicket.apache.org by Marco Di Sabatino Di Diodoro <ma...@tirasa.net> on 2016/01/15 11:13:22 UTC

WicketTester and confirmation modal

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

<div role="dialog" tabindex="-1" class="bootbox modal fade 
bootbox-confirm in" style="display: block; padding-right: 16px;">
     <div class="modal-dialog">
         <div class="modal-content">
             <div class="modal-body">
                 <button aria-hidden="true" data-dismiss="modal" 
class="bootbox-close-button close" type="button" style="margin-top: 
-10px;">×</button>
                 <div class="bootbox-body">Do you really want to delete 
the selected item(s)?</div>
             </div>
             <div class="modal-footer">
                 <button class="btn btn-default" type="button" 
data-bb-handler="cancel">Cancel</button>
                 <button class="btn btn-primary" type="button" 
data-bb-handler="confirm">OK</button>
             </div>
         </div>
     </div>
</div>

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 0859111173
http://www.tirasa.net

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


Re: WicketTester and confirmation modal

Posted by Marco Di Sabatino Di Diodoro <ma...@tirasa.net>.

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.disabatino@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
>>
>> <div role="dialog" tabindex="-1" class="bootbox modal fade bootbox-confirm
>> in" style="display: block; padding-right: 16px;">
>>      <div class="modal-dialog">
>>          <div class="modal-content">
>>              <div class="modal-body">
>>                  <button aria-hidden="true" data-dismiss="modal"
>> class="bootbox-close-button close" type="button" style="margin-top:
>> -10px;">×</button>
>>                  <div class="bootbox-body">Do you really want to delete the
>> selected item(s)?</div>
>>              </div>
>>              <div class="modal-footer">
>>                  <button class="btn btn-default" type="button"
>> data-bb-handler="cancel">Cancel</button>
>>                  <button class="btn btn-primary" type="button"
>> data-bb-handler="confirm">OK</button>
>>              </div>
>>          </div>
>>      </div>
>> </div>
>>
>> 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 0859111173
>> 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 0859111173
http://www.tirasa.net

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


Re: WicketTester and confirmation modal

Posted by Martin Grigorov <mg...@apache.org>.
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.disabatino@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
>
> <div role="dialog" tabindex="-1" class="bootbox modal fade bootbox-confirm
> in" style="display: block; padding-right: 16px;">
>     <div class="modal-dialog">
>         <div class="modal-content">
>             <div class="modal-body">
>                 <button aria-hidden="true" data-dismiss="modal"
> class="bootbox-close-button close" type="button" style="margin-top:
> -10px;">×</button>
>                 <div class="bootbox-body">Do you really want to delete the
> selected item(s)?</div>
>             </div>
>             <div class="modal-footer">
>                 <button class="btn btn-default" type="button"
> data-bb-handler="cancel">Cancel</button>
>                 <button class="btn btn-primary" type="button"
> data-bb-handler="confirm">OK</button>
>             </div>
>         </div>
>     </div>
> </div>
>
> 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 0859111173
> http://www.tirasa.net
>
> Apache Syncope PMC Member
> http://people.apache.org/~mdisabatino/
>
>