use of com.qcadoo.view.internal.api.InternalComponentState in project qcadoo by qcadoo.
the class FormComponentStateTest method shouldInitialeFormWithNullEntityId.
@Test
public void shouldInitialeFormWithNullEntityId() throws Exception {
// given
FormComponentPattern pattern = mock(FormComponentPattern.class);
given(pattern.getExpressionNew()).willReturn(null);
given(pattern.getExpressionEdit()).willReturn(null);
setField(pattern, "applicationContext", applicationContext);
InternalComponentState componentState = new FormComponentState(pattern);
JSONObject json = new JSONObject();
JSONObject jsonContent = new JSONObject();
jsonContent.put(FormComponentState.JSON_ENTITY_ID, (String) null);
json.put(AbstractComponentState.JSON_CONTENT, jsonContent);
JSONObject jsonChildren = new JSONObject();
json.put(AbstractComponentState.JSON_CHILDREN, jsonChildren);
// when
componentState.initialize(json, Locale.ENGLISH);
// then
assertNull(componentState.getFieldValue());
}
use of com.qcadoo.view.internal.api.InternalComponentState in project qcadoo by qcadoo.
the class ComponentStateTest method shouldRenderJsonWithFieldValue.
@Test
public void shouldRenderJsonWithFieldValue() throws Exception {
// given
InternalComponentState componentState = new SimpleComponentState();
componentState.setFieldValue("text");
componentState.initialize(new JSONObject(), Locale.ENGLISH);
// when
JSONObject json = componentState.render();
// then
assertEquals("text", json.getJSONObject(AbstractComponentState.JSON_CONTENT).getString(AbstractComponentState.JSON_VALUE));
}
use of com.qcadoo.view.internal.api.InternalComponentState in project qcadoo by qcadoo.
the class ComponentStateTest method shouldModifyVisibleFlag.
@Test
public void shouldModifyVisibleFlag() throws Exception {
// given
InternalComponentState componentState = new SimpleComponentState();
// when
componentState.setVisible(false);
// then
assertFalse(componentState.isVisible());
assertFalse(componentState.render().getBoolean(AbstractComponentState.JSON_VISIBLE));
}
use of com.qcadoo.view.internal.api.InternalComponentState in project qcadoo by qcadoo.
the class ComponentStateTest method shouldHaveEnableFlag.
@Test
public void shouldHaveEnableFlag() throws Exception {
// given
InternalComponentState componentState = new SimpleComponentState();
JSONObject json = new JSONObject();
JSONObject jsonContent = new JSONObject();
jsonContent.put(AbstractComponentState.JSON_VALUE, "text");
json.put(AbstractComponentState.JSON_CONTENT, jsonContent);
json.put(AbstractComponentState.JSON_ENABLED, true);
// when
componentState.initialize(json, Locale.ENGLISH);
// then
assertTrue(componentState.isEnabled());
assertTrue(componentState.render().getBoolean(AbstractComponentState.JSON_ENABLED));
}
use of com.qcadoo.view.internal.api.InternalComponentState in project qcadoo by qcadoo.
the class ContainerStateTest method shouldInitializeChildren.
@Test
public void shouldInitializeChildren() throws Exception {
// given
InternalComponentState component1 = createMockComponent("component1");
InternalComponentState component2 = createMockComponent("component2");
FormComponentPattern pattern = mock(FormComponentPattern.class);
given(pattern.getExpressionNew()).willReturn(null);
given(pattern.getExpressionEdit()).willReturn(null);
setField(pattern, "applicationContext", applicationContext);
FormComponentState container = new FormComponentState(pattern);
container.addChild(component1);
container.addChild(component2);
JSONObject json = new JSONObject();
JSONObject children = new JSONObject();
JSONObject component1Json = new JSONObject();
component1Json.put(AbstractComponentState.JSON_CONTENT, new JSONObject());
JSONObject component2Json = new JSONObject();
component2Json.put(AbstractComponentState.JSON_CONTENT, new JSONObject());
children.put("component1", component1Json);
children.put("component2", component2Json);
json.put(AbstractComponentState.JSON_CHILDREN, children);
json.put(AbstractComponentState.JSON_CONTENT, new JSONObject(Collections.singletonMap("entityId", 13L)));
// when
container.initialize(json, Locale.ENGLISH);
// then
verify(component1).initialize(component1Json, Locale.ENGLISH);
verify(component2).initialize(component2Json, Locale.ENGLISH);
}
Aggregations