From 34a1a6f8ca690efc293b999bda9b6c2700cd3f39 Mon Sep 17 00:00:00 2001 From: Artur Signell Date: Sun, 1 Nov 2009 20:05:44 +0000 Subject: [PATCH] Merged (partly manually) test updates from [9345],[9346],[9357] svn changeset:9556/svn branch:6.2 --- .../tests/components/ComponentTestCase.java | 110 +++++++++++++++ .../vaadin/tests/components/label/Labels.html | 92 ++++++++++++ .../vaadin/tests/components/label/Labels.java | 132 ++++++++++++++++++ .../components/textfield/TextFields.java | 122 ++++------------ 4 files changed, 365 insertions(+), 91 deletions(-) create mode 100644 tests/src/com/vaadin/tests/components/ComponentTestCase.java create mode 100644 tests/src/com/vaadin/tests/components/label/Labels.html create mode 100644 tests/src/com/vaadin/tests/components/label/Labels.java diff --git a/tests/src/com/vaadin/tests/components/ComponentTestCase.java b/tests/src/com/vaadin/tests/components/ComponentTestCase.java new file mode 100644 index 0000000000..3c6d6cbcb3 --- /dev/null +++ b/tests/src/com/vaadin/tests/components/ComponentTestCase.java @@ -0,0 +1,110 @@ +package com.vaadin.tests.components; + +import java.util.ArrayList; +import java.util.List; + +import com.vaadin.terminal.UserError; +import com.vaadin.ui.AbstractComponent; +import com.vaadin.ui.AbstractField; +import com.vaadin.ui.Component; +import com.vaadin.ui.HorizontalLayout; +import com.vaadin.ui.Layout.SpacingHandler; + +public abstract class ComponentTestCase extends TestBase { + + private List testComponents = new ArrayList(); + + @Override + protected void setup() { + ((SpacingHandler) getLayout()).setSpacing(true); + addComponent(createActionLayout()); + } + + @Override + protected String getDescription() { + // TODO Auto-generated method stub + return null; + } + + @Override + protected Integer getTicketNumber() { + // TODO Auto-generated method stub + return null; + } + + protected abstract List createActions(); + + private Component createActionLayout() { + HorizontalLayout actionLayout = new HorizontalLayout(); + actionLayout.setSpacing(true); + actionLayout.setMargin(true); + for (Component c : createActions()) { + actionLayout.addComponent(c); + } + addComponent(actionLayout); + return actionLayout; + } + + protected void addTestComponent(AbstractComponent c) { + testComponents.add(c); + addComponent(c); + } + + protected List getTestComponents() { + return testComponents; + } + + protected void setErrorIndicators(boolean on) { + for (AbstractComponent c : getTestComponents()) { + if (c == null) { + continue; + } + + if (on) { + c.setComponentError(new UserError("It failed!")); + } else { + c.setComponentError(null); + + } + } + + } + + protected void setRequired(boolean on) { + + for (AbstractComponent c : getTestComponents()) { + if (c == null) { + continue; + } + + if (c instanceof AbstractField) { + ((AbstractField) c).setRequired(on); + } + + } + + } + + protected void setEnabled(boolean on) { + for (AbstractComponent c : getTestComponents()) { + if (c == null) { + continue; + } + + c.setEnabled(on); + } + + } + + protected void setReadOnly(boolean on) { + for (AbstractComponent c : getTestComponents()) { + if (c == null) { + continue; + } + + c.setReadOnly(on); + } + + } + +} diff --git a/tests/src/com/vaadin/tests/components/label/Labels.html b/tests/src/com/vaadin/tests/components/label/Labels.html new file mode 100644 index 0000000000..214db23b4b --- /dev/null +++ b/tests/src/com/vaadin/tests/components/label/Labels.html @@ -0,0 +1,92 @@ + + + + + + +Labels + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Labels
open/run/com.vaadin.tests.components.label.Labels
screenCaptureenabled
waitForVaadin
mouseClickvaadin=runcomvaadintestscomponentslabelLabels::/VVerticalLayout[0]/ChildComponentContainer[1]/VVerticalLayout[0]/ChildComponentContainer[0]/VHorizontalLayout[0]/ChildComponentContainer[1]/VCheckBox[0]/domChild[0]9,9
waitForVaadin
mouseClickvaadin=runcomvaadintestscomponentslabelLabels::/VVerticalLayout[0]/ChildComponentContainer[1]/VVerticalLayout[0]/ChildComponentContainer[0]/VHorizontalLayout[0]/ChildComponentContainer[0]/VCheckBox[0]/domChild[0]8,2
waitForVaadin
screenCaptureerrorindicators
mouseClickvaadin=runcomvaadintestscomponentslabelLabels::/VVerticalLayout[0]/ChildComponentContainer[1]/VVerticalLayout[0]/ChildComponentContainer[0]/VHorizontalLayout[0]/ChildComponentContainer[1]/VCheckBox[0]/domChild[0]0,10
waitForVaadin
mouseClickvaadin=runcomvaadintestscomponentslabelLabels::/VVerticalLayout[0]/ChildComponentContainer[1]/VVerticalLayout[0]/ChildComponentContainer[0]/VHorizontalLayout[0]/ChildComponentContainer[2]/VCheckBox[0]/domChild[0]2,5
waitForVaadin
mouseClickvaadin=runcomvaadintestscomponentslabelLabels::/VVerticalLayout[0]/ChildComponentContainer[1]/VVerticalLayout[0]/ChildComponentContainer[0]/VHorizontalLayout[0]/ChildComponentContainer[0]/VCheckBox[0]/domChild[1]0,8
waitForVaadin
screenCapturedisabled
+ + diff --git a/tests/src/com/vaadin/tests/components/label/Labels.java b/tests/src/com/vaadin/tests/components/label/Labels.java new file mode 100644 index 0000000000..a1acf403ee --- /dev/null +++ b/tests/src/com/vaadin/tests/components/label/Labels.java @@ -0,0 +1,132 @@ +package com.vaadin.tests.components.label; + +import java.util.ArrayList; +import java.util.List; + +import com.vaadin.tests.components.ComponentTestCase; +import com.vaadin.tests.util.LoremIpsum; +import com.vaadin.ui.Button; +import com.vaadin.ui.CheckBox; +import com.vaadin.ui.Component; +import com.vaadin.ui.HorizontalLayout; +import com.vaadin.ui.Label; +import com.vaadin.ui.Button.ClickEvent; + +public class Labels extends ComponentTestCase { + + Label label[] = new Label[20]; + + @Override + protected void setup() { + super.setup(); + + Label l; + l = createLabel("This is an undefined wide label which do not wrap. It should be clipped at the end of the screen" + + LoremIpsum.get(1000)); + l.setWidth(null); + addTestComponent(l); + + l = createLabel("This is a 200px wide simple label which wrap"); + l.setWidth("200px"); + addTestComponent(l); + + l = createLabel("This is a 100% wide simple label which should wrap. " + + LoremIpsum.get(1500)); + l.setWidth("100%"); + addTestComponent(l); + + l = createLabel("This is a 100% wide simple with fixed 65px height. It should wrap. " + + LoremIpsum.get(5000)); + l.setWidth("100%"); + l.setHeight("65px"); + addTestComponent(l); + + l = createLabel( + "

Hello

I am a rich Label

", + "This is an XHTML label with rich content"); + l.setContentMode(Label.CONTENT_XHTML); + addTestComponent(l); + + l = createLabel( + "

Hello

I am a rich Label

", + "This is an XHTML label with fixed 200px width and rich content"); + l.setContentMode(Label.CONTENT_XHTML); + l.setWidth("200px"); + addTestComponent(l); + + } + + private Component createActionLayout() { + HorizontalLayout actionLayout = new HorizontalLayout(); + actionLayout.setSpacing(true); + actionLayout.setMargin(true); + for (Component c : createActions()) { + actionLayout.addComponent(c); + } + addComponent(actionLayout); + return actionLayout; + } + + private Label createLabel(String text, String caption) { + Label l = new Label(text); + l.setCaption(caption); + + return l; + } + + private Label createLabel(String text) { + return createLabel(text, null); + } + + @Override + protected String getDescription() { + return "A generic test for Labels in different configurations"; + } + + @Override + protected List createActions() { + ArrayList actions = new ArrayList(); + + CheckBox errorIndicators = new CheckBox("Error indicators", + new Button.ClickListener() { + public void buttonClick(ClickEvent event) { + Button b = event.getButton(); + boolean enabled = (Boolean) b.getValue(); + setErrorIndicators(enabled); + + } + }); + + CheckBox enabled = new CheckBox("Enabled", new Button.ClickListener() { + public void buttonClick(ClickEvent event) { + Button b = event.getButton(); + boolean enabled = (Boolean) b.getValue(); + setEnabled(enabled); + } + }); + + CheckBox readonly = new CheckBox("Readonly", + new Button.ClickListener() { + public void buttonClick(ClickEvent event) { + Button b = event.getButton(); + boolean enabled = (Boolean) b.getValue(); + setReadOnly(enabled); + } + }); + + errorIndicators.setValue(new Boolean(false)); + readonly.setValue(new Boolean(false)); + enabled.setValue(new Boolean(true)); + + errorIndicators.setImmediate(true); + readonly.setImmediate(true); + enabled.setImmediate(true); + + actions.add(errorIndicators); + actions.add(readonly); + actions.add(enabled); + + return actions; + } + +} diff --git a/tests/src/com/vaadin/tests/components/textfield/TextFields.java b/tests/src/com/vaadin/tests/components/textfield/TextFields.java index 7b7c3b3415..9be2c73c41 100644 --- a/tests/src/com/vaadin/tests/components/textfield/TextFields.java +++ b/tests/src/com/vaadin/tests/components/textfield/TextFields.java @@ -3,66 +3,55 @@ package com.vaadin.tests.components.textfield; import java.util.ArrayList; import java.util.List; -import com.vaadin.terminal.UserError; -import com.vaadin.tests.components.TestBase; +import com.vaadin.tests.components.ComponentTestCase; import com.vaadin.ui.Button; import com.vaadin.ui.CheckBox; import com.vaadin.ui.Component; -import com.vaadin.ui.HorizontalLayout; import com.vaadin.ui.TextField; import com.vaadin.ui.Button.ClickEvent; -public class TextFields extends TestBase { - - private TextField textFields[] = new TextField[20]; +public class TextFields extends ComponentTestCase { @Override protected void setup() { - HorizontalLayout actionLayout = new HorizontalLayout(); - actionLayout.setSpacing(true); - actionLayout.setMargin(true); - for (Component c : createActions()) { - actionLayout.addComponent(c); - } - addComponent(actionLayout); + super.setup(); - int index = 0; + TextField tf; - textFields[index] = createTextField("TextField 100% wide"); - textFields[index].setWidth("100%"); - addComponent(textFields[index++]); + tf = createTextField("TextField 100% wide"); + tf.setWidth("100%"); + addTestComponent(tf); - textFields[index] = createTextField(null, - "TextField 100% wide, no caption"); - textFields[index].setWidth("100%"); - addComponent(textFields[index++]); + tf = createTextField(null, "TextField 100% wide, no caption"); + tf.setWidth("100%"); + addTestComponent(tf); - textFields[index] = createTextField("TextField auto wide"); - addComponent(textFields[index++]); + tf = createTextField("TextField auto wide"); + addTestComponent(tf); - textFields[index] = createTextField("TextField with input prompt"); - textFields[index].setInputPrompt("Please enter a value"); - addComponent(textFields[index++]); + tf = createTextField("TextField with input prompt"); + tf.setInputPrompt("Please enter a value"); + addTestComponent(tf); - textFields[index] = createTextField("100px wide textfield"); - textFields[index].setWidth("100px"); - addComponent(textFields[index++]); + tf = createTextField("100px wide textfield"); + tf.setWidth("100px"); + addTestComponent(tf); - textFields[index] = createTextField("150px wide, 120px high textfield"); - textFields[index].setWidth("150px"); - textFields[index].setHeight("120px"); - addComponent(textFields[index++]); + tf = createTextField("150px wide, 120px high textfield"); + tf.setWidth("150px"); + tf.setHeight("120px"); + addTestComponent(tf); - textFields[index] = createTextField("50px high textfield"); - textFields[index].setHeight("50px"); - addComponent(textFields[index++]); + tf = createTextField("50px high textfield"); + tf.setHeight("50px"); + addTestComponent(tf); - textFields[index] = createTextField(null, "No caption"); - addComponent(textFields[index++]); + tf = createTextField(null, "No caption"); + addTestComponent(tf); - textFields[index] = createTextField(null, "No caption and input prompt"); - textFields[index].setInputPrompt("Enter a value"); - addComponent(textFields[index++]); + tf = createTextField(null, "No caption and input prompt"); + tf.setInputPrompt("Enter a value"); + addTestComponent(tf); } @@ -88,6 +77,7 @@ public class TextFields extends TestBase { return null; } + @Override protected List createActions() { ArrayList actions = new ArrayList(); @@ -145,54 +135,4 @@ public class TextFields extends TestBase { return actions; } - protected void setRequired(boolean on) { - - for (TextField tf : textFields) { - if (tf == null) { - continue; - } - - tf.setRequired(on); - } - - } - - protected void setErrorIndicators(boolean on) { - for (TextField tf : textFields) { - if (tf == null) { - continue; - } - - if (on) { - tf.setComponentError(new UserError("It failed!")); - } else { - tf.setComponentError(null); - - } - } - - } - - protected void setEnabled(boolean on) { - for (TextField tf : textFields) { - if (tf == null) { - continue; - } - - tf.setEnabled(on); - } - - } - - protected void setReadOnly(boolean on) { - for (TextField tf : textFields) { - if (tf == null) { - continue; - } - - tf.setReadOnly(on); - } - - } - } -- 2.39.5