use of com.qcadoo.view.internal.components.window.WindowComponentPattern in project qcadoo by qcadoo.
the class ComponentPatternTest method shouldHaveListenersInOptions.
@Test
public void shouldHaveListenersInOptions() throws Exception {
// given
InternalViewDefinition viewDefinition = mock(InternalViewDefinition.class);
AbstractContainerPattern parent = new WindowComponentPattern(getComponentDefinition("f1", viewDefinition));
ComponentPatternMock child1 = new ComponentPatternMock(getComponentDefinition("t1", "t1", null, parent, viewDefinition));
ComponentPatternMock child2 = new ComponentPatternMock(getComponentDefinition("t2", "t2", null, parent, viewDefinition));
ComponentPatternMock child3 = new ComponentPatternMock(getComponentDefinition("t3", null, "t3", parent, viewDefinition));
parent.addChild(child1);
parent.addChild(child2);
parent.addChild(child3);
parent.initialize();
child1.initialize();
child2.initialize();
child3.initialize();
// when
Map<String, Object> model = parent.prepareView(Locale.ENGLISH);
// then
JSONObject options = (JSONObject) model.get("jsOptions");
JSONArray listenersArray = options.getJSONArray("listeners");
assertEquals(3, listenersArray.length());
assertTrue(jsonArrayContain(listenersArray, "f1.t1"));
assertTrue(jsonArrayContain(listenersArray, "f1.t2"));
assertTrue(jsonArrayContain(listenersArray, "f1.t3"));
}
use of com.qcadoo.view.internal.components.window.WindowComponentPattern in project qcadoo by qcadoo.
the class ComponentPatternTest method shouldReturnValidPath.
@Test
public void shouldReturnValidPath() throws Exception {
// given
ContainerPattern root = new WindowComponentPattern(getComponentDefinition("rootName", null));
ContainerPattern child1 = new WindowComponentPattern(getComponentDefinition("child1", root, null));
ComponentPattern child2 = new TextInputComponentPattern(getComponentDefinition("child2", root, null));
ComponentPattern child11 = new TextInputComponentPattern(getComponentDefinition("child11", child1, null));
// when
String rootPathName = root.getPath();
String child1PathName = child1.getPath();
String child2PathName = child2.getPath();
String child11PathName = child11.getPath();
// then
Assert.assertEquals("rootName", rootPathName);
Assert.assertEquals("rootName.child1", child1PathName);
Assert.assertEquals("rootName.child2", child2PathName);
Assert.assertEquals("rootName.child1.child11", child11PathName);
}
use of com.qcadoo.view.internal.components.window.WindowComponentPattern in project qcadoo by qcadoo.
the class InitializationTest method shouldTakeDataDefinitionFromParent.
@Test
public void shouldTakeDataDefinitionFromParent() throws Exception {
// given
DataDefinition dataDefinition = mock(DataDefinition.class);
InternalViewDefinition viewDefinition = mock(InternalViewDefinition.class);
AbstractContainerPattern parent = new WindowComponentPattern(getComponentDefinition("parent", viewDefinition));
setField(parent, "dataDefinition", dataDefinition);
AbstractComponentPattern pattern = new TextInputComponentPattern(getComponentDefinition("test", parent, viewDefinition));
// when
pattern.initialize();
// then
Assert.assertEquals(dataDefinition, getField(pattern, "dataDefinition"));
}
use of com.qcadoo.view.internal.components.window.WindowComponentPattern in project qcadoo by qcadoo.
the class InitializationTest method shouldGetDataDefinitionFromBelongsToTypeFieldDefinition.
@Test
public void shouldGetDataDefinitionFromBelongsToTypeFieldDefinition() throws Exception {
// given
BelongsToType fieldType = mock(BelongsToType.class);
FieldDefinition fieldDefinition = mock(FieldDefinition.class);
given(fieldDefinition.getType()).willReturn(fieldType);
DataDefinition dataDefinition = mock(DataDefinition.class);
given(dataDefinition.getField("field")).willReturn(fieldDefinition);
DataDefinition belongsToDefinition = mock(DataDefinition.class);
given(fieldType.getDataDefinition()).willReturn(belongsToDefinition);
InternalViewDefinition viewDefinition = mock(InternalViewDefinition.class);
AbstractContainerPattern parent = new WindowComponentPattern(getComponentDefinition("parent", viewDefinition));
setField(parent, "dataDefinition", dataDefinition);
setField(parent, "initialized", true);
AbstractComponentPattern pattern = new TextInputComponentPattern(getComponentDefinition("test", "field", null, parent, viewDefinition));
// when
pattern.initialize();
// then
Assert.assertEquals(belongsToDefinition, getField(pattern, "dataDefinition"));
Assert.assertEquals(fieldDefinition, getField(pattern, "fieldDefinition"));
}
use of com.qcadoo.view.internal.components.window.WindowComponentPattern in project qcadoo by qcadoo.
the class InitializationTest method shouldGetDataDefinitionFromHasManyTypeScopeFieldDefinition.
@Test
public void shouldGetDataDefinitionFromHasManyTypeScopeFieldDefinition() throws Exception {
// given
HasManyType fieldType = mock(HasManyType.class);
FieldDefinition fieldDefinition = mock(FieldDefinition.class);
given(fieldDefinition.getType()).willReturn(fieldType);
DataDefinition dataDefinition = mock(DataDefinition.class);
given(dataDefinition.getField("field")).willReturn(fieldDefinition);
DataDefinition belongsToDefinition = mock(DataDefinition.class);
given(fieldType.getDataDefinition()).willReturn(belongsToDefinition);
InternalViewDefinition viewDefinition = mock(InternalViewDefinition.class);
AbstractContainerPattern parent = new WindowComponentPattern(getComponentDefinition("parent", viewDefinition));
setField(parent, "dataDefinition", dataDefinition);
setField(parent, "initialized", true);
AbstractComponentPattern pattern = new TextInputComponentPattern(getComponentDefinition("test", null, "field", parent, viewDefinition));
// when
pattern.initialize();
// then
Assert.assertEquals(belongsToDefinition, getField(pattern, "dataDefinition"));
Assert.assertEquals(fieldDefinition, getField(pattern, "scopeFieldDefinition"));
}
Aggregations