Search in sources :

Example 1 with LinkkiText

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

the class OkCancelDialogTest method displayingMessage.

private Matcher<OkCancelDialog> displayingMessage(String text) {
    return new TypeSafeMatcher<OkCancelDialog>() {

        @Override
        public void describeTo(Description description) {
            description.appendText("an OkCancelDialog displaying a message with the text '");
            description.appendText(text);
            description.appendText("'");
        }

        @Override
        protected boolean matchesSafely(OkCancelDialog dialog) {
            @NonNull Div layout = dialog.getMessageArea();
            LinkkiText message = (LinkkiText) layout.getComponentAt(0);
            return text.contentEquals(message.getText());
        }
    };
}
Also used : Div(com.vaadin.flow.component.html.Div) TypeSafeMatcher(org.hamcrest.TypeSafeMatcher) Description(org.hamcrest.Description) LinkkiText(org.linkki.core.vaadin.component.base.LinkkiText) NonNull(edu.umd.cs.findbugs.annotations.NonNull)

Example 2 with LinkkiText

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

the class BindLabelValueAspectDefinitionTest method testCreateComponentValueSetter_UsesCustomConverter.

@Test
void testCreateComponentValueSetter_UsesCustomConverter() {
    LinkkiText label = new LinkkiText();
    Consumer<Object> valueSetter = new BindLabelValueAspectDefinition().createComponentValueSetter(new NoLabelComponentWrapper(label));
    LinkkiConverterRegistry converterRegistry = LinkkiConverterRegistry.DEFAULT.with(new Converter<String, FooBar>() {

        private static final long serialVersionUID = 1L;

        @Override
        public Result<FooBar> convertToModel(String value, ValueContext context) {
            return Result.ok(FooBar.valueOf(value));
        }

        @Override
        public String convertToPresentation(FooBar value, ValueContext context) {
            return value == FooBar.FOO ? "Foo" : "Bar";
        }
    });
    VaadinSession vaadinSession = mock(VaadinSession.class);
    when(vaadinSession.getAttribute(LinkkiConverterRegistry.class)).thenReturn(converterRegistry);
    VaadinSession.setCurrent(vaadinSession);
    valueSetter.accept(FooBar.FOO);
    assertThat(label.getText(), is("Foo"));
}
Also used : ValueContext(com.vaadin.flow.data.binder.ValueContext) LinkkiText(org.linkki.core.vaadin.component.base.LinkkiText) VaadinSession(com.vaadin.flow.server.VaadinSession) LinkkiConverterRegistry(org.linkki.core.ui.converters.LinkkiConverterRegistry) Result(com.vaadin.flow.data.binder.Result) NoLabelComponentWrapper(org.linkki.core.ui.wrapper.NoLabelComponentWrapper) Test(org.junit.jupiter.api.Test)

Example 3 with LinkkiText

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

the class BindLabelValueAspectDefinitionTest method testCreateComponentValueSetter_UsesStandardConverter.

@Test
void testCreateComponentValueSetter_UsesStandardConverter() {
    UI.getCurrent().setLocale(Locale.GERMAN);
    LinkkiText label = new LinkkiText();
    Consumer<Object> valueSetter = new BindLabelValueAspectDefinition().createComponentValueSetter(new NoLabelComponentWrapper(label));
    valueSetter.accept(Integer.valueOf(123456));
    assertThat(label.getText(), is("123.456"));
}
Also used : LinkkiText(org.linkki.core.vaadin.component.base.LinkkiText) NoLabelComponentWrapper(org.linkki.core.ui.wrapper.NoLabelComponentWrapper) Test(org.junit.jupiter.api.Test)

Example 4 with LinkkiText

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

the class BindLabelValueAspectDefinitionTest method testCreateComponentValueSetter_SetsString.

@Test
void testCreateComponentValueSetter_SetsString() {
    LinkkiText label = new LinkkiText();
    Consumer<Object> valueSetter = new BindLabelValueAspectDefinition().createComponentValueSetter(new NoLabelComponentWrapper(label));
    valueSetter.accept("foo");
    assertThat(label.getText(), is("foo"));
    assertThat(label.getElement().getProperty("innerHTML"), is(nullValue()));
}
Also used : LinkkiText(org.linkki.core.vaadin.component.base.LinkkiText) NoLabelComponentWrapper(org.linkki.core.ui.wrapper.NoLabelComponentWrapper) Test(org.junit.jupiter.api.Test)

Example 5 with LinkkiText

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

the class BindLabelValueAspectDefinitionTest method testCreateComponentValueSetter_UsesStandardConverter_DependingOnUiLocale.

@Test
void testCreateComponentValueSetter_UsesStandardConverter_DependingOnUiLocale() {
    UI.getCurrent().setLocale(Locale.US);
    LinkkiText label = new LinkkiText();
    Consumer<Object> valueSetter = new BindLabelValueAspectDefinition().createComponentValueSetter(new NoLabelComponentWrapper(label));
    valueSetter.accept(Integer.valueOf(123456));
    assertThat(label.getText(), is("123,456"));
}
Also used : LinkkiText(org.linkki.core.vaadin.component.base.LinkkiText) NoLabelComponentWrapper(org.linkki.core.ui.wrapper.NoLabelComponentWrapper) Test(org.junit.jupiter.api.Test)

Aggregations

LinkkiText (org.linkki.core.vaadin.component.base.LinkkiText)17 Test (org.junit.jupiter.api.Test)13 NoLabelComponentWrapper (org.linkki.core.ui.wrapper.NoLabelComponentWrapper)11 Result (com.vaadin.flow.data.binder.Result)2 ValueContext (com.vaadin.flow.data.binder.ValueContext)2 VaadinSession (com.vaadin.flow.server.VaadinSession)2 LinkkiConverterRegistry (org.linkki.core.ui.converters.LinkkiConverterRegistry)2 AccordionPanel (com.vaadin.flow.component.accordion.AccordionPanel)1 Div (com.vaadin.flow.component.html.Div)1 VerticalLayout (com.vaadin.flow.component.orderedlayout.VerticalLayout)1 NonNull (edu.umd.cs.findbugs.annotations.NonNull)1 Description (org.hamcrest.Description)1 TypeSafeMatcher (org.hamcrest.TypeSafeMatcher)1 BindingContext (org.linkki.core.binding.BindingContext)1 Severity (org.linkki.core.binding.validation.message.Severity)1