Search in sources :

Example 1 with FieldEntityIdChangeListener

use of com.qcadoo.view.internal.FieldEntityIdChangeListener in project qcadoo by qcadoo.

the class FieldEntityIdChangeListenerTest method shouldHaveFieldListeners.

@Test
public void shouldHaveFieldListeners() throws Exception {
    // given
    ComponentState component1 = createMockComponent("component1");
    ComponentState component2 = createMockComponent("component2");
    FormComponentPattern pattern = mock(FormComponentPattern.class);
    given(pattern.getExpressionNew()).willReturn(null);
    given(pattern.getExpressionEdit()).willReturn(null);
    ApplicationContext applicationContext = mock(ApplicationContext.class);
    setField(pattern, "applicationContext", applicationContext);
    FormComponentState container = new FormComponentState(pattern);
    container.addFieldEntityIdChangeListener("field1", (FieldEntityIdChangeListener) component1);
    container.addFieldEntityIdChangeListener("field2", (FieldEntityIdChangeListener) component2);
    // when
    container.setFieldValue(13L);
    // then
    verify((FieldEntityIdChangeListener) component1).onFieldEntityIdChange(13L);
    verify((FieldEntityIdChangeListener) component2).onFieldEntityIdChange(13L);
}
Also used : ApplicationContext(org.springframework.context.ApplicationContext) FormComponentPattern(com.qcadoo.view.internal.components.form.FormComponentPattern) FieldEntityIdChangeListener(com.qcadoo.view.internal.FieldEntityIdChangeListener) ComponentState(com.qcadoo.view.api.ComponentState) FormComponentState(com.qcadoo.view.internal.components.form.FormComponentState) FormComponentState(com.qcadoo.view.internal.components.form.FormComponentState) Test(org.junit.Test)

Example 2 with FieldEntityIdChangeListener

use of com.qcadoo.view.internal.FieldEntityIdChangeListener in project qcadoo by qcadoo.

the class GridComponentStateTest method shouldNotModeUpSelectedEntityOnFail.

@Test(expected = IllegalStateException.class)
public void shouldNotModeUpSelectedEntityOnFail() throws Exception {
    // given
    FieldEntityIdChangeListener listener = mock(FieldEntityIdChangeListener.class);
    SearchResult result = mock(SearchResult.class);
    given(substituteCriteria.list()).willReturn(result);
    given(result.getTotalNumberOfEntities()).willReturn(0);
    given(result.getEntities()).willReturn(Collections.<Entity>emptyList());
    willThrow(new IllegalStateException()).given(substituteDataDefinition).move(13L, -1);
    grid.initialize(json, Locale.ENGLISH);
    grid.addFieldEntityIdChangeListener("field", listener);
    // when
    grid.performEvent(viewDefinitionState, "moveUp");
}
Also used : SearchResult(com.qcadoo.model.api.search.SearchResult) FieldEntityIdChangeListener(com.qcadoo.view.internal.FieldEntityIdChangeListener) AbstractStateTest(com.qcadoo.view.internal.states.AbstractStateTest) Test(org.junit.Test)

Example 3 with FieldEntityIdChangeListener

use of com.qcadoo.view.internal.FieldEntityIdChangeListener in project qcadoo by qcadoo.

the class GridComponentStateTest method shouldNotModeDownSelectedEntityOnFail.

@Test(expected = IllegalStateException.class)
public void shouldNotModeDownSelectedEntityOnFail() throws Exception {
    // given
    FieldEntityIdChangeListener listener = mock(FieldEntityIdChangeListener.class);
    SearchResult result = mock(SearchResult.class);
    given(substituteCriteria.list()).willReturn(result);
    given(result.getTotalNumberOfEntities()).willReturn(0);
    given(result.getEntities()).willReturn(Collections.<Entity>emptyList());
    willThrow(new IllegalStateException()).given(substituteDataDefinition).move(13L, 1);
    grid.initialize(json, Locale.ENGLISH);
    grid.addFieldEntityIdChangeListener("field", listener);
    // when
    grid.performEvent(viewDefinitionState, "moveDown");
}
Also used : SearchResult(com.qcadoo.model.api.search.SearchResult) FieldEntityIdChangeListener(com.qcadoo.view.internal.FieldEntityIdChangeListener) AbstractStateTest(com.qcadoo.view.internal.states.AbstractStateTest) Test(org.junit.Test)

Example 4 with FieldEntityIdChangeListener

use of com.qcadoo.view.internal.FieldEntityIdChangeListener in project qcadoo by qcadoo.

the class GridComponentStateTest method shouldRefresh.

@Test
public void shouldRefresh() throws Exception {
    // given
    FieldEntityIdChangeListener listener = mock(FieldEntityIdChangeListener.class);
    SearchResult result = mock(SearchResult.class);
    given(substituteCriteria.list()).willReturn(result);
    given(result.getTotalNumberOfEntities()).willReturn(0);
    given(result.getEntities()).willReturn(Collections.<Entity>emptyList());
    grid.initialize(json, Locale.ENGLISH);
    grid.addFieldEntityIdChangeListener("field", listener);
    // when
    grid.performEvent(viewDefinitionState, "refresh");
}
Also used : SearchResult(com.qcadoo.model.api.search.SearchResult) FieldEntityIdChangeListener(com.qcadoo.view.internal.FieldEntityIdChangeListener) AbstractStateTest(com.qcadoo.view.internal.states.AbstractStateTest) Test(org.junit.Test)

Example 5 with FieldEntityIdChangeListener

use of com.qcadoo.view.internal.FieldEntityIdChangeListener in project qcadoo by qcadoo.

the class GridComponentStateTest method shouldSelectEntity.

@Test
public void shouldSelectEntity() throws Exception {
    // given
    FieldEntityIdChangeListener listener = mock(FieldEntityIdChangeListener.class);
    SearchResult result = mock(SearchResult.class);
    given(substituteCriteria.list()).willReturn(result);
    given(result.getTotalNumberOfEntities()).willReturn(0);
    given(result.getEntities()).willReturn(Collections.<Entity>emptyList());
    grid.initialize(json, Locale.ENGLISH);
    grid.addFieldEntityIdChangeListener("field", listener);
    // when
    grid.performEvent(viewDefinitionState, "select");
    // then
    verify(listener).onFieldEntityIdChange(13L);
}
Also used : SearchResult(com.qcadoo.model.api.search.SearchResult) FieldEntityIdChangeListener(com.qcadoo.view.internal.FieldEntityIdChangeListener) AbstractStateTest(com.qcadoo.view.internal.states.AbstractStateTest) Test(org.junit.Test)

Aggregations

FieldEntityIdChangeListener (com.qcadoo.view.internal.FieldEntityIdChangeListener)5 Test (org.junit.Test)5 SearchResult (com.qcadoo.model.api.search.SearchResult)4 AbstractStateTest (com.qcadoo.view.internal.states.AbstractStateTest)4 ComponentState (com.qcadoo.view.api.ComponentState)1 FormComponentPattern (com.qcadoo.view.internal.components.form.FormComponentPattern)1 FormComponentState (com.qcadoo.view.internal.components.form.FormComponentState)1 ApplicationContext (org.springframework.context.ApplicationContext)1