use of com.qcadoo.view.internal.components.form.FormComponentPattern in project qcadoo by qcadoo.
the class ComponentStateTest method shouldNotHaveRequestUpdateStateIfNotValid.
@Test
public void shouldNotHaveRequestUpdateStateIfNotValid() throws Exception {
// given
TranslationService translationService = mock(TranslationService.class);
FormComponentPattern pattern = mock(FormComponentPattern.class);
given(pattern.getExpressionNew()).willReturn(null);
given(pattern.getExpressionEdit()).willReturn(null);
ApplicationContext applicationContext = mock(ApplicationContext.class);
setField(pattern, "applicationContext", applicationContext);
AbstractComponentState componentState = new FormComponentState(pattern);
componentState.setTranslationService(translationService);
componentState.initialize(new JSONObject(ImmutableMap.of("components", new JSONObject())), Locale.ENGLISH);
componentState.addMessage("test", MessageType.FAILURE);
// when
JSONObject json = componentState.render();
// then
assertFalse(json.getBoolean(AbstractComponentState.JSON_UPDATE_STATE));
}
use of com.qcadoo.view.internal.components.form.FormComponentPattern 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);
}
use of com.qcadoo.view.internal.components.form.FormComponentPattern in project qcadoo by qcadoo.
the class ContainerStateTest method shouldHaveChildren.
@Test
public void shouldHaveChildren() 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);
// when
Map<String, InternalComponentState> children = container.getChildren();
// then
assertNotNull(children);
assertEquals(2, children.size());
}
use of com.qcadoo.view.internal.components.form.FormComponentPattern in project qcadoo by qcadoo.
the class ContainerStateTest method shouldReturnChildByName.
@Test
public void shouldReturnChildByName() throws Exception {
// given
InternalComponentState component = createMockComponent("component");
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(component);
// when
ComponentState child = container.getChild("component");
// then
assertSame(component, child);
}
use of com.qcadoo.view.internal.components.form.FormComponentPattern in project qcadoo by qcadoo.
the class DefaultEventHandlerTest method shouldCallMultipleEventMethods.
@Test
public void shouldCallMultipleEventMethods() 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);
ViewEventListenerHook eventListener1 = mock(ViewEventListenerHook.class);
given(eventListener1.getEventName()).willReturn("clear");
component.registerCustomEvent(eventListener1);
ViewEventListenerHook eventListener2 = mock(ViewEventListenerHook.class);
given(eventListener2.getEventName()).willReturn("clear");
component.registerCustomEvent(eventListener2);
// when
component.performEvent(viewDefinitionState, "clear");
// then
assertNull("value is " + component.getFieldValue(), component.getFieldValue());
Mockito.verify(eventListener1).invokeEvent(viewDefinitionState, component, new String[0]);
Mockito.verify(eventListener2).invokeEvent(viewDefinitionState, component, new String[0]);
}
Aggregations