Search in sources :

Example 11 with TestLabel

use of com.vaadin.flow.data.binder.testcomponents.TestLabel in project flow by vaadin.

the class BinderValidationStatusTest method bindingWithStatusLabel_labelIsUpdatedAccordingStatus.

@Test
public void bindingWithStatusLabel_labelIsUpdatedAccordingStatus() {
    TestLabel label = new TestLabel();
    Binding<Person, String> binding = binder.forField(nameField).withValidator(notEmpty).withStatusLabel(label).bind(Person::getFirstName, Person::setFirstName);
    nameField.setValue("");
    // First validation fails => should be event with ERROR status and
    // message
    binding.validate();
    assertVisible(label, true);
    Assert.assertEquals(EMPTY_ERROR_MESSAGE, label.getText());
    nameField.setValue("foo");
    // Second validation succeeds => should be event with OK status and
    // no message
    binding.validate();
    assertVisible(label, false);
    Assert.assertEquals("", label.getText());
}
Also used : TestLabel(com.vaadin.flow.data.binder.testcomponents.TestLabel) Person(com.vaadin.flow.tests.data.bean.Person) Test(org.junit.Test)

Example 12 with TestLabel

use of com.vaadin.flow.data.binder.testcomponents.TestLabel in project flow by vaadin.

the class ReadOnlyHasValueTest method setup.

@Before
public void setup() {
    label = new TestLabel();
    hasValue = new ReadOnlyHasValue<>(label::setText);
}
Also used : TestLabel(com.vaadin.flow.data.binder.testcomponents.TestLabel) Before(org.junit.Before)

Example 13 with TestLabel

use of com.vaadin.flow.data.binder.testcomponents.TestLabel in project flow by vaadin.

the class ValidatorTestBase method setUp.

@Before
public void setUp() {
    ui = new UI() {

        @Override
        public Locale getLocale() {
            return locale;
        }
    };
    UI.setCurrent(ui);
    localeContext = new TestLabel();
}
Also used : Locale(java.util.Locale) UI(com.vaadin.flow.component.UI) TestLabel(com.vaadin.flow.data.binder.testcomponents.TestLabel) Before(org.junit.Before)

Aggregations

TestLabel (com.vaadin.flow.data.binder.testcomponents.TestLabel)13 Test (org.junit.Test)11 Person (com.vaadin.flow.tests.data.bean.Person)9 Before (org.junit.Before)2 UI (com.vaadin.flow.component.UI)1 TestTextField (com.vaadin.flow.data.binder.testcomponents.TestTextField)1 Registration (com.vaadin.flow.shared.Registration)1 Locale (java.util.Locale)1 Matchers.isEmptyString (org.hamcrest.Matchers.isEmptyString)1