Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add i18n error message support for EmailField #6463

Merged
merged 3 commits into from
Jul 25, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,20 @@ public class EmailFieldBasicValidationPage
public static final String MIN_LENGTH_INPUT = "min-length-input";
public static final String MAX_LENGTH_INPUT = "max-length-input";

public static final String REQUIRED_ERROR_MESSAGE = "Field is required";
public static final String MIN_LENGTH_ERROR_MESSAGE = "Value is too short";
public static final String MAX_LENGTH_ERROR_MESSAGE = "Value is too long";
public static final String PATTERN_ERROR_MESSAGE = "Value has incorrect format";

public EmailFieldBasicValidationPage() {
super();

testField.setI18n(new EmailField.EmailFieldI18n()
.setRequiredErrorMessage(REQUIRED_ERROR_MESSAGE)
.setMinLengthErrorMessage(MIN_LENGTH_ERROR_MESSAGE)
.setMaxLengthErrorMessage(MAX_LENGTH_ERROR_MESSAGE)
.setPatternErrorMessage(PATTERN_ERROR_MESSAGE));

add(createButton(REQUIRED_BUTTON, "Enable required", event -> {
testField.setRequired(true);
}));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,11 @@ public class EmailFieldBinderValidationPage
public static final String MAX_LENGTH_INPUT = "max-length-input";
public static final String EXPECTED_VALUE_INPUT = "expected-value-input";

public static final String REQUIRED_ERROR_MESSAGE = "The field is required";
public static final String UNEXPECTED_VALUE_ERROR_MESSAGE = "The field doesn't match the expected value";
public static final String REQUIRED_ERROR_MESSAGE = "Field is required";
public static final String MIN_LENGTH_ERROR_MESSAGE = "Value is too short";
public static final String MAX_LENGTH_ERROR_MESSAGE = "Value is too long";
public static final String PATTERN_ERROR_MESSAGE = "Value does not match the pattern";
public static final String UNEXPECTED_VALUE_ERROR_MESSAGE = "Value does not match the expected value";

public static class Bean {
private String property;
Expand Down Expand Up @@ -59,6 +62,11 @@ public EmailFieldBinderValidationPage() {
incrementServerValidationCounter();
});

testField.setI18n(new EmailField.EmailFieldI18n()
.setMinLengthErrorMessage(MIN_LENGTH_ERROR_MESSAGE)
.setMaxLengthErrorMessage(MAX_LENGTH_ERROR_MESSAGE)
.setPatternErrorMessage(PATTERN_ERROR_MESSAGE));

add(createInput(EXPECTED_VALUE_INPUT, "Set expected value", event -> {
expectedValue = event.getValue();
}));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,13 @@
import com.vaadin.tests.validation.AbstractValidationIT;

import static com.vaadin.flow.component.textfield.tests.validation.EmailFieldBasicValidationPage.MIN_LENGTH_INPUT;
import static com.vaadin.flow.component.textfield.tests.validation.EmailFieldBasicValidationPage.PATTERN_ERROR_MESSAGE;
import static com.vaadin.flow.component.textfield.tests.validation.EmailFieldBasicValidationPage.MAX_LENGTH_ERROR_MESSAGE;
import static com.vaadin.flow.component.textfield.tests.validation.EmailFieldBasicValidationPage.MAX_LENGTH_INPUT;
import static com.vaadin.flow.component.textfield.tests.validation.EmailFieldBasicValidationPage.MIN_LENGTH_ERROR_MESSAGE;
import static com.vaadin.flow.component.textfield.tests.validation.EmailFieldBasicValidationPage.PATTERN_INPUT;
import static com.vaadin.flow.component.textfield.tests.validation.EmailFieldBasicValidationPage.REQUIRED_BUTTON;
import static com.vaadin.flow.component.textfield.tests.validation.EmailFieldBasicValidationPage.REQUIRED_ERROR_MESSAGE;

@TestPath("vaadin-email-field/validation/basic")
public class EmailFieldBasicValidationIT
Expand All @@ -34,6 +38,7 @@ public class EmailFieldBasicValidationIT
public void fieldIsInitiallyValid() {
assertClientValid();
assertServerValid();
assertErrorMessage(null);
}

@Test
Expand All @@ -42,6 +47,7 @@ public void triggerBlur_assertValidity() {
assertValidationCount(0);
assertServerValid();
assertClientValid();
assertErrorMessage(null);
}

@Test
Expand All @@ -52,6 +58,7 @@ public void required_triggerBlur_assertValidity() {
assertValidationCount(0);
assertServerValid();
assertClientValid();
assertErrorMessage(null);
}

@Test
Expand All @@ -62,11 +69,13 @@ public void required_changeValue_assertValidity() {
assertValidationCount(1);
assertServerValid();
assertClientValid();
assertErrorMessage("");

testField.setValue("");
assertValidationCount(1);
assertServerInvalid();
assertClientInvalid();
assertErrorMessage(REQUIRED_ERROR_MESSAGE);
}

@Test
Expand All @@ -77,16 +86,19 @@ public void minLength_changeValue_assertValidity() {
assertValidationCount(1);
assertClientInvalid();
assertServerInvalid();
assertErrorMessage(MIN_LENGTH_ERROR_MESSAGE);

testField.setValue("[email protected]");
assertValidationCount(1);
assertClientValid();
assertServerValid();
assertErrorMessage("");

testField.setValue("[email protected]");
assertValidationCount(1);
assertClientValid();
assertServerValid();
assertErrorMessage("");
}

@Test
Expand All @@ -97,16 +109,19 @@ public void maxLength_changeValue_assertValidity() {
assertValidationCount(1);
assertClientInvalid();
assertServerInvalid();
assertErrorMessage(MAX_LENGTH_ERROR_MESSAGE);

testField.setValue("[email protected]");
assertValidationCount(1);
assertClientValid();
assertServerValid();
assertErrorMessage("");

testField.setValue("[email protected]");
assertValidationCount(1);
assertClientValid();
assertServerValid();
assertErrorMessage("");
}

@Test
Expand All @@ -115,11 +130,13 @@ public void defaultPattern_changeValue_assertValidity() {
assertValidationCount(1);
assertClientInvalid();
assertServerInvalid();
assertErrorMessage(PATTERN_ERROR_MESSAGE);

testField.setValue("[email protected]");
assertValidationCount(1);
assertClientValid();
assertServerValid();
assertErrorMessage("");
}

@Test
Expand All @@ -131,11 +148,13 @@ public void pattern_changeValue_assertValidity() {
assertValidationCount(1);
assertClientInvalid();
assertServerInvalid();
assertErrorMessage(PATTERN_ERROR_MESSAGE);

testField.setValue("[email protected]");
assertValidationCount(1);
assertClientValid();
assertServerValid();
assertErrorMessage("");
}

@Test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,11 @@

import static com.vaadin.flow.component.textfield.tests.validation.EmailFieldBinderValidationPage.PATTERN_INPUT;
import static com.vaadin.flow.component.textfield.tests.validation.EmailFieldBinderValidationPage.MIN_LENGTH_INPUT;
import static com.vaadin.flow.component.textfield.tests.validation.EmailFieldBinderValidationPage.PATTERN_ERROR_MESSAGE;
import static com.vaadin.flow.component.textfield.tests.validation.EmailFieldBinderValidationPage.MAX_LENGTH_INPUT;
import static com.vaadin.flow.component.textfield.tests.validation.EmailFieldBinderValidationPage.MIN_LENGTH_ERROR_MESSAGE;
import static com.vaadin.flow.component.textfield.tests.validation.EmailFieldBinderValidationPage.EXPECTED_VALUE_INPUT;
import static com.vaadin.flow.component.textfield.tests.validation.EmailFieldBinderValidationPage.MAX_LENGTH_ERROR_MESSAGE;
import static com.vaadin.flow.component.textfield.tests.validation.EmailFieldBinderValidationPage.REQUIRED_ERROR_MESSAGE;
import static com.vaadin.flow.component.textfield.tests.validation.EmailFieldBinderValidationPage.UNEXPECTED_VALUE_ERROR_MESSAGE;

Expand All @@ -45,6 +48,7 @@ public void required_triggerBlur_assertValidity() {
assertValidationCount(0);
assertServerValid();
assertClientValid();
assertErrorMessage(null);
}

@Test
Expand Down Expand Up @@ -75,7 +79,7 @@ public void minLength_changeValue_assertValidity() {
assertValidationCount(1);
assertClientInvalid();
assertServerInvalid();
assertErrorMessage("");
assertErrorMessage(MIN_LENGTH_ERROR_MESSAGE);

// Binder validation fails:
testField.setValue("[email protected]");
Expand All @@ -102,7 +106,7 @@ public void maxLength_changeValue_assertValidity() {
assertValidationCount(1);
assertClientInvalid();
assertServerInvalid();
assertErrorMessage("");
assertErrorMessage(MAX_LENGTH_ERROR_MESSAGE);

// Binder validation fails:
testField.setValue("[email protected]");
Expand All @@ -127,7 +131,7 @@ public void defaultPattern_changeValue_assertValidity() {
assertValidationCount(1);
assertClientInvalid();
assertServerInvalid();
assertErrorMessage("");
assertErrorMessage(PATTERN_ERROR_MESSAGE);

testField.setValue("[email protected]");
assertValidationCount(1);
Expand All @@ -147,7 +151,7 @@ public void pattern_changeValue_assertValidity() {
assertValidationCount(1);
assertClientInvalid();
assertServerInvalid();
assertErrorMessage("");
assertErrorMessage(PATTERN_ERROR_MESSAGE);

// Binder validation fails:
testField.setValue("[email protected]");
Expand Down
Loading