Search in sources :

Example 6 with ComponentOption

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

the class SelectComponentStateTest method stubValuesOption.

private void stubValuesOption(String optionValue) throws JSONException {
    SelectComponentPattern pattern = (SelectComponentPattern) getField(componentState, "selectComponentPattern");
    ComponentOption option = new ComponentOption("values", Collections.singletonMap("value", optionValue));
    pattern.addOption(option);
    pattern.initializeComponent();
}
Also used : ComponentOption(com.qcadoo.view.internal.ComponentOption)

Example 7 with ComponentOption

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

the class GridComponentPatternTest method shouldHaveScopeFieldName.

@Test
public void shouldHaveScopeFieldName() throws Exception {
    // given
    DataDefinition dataDefinition = mock(DataDefinition.class);
    BelongsToType belongsToFieldType = mock(BelongsToType.class);
    FieldDefinition belongsToFieldDefinition = mock(FieldDefinition.class);
    given(belongsToFieldDefinition.getName()).willReturn("joinName");
    given(belongsToFieldDefinition.getType()).willReturn(belongsToFieldType);
    given(belongsToFieldDefinition.getDataDefinition()).willReturn(dataDefinition);
    HasManyType hasManyFieldType = mock(HasManyType.class);
    given(hasManyFieldType.getJoinFieldName()).willReturn("joinName");
    given(hasManyFieldType.getDataDefinition()).willReturn(dataDefinition);
    FieldDefinition hasManyFieldDefinition = mock(FieldDefinition.class);
    given(hasManyFieldDefinition.getName()).willReturn("fieldName");
    given(hasManyFieldDefinition.getType()).willReturn(hasManyFieldType);
    given(hasManyFieldDefinition.getDataDefinition()).willReturn(dataDefinition);
    given(dataDefinition.getField("field")).willReturn(hasManyFieldDefinition);
    given(dataDefinition.getField("joinName")).willReturn(belongsToFieldDefinition);
    InternalViewDefinition viewDefinition = mock(InternalViewDefinition.class);
    AbstractComponentPattern sourceComponent = new TextInputComponentPattern(getComponentDefinition("component", viewDefinition));
    setField(sourceComponent, "dataDefinition", dataDefinition);
    setField(sourceComponent, "initialized", true);
    given(viewDefinition.getComponentByReference("component")).willReturn(sourceComponent);
    ComponentDefinition componentDefinition = getComponentDefinition(QcadooViewConstants.L_GRID, null, "#{component}.field", null, viewDefinition);
    componentDefinition.setTranslationService(translationService);
    componentDefinition.setApplicationContext(applicationContext);
    GridComponentPattern pattern = new GridComponentPattern(componentDefinition);
    pattern.addOption(new ComponentOption("order", ImmutableMap.of("column", "name", "direction", "asc")));
    // when
    pattern.initialize();
    // then
    JSONObject options = getJsOptions(pattern);
    assertEquals("joinName", options.getString("belongsToFieldName"));
}
Also used : HasManyType(com.qcadoo.model.api.types.HasManyType) BelongsToType(com.qcadoo.model.api.types.BelongsToType) GridComponentPattern(com.qcadoo.view.internal.components.grid.GridComponentPattern) JSONObject(org.json.JSONObject) AbstractComponentPattern(com.qcadoo.view.internal.patterns.AbstractComponentPattern) InternalViewDefinition(com.qcadoo.view.internal.api.InternalViewDefinition) ComponentOption(com.qcadoo.view.internal.ComponentOption) FieldDefinition(com.qcadoo.model.api.FieldDefinition) DataDefinition(com.qcadoo.model.api.DataDefinition) TextInputComponentPattern(com.qcadoo.view.internal.components.TextInputComponentPattern) ComponentDefinition(com.qcadoo.view.internal.ComponentDefinition) AbstractPatternTest(com.qcadoo.view.internal.patterns.AbstractPatternTest) Test(org.junit.Test)

Example 8 with ComponentOption

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

the class GridComponentPatternTest method shouldBeFullscreen.

@Test
public void shouldBeFullscreen() throws Exception {
    // given
    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);
    GridComponentPattern pattern = new GridComponentPattern(componentDefinition);
    pattern.addOption(new ComponentOption("fullscreen", ImmutableMap.of("value", "true")));
    pattern.addOption(new ComponentOption("order", ImmutableMap.of("column", "name", "direction", "asc")));
    // when
    pattern.initialize();
    // then
    JSONObject options = getJsOptions(pattern);
    assertTrue(options.getBoolean("fullscreen"));
    assertEquals(0, options.getInt("width"));
    assertEquals(0, options.getInt("height"));
}
Also used : GridComponentPattern(com.qcadoo.view.internal.components.grid.GridComponentPattern) JSONObject(org.json.JSONObject) InternalViewDefinition(com.qcadoo.view.internal.api.InternalViewDefinition) ComponentOption(com.qcadoo.view.internal.ComponentOption) DataDefinition(com.qcadoo.model.api.DataDefinition) ComponentDefinition(com.qcadoo.view.internal.ComponentDefinition) AbstractPatternTest(com.qcadoo.view.internal.patterns.AbstractPatternTest) Test(org.junit.Test)

Example 9 with ComponentOption

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

the class GridComponentPatternTest method shouldReturnState.

@Test
public void shouldReturnState() throws Exception {
    // given
    InternalViewDefinitionState viewDefinitionState = mock(InternalViewDefinitionState.class);
    DataDefinition dataDefinition = mock(DataDefinition.class);
    BelongsToType belongsToFieldType = mock(BelongsToType.class);
    FieldDefinition belongsToFieldDefinition = mock(FieldDefinition.class);
    given(belongsToFieldDefinition.getName()).willReturn("joinName");
    given(belongsToFieldDefinition.getType()).willReturn(belongsToFieldType);
    HasManyType hasManyFieldType = mock(HasManyType.class);
    given(hasManyFieldType.getJoinFieldName()).willReturn("joinName");
    given(hasManyFieldType.getDataDefinition()).willReturn(dataDefinition);
    FieldDefinition hasManyFieldDefinition = mock(FieldDefinition.class);
    given(hasManyFieldDefinition.getName()).willReturn("fieldName");
    given(hasManyFieldDefinition.getType()).willReturn(hasManyFieldType);
    given(dataDefinition.getField("field")).willReturn(hasManyFieldDefinition);
    given(dataDefinition.getField("joinName")).willReturn(belongsToFieldDefinition);
    InternalViewDefinition viewDefinition = mock(InternalViewDefinition.class);
    AbstractComponentPattern sourceComponent = new TextInputComponentPattern(getComponentDefinition("component", viewDefinition));
    setField(sourceComponent, "dataDefinition", dataDefinition);
    setField(sourceComponent, "initialized", true);
    given(viewDefinition.getComponentByReference("component")).willReturn(sourceComponent);
    ComponentDefinition componentDefinition = getComponentDefinition(QcadooViewConstants.L_GRID, null, "#{component}.field", null, viewDefinition);
    componentDefinition.setTranslationService(translationService);
    componentDefinition.setApplicationContext(applicationContext);
    GridComponentPattern pattern = new GridComponentPattern(componentDefinition);
    pattern.addOption(new ComponentOption("order", ImmutableMap.of("column", "name", "direction", "asc")));
    pattern.initialize();
    // when
    ComponentState state = pattern.createComponentState(viewDefinitionState);
    // then
    assertTrue(state instanceof GridComponent);
    assertEquals(belongsToFieldDefinition, getField(state, "belongsToFieldDefinition"));
    assertEquals(getField(pattern, "columns"), getField(state, "columns"));
}
Also used : 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) DataDefinition(com.qcadoo.model.api.DataDefinition) TextInputComponentPattern(com.qcadoo.view.internal.components.TextInputComponentPattern) HasManyType(com.qcadoo.model.api.types.HasManyType) BelongsToType(com.qcadoo.model.api.types.BelongsToType) GridComponentPattern(com.qcadoo.view.internal.components.grid.GridComponentPattern) AbstractComponentPattern(com.qcadoo.view.internal.patterns.AbstractComponentPattern) ComponentDefinition(com.qcadoo.view.internal.ComponentDefinition) ComponentState(com.qcadoo.view.api.ComponentState) AbstractPatternTest(com.qcadoo.view.internal.patterns.AbstractPatternTest) Test(org.junit.Test)

Example 10 with ComponentOption

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

the class GridComponentPatternTest method shouldFilterOutColumnsInvisibleForTenant.

@Test
public void shouldFilterOutColumnsInvisibleForTenant() throws Exception {
    // given
    PluginStateResolver pluginStateResolver = mock(PluginStateResolver.class);
    PluginUtilsService pluginUtil = new PluginUtilsService(pluginStateResolver);
    pluginUtil.init();
    given(pluginStateResolver.isEnabled("disabledPlugin")).willReturn(false);
    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(1, 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"));
    assertFalse(stateColumns.keySet().contains("invisible"));
    assertNull(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)

Aggregations

ComponentOption (com.qcadoo.view.internal.ComponentOption)11 DataDefinition (com.qcadoo.model.api.DataDefinition)8 ComponentDefinition (com.qcadoo.view.internal.ComponentDefinition)8 InternalViewDefinition (com.qcadoo.view.internal.api.InternalViewDefinition)8 GridComponentPattern (com.qcadoo.view.internal.components.grid.GridComponentPattern)8 AbstractPatternTest (com.qcadoo.view.internal.patterns.AbstractPatternTest)8 Test (org.junit.Test)8 FieldDefinition (com.qcadoo.model.api.FieldDefinition)5 JSONObject (org.json.JSONObject)5 EnumType (com.qcadoo.model.internal.types.EnumType)3 ComponentState (com.qcadoo.view.api.ComponentState)3 GridComponent (com.qcadoo.view.api.components.GridComponent)3 InternalViewDefinitionState (com.qcadoo.view.internal.api.InternalViewDefinitionState)3 ImmutableMap (com.google.common.collect.ImmutableMap)2 BelongsToType (com.qcadoo.model.api.types.BelongsToType)2 HasManyType (com.qcadoo.model.api.types.HasManyType)2 PluginStateResolver (com.qcadoo.plugin.api.PluginStateResolver)2 PluginUtilsService (com.qcadoo.plugin.internal.PluginUtilsService)2 TextInputComponentPattern (com.qcadoo.view.internal.components.TextInputComponentPattern)2 GridComponentColumn (com.qcadoo.view.internal.components.grid.GridComponentColumn)2