Skip to content

Commit

Permalink
add eager validation tests
Browse files Browse the repository at this point in the history
  • Loading branch information
vursen committed Oct 16, 2023
1 parent 7e93f6a commit 997e98b
Show file tree
Hide file tree
Showing 4 changed files with 222 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -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<BigDecimalField> {
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<Bean> binder = new Binder<>(Bean.class);
binder.forField(testField).bind("property");
binder.addStatusChangeListener(event -> {
incrementServerValidationCounter();
});
}

protected BigDecimalField createTestField() {
return new BigDecimalField();
}
}
Original file line number Diff line number Diff line change
@@ -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<BigDecimalField> {
public BigDecimalFieldEagerValidationPage() {
super();
testField.setValueChangeMode(ValueChangeMode.EAGER);
}

protected BigDecimalField createTestField() {
return new BigDecimalField() {
@Override
protected void validate() {
super.validate();
incrementServerValidationCounter();
}
};
}
}
Original file line number Diff line number Diff line change
@@ -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<BigDecimalFieldElement> {
@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();
}
}
Original file line number Diff line number Diff line change
@@ -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<BigDecimalFieldElement> {
@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();
}
}

0 comments on commit 997e98b

Please sign in to comment.