diff --git a/vaadin-text-field-flow-parent/vaadin-text-field-flow-integration-tests/src/main/java/com/vaadin/flow/component/textfield/tests/validation/BigDecimalFieldEagerBinderValidationPage.java b/vaadin-text-field-flow-parent/vaadin-text-field-flow-integration-tests/src/main/java/com/vaadin/flow/component/textfield/tests/validation/BigDecimalFieldEagerBinderValidationPage.java new file mode 100644 index 00000000000..9e8e690b271 --- /dev/null +++ b/vaadin-text-field-flow-parent/vaadin-text-field-flow-integration-tests/src/main/java/com/vaadin/flow/component/textfield/tests/validation/BigDecimalFieldEagerBinderValidationPage.java @@ -0,0 +1,54 @@ +/* + * Copyright 2000-2023 Vaadin Ltd. + * + * Licensed under the Apache License, Version 2.0 (the "License"); you may not + * use this file except in compliance with the License. You may obtain a copy of + * the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT + * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the + * License for the specific language governing permissions and limitations under + * the License. + */ +package com.vaadin.flow.component.textfield.tests.validation; + +import com.vaadin.flow.component.textfield.BigDecimalField; +import com.vaadin.flow.data.binder.Binder; +import com.vaadin.flow.data.value.ValueChangeMode; +import com.vaadin.flow.router.Route; +import com.vaadin.tests.validation.AbstractValidationPage; + +@Route("vaadin-big-decimal-field/validation/eager-binder") +public class BigDecimalFieldEagerBinderValidationPage + extends AbstractValidationPage { + public static class Bean { + private Integer property; + + public Integer getProperty() { + return property; + } + + public void setProperty(Integer property) { + this.property = property; + } + } + + public BigDecimalFieldEagerBinderValidationPage() { + super(); + + testField.setValueChangeMode(ValueChangeMode.EAGER); + + Binder binder = new Binder<>(Bean.class); + binder.forField(testField).bind("property"); + binder.addStatusChangeListener(event -> { + incrementServerValidationCounter(); + }); + } + + protected BigDecimalField createTestField() { + return new BigDecimalField(); + } +} diff --git a/vaadin-text-field-flow-parent/vaadin-text-field-flow-integration-tests/src/main/java/com/vaadin/flow/component/textfield/tests/validation/BigDecimalFieldEagerValidationPage.java b/vaadin-text-field-flow-parent/vaadin-text-field-flow-integration-tests/src/main/java/com/vaadin/flow/component/textfield/tests/validation/BigDecimalFieldEagerValidationPage.java new file mode 100644 index 00000000000..c7e8775c787 --- /dev/null +++ b/vaadin-text-field-flow-parent/vaadin-text-field-flow-integration-tests/src/main/java/com/vaadin/flow/component/textfield/tests/validation/BigDecimalFieldEagerValidationPage.java @@ -0,0 +1,40 @@ +/* + * Copyright 2000-2023 Vaadin Ltd. + * + * Licensed under the Apache License, Version 2.0 (the "License"); you may not + * use this file except in compliance with the License. You may obtain a copy of + * the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT + * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the + * License for the specific language governing permissions and limitations under + * the License. + */ +package com.vaadin.flow.component.textfield.tests.validation; + +import com.vaadin.flow.component.textfield.BigDecimalField; +import com.vaadin.flow.data.value.ValueChangeMode; +import com.vaadin.flow.router.Route; +import com.vaadin.tests.validation.AbstractValidationPage; + +@Route("vaadin-big-decimal-field/validation/eager") +public class BigDecimalFieldEagerValidationPage + extends AbstractValidationPage { + public BigDecimalFieldEagerValidationPage() { + super(); + testField.setValueChangeMode(ValueChangeMode.EAGER); + } + + protected BigDecimalField createTestField() { + return new BigDecimalField() { + @Override + protected void validate() { + super.validate(); + incrementServerValidationCounter(); + } + }; + } +} diff --git a/vaadin-text-field-flow-parent/vaadin-text-field-flow-integration-tests/src/test/java/com/vaadin/flow/component/textfield/tests/validation/BigDecimalFieldEagerBinderValidationIT.java b/vaadin-text-field-flow-parent/vaadin-text-field-flow-integration-tests/src/test/java/com/vaadin/flow/component/textfield/tests/validation/BigDecimalFieldEagerBinderValidationIT.java new file mode 100644 index 00000000000..273c264e7ad --- /dev/null +++ b/vaadin-text-field-flow-parent/vaadin-text-field-flow-integration-tests/src/test/java/com/vaadin/flow/component/textfield/tests/validation/BigDecimalFieldEagerBinderValidationIT.java @@ -0,0 +1,64 @@ +/* + * Copyright 2000-2023 Vaadin Ltd. + * + * Licensed under the Apache License, Version 2.0 (the "License"); you may not + * use this file except in compliance with the License. You may obtain a copy of + * the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT + * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the + * License for the specific language governing permissions and limitations under + * the License. + */ +package com.vaadin.flow.component.textfield.tests.validation; + +import org.junit.Test; +import org.openqa.selenium.Keys; + +import com.vaadin.flow.component.textfield.testbench.BigDecimalFieldElement; +import com.vaadin.flow.testutil.TestPath; +import com.vaadin.tests.validation.AbstractValidationIT; + +@TestPath("vaadin-big-decimal-field/validation/eager-binder") +public class BigDecimalFieldEagerBinderValidationIT + extends AbstractValidationIT { + @Test + public void enterChars_fieldValidatesOnEveryChar() { + // Entered: - + testField.sendKeys("-"); + assertValidationCount(1); + assertServerInvalid(); + assertClientInvalid(); + + resetValidationCount(); + + // Entered: -2 + testField.sendKeys("2"); + assertValidationCount(1); + assertServerValid(); + assertClientValid(); + + resetValidationCount(); + + // Entered: - + testField.sendKeys(Keys.BACK_SPACE); + assertValidationCount(1); + assertServerInvalid(); + assertClientInvalid(); + + resetValidationCount(); + + // Entered: + testField.sendKeys(Keys.BACK_SPACE); + assertValidationCount(1); + assertServerValid(); + assertClientValid(); + } + + protected BigDecimalFieldElement getTestField() { + return $(BigDecimalFieldElement.class).first(); + } +} diff --git a/vaadin-text-field-flow-parent/vaadin-text-field-flow-integration-tests/src/test/java/com/vaadin/flow/component/textfield/tests/validation/BigDecimalFieldEagerValidationIT.java b/vaadin-text-field-flow-parent/vaadin-text-field-flow-integration-tests/src/test/java/com/vaadin/flow/component/textfield/tests/validation/BigDecimalFieldEagerValidationIT.java new file mode 100644 index 00000000000..66247b1e1c7 --- /dev/null +++ b/vaadin-text-field-flow-parent/vaadin-text-field-flow-integration-tests/src/test/java/com/vaadin/flow/component/textfield/tests/validation/BigDecimalFieldEagerValidationIT.java @@ -0,0 +1,64 @@ +/* + * Copyright 2000-2023 Vaadin Ltd. + * + * Licensed under the Apache License, Version 2.0 (the "License"); you may not + * use this file except in compliance with the License. You may obtain a copy of + * the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT + * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the + * License for the specific language governing permissions and limitations under + * the License. + */ +package com.vaadin.flow.component.textfield.tests.validation; + +import org.junit.Test; +import org.openqa.selenium.Keys; + +import com.vaadin.flow.component.textfield.testbench.BigDecimalFieldElement; +import com.vaadin.flow.testutil.TestPath; +import com.vaadin.tests.validation.AbstractValidationIT; + +@TestPath("vaadin-big-decimal-field/validation/eager") +public class BigDecimalFieldEagerValidationIT + extends AbstractValidationIT { + @Test + public void enterChars_fieldValidatesOnEveryChar() { + // Entered: - + testField.sendKeys("-"); + assertValidationCount(1); + assertServerInvalid(); + assertClientInvalid(); + + resetValidationCount(); + + // Entered: -2 + testField.sendKeys("2"); + assertValidationCount(1); + assertServerValid(); + assertClientValid(); + + resetValidationCount(); + + // Entered: - + testField.sendKeys(Keys.BACK_SPACE); + assertValidationCount(1); + assertServerInvalid(); + assertClientInvalid(); + + resetValidationCount(); + + // Entered: + testField.sendKeys(Keys.BACK_SPACE); + assertValidationCount(1); + assertServerValid(); + assertClientValid(); + } + + protected BigDecimalFieldElement getTestField() { + return $(BigDecimalFieldElement.class).first(); + } +}