|
@@ -23,43 +23,39 @@
|
23
|
23
|
package com.dmdirc.addons.ui_swing.components.frames;
|
24
|
24
|
|
25
|
25
|
import com.dmdirc.Main;
|
|
26
|
+import com.dmdirc.WritableFrameContainer;
|
|
27
|
+import com.dmdirc.addons.ui_swing.ClassComponentMatcher;
|
|
28
|
+import com.dmdirc.addons.ui_swing.MainFrame;
|
26
|
29
|
import com.dmdirc.config.ConfigManager;
|
27
|
30
|
import com.dmdirc.config.IdentityManager;
|
28
|
31
|
import com.dmdirc.config.InvalidIdentityFileException;
|
29
|
|
-import com.dmdirc.harness.TestConfigManagerMap;
|
30
|
|
-import com.dmdirc.harness.TestWritableFrameContainer;
|
31
|
|
-import com.dmdirc.harness.ui.ClassFinder;
|
32
|
|
-import com.dmdirc.ui.WindowManager;
|
33
|
32
|
import com.dmdirc.addons.ui_swing.SwingController;
|
34
|
|
-import com.dmdirc.addons.ui_swing.UIUtilities;
|
|
33
|
+import com.dmdirc.addons.ui_swing.SwingWindowFactory;
|
35
|
34
|
import com.dmdirc.addons.ui_swing.components.TextAreaInputField;
|
36
|
35
|
import com.dmdirc.plugins.PluginManager;
|
37
|
|
-import com.dmdirc.ui.interfaces.InputWindow;
|
|
36
|
+import com.dmdirc.ui.messages.IRCDocument;
|
38
|
37
|
|
39
|
|
-import java.awt.event.KeyEvent;
|
40
|
38
|
|
41
|
|
-import org.fest.swing.core.KeyPressInfo;
|
42
|
|
-import org.fest.swing.core.matcher.DialogMatcher;
|
43
|
|
-import org.fest.swing.core.matcher.JButtonMatcher;
|
44
|
|
-import org.fest.swing.fixture.DialogFixture;
|
45
|
|
-import org.fest.swing.fixture.FrameFixture;
|
46
|
|
-import org.fest.swing.fixture.JInternalFrameFixture;
|
47
|
39
|
import org.junit.After;
|
48
|
40
|
import org.junit.Before;
|
49
|
|
-import org.junit.BeforeClass;
|
50
|
41
|
import org.junit.Test;
|
51
|
|
-
|
52
|
|
-public class InputTextFrameTest {
|
53
|
|
-
|
54
|
|
- static FrameFixture mainframe;
|
55
|
|
- static JInternalFrameFixture window;
|
56
|
|
- static TestConfigManagerMap cmmap;
|
57
|
|
- static TestWritableFrameContainer<InputWindow> owner;
|
58
|
|
- static SwingController controller;
|
59
|
|
-
|
60
|
|
- @BeforeClass
|
61
|
|
- public static void setUpClass() throws InvalidIdentityFileException {
|
62
|
|
- IdentityManager.load();
|
|
42
|
+import org.uispec4j.Trigger;
|
|
43
|
+import org.uispec4j.UISpecTestCase;
|
|
44
|
+import org.uispec4j.Window;
|
|
45
|
+import org.uispec4j.interception.WindowInterceptor;
|
|
46
|
+import static org.mockito.Mockito.*;
|
|
47
|
+
|
|
48
|
+public class InputTextFrameTest extends UISpecTestCase {
|
|
49
|
+
|
|
50
|
+ static InputTextFrame tf;
|
|
51
|
+ static String text;
|
|
52
|
+
|
|
53
|
+ static {
|
|
54
|
+ try {
|
|
55
|
+ IdentityManager.load();
|
|
56
|
+ } catch (InvalidIdentityFileException ex) {
|
|
57
|
+ //Ignore
|
|
58
|
+ }
|
63
|
59
|
IdentityManager.getAddonIdentity().setOption("test", "windowMenuItems",
|
64
|
60
|
"1");
|
65
|
61
|
IdentityManager.getAddonIdentity().setOption("test",
|
|
@@ -69,142 +65,119 @@ public class InputTextFrameTest {
|
69
|
65
|
"textpanebackground", "");
|
70
|
66
|
IdentityManager.getAddonIdentity().setOption("test", "desktopbackground",
|
71
|
67
|
"");
|
72
|
|
- controller = new SwingController();
|
73
|
|
- controller.setDomain("test");
|
74
|
|
- controller.onLoad();
|
75
|
|
-
|
76
|
68
|
Main.ensureExists(PluginManager.getPluginManager(), "tabcompletion");
|
77
|
69
|
|
78
|
|
- UIUtilities.initUISettings();
|
79
|
|
-
|
80
|
|
- mainframe = new FrameFixture(controller.getMainWindow());
|
81
|
|
- }
|
82
|
|
-
|
83
|
|
- @Before
|
84
|
|
- public void setUp() {
|
85
|
|
- cmmap = new TestConfigManagerMap();
|
86
|
|
- cmmap.settings.put("ui.pasteProtectionLimit", "1");
|
87
|
|
-
|
88
|
|
- owner = new TestWritableFrameContainer<InputWindow>(512, cmmap,
|
89
|
|
- InputWindow.class);
|
90
|
|
- setupWindow(cmmap);
|
91
|
|
- }
|
92
|
|
-
|
93
|
|
- @After
|
94
|
|
- public void tearDown() {
|
95
|
|
- UIUtilities.invokeAndWait(new Runnable() {
|
96
|
|
-
|
97
|
|
- @Override
|
98
|
|
- public void run() {
|
99
|
|
- window.close();
|
100
|
|
- controller.getWindowFactory().getSwingWindow(owner).close();
|
101
|
|
- WindowManager.removeWindow(owner);
|
102
|
|
- }
|
103
|
|
- });
|
|
70
|
+ final IRCDocument document = mock(IRCDocument.class);
|
|
71
|
+ @SuppressWarnings("unchecked")
|
|
72
|
+ final WritableFrameContainer<CustomInputFrame> container = mock(
|
|
73
|
+ WritableFrameContainer.class);
|
|
74
|
+ final ConfigManager config = mock(ConfigManager.class);
|
|
75
|
+ when(container.getDocument()).thenReturn(document);
|
|
76
|
+ when(container.getConfigManager()).thenReturn(config);
|
|
77
|
+ when(config.getOption(anyString(), anyString())).thenReturn("mirc");
|
|
78
|
+ final SwingController controller = mock(SwingController.class);
|
|
79
|
+ when(controller.getDomain()).thenReturn("test");
|
|
80
|
+ final SwingWindowFactory wf = new SwingWindowFactory(controller);
|
|
81
|
+ when(controller.getWindowFactory()).thenReturn(wf);
|
|
82
|
+ final MainFrame mainFrame = new MainFrame(controller);
|
|
83
|
+ when(controller.getMainFrame()).thenReturn(mainFrame);
|
|
84
|
+
|
|
85
|
+ tf = new CustomInputFrame(controller, container);
|
|
86
|
+ text = "line1\nline2";
|
104
|
87
|
}
|
105
|
88
|
|
106
|
89
|
@Test
|
107
|
90
|
public void testPasteDialogContents() throws InterruptedException {
|
108
|
|
- UIUtilities.invokeAndWait(new Runnable() {
|
109
|
|
-
|
110
|
|
- @Override
|
111
|
|
- public void run() {
|
112
|
|
- ((InputTextFrame) window.target).doPaste("line1\nline2");
|
113
|
|
-
|
114
|
|
- final DialogFixture dlg = mainframe.dialog(DialogMatcher.
|
115
|
|
- withTitle(
|
116
|
|
- "DMDirc: Multi-line paste").andShowing());
|
117
|
|
-
|
118
|
|
- dlg.requireVisible().button(JButtonMatcher.withText("Edit")).
|
119
|
|
- click();
|
120
|
|
- dlg.textBox(new ClassFinder<TextAreaInputField>(
|
121
|
|
- TextAreaInputField.class,
|
122
|
|
- null)).requireText("line1\nline2");
|
123
|
|
- dlg.target.dispose();
|
124
|
|
- }
|
125
|
|
- });
|
|
91
|
+ final Window dialog = getDialog();
|
|
92
|
+ dialog.titleEquals("DMDirc: Multi-line paste").check();
|
|
93
|
+ dialog.getButton("Edit").click();
|
|
94
|
+ assertTrue(dialog.getTextBox(new ClassComponentMatcher(dialog,
|
|
95
|
+ TextAreaInputField.class)).getText().equals(text));
|
126
|
96
|
}
|
127
|
97
|
|
128
|
98
|
@Test
|
129
|
99
|
public void testPasteDialogWithTextBefore() throws InterruptedException {
|
130
|
|
- UIUtilities.invokeAndWait(new Runnable() {
|
131
|
|
-
|
132
|
|
- @Override
|
133
|
|
- public void run() {
|
134
|
|
- window.textBox().enterText("testing:");
|
135
|
|
- ((InputTextFrame) window.target).doPaste("line1\nline2");
|
136
|
|
-
|
137
|
|
- final DialogFixture dlg = mainframe.dialog(DialogMatcher.
|
138
|
|
- withTitle("DMDirc: Multi-line paste").andShowing());
|
139
|
|
-
|
140
|
|
- dlg.requireVisible().button(JButtonMatcher.withText("Edit")).
|
141
|
|
- click();
|
142
|
|
- dlg.textBox(new ClassFinder<TextAreaInputField>(
|
143
|
|
- TextAreaInputField.class, null)).requireText(
|
144
|
|
- "testing:line1\nline2");
|
145
|
|
- dlg.target.dispose();
|
146
|
|
- }
|
147
|
|
- });
|
|
100
|
+ tf.getInputField().setText("testing:");
|
|
101
|
+ final Window dialog = getDialog();
|
|
102
|
+ dialog.titleEquals("DMDirc: Multi-line paste").check();
|
|
103
|
+ dialog.getButton("Edit").click();
|
|
104
|
+ assertTrue(dialog.getTextBox(new ClassComponentMatcher(dialog,
|
|
105
|
+ TextAreaInputField.class)).getText().equals("testing:" + text));
|
148
|
106
|
}
|
149
|
107
|
|
150
|
108
|
@Test
|
151
|
109
|
public void testPasteDialogWithTextAfter() throws InterruptedException {
|
152
|
|
- UIUtilities.invokeAndWait(new Runnable() {
|
153
|
|
-
|
154
|
|
- @Override
|
155
|
|
- public void run() {
|
156
|
|
- window.textBox().enterText("<- testing").pressAndReleaseKey(
|
157
|
|
- KeyPressInfo.keyCode(KeyEvent.VK_HOME));
|
158
|
|
- ((InputTextFrame) window.target).doPaste("line1\nline2");
|
159
|
|
-
|
160
|
|
- final DialogFixture dlg = mainframe.dialog(DialogMatcher.
|
161
|
|
- withTitle(
|
162
|
|
- "DMDirc: Multi-line paste").andShowing());
|
163
|
|
-
|
164
|
|
- dlg.requireVisible().button(JButtonMatcher.withText("Edit")).
|
165
|
|
- click();
|
166
|
|
- dlg.textBox(new ClassFinder<TextAreaInputField>(
|
167
|
|
- TextAreaInputField.class,
|
168
|
|
- null)).requireText("line1\nline2<- testing");
|
169
|
|
- dlg.target.dispose();
|
170
|
|
- }
|
171
|
|
- });
|
|
110
|
+ tf.getInputField().setText(":testing");
|
|
111
|
+ tf.getInputField().setCaretPosition(0);
|
|
112
|
+ final Window dialog = getDialog();
|
|
113
|
+ dialog.titleEquals("DMDirc: Multi-line paste").check();
|
|
114
|
+ dialog.getButton("Edit").click();
|
|
115
|
+ assertTrue(dialog.getTextBox(new ClassComponentMatcher(dialog,
|
|
116
|
+ TextAreaInputField.class)).getText().equals(text + ":testing"));
|
172
|
117
|
}
|
173
|
118
|
|
174
|
119
|
@Test
|
175
|
120
|
public void testPasteDialogWithTextAround() throws InterruptedException {
|
176
|
|
- UIUtilities.invokeAndWait(new Runnable() {
|
177
|
|
-
|
178
|
|
- @Override
|
179
|
|
- public void run() {
|
180
|
|
- window.textBox().enterText("testing:<- testing").selectText(8, 8);
|
181
|
|
- ((InputTextFrame) window.target).doPaste("line1\nline2");
|
182
|
|
-
|
183
|
|
- final DialogFixture dlg = mainframe.dialog(DialogMatcher.
|
184
|
|
- withTitle(
|
185
|
|
- "DMDirc: Multi-line paste").andShowing());
|
186
|
|
-
|
187
|
|
- dlg.requireVisible().button(JButtonMatcher.withText("Edit")).
|
188
|
|
- click();
|
189
|
|
- dlg.textBox(new ClassFinder<TextAreaInputField>(
|
190
|
|
- TextAreaInputField.class,
|
191
|
|
- null)).requireText("testing:line1\nline2<- testing");
|
192
|
|
- dlg.target.dispose();
|
193
|
|
- }
|
194
|
|
- });
|
|
121
|
+ tf.getInputField().setText("testing::testing");
|
|
122
|
+ tf.getInputField().setCaretPosition(8);
|
|
123
|
+ final Window dialog = getDialog();
|
|
124
|
+ dialog.titleEquals("DMDirc: Multi-line paste").check();
|
|
125
|
+ dialog.getButton("Edit").click();
|
|
126
|
+ assertEquals("testing:" + text + ":testing",
|
|
127
|
+ dialog.getTextBox(new ClassComponentMatcher(dialog,
|
|
128
|
+ TextAreaInputField.class)).getText());
|
195
|
129
|
}
|
196
|
130
|
|
197
|
|
- protected void setupWindow(final ConfigManager configManager) {
|
198
|
|
- final CustomInputFrame titf = new CustomInputFrame(controller, owner);
|
199
|
|
-
|
200
|
|
- owner.setTitle("testing123");
|
201
|
|
- owner.addWindow(titf);
|
202
|
|
-
|
203
|
|
- WindowManager.addWindow(owner);
|
|
131
|
+ @Test
|
|
132
|
+ public void testPasteDialogWithSelection() {
|
|
133
|
+ tf.getInputField().setText("testing:SELECTED:testing");
|
|
134
|
+ tf.getInputField().setSelectionStart(8);
|
|
135
|
+ tf.getInputField().setSelectionEnd(16);
|
|
136
|
+ final Window dialog = getDialog();
|
|
137
|
+ dialog.titleEquals("DMDirc: Multi-line paste").check();
|
|
138
|
+ dialog.getButton("Edit").click();
|
|
139
|
+ assertEquals("testing:" + text + ":testing",
|
|
140
|
+ dialog.getTextBox(new ClassComponentMatcher(dialog,
|
|
141
|
+ TextAreaInputField.class)).getText());
|
|
142
|
+ }
|
204
|
143
|
|
205
|
|
- titf.open();
|
|
144
|
+ /**
|
|
145
|
+ * Creates a new paste dialog with the specified text for the specified
|
|
146
|
+ * frame.
|
|
147
|
+ *
|
|
148
|
+ * @param frame Parent frame
|
|
149
|
+ * @param text Text to "paste"
|
|
150
|
+ *
|
|
151
|
+ * @return Wrapped Dialog
|
|
152
|
+ */
|
|
153
|
+ private Window getDialog() {
|
|
154
|
+ return WindowInterceptor.run(new PasteDialogTrigger(tf, text));
|
|
155
|
+ }
|
206
|
156
|
|
207
|
|
- window = new JInternalFrameFixture(mainframe.robot, titf);
|
208
|
|
- window.robot.settings().eventPostingDelay(250);
|
|
157
|
+ /**
|
|
158
|
+ * Creates a new paste dialog for the specified frame with the specified text.
|
|
159
|
+ */
|
|
160
|
+ private class PasteDialogTrigger implements Trigger {
|
|
161
|
+
|
|
162
|
+ private InputTextFrame frame;
|
|
163
|
+ private String text;
|
|
164
|
+
|
|
165
|
+ /**
|
|
166
|
+ * Creates a new paste dialog for the specified frame with the specified text.
|
|
167
|
+ *
|
|
168
|
+ * @param frame Parent frame
|
|
169
|
+ * @param text Text to "paste"
|
|
170
|
+ */
|
|
171
|
+ public PasteDialogTrigger(final InputTextFrame frame, final String text) {
|
|
172
|
+ this.frame = frame;
|
|
173
|
+ this.text = text;
|
|
174
|
+ }
|
|
175
|
+
|
|
176
|
+ /** {@inheritDoc} */
|
|
177
|
+ @Override
|
|
178
|
+ public void run() throws Exception {
|
|
179
|
+ frame.doPaste(text);
|
|
180
|
+ }
|
209
|
181
|
}
|
|
182
|
+
|
210
|
183
|
}
|