Search in sources :

Example 96 with Person

use of com.vaadin.flow.tests.data.bean.Person in project flow by vaadin.

the class BinderValidationStatusTest method binderWithStatusLabel_setAfterHandler.

@Test(expected = IllegalStateException.class)
public void binderWithStatusLabel_setAfterHandler() {
    TestLabel label = new TestLabel();
    BindingBuilder<Person, String> binding = binder.forField(nameField);
    binding.bind(Person::getFirstName, Person::setFirstName);
    binder.setValidationStatusHandler(event -> {
    });
    binder.setStatusLabel(label);
}
Also used : TestLabel(com.vaadin.flow.data.binder.testcomponents.TestLabel) Person(com.vaadin.flow.tests.data.bean.Person) Test(org.junit.Test)

Example 97 with Person

use of com.vaadin.flow.tests.data.bean.Person 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)

Aggregations

Person (com.vaadin.flow.tests.data.bean.Person)97 Test (org.junit.Test)92 TestTextField (com.vaadin.flow.data.binder.testcomponents.TestTextField)51 Matchers.isEmptyString (org.hamcrest.Matchers.isEmptyString)49 StringToIntegerConverter (com.vaadin.flow.data.converter.StringToIntegerConverter)34 Matchers.containsString (org.hamcrest.Matchers.containsString)31 Before (org.junit.Before)30 NotEmptyValidator (com.vaadin.flow.data.validator.NotEmptyValidator)29 AtomicBoolean (java.util.concurrent.atomic.AtomicBoolean)28 HasValue (com.vaadin.flow.component.HasValue)26 BindingBuilder (com.vaadin.flow.data.binder.Binder.BindingBuilder)26 Assert (org.junit.Assert)26 Binding (com.vaadin.flow.data.binder.Binder.Binding)25 CurrentInstance (com.vaadin.flow.internal.CurrentInstance)25 Serializable (java.io.Serializable)25 HashMap (java.util.HashMap)25 Map (java.util.Map)25 Assert.assertEquals (org.junit.Assert.assertEquals)25 Assert.assertFalse (org.junit.Assert.assertFalse)25 Assert.assertNotNull (org.junit.Assert.assertNotNull)25