From fc4ff50b2bdc3c7dc5197d15d6696b661838e2cf Mon Sep 17 00:00:00 2001 From: Artur Signell Date: Thu, 8 Dec 2011 15:37:54 +0000 Subject: [PATCH] Test for how validators work with empty fields svn changeset:22329/svn branch:6.7 --- .../ValidationOfRequiredEmptyFields.html | 133 ++++++++++++++++++ .../ValidationOfRequiredEmptyFields.java | 94 +++++++++++++ 2 files changed, 227 insertions(+) create mode 100644 tests/testbench/com/vaadin/tests/validation/ValidationOfRequiredEmptyFields.html create mode 100644 tests/testbench/com/vaadin/tests/validation/ValidationOfRequiredEmptyFields.java diff --git a/tests/testbench/com/vaadin/tests/validation/ValidationOfRequiredEmptyFields.html b/tests/testbench/com/vaadin/tests/validation/ValidationOfRequiredEmptyFields.html new file mode 100644 index 0000000000..4b273ca260 --- /dev/null +++ b/tests/testbench/com/vaadin/tests/validation/ValidationOfRequiredEmptyFields.html @@ -0,0 +1,133 @@ + + + + + + +New Test + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
New Test
open/run/com.vaadin.tests.validation.ValidationOfRequiredFields?restartApplication
mouseClickvaadin=runcomvaadintestsvalidationValidationOfRequiredFields::/VVerticalLayout[0]/ChildComponentContainer[1]/VVerticalLayout[0]/ChildComponentContainer[0]/VCheckBox[0]/domChild[0]11,8
mouseClickvaadin=runcomvaadintestsvalidationValidationOfRequiredFields::/VVerticalLayout[0]/ChildComponentContainer[1]/VVerticalLayout[0]/ChildComponentContainer[1]/VTextField[0]60,11
enterCharactervaadin=runcomvaadintestsvalidationValidationOfRequiredFields::/VVerticalLayout[0]/ChildComponentContainer[1]/VVerticalLayout[0]/ChildComponentContainer[1]/VTextField[0]The field is required
showTooltipvaadin=runcomvaadintestsvalidationValidationOfRequiredFields::/VVerticalLayout[0]/ChildComponentContainer[1]/VVerticalLayout[0]/ChildComponentContainer[4]/VTextField[0]0,0
screenCapturerequired-message
mouseClickvaadin=runcomvaadintestsvalidationValidationOfRequiredFields::/VVerticalLayout[0]/ChildComponentContainer[1]/VVerticalLayout[0]/ChildComponentContainer[2]/VCheckBox[0]/domChild[0]13,5
mouseClickvaadin=runcomvaadintestsvalidationValidationOfRequiredFields::/VVerticalLayout[0]/ChildComponentContainer[1]/VVerticalLayout[0]/ChildComponentContainer[4]/VTextField[0]28,13
enterCharactervaadin=runcomvaadintestsvalidationValidationOfRequiredFields::/VVerticalLayout[0]/ChildComponentContainer[1]/VVerticalLayout[0]/ChildComponentContainer[4]/VTextField[0]a
mouseClickvaadin=runcomvaadintestsvalidationValidationOfRequiredFields::/VVerticalLayout[0]/domChild[0]/domChild[1]34,186
showTooltipvaadin=runcomvaadintestsvalidationValidationOfRequiredFields::/VVerticalLayout[0]/ChildComponentContainer[1]/VVerticalLayout[0]/ChildComponentContainer[4]/VTextField[0]0,0
screenCaptureerror-must-be-int
showTooltipvaadin=runcomvaadintestsvalidationValidationOfRequiredFields::/VVerticalLayout[0]/ChildComponentContainer[1]/VVerticalLayout[0]/ChildComponentContainer[3]/VCheckBox[0]/domChild[0]
mouseClickvaadin=runcomvaadintestsvalidationValidationOfRequiredFields::/VVerticalLayout[0]/ChildComponentContainer[1]/VVerticalLayout[0]/ChildComponentContainer[3]/VCheckBox[0]/domChild[0]45,9
showTooltipvaadin=runcomvaadintestsvalidationValidationOfRequiredFields::/VVerticalLayout[0]/ChildComponentContainer[1]/VVerticalLayout[0]/ChildComponentContainer[4]/VTextField[0]0,0
screenCaptureerror-must-be-int-and-5-to-10-chars
mouseClickvaadin=runcomvaadintestsvalidationValidationOfRequiredFields::/VVerticalLayout[0]/ChildComponentContainer[1]/VVerticalLayout[0]/ChildComponentContainer[3]/VCheckBox[0]/domChild[0]12,7
mouseClickvaadin=runcomvaadintestsvalidationValidationOfRequiredFields::/VVerticalLayout[0]/ChildComponentContainer[1]/VVerticalLayout[0]/ChildComponentContainer[4]/VTextField[0]124,12
typevaadin=runcomvaadintestsvalidationValidationOfRequiredFields::/VVerticalLayout[0]/ChildComponentContainer[1]/VVerticalLayout[0]/ChildComponentContainer[4]/VTextField[0]
mouseClickvaadin=runcomvaadintestsvalidationValidationOfRequiredFields::/VVerticalLayout[0]/ChildComponentContainer[1]/VVerticalLayout[0]/ChildComponentContainer[0]/VCheckBox[0]/domChild[0]8,10
mouseClickvaadin=runcomvaadintestsvalidationValidationOfRequiredFields::/VVerticalLayout[0]/ChildComponentContainer[1]/VVerticalLayout[0]/ChildComponentContainer[3]/VCheckBox[0]/domChild[0]13,7
showTooltipvaadin=runcomvaadintestsvalidationValidationOfRequiredFields::/VVerticalLayout[0]/ChildComponentContainer[1]/VVerticalLayout[0]/ChildComponentContainer[4]/VTextField[0]0,0
screenCaptureempty-invalid-not-required
+ + diff --git a/tests/testbench/com/vaadin/tests/validation/ValidationOfRequiredEmptyFields.java b/tests/testbench/com/vaadin/tests/validation/ValidationOfRequiredEmptyFields.java new file mode 100644 index 0000000000..396b244758 --- /dev/null +++ b/tests/testbench/com/vaadin/tests/validation/ValidationOfRequiredEmptyFields.java @@ -0,0 +1,94 @@ +package com.vaadin.tests.validation; + +import com.vaadin.data.Property.ValueChangeEvent; +import com.vaadin.data.Property.ValueChangeListener; +import com.vaadin.data.Validator; +import com.vaadin.data.validator.IntegerValidator; +import com.vaadin.data.validator.StringLengthValidator; +import com.vaadin.tests.components.TestBase; +import com.vaadin.ui.CheckBox; +import com.vaadin.ui.TextField; + +public class ValidationOfRequiredEmptyFields extends TestBase { + + private TextField tf; + private CheckBox requiredInput; + private TextField requiredErrorInput; + + private Validator integerValidator = new IntegerValidator( + "Must be an integer"); + private Validator stringLengthValidator = new StringLengthValidator( + "Must be 5-10 chars", 5, 10, false); + private CheckBox integerValidatorInput; + private CheckBox stringLengthValidatorInput; + + @Override + protected void setup() { + requiredInput = new CheckBox("Field required"); + requiredInput.setImmediate(true); + requiredInput.addListener(new ValueChangeListener() { + public void valueChange(ValueChangeEvent event) { + tf.setRequired((Boolean) requiredInput.getValue()); + } + }); + + requiredErrorInput = new TextField("Required error message"); + requiredErrorInput.setImmediate(true); + requiredErrorInput.addListener(new ValueChangeListener() { + public void valueChange(ValueChangeEvent event) { + tf.setRequiredError((String) requiredErrorInput.getValue()); + } + }); + + integerValidatorInput = new CheckBox("Integer.parseInt validator"); + integerValidatorInput.setImmediate(true); + integerValidatorInput.addListener(new ValueChangeListener() { + + public void valueChange(ValueChangeEvent event) { + if ((Boolean) integerValidatorInput.getValue()) { + tf.addValidator(integerValidator); + } else { + tf.removeValidator(integerValidator); + } + } + }); + stringLengthValidatorInput = new CheckBox( + "stringLength.parseInt validator"); + stringLengthValidatorInput.setImmediate(true); + stringLengthValidatorInput.addListener(new ValueChangeListener() { + + public void valueChange(ValueChangeEvent event) { + if ((Boolean) stringLengthValidatorInput.getValue()) { + tf.addValidator(stringLengthValidator); + } else { + tf.removeValidator(stringLengthValidator); + } + } + }); + + tf = new TextField(); + tf.setImmediate(true); + + requiredInput.setValue(false); + requiredErrorInput.setValue(""); + integerValidatorInput.setValue(false); + stringLengthValidatorInput.setValue(false); + + addComponent(requiredInput); + addComponent(requiredErrorInput); + addComponent(integerValidatorInput); + addComponent(stringLengthValidatorInput); + addComponent(tf); + } + + @Override + protected String getDescription() { + return null; + } + + @Override + protected Integer getTicketNumber() { + return 3851; + } + +} -- 2.39.5