Search in sources :

Example 6 with FormWithOneField

use of org.eclipse.scout.rt.ui.html.json.form.fixtures.FormWithOneField in project scout.rt by eclipse.

the class JsonFormTest method testRequestFocusInPostLoad.

/**
 * {@link IForm#requestFocus(org.eclipse.scout.rt.client.ui.form.fields.IFormField)} in
 * {@link AbstractFormHandler#execPostLoad()} must set <i>initialFocus</i> property.
 */
@Test
public void testRequestFocusInPostLoad() {
    FormWithOneField form = new FormWithOneField();
    IJsonAdapter<?> adapter = UiSessionTestUtility.newJsonAdapter(m_uiSession, form, m_uiSession.getRootJsonAdapter());
    form.start();
    assertNotNull(adapter.toJson().get(JsonForm.PROP_INITIAL_FOCUS));
    form.doClose();
}
Also used : FormWithOneField(org.eclipse.scout.rt.ui.html.json.form.fixtures.FormWithOneField) Test(org.junit.Test) JsonResponseTest(org.eclipse.scout.rt.ui.html.json.JsonResponseTest)

Example 7 with FormWithOneField

use of org.eclipse.scout.rt.ui.html.json.form.fixtures.FormWithOneField in project scout.rt by eclipse.

the class JsonFormTableControlTest method testLazyLoadingForm_onModelSelectionChanged.

@Test
public void testLazyLoadingForm_onModelSelectionChanged() throws JSONException {
    FormWithOneField form = new FormWithOneField();
    form.setShowOnStart(false);
    FormTableControl control = new FormTableControl();
    control.setTable(new Table());
    control.setForm(form);
    control.decorateForm();
    JsonTableControl<ITableControl> jsonControl = UiSessionTestUtility.newJsonAdapter(m_uiSession, control, null);
    assertNull(jsonControl.getAdapter(form));
    control.setSelected(true);
    IJsonAdapter<?> formAdapter = jsonControl.getAdapter(form);
    assertNotNull(formAdapter);
    String formId = JsonTestUtility.extractProperty(m_uiSession.currentJsonResponse(), jsonControl.getId(), "form");
    assertEquals(formAdapter.getId(), formId);
}
Also used : Table(org.eclipse.scout.rt.ui.html.json.table.fixtures.Table) ITableControl(org.eclipse.scout.rt.client.ui.basic.table.controls.ITableControl) FormTableControl(org.eclipse.scout.rt.ui.html.json.table.fixtures.FormTableControl) FormWithOneField(org.eclipse.scout.rt.ui.html.json.form.fixtures.FormWithOneField) Test(org.junit.Test)

Example 8 with FormWithOneField

use of org.eclipse.scout.rt.ui.html.json.form.fixtures.FormWithOneField in project scout.rt by eclipse.

the class JsonMenuTest method testDontSendNonDisplayableMenusSpecialCaseWithEvent.

/**
 * Even more special case: Menus that are set to visibleGranted=false may already be referred in an event for another
 * (still available) adapter.
 */
@Test
public void testDontSendNonDisplayableMenusSpecialCaseWithEvent() throws Exception {
    // skip startup response
    JsonTestUtility.endRequest(m_uiSession);
    IForm form = new FormWithOneField();
    IMenu menu = new AbstractMenu() {

        @Override
        protected void execInitAction() {
            setVisibleGranted(false);
        }
    };
    IJsonAdapter<?> jsonForm = m_uiSession.createJsonAdapter(form, null);
    IJsonAdapter<?> jsonRootGroupBox = jsonForm.getAdapter(form.getRootGroupBox());
    // Test:
    // 3 adapters in response: Form, MainBox, StringField
    // 0 events in response
    assertEquals(3, JsonResponseTestUtility.adapterMap(m_uiSession.currentJsonResponse()).size());
    assertEquals(0, JsonResponseTestUtility.eventList(m_uiSession.currentJsonResponse()).size());
    // ------------------
    // End request and simulate context menu change event on form
    JsonTestUtility.endRequest(m_uiSession);
    form.getRootGroupBox().getContextMenu().addChildAction(menu);
    // Test:
    // 1 adapters in response: Menu
    // 1 events in response: PROP_MENU
    assertEquals(1, JsonResponseTestUtility.adapterMap(m_uiSession.currentJsonResponse()).size());
    assertEquals(1, JsonResponseTestUtility.eventList(m_uiSession.currentJsonResponse()).size());
    // ------------------
    // After attachment of adapter!
    ActionUtility.initActions(CollectionUtility.arrayList(menu));
    // Test:
    // - 0 adapters in response (-1 menu)
    // - 1 events in response: PROP_MENU <-- this would be wrong! But when the JSON string is generated, the adapter is removed from the list
    assertEquals(0, JsonResponseTestUtility.adapterMap(m_uiSession.currentJsonResponse()).size());
    assertEquals(1, JsonResponseTestUtility.eventList(m_uiSession.currentJsonResponse()).size());
    // Check that the event's properties are empty after toJson()
    JSONObject json = m_uiSession.currentJsonResponse().toJson();
    assertFalse(json.has("adapterData"));
    JSONArray events = json.getJSONArray("events");
    assertEquals(1, events.length());
    assertEquals(jsonRootGroupBox.getId(), events.getJSONObject(0).get("target"));
    assertEquals("property", events.getJSONObject(0).get("type"));
    assertEquals(0, events.getJSONObject(0).getJSONObject("properties").getJSONArray("menus").length());
}
Also used : IMenu(org.eclipse.scout.rt.client.ui.action.menu.IMenu) AbstractMenu(org.eclipse.scout.rt.client.ui.action.menu.AbstractMenu) JSONObject(org.json.JSONObject) JSONArray(org.json.JSONArray) IForm(org.eclipse.scout.rt.client.ui.form.IForm) FormWithOneField(org.eclipse.scout.rt.ui.html.json.form.fixtures.FormWithOneField) Test(org.junit.Test)

Example 9 with FormWithOneField

use of org.eclipse.scout.rt.ui.html.json.form.fixtures.FormWithOneField in project scout.rt by eclipse.

the class JsonFormTableControlTest method testLazyLoadingForm_onModelFormChanged.

@Test
public void testLazyLoadingForm_onModelFormChanged() throws JSONException {
    FormWithOneField form = new FormWithOneField();
    form.setShowOnStart(false);
    FormTableControl control = new FormTableControl();
    control.setTable(new Table());
    control.setForm(form);
    control.decorateForm();
    JsonTableControl<ITableControl> jsonControl = UiSessionTestUtility.newJsonAdapter(m_uiSession, control, null);
    assertNull(jsonControl.getAdapter(form));
    FormWithOneField anotherForm = new FormWithOneField();
    anotherForm.setShowOnStart(false);
    control.setForm(anotherForm);
    control.decorateForm();
    // Both forms have to be null because the control has not been selected yet
    assertNull(jsonControl.getAdapter(form));
    assertNull(jsonControl.getAdapter(anotherForm));
    control.setSelected(true);
    IJsonAdapter<?> formAdapter = jsonControl.getAdapter(anotherForm);
    // Form is still null because it was exchanged with anotherForm
    assertNull(jsonControl.getAdapter(form));
    assertNotNull(formAdapter);
    String formId = JsonTestUtility.extractProperty(m_uiSession.currentJsonResponse(), jsonControl.getId(), "form");
    assertEquals(formAdapter.getId(), formId);
}
Also used : Table(org.eclipse.scout.rt.ui.html.json.table.fixtures.Table) ITableControl(org.eclipse.scout.rt.client.ui.basic.table.controls.ITableControl) FormTableControl(org.eclipse.scout.rt.ui.html.json.table.fixtures.FormTableControl) FormWithOneField(org.eclipse.scout.rt.ui.html.json.form.fixtures.FormWithOneField) Test(org.junit.Test)

Example 10 with FormWithOneField

use of org.eclipse.scout.rt.ui.html.json.form.fixtures.FormWithOneField in project scout.rt by eclipse.

the class JsonFormTableControlTest method testNonLazyLoadingFormWhenSelected.

@Test
public void testNonLazyLoadingFormWhenSelected() throws JSONException {
    FormWithOneField form = new FormWithOneField();
    FormTableControl control = new FormTableControl();
    control.setTable(new Table());
    control.setForm(form);
    control.decorateForm();
    control.setSelected(true);
    JsonTableControl<ITableControl> jsonControl = UiSessionTestUtility.newJsonAdapter(m_uiSession, control, null);
    IJsonAdapter<?> formAdapter = jsonControl.getAdapter(form);
    assertNotNull(formAdapter);
    // Expects formId is sent along with the control and not with a separate property change event
    String formId = JsonTestUtility.extractProperty(m_uiSession.currentJsonResponse(), jsonControl.getId(), "form");
    assertNull(formId);
}
Also used : Table(org.eclipse.scout.rt.ui.html.json.table.fixtures.Table) ITableControl(org.eclipse.scout.rt.client.ui.basic.table.controls.ITableControl) FormTableControl(org.eclipse.scout.rt.ui.html.json.table.fixtures.FormTableControl) FormWithOneField(org.eclipse.scout.rt.ui.html.json.form.fixtures.FormWithOneField) Test(org.junit.Test)

Aggregations

FormWithOneField (org.eclipse.scout.rt.ui.html.json.form.fixtures.FormWithOneField)16 Test (org.junit.Test)14 JsonResponseTest (org.eclipse.scout.rt.ui.html.json.JsonResponseTest)5 ITableControl (org.eclipse.scout.rt.client.ui.basic.table.controls.ITableControl)4 IDesktop (org.eclipse.scout.rt.client.ui.desktop.IDesktop)4 JsonEvent (org.eclipse.scout.rt.ui.html.json.JsonEvent)4 JsonForm (org.eclipse.scout.rt.ui.html.json.form.JsonForm)4 FormTableControl (org.eclipse.scout.rt.ui.html.json.table.fixtures.FormTableControl)4 Table (org.eclipse.scout.rt.ui.html.json.table.fixtures.Table)4 JsonAdapterRegistryTest (org.eclipse.scout.rt.ui.html.json.JsonAdapterRegistryTest)3 DesktopWithOneOutline (org.eclipse.scout.rt.ui.html.json.desktop.fixtures.DesktopWithOneOutline)3 JSONObject (org.json.JSONObject)2 AbstractMenu (org.eclipse.scout.rt.client.ui.action.menu.AbstractMenu)1 IMenu (org.eclipse.scout.rt.client.ui.action.menu.IMenu)1 IForm (org.eclipse.scout.rt.client.ui.form.IForm)1 IFormMenu (org.eclipse.scout.rt.client.ui.form.IFormMenu)1 JsonResponse (org.eclipse.scout.rt.ui.html.json.JsonResponse)1 JsonFormMenu (org.eclipse.scout.rt.ui.html.json.desktop.JsonFormMenu)1 FormMenu (org.eclipse.scout.rt.ui.html.json.form.fixtures.FormMenu)1 JSONArray (org.json.JSONArray)1