Search in sources :

Example 1 with ComponentState

use of com.qcadoo.view.api.ComponentState in project qcadoo by qcadoo.

the class GridComponentPatternTest method shouldNotFilterOutColumnsVisibleForTenant.

@Test
public void shouldNotFilterOutColumnsVisibleForTenant() throws Exception {
    // given
    PluginStateResolver pluginStateResolver = mock(PluginStateResolver.class);
    PluginUtilsService pluginUtil = new PluginUtilsService(pluginStateResolver);
    pluginUtil.init();
    given(pluginStateResolver.isEnabled("disabledPlugin")).willReturn(true);
    InternalViewDefinitionState viewDefinitionState = mock(InternalViewDefinitionState.class);
    DataDefinition dataDefinition = mock(DataDefinition.class);
    InternalViewDefinition viewDefinition = mock(InternalViewDefinition.class);
    given(viewDefinition.getDataDefinition()).willReturn(dataDefinition);
    ComponentDefinition componentDefinition = getComponentDefinition(QcadooViewConstants.L_GRID, viewDefinition);
    componentDefinition.setTranslationService(translationService);
    componentDefinition.setApplicationContext(applicationContext);
    componentDefinition.setDataDefinition(dataDefinition);
    GridComponentPattern pattern = new GridComponentPattern(componentDefinition);
    FieldDefinition nameFieldDefinition = mock(FieldDefinition.class);
    given(nameFieldDefinition.getType()).willReturn(new EnumType(translationService, "", true, "v1", "v2"));
    given(dataDefinition.getField("name")).willReturn(nameFieldDefinition);
    pattern.addOption(new ComponentOption("column", ImmutableMap.of("name", "name", "fields", "name", "hidden", "true")));
    pattern.addOption(new ComponentOption("order", ImmutableMap.of("column", "name", "direction", "asc")));
    ViewGridColumnModuleColumnModel columnModel = new ViewGridColumnModuleColumnModel("invisible", "name");
    columnModel.setWidth(100);
    pattern.addColumn("disabledPlugin", columnModel);
    pattern.initialize();
    // when
    ComponentState state = pattern.createComponentState(viewDefinitionState);
    // then
    assertTrue(state instanceof GridComponent);
    @SuppressWarnings("unchecked") Map<String, GridComponentColumn> patternColumns = (Map<String, GridComponentColumn>) getField(pattern, "columns");
    @SuppressWarnings("unchecked") Map<String, GridComponentColumn> stateColumns = (Map<String, GridComponentColumn>) getField(state, "columns");
    assertEquals(2, patternColumns.size());
    assertEquals(2, stateColumns.size());
    assertTrue(patternColumns.keySet().contains("name"));
    assertNotNull(patternColumns.get("name"));
    assertTrue(patternColumns.keySet().contains("invisible"));
    assertNotNull(patternColumns.get("invisible"));
    assertTrue(stateColumns.keySet().contains("name"));
    assertNotNull(stateColumns.get("name"));
    assertTrue(stateColumns.keySet().contains("invisible"));
    assertNotNull(stateColumns.get("invisible"));
}
Also used : PluginUtilsService(com.qcadoo.plugin.internal.PluginUtilsService) ViewGridColumnModuleColumnModel(com.qcadoo.view.internal.module.gridColumn.ViewGridColumnModuleColumnModel) InternalViewDefinitionState(com.qcadoo.view.internal.api.InternalViewDefinitionState) InternalViewDefinition(com.qcadoo.view.internal.api.InternalViewDefinition) ComponentOption(com.qcadoo.view.internal.ComponentOption) GridComponent(com.qcadoo.view.api.components.GridComponent) FieldDefinition(com.qcadoo.model.api.FieldDefinition) GridComponentColumn(com.qcadoo.view.internal.components.grid.GridComponentColumn) DataDefinition(com.qcadoo.model.api.DataDefinition) GridComponentPattern(com.qcadoo.view.internal.components.grid.GridComponentPattern) PluginStateResolver(com.qcadoo.plugin.api.PluginStateResolver) EnumType(com.qcadoo.model.internal.types.EnumType) Map(java.util.Map) ImmutableMap(com.google.common.collect.ImmutableMap) ComponentDefinition(com.qcadoo.view.internal.ComponentDefinition) ComponentState(com.qcadoo.view.api.ComponentState) AbstractPatternTest(com.qcadoo.view.internal.patterns.AbstractPatternTest) Test(org.junit.Test)

Example 2 with ComponentState

use of com.qcadoo.view.api.ComponentState in project qcadoo by qcadoo.

the class ContainerStateTest method shouldReturnNullIfChildNotExist.

@Test
public void shouldReturnNullIfChildNotExist() throws Exception {
    // given
    FormComponentPattern pattern = mock(FormComponentPattern.class);
    given(pattern.getExpressionNew()).willReturn(null);
    given(pattern.getExpressionEdit()).willReturn(null);
    setField(pattern, "applicationContext", applicationContext);
    FormComponentState container = new FormComponentState(pattern);
    // when
    ComponentState child = container.getChild("component");
    // then
    assertNull(child);
}
Also used : FormComponentPattern(com.qcadoo.view.internal.components.form.FormComponentPattern) 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 3 with ComponentState

use of com.qcadoo.view.api.ComponentState 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 4 with ComponentState

use of com.qcadoo.view.api.ComponentState in project qcadoo by qcadoo.

the class ViewDefinitionStateTest method shouldReturnStateByFunctionalPath.

@Test
public void shouldReturnStateByFunctionalPath() throws Exception {
    // given
    InternalViewDefinitionState viewDefinitionState = new ViewDefinitionStateImpl();
    ContainerState state = mock(ContainerState.class);
    viewDefinitionState.registerComponent("reference", state);
    // when
    ComponentState actualState = viewDefinitionState.getComponentByReference("reference");
    // then
    assertEquals(state, actualState);
}
Also used : InternalViewDefinitionState(com.qcadoo.view.internal.api.InternalViewDefinitionState) ViewDefinitionStateImpl(com.qcadoo.view.internal.internal.ViewDefinitionStateImpl) ContainerState(com.qcadoo.view.internal.api.ContainerState) ComponentState(com.qcadoo.view.api.ComponentState) InternalComponentState(com.qcadoo.view.internal.api.InternalComponentState) Test(org.junit.Test) AbstractStateTest(com.qcadoo.view.internal.states.AbstractStateTest)

Example 5 with ComponentState

use of com.qcadoo.view.api.ComponentState in project qcadoo by qcadoo.

the class ScopeEntityIdChangeListenerTest method shouldHaveScopeListeners.

@Test
public void shouldHaveScopeListeners() 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.addScopeEntityIdChangeListener("component1", (ScopeEntityIdChangeListener) component1);
    container.addScopeEntityIdChangeListener("component2", (ScopeEntityIdChangeListener) component2);
    // when
    container.setFieldValue(13L);
    // then
    verify((ScopeEntityIdChangeListener) component1).onScopeEntityIdChange(13L);
    verify((ScopeEntityIdChangeListener) component2).onScopeEntityIdChange(13L);
}
Also used : ApplicationContext(org.springframework.context.ApplicationContext) FormComponentPattern(com.qcadoo.view.internal.components.form.FormComponentPattern) ScopeEntityIdChangeListener(com.qcadoo.view.internal.ScopeEntityIdChangeListener) 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)

Aggregations

ComponentState (com.qcadoo.view.api.ComponentState)68 Entity (com.qcadoo.model.api.Entity)33 FormComponent (com.qcadoo.view.api.components.FormComponent)31 GridComponent (com.qcadoo.view.api.components.GridComponent)23 ViewDefinitionState (com.qcadoo.view.api.ViewDefinitionState)21 Autowired (org.springframework.beans.factory.annotation.Autowired)17 FieldComponent (com.qcadoo.view.api.components.FieldComponent)16 Test (org.junit.Test)16 Service (org.springframework.stereotype.Service)16 QcadooViewConstants (com.qcadoo.view.constants.QcadooViewConstants)15 Collectors (java.util.stream.Collectors)14 List (java.util.List)13 DataDefinition (com.qcadoo.model.api.DataDefinition)12 Lists (com.google.common.collect.Lists)11 DataDefinitionService (com.qcadoo.model.api.DataDefinitionService)11 Map (java.util.Map)11 BigDecimal (java.math.BigDecimal)10 Maps (com.google.common.collect.Maps)8 LookupComponent (com.qcadoo.view.api.components.LookupComponent)8 Transactional (org.springframework.transaction.annotation.Transactional)8