From a91f7ddca1dbe0b039859f6581e750df9a96e898 Mon Sep 17 00:00:00 2001 From: Artur Signell Date: Tue, 7 Dec 2010 13:44:20 +0000 Subject: Updated tests to be consistent with AbstractTextField hierarchy (#3752) svn changeset:16363/svn branch:6.5 --- .../abstractfield/AbstractTextFieldTest.java | 180 ++++++++++++++++++++- .../tests/components/textarea/TextAreaTest.java | 177 +------------------- .../components/textfield/TextFieldMaxLength.html | 7 +- .../textfield/TextFieldNullRepresentation.html | 3 +- .../TextFieldNullRepresentationAndSelection.html | 5 +- .../tests/components/textfield/TextFieldTest.java | 174 -------------------- 6 files changed, 186 insertions(+), 360 deletions(-) (limited to 'tests') diff --git a/tests/src/com/vaadin/tests/components/abstractfield/AbstractTextFieldTest.java b/tests/src/com/vaadin/tests/components/abstractfield/AbstractTextFieldTest.java index 848a7d5c90..eb9adef8d2 100644 --- a/tests/src/com/vaadin/tests/components/abstractfield/AbstractTextFieldTest.java +++ b/tests/src/com/vaadin/tests/components/abstractfield/AbstractTextFieldTest.java @@ -1,11 +1,16 @@ package com.vaadin.tests.components.abstractfield; +import java.util.ArrayList; import java.util.LinkedHashMap; +import java.util.List; +import com.vaadin.event.FieldEvents.TextChangeEvent; +import com.vaadin.event.FieldEvents.TextChangeListener; import com.vaadin.ui.AbstractTextField; +import com.vaadin.ui.AbstractTextField.TextChangeEventMode; public abstract class AbstractTextFieldTest - extends AbstractFieldTest { + extends AbstractFieldTest implements TextChangeListener { private Command maxlengthCommand = new Command() { @@ -27,6 +32,60 @@ public abstract class AbstractTextFieldTest } }; + private Command inputPromptCommand = new Command() { + public void execute(T c, String value, Object data) { + c.setInputPrompt(value); + } + }; + + private Command textChangeListenerCommand = new Command() { + public void execute(T c, Boolean value, Object data) { + if (value) { + c.addListener((TextChangeListener) AbstractTextFieldTest.this); + } else { + c.removeListener((TextChangeListener) AbstractTextFieldTest.this); + } + } + }; + + private Command colsCommand = new Command() { + public void execute(T c, Integer value, Object data) { + c.setColumns(value); + } + }; + + private Command textChangeEventModeCommand = new Command() { + public void execute(T c, TextChangeEventMode value, Object data) { + c.setTextChangeEventMode(value); + } + }; + + private Command textChangeTimeoutCommand = new Command() { + public void execute(T c, Integer value, Object data) { + c.setTextChangeTimeout(value); + } + }; + + private Command selectionRangeCommand = new Command() { + public void execute(T c, Range value, Object data) { + c.setSelectionRange(value.getStart(), + value.getEnd() - value.getStart()); + + } + }; + private Command selectAllCommand = new Command() { + public void execute(T c, Object value, Object data) { + c.selectAll(); + } + }; + + private Command setCursorPositionCommand = new Command() { + + public void execute(T c, Integer value, Object data) { + c.setCursorPosition(value); + } + }; + @Override protected void createActions() { super.createActions(); @@ -36,6 +95,18 @@ public abstract class AbstractTextFieldTest createNullSettingAllowedAction(CATEGORY_FEATURES); createNullRepresentationAction(CATEGORY_FEATURES); createMaxLengthAction(CATEGORY_FEATURES); + + createInputPromptAction(CATEGORY_FEATURES); + createColsAction(CATEGORY_STATE); + + createTextChangeListener(CATEGORY_LISTENERS); + createTextChangeEventModeAction(CATEGORY_FEATURES); + createTextChangeEventTimeoutAction(CATEGORY_FEATURES); + + createSetTextValueAction(CATEGORY_ACTIONS); + createCursorPositionAction(CATEGORY_ACTIONS); + createSelectionRangeAction(CATEGORY_ACTIONS); + } private void createNullSettingAllowedAction(String category) { @@ -60,4 +131,111 @@ public abstract class AbstractTextFieldTest maxlengthCommand); } + + public class Range { + private int start; + private int end; + + public Range(int start, int end) { + this.start = start; + this.end = end; + } + + public int getStart() { + return start; + } + + public int getEnd() { + return end; + } + + @Override + public String toString() { + return start + "-" + end; + } + } + + private void createSelectionRangeAction(String category) { + List options = new ArrayList(); + options.add(new Range(0, 10)); + options.add(new Range(0, 1)); + options.add(new Range(0, 2)); + options.add(new Range(1, 2)); + options.add(new Range(2, 5)); + options.add(new Range(5, 10)); + + createCategory("Select range", category); + + createClickAction("All", "Select range", selectAllCommand, null); + for (Range range : options) { + createClickAction(range.toString(), "Select range", + selectionRangeCommand, range); + } + + } + + private void createCursorPositionAction(String category) { + String subCategory = "Set cursor position"; + createCategory(subCategory, category); + for (int i = 0; i < 20; i++) { + createClickAction(String.valueOf(i), subCategory, + setCursorPositionCommand, Integer.valueOf(i)); + } + + } + + private void createTextChangeEventTimeoutAction(String category) { + LinkedHashMap options = new LinkedHashMap(); + options.put("0", 0); + options.put("100ms", 100); + options.put("500ms", 500); + options.put("1s", 1000); + options.put("2s", 2000); + options.put("5s", 5000); + + createSelectAction("TextChange timeout", category, options, "0", + textChangeTimeoutCommand); + } + + private void createTextChangeEventModeAction(String category) { + LinkedHashMap options = new LinkedHashMap(); + for (TextChangeEventMode m : TextChangeEventMode.values()) { + options.put(m.toString(), m); + } + + createSelectAction("TextChange event mode", category, options, + TextChangeEventMode.EAGER.toString(), + textChangeEventModeCommand); + + } + + private void createTextChangeListener(String category) { + createBooleanAction("Text change listener", category, false, + textChangeListenerCommand); + + } + + private void createColsAction(String category) { + LinkedHashMap options = createIntegerOptions(20); + createSelectAction("Columns", category, options, "0", colsCommand); + } + + private void createInputPromptAction(String category) { + LinkedHashMap options = new LinkedHashMap(); + options.put("-", null); + options.put("Enter a value", "Enter a value"); + options.put("- Click here -", "- Click here -"); + createSelectAction("Input prompt", category, options, "-", + inputPromptCommand); + + } + + public void textChange(TextChangeEvent event) { + AbstractTextField tf = (AbstractTextField) event.getComponent(); + log("TextChangeEvent: text='" + event.getText() + "', cursor position=" + + event.getCursorPosition() + " (field cursor pos: " + + tf.getCursorPosition() + ")"); + + } + } diff --git a/tests/src/com/vaadin/tests/components/textarea/TextAreaTest.java b/tests/src/com/vaadin/tests/components/textarea/TextAreaTest.java index 1977067a19..546a1bee32 100644 --- a/tests/src/com/vaadin/tests/components/textarea/TextAreaTest.java +++ b/tests/src/com/vaadin/tests/components/textarea/TextAreaTest.java @@ -1,17 +1,11 @@ package com.vaadin.tests.components.textarea; -import java.util.ArrayList; import java.util.LinkedHashMap; -import java.util.List; -import com.vaadin.event.FieldEvents.TextChangeEvent; -import com.vaadin.event.FieldEvents.TextChangeListener; import com.vaadin.tests.components.abstractfield.AbstractTextFieldTest; -import com.vaadin.ui.AbstractTextField.TextChangeEventMode; import com.vaadin.ui.TextArea; -public class TextAreaTest extends AbstractTextFieldTest