Search in sources :

Example 16 with FormComponentPattern

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));
}
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) FormComponentState(com.qcadoo.view.internal.components.form.FormComponentState) Test(org.junit.Test)

Example 17 with FormComponentPattern

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

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

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

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

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