Search in sources :

Example 6 with AbstractAjaxBehavior

use of org.apache.wicket.behavior.AbstractAjaxBehavior in project wicket by apache.

the class AjaxEditableTest method testDisabledAjaxEditableLabel.

/**
 * Tests whether disabling/enabling an AjaxEditableLabel also disables/enables the
 * <code>LabelBehavior</code>
 */
@SuppressWarnings({ "unchecked" })
@Test
public void testDisabledAjaxEditableLabel() {
    Page page = tester.getLastRenderedPage();
    AjaxEditableLabel<String> ajaxLabel = (AjaxEditableLabel<String>) page.get("ajaxLabel");
    AjaxLink<Void> toggle = (AjaxLink<Void>) page.get("toggle");
    AbstractAjaxBehavior toggleBehavior = (AbstractAjaxBehavior) toggle.getBehaviors().get(0);
    // check for correct rendering
    tester.assertInvisible("ajaxLabel:editor");
    tester.assertVisible("ajaxLabel:label");
    // disable ajaxLabel
    tester.executeBehavior(toggleBehavior);
    // check for the *absence* of the ajax onclick call
    String markup = tester.getTagById(ajaxLabel.getMarkupId()).getMarkup();
    assertFalse(markup.matches(".*onclick=\"var wcall=wicketAjaxGet.*"));
    // enable ajaxLabel
    tester.executeBehavior(toggleBehavior);
// check for the *presence* of the ajax onclick call
// TODO Wicket.next - re-enable
// markup = tester.getTagById(ajaxLabel.getMarkupId()).getMarkup();
// assertTrue(markup.matches(".*onclick=\"var wcall=Wicket.Ajax.get.*"));
}
Also used : Page(org.apache.wicket.Page) AjaxLink(org.apache.wicket.ajax.markup.html.AjaxLink) AbstractAjaxBehavior(org.apache.wicket.behavior.AbstractAjaxBehavior) Test(org.junit.Test)

Example 7 with AbstractAjaxBehavior

use of org.apache.wicket.behavior.AbstractAjaxBehavior in project wicket by apache.

the class AjaxEditableTest method testAjaxEditableLabel.

/**
 * Tests default AjaxEditableLabel behavior
 */
@SuppressWarnings({ "unchecked" })
@Test
public void testAjaxEditableLabel() {
    Page page = tester.getLastRenderedPage();
    AjaxEditableLabel<String> ajaxLabel = (AjaxEditableLabel<String>) page.get("ajaxLabel");
    AbstractAjaxBehavior labelBehavior = (AbstractAjaxBehavior) ajaxLabel.get("label").getBehaviors().get(0);
    AbstractAjaxBehavior editorBehavior = (AbstractAjaxBehavior) ajaxLabel.get("editor").getBehaviors().get(0);
    // "click" on the label and check for valid visibility
    tester.executeBehavior(labelBehavior);
    tester.assertVisible("ajaxLabel:editor");
    tester.assertInvisible("ajaxLabel:label");
    // "leave" the editor and check for valid visibility
    tester.executeBehavior(editorBehavior);
    tester.assertInvisible("ajaxLabel:editor");
    tester.assertVisible("ajaxLabel:label");
}
Also used : Page(org.apache.wicket.Page) AbstractAjaxBehavior(org.apache.wicket.behavior.AbstractAjaxBehavior) Test(org.junit.Test)

Aggregations

AbstractAjaxBehavior (org.apache.wicket.behavior.AbstractAjaxBehavior)7 Page (org.apache.wicket.Page)5 Test (org.junit.Test)5 Component (org.apache.wicket.Component)3 AjaxLink (org.apache.wicket.ajax.markup.html.AjaxLink)1 Url (org.apache.wicket.request.Url)1 ResourceStreamRequestHandler (org.apache.wicket.request.handler.resource.ResourceStreamRequestHandler)1 FileResourceStream (org.apache.wicket.util.resource.FileResourceStream)1 FileSystemResourceStream (org.apache.wicket.util.resource.FileSystemResourceStream)1 IResourceStream (org.apache.wicket.util.resource.IResourceStream)1