Search in sources :

Example 1 with InternalComponentState

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

the class AbstractStateTest method createMockComponent.

protected InternalComponentState createMockComponent(final String name) {
    InternalComponentState component1 = mock(InternalComponentState.class, withSettings().extraInterfaces(ScopeEntityIdChangeListener.class, FieldEntityIdChangeListener.class));
    given(component1.getName()).willReturn(name);
    return component1;
}
Also used : ScopeEntityIdChangeListener(com.qcadoo.view.internal.ScopeEntityIdChangeListener) FieldEntityIdChangeListener(com.qcadoo.view.internal.FieldEntityIdChangeListener) InternalComponentState(com.qcadoo.view.internal.api.InternalComponentState)

Example 2 with InternalComponentState

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

the class ComponentStateTest method shouldNotRenderComponentIfNotRequested.

@Test
public void shouldNotRenderComponentIfNotRequested() throws Exception {
    // given
    InternalComponentState componentState = new SimpleComponentState();
    // when
    JSONObject json = componentState.render();
    // then
    assertFalse(json.has(AbstractComponentState.JSON_CONTENT));
}
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 3 with InternalComponentState

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

the class ComponentStateTest method shouldRenderJsonWithNullFieldValue.

@Test
public void shouldRenderJsonWithNullFieldValue() throws Exception {
    // given
    InternalComponentState componentState = new SimpleComponentState();
    componentState.setFieldValue(null);
    componentState.initialize(new JSONObject(), Locale.ENGLISH);
    // when
    JSONObject json = componentState.render();
    // then
    assertFalse(json.getJSONObject(AbstractComponentState.JSON_CONTENT).has(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 4 with InternalComponentState

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

the class ComponentStateTest method shouldModifyEnableFlag.

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

Example 5 with InternalComponentState

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

the class ComponentStateTest method shouldHaveVisibleFlag.

@Test
public void shouldHaveVisibleFlag() 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_VISIBLE, true);
    // when
    componentState.initialize(json, Locale.ENGLISH);
    // then
    assertTrue(componentState.isVisible());
    assertTrue(componentState.render().getBoolean(AbstractComponentState.JSON_VISIBLE));
}
Also used : JSONObject(org.json.JSONObject) SimpleComponentState(com.qcadoo.view.internal.components.SimpleComponentState) InternalComponentState(com.qcadoo.view.internal.api.InternalComponentState) 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