use of com.qcadoo.view.internal.components.form.FormComponentState 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.FormComponentState 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());
}
use of com.qcadoo.view.internal.components.form.FormComponentState in project qcadoo by qcadoo.
the class DefaultEventHandlerTest method shouldCallCustomEventMethod.
@Test
public void shouldCallCustomEventMethod() 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);
ViewEventListenerHook eventListener = mock(ViewEventListenerHook.class);
given(eventListener.getEventName()).willReturn("custom");
component.registerCustomEvent(eventListener);
// when
component.performEvent(viewDefinitionState, "custom", "arg0", "arg1");
// then
Mockito.verify(eventListener).invokeEvent(viewDefinitionState, component, new String[] { "arg0", "arg1" });
}
use of com.qcadoo.view.internal.components.form.FormComponentState in project qcadoo by qcadoo.
the class DefaultEventHandlerTest method shouldNotThrowExceptionWhenEventNotExists.
@Test
public void shouldNotThrowExceptionWhenEventNotExists() 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, "noSuchMethod");
}
use of com.qcadoo.view.internal.components.form.FormComponentState in project qcadoo by qcadoo.
the class FieldEntityIdChangeListenerTest method shouldHaveFieldListeners.
@Test
public void shouldHaveFieldListeners() throws Exception {
// given
ComponentState component1 = createMockComponent("component1");
ComponentState component2 = createMockComponent("component2");
FormComponentPattern pattern = mock(FormComponentPattern.class);
given(pattern.getExpressionNew()).willReturn(null);
given(pattern.getExpressionEdit()).willReturn(null);
ApplicationContext applicationContext = mock(ApplicationContext.class);
setField(pattern, "applicationContext", applicationContext);
FormComponentState container = new FormComponentState(pattern);
container.addFieldEntityIdChangeListener("field1", (FieldEntityIdChangeListener) component1);
container.addFieldEntityIdChangeListener("field2", (FieldEntityIdChangeListener) component2);
// when
container.setFieldValue(13L);
// then
verify((FieldEntityIdChangeListener) component1).onFieldEntityIdChange(13L);
verify((FieldEntityIdChangeListener) component2).onFieldEntityIdChange(13L);
}
Aggregations