Search in sources :

Example 6 with FormComponentPattern

use of com.qcadoo.view.internal.components.form.FormComponentPattern 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 7 with FormComponentPattern

use of com.qcadoo.view.internal.components.form.FormComponentPattern 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 8 with FormComponentPattern

use of com.qcadoo.view.internal.components.form.FormComponentPattern 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)

Example 9 with FormComponentPattern

use of com.qcadoo.view.internal.components.form.FormComponentPattern in project qcadoo by qcadoo.

the class ContainerPatternTest method shouldNotCallInitializeOnChildren.

@Test
public void shouldNotCallInitializeOnChildren() throws Exception {
    // given
    InternalViewDefinition viewDefinition = Mockito.mock(InternalViewDefinition.class);
    ComponentPattern child = Mockito.mock(ComponentPattern.class);
    AbstractContainerPattern parent = new FormComponentPattern(getComponentDefinition("test", viewDefinition));
    parent.addChild(child);
    // when
    parent.initialize();
    // then
    Mockito.verify(child, never()).initialize();
}
Also used : FormComponentPattern(com.qcadoo.view.internal.components.form.FormComponentPattern) InternalViewDefinition(com.qcadoo.view.internal.api.InternalViewDefinition) FormComponentPattern(com.qcadoo.view.internal.components.form.FormComponentPattern) ComponentPattern(com.qcadoo.view.internal.api.ComponentPattern) TextInputComponentPattern(com.qcadoo.view.internal.components.TextInputComponentPattern) Test(org.junit.Test)

Example 10 with FormComponentPattern

use of com.qcadoo.view.internal.components.form.FormComponentPattern in project qcadoo by qcadoo.

the class ContainerPatternTest method shouldReturnChildByName.

@Test
public void shouldReturnChildByName() throws Exception {
    // given
    AbstractContainerPattern parent = new FormComponentPattern(getComponentDefinition("test", null));
    ComponentPattern child1 = new TextInputComponentPattern(getComponentDefinition("test1", parent, null));
    parent.addChild(child1);
    // when
    ComponentPattern child = parent.getChild("test1");
    // then
    Assert.assertEquals(child1, child);
}
Also used : FormComponentPattern(com.qcadoo.view.internal.components.form.FormComponentPattern) FormComponentPattern(com.qcadoo.view.internal.components.form.FormComponentPattern) ComponentPattern(com.qcadoo.view.internal.api.ComponentPattern) TextInputComponentPattern(com.qcadoo.view.internal.components.TextInputComponentPattern) TextInputComponentPattern(com.qcadoo.view.internal.components.TextInputComponentPattern) 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