Search in sources :

Example 21 with InternalComponentState

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

the class FormComponentStateTest method shouldInitialeFormWithNullEntityId.

@Test
public void shouldInitialeFormWithNullEntityId() throws Exception {
    // given
    FormComponentPattern pattern = mock(FormComponentPattern.class);
    given(pattern.getExpressionNew()).willReturn(null);
    given(pattern.getExpressionEdit()).willReturn(null);
    setField(pattern, "applicationContext", applicationContext);
    InternalComponentState componentState = new FormComponentState(pattern);
    JSONObject json = new JSONObject();
    JSONObject jsonContent = new JSONObject();
    jsonContent.put(FormComponentState.JSON_ENTITY_ID, (String) null);
    json.put(AbstractComponentState.JSON_CONTENT, jsonContent);
    JSONObject jsonChildren = new JSONObject();
    json.put(AbstractComponentState.JSON_CHILDREN, jsonChildren);
    // when
    componentState.initialize(json, Locale.ENGLISH);
    // then
    assertNull(componentState.getFieldValue());
}
Also used : FormComponentPattern(com.qcadoo.view.internal.components.form.FormComponentPattern) JSONObject(org.json.JSONObject) InternalComponentState(com.qcadoo.view.internal.api.InternalComponentState) FormComponentState(com.qcadoo.view.internal.components.form.FormComponentState) AbstractStateTest(com.qcadoo.view.internal.states.AbstractStateTest) Test(org.junit.Test)

Example 22 with InternalComponentState

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

the class ComponentStateTest method shouldRenderJsonWithFieldValue.

@Test
public void shouldRenderJsonWithFieldValue() throws Exception {
    // given
    InternalComponentState componentState = new SimpleComponentState();
    componentState.setFieldValue("text");
    componentState.initialize(new JSONObject(), Locale.ENGLISH);
    // when
    JSONObject json = componentState.render();
    // then
    assertEquals("text", json.getJSONObject(AbstractComponentState.JSON_CONTENT).getString(AbstractComponentState.JSON_VALUE));
}
Also used : JSONObject(org.json.JSONObject) SimpleComponentState(com.qcadoo.view.internal.components.SimpleComponentState) InternalComponentState(com.qcadoo.view.internal.api.InternalComponentState) Test(org.junit.Test)

Example 23 with InternalComponentState

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

the class ComponentStateTest method shouldModifyVisibleFlag.

@Test
public void shouldModifyVisibleFlag() throws Exception {
    // given
    InternalComponentState componentState = new SimpleComponentState();
    // when
    componentState.setVisible(false);
    // then
    assertFalse(componentState.isVisible());
    assertFalse(componentState.render().getBoolean(AbstractComponentState.JSON_VISIBLE));
}
Also used : SimpleComponentState(com.qcadoo.view.internal.components.SimpleComponentState) InternalComponentState(com.qcadoo.view.internal.api.InternalComponentState) Test(org.junit.Test)

Example 24 with InternalComponentState

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

the class ComponentStateTest method shouldHaveEnableFlag.

@Test
public void shouldHaveEnableFlag() throws Exception {
    // given
    InternalComponentState componentState = new SimpleComponentState();
    JSONObject json = new JSONObject();
    JSONObject jsonContent = new JSONObject();
    jsonContent.put(AbstractComponentState.JSON_VALUE, "text");
    json.put(AbstractComponentState.JSON_CONTENT, jsonContent);
    json.put(AbstractComponentState.JSON_ENABLED, true);
    // when
    componentState.initialize(json, Locale.ENGLISH);
    // then
    assertTrue(componentState.isEnabled());
    assertTrue(componentState.render().getBoolean(AbstractComponentState.JSON_ENABLED));
}
Also used : JSONObject(org.json.JSONObject) SimpleComponentState(com.qcadoo.view.internal.components.SimpleComponentState) InternalComponentState(com.qcadoo.view.internal.api.InternalComponentState) Test(org.junit.Test)

Example 25 with InternalComponentState

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

the class ContainerStateTest method shouldInitializeChildren.

@Test
public void shouldInitializeChildren() 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);
    JSONObject json = new JSONObject();
    JSONObject children = new JSONObject();
    JSONObject component1Json = new JSONObject();
    component1Json.put(AbstractComponentState.JSON_CONTENT, new JSONObject());
    JSONObject component2Json = new JSONObject();
    component2Json.put(AbstractComponentState.JSON_CONTENT, new JSONObject());
    children.put("component1", component1Json);
    children.put("component2", component2Json);
    json.put(AbstractComponentState.JSON_CHILDREN, children);
    json.put(AbstractComponentState.JSON_CONTENT, new JSONObject(Collections.singletonMap("entityId", 13L)));
    // when
    container.initialize(json, Locale.ENGLISH);
    // then
    verify(component1).initialize(component1Json, Locale.ENGLISH);
    verify(component2).initialize(component2Json, Locale.ENGLISH);
}
Also used : FormComponentPattern(com.qcadoo.view.internal.components.form.FormComponentPattern) JSONObject(org.json.JSONObject) InternalComponentState(com.qcadoo.view.internal.api.InternalComponentState) FormComponentState(com.qcadoo.view.internal.components.form.FormComponentState) Test(org.junit.Test)

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