Search in sources :

Example 21 with FormComponentPattern

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

the class ComponentPatternTest method shouldFailWithoutName.

@Test
public void shouldFailWithoutName() throws Exception {
    // when
    try {
        new FormComponentPattern(new ComponentDefinition());
        Assert.fail();
    } catch (IllegalArgumentException ignored) {
    // Success
    }
}
Also used : FormComponentPattern(com.qcadoo.view.internal.components.form.FormComponentPattern) ComponentDefinition(com.qcadoo.view.internal.ComponentDefinition) Test(org.junit.Test)

Example 22 with FormComponentPattern

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

the class ComponentPatternTest method shouldHaveValidInstance.

@Test
@SuppressWarnings("unchecked")
public void shouldHaveValidInstance() throws Exception {
    // given
    InternalViewDefinitionState viewDefinitionState = mock(InternalViewDefinitionState.class);
    TranslationService translationService = mock(TranslationService.class);
    ApplicationContext applicationContext = mock(ApplicationContext.class);
    InternalViewDefinition viewDefinition = mock(InternalViewDefinition.class);
    ComponentDefinition componentDefinition = getComponentDefinition("testName", null);
    componentDefinition.setTranslationService(translationService);
    componentDefinition.setApplicationContext(applicationContext);
    componentDefinition.setViewDefinition(viewDefinition);
    AbstractComponentPattern pattern = new FormComponentPattern(componentDefinition);
    ViewEventListenerHook viewEventListenerHook = mock(ViewEventListenerHook.class);
    given(viewEventListenerHook.getEventName()).willReturn("save");
    pattern.addCustomEvent(viewEventListenerHook);
    // when
    ComponentState state = pattern.createComponentState(viewDefinitionState);
    // then
    assertTrue(state instanceof FormComponent);
    EventHandlerHolder eventHandlerHolder = (EventHandlerHolder) getField(state, "eventHandlerHolder");
    Map<String, List<EventHandlerHolder.EventHandler>> eventHandlers = (Map<String, List<EventHandlerHolder.EventHandler>>) getField(eventHandlerHolder, "eventHandlers");
    List<EventHandlerHolder.EventHandler> handlers = eventHandlers.get("save");
    assertNotNull(handlers);
    assertEquals(2, handlers.size());
    assertEquals(viewEventListenerHook, handlers.get(1));
}
Also used : FormComponent(com.qcadoo.view.api.components.FormComponent) InternalViewDefinitionState(com.qcadoo.view.internal.api.InternalViewDefinitionState) InternalViewDefinition(com.qcadoo.view.internal.api.InternalViewDefinition) EventHandlerHolder(com.qcadoo.view.internal.internal.EventHandlerHolder) ApplicationContext(org.springframework.context.ApplicationContext) ViewEventListenerHook(com.qcadoo.view.internal.hooks.ViewEventListenerHook) FormComponentPattern(com.qcadoo.view.internal.components.form.FormComponentPattern) TranslationService(com.qcadoo.localization.api.TranslationService) List(java.util.List) Map(java.util.Map) ComponentDefinition(com.qcadoo.view.internal.ComponentDefinition) ComponentState(com.qcadoo.view.api.ComponentState) Test(org.junit.Test)

Example 23 with FormComponentPattern

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

the class ComponentPatternTest method shouldHaveName.

@Test
public void shouldHaveName() throws Exception {
    // given
    ComponentPattern pattern = new FormComponentPattern(getComponentDefinition("testName", null));
    // when
    String name = pattern.getName();
    // then
    Assert.assertEquals("testName", name);
}
Also used : FormComponentPattern(com.qcadoo.view.internal.components.form.FormComponentPattern) FormComponentPattern(com.qcadoo.view.internal.components.form.FormComponentPattern) TextInputComponentPattern(com.qcadoo.view.internal.components.TextInputComponentPattern) WindowComponentPattern(com.qcadoo.view.internal.components.window.WindowComponentPattern) ComponentPattern(com.qcadoo.view.internal.api.ComponentPattern) Test(org.junit.Test)

Example 24 with FormComponentPattern

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

the class ContainerPatternTest method shouldHaveChildren.

@Test
public void shouldHaveChildren() throws Exception {
    // given
    AbstractContainerPattern parent = new FormComponentPattern(getComponentDefinition("test", null));
    ComponentPattern child1 = new TextInputComponentPattern(getComponentDefinition("test1", parent, null));
    ComponentPattern child2 = new TextInputComponentPattern(getComponentDefinition("test2", parent, null));
    parent.addChild(child1);
    parent.addChild(child2);
    // when
    Map<String, ComponentPattern> children = parent.getChildren();
    // then
    Assert.assertEquals(2, children.size());
    Assert.assertEquals(child1, children.get("test1"));
    Assert.assertEquals(child2, children.get("test2"));
}
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)

Example 25 with FormComponentPattern

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

the class ContainerPatternTest method shouldReturnNullWhenChildNotExist.

@Test
public void shouldReturnNullWhenChildNotExist() throws Exception {
    // given
    AbstractContainerPattern parent = new FormComponentPattern(getComponentDefinition("test", null));
    // when
    ComponentPattern child = parent.getChild("test3");
    // then
    Assert.assertNull(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) 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