Search in sources :

Example 1 with LabelComponentFormItem

use of org.linkki.core.vaadin.component.base.LabelComponentFormItem in project linkki by linkki-framework.

the class DialogBindingManagerTest method testBindingsInCreatedContextsDisplayMessagesFromDialog.

@Test
public void testBindingsInCreatedContextsDisplayMessagesFromDialog() {
    OkCancelDialog dialog = OkCancelDialog.builder("").build();
    // Use the NOP validation service in the binding manager
    DialogBindingManager manager = new DialogBindingManager(dialog, ValidationService.NOP_VALIDATION_SERVICE);
    BindingContext ctx = manager.getContext("foo");
    // Change the dialog's validation service to make sure dialog's validate method is used and
    // not the validation service the manager was created with (so that the dialog could filter
    // the messages)
    MessageList messages = new MessageList(Message.newError("code", "text"));
    dialog.setValidationService(ValidationService.of(messages));
    PropertyDispatcher propertyDispatcher = mock(PropertyDispatcher.class);
    Object pmo = mock(Object.class);
    when(propertyDispatcher.getBoundObject()).thenReturn(pmo);
    when(propertyDispatcher.getMessages(any())).thenReturn(new MessageList());
    FormItemComponentWrapper componentWrapper = new FormItemComponentWrapper(new LabelComponentFormItem(new Button(), new Label()));
    ElementBinding binding = spy(new ElementBinding(componentWrapper, propertyDispatcher, Handler.NOP_HANDLER, new ArrayList<>()));
    ctx.add(binding, componentWrapper);
    ctx.modelChanged();
    verify(binding).displayMessages(messages);
}
Also used : Button(com.vaadin.flow.component.button.Button) Label(com.vaadin.flow.component.html.Label) ArrayList(java.util.ArrayList) PropertyDispatcher(org.linkki.core.binding.dispatcher.PropertyDispatcher) LabelComponentFormItem(org.linkki.core.vaadin.component.base.LabelComponentFormItem) ElementBinding(org.linkki.core.binding.ElementBinding) BindingContext(org.linkki.core.binding.BindingContext) FormItemComponentWrapper(org.linkki.core.ui.wrapper.FormItemComponentWrapper) MessageList(org.linkki.core.binding.validation.message.MessageList) Test(org.junit.jupiter.api.Test)

Example 2 with LabelComponentFormItem

use of org.linkki.core.vaadin.component.base.LabelComponentFormItem in project linkki by linkki-framework.

the class FormItemComponentWrapperTest method testSetTooltip.

@Test
void testSetTooltip() {
    TextField formTextField = new TextField();
    LabelComponentFormItem formItem = new LabelComponentFormItem(formTextField, new Label("SomeText"));
    FormItemComponentWrapper wrapper = new FormItemComponentWrapper(formItem);
    wrapper.setTooltip("testTip");
    assertThat(getTitleAttribute(wrapper), is("testTip"));
    wrapper.setTooltip("<script>");
    assertThat(getTitleAttribute(wrapper), is(""));
    wrapper.setTooltip("<div> some text </div>");
    assertThat(getTitleAttribute(wrapper), is(" some text "));
    wrapper.setTooltip("<div> some text <br> with page break</div> ");
    assertThat(getTitleAttribute(wrapper), is(" some text \n with page break "));
}
Also used : Label(com.vaadin.flow.component.html.Label) TextField(com.vaadin.flow.component.textfield.TextField) LabelComponentFormItem(org.linkki.core.vaadin.component.base.LabelComponentFormItem) Test(org.junit.jupiter.api.Test)

Example 3 with LabelComponentFormItem

use of org.linkki.core.vaadin.component.base.LabelComponentFormItem in project linkki by linkki-framework.

the class UINestedComponentIntegrationTest method testApsectOnNestedComponent.

@Test
public void testApsectOnNestedComponent() {
    NestedComponentPmo pmo = new NestedComponentPmo();
    BindingContext bindingContext = new BindingContext();
    BaseSection component = (BaseSection) VaadinUiCreator.createComponent(pmo, bindingContext);
    LabelComponentFormItem nestedComponent = (LabelComponentFormItem) getChild(component.getContentWrapper(), 1);
    assertThat(nestedComponent.isVisible(), is(true));
    pmo.setVisible(false);
    bindingContext.modelChanged();
    assertThat(nestedComponent.isVisible(), is(false));
}
Also used : BaseSection(org.linkki.core.vaadin.component.section.BaseSection) LabelComponentFormItem(org.linkki.core.vaadin.component.base.LabelComponentFormItem) BindingContext(org.linkki.core.binding.BindingContext) Test(org.junit.jupiter.api.Test)

Example 4 with LabelComponentFormItem

use of org.linkki.core.vaadin.component.base.LabelComponentFormItem in project linkki by linkki-framework.

the class FormItemComponentWrapperTest method setUp.

@BeforeEach
void setUp() {
    propertyDispatcherValue = mock(PropertyDispatcher.class);
    when(propertyDispatcherValue.getProperty()).thenReturn("value");
    propertyDispatcherEnumValue = mock(PropertyDispatcher.class);
    when(propertyDispatcherEnumValue.getProperty()).thenReturn("enumValue");
    doReturn(TestEnum.class).when(propertyDispatcherEnumValue).getValueClass();
    messageList = new MessageList();
    when(propertyDispatcherValue.getMessages(any(MessageList.class))).thenReturn(messageList);
    when(propertyDispatcherEnumValue.getMessages(any(MessageList.class))).thenReturn(messageList);
    selectBinding = new ElementBinding(new FormItemComponentWrapper(new LabelComponentFormItem(selectField, label)), propertyDispatcherEnumValue, Handler.NOP_HANDLER, new ArrayList<>());
}
Also used : ArrayList(java.util.ArrayList) PropertyDispatcher(org.linkki.core.binding.dispatcher.PropertyDispatcher) ElementBinding(org.linkki.core.binding.ElementBinding) LabelComponentFormItem(org.linkki.core.vaadin.component.base.LabelComponentFormItem) MessageList(org.linkki.core.binding.validation.message.MessageList) BeforeEach(org.junit.jupiter.api.BeforeEach)

Example 5 with LabelComponentFormItem

use of org.linkki.core.vaadin.component.base.LabelComponentFormItem in project linkki by linkki-framework.

the class FormItemComponentWrapperTest method testUpdateFromPmo_updateAspect.

@Test
void testUpdateFromPmo_updateAspect() {
    Handler componentUpdater = mock(Handler.class);
    LinkkiAspectDefinition aspectDefinition = mock(LinkkiAspectDefinition.class);
    when(aspectDefinition.supports(any())).thenReturn(true);
    when(aspectDefinition.createUiUpdater(any(), any())).thenReturn(componentUpdater);
    ElementBinding fieldBinding = new ElementBinding(new FormItemComponentWrapper(new LabelComponentFormItem(field, label)), propertyDispatcherValue, Handler.NOP_HANDLER, Arrays.asList(aspectDefinition));
    fieldBinding.updateFromPmo();
    verify(componentUpdater).apply();
}
Also used : Handler(org.linkki.util.handler.Handler) LinkkiAspectDefinition(org.linkki.core.binding.descriptor.aspect.LinkkiAspectDefinition) ElementBinding(org.linkki.core.binding.ElementBinding) LabelComponentFormItem(org.linkki.core.vaadin.component.base.LabelComponentFormItem) Test(org.junit.jupiter.api.Test)

Aggregations

LabelComponentFormItem (org.linkki.core.vaadin.component.base.LabelComponentFormItem)5 Test (org.junit.jupiter.api.Test)4 ElementBinding (org.linkki.core.binding.ElementBinding)3 Label (com.vaadin.flow.component.html.Label)2 ArrayList (java.util.ArrayList)2 BindingContext (org.linkki.core.binding.BindingContext)2 PropertyDispatcher (org.linkki.core.binding.dispatcher.PropertyDispatcher)2 MessageList (org.linkki.core.binding.validation.message.MessageList)2 Button (com.vaadin.flow.component.button.Button)1 TextField (com.vaadin.flow.component.textfield.TextField)1 BeforeEach (org.junit.jupiter.api.BeforeEach)1 LinkkiAspectDefinition (org.linkki.core.binding.descriptor.aspect.LinkkiAspectDefinition)1 FormItemComponentWrapper (org.linkki.core.ui.wrapper.FormItemComponentWrapper)1 BaseSection (org.linkki.core.vaadin.component.section.BaseSection)1 Handler (org.linkki.util.handler.Handler)1