Search in sources :

Example 21 with FormComponentState

use of com.qcadoo.view.internal.components.form.FormComponentState 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);
}
Also used : FormComponentPattern(com.qcadoo.view.internal.components.form.FormComponentPattern) JSONObject(org.json.JSONObject) InternalComponentState(com.qcadoo.view.internal.api.InternalComponentState) FormComponentState(com.qcadoo.view.internal.components.form.FormComponentState) Test(org.junit.Test)

Example 22 with FormComponentState

use of com.qcadoo.view.internal.components.form.FormComponentState 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());
}
Also used : FormComponentPattern(com.qcadoo.view.internal.components.form.FormComponentPattern) InternalComponentState(com.qcadoo.view.internal.api.InternalComponentState) FormComponentState(com.qcadoo.view.internal.components.form.FormComponentState) Test(org.junit.Test)

Example 23 with FormComponentState

use of com.qcadoo.view.internal.components.form.FormComponentState 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);
}
Also used : FormComponentPattern(com.qcadoo.view.internal.components.form.FormComponentPattern) InternalComponentState(com.qcadoo.view.internal.api.InternalComponentState) FormComponentState(com.qcadoo.view.internal.components.form.FormComponentState) ComponentState(com.qcadoo.view.api.ComponentState) FormComponentState(com.qcadoo.view.internal.components.form.FormComponentState) InternalComponentState(com.qcadoo.view.internal.api.InternalComponentState) Test(org.junit.Test)

Example 24 with FormComponentState

use of com.qcadoo.view.internal.components.form.FormComponentState 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]);
}
Also used : ViewEventListenerHook(com.qcadoo.view.internal.hooks.ViewEventListenerHook) FormComponentPattern(com.qcadoo.view.internal.components.form.FormComponentPattern) ViewDefinitionState(com.qcadoo.view.api.ViewDefinitionState) FormComponentState(com.qcadoo.view.internal.components.form.FormComponentState) Test(org.junit.Test)

Aggregations

FormComponentState (com.qcadoo.view.internal.components.form.FormComponentState)24 FormComponentPattern (com.qcadoo.view.internal.components.form.FormComponentPattern)18 Test (org.junit.Test)17 JSONObject (org.json.JSONObject)12 InternalComponentState (com.qcadoo.view.internal.api.InternalComponentState)8 ViewDefinitionState (com.qcadoo.view.api.ViewDefinitionState)5 ApplicationContext (org.springframework.context.ApplicationContext)5 TranslationService (com.qcadoo.localization.api.TranslationService)4 ComponentState (com.qcadoo.view.api.ComponentState)4 DataDefinition (com.qcadoo.model.api.DataDefinition)3 Entity (com.qcadoo.model.api.Entity)3 AbstractStateTest (com.qcadoo.view.internal.states.AbstractStateTest)3 ExpressionServiceImpl (com.qcadoo.model.internal.ExpressionServiceImpl)2 FormComponent (com.qcadoo.view.api.components.FormComponent)2 InternalViewDefinitionState (com.qcadoo.view.internal.api.InternalViewDefinitionState)2 ViewEventListenerHook (com.qcadoo.view.internal.hooks.ViewEventListenerHook)2 ViewDefinitionStateImpl (com.qcadoo.view.internal.internal.ViewDefinitionStateImpl)2 JSONArray (org.json.JSONArray)2 FieldDefinition (com.qcadoo.model.api.FieldDefinition)1 DefaultEntity (com.qcadoo.model.internal.DefaultEntity)1