use of com.qcadoo.view.internal.components.form.FormComponentPattern in project qcadoo by qcadoo.
the class ComponentStateTest method shouldHaveRequestUpdateStateFlag.
@Test
public void shouldHaveRequestUpdateStateFlag() throws Exception {
// given
new ExpressionServiceImpl().init();
TranslationService translationService = mock(TranslationService.class);
DataDefinition dataDefinition = mock(DataDefinition.class);
FormComponentPattern pattern = mock(FormComponentPattern.class);
given(pattern.getExpressionNew()).willReturn(null);
given(pattern.getExpressionEdit()).willReturn("2");
ApplicationContext applicationContext = mock(ApplicationContext.class);
setField(pattern, "applicationContext", applicationContext);
AbstractComponentState componentState = new FormComponentState(pattern);
componentState.setTranslationService(translationService);
componentState.setDataDefinition(dataDefinition);
componentState.setFieldValue(13L);
componentState.initialize(new JSONObject(ImmutableMap.of("components", new JSONObject())), Locale.ENGLISH);
// when
JSONObject json = componentState.render();
// then
assertTrue(json.getBoolean(AbstractComponentState.JSON_UPDATE_STATE));
}
use of com.qcadoo.view.internal.components.form.FormComponentPattern in project qcadoo by qcadoo.
the class ContainerStateTest method shouldReturnNullIfChildNotExist.
@Test
public void shouldReturnNullIfChildNotExist() throws Exception {
// given
FormComponentPattern pattern = mock(FormComponentPattern.class);
given(pattern.getExpressionNew()).willReturn(null);
given(pattern.getExpressionEdit()).willReturn(null);
setField(pattern, "applicationContext", applicationContext);
FormComponentState container = new FormComponentState(pattern);
// when
ComponentState child = container.getChild("component");
// then
assertNull(child);
}
use of com.qcadoo.view.internal.components.form.FormComponentPattern in project qcadoo by qcadoo.
the class ContainerStateTest method shouldHaveNoChildren.
@Test
public void shouldHaveNoChildren() throws Exception {
// given
FormComponentPattern pattern = mock(FormComponentPattern.class);
given(pattern.getExpressionNew()).willReturn(null);
given(pattern.getExpressionEdit()).willReturn(null);
setField(pattern, "applicationContext", applicationContext);
FormComponentState container = new FormComponentState(pattern);
// when
Map<String, InternalComponentState> children = container.getChildren();
// then
assertNotNull(children);
assertEquals(0, children.size());
}
use of com.qcadoo.view.internal.components.form.FormComponentPattern in project qcadoo by qcadoo.
the class ContainerStateTest method shouldRenderChildren.
@Test
public void shouldRenderChildren() throws Exception {
// given
JSONObject component1Json = new JSONObject();
component1Json.put(AbstractComponentState.JSON_CONTENT, "test1");
JSONObject component2Json = new JSONObject();
component2Json.put(AbstractComponentState.JSON_CONTENT, "test2");
InternalComponentState component1 = createMockComponent("component1");
given(component1.render()).willReturn(component1Json);
InternalComponentState component2 = createMockComponent("component2");
given(component2.render()).willReturn(component2Json);
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);
// when
JSONObject json = container.render();
// then
verify(component1).render();
verify(component2).render();
assertEquals("test1", json.getJSONObject(AbstractComponentState.JSON_CHILDREN).getJSONObject("component1").getString(AbstractComponentState.JSON_CONTENT));
assertEquals("test2", json.getJSONObject(AbstractComponentState.JSON_CHILDREN).getJSONObject("component2").getString(AbstractComponentState.JSON_CONTENT));
}
use of com.qcadoo.view.internal.components.form.FormComponentPattern in project qcadoo by qcadoo.
the class DefaultEventHandlerTest method shouldCallEventMethod.
@Test
public void shouldCallEventMethod() throws Exception {
// given
ViewDefinitionState viewDefinitionState = mock(ViewDefinitionState.class);
FormComponentPattern pattern = mock(FormComponentPattern.class);
given(pattern.getExpressionNew()).willReturn(null);
given(pattern.getExpressionEdit()).willReturn(null);
setField(pattern, "applicationContext", applicationContext);
FormComponentState component = new FormComponentState(pattern);
component.setFieldValue(13L);
// when
component.performEvent(viewDefinitionState, "clear");
// then
assertNull("value is " + component.getFieldValue(), component.getFieldValue());
}
Aggregations