summaryrefslogtreecommitdiffstats
path: root/uitest/src/com/vaadin/tests/fieldgroup
diff options
context:
space:
mode:
Diffstat (limited to 'uitest/src/com/vaadin/tests/fieldgroup')
-rw-r--r--uitest/src/com/vaadin/tests/fieldgroup/AbstractBasicCrud.java64
-rw-r--r--uitest/src/com/vaadin/tests/fieldgroup/BasicCrudGridEditorRowTest.java40
2 files changed, 101 insertions, 3 deletions
diff --git a/uitest/src/com/vaadin/tests/fieldgroup/AbstractBasicCrud.java b/uitest/src/com/vaadin/tests/fieldgroup/AbstractBasicCrud.java
index 30cc5676bb..c88047e414 100644
--- a/uitest/src/com/vaadin/tests/fieldgroup/AbstractBasicCrud.java
+++ b/uitest/src/com/vaadin/tests/fieldgroup/AbstractBasicCrud.java
@@ -16,16 +16,20 @@
package com.vaadin.tests.fieldgroup;
import java.util.Iterator;
+import java.util.Map;
import com.vaadin.annotations.Theme;
import com.vaadin.data.Property.ValueChangeEvent;
import com.vaadin.data.Property.ValueChangeListener;
+import com.vaadin.data.Validator.InvalidValueException;
import com.vaadin.data.fieldgroup.BeanFieldGroup;
import com.vaadin.data.fieldgroup.FieldGroup.CommitException;
import com.vaadin.data.fieldgroup.PropertyId;
import com.vaadin.data.util.BeanItem;
import com.vaadin.data.util.BeanItemContainer;
+import com.vaadin.data.validator.IntegerRangeValidator;
import com.vaadin.server.VaadinRequest;
+import com.vaadin.shared.ui.label.ContentMode;
import com.vaadin.shared.util.SharedUtil;
import com.vaadin.tests.components.AbstractTestUIWithLog;
import com.vaadin.ui.Alignment;
@@ -34,10 +38,15 @@ import com.vaadin.ui.Button.ClickEvent;
import com.vaadin.ui.Button.ClickListener;
import com.vaadin.ui.CheckBox;
import com.vaadin.ui.ComboBox;
+import com.vaadin.ui.Component;
import com.vaadin.ui.Field;
import com.vaadin.ui.GridLayout;
import com.vaadin.ui.HorizontalLayout;
+import com.vaadin.ui.Label;
+import com.vaadin.ui.Notification;
+import com.vaadin.ui.Notification.Type;
import com.vaadin.ui.TextField;
+import com.vaadin.ui.themes.ValoTheme;
@Theme("valo")
public abstract class AbstractBasicCrud extends AbstractTestUIWithLog {
@@ -100,6 +109,7 @@ public abstract class AbstractBasicCrud extends AbstractTestUIWithLog {
private TextField birthDate = new TextField("Birth date");
private TextField age = new TextField("Age");
private CheckBox alive = new CheckBox("Alive");
+ private Label errorLabel = new Label((String) null, ContentMode.HTML);
@PropertyId("address.streetAddress")
private TextField address_streetAddress = new TextField(
@@ -120,17 +130,51 @@ public abstract class AbstractBasicCrud extends AbstractTestUIWithLog {
address_country.setNullRepresentation("");
birthDate.setNullRepresentation("");
+ age.addValidator(new IntegerRangeValidator(
+ "Must be between 0 and 100", 0, 100));
+
setDefaultComponentAlignment(Alignment.MIDDLE_LEFT);
addComponents(firstName, lastName, gender, birthDate, age, alive,
address_streetAddress, address_postalCode, address_city,
address_country);
+ errorLabel.addStyleName(ValoTheme.LABEL_COLORED);
+ setRows(3);
+ addComponent(errorLabel, 0, 2, getColumns() - 1, 2);
+
HorizontalLayout hl = new HorizontalLayout(save, cancel);
hl.setSpacing(true);
addComponent(hl);
}
+ @Override
+ protected void handleCommitException(CommitException e) {
+ String message = "";
+ // Produce error message in the order in which the fields are in the
+ // layout
+ for (Component c : this) {
+ if (!(c instanceof Field)) {
+ continue;
+ }
+ Field<?> f = (Field<?>) c;
+ Map<Field<?>, InvalidValueException> exceptions = e
+ .getInvalidFields();
+ if (exceptions.containsKey(f)) {
+ message += f.getCaption() + ": "
+ + exceptions.get(f).getLocalizedMessage()
+ + "<br/>\n";
+ }
+ }
+
+ errorLabel.setValue(message);
+ }
+
+ @Override
+ protected void discard() {
+ super.discard();
+ errorLabel.setValue(null);
+ }
}
protected abstract void deselectAll();
@@ -153,6 +197,7 @@ public abstract class AbstractBasicCrud extends AbstractTestUIWithLog {
fieldGroup.commit();
log("Saved " + fieldGroup.getItemDataSource());
} catch (CommitException e) {
+ handleCommitException(e);
log("Commit failed: " + e.getMessage());
}
}
@@ -161,11 +206,28 @@ public abstract class AbstractBasicCrud extends AbstractTestUIWithLog {
@Override
public void buttonClick(ClickEvent event) {
log("Discarded " + fieldGroup.getItemDataSource());
- deselectAll();
+ discard();
}
});
}
+ protected void discard() {
+ deselectAll();
+ }
+
+ protected void handleCommitException(CommitException e) {
+ String message = "";
+ for (Object propertyId : e.getInvalidFields().keySet()) {
+ Field<?> f = e.getFieldGroup().getField(propertyId);
+ message += f.getCaption() + ": "
+ + e.getInvalidFields().get(propertyId);
+ }
+
+ if (!message.isEmpty()) {
+ Notification.show(message, Type.ERROR_MESSAGE);
+ }
+ }
+
public void edit(BeanItem<ComplexPerson> item) {
fieldGroup.setItemDataSource(item);
}
diff --git a/uitest/src/com/vaadin/tests/fieldgroup/BasicCrudGridEditorRowTest.java b/uitest/src/com/vaadin/tests/fieldgroup/BasicCrudGridEditorRowTest.java
index 3ccd547417..bdf8603c48 100644
--- a/uitest/src/com/vaadin/tests/fieldgroup/BasicCrudGridEditorRowTest.java
+++ b/uitest/src/com/vaadin/tests/fieldgroup/BasicCrudGridEditorRowTest.java
@@ -15,25 +15,61 @@
*/
package com.vaadin.tests.fieldgroup;
+import org.junit.Assert;
+import org.junit.Before;
import org.junit.Test;
+import org.openqa.selenium.By;
+import org.openqa.selenium.Keys;
+import org.openqa.selenium.WebElement;
import org.openqa.selenium.interactions.Actions;
+import com.vaadin.testbench.elements.DateFieldElement;
import com.vaadin.testbench.elements.GridElement;
import com.vaadin.testbench.elements.GridElement.GridCellElement;
+import com.vaadin.testbench.elements.GridElement.GridEditorElement;
+import com.vaadin.tests.annotations.TestCategory;
import com.vaadin.tests.tb3.MultiBrowserTest;
+@TestCategory("grid")
public class BasicCrudGridEditorRowTest extends MultiBrowserTest {
+ private GridElement grid;
+
+ @Before
+ public void openTest() {
+ openTestURL();
+ grid = $(GridElement.class).first();
+
+ }
@Test
public void lookAndFeel() throws Exception {
- openTestURL();
- GridElement grid = $(GridElement.class).first();
GridCellElement ritaBirthdate = grid.getCell(2, 3);
compareScreen("grid");
// Open editor row
new Actions(getDriver()).doubleClick(ritaBirthdate).perform();
compareScreen("editorrow");
+ }
+
+ @Test
+ public void editorRowOneInvalidValue() throws Exception {
+ GridCellElement ritaBirthdate = grid.getCell(2, 3);
+ // Open editor row
+ new Actions(getDriver()).doubleClick(ritaBirthdate).perform();
+ GridEditorElement editor = grid.getEditor();
+ DateFieldElement dateField = editor.$(DateFieldElement.class).first();
+ WebElement input = dateField.findElement(By.xpath("input"));
+ // input.click();
+ input.sendKeys("Invalid", Keys.TAB);
+ editor.save();
+
+ Assert.assertTrue("Editor wasn't displayed.", editor.isDisplayed());
+ Assert.assertTrue("DateField wasn't displayed.",
+ dateField.isDisplayed());
+
+ Assert.assertTrue("DateField didn't have 'v-invalid' css class.",
+ hasCssClass(dateField, "v-datefield-error"));
}
+
}