Search in sources :

Example 11 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_onUiSelectionChanged.

@Test
public void testLazyLoadingForm_onUiSelectionChanged() throws Exception {
    FormWithOneField form = new FormWithOneField();
    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));
    JsonEvent event = createJsonSelectedEvent(jsonControl.getId(), true);
    jsonControl.handleUiEvent(event);
    // Form needs to be created and sent if selection changes to true
    IJsonAdapter<?> formAdapter = jsonControl.getAdapter(form);
    assertNotNull(formAdapter);
    String formId = JsonTestUtility.extractProperty(m_uiSession.currentJsonResponse(), jsonControl.getId(), "form");
    assertEquals(formAdapter.getId(), formId);
    JsonTestUtility.endRequest(m_uiSession);
    // Don't send form again on subsequent selection changes
    event = createJsonSelectedEvent(jsonControl.getId(), false);
    jsonControl.handleUiEvent(event);
    formId = JsonTestUtility.extractProperty(m_uiSession.currentJsonResponse(), jsonControl.getId(), "form");
    assertNull(formId);
    JsonTestUtility.endRequest(m_uiSession);
    event = createJsonSelectedEvent(jsonControl.getId(), true);
    jsonControl.handleUiEvent(event);
    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) JsonEvent(org.eclipse.scout.rt.ui.html.json.JsonEvent) 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 12 with FormWithOneField

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

the class JsonAdapterRegistryTest method testFormOpenedAndClosedInSameRequest.

public static void testFormOpenedAndClosedInSameRequest(UiSession uiSession) throws JSONException {
    JsonDesktop<IDesktop> jsonDesktop = UiSessionTestUtility.newJsonAdapter(uiSession, uiSession.getClientSession().getDesktop(), null);
    FormWithOneField form = new FormWithOneField();
    form.start();
    JsonForm formAdapter = (JsonForm) jsonDesktop.getAdapter(form);
    assertNotNull(formAdapter);
    form.doClose();
    formAdapter = (JsonForm) jsonDesktop.getAdapter(form);
    assertNull(formAdapter);
    assertEquals(1, uiSession.currentJsonResponse().eventList().size());
    assertEquals(uiSession.getUiSessionId(), uiSession.currentJsonResponse().eventList().get(0).getTarget());
    assertEquals("disposeAdapter", uiSession.currentJsonResponse().eventList().get(0).getType());
    assertEquals(0, uiSession.currentJsonResponse().adapterMap().size());
}
Also used : JsonForm(org.eclipse.scout.rt.ui.html.json.form.JsonForm) FormWithOneField(org.eclipse.scout.rt.ui.html.json.form.fixtures.FormWithOneField) IDesktop(org.eclipse.scout.rt.client.ui.desktop.IDesktop)

Example 13 with FormWithOneField

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

the class JsonFormTest method testFormOpenCloseInTwoRequests.

@Test
public void testFormOpenCloseInTwoRequests() throws Exception {
    // Create adapter for client session and desktop
    UiSessionTestUtility.newJsonAdapter(m_uiSession, IClientSession.CURRENT.get(), null);
    JsonTestUtility.processBufferedEvents(m_uiSession);
    JsonTestUtility.endRequest(m_uiSession);
    // ---------
    FormWithOneField form = new FormWithOneField();
    // --- 1 ---
    form.start();
    JsonTestUtility.processBufferedEvents(m_uiSession);
    assertFalse(JsonResponseTest.getAdapterData(m_uiSession.currentJsonResponse()).isEmpty());
    assertEquals(2, m_uiSession.currentJsonResponse().getEventList().size());
    assertEquals("requestFocus", m_uiSession.currentJsonResponse().getEventList().get(0).getType());
    assertEquals("formShow", m_uiSession.currentJsonResponse().getEventList().get(1).getType());
    JsonTestUtility.endRequest(m_uiSession);
    // --- 2 ---
    form.doClose();
    JsonTestUtility.processBufferedEvents(m_uiSession);
    assertTrue(JsonResponseTest.getAdapterData(m_uiSession.currentJsonResponse()).isEmpty());
    assertEquals(2, m_uiSession.currentJsonResponse().getEventList().size());
    assertEquals("formHide", m_uiSession.currentJsonResponse().getEventList().get(0).getType());
    assertEquals("disposeAdapter", m_uiSession.currentJsonResponse().getEventList().get(1).getType());
}
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 14 with FormWithOneField

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

the class JsonFormTest method testFormOpenCloseInSameRequest.

@Test
public void testFormOpenCloseInSameRequest() throws Exception {
    // Create adapter for client session and desktop
    UiSessionTestUtility.newJsonAdapter(m_uiSession, IClientSession.CURRENT.get(), null);
    JsonTestUtility.processBufferedEvents(m_uiSession);
    JsonTestUtility.endRequest(m_uiSession);
    // ---------
    FormWithOneField form = new FormWithOneField();
    form.start();
    form.doClose();
    JsonTestUtility.processBufferedEvents(m_uiSession);
    assertTrue(JsonResponseTest.getAdapterData(m_uiSession.currentJsonResponse()).isEmpty());
    assertEquals(1, m_uiSession.currentJsonResponse().getEventList().size());
    assertEquals("disposeAdapter", m_uiSession.currentJsonResponse().getEventList().get(0).getType());
}
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 15 with FormWithOneField

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

the class JsonFormTest method testFormVisibleGrantedFalse.

@Test
public void testFormVisibleGrantedFalse() throws Exception {
    // Create adapter for client session and desktop
    UiSessionTestUtility.newJsonAdapter(m_uiSession, IClientSession.CURRENT.get(), null);
    JsonTestUtility.processBufferedEvents(m_uiSession);
    JsonTestUtility.endRequest(m_uiSession);
    // ---------
    FormWithOneField form = new FormWithOneField();
    IJsonAdapter<?> formAdapter = m_uiSession.getJsonAdapter(form, m_uiSession.getRootJsonAdapter());
    assertNull(formAdapter);
    // --- 1 ---
    // Assume the adapter was somehow attached (including the child adapters)
    formAdapter = m_uiSession.getOrCreateJsonAdapter(form, m_uiSession.getRootJsonAdapter());
    // Now set the field visibleGranted=false, then start it -> field should not be included in response
    form.getStringField().setVisibleGranted(false);
    form.start();
    formAdapter = m_uiSession.getJsonAdapter(form, null);
    assertEquals(1, m_uiSession.getJsonChildAdapters(formAdapter).size());
    IJsonAdapter<?> mainBoxAdapter = m_uiSession.getJsonChildAdapters(formAdapter).get(0);
    // field not sent to UI
    assertEquals(0, m_uiSession.getJsonChildAdapters(mainBoxAdapter).size());
    JsonTestUtility.processBufferedEvents(m_uiSession);
    // form, mainbox
    assertEquals(2, JsonResponseTest.getAdapterData(m_uiSession.currentJsonResponse()).size());
    assertEquals(3, m_uiSession.currentJsonResponse().getEventList().size());
    // mainbox visible=false
    assertEquals("property", m_uiSession.currentJsonResponse().getEventList().get(0).getType());
    assertEquals("formActivate", m_uiSession.currentJsonResponse().getEventList().get(1).getType());
    assertEquals("formShow", m_uiSession.currentJsonResponse().getEventList().get(2).getType());
    // "requestFocus" event not sent
    JsonTestUtility.endRequest(m_uiSession);
    // --- 2 ---
    form.getStringField().setValue("test");
    JsonTestUtility.processBufferedEvents(m_uiSession);
    // event not sent to UI
    assertEquals(1, m_uiSession.currentJsonResponse().getEventList().size());
    JsonTestUtility.endRequest(m_uiSession);
    // --- 3 ---
    form.doReset();
    JsonTestUtility.processBufferedEvents(m_uiSession);
    assertTrue(JsonResponseTest.getAdapterData(m_uiSession.currentJsonResponse()).isEmpty());
    // no event for invisible field
    assertEquals(1, m_uiSession.currentJsonResponse().getEventList().size());
    // --- 4 ---
    form.doClose();
    JsonTestUtility.processBufferedEvents(m_uiSession);
    assertTrue(JsonResponseTest.getAdapterData(m_uiSession.currentJsonResponse()).isEmpty());
    assertEquals(2, m_uiSession.currentJsonResponse().getEventList().size());
    assertEquals("formHide", m_uiSession.currentJsonResponse().getEventList().get(0).getType());
    assertEquals("disposeAdapter", m_uiSession.currentJsonResponse().getEventList().get(1).getType());
}
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)

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