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"));
}
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);
}
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);
}
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);
}
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);
}
Aggregations