Search in sources :

Example 21 with ComponentDefinition

use of com.qcadoo.view.internal.ComponentDefinition 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 22 with ComponentDefinition

use of com.qcadoo.view.internal.ComponentDefinition in project qcadoo by qcadoo.

the class ComponentPatternTest method shouldHaveHasDescriptionFlag.

@Test
public void shouldHaveHasDescriptionFlag() throws Exception {
    // given
    ComponentDefinition componentDefinition = getComponentDefinition("testName", null);
    componentDefinition.setHasDescription(true);
    AbstractComponentPattern pattern = new TextInputComponentPattern(componentDefinition);
    // then
    assertTrue(pattern.isHasDescription());
}
Also used : ComponentDefinition(com.qcadoo.view.internal.ComponentDefinition) TextInputComponentPattern(com.qcadoo.view.internal.components.TextInputComponentPattern) Test(org.junit.Test)

Aggregations

ComponentDefinition (com.qcadoo.view.internal.ComponentDefinition)22 Test (org.junit.Test)15 InternalViewDefinition (com.qcadoo.view.internal.api.InternalViewDefinition)13 DataDefinition (com.qcadoo.model.api.DataDefinition)9 ComponentOption (com.qcadoo.view.internal.ComponentOption)8 GridComponentPattern (com.qcadoo.view.internal.components.grid.GridComponentPattern)8 AbstractPatternTest (com.qcadoo.view.internal.patterns.AbstractPatternTest)8 TextInputComponentPattern (com.qcadoo.view.internal.components.TextInputComponentPattern)7 FieldDefinition (com.qcadoo.model.api.FieldDefinition)6 JSONObject (org.json.JSONObject)6 TranslationService (com.qcadoo.localization.api.TranslationService)4 ComponentState (com.qcadoo.view.api.ComponentState)4 InternalViewDefinitionState (com.qcadoo.view.internal.api.InternalViewDefinitionState)4 Node (org.w3c.dom.Node)4 EnumType (com.qcadoo.model.internal.types.EnumType)3 GridComponent (com.qcadoo.view.api.components.GridComponent)3 Map (java.util.Map)3 ImmutableMap (com.google.common.collect.ImmutableMap)2 BelongsToType (com.qcadoo.model.api.types.BelongsToType)2 HasManyType (com.qcadoo.model.api.types.HasManyType)2