Search in sources :

Example 26 with FormComponentPattern

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

the class ContainerPatternTest method shouldCallStateOnChildren.

@Test
public void shouldCallStateOnChildren() throws Exception {
    // given
    ViewDefinitionState viewDefinitionState = Mockito.mock(ViewDefinitionState.class);
    AbstractComponentPattern child = Mockito.mock(AbstractComponentPattern.class);
    AbstractContainerPattern parent = new FormComponentPattern(getComponentDefinition("test", null));
    parent.addChild(child);
    // when
    parent.updateComponentStateListeners(viewDefinitionState);
    // then
    Mockito.verify(child).updateComponentStateListeners(viewDefinitionState);
}
Also used : FormComponentPattern(com.qcadoo.view.internal.components.form.FormComponentPattern) ViewDefinitionState(com.qcadoo.view.api.ViewDefinitionState) InternalViewDefinitionState(com.qcadoo.view.internal.api.InternalViewDefinitionState) Test(org.junit.Test)

Example 27 with FormComponentPattern

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

the class InitializationTest method shouldInitializeAllComponents.

@Test
public void shouldInitializeAllComponents() throws Exception {
    // given
    DataDefinition dataDefinition = mock(DataDefinition.class);
    DataDefinition hasManyDataDefinition = mock(DataDefinition.class);
    DataDefinition belongsToDataDefinition = mock(DataDefinition.class);
    FieldDefinition fieldDefinition = mock(FieldDefinition.class);
    FieldDefinition hasManyFieldDefinition = mock(FieldDefinition.class);
    FieldDefinition belongsToFieldDefinition = mock(FieldDefinition.class);
    FieldType fieldType = mock(FieldType.class);
    BelongsToType belongsToType = mock(BelongsToType.class);
    HasManyType hasManyType = mock(HasManyType.class);
    given(dataDefinition.getField("hasMany")).willReturn(hasManyFieldDefinition);
    given(belongsToDataDefinition.getField("hasMany")).willReturn(hasManyFieldDefinition);
    given(dataDefinition.getField("belongsTo")).willReturn(belongsToFieldDefinition);
    given(dataDefinition.getField("field")).willReturn(fieldDefinition);
    given(fieldDefinition.getType()).willReturn(fieldType);
    given(hasManyFieldDefinition.getType()).willReturn(hasManyType);
    given(belongsToFieldDefinition.getType()).willReturn(belongsToType);
    given(hasManyType.getDataDefinition()).willReturn(hasManyDataDefinition);
    given(belongsToType.getDataDefinition()).willReturn(belongsToDataDefinition);
    InternalViewDefinition viewDefinition = new ViewDefinitionImpl("view", "plugin", dataDefinition, true, null);
    AbstractContainerPattern parent = new FormComponentPattern(getComponentDefinition("parent", viewDefinition));
    AbstractContainerPattern form = new FormComponentPattern(getComponentDefinition(QcadooViewConstants.L_FORM, null, null, parent, viewDefinition));
    AbstractComponentPattern input = new TextInputComponentPattern(getComponentDefinition("input", "field", null, form, viewDefinition));
    AbstractComponentPattern select = new TextInputComponentPattern(getComponentDefinition("select", "belongsTo", null, form, viewDefinition));
    AbstractComponentPattern subselect = new TextInputComponentPattern(getComponentDefinition("subselect", "#{parent.form}.hasMany", "#{parent.form.select}.hasMany", form, viewDefinition));
    AbstractComponentPattern grid = new TextInputComponentPattern(getComponentDefinition(QcadooViewConstants.L_GRID, null, "#{parent.form}.hasMany", parent, viewDefinition));
    parent.addChild(form);
    parent.addChild(grid);
    form.addChild(input);
    form.addChild(select);
    form.addChild(subselect);
    viewDefinition.addComponentPattern(parent);
    // when
    viewDefinition.initialize();
    // then
    assertEquals(dataDefinition, getField(parent, "dataDefinition"));
    assertEquals(dataDefinition, getField(form, "dataDefinition"));
    assertEquals(dataDefinition, getField(input, "dataDefinition"));
    assertEquals(belongsToDataDefinition, getField(select, "dataDefinition"));
    assertEquals(hasManyDataDefinition, getField(subselect, "dataDefinition"));
    assertEquals(hasManyDataDefinition, getField(grid, "dataDefinition"));
    assertNull(getField(parent, "scopeFieldDefinition"));
    assertNull(getField(form, "scopeFieldDefinition"));
    assertNull(getField(input, "scopeFieldDefinition"));
    assertNull(getField(select, "scopeFieldDefinition"));
    assertEquals(hasManyFieldDefinition, getField(subselect, "scopeFieldDefinition"));
    assertEquals(hasManyFieldDefinition, getField(grid, "scopeFieldDefinition"));
    assertNull(getField(parent, "fieldDefinition"));
    assertNull(getField(form, "fieldDefinition"));
    assertEquals(fieldDefinition, getField(input, "fieldDefinition"));
    assertEquals(belongsToFieldDefinition, getField(select, "fieldDefinition"));
    assertEquals(hasManyFieldDefinition, getField(subselect, "fieldDefinition"));
    assertNull(getField(grid, "fieldDefinition"));
}
Also used : HasManyType(com.qcadoo.model.api.types.HasManyType) ViewDefinitionImpl(com.qcadoo.view.internal.internal.ViewDefinitionImpl) BelongsToType(com.qcadoo.model.api.types.BelongsToType) FormComponentPattern(com.qcadoo.view.internal.components.form.FormComponentPattern) InternalViewDefinition(com.qcadoo.view.internal.api.InternalViewDefinition) FieldDefinition(com.qcadoo.model.api.FieldDefinition) DataDefinition(com.qcadoo.model.api.DataDefinition) FieldType(com.qcadoo.model.api.types.FieldType) TextInputComponentPattern(com.qcadoo.view.internal.components.TextInputComponentPattern) Test(org.junit.Test)

Example 28 with FormComponentPattern

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

the class ViewDefinitionTest method shouldReturnJsFilePaths.

@Test
public void shouldReturnJsFilePaths() throws Exception {
    // given
    ViewDefinitionImpl viewDefinition = new ViewDefinitionImpl("name", "plugin", mock(DataDefinition.class), true, null);
    AbstractContainerPattern parent = new WindowComponentPattern(getComponentDefinition("test", viewDefinition));
    ComponentPattern form = new FormComponentPattern(getComponentDefinition("test", parent, viewDefinition));
    parent.addChild(form);
    viewDefinition.addComponentPattern(parent);
    viewDefinition.initialize();
    // when
    Set<String> paths = viewDefinition.getJsFilePaths();
    // then
    Assert.assertEquals(1, paths.size());
}
Also used : ViewDefinitionImpl(com.qcadoo.view.internal.internal.ViewDefinitionImpl) WindowComponentPattern(com.qcadoo.view.internal.components.window.WindowComponentPattern) FormComponentPattern(com.qcadoo.view.internal.components.form.FormComponentPattern) AbstractContainerPattern(com.qcadoo.view.internal.patterns.AbstractContainerPattern) FormComponentPattern(com.qcadoo.view.internal.components.form.FormComponentPattern) WindowComponentPattern(com.qcadoo.view.internal.components.window.WindowComponentPattern) ComponentPattern(com.qcadoo.view.internal.api.ComponentPattern) DataDefinition(com.qcadoo.model.api.DataDefinition) Test(org.junit.Test) AbstractPatternTest(com.qcadoo.view.internal.patterns.AbstractPatternTest)

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