Skip to content

Commit

Permalink
test: add validation counter (#5570)
Browse files Browse the repository at this point in the history
  • Loading branch information
vursen authored Oct 13, 2023
1 parent 62ab0e6 commit 8951476
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 0 deletions.
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

0 comments on commit 8951476

Please sign in to comment.