Search in sources :

Example 6 with FormComponentState

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));
}
Also used : JSONObject(org.json.JSONObject) 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 7 with FormComponentState

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());
}
Also used : 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)

Example 8 with FormComponentState

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" });
}
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)

Example 9 with FormComponentState

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");
}
Also used : 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)

Example 10 with FormComponentState

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);
}
Also used : ApplicationContext(org.springframework.context.ApplicationContext) FormComponentPattern(com.qcadoo.view.internal.components.form.FormComponentPattern) FieldEntityIdChangeListener(com.qcadoo.view.internal.FieldEntityIdChangeListener) ComponentState(com.qcadoo.view.api.ComponentState) FormComponentState(com.qcadoo.view.internal.components.form.FormComponentState) 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