1
0
mirror of https://github.com/arduino/Arduino.git synced 2024-12-01 12:24:14 +01:00

first functional test made with FEST: simulation of user interaction with the IDE

found and solved a bug with caret positioning with a cleared editor (see #1288)
This commit is contained in:
Federico Fissore 2013-02-20 09:36:33 +01:00
parent 271a2c53d4
commit e399b1e50a
2 changed files with 74 additions and 1 deletions

View File

@ -232,6 +232,7 @@ public class Editor extends JFrame implements RunnerListener {
upper.add(header);
textarea = new JEditTextArea(new PdeTextAreaDefaults());
textarea.setName("editor");
textarea.setRightClickPopup(new TextAreaPopup());
textarea.setHorizontalOffset(6);
@ -1135,9 +1136,11 @@ public class Editor extends JFrame implements RunnerListener {
protected JMenu buildEditMenu() {
JMenu menu = new JMenu(_("Edit"));
menu.setName("menuEdit");
JMenuItem item;
undoItem = newJMenuItem(_("Undo"), 'Z');
undoItem.setName("menuEditUndo");
undoItem.addActionListener(undoAction = new UndoAction());
menu.add(undoItem);
@ -1146,6 +1149,7 @@ public class Editor extends JFrame implements RunnerListener {
} else {
redoItem = newJMenuItemShift(_("Redo"), 'Z');
}
redoItem.setName("menuEditRedo");
redoItem.addActionListener(redoAction = new RedoAction());
menu.add(redoItem);
@ -1345,7 +1349,10 @@ public class Editor extends JFrame implements RunnerListener {
}
if (undo.getLastUndoableEdit() != null && undo.getLastUndoableEdit() instanceof CaretAwareUndoableEdit) {
CaretAwareUndoableEdit undoableEdit = (CaretAwareUndoableEdit) undo.getLastUndoableEdit();
textarea.setCaretPosition(undoableEdit.getCaretPosition() - 1);
int nextCaretPosition = undoableEdit.getCaretPosition() - 1;
if (nextCaretPosition >= 0 && textarea.getDocumentLength() > nextCaretPosition) {
textarea.setCaretPosition(nextCaretPosition);
}
}
updateUndoState();
redoAction.updateRedoState();

View File

@ -0,0 +1,66 @@
package processing.app;
import org.fest.swing.core.ComponentMatcher;
import org.fest.swing.fixture.FrameFixture;
import org.fest.swing.fixture.JMenuItemFixture;
import org.junit.Before;
import org.junit.Test;
import processing.app.syntax.JEditTextArea;
import javax.swing.*;
import java.awt.*;
import static org.junit.Assert.assertEquals;
public class ReplacingTextGeneratesTwoUndoActionsTest {
private FrameFixture window;
private Base base;
@Before
public void setUp() throws Exception {
Base.initPlatform();
Preferences.init(null);
JPopupMenu.setDefaultLightWeightPopupEnabled(false);
Theme.init();
Base.platform.setLookAndFeel();
Base.untitledFolder = Base.createTempFolder("untitled");
Base.untitledFolder.deleteOnExit();
base = new Base(new String[0]);
window = new FrameFixture(base.editors.get(0));
}
@Test
public void testName() throws Exception {
JMenuItemFixture menuEditUndo = window.menuItem("menuEditUndo");
menuEditUndo.requireDisabled();
JMenuItemFixture menuEditRedo = window.menuItem("menuEditRedo");
menuEditRedo.requireDisabled();
JEditTextArea jEditTextArea = (JEditTextArea) window.robot.finder().find(new ComponentMatcher() {
@Override
public boolean matches(Component component) {
return component instanceof JEditTextArea && "editor".equals(component.getName());
}
});
jEditTextArea.setText("fake text");
menuEditUndo.requireEnabled();
menuEditUndo.click();
assertEquals("", jEditTextArea.getText());
menuEditRedo.requireEnabled();
menuEditRedo.click();
assertEquals("fake text", jEditTextArea.getText());
menuEditUndo.requireEnabled();
menuEditUndo.click();
menuEditUndo.click();
menuEditUndo.requireDisabled();
menuEditRedo.requireEnabled();
}
}