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

test: add validation counter #5570

Merged
merged 1 commit into from
Oct 13, 2023
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 @@ -26,6 +26,8 @@
import static com.vaadin.tests.validation.AbstractValidationPage.DETACH_FIELD_BUTTON;
import static com.vaadin.tests.validation.AbstractValidationPage.SERVER_VALIDITY_STATE;
import static com.vaadin.tests.validation.AbstractValidationPage.SERVER_VALIDITY_STATE_BUTTON;
import static com.vaadin.tests.validation.AbstractValidationPage.SERVER_VALIDATION_COUNTER;
import static com.vaadin.tests.validation.AbstractValidationPage.SERVER_VALIDATION_COUNTER_RESET_BUTTON;

public abstract class AbstractValidationIT<T extends TestBenchElement>
extends AbstractComponentIT {
Expand All @@ -39,6 +41,17 @@ public void init() {

protected abstract T getTestField();

protected void assertValidationCount(int expected) {
int actual = Integer
.parseInt($("div").id(SERVER_VALIDATION_COUNTER).getText());
Assert.assertEquals("The field should have validated " + expected
+ " times on the server-side", expected, actual);
}

protected void resetValidationCount() {
$("button").id(SERVER_VALIDATION_COUNTER_RESET_BUTTON).click();
}

protected void assertErrorMessage(String expected) {
Assert.assertEquals(expected,
testField.getPropertyString("errorMessage"));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,16 +30,22 @@ public abstract class AbstractValidationPage<T extends Component & HasValidation
public static final String SERVER_VALIDITY_STATE = "server-validity-state";
public static final String SERVER_VALIDITY_STATE_BUTTON = "server-validity-state-button";

public static final String SERVER_VALIDATION_COUNTER = "server-validation-counter";
public static final String SERVER_VALIDATION_COUNTER_RESET_BUTTON = "server-validation-counter-reset-button";

public static final String ATTACH_FIELD_BUTTON = "attach-field-button";
public static final String DETACH_FIELD_BUTTON = "detach-field-button";

private Div serverValidationCounter;

protected T testField;

protected AbstractValidationPage() {
testField = createTestField();
add(testField);

addServerValidityStateControls();
addServerValidationCounter();
addAttachDetachControls();
}

Expand All @@ -57,6 +63,25 @@ private void addServerValidityStateControls() {
add(new Div(validityState, validityStateButton));
}

private void addServerValidationCounter() {
serverValidationCounter = new Div();
serverValidationCounter.setId(SERVER_VALIDATION_COUNTER);
serverValidationCounter.setText("0");

NativeButton serverValidationCounterResetButton = createButton(
SERVER_VALIDATION_COUNTER_RESET_BUTTON,
"Reset server validation counter",
event -> serverValidationCounter.setText("0"));

add(new Div(serverValidationCounter,
serverValidationCounterResetButton));
}

protected void incrementServerValidationCounter() {
int count = Integer.parseInt(serverValidationCounter.getText());
serverValidationCounter.setText(String.valueOf(count + 1));
}

private void addAttachDetachControls() {
NativeButton attachButton = createButton(ATTACH_FIELD_BUTTON,
"Attach field", event -> add(testField));
Expand Down