Search in sources :

Example 1 with WindowComponentPattern

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"));
}
Also used : WindowComponentPattern(com.qcadoo.view.internal.components.window.WindowComponentPattern) JSONObject(org.json.JSONObject) InternalViewDefinition(com.qcadoo.view.internal.api.InternalViewDefinition) JSONArray(org.json.JSONArray) JSONObject(org.json.JSONObject) Test(org.junit.Test)

Example 2 with WindowComponentPattern

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);
}
Also used : ContainerPattern(com.qcadoo.view.internal.api.ContainerPattern) WindowComponentPattern(com.qcadoo.view.internal.components.window.WindowComponentPattern) FormComponentPattern(com.qcadoo.view.internal.components.form.FormComponentPattern) TextInputComponentPattern(com.qcadoo.view.internal.components.TextInputComponentPattern) WindowComponentPattern(com.qcadoo.view.internal.components.window.WindowComponentPattern) ComponentPattern(com.qcadoo.view.internal.api.ComponentPattern) TextInputComponentPattern(com.qcadoo.view.internal.components.TextInputComponentPattern) Test(org.junit.Test)

Example 3 with WindowComponentPattern

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"));
}
Also used : WindowComponentPattern(com.qcadoo.view.internal.components.window.WindowComponentPattern) InternalViewDefinition(com.qcadoo.view.internal.api.InternalViewDefinition) DataDefinition(com.qcadoo.model.api.DataDefinition) TextInputComponentPattern(com.qcadoo.view.internal.components.TextInputComponentPattern) Test(org.junit.Test)

Example 4 with WindowComponentPattern

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"));
}
Also used : BelongsToType(com.qcadoo.model.api.types.BelongsToType) WindowComponentPattern(com.qcadoo.view.internal.components.window.WindowComponentPattern) InternalViewDefinition(com.qcadoo.view.internal.api.InternalViewDefinition) FieldDefinition(com.qcadoo.model.api.FieldDefinition) DataDefinition(com.qcadoo.model.api.DataDefinition) TextInputComponentPattern(com.qcadoo.view.internal.components.TextInputComponentPattern) Test(org.junit.Test)

Example 5 with WindowComponentPattern

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"));
}
Also used : HasManyType(com.qcadoo.model.api.types.HasManyType) WindowComponentPattern(com.qcadoo.view.internal.components.window.WindowComponentPattern) InternalViewDefinition(com.qcadoo.view.internal.api.InternalViewDefinition) FieldDefinition(com.qcadoo.model.api.FieldDefinition) DataDefinition(com.qcadoo.model.api.DataDefinition) TextInputComponentPattern(com.qcadoo.view.internal.components.TextInputComponentPattern) Test(org.junit.Test)

Aggregations

WindowComponentPattern (com.qcadoo.view.internal.components.window.WindowComponentPattern)16 Test (org.junit.Test)12 InternalViewDefinition (com.qcadoo.view.internal.api.InternalViewDefinition)11 DataDefinition (com.qcadoo.model.api.DataDefinition)9 TextInputComponentPattern (com.qcadoo.view.internal.components.TextInputComponentPattern)9 FieldDefinition (com.qcadoo.model.api.FieldDefinition)6 ComponentPattern (com.qcadoo.view.internal.api.ComponentPattern)4 FormComponentPattern (com.qcadoo.view.internal.components.form.FormComponentPattern)3 BelongsToType (com.qcadoo.model.api.types.BelongsToType)2 HasManyType (com.qcadoo.model.api.types.HasManyType)2 ModuleException (com.qcadoo.plugin.api.ModuleException)2 ViewDefinitionImpl (com.qcadoo.view.internal.internal.ViewDefinitionImpl)2 ViewDefinitionParserException (com.qcadoo.view.internal.xml.ViewDefinitionParserException)2 ViewDefinitionParserNodeException (com.qcadoo.view.internal.xml.ViewDefinitionParserNodeException)2 IOException (java.io.IOException)2 JSONObject (org.json.JSONObject)2 Node (org.w3c.dom.Node)2 ImmutableMap (com.google.common.collect.ImmutableMap)1 ComponentDefinition (com.qcadoo.view.internal.ComponentDefinition)1 ContainerPattern (com.qcadoo.view.internal.api.ContainerPattern)1