Search in sources :

Example 1 with FormComponentPattern

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));
}
Also used : ApplicationContext(org.springframework.context.ApplicationContext) FormComponentPattern(com.qcadoo.view.internal.components.form.FormComponentPattern) JSONObject(org.json.JSONObject) TranslationService(com.qcadoo.localization.api.TranslationService) ExpressionServiceImpl(com.qcadoo.model.internal.ExpressionServiceImpl) DataDefinition(com.qcadoo.model.api.DataDefinition) FormComponentState(com.qcadoo.view.internal.components.form.FormComponentState) Test(org.junit.Test)

Example 2 with FormComponentPattern

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);
}
Also used : FormComponentPattern(com.qcadoo.view.internal.components.form.FormComponentPattern) 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 3 with FormComponentPattern

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

Example 4 with FormComponentPattern

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));
}
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 5 with FormComponentPattern

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

Aggregations

FormComponentPattern (com.qcadoo.view.internal.components.form.FormComponentPattern)28 Test (org.junit.Test)27 FormComponentState (com.qcadoo.view.internal.components.form.FormComponentState)18 InternalComponentState (com.qcadoo.view.internal.api.InternalComponentState)8 JSONObject (org.json.JSONObject)8 ViewDefinitionState (com.qcadoo.view.api.ViewDefinitionState)6 ComponentPattern (com.qcadoo.view.internal.api.ComponentPattern)6 TextInputComponentPattern (com.qcadoo.view.internal.components.TextInputComponentPattern)6 ApplicationContext (org.springframework.context.ApplicationContext)6 TranslationService (com.qcadoo.localization.api.TranslationService)5 DataDefinition (com.qcadoo.model.api.DataDefinition)5 ComponentState (com.qcadoo.view.api.ComponentState)5 InternalViewDefinition (com.qcadoo.view.internal.api.InternalViewDefinition)3 ViewEventListenerHook (com.qcadoo.view.internal.hooks.ViewEventListenerHook)3 AbstractStateTest (com.qcadoo.view.internal.states.AbstractStateTest)3 FieldDefinition (com.qcadoo.model.api.FieldDefinition)2 ExpressionServiceImpl (com.qcadoo.model.internal.ExpressionServiceImpl)2 ComponentDefinition (com.qcadoo.view.internal.ComponentDefinition)2 InternalViewDefinitionState (com.qcadoo.view.internal.api.InternalViewDefinitionState)2 WindowComponentPattern (com.qcadoo.view.internal.components.window.WindowComponentPattern)2