Search in sources :

Example 26 with InternalComponentState

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

the class ContainerStateTest method shouldHaveChildren.

@Test
public void shouldHaveChildren() throws Exception {
    // given
    InternalComponentState component1 = createMockComponent("component1");
    InternalComponentState component2 = createMockComponent("component2");
    FormComponentPattern pattern = mock(FormComponentPattern.class);
    given(pattern.getExpressionNew()).willReturn(null);
    given(pattern.getExpressionEdit()).willReturn(null);
    setField(pattern, "applicationContext", applicationContext);
    FormComponentState container = new FormComponentState(pattern);
    container.addChild(component1);
    container.addChild(component2);
    // when
    Map<String, InternalComponentState> children = container.getChildren();
    // then
    assertNotNull(children);
    assertEquals(2, children.size());
}
Also used : FormComponentPattern(com.qcadoo.view.internal.components.form.FormComponentPattern) InternalComponentState(com.qcadoo.view.internal.api.InternalComponentState) FormComponentState(com.qcadoo.view.internal.components.form.FormComponentState) Test(org.junit.Test)

Example 27 with InternalComponentState

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

the class ContainerStateTest method shouldReturnChildByName.

@Test
public void shouldReturnChildByName() throws Exception {
    // given
    InternalComponentState component = createMockComponent("component");
    FormComponentPattern pattern = mock(FormComponentPattern.class);
    given(pattern.getExpressionNew()).willReturn(null);
    given(pattern.getExpressionEdit()).willReturn(null);
    setField(pattern, "applicationContext", applicationContext);
    FormComponentState container = new FormComponentState(pattern);
    container.addChild(component);
    // when
    ComponentState child = container.getChild("component");
    // then
    assertSame(component, child);
}
Also used : FormComponentPattern(com.qcadoo.view.internal.components.form.FormComponentPattern) InternalComponentState(com.qcadoo.view.internal.api.InternalComponentState) FormComponentState(com.qcadoo.view.internal.components.form.FormComponentState) ComponentState(com.qcadoo.view.api.ComponentState) FormComponentState(com.qcadoo.view.internal.components.form.FormComponentState) InternalComponentState(com.qcadoo.view.internal.api.InternalComponentState) Test(org.junit.Test)

Example 28 with InternalComponentState

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

the class ContainerPatternTest method shouldCallCreateComponentStateOnChildren.

@Test
public void shouldCallCreateComponentStateOnChildren() throws Exception {
    // given
    InternalViewDefinition viewDefinition = mock(InternalViewDefinition.class);
    InternalViewDefinitionState viewDefinitionState = mock(InternalViewDefinitionState.class);
    AbstractContainerState state = new EmptyContainerState();
    InternalComponentState state1 = mock(InternalComponentState.class);
    given(state1.getName()).willReturn("name1");
    InternalComponentState state2 = mock(InternalComponentState.class);
    given(state2.getName()).willReturn("name2");
    ComponentPattern pattern1 = mock(ComponentPattern.class);
    given(pattern1.getName()).willReturn("name1");
    given(pattern1.createComponentState(viewDefinitionState)).willReturn(state1);
    ComponentPattern pattern2 = mock(ComponentPattern.class);
    given(pattern2.getName()).willReturn("name2");
    given(pattern2.createComponentState(viewDefinitionState)).willReturn(state2);
    ContainerPatternMock parent = new ContainerPatternMock(getComponentDefinition("name", viewDefinition), state);
    parent.addChild(pattern1);
    parent.addChild(pattern2);
    // when
    ComponentState actualState = parent.createComponentState(viewDefinitionState);
    // then
    assertEquals(state, actualState);
    verify(pattern1).createComponentState(viewDefinitionState);
    verify(pattern2).createComponentState(viewDefinitionState);
    verify(viewDefinitionState).registerComponent("name", actualState);
    assertEquals(state1, state.getChild("name1"));
    assertEquals(state2, state.getChild("name2"));
}
Also used : AbstractContainerState(com.qcadoo.view.internal.states.AbstractContainerState) InternalViewDefinitionState(com.qcadoo.view.internal.api.InternalViewDefinitionState) InternalViewDefinition(com.qcadoo.view.internal.api.InternalViewDefinition) EmptyContainerState(com.qcadoo.view.internal.components.EmptyContainerState) FormComponentPattern(com.qcadoo.view.internal.components.form.FormComponentPattern) ComponentPattern(com.qcadoo.view.internal.api.ComponentPattern) TextInputComponentPattern(com.qcadoo.view.internal.components.TextInputComponentPattern) InternalComponentState(com.qcadoo.view.internal.api.InternalComponentState) ComponentState(com.qcadoo.view.api.ComponentState) InternalComponentState(com.qcadoo.view.internal.api.InternalComponentState) Test(org.junit.Test)

Example 29 with InternalComponentState

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

the class ViewDefinitionStateTest method shouldPerformEventOnState.

@Test
public void shouldPerformEventOnState() throws Exception {
    // given
    ViewDefinitionStateImpl viewDefinitionState = new ViewDefinitionStateImpl();
    ContainerState state1 = mock(ContainerState.class);
    given(state1.getName()).willReturn("name1");
    InternalComponentState state2 = mock(InternalComponentState.class);
    viewDefinitionState.addChild(state1);
    given(state1.getChild("name2")).willReturn(state2);
    // when
    viewDefinitionState.performEvent("name1.name2", "event", new String[] { "arg1", "arg2" });
    // then
    Mockito.verify(state2).performEvent(viewDefinitionState, "event", "arg1", "arg2");
}
Also used : ViewDefinitionStateImpl(com.qcadoo.view.internal.internal.ViewDefinitionStateImpl) ContainerState(com.qcadoo.view.internal.api.ContainerState) InternalComponentState(com.qcadoo.view.internal.api.InternalComponentState) Test(org.junit.Test) AbstractStateTest(com.qcadoo.view.internal.states.AbstractStateTest)

Aggregations

InternalComponentState (com.qcadoo.view.internal.api.InternalComponentState)29 Test (org.junit.Test)20 JSONObject (org.json.JSONObject)17 SimpleComponentState (com.qcadoo.view.internal.components.SimpleComponentState)8 FormComponentPattern (com.qcadoo.view.internal.components.form.FormComponentPattern)8 FormComponentState (com.qcadoo.view.internal.components.form.FormComponentState)7 ContainerState (com.qcadoo.view.internal.api.ContainerState)4 AbstractStateTest (com.qcadoo.view.internal.states.AbstractStateTest)4 Map (java.util.Map)4 ComponentState (com.qcadoo.view.api.ComponentState)3 InternalViewDefinition (com.qcadoo.view.internal.api.InternalViewDefinition)3 JSONArray (org.json.JSONArray)3 ComponentPattern (com.qcadoo.view.internal.api.ComponentPattern)2 InternalViewDefinitionState (com.qcadoo.view.internal.api.InternalViewDefinitionState)2 ViewDefinitionStateImpl (com.qcadoo.view.internal.internal.ViewDefinitionStateImpl)2 AbstractContainerState (com.qcadoo.view.internal.states.AbstractContainerState)2 HashMap (java.util.HashMap)2 LinkedList (java.util.LinkedList)2 DataDefinition (com.qcadoo.model.api.DataDefinition)1 CrudService (com.qcadoo.view.api.crud.CrudService)1