use of com.qcadoo.view.internal.components.TextInputComponentPattern in project qcadoo by qcadoo.
the class InitializationTest method shouldTakeDataDefinitionFromView.
@Test
public void shouldTakeDataDefinitionFromView() throws Exception {
// given
DataDefinition dataDefinition = mock(DataDefinition.class);
InternalViewDefinition viewDefinition = mock(InternalViewDefinition.class);
given(viewDefinition.getDataDefinition()).willReturn(dataDefinition);
AbstractComponentPattern pattern = new TextInputComponentPattern(getComponentDefinition("test", viewDefinition));
// when
pattern.initialize();
// then
Assert.assertEquals(dataDefinition, ReflectionTestUtils.getField(pattern, "dataDefinition"));
}
use of com.qcadoo.view.internal.components.TextInputComponentPattern 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"));
}
use of com.qcadoo.view.internal.components.TextInputComponentPattern 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"));
}
use of com.qcadoo.view.internal.components.TextInputComponentPattern in project qcadoo by qcadoo.
the class ComponentPatternTest method shouldAddItselfToParentOnInitialize.
@Test
public void shouldAddItselfToParentOnInitialize() throws Exception {
// given
InternalViewDefinition viewDefinition = mock(InternalViewDefinition.class);
AbstractContainerPattern parent = new WindowComponentPattern(getComponentDefinition("test", viewDefinition));
ComponentPattern pattern = new TextInputComponentPattern(getComponentDefinition("testName", "testField", null, parent, viewDefinition));
// when
pattern.initialize();
// then
assertEquals(pattern, parent.getFieldEntityIdChangeListeners().get("testField"));
}
use of com.qcadoo.view.internal.components.TextInputComponentPattern in project qcadoo by qcadoo.
the class ComponentPatternTest method shouldHaveReferenceName.
@Test
public void shouldHaveReferenceName() throws Exception {
// given
ComponentDefinition componentDefinition = getComponentDefinition("testName", null);
componentDefinition.setReference("uniqueReferenceName");
AbstractComponentPattern pattern = new TextInputComponentPattern(componentDefinition);
// then
assertEquals("uniqueReferenceName", pattern.getReference());
}
Aggregations