Search in sources :

Example 1 with FieldChangeHandler

use of org.kie.workbench.common.forms.processing.engine.handling.FieldChangeHandler in project kie-wb-common by kiegroup.

the class SubFormWidgetTest method testAddFieldChangeHandler.

@Test
public void testAddFieldChangeHandler() {
    FieldChangeHandler handler = mock(FieldChangeHandler.class);
    subFormWidget.addFieldChangeHandler(handler);
    verify(formRenderer).addFieldChangeHandler(same(handler));
}
Also used : FieldChangeHandler(org.kie.workbench.common.forms.processing.engine.handling.FieldChangeHandler) Test(org.junit.Test)

Example 2 with FieldChangeHandler

use of org.kie.workbench.common.forms.processing.engine.handling.FieldChangeHandler in project kie-wb-common by kiegroup.

the class FormPropertiesWidgetTest method testShowDomainObject.

@Test
@SuppressWarnings("unchecked")
public void testShowDomainObject() {
    tested.init();
    final String fieldName = "fieldName";
    final String fieldValue = "fieldValue";
    final Command callback = mock(Command.class);
    when(formsCanvasSessionHandler.getDiagram()).thenReturn(diagram);
    when(domainObject.getDomainObjectUUID()).thenReturn(DOMAIN_OBJECT_UUID);
    when(domainObject.getDomainObjectNameTranslationKey()).thenReturn(DOMAIN_OBJECT_TRANSLATION_KEY);
    when(formsCanvasSessionHandler.getSession()).thenReturn(session);
    verify(formsCanvasSessionHandler).setRenderer(formRendererArgumentCaptor.capture());
    final FormsCanvasSessionHandler.FormRenderer formRenderer = formRendererArgumentCaptor.getValue();
    formRenderer.render(GRAPH_UUID, domainObject, callback);
    verify(formsContainer).render(eq(GRAPH_UUID), eq(DOMAIN_OBJECT_UUID), eq(domainObject), Mockito.<Path>any(), fieldChangeHandlerArgumentCaptor.capture(), eq(RenderMode.EDIT_MODE));
    final FieldChangeHandler fieldChangeHandler = fieldChangeHandlerArgumentCaptor.getValue();
    fieldChangeHandler.onFieldChange(fieldName, fieldValue);
    verify(formsCanvasSessionHandler).executeUpdateDomainObjectProperty(eq(domainObject), eq(fieldName), eq(fieldValue));
    verify(propertiesOpenedEvent).fire(formPropertiesOpenedArgumentCaptor.capture());
    final FormPropertiesOpened formPropertiesOpened = formPropertiesOpenedArgumentCaptor.getValue();
    assertThat(formPropertiesOpened.getUuid()).isEqualTo(DOMAIN_OBJECT_UUID);
    assertThat(formPropertiesOpened.getName()).isEqualTo(DOMAIN_OBJECT_TRANSLATION_KEY);
    assertThat(formPropertiesOpened.getSession()).isEqualTo(session);
    verify(callback).execute();
}
Also used : Command(org.uberfire.mvp.Command) FormPropertiesOpened(org.kie.workbench.common.stunner.forms.client.event.FormPropertiesOpened) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) FieldChangeHandler(org.kie.workbench.common.forms.processing.engine.handling.FieldChangeHandler) Test(org.junit.Test)

Example 3 with FieldChangeHandler

use of org.kie.workbench.common.forms.processing.engine.handling.FieldChangeHandler in project kie-wb-common by kiegroup.

the class FormsContainerTest method testRender.

private FormDisplayer testRender(NodeImpl<Definition<?>> node, int expectedDisplayers, int currentDisplayerRender, RenderMode renderMode) {
    // clear mocks
    reset(renderer);
    reset(formFieldChangedEvent);
    formsContainer.render(GRAPH_UUID, node.getUUID(), node.getContent().getDefinition(), path, fieldChangeHandler, renderMode);
    verify(displayersInstance, times(expectedDisplayers)).get();
    assertThat(activeDisplayers).isNotEmpty().hasSize(expectedDisplayers);
    FormDisplayer displayer = activeDisplayers.get(expectedDisplayers - 1);
    verify(displayer, times(currentDisplayerRender)).render(node.getUUID(), node.getContent().getDefinition(), path, fieldChangeHandler, renderMode);
    verify(displayer, times(currentDisplayerRender)).hide();
    verify(view, times(currentDisplayerRender)).addDisplayer(displayer);
    verify(displayer).show();
    // test fire FormFieldChanged event
    final ArgumentCaptor<FieldChangeHandler> fieldChangeHandlerArgumentCaptor = ArgumentCaptor.forClass(FieldChangeHandler.class);
    verify(renderer).addFieldChangeHandler(fieldChangeHandlerArgumentCaptor.capture());
    fieldChangeHandlerArgumentCaptor.getValue().onFieldChange("field", "value");
    final ArgumentCaptor<FormFieldChanged> formFieldChangedArgumentCaptor = ArgumentCaptor.forClass(FormFieldChanged.class);
    verify(formFieldChangedEvent).fire(formFieldChangedArgumentCaptor.capture());
    final FormFieldChanged formFieldChanged = formFieldChangedArgumentCaptor.getValue();
    assertThat(formFieldChanged.getName()).isEqualTo("field");
    assertThat(formFieldChanged.getValue()).isEqualTo("value");
    assertThat(formFieldChanged.getUuid()).isEqualTo(node.getUUID());
    return displayer;
}
Also used : FormDisplayer(org.kie.workbench.common.stunner.forms.client.widgets.container.displayer.FormDisplayer) FormFieldChanged(org.kie.workbench.common.stunner.forms.client.event.FormFieldChanged) FieldChangeHandler(org.kie.workbench.common.forms.processing.engine.handling.FieldChangeHandler)

Aggregations

FieldChangeHandler (org.kie.workbench.common.forms.processing.engine.handling.FieldChangeHandler)3 Test (org.junit.Test)2 FormFieldChanged (org.kie.workbench.common.stunner.forms.client.event.FormFieldChanged)1 FormPropertiesOpened (org.kie.workbench.common.stunner.forms.client.event.FormPropertiesOpened)1 FormDisplayer (org.kie.workbench.common.stunner.forms.client.widgets.container.displayer.FormDisplayer)1 ArgumentMatchers.anyString (org.mockito.ArgumentMatchers.anyString)1 Command (org.uberfire.mvp.Command)1