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);
}
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());
}
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());
}
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());
}
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());
}
Aggregations