use of org.eclipse.scout.rt.ui.html.json.form.fixtures.FormWithOneField in project scout.rt by eclipse.
the class JsonDesktopTest method testFormClosedBeforeRemovedInSameRequest.
@Test
public void testFormClosedBeforeRemovedInSameRequest() throws JSONException {
DesktopWithOneOutline desktop = new DesktopWithOneOutline();
desktop.initDesktop();
JsonDesktop<IDesktop> jsonDesktop = createJsonDesktop(desktop);
FormWithOneField form = new FormWithOneField();
form.setDisplayParent(desktop);
form.setShowOnStart(false);
JsonForm jsonForm = (JsonForm) jsonDesktop.getAdapter(form);
assertNull(jsonForm);
desktop.showForm(form);
jsonForm = (JsonForm) jsonDesktop.getAdapter(form);
assertNotNull(jsonForm);
List<JsonEvent> responseEvents = JsonTestUtility.extractEventsFromResponse(m_uiSession.currentJsonResponse(), "formShow");
assertEquals(1, responseEvents.size());
form.start();
form.doClose();
responseEvents = JsonTestUtility.extractEventsFromResponse(m_uiSession.currentJsonResponse(), "formClosed");
assertEquals(0, responseEvents.size());
responseEvents = JsonTestUtility.extractEventsFromResponse(m_uiSession.currentJsonResponse(), "disposeAdapter");
assertEquals(1, responseEvents.size());
desktop.hideForm(form);
responseEvents = JsonTestUtility.extractEventsFromResponse(m_uiSession.currentJsonResponse(), "formHide");
assertEquals(0, responseEvents.size());
}
use of org.eclipse.scout.rt.ui.html.json.form.fixtures.FormWithOneField in project scout.rt by eclipse.
the class JsonDesktopTest method testFormClosedBeforeRemovedInDifferentRequests.
@Test
public void testFormClosedBeforeRemovedInDifferentRequests() throws Exception {
DesktopWithOneOutline desktop = new DesktopWithOneOutline();
desktop.initDesktop();
JsonDesktop<IDesktop> jsonDesktop = createJsonDesktop(desktop);
FormWithOneField form = new FormWithOneField();
form.setDisplayParent(desktop);
form.setShowOnStart(false);
JsonForm jsonForm = (JsonForm) jsonDesktop.getAdapter(form);
assertNull(jsonForm);
desktop.showForm(form);
jsonForm = (JsonForm) jsonDesktop.getAdapter(form);
assertNotNull(jsonForm);
List<JsonEvent> responseEvents = JsonTestUtility.extractEventsFromResponse(m_uiSession.currentJsonResponse(), "formShow");
assertEquals(1, responseEvents.size());
form.start();
JsonTestUtility.endRequest(m_uiSession);
// -------------------------------
// New request:
form.doClose();
responseEvents = JsonTestUtility.extractEventsFromResponse(m_uiSession.currentJsonResponse(), "formClosed");
assertEquals(0, responseEvents.size());
responseEvents = JsonTestUtility.extractEventsFromResponse(m_uiSession.currentJsonResponse(), "disposeAdapter");
assertEquals(1, responseEvents.size());
desktop.hideForm(form);
responseEvents = JsonTestUtility.extractEventsFromResponse(m_uiSession.currentJsonResponse(), "formHide");
// 0 instead of 1, because formClosed includes "formHide" implicitly. The event itself cannot be sent, because
// the form adapter is already disposed when the form is closed.
assertEquals(0, responseEvents.size());
}
use of org.eclipse.scout.rt.ui.html.json.form.fixtures.FormWithOneField in project scout.rt by eclipse.
the class JsonDesktopTest method testFormAddedAndRemoved.
@Test
public void testFormAddedAndRemoved() throws Exception {
DesktopWithOneOutline desktop = new DesktopWithOneOutline();
desktop.initDesktop();
JsonDesktop<IDesktop> jsonDesktop = createJsonDesktop(desktop);
FormWithOneField form = new FormWithOneField();
form.setDisplayParent(desktop);
form.setShowOnStart(false);
JsonForm formAdapter = (JsonForm) jsonDesktop.getAdapter(form);
assertNull(formAdapter);
desktop.showForm(form);
formAdapter = (JsonForm) jsonDesktop.getAdapter(form);
assertNotNull(formAdapter);
JsonResponse jsonResp = m_uiSession.currentJsonResponse();
List<JsonEvent> responseEvents = JsonTestUtility.extractEventsFromResponse(jsonResp, "formShow");
assertTrue(responseEvents.size() == 1);
JsonEvent event = responseEvents.get(0);
String formId = event.getData().getString("form");
// Add event must contain reference (by ID) to form.
assertEquals(jsonDesktop.getId(), event.getTarget());
assertEquals(formAdapter.getId(), formId);
// adapter-data for form must exist in 'adapterData' property of response
JSONObject json = jsonResp.toJson();
JSONObject adapterData = JsonTestUtility.getAdapterData(json, formId);
assertEquals(formAdapter.getId(), adapterData.getString("id"));
assertEquals("Form", adapterData.getString("objectType"));
String rootGroupBoxId = adapterData.getString("rootGroupBox");
adapterData = JsonTestUtility.getAdapterData(json, rootGroupBoxId);
assertEquals("GroupBox", adapterData.getString("objectType"));
// we could continue to test the reference structure in the JSON response,
// but for the moment this should be enough...
JsonTestUtility.endRequest(m_uiSession);
desktop.hideForm(form);
responseEvents = JsonTestUtility.extractEventsFromResponse(m_uiSession.currentJsonResponse(), "formHide");
assertTrue(responseEvents.size() == 1);
event = responseEvents.get(0);
formId = event.getData().getString("form");
// Remove event must only contain the id, no other properties
assertEquals(jsonDesktop.getId(), event.getTarget());
assertEquals(formAdapter.getId(), formId);
}
use of org.eclipse.scout.rt.ui.html.json.form.fixtures.FormWithOneField in project scout.rt by eclipse.
the class JsonFormMenuTest method testPreventFormDisposal.
/**
* Form disposal is controlled by the model and must not be triggered by the parent
*/
@Test
public void testPreventFormDisposal() {
FormMenu button = new FormMenu();
FormWithOneField form = new FormWithOneField();
form.start();
button.setForm(form);
JsonFormMenu<IFormMenu<IForm>> jsonFormMenu = m_uiSession.createJsonAdapter(button, null);
assertNotNull(jsonFormMenu.getAdapter(form));
jsonFormMenu.dispose();
// Form has not been closed yet -> must still be registered
assertNotNull(jsonFormMenu.getAdapter(form));
form.doClose();
assertNull(jsonFormMenu.getAdapter(form));
}
use of org.eclipse.scout.rt.ui.html.json.form.fixtures.FormWithOneField in project scout.rt by eclipse.
the class JsonFormTest method testFormDisposalOnClose.
/**
* Form disposal is controlled by the model and must not be triggered by the parent
*/
@Test
public void testFormDisposalOnClose() {
FormWithOneField form = new FormWithOneField();
UiSessionTestUtility.newJsonAdapter(m_uiSession, form, m_uiSession.getRootJsonAdapter());
form.start();
assertNotNull(m_uiSession.getJsonAdapter(form, m_uiSession.getRootJsonAdapter()));
form.doClose();
assertNull(m_uiSession.getJsonAdapter(form, m_uiSession.getRootJsonAdapter()));
}
Aggregations