Search in sources :

Example 26 with ComponentPattern

use of com.qcadoo.view.internal.api.ComponentPattern in project qcadoo by qcadoo.

the class ContainerPatternTest method shouldReturnNullWhenChildNotExist.

@Test
public void shouldReturnNullWhenChildNotExist() throws Exception {
    // given
    AbstractContainerPattern parent = new FormComponentPattern(getComponentDefinition("test", null));
    // when
    ComponentPattern child = parent.getChild("test3");
    // then
    Assert.assertNull(child);
}
Also used : FormComponentPattern(com.qcadoo.view.internal.components.form.FormComponentPattern) FormComponentPattern(com.qcadoo.view.internal.components.form.FormComponentPattern) ComponentPattern(com.qcadoo.view.internal.api.ComponentPattern) TextInputComponentPattern(com.qcadoo.view.internal.components.TextInputComponentPattern) Test(org.junit.Test)

Example 27 with ComponentPattern

use of com.qcadoo.view.internal.api.ComponentPattern in project qcadoo by qcadoo.

the class FieldAndScopeListenerPatternTest method shouldHaveFieldListeners.

@Test
public void shouldHaveFieldListeners() throws Exception {
    // given
    InternalViewDefinition viewDefinition = mock(InternalViewDefinition.class);
    AbstractContainerPattern parent = new ContainerPatternMock(getComponentDefinition("f1", viewDefinition));
    ComponentPatternMock child1 = new ComponentPatternMock(getComponentDefinition("t1", "t1", null, parent, viewDefinition));
    ComponentPatternMock child2 = new ComponentPatternMock(getComponentDefinition("t2", "t2", null, parent, viewDefinition));
    parent.addChild(child1);
    parent.addChild(child2);
    parent.initialize();
    child1.initialize();
    child2.initialize();
    // when
    Map<String, ComponentPattern> listeners = parent.getFieldEntityIdChangeListeners();
    // then
    Assert.assertEquals(2, listeners.size());
    Assert.assertEquals(child1, listeners.get("t1"));
    Assert.assertEquals(child2, listeners.get("t2"));
}
Also used : InternalViewDefinition(com.qcadoo.view.internal.api.InternalViewDefinition) ComponentPattern(com.qcadoo.view.internal.api.ComponentPattern) TextInputComponentPattern(com.qcadoo.view.internal.components.TextInputComponentPattern) Test(org.junit.Test)

Example 28 with ComponentPattern

use of com.qcadoo.view.internal.api.ComponentPattern in project qcadoo by qcadoo.

the class FieldAndScopeListenerPatternTest method shouldHaveScopeListeners.

@Test
public void shouldHaveScopeListeners() throws Exception {
    // given
    InternalViewDefinition viewDefinition = mock(InternalViewDefinition.class);
    AbstractContainerPattern parent = new ContainerPatternMock(getComponentDefinition("f1", viewDefinition));
    ComponentPatternMock child1 = new ComponentPatternMock(getComponentDefinition("t1", null, "t1", parent, viewDefinition));
    ComponentPatternMock child2 = new ComponentPatternMock(getComponentDefinition("t2", null, "t2", parent, viewDefinition));
    parent.addChild(child1);
    parent.addChild(child2);
    parent.initialize();
    child1.initialize();
    child2.initialize();
    // when
    Map<String, ComponentPattern> listeners = parent.getScopeEntityIdChangeListeners();
    // then
    Assert.assertEquals(2, listeners.size());
    Assert.assertEquals(child1, listeners.get("t1"));
    Assert.assertEquals(child2, listeners.get("t2"));
}
Also used : InternalViewDefinition(com.qcadoo.view.internal.api.InternalViewDefinition) ComponentPattern(com.qcadoo.view.internal.api.ComponentPattern) TextInputComponentPattern(com.qcadoo.view.internal.components.TextInputComponentPattern) Test(org.junit.Test)

Example 29 with ComponentPattern

use of com.qcadoo.view.internal.api.ComponentPattern in project qcadoo by qcadoo.

the class ViewDefinitionTest method shouldCallInitializeOnChildren.

@Test
public void shouldCallInitializeOnChildren() throws Exception {
    // given
    InternalViewDefinition viewDefinition = new ViewDefinitionImpl("name", "plugin", mock(DataDefinition.class), true, null);
    ComponentPattern pattern1 = Mockito.mock(ComponentPattern.class);
    given(pattern1.getName()).willReturn("test1");
    given(pattern1.initialize()).willReturn(false, true);
    ComponentPattern pattern2 = Mockito.mock(ComponentPattern.class);
    given(pattern2.getName()).willReturn("test2");
    given(pattern2.initialize()).willReturn(true);
    viewDefinition.addComponentPattern(pattern1);
    viewDefinition.addComponentPattern(pattern2);
    // when
    viewDefinition.initialize();
    // then
    Mockito.verify(pattern1, times(2)).initialize();
    Mockito.verify(pattern2, times(2)).initialize();
}
Also used : ViewDefinitionImpl(com.qcadoo.view.internal.internal.ViewDefinitionImpl) InternalViewDefinition(com.qcadoo.view.internal.api.InternalViewDefinition) FormComponentPattern(com.qcadoo.view.internal.components.form.FormComponentPattern) WindowComponentPattern(com.qcadoo.view.internal.components.window.WindowComponentPattern) ComponentPattern(com.qcadoo.view.internal.api.ComponentPattern) DataDefinition(com.qcadoo.model.api.DataDefinition) Test(org.junit.Test) AbstractPatternTest(com.qcadoo.view.internal.patterns.AbstractPatternTest)

Example 30 with ComponentPattern

use of com.qcadoo.view.internal.api.ComponentPattern in project qcadoo by qcadoo.

the class ViewDefinitionTest method shouldReturnJsFilePaths.

@Test
public void shouldReturnJsFilePaths() throws Exception {
    // given
    ViewDefinitionImpl viewDefinition = new ViewDefinitionImpl("name", "plugin", mock(DataDefinition.class), true, null);
    AbstractContainerPattern parent = new WindowComponentPattern(getComponentDefinition("test", viewDefinition));
    ComponentPattern form = new FormComponentPattern(getComponentDefinition("test", parent, viewDefinition));
    parent.addChild(form);
    viewDefinition.addComponentPattern(parent);
    viewDefinition.initialize();
    // when
    Set<String> paths = viewDefinition.getJsFilePaths();
    // then
    Assert.assertEquals(1, paths.size());
}
Also used : ViewDefinitionImpl(com.qcadoo.view.internal.internal.ViewDefinitionImpl) WindowComponentPattern(com.qcadoo.view.internal.components.window.WindowComponentPattern) FormComponentPattern(com.qcadoo.view.internal.components.form.FormComponentPattern) AbstractContainerPattern(com.qcadoo.view.internal.patterns.AbstractContainerPattern) FormComponentPattern(com.qcadoo.view.internal.components.form.FormComponentPattern) WindowComponentPattern(com.qcadoo.view.internal.components.window.WindowComponentPattern) ComponentPattern(com.qcadoo.view.internal.api.ComponentPattern) DataDefinition(com.qcadoo.model.api.DataDefinition) Test(org.junit.Test) AbstractPatternTest(com.qcadoo.view.internal.patterns.AbstractPatternTest)

Aggregations

ComponentPattern (com.qcadoo.view.internal.api.ComponentPattern)30 Test (org.junit.Test)15 WindowComponentPattern (com.qcadoo.view.internal.components.window.WindowComponentPattern)14 InternalViewDefinition (com.qcadoo.view.internal.api.InternalViewDefinition)13 FormComponentPattern (com.qcadoo.view.internal.components.form.FormComponentPattern)13 TextInputComponentPattern (com.qcadoo.view.internal.components.TextInputComponentPattern)10 AbstractComponentPattern (com.qcadoo.view.internal.patterns.AbstractComponentPattern)6 DataDefinition (com.qcadoo.model.api.DataDefinition)5 ViewDefinitionImpl (com.qcadoo.view.internal.internal.ViewDefinitionImpl)5 AbstractPatternTest (com.qcadoo.view.internal.patterns.AbstractPatternTest)5 JSONObject (org.json.JSONObject)5 Node (org.w3c.dom.Node)5 JSONException (org.json.JSONException)3 NodeList (org.w3c.dom.NodeList)3 ModuleException (com.qcadoo.plugin.api.ModuleException)2 ComponentState (com.qcadoo.view.api.ComponentState)2 ComponentDefinition (com.qcadoo.view.internal.ComponentDefinition)2 ContainerPattern (com.qcadoo.view.internal.api.ContainerPattern)2 InternalComponentState (com.qcadoo.view.internal.api.InternalComponentState)2 AbstractContainerPattern (com.qcadoo.view.internal.patterns.AbstractContainerPattern)2