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