You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

InputTextFrameTest.java 5.1KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138
  1. /*
  2. * Copyright (c) 2006-2011 Chris Smith, Shane Mc Cormack, Gregory Holmes
  3. *
  4. * Permission is hereby granted, free of charge, to any person obtaining a copy
  5. * of this software and associated documentation files (the "Software"), to deal
  6. * in the Software without restriction, including without limitation the rights
  7. * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
  8. * copies of the Software, and to permit persons to whom the Software is
  9. * furnished to do so, subject to the following conditions:
  10. *
  11. * The above copyright notice and this permission notice shall be included in
  12. * all copies or substantial portions of the Software.
  13. *
  14. * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  15. * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  16. * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  17. * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  18. * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
  19. * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
  20. * SOFTWARE.
  21. */
  22. package com.dmdirc.addons.ui_swing.components.frames;
  23. import com.dmdirc.harness.ui.ClassComponentMatcher;
  24. import com.dmdirc.harness.ui.DMDircUITestCase;
  25. import com.dmdirc.addons.ui_swing.components.inputfields.TextAreaInputField;
  26. import org.junit.Test;
  27. import org.uispec4j.Trigger;
  28. import org.uispec4j.Window;
  29. import org.uispec4j.interception.WindowInterceptor;
  30. public class InputTextFrameTest extends DMDircUITestCase {
  31. static InputTextFrame tf;
  32. static String text;
  33. static {
  34. tf = new CustomInputFrame(getMockedControllerAndMainFrame(),
  35. getMockedContainer());
  36. text = "line1\nline2";
  37. }
  38. @Test
  39. public void testPasteDialogContents() throws InterruptedException {
  40. final Window dialog = getDialog();
  41. dialog.titleEquals("DMDirc: Multi-line paste").check();
  42. dialog.getButton("Edit").click();
  43. assertTrue(dialog.getTextBox(new ClassComponentMatcher(
  44. TextAreaInputField.class)).getText().equals(text));
  45. }
  46. @Test
  47. public void testPasteDialogWithTextBefore() throws InterruptedException {
  48. tf.getInputField().setText("testing:");
  49. final Window dialog = getDialog();
  50. dialog.titleEquals("DMDirc: Multi-line paste").check();
  51. dialog.getButton("Edit").click();
  52. assertTrue(dialog.getTextBox(new ClassComponentMatcher(
  53. TextAreaInputField.class)).getText().equals("testing:" + text));
  54. }
  55. @Test
  56. public void testPasteDialogWithTextAfter() throws InterruptedException {
  57. tf.getInputField().setText(":testing");
  58. tf.getInputField().setCaretPosition(0);
  59. final Window dialog = getDialog();
  60. dialog.titleEquals("DMDirc: Multi-line paste").check();
  61. dialog.getButton("Edit").click();
  62. assertTrue(dialog.getTextBox(new ClassComponentMatcher(
  63. TextAreaInputField.class)).getText().equals(text + ":testing"));
  64. }
  65. @Test
  66. public void testPasteDialogWithTextAround() throws InterruptedException {
  67. tf.getInputField().setText("testing::testing");
  68. tf.getInputField().setCaretPosition(8);
  69. final Window dialog = getDialog();
  70. dialog.titleEquals("DMDirc: Multi-line paste").check();
  71. dialog.getButton("Edit").click();
  72. assertEquals("testing:" + text + ":testing",
  73. dialog.getTextBox(new ClassComponentMatcher(
  74. TextAreaInputField.class)).getText());
  75. }
  76. @Test
  77. public void testPasteDialogWithSelection() {
  78. tf.getInputField().setText("testing:SELECTED:testing");
  79. tf.getInputField().setSelectionStart(8);
  80. tf.getInputField().setSelectionEnd(16);
  81. final Window dialog = getDialog();
  82. dialog.titleEquals("DMDirc: Multi-line paste").check();
  83. dialog.getButton("Edit").click();
  84. assertEquals("testing:" + text + ":testing",
  85. dialog.getTextBox(new ClassComponentMatcher(
  86. TextAreaInputField.class)).getText());
  87. }
  88. /**
  89. * Creates a new paste dialog with the specified text for the specified
  90. * frame.
  91. *
  92. * @param frame Parent frame
  93. * @param text Text to "paste"
  94. *
  95. * @return Wrapped Dialog
  96. */
  97. private Window getDialog() {
  98. return WindowInterceptor.run(new PasteDialogTrigger(tf, text));
  99. }
  100. /**
  101. * Creates a new paste dialog for the specified frame with the specified text.
  102. */
  103. private static class PasteDialogTrigger implements Trigger {
  104. private InputTextFrame frame;
  105. private String text;
  106. /**
  107. * Creates a new paste dialog for the specified frame with the specified text.
  108. *
  109. * @param frame Parent frame
  110. * @param text Text to "paste"
  111. */
  112. public PasteDialogTrigger(final InputTextFrame frame, final String text) {
  113. this.frame = frame;
  114. this.text = text;
  115. }
  116. /** {@inheritDoc} */
  117. @Override
  118. public void run() throws Exception {
  119. frame.doPaste(text);
  120. }
  121. }
  122. }