From 0f2f194da921ad387159d1e0c740103c67e2b4ee Mon Sep 17 00:00:00 2001 From: Jordan Martinez Date: Sat, 30 Sep 2017 08:42:00 -0700 Subject: [PATCH 01/23] Move SingleLineTests into (new) navigation package --- .../richtext/keyboard/NavigationTests.java | 182 --------------- .../keyboard/navigation/SingleLineTests.java | 220 ++++++++++++++++++ .../richtext/keyboard/navigation/Utils.java | 32 +++ 3 files changed, 252 insertions(+), 182 deletions(-) create mode 100644 richtextfx/src/integrationTest/java/org/fxmisc/richtext/keyboard/navigation/SingleLineTests.java create mode 100644 richtextfx/src/integrationTest/java/org/fxmisc/richtext/keyboard/navigation/Utils.java diff --git a/richtextfx/src/integrationTest/java/org/fxmisc/richtext/keyboard/NavigationTests.java b/richtextfx/src/integrationTest/java/org/fxmisc/richtext/keyboard/NavigationTests.java index ae2b67413..56baf5dbf 100644 --- a/richtextfx/src/integrationTest/java/org/fxmisc/richtext/keyboard/NavigationTests.java +++ b/richtextfx/src/integrationTest/java/org/fxmisc/richtext/keyboard/NavigationTests.java @@ -43,188 +43,6 @@ private int entityEnd(int entityIndex, String[] array, GenericStyledArea a + b) + + entityIndex; // for delimiter characters + } + } + + public static int entityEnd(int entityIndex, String[] array, GenericStyledArea area) { + if (entityIndex == array.length - 1) { + return area.getLength(); + } else { + return entityStart(entityIndex + 1, array) - 1; + } + } +} From e2c0e9a7a67ad2d8f3c85bb66daf299026714778 Mon Sep 17 00:00:00 2001 From: Jordan Martinez Date: Sat, 30 Sep 2017 09:18:00 -0700 Subject: [PATCH 02/23] Move MultiLineGridlikeTextTests into navigation package --- .../richtext/keyboard/NavigationTests.java | 271 ---------------- .../MultiLineGridlikeTextTests.java | 296 ++++++++++++++++++ 2 files changed, 296 insertions(+), 271 deletions(-) create mode 100644 richtextfx/src/integrationTest/java/org/fxmisc/richtext/keyboard/navigation/MultiLineGridlikeTextTests.java diff --git a/richtextfx/src/integrationTest/java/org/fxmisc/richtext/keyboard/NavigationTests.java b/richtextfx/src/integrationTest/java/org/fxmisc/richtext/keyboard/NavigationTests.java index 56baf5dbf..1d574f048 100644 --- a/richtextfx/src/integrationTest/java/org/fxmisc/richtext/keyboard/NavigationTests.java +++ b/richtextfx/src/integrationTest/java/org/fxmisc/richtext/keyboard/NavigationTests.java @@ -43,277 +43,6 @@ private int entityEnd(int entityIndex, String[] array, GenericStyledArea textFlowIsReady = WaitForAsyncUtils.asyncFx(() -> { - while (area.getParagraphLinesCount(0) != lines.length) { - sleep(10); - } - }); - WaitForAsyncUtils.waitFor(5, TimeUnit.SECONDS, textFlowIsReady); - } - - @Override - public void start(Stage stage) throws Exception { - super.start(stage); - area.setWrapText(true); - area.replaceText(fullText); - - // insures area's text appears exactly as the declaration of `lines` - stage.setWidth(150); - area.setStyle( - "-fx-font-family: monospace;" + - "-fx-font-size: 12pt;" - ); - } - - public class NoModifiers { - - @Before - public void setup() throws TimeoutException { - waitForMultiLineRegistration(); - } - - @Test - public void up() { - moveCaretTo(lineStart(2)); - assertTrue(area.getSelectedText().isEmpty()); - - type(UP); - - assertEquals(lineStart(1), area.getCaretPosition()); - assertTrue(area.getSelectedText().isEmpty()); - } - - @Test - public void down() { - moveCaretTo(lineStart(1)); - assertTrue(area.getSelectedText().isEmpty()); - - type(DOWN); - - assertEquals(lineStart(2), area.getCaretPosition()); - assertTrue(area.getSelectedText().isEmpty()); - } - - @Test - public void home() { - moveCaretTo(lineEnd(1)); - assertTrue(area.getSelectedText().isEmpty()); - - type(HOME); - - assertEquals(lineStart(1), area.getCaretPosition()); - assertTrue(area.getSelectedText().isEmpty()); - } - - @Test - public void end() { - moveCaretTo(lineStart(1)); - assertTrue(area.getSelectedText().isEmpty()); - - type(END); - - assertEquals(lineEnd(1), area.getCaretPosition()); - assertTrue(area.getSelectedText().isEmpty()); - } - - } - - public class ShortcutDown { - - @Before - public void setup() throws TimeoutException { - waitForMultiLineRegistration(); - - press(SHORTCUT); - } - - // up/down do nothing - @Test - public void up() { - assertTrue(area.getSelectedText().isEmpty()); - moveCaretTo(lineStart(2)); - - type(UP); - - assertEquals(lineStart(2), area.getCaretPosition()); - assertTrue(area.getSelectedText().isEmpty()); - } - - @Test - public void down() { - assertTrue(area.getSelectedText().isEmpty()); - moveCaretTo(lineStart(2)); - - type(DOWN); - - assertEquals(lineStart(2), area.getCaretPosition()); - assertTrue(area.getSelectedText().isEmpty()); - } - - @Test - public void home() { - moveCaretTo(lineStart(2)); - assertTrue(area.getSelectedText().isEmpty()); - - type(HOME); - - assertEquals(0, area.getCaretPosition()); - assertTrue(area.getSelectedText().isEmpty()); - } - - @Test - public void end() { - moveCaretTo(lineStart(1)); - assertTrue(area.getSelectedText().isEmpty()); - - type(END); - - assertEquals(area.getLength(), area.getCaretPosition()); - assertTrue(area.getSelectedText().isEmpty()); - } - - } - - public class ShiftDown { - - @Before - public void setup() throws TimeoutException { - waitForMultiLineRegistration(); - - press(SHIFT); - } - - @Test - public void up() { - moveCaretTo(lineStart(2)); - assertTrue(area.getSelectedText().isEmpty()); - - type(UP); - - assertEquals(lineStart(1), area.getCaretPosition()); - assertEquals(lines[1] + " ", area.getSelectedText()); - } - - @Test - public void down() { - moveCaretTo(lineStart(1)); - assertTrue(area.getSelectedText().isEmpty()); - - type(DOWN); - - assertEquals(lineStart(2), area.getCaretPosition()); - assertEquals(lines[1] + " ", area.getSelectedText()); - } - - @Test - public void home() { - moveCaretTo(lineEnd(1)); - assertTrue(area.getSelectedText().isEmpty()); - - type(HOME); - - assertEquals(lineStart(1), area.getCaretPosition()); - assertEquals(lines[1], area.getSelectedText()); - } - - @Test - public void end() { - moveCaretTo(lineStart(1)); - assertTrue(area.getSelectedText().isEmpty()); - - type(END); - - assertEquals(lineEnd(1), area.getCaretPosition()); - assertEquals(lines[1], area.getSelectedText()); - } - - } - - public class ShortcutShiftDown { - - @Before - public void setup() throws TimeoutException { - waitForMultiLineRegistration(); - - press(SHORTCUT, SHIFT); - } - - @Test - public void up() { - moveCaretTo(lineStart(2)); - assertTrue(area.getSelectedText().isEmpty()); - - type(UP); - - assertEquals(lineStart(2), area.getCaretPosition()); - assertTrue(area.getSelectedText().isEmpty()); - } - - @Test - public void down() { - moveCaretTo(lineStart(1)); - assertTrue(area.getSelectedText().isEmpty()); - - type(DOWN); - - assertEquals(lineStart(1), area.getCaretPosition()); - assertTrue(area.getSelectedText().isEmpty()); - } - - @Test - public void home() { - moveCaretTo(area.getLength()); - assertTrue(area.getSelectedText().isEmpty()); - - type(HOME); - - assertEquals(0, area.getCaretPosition()); - assertEquals(area.getText(), area.getSelectedText()); - } - - @Test - public void end() { - moveCaretTo(0); - assertTrue(area.getSelectedText().isEmpty()); - - type(END); - - assertEquals(area.getLength(), area.getCaretPosition()); - assertEquals(area.getText(), area.getSelectedText()); - } - - } - - } - public class MultiLineJaggedTextTests extends InlineCssTextAreaAppTest { String threeLinesOfText = "Some long amount of text to take up a lot of space in the given area."; diff --git a/richtextfx/src/integrationTest/java/org/fxmisc/richtext/keyboard/navigation/MultiLineGridlikeTextTests.java b/richtextfx/src/integrationTest/java/org/fxmisc/richtext/keyboard/navigation/MultiLineGridlikeTextTests.java new file mode 100644 index 000000000..08d43cc11 --- /dev/null +++ b/richtextfx/src/integrationTest/java/org/fxmisc/richtext/keyboard/navigation/MultiLineGridlikeTextTests.java @@ -0,0 +1,296 @@ +package org.fxmisc.richtext.keyboard.navigation; + +import com.nitorcreations.junit.runners.NestedRunner; +import javafx.stage.Stage; +import org.fxmisc.richtext.InlineCssTextAreaAppTest; +import org.junit.Before; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.testfx.util.WaitForAsyncUtils; + +import java.util.concurrent.Future; +import java.util.concurrent.TimeUnit; +import java.util.concurrent.TimeoutException; + +import static javafx.scene.input.KeyCode.DOWN; +import static javafx.scene.input.KeyCode.END; +import static javafx.scene.input.KeyCode.HOME; +import static javafx.scene.input.KeyCode.SHIFT; +import static javafx.scene.input.KeyCode.SHORTCUT; +import static javafx.scene.input.KeyCode.UP; +import static org.fxmisc.richtext.keyboard.navigation.Utils.entityEnd; +import static org.fxmisc.richtext.keyboard.navigation.Utils.entityStart; +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertTrue; + +@RunWith(NestedRunner.class) +public class MultiLineGridlikeTextTests extends InlineCssTextAreaAppTest { + + public final String[] lines = { + "01 02 03 04 05", + "11 12 13 14 15", + "21 22 23 24 25", + "31 32 33 34 35", + "41 42 43 44 45" + }; + + private int lineStart(int lineIndex) { + return entityStart(lineIndex, lines); + } + + private int lineEnd(int lineIndex) { + return entityEnd(lineIndex, lines, area); + } + + String fullText = String.join(" ", lines); + + private void moveCaretTo(int position) { + area.moveTo(position); + } + + private void waitForMultiLineRegistration() throws TimeoutException { + // When the stage's width changes, TextFlow does not properly handle API calls to a + // multi-line paragraph immediately. So, wait until it correctly responds + // to the stage width change + Future textFlowIsReady = WaitForAsyncUtils.asyncFx(() -> { + while (area.getParagraphLinesCount(0) != lines.length) { + sleep(10); + } + }); + WaitForAsyncUtils.waitFor(5, TimeUnit.SECONDS, textFlowIsReady); + } + + @Override + public void start(Stage stage) throws Exception { + super.start(stage); + area.setWrapText(true); + area.replaceText(fullText); + + // insures area's text appears exactly as the declaration of `lines` + stage.setWidth(150); + area.setStyle( + "-fx-font-family: monospace;" + + "-fx-font-size: 12pt;" + ); + } + + public class WhenNoModifiersPressed { + + @Before + public void setup() throws TimeoutException { + waitForMultiLineRegistration(); + } + + @Test + public void up_moves_caret_to_previous_line() { + moveCaretTo(lineStart(2)); + assertTrue(area.getSelectedText().isEmpty()); + + type(UP); + + assertEquals(lineStart(1), area.getCaretPosition()); + assertTrue(area.getSelectedText().isEmpty()); + } + + @Test + public void down_moves_caret_to_next_line() { + moveCaretTo(lineStart(1)); + assertTrue(area.getSelectedText().isEmpty()); + + type(DOWN); + + assertEquals(lineStart(2), area.getCaretPosition()); + assertTrue(area.getSelectedText().isEmpty()); + } + + @Test + public void home_moves_caret_to_start_of_current_line() { + moveCaretTo(lineEnd(1)); + assertTrue(area.getSelectedText().isEmpty()); + + type(HOME); + + assertEquals(lineStart(1), area.getCaretPosition()); + assertTrue(area.getSelectedText().isEmpty()); + } + + @Test + public void end_moves_caret_to_end_of_current_line() { + moveCaretTo(lineStart(1)); + assertTrue(area.getSelectedText().isEmpty()); + + type(END); + + assertEquals(lineEnd(1), area.getCaretPosition()); + assertTrue(area.getSelectedText().isEmpty()); + } + + } + + public class WhenShortcutIsPressed { + + @Before + public void setup() throws TimeoutException { + waitForMultiLineRegistration(); + + press(SHORTCUT); + } + + // up/down do nothing + @Test + public void up_moves_caret_to_previous_line() { + assertTrue(area.getSelectedText().isEmpty()); + moveCaretTo(lineStart(2)); + + type(UP); + + assertEquals(lineStart(2), area.getCaretPosition()); + assertTrue(area.getSelectedText().isEmpty()); + } + + @Test + public void down_moves_caret_to_next_line() { + assertTrue(area.getSelectedText().isEmpty()); + moveCaretTo(lineStart(2)); + + type(DOWN); + + assertEquals(lineStart(2), area.getCaretPosition()); + assertTrue(area.getSelectedText().isEmpty()); + } + + @Test + public void home_moves_caret_to_start_of_current_paragraph() { + moveCaretTo(lineStart(2)); + assertTrue(area.getSelectedText().isEmpty()); + + type(HOME); + + assertEquals(0, area.getCaretPosition()); + assertTrue(area.getSelectedText().isEmpty()); + } + + @Test + public void end_moves_caret_to_end_of_current_paragraph() { + moveCaretTo(lineStart(1)); + assertTrue(area.getSelectedText().isEmpty()); + + type(END); + + assertEquals(area.getLength(), area.getCaretPosition()); + assertTrue(area.getSelectedText().isEmpty()); + } + + } + + public class WhenShiftIsPressed { + + @Before + public void setup() throws TimeoutException { + waitForMultiLineRegistration(); + + press(SHIFT); + } + + @Test + public void up() { + moveCaretTo(lineStart(2)); + assertTrue(area.getSelectedText().isEmpty()); + + type(UP); + + assertEquals(lineStart(1), area.getCaretPosition()); + assertEquals(lines[1] + " ", area.getSelectedText()); + } + + @Test + public void down() { + moveCaretTo(lineStart(1)); + assertTrue(area.getSelectedText().isEmpty()); + + type(DOWN); + + assertEquals(lineStart(2), area.getCaretPosition()); + assertEquals(lines[1] + " ", area.getSelectedText()); + } + + @Test + public void home_selects_up_to_the_start_of_current_line() { + moveCaretTo(lineEnd(1)); + assertTrue(area.getSelectedText().isEmpty()); + + type(HOME); + + assertEquals(lineStart(1), area.getCaretPosition()); + assertEquals(lines[1], area.getSelectedText()); + } + + @Test + public void end_selects_up_to_the_end_of_current_line() { + moveCaretTo(lineStart(1)); + assertTrue(area.getSelectedText().isEmpty()); + + type(END); + + assertEquals(lineEnd(1), area.getCaretPosition()); + assertEquals(lines[1], area.getSelectedText()); + } + + } + + public class ShortcutShiftDown { + + @Before + public void setup() throws TimeoutException { + waitForMultiLineRegistration(); + + press(SHORTCUT, SHIFT); + } + + @Test + public void up() { + moveCaretTo(lineStart(2)); + assertTrue(area.getSelectedText().isEmpty()); + + type(UP); + + assertEquals(lineStart(2), area.getCaretPosition()); + assertTrue(area.getSelectedText().isEmpty()); + } + + @Test + public void down() { + moveCaretTo(lineStart(1)); + assertTrue(area.getSelectedText().isEmpty()); + + type(DOWN); + + assertEquals(lineStart(1), area.getCaretPosition()); + assertTrue(area.getSelectedText().isEmpty()); + } + + @Test + public void home_selects_up_to_the_start_of_current_paragraph() { + moveCaretTo(area.getLength()); + assertTrue(area.getSelectedText().isEmpty()); + + type(HOME); + + assertEquals(0, area.getCaretPosition()); + assertEquals(area.getText(), area.getSelectedText()); + } + + @Test + public void end_selects_up_to_the_end_of_current_paragraph() { + moveCaretTo(0); + assertTrue(area.getSelectedText().isEmpty()); + + type(END); + + assertEquals(area.getLength(), area.getCaretPosition()); + assertEquals(area.getText(), area.getSelectedText()); + } + + } + +} From 28eb926ff2b2566600ab89b90a8a233c9be2c81d Mon Sep 17 00:00:00 2001 From: Jordan Martinez Date: Sat, 30 Sep 2017 09:20:29 -0700 Subject: [PATCH 03/23] Move MultiLineJaggedTextTests into navigation package --- .../richtext/keyboard/NavigationTests.java | 47 -------------- .../navigation/MultiLineJaggedTextTests.java | 61 +++++++++++++++++++ 2 files changed, 61 insertions(+), 47 deletions(-) create mode 100644 richtextfx/src/integrationTest/java/org/fxmisc/richtext/keyboard/navigation/MultiLineJaggedTextTests.java diff --git a/richtextfx/src/integrationTest/java/org/fxmisc/richtext/keyboard/NavigationTests.java b/richtextfx/src/integrationTest/java/org/fxmisc/richtext/keyboard/NavigationTests.java index 1d574f048..b5c16f8ce 100644 --- a/richtextfx/src/integrationTest/java/org/fxmisc/richtext/keyboard/NavigationTests.java +++ b/richtextfx/src/integrationTest/java/org/fxmisc/richtext/keyboard/NavigationTests.java @@ -43,53 +43,6 @@ private int entityEnd(int entityIndex, String[] array, GenericStyledArea textFlowIsReady = WaitForAsyncUtils.asyncFx(() -> { - while (area.getParagraphLinesCount(0) != 3) { - sleep(10); - } - }); - WaitForAsyncUtils.waitFor(5, TimeUnit.SECONDS, textFlowIsReady); - } - - @Test - public void pressingDownMovesCaretToNextLine() throws TimeoutException { - waitForMultiLineRegistration(); - - area.moveTo(27); - - push(DOWN); - - assertEquals(57, area.getCaretPosition()); - } - - @Test - public void pressingUpMovesCaretToPrevLine() throws TimeoutException { - waitForMultiLineRegistration(); - - area.moveTo(66); - - push(UP); - - assertEquals(36, area.getCaretPosition()); - } - } - public class ViewportTests extends InlineCssTextAreaAppTest { @Override diff --git a/richtextfx/src/integrationTest/java/org/fxmisc/richtext/keyboard/navigation/MultiLineJaggedTextTests.java b/richtextfx/src/integrationTest/java/org/fxmisc/richtext/keyboard/navigation/MultiLineJaggedTextTests.java new file mode 100644 index 000000000..b2dd34d2f --- /dev/null +++ b/richtextfx/src/integrationTest/java/org/fxmisc/richtext/keyboard/navigation/MultiLineJaggedTextTests.java @@ -0,0 +1,61 @@ +package org.fxmisc.richtext.keyboard.navigation; + +import javafx.stage.Stage; +import org.fxmisc.richtext.InlineCssTextAreaAppTest; +import org.junit.Test; +import org.testfx.util.WaitForAsyncUtils; + +import java.util.concurrent.Future; +import java.util.concurrent.TimeUnit; +import java.util.concurrent.TimeoutException; + +import static javafx.scene.input.KeyCode.DOWN; +import static javafx.scene.input.KeyCode.UP; +import static org.junit.Assert.assertEquals; + +public class MultiLineJaggedTextTests extends InlineCssTextAreaAppTest { + + String threeLinesOfText = "Some long amount of text to take up a lot of space in the given area."; + + @Override + public void start(Stage stage) throws Exception { + super.start(stage); + stage.setWidth(200); + area.replaceText(threeLinesOfText); + area.setWrapText(true); + } + + private void waitForMultiLineRegistration() throws TimeoutException { + // When the stage's width changes, TextFlow does not properly handle API calls to a + // multi-line paragraph immediately. So, wait until it correctly responds + // to the stage width change + Future textFlowIsReady = WaitForAsyncUtils.asyncFx(() -> { + while (area.getParagraphLinesCount(0) != 3) { + sleep(10); + } + }); + WaitForAsyncUtils.waitFor(5, TimeUnit.SECONDS, textFlowIsReady); + } + + @Test + public void pressingDownMovesCaretToNextLine() throws TimeoutException { + waitForMultiLineRegistration(); + + area.moveTo(27); + + push(DOWN); + + assertEquals(57, area.getCaretPosition()); + } + + @Test + public void pressingUpMovesCaretToPrevLine() throws TimeoutException { + waitForMultiLineRegistration(); + + area.moveTo(66); + + push(UP); + + assertEquals(36, area.getCaretPosition()); + } +} From 612965a83f8b18c10baacc67c6a3d0c0278c587f Mon Sep 17 00:00:00 2001 From: Jordan Martinez Date: Sat, 30 Sep 2017 09:21:42 -0700 Subject: [PATCH 04/23] Move ViewportTests to separate file: PageUpDownTests --- .../richtext/keyboard/NavigationTests.java | 133 ------------------ .../richtext/keyboard/PageUpDownTests.java | 102 ++++++++++++++ 2 files changed, 102 insertions(+), 133 deletions(-) delete mode 100644 richtextfx/src/integrationTest/java/org/fxmisc/richtext/keyboard/NavigationTests.java create mode 100644 richtextfx/src/integrationTest/java/org/fxmisc/richtext/keyboard/PageUpDownTests.java diff --git a/richtextfx/src/integrationTest/java/org/fxmisc/richtext/keyboard/NavigationTests.java b/richtextfx/src/integrationTest/java/org/fxmisc/richtext/keyboard/NavigationTests.java deleted file mode 100644 index b5c16f8ce..000000000 --- a/richtextfx/src/integrationTest/java/org/fxmisc/richtext/keyboard/NavigationTests.java +++ /dev/null @@ -1,133 +0,0 @@ -package org.fxmisc.richtext.keyboard; - -import com.nitorcreations.junit.runners.NestedRunner; -import javafx.geometry.Bounds; -import javafx.stage.Stage; -import org.fxmisc.richtext.GenericStyledArea; -import org.fxmisc.richtext.InlineCssTextAreaAppTest; -import org.junit.Before; -import org.junit.Ignore; -import org.junit.Test; -import org.junit.runner.RunWith; -import org.testfx.util.WaitForAsyncUtils; - -import java.util.Arrays; -import java.util.concurrent.Future; -import java.util.concurrent.TimeUnit; -import java.util.concurrent.TimeoutException; - -import static javafx.scene.input.KeyCode.*; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertTrue; - -@RunWith(NestedRunner.class) -public class NavigationTests { - - private int entityStart(int entityIndex, String[] array) { - if (entityIndex == 0) { - return 0; - } else { - return Arrays.stream(array) - .map(String::length) - .limit(entityIndex) - .reduce(0, (a, b) -> a + b) - + entityIndex; // for delimiter characters - } - } - - private int entityEnd(int entityIndex, String[] array, GenericStyledArea area) { - if (entityIndex == array.length - 1) { - return area.getLength(); - } else { - return entityStart(entityIndex + 1, array) - 1; - } - } - - public class ViewportTests extends InlineCssTextAreaAppTest { - - @Override - public void start(Stage stage) throws Exception { - super.start(stage); - - // allow 6 lines to be displayed - stage.setHeight(90); - - StringBuilder sb = new StringBuilder(); - for (int i = 0; i < 8; i++) { - sb.append(i).append("\n"); - } - sb.append(9); - area.replaceText(sb.toString()); - } - - @Test - public void testPageUp() { - interact(() -> { - area.moveTo(5, 0); - area.requestFollowCaret(); - }); - assertTrue(area.getSelectedText().isEmpty()); - Bounds beforeBounds = area.getCaretBounds().get(); - - type(PAGE_UP); - - Bounds afterBounds = area.getCaretBounds().get(); - assertEquals(0, area.getCaretPosition()); - assertTrue(area.getSelectedText().isEmpty()); - assertTrue(beforeBounds.getMinY() > afterBounds.getMinY()); - } - - @Ignore("doesn't work despite 'testShiftPageDown' working fine using the same code") - @Test - public void testPageDown() throws Exception { - interact(() -> { - area.moveTo(0); - area.requestFollowCaret(); - }); - assertTrue(area.getSelectedText().isEmpty()); - Bounds beforeBounds = area.getCaretBounds().get(); - - type(PAGE_DOWN); - - Bounds afterBounds = area.getCaretBounds().get(); - assertEquals(area.getAbsolutePosition(5, 0), area.getCaretPosition()); - assertTrue(area.getSelectedText().isEmpty()); - assertTrue(beforeBounds.getMinY() < afterBounds.getMinY()); - } - - @Test - public void testShiftPageUp() { - interact(() -> { - area.moveTo(5, 0); - area.requestFollowCaret(); - }); - assertTrue(area.getSelectedText().isEmpty()); - Bounds beforeBounds = area.getCaretBounds().get(); - - press(SHIFT).type(PAGE_UP).release(SHIFT); - - Bounds afterBounds = area.getCaretBounds().get(); - assertEquals(0, area.getCaretPosition()); - assertEquals(area.getText(0, 0, 5, 0), area.getSelectedText()); - assertTrue(beforeBounds.getMinY() > afterBounds.getMinY()); - } - - @Test - public void testShiftPageDown() { - interact(() -> { - area.moveTo(0); - area.requestFollowCaret(); - }); - assertTrue(area.getSelectedText().isEmpty()); - Bounds beforeBounds = area.getCaretBounds().get(); - - press(SHIFT).type(PAGE_DOWN).release(SHIFT); - - Bounds afterBounds = area.getCaretBounds().get(); - assertEquals(area.getAbsolutePosition(5, 0), area.getCaretPosition()); - assertEquals(area.getText(0, 0, 5, 0), area.getSelectedText()); - assertTrue(beforeBounds.getMinY() < afterBounds.getMinY()); - } - - } -} diff --git a/richtextfx/src/integrationTest/java/org/fxmisc/richtext/keyboard/PageUpDownTests.java b/richtextfx/src/integrationTest/java/org/fxmisc/richtext/keyboard/PageUpDownTests.java new file mode 100644 index 000000000..aef6f6552 --- /dev/null +++ b/richtextfx/src/integrationTest/java/org/fxmisc/richtext/keyboard/PageUpDownTests.java @@ -0,0 +1,102 @@ +package org.fxmisc.richtext.keyboard; + +import javafx.geometry.Bounds; +import javafx.stage.Stage; +import org.fxmisc.richtext.InlineCssTextAreaAppTest; +import org.junit.Ignore; +import org.junit.Test; + +import static javafx.scene.input.KeyCode.PAGE_DOWN; +import static javafx.scene.input.KeyCode.PAGE_UP; +import static javafx.scene.input.KeyCode.SHIFT; +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertTrue; + +public class PageUpDownTests extends InlineCssTextAreaAppTest { + + @Override + public void start(Stage stage) throws Exception { + super.start(stage); + + // allow 6 lines to be displayed + stage.setHeight(90); + + StringBuilder sb = new StringBuilder(); + for (int i = 0; i < 8; i++) { + sb.append(i).append("\n"); + } + sb.append(9); + area.replaceText(sb.toString()); + } + + @Test + public void testPageUp() { + interact(() -> { + area.moveTo(5, 0); + area.requestFollowCaret(); + }); + assertTrue(area.getSelectedText().isEmpty()); + Bounds beforeBounds = area.getCaretBounds().get(); + + type(PAGE_UP); + + Bounds afterBounds = area.getCaretBounds().get(); + assertEquals(0, area.getCaretPosition()); + assertTrue(area.getSelectedText().isEmpty()); + assertTrue(beforeBounds.getMinY() > afterBounds.getMinY()); + } + + @Ignore("doesn't work despite 'testShiftPageDown' working fine using the same code") + @Test + public void testPageDown() throws Exception { + interact(() -> { + area.moveTo(0); + area.requestFollowCaret(); + }); + assertTrue(area.getSelectedText().isEmpty()); + Bounds beforeBounds = area.getCaretBounds().get(); + + type(PAGE_DOWN); + + Bounds afterBounds = area.getCaretBounds().get(); + assertEquals(area.getAbsolutePosition(5, 0), area.getCaretPosition()); + assertTrue(area.getSelectedText().isEmpty()); + assertTrue(beforeBounds.getMinY() < afterBounds.getMinY()); + } + + @Test + public void testShiftPageUp() { + interact(() -> { + area.moveTo(5, 0); + area.requestFollowCaret(); + }); + assertTrue(area.getSelectedText().isEmpty()); + Bounds beforeBounds = area.getCaretBounds().get(); + + press(SHIFT).type(PAGE_UP).release(SHIFT); + + Bounds afterBounds = area.getCaretBounds().get(); + assertEquals(0, area.getCaretPosition()); + assertEquals(area.getText(0, 0, 5, 0), area.getSelectedText()); + assertTrue(beforeBounds.getMinY() > afterBounds.getMinY()); + } + + @Test + public void testShiftPageDown() { + interact(() -> { + area.moveTo(0); + area.requestFollowCaret(); + }); + assertTrue(area.getSelectedText().isEmpty()); + Bounds beforeBounds = area.getCaretBounds().get(); + + press(SHIFT).type(PAGE_DOWN).release(SHIFT); + + Bounds afterBounds = area.getCaretBounds().get(); + assertEquals(area.getAbsolutePosition(5, 0), area.getCaretPosition()); + assertEquals(area.getText(0, 0, 5, 0), area.getSelectedText()); + assertTrue(beforeBounds.getMinY() < afterBounds.getMinY()); + } + +} + From e63054639489dcc5800b8d550bad258fbdac2d9c Mon Sep 17 00:00:00 2001 From: Jordan Martinez Date: Sat, 30 Sep 2017 09:34:50 -0700 Subject: [PATCH 05/23] Move helper fields/methods to base test if need different area flavor --- .../richtext/InlineCssTextAreaAppTest.java | 78 +----------- .../fxmisc/richtext/RichTextFXTestBase.java | 117 ++++++++++++++++++ 2 files changed, 118 insertions(+), 77 deletions(-) create mode 100644 richtextfx/src/integrationTest/java/org/fxmisc/richtext/RichTextFXTestBase.java diff --git a/richtextfx/src/integrationTest/java/org/fxmisc/richtext/InlineCssTextAreaAppTest.java b/richtextfx/src/integrationTest/java/org/fxmisc/richtext/InlineCssTextAreaAppTest.java index 81a171fbd..3dd1458f5 100644 --- a/richtextfx/src/integrationTest/java/org/fxmisc/richtext/InlineCssTextAreaAppTest.java +++ b/richtextfx/src/integrationTest/java/org/fxmisc/richtext/InlineCssTextAreaAppTest.java @@ -1,36 +1,19 @@ package org.fxmisc.richtext; import javafx.geometry.Pos; -import javafx.scene.Node; import javafx.scene.Scene; import javafx.scene.control.ContextMenu; import javafx.scene.control.MenuItem; import javafx.scene.input.MouseButton; import javafx.stage.Stage; -import javafx.stage.Window; import org.testfx.api.FxRobotInterface; -import org.testfx.framework.junit.ApplicationTest; import org.testfx.service.query.PointQuery; -import static org.junit.Assume.assumeTrue; - /** * TestFX tests should subclass this if it needs to run tests on a simple area. Any view-related API needs to be * wrapped in a {@link #interact(Runnable)} call, but model API does not need to be wrapped in it. */ -public class InlineCssTextAreaAppTest extends ApplicationTest { - - static { - String osName = System.getProperty("os.name").toLowerCase(); - - isWindows = osName.startsWith("win"); - isMac = osName.startsWith("mac"); - isLinux = osName.startsWith("linux"); - } - - public static final boolean isWindows; - public static final boolean isMac; - public static final boolean isLinux; +public class InlineCssTextAreaAppTest extends RichTextFXTestBase { public Stage stage; public Scene scene; @@ -58,18 +41,6 @@ public void start(Stage stage) throws Exception { area.requestFocus(); } - public final PointQuery position(Scene scene, Pos pos, double xOffset, double yOffset) { - return point(scene).atPosition(pos).atOffset(xOffset, yOffset); - } - - public final PointQuery position(Window window, Pos pos, double xOffset, double yOffset) { - return point(window).atPosition(pos).atOffset(xOffset, yOffset); - } - - public final PointQuery position(Node node, Pos pos, double xOffset, double yOffset) { - return point(node).atPosition(pos).atOffset(xOffset, yOffset); - } - public final PointQuery position(Pos pos, double xOffset, double yOffset) { return position(area, pos, xOffset, yOffset); } @@ -98,51 +69,4 @@ public final FxRobotInterface rightClickOnFirstLine() { return clickOnFirstLine(MouseButton.SECONDARY); } - /** - * If not on Windows environment, calling this in @Before method will skip the entire test suite whereas calling - * this in @Test will skip just that test method - */ - public final void run_only_on_windows() { - assumeTrue(isWindows); - } - - /** - * If not on Linux environment, calling this in @Before method will skip the entire test suite whereas calling - * this in @Test will skip just that test method - */ - public final void run_only_on_linux() { - assumeTrue(isLinux); - } - - /** - * If not on Mac environment, calling this in @Before method will skip the entire test suite whereas calling - * this in @Test will skip just that test method - */ - public final void run_only_on_mac() { - assumeTrue(isMac); - } - - /** - * If on Windows environment, calling this in @Before method will skip the entire test suite whereas calling - * this in @Test will skip just that test method - */ - public final void skip_if_on_windows() { - assumeTrue(!isWindows); - } - - /** - * If on Linux environment, calling this in @Before method will skip the entire test suite whereas calling - * this in @Test will skip just that test method - */ - public final void skip_if_on_linux() { - assumeTrue(!isLinux); - } - - /** - * If on Mac environment, calling this in @Before method will skip the entire test suite whereas calling - * this in @Test will skip just that test method - */ - public final void skip_if_on_mac() { - assumeTrue(!isMac); - } } diff --git a/richtextfx/src/integrationTest/java/org/fxmisc/richtext/RichTextFXTestBase.java b/richtextfx/src/integrationTest/java/org/fxmisc/richtext/RichTextFXTestBase.java new file mode 100644 index 000000000..67a20f8bf --- /dev/null +++ b/richtextfx/src/integrationTest/java/org/fxmisc/richtext/RichTextFXTestBase.java @@ -0,0 +1,117 @@ +package org.fxmisc.richtext; + +import javafx.geometry.Pos; +import javafx.scene.Node; +import javafx.scene.Scene; +import javafx.stage.Window; +import org.testfx.framework.junit.ApplicationTest; +import org.testfx.service.query.PointQuery; + +import static org.junit.Assume.assumeTrue; + +/** + * Provides useful static fields and helper methods for RichTextFX integration tests. + * + *
    + *
  • + * Helps determine which OS is currently running the test and whether to run/skip a test on that OS + *
  • + *
  • + * Getting the position o + *
  • + *
+ */ +public abstract class RichTextFXTestBase extends ApplicationTest { + + static { + String osName = System.getProperty("os.name").toLowerCase(); + + IS_WINDOWS = osName.startsWith("win"); + IS_MAC = osName.startsWith("mac"); + IS_LINUX = osName.startsWith("linux"); + } + + /* *********************************************** * + * OS-RELATED + * *********************************************** */ + + public static final boolean IS_WINDOWS; + public static final boolean IS_MAC; + public static final boolean IS_LINUX; + + /** + * If not on Windows environment, calling this in @Before method will skip the entire test suite whereas calling + * this in @Test will skip just that test method + */ + public final void run_only_on_windows() { + assumeTrue(IS_WINDOWS); + } + + /** + * If not on Linux environment, calling this in @Before method will skip the entire test suite whereas calling + * this in @Test will skip just that test method + */ + public final void run_only_on_linux() { + assumeTrue(IS_LINUX); + } + + /** + * If not on Mac environment, calling this in @Before method will skip the entire test suite whereas calling + * this in @Test will skip just that test method + */ + public final void run_only_on_mac() { + assumeTrue(IS_MAC); + } + + /** + * If on Windows environment, calling this in @Before method will skip the entire test suite whereas calling + * this in @Test will skip just that test method + */ + public final void skip_if_on_windows() { + assumeTrue(!IS_WINDOWS); + } + + /** + * If on Linux environment, calling this in @Before method will skip the entire test suite whereas calling + * this in @Test will skip just that test method + */ + public final void skip_if_on_linux() { + assumeTrue(!IS_LINUX); + } + + /** + * If on Mac environment, calling this in @Before method will skip the entire test suite whereas calling + * this in @Test will skip just that test method + */ + public final void skip_if_on_mac() { + assumeTrue(!IS_MAC); + } + + /* *********************************************** * + * Position-Related + * *********************************************** */ + + /** + * Returns a specific position in the scene, starting at {@code pos} and offsetting from that place by + * {@code xOffset} and {@code yOffset} + */ + public final PointQuery position(Scene scene, Pos pos, double xOffset, double yOffset) { + return point(scene).atPosition(pos).atOffset(xOffset, yOffset); + } + + /** + * Returns a specific position in the window, starting at {@code pos} and offsetting from that place by + * {@code xOffset} and {@code yOffset} + */ + public final PointQuery position(Window window, Pos pos, double xOffset, double yOffset) { + return point(window).atPosition(pos).atOffset(xOffset, yOffset); + } + + /** + * Returns a specific position in the node, starting at {@code pos} and offsetting from that place by + * {@code xOffset} and {@code yOffset} + */ + public final PointQuery position(Node node, Pos pos, double xOffset, double yOffset) { + return point(node).atPosition(pos).atOffset(xOffset, yOffset); + } +} From 12b029b279ac781b119be19acac79148748c6271 Mon Sep 17 00:00:00 2001 From: Jordan Martinez Date: Sat, 30 Sep 2017 09:51:07 -0700 Subject: [PATCH 06/23] Only set context menu is ContextMenuTests --- .../richtext/InlineCssTextAreaAppTest.java | 9 ----- .../richtext/mouse/ContextMenuTests.java | 33 ++++++++++++++++--- 2 files changed, 29 insertions(+), 13 deletions(-) diff --git a/richtextfx/src/integrationTest/java/org/fxmisc/richtext/InlineCssTextAreaAppTest.java b/richtextfx/src/integrationTest/java/org/fxmisc/richtext/InlineCssTextAreaAppTest.java index 3dd1458f5..249b63265 100644 --- a/richtextfx/src/integrationTest/java/org/fxmisc/richtext/InlineCssTextAreaAppTest.java +++ b/richtextfx/src/integrationTest/java/org/fxmisc/richtext/InlineCssTextAreaAppTest.java @@ -2,8 +2,6 @@ import javafx.geometry.Pos; import javafx.scene.Scene; -import javafx.scene.control.ContextMenu; -import javafx.scene.control.MenuItem; import javafx.scene.input.MouseButton; import javafx.stage.Stage; import org.testfx.api.FxRobotInterface; @@ -18,7 +16,6 @@ public class InlineCssTextAreaAppTest extends RichTextFXTestBase { public Stage stage; public Scene scene; public InlineCssTextArea area; - public ContextMenu menu; @Override public void start(Stage stage) throws Exception { @@ -31,12 +28,6 @@ public void start(Stage stage) throws Exception { stage.setHeight(400); stage.show(); - menu = new ContextMenu(new MenuItem("A menu item")); - area.setContextMenu(menu); - // offset needs to be 5+ to prevent test failures - area.setContextMenuXOffset(30); - area.setContextMenuYOffset(30); - // so tests don't need to do this themselves area.requestFocus(); } diff --git a/richtextfx/src/integrationTest/java/org/fxmisc/richtext/mouse/ContextMenuTests.java b/richtextfx/src/integrationTest/java/org/fxmisc/richtext/mouse/ContextMenuTests.java index 377a87b6e..9851fdf18 100644 --- a/richtextfx/src/integrationTest/java/org/fxmisc/richtext/mouse/ContextMenuTests.java +++ b/richtextfx/src/integrationTest/java/org/fxmisc/richtext/mouse/ContextMenuTests.java @@ -2,9 +2,13 @@ import javafx.geometry.Point2D; import javafx.geometry.Pos; +import javafx.scene.control.ContextMenu; +import javafx.scene.control.MenuItem; import javafx.scene.input.KeyCode; import javafx.scene.input.MouseButton; +import javafx.stage.Stage; import org.fxmisc.richtext.InlineCssTextAreaAppTest; +import org.junit.After; import org.junit.Test; import static junit.framework.TestCase.assertFalse; @@ -12,6 +16,25 @@ public class ContextMenuTests extends InlineCssTextAreaAppTest { + private ContextMenu menu; + + // offset needs to be 5+ to prevent test failures + private double offset = 30; + + @Override + public void start(Stage stage) throws Exception { + super.start(stage); + menu = new ContextMenu(new MenuItem("A menu item")); + area.setContextMenu(menu); + area.setContextMenuXOffset(offset); + area.setContextMenuYOffset(offset); + } + + @After + public void cleanup() { + interact(menu::hide); + } + @Test public void clickingSecondaryShowsContextMenu() { // Linux passes; Mac fails; Windows untested @@ -43,18 +66,20 @@ public void pressingSecondaryShowsContextMenu() { @Test public void pressingPrimaryMouseButtonHidesContextMenu() { // given menu is showing - showContextMenuAt(Pos.TOP_LEFT, 30); + showContextMenuAt(); moveTo(firstLineOfArea()).press(MouseButton.PRIMARY); + assertFalse(area.getContextMenu().isShowing()); } @Test public void pressingMiddleMouseButtonHidesContextMenu() { // given menu is showing - showContextMenuAt(Pos.TOP_LEFT, 30); + showContextMenuAt(); moveTo(firstLineOfArea()).press(MouseButton.MIDDLE); + assertFalse(area.getContextMenu().isShowing()); } @@ -68,8 +93,8 @@ public void requestingContextMenuViaKeyboardWorksOnWindows() { assertTrue(area.getContextMenu().isShowing()); } - private void showContextMenuAt(Pos posInArea, double offset) { - Point2D screenPoint = point(area).atPosition(posInArea).atOffset(offset, offset).query(); + private void showContextMenuAt() { + Point2D screenPoint = position(Pos.TOP_LEFT, offset, offset).query(); interact(() -> area.getContextMenu().show(area, screenPoint.getX(), screenPoint.getY())); } From c2196f25214e25801ebf867315b44a5dd6059c17 Mon Sep 17 00:00:00 2001 From: Jordan Martinez Date: Sat, 30 Sep 2017 10:11:18 -0700 Subject: [PATCH 07/23] Prevent super class stage dimension changes from messing up assertions --- .../java/org/fxmisc/richtext/api/HitTests.java | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/richtextfx/src/integrationTest/java/org/fxmisc/richtext/api/HitTests.java b/richtextfx/src/integrationTest/java/org/fxmisc/richtext/api/HitTests.java index 9aa587174..97ec51fef 100644 --- a/richtextfx/src/integrationTest/java/org/fxmisc/richtext/api/HitTests.java +++ b/richtextfx/src/integrationTest/java/org/fxmisc/richtext/api/HitTests.java @@ -5,6 +5,7 @@ import javafx.geometry.Insets; import javafx.geometry.Point2D; import javafx.geometry.Pos; +import javafx.stage.Stage; import org.fxmisc.richtext.InlineCssTextAreaAppTest; import org.fxmisc.richtext.model.NavigationActions; import org.junit.Before; @@ -19,6 +20,15 @@ @RunWith(NestedRunner.class) public class HitTests extends InlineCssTextAreaAppTest { + @Override + public void start(Stage stage) throws Exception { + super.start(stage); + + // insure stage width doesn't change irregardless of changes in superclass' start method + stage.setWidth(400); + stage.setHeight(400); + } + private void moveCaretToAreaEnd() { area.moveTo(area.getLength()); } From 3a385225d923de07286ecbd99c3fb01a43b4390f Mon Sep 17 00:00:00 2001 From: Jordan Martinez Date: Sat, 30 Sep 2017 10:17:28 -0700 Subject: [PATCH 08/23] Initialize text and padding only once --- .../org/fxmisc/richtext/api/HitTests.java | 69 +++++++------------ 1 file changed, 25 insertions(+), 44 deletions(-) diff --git a/richtextfx/src/integrationTest/java/org/fxmisc/richtext/api/HitTests.java b/richtextfx/src/integrationTest/java/org/fxmisc/richtext/api/HitTests.java index 97ec51fef..2e2ec3417 100644 --- a/richtextfx/src/integrationTest/java/org/fxmisc/richtext/api/HitTests.java +++ b/richtextfx/src/integrationTest/java/org/fxmisc/richtext/api/HitTests.java @@ -20,6 +20,23 @@ @RunWith(NestedRunner.class) public class HitTests extends InlineCssTextAreaAppTest { + private static final String ALPHABET = "abcdefghijklmnopqrstuvwxyz"; + private static final String FIFTY_PARS; + private static final double PADDING_AMOUNT = 20; + + static { + int totalPars = 50; + int indexLimit = totalPars - 1; + StringBuilder sb = new StringBuilder(); + Consumer appendParagraph = i -> sb.append("Par #").append(i).append(" ").append(ALPHABET); + for (int i = 0; i < indexLimit; i++) { + appendParagraph.accept(i); + sb.append("\n"); + } + appendParagraph.accept(indexLimit); + FIFTY_PARS = sb.toString(); + } + @Override public void start(Stage stage) throws Exception { super.start(stage); @@ -35,8 +52,6 @@ private void moveCaretToAreaEnd() { public class WhenAreaIsPadded { - double paddingAmount = 20; - public class AndHitsOccurOutsideArea { String text = "text"; @@ -49,7 +64,7 @@ public void setup() { @Test public void clickingInTopPaddingMovesCaretToTopLine() { - interact(() -> area.setPadding(new Insets(paddingAmount, 0, 0, 0))); + interact(() -> area.setPadding(new Insets(PADDING_AMOUNT, 0, 0, 0))); moveCaretToAreaEnd(); moveTo(position(Pos.TOP_LEFT, 1, 2)).clickOn(PRIMARY); @@ -62,7 +77,7 @@ public void clickingInTopPaddingMovesCaretToTopLine() { @Test public void clickingInLeftPaddingMovesCaretToBeginningOfLineOnSingleLineParagraph() { - interact(() -> area.setPadding(new Insets(0, 0, 0, paddingAmount))); + interact(() -> area.setPadding(new Insets(0, 0, 0, PADDING_AMOUNT))); moveCaretToAreaEnd(); moveTo(position(Pos.TOP_LEFT, 1, 1)).clickOn(PRIMARY); @@ -72,7 +87,7 @@ public void clickingInLeftPaddingMovesCaretToBeginningOfLineOnSingleLineParagrap @Test public void clickingInRightPaddingMovesCaretToEndOfLineOnSingleLineParagraph() { interact(() -> { - area.setPadding(new Insets(0, paddingAmount, 0, 0)); + area.setPadding(new Insets(0, PADDING_AMOUNT, 0, 0)); area.moveTo(0); // insure we're scrolled all the way to the right @@ -86,7 +101,7 @@ public void clickingInRightPaddingMovesCaretToEndOfLineOnSingleLineParagraph() { @Test public void clickingInBottomPaddingMovesCaretToBottomLine() { interact(() -> { - area.setPadding(new Insets(0, 0, paddingAmount, 0)); + area.setPadding(new Insets(0, 0, PADDING_AMOUNT, 0)); area.moveTo(0); // insure we're scrolled all the way to the bottom @@ -101,27 +116,11 @@ public void clickingInBottomPaddingMovesCaretToBottomLine() { public class AndHitsOccurInsideArea { - String text = "abcdefghijklmnopqrstuvwxyz"; - String fullText; - - { - int totalPars = 50; - int indexLimit = totalPars - 1; - StringBuilder sb = new StringBuilder(); - Consumer appendParagraph = i -> sb.append("Par #").append(i).append(" ").append(text); - for (int i = 0; i < indexLimit; i++) { - appendParagraph.accept(i); - sb.append("\n"); - } - appendParagraph.accept(indexLimit); - fullText = sb.toString(); - } - @Before public void setup() { interact(() -> { - area.replaceText(fullText); - area.setPadding(new Insets(paddingAmount)); + area.replaceText(FIFTY_PARS); + area.setPadding(new Insets(PADDING_AMOUNT)); area.setStyle("-fx-font-family: monospace; -fx-font-size: 12pt;"); }); } @@ -177,28 +176,10 @@ public void nextPageMovesCaretToBottomOfPage() { public class WhenParagraphBoxIsPadded { - double paddingAmount = 20; - - String text = "abcdefghijklmnopqrstuvwxyz"; - String fullText; - - { - int totalPars = 50; - int indexLimit = totalPars - 1; - StringBuilder sb = new StringBuilder(); - Consumer appendParagraph = i -> sb.append("Par #").append(i).append(" ").append(text); - for (int i = 0; i < indexLimit; i++) { - appendParagraph.accept(i); - sb.append("\n"); - } - appendParagraph.accept(indexLimit); - fullText = sb.toString(); - } - @Before public void setup() { interact(() -> { - area.replaceText(fullText); + area.replaceText(FIFTY_PARS); area.setStyle("-fx-font-family: monospace; -fx-font-size: 12pt;"); scene.getStylesheets().add(HitTests.class.getResource("padded-paragraph-box.css").toExternalForm()); }); @@ -215,7 +196,7 @@ public class AndAreaIsPadded { @Test public void clickingCharacterShouldMoveCaretToThatPosition() { - interact(() -> area.setPadding(new Insets(paddingAmount))); + interact(() -> area.setPadding(new Insets(PADDING_AMOUNT))); runTest(); } From 5f8d00b2e0e2b717397dc772ffd9155efccf7599 Mon Sep 17 00:00:00 2001 From: Jordan Martinez Date: Sat, 30 Sep 2017 10:43:09 -0700 Subject: [PATCH 09/23] Use more accurate way to determine caret's paragraph --- .../java/org/fxmisc/richtext/api/HitTests.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/richtextfx/src/integrationTest/java/org/fxmisc/richtext/api/HitTests.java b/richtextfx/src/integrationTest/java/org/fxmisc/richtext/api/HitTests.java index 2e2ec3417..af34a1247 100644 --- a/richtextfx/src/integrationTest/java/org/fxmisc/richtext/api/HitTests.java +++ b/richtextfx/src/integrationTest/java/org/fxmisc/richtext/api/HitTests.java @@ -149,7 +149,7 @@ public void prevPageMovesCaretToTopOfPage() { }); assertEquals(0, area.getCaretColumn()); - assertEquals(32, area.getCurrentParagraph()); + assertEquals(area.firstVisibleParToAllParIndex(), area.getCurrentParagraph()); } @Test @@ -167,7 +167,7 @@ public void nextPageMovesCaretToBottomOfPage() { }); assertEquals(0, area.getCaretColumn()); - assertEquals(17, area.getCurrentParagraph()); + assertEquals(area.lastVisibleParToAllParIndex(), area.getCurrentParagraph()); } } From 6577e7856e4da9a53ad3d6d9711833d6873e5ef0 Mon Sep 17 00:00:00 2001 From: Jordan Martinez Date: Sat, 30 Sep 2017 17:59:28 -0700 Subject: [PATCH 10/23] Run prev/next page tests on every OS --- .../java/org/fxmisc/richtext/api/HitTests.java | 8 -------- 1 file changed, 8 deletions(-) diff --git a/richtextfx/src/integrationTest/java/org/fxmisc/richtext/api/HitTests.java b/richtextfx/src/integrationTest/java/org/fxmisc/richtext/api/HitTests.java index af34a1247..a0f0508e9 100644 --- a/richtextfx/src/integrationTest/java/org/fxmisc/richtext/api/HitTests.java +++ b/richtextfx/src/integrationTest/java/org/fxmisc/richtext/api/HitTests.java @@ -135,10 +135,6 @@ public void clickingCharacterShouldMoveCaretToThatPosition() { @Test public void prevPageMovesCaretToTopOfPage() { - // Mac: failed; Windows: untested - // TODO: test on respective OS and update expected values to be correct - run_only_on_linux(); - area.showParagraphAtBottom(area.getParagraphs().size() - 1); // move to last line, column 0 area.moveTo(area.getParagraphs().size() - 1, 0); @@ -154,10 +150,6 @@ public void prevPageMovesCaretToTopOfPage() { @Test public void nextPageMovesCaretToBottomOfPage() { - // Mac: failed; Windows: untested - // TODO: test on respective OS and update expected values to be correct - run_only_on_linux(); - area.showParagraphAtTop(0); area.moveTo(0); From a13af4d119b9c3257d5d328746fe40f468439ba2 Mon Sep 17 00:00:00 2001 From: Jordan Martinez Date: Sat, 30 Sep 2017 19:01:31 -0700 Subject: [PATCH 11/23] Add "_" in-between words in class/test names; optimize string creation --- .../org/fxmisc/richtext/api/CaretTests.java | 22 +++++---- .../richtext/api/CharacterBoundsTest.java | 2 +- .../fxmisc/richtext/api/ClipboardTests.java | 4 +- .../org/fxmisc/richtext/api/HitTests.java | 30 ++++++------ .../richtext/api/MiscellaneousTests.java | 6 +-- .../richtext/api/MouseOverTextDelayTests.java | 8 ++-- .../api/ParagraphLinesCountTests.java | 4 +- .../fxmisc/richtext/api/UndoManagerTests.java | 2 +- .../richtext/keyboard/CutCopyPasteTests.java | 40 ++++++++-------- .../richtext/keyboard/DeletionTests.java | 12 ++--- .../richtext/keyboard/PageUpDownTests.java | 27 ++++++----- .../fxmisc/richtext/keyboard/TypingTests.java | 2 +- .../MultiLineGridlikeTextTests.java | 8 ++-- .../navigation/MultiLineJaggedTextTests.java | 4 +- .../keyboard/navigation/SingleLineTests.java | 8 ++-- .../richtext/mouse/ClickAndDragTests.java | 46 +++++++++---------- .../richtext/mouse/ContextMenuTests.java | 10 ++-- 17 files changed, 123 insertions(+), 112 deletions(-) diff --git a/richtextfx/src/integrationTest/java/org/fxmisc/richtext/api/CaretTests.java b/richtextfx/src/integrationTest/java/org/fxmisc/richtext/api/CaretTests.java index 4f5d47e56..ac1ebcd53 100644 --- a/richtextfx/src/integrationTest/java/org/fxmisc/richtext/api/CaretTests.java +++ b/richtextfx/src/integrationTest/java/org/fxmisc/richtext/api/CaretTests.java @@ -11,24 +11,30 @@ public class CaretTests extends InlineCssTextAreaAppTest { + private static final String FIFTY_PARS_OF_TEXT; + + static { + StringBuilder sb = new StringBuilder(); + for (int i = 0; i < 50; i++) { + sb.append(i).append("\n"); + } + sb.append(50); + FIFTY_PARS_OF_TEXT = sb.toString(); + } + @Override public void start(Stage stage) throws Exception { super.start(stage); // insure caret is always visible area.setShowCaret(Caret.CaretVisibility.ON); - - StringBuilder sb = new StringBuilder(); - for (int i = 0; i < 50; i++) { - sb.append(i).append("\n"); - } - area.replaceText(sb.toString()); + area.replaceText(FIFTY_PARS_OF_TEXT); area.moveTo(0); area.showParagraphAtTop(0); } @Test - public void testMoveCaretAndFollowIt() { + public void caret_bounds_are_present_after_moving_caret_and_following_it() { assertTrue(area.getCaretBounds().isPresent()); // move caret outside of viewport @@ -43,7 +49,7 @@ public void testMoveCaretAndFollowIt() { } @Test - public void testMoveCaretWithoutFollowingIt() { + public void caret_bounds_are_absent_after_moving_caret_without_following_it() { assertTrue(area.getCaretBounds().isPresent()); // move caret outside of viewport diff --git a/richtextfx/src/integrationTest/java/org/fxmisc/richtext/api/CharacterBoundsTest.java b/richtextfx/src/integrationTest/java/org/fxmisc/richtext/api/CharacterBoundsTest.java index 72813fab0..580f57b35 100644 --- a/richtextfx/src/integrationTest/java/org/fxmisc/richtext/api/CharacterBoundsTest.java +++ b/richtextfx/src/integrationTest/java/org/fxmisc/richtext/api/CharacterBoundsTest.java @@ -16,7 +16,7 @@ public void start(Stage stage) throws Exception { } @Test - public void selectionBoundsUnchangedWhenCallGetCharacterBounds() { + public void selection_bounds_are_unchanged_when_call_getCharacterBounds() { area.selectAll(); Bounds bounds = area.getSelectionBounds().get(); diff --git a/richtextfx/src/integrationTest/java/org/fxmisc/richtext/api/ClipboardTests.java b/richtextfx/src/integrationTest/java/org/fxmisc/richtext/api/ClipboardTests.java index 127ab3744..8d27c9bfe 100644 --- a/richtextfx/src/integrationTest/java/org/fxmisc/richtext/api/ClipboardTests.java +++ b/richtextfx/src/integrationTest/java/org/fxmisc/richtext/api/ClipboardTests.java @@ -30,7 +30,7 @@ public void start(Stage primaryStage) throws Exception { } - public class WhenUserMakesSelectionEndingInNewLineCharacter { + public class When_User_Makes_Selection_Ending_In_Newline_Character { @Before public void setup() { @@ -38,7 +38,7 @@ public void setup() { } @Test - public void copyingShouldNotThrowException() { + public void copying_and_pasting_should_not_throw_exception() { push(CONTROL, C); push(CONTROL, V); diff --git a/richtextfx/src/integrationTest/java/org/fxmisc/richtext/api/HitTests.java b/richtextfx/src/integrationTest/java/org/fxmisc/richtext/api/HitTests.java index a0f0508e9..4ec7ef34c 100644 --- a/richtextfx/src/integrationTest/java/org/fxmisc/richtext/api/HitTests.java +++ b/richtextfx/src/integrationTest/java/org/fxmisc/richtext/api/HitTests.java @@ -50,9 +50,9 @@ private void moveCaretToAreaEnd() { area.moveTo(area.getLength()); } - public class WhenAreaIsPadded { + public class When_Area_Is_Padded { - public class AndHitsOccurOutsideArea { + public class And_Hits_Occur_Outside_Area { String text = "text"; String fullText = text + "\n" + text; @@ -63,7 +63,7 @@ public void setup() { } @Test - public void clickingInTopPaddingMovesCaretToTopLine() { + public void clicking_in_top_padding_moves_caret_to_top_line() { interact(() -> area.setPadding(new Insets(PADDING_AMOUNT, 0, 0, 0))); moveCaretToAreaEnd(); @@ -76,7 +76,7 @@ public void clickingInTopPaddingMovesCaretToTopLine() { } @Test - public void clickingInLeftPaddingMovesCaretToBeginningOfLineOnSingleLineParagraph() { + public void clicking_in_left_padding_moves_caret_to_beginning_of_line_on_single_line_paragraph() { interact(() -> area.setPadding(new Insets(0, 0, 0, PADDING_AMOUNT))); moveCaretToAreaEnd(); @@ -85,7 +85,7 @@ public void clickingInLeftPaddingMovesCaretToBeginningOfLineOnSingleLineParagrap } @Test - public void clickingInRightPaddingMovesCaretToEndOfLineOnSingleLineParagraph() { + public void clicking_in_right_padding_moves_caret_to_end_of_line_on_single_line_paragraph() { interact(() -> { area.setPadding(new Insets(0, PADDING_AMOUNT, 0, 0)); area.moveTo(0); @@ -99,7 +99,7 @@ public void clickingInRightPaddingMovesCaretToEndOfLineOnSingleLineParagraph() { } @Test - public void clickingInBottomPaddingMovesCaretToBottomLine() { + public void clicking_in_bottom_padding_moves_caret_to_bottom_line() { interact(() -> { area.setPadding(new Insets(0, 0, PADDING_AMOUNT, 0)); area.moveTo(0); @@ -114,7 +114,7 @@ public void clickingInBottomPaddingMovesCaretToBottomLine() { } - public class AndHitsOccurInsideArea { + public class And_Hits_Occur_Inside_Area { @Before public void setup() { @@ -126,7 +126,7 @@ public void setup() { } @Test - public void clickingCharacterShouldMoveCaretToThatPosition() { + public void clicking_character_should_move_caret_to_that_position() { int start = area.getAbsolutePosition(3, 8); Bounds b = area.getCharacterBoundsOnScreen(start, start + 1).get(); moveTo(b).clickOn(PRIMARY); @@ -134,7 +134,7 @@ public void clickingCharacterShouldMoveCaretToThatPosition() { } @Test - public void prevPageMovesCaretToTopOfPage() { + public void prev_page_moves_caret_to_top_of_page() { area.showParagraphAtBottom(area.getParagraphs().size() - 1); // move to last line, column 0 area.moveTo(area.getParagraphs().size() - 1, 0); @@ -149,7 +149,7 @@ public void prevPageMovesCaretToTopOfPage() { } @Test - public void nextPageMovesCaretToBottomOfPage() { + public void next_page_moves_caret_to_bottom_of_page() { area.showParagraphAtTop(0); area.moveTo(0); @@ -166,7 +166,7 @@ public void nextPageMovesCaretToBottomOfPage() { } - public class WhenParagraphBoxIsPadded { + public class When_ParagraphBox_Is_Padded { @Before public void setup() { @@ -184,20 +184,20 @@ private void runTest() { assertEquals(start, area.getCaretPosition()); } - public class AndAreaIsPadded { + public class And_Area_Is_Padded { @Test - public void clickingCharacterShouldMoveCaretToThatPosition() { + public void clicking_character_should_move_caret_to_that_position() { interact(() -> area.setPadding(new Insets(PADDING_AMOUNT))); runTest(); } } - public class AndAreaIsNotPadded { + public class And_Area_Is_Not_Padded { @Test - public void clickingCharacterShouldMoveCaretToThatPosition() { + public void clicking_character_should_move_caret_to_that_position() { runTest(); } diff --git a/richtextfx/src/integrationTest/java/org/fxmisc/richtext/api/MiscellaneousTests.java b/richtextfx/src/integrationTest/java/org/fxmisc/richtext/api/MiscellaneousTests.java index 2d4a4e106..3ced319bf 100644 --- a/richtextfx/src/integrationTest/java/org/fxmisc/richtext/api/MiscellaneousTests.java +++ b/richtextfx/src/integrationTest/java/org/fxmisc/richtext/api/MiscellaneousTests.java @@ -12,7 +12,7 @@ @RunWith(NestedRunner.class) public class MiscellaneousTests { - public class WhenAreaEndsWithEmptyLine extends InlineCssTextAreaAppTest { + public class When_Area_Ends_With_Empty_Line extends InlineCssTextAreaAppTest { @Override public void start(Stage stage) throws Exception { @@ -20,7 +20,7 @@ public void start(Stage stage) throws Exception { area.replaceText(0, 0, "abc\n"); } - public class AndAllTextIsSelected { + public class And_All_Text_Is_Selected { @Before public void selectAllText() { @@ -29,7 +29,7 @@ public void selectAllText() { @Test - public void pressingDeleteShouldNotThrowException() { + public void pressing_delete_should_not_throw_exception() { push(DELETE); } diff --git a/richtextfx/src/integrationTest/java/org/fxmisc/richtext/api/MouseOverTextDelayTests.java b/richtextfx/src/integrationTest/java/org/fxmisc/richtext/api/MouseOverTextDelayTests.java index 986eac5c3..d526c290d 100644 --- a/richtextfx/src/integrationTest/java/org/fxmisc/richtext/api/MouseOverTextDelayTests.java +++ b/richtextfx/src/integrationTest/java/org/fxmisc/richtext/api/MouseOverTextDelayTests.java @@ -50,7 +50,7 @@ private void setDelay(long milliseconds) { } @Test - public void nullDelayNeverFires() { + public void null_delay_never_fires() { setDelay(null); moveTo(firstLineOfArea()).sleep(300); @@ -60,7 +60,7 @@ public void nullDelayNeverFires() { @Ignore("END events are fired multiple times when BEGIN event hasn't yet fired") @Test - public void eventsFireAfterDelayAndPostMove() { + public void events_fire_after_delay_and_post_move() { setDelay(100); moveTo(firstLineOfArea()).sleep(300); @@ -76,7 +76,7 @@ public void eventsFireAfterDelayAndPostMove() { @Ignore("setting delay while mouse is over text fires END event when BEGIN event hasn't yet fired") @Test - public void settingDelayWhileMouseOverTextDoesNotFireEvent() { + public void setting_delay_while_mouse_is_over_text_does_not_fire_event() { setDelay(null); moveTo(firstLineOfArea()).sleep(300); @@ -94,7 +94,7 @@ public void settingDelayWhileMouseOverTextDoesNotFireEvent() { @Ignore("this test is only important when above two tests get fixed") @Test - public void settingDelayBeforeEndFiresPreventsEndFromFiring() { + public void setting_delay_before_end_fires_prevents_end_from_firing() { setDelay(100); moveTo(firstLineOfArea()).sleep(200); diff --git a/richtextfx/src/integrationTest/java/org/fxmisc/richtext/api/ParagraphLinesCountTests.java b/richtextfx/src/integrationTest/java/org/fxmisc/richtext/api/ParagraphLinesCountTests.java index f8d42843e..f4ea1d3e0 100644 --- a/richtextfx/src/integrationTest/java/org/fxmisc/richtext/api/ParagraphLinesCountTests.java +++ b/richtextfx/src/integrationTest/java/org/fxmisc/richtext/api/ParagraphLinesCountTests.java @@ -9,7 +9,7 @@ public class ParagraphLinesCountTests extends InlineCssTextAreaAppTest { @Test - public void multiLineReturnsCorrectCount() { + public void multi_line_returns_correct_count() { String[] lines = { "01 02 03 04 05", "11 12 13 14 15", @@ -25,7 +25,7 @@ public void multiLineReturnsCorrectCount() { } @Test - public void singleLineReturnsOne() { + public void single_line_returns_one() { interact(() -> area.replaceText("some text")); assertFalse(area.isWrapText()); diff --git a/richtextfx/src/integrationTest/java/org/fxmisc/richtext/api/UndoManagerTests.java b/richtextfx/src/integrationTest/java/org/fxmisc/richtext/api/UndoManagerTests.java index a9c162efc..3187e314c 100644 --- a/richtextfx/src/integrationTest/java/org/fxmisc/richtext/api/UndoManagerTests.java +++ b/richtextfx/src/integrationTest/java/org/fxmisc/richtext/api/UndoManagerTests.java @@ -9,7 +9,7 @@ public class UndoManagerTests extends InlineCssTextAreaAppTest { @Test - public void preventMergeOfIncomingChangeAfterPeriodOfUserInactivity() { + public void incoming_change_is_not_merged_after_period_of_user_inactivity() { String text1 = "text1"; String text2 = "text2"; diff --git a/richtextfx/src/integrationTest/java/org/fxmisc/richtext/keyboard/CutCopyPasteTests.java b/richtextfx/src/integrationTest/java/org/fxmisc/richtext/keyboard/CutCopyPasteTests.java index b47af6c71..b27cb6a9a 100644 --- a/richtextfx/src/integrationTest/java/org/fxmisc/richtext/keyboard/CutCopyPasteTests.java +++ b/richtextfx/src/integrationTest/java/org/fxmisc/richtext/keyboard/CutCopyPasteTests.java @@ -32,7 +32,7 @@ public void start(Stage stage) throws Exception { area.replaceText(fullText); } - public class WhenNothingIsSelected { + public class When_Nothing_Is_Selected { @Before public void insureSelectionIsEmpty() { @@ -40,7 +40,7 @@ public void insureSelectionIsEmpty() { assertTrue(area.getSelectedText().isEmpty()); } - public class NothingIsStoredInClipboardWhenCopyVia { + public class Nothing_Is_Stored_In_Clipboard_When_Copy_Via { private void runAssert() { interact(() -> assertFalse(Clipboard.getSystemClipboard().hasString())); @@ -59,14 +59,14 @@ public void copy() { } @Test - public void shortcut_C() { + public void shortcut_c() { press(SHORTCUT, C); runAssert(); } @Test - public void shortcut_Insert() { + public void shortcut_insert() { press(SHORTCUT, INSERT); runAssert(); @@ -74,7 +74,7 @@ public void shortcut_Insert() { } - public class NothingIsRemovedInAreaWhenCutVia { + public class Nothing_Is_Removed_In_Area_When_Cut_Via { private void runAssert() { assertEquals(fullText, area.getText()); @@ -88,14 +88,14 @@ public void cut() { } @Test - public void shortcut_X() { + public void shortcut_x() { press(SHORTCUT, X); runAssert(); } @Test - public void shift_Delete() { + public void shift_delete() { press(SHIFT, DELETE); runAssert(); @@ -103,7 +103,7 @@ public void shift_Delete() { } - public class TextIsInsertedInAreaWhenPasteVia { + public class Text_Is_Inserted_In_Area_When_Paste_Via { private void runAssert() { assertEquals(beginning + text + middle + end, area.getText()); @@ -131,14 +131,14 @@ public void paste() { } @Test - public void shortcut_V() { + public void shortcut_v() { press(SHORTCUT, V); runAssert(); } @Test - public void shift_Insert() { + public void shift_insert() { press(SHIFT, INSERT); runAssert(); @@ -146,7 +146,7 @@ public void shift_Insert() { } } - public class WhenTextIsSelected { + public class When_Text_Is_Selected { int startMiddle = beginning.length(); int endMiddle = startMiddle + middle.length(); @@ -157,7 +157,7 @@ public void selectMiddle() { assertEquals(middle, area.getSelectedText()); } - public class SelectionIsStoredInClipboardWhenCopyVia { + public class Selection_Is_Stored_In_Clipboard_When_Copy_Via { private void runAssert() { interact(() -> { @@ -174,14 +174,14 @@ public void copy() { } @Test - public void shortcut_C() { + public void shortcut_c() { press(SHORTCUT, C); runAssert(); } @Test - public void shortcut_Insert() { + public void shortcut_insert() { press(SHORTCUT, INSERT); runAssert(); @@ -189,7 +189,7 @@ public void shortcut_Insert() { } - public class SelectionIsRemovedAndStoredInClipboardWhenCutVia { + public class Selection_Is_Removed_And_Stored_In_Clipboard_When_Cut_Via { private void runAssert() { assertEquals(beginning + end, area.getText()); @@ -212,14 +212,14 @@ public void cut() { } @Test - public void shortcut_X() { + public void shortcut_x() { press(SHORTCUT, X); runAssert(); } @Test - public void shift_Delete() { + public void shift_delete() { press(SHIFT, DELETE); runAssert(); @@ -227,7 +227,7 @@ public void shift_Delete() { } - public class SelectionIsReplacedInAreaWhenPasteVia { + public class Selection_Is_Replaced_In_Area_When_Paste_Via { @Before public void storeTextInClipboard() { @@ -256,14 +256,14 @@ public void paste() { } @Test - public void shortcut_V() { + public void shortcut_v() { press(SHORTCUT, V); runAssert(); } @Test - public void shift_Insert() { + public void shift_insert() { press(SHIFT, INSERT); runAssert(); diff --git a/richtextfx/src/integrationTest/java/org/fxmisc/richtext/keyboard/DeletionTests.java b/richtextfx/src/integrationTest/java/org/fxmisc/richtext/keyboard/DeletionTests.java index 161d0531a..fd0c1db8e 100644 --- a/richtextfx/src/integrationTest/java/org/fxmisc/richtext/keyboard/DeletionTests.java +++ b/richtextfx/src/integrationTest/java/org/fxmisc/richtext/keyboard/DeletionTests.java @@ -31,7 +31,7 @@ private String withoutFirstChar(String s) { return s.substring(1); } - public class WhenShortcutIsDown extends InlineCssTextAreaAppTest { + public class When_Shortcut_Is_Down extends InlineCssTextAreaAppTest { @Override public void start(Stage stage) throws Exception { @@ -42,7 +42,7 @@ public void start(Stage stage) throws Exception { } @Test - public void pressingDeleteRemovesNextWordAndSpace() { + public void pressing_delete_removes_next_word_and_space() { area.moveTo(0); int pos = area.getCaretPosition(); @@ -53,7 +53,7 @@ public void pressingDeleteRemovesNextWordAndSpace() { } @Test - public void pressingBackspaceRemovesPreviousWordAndSpace() { + public void pressing_backspace_removes_previous_word_and_space() { area.end(CLEAR); int pos = area.getCaretPosition(); @@ -64,7 +64,7 @@ public void pressingBackspaceRemovesPreviousWordAndSpace() { } } - public class WhenModifiersAreNotDown extends InlineCssTextAreaAppTest { + public class When_No_Modifiers extends InlineCssTextAreaAppTest { @Override public void start(Stage stage) throws Exception { @@ -73,7 +73,7 @@ public void start(Stage stage) throws Exception { } @Test - public void pressingDeleteRemovesNextChar() { + public void pressing_delete_removes_next_char() { area.moveTo(0); int pos = area.getCaretPosition(); @@ -84,7 +84,7 @@ public void pressingDeleteRemovesNextChar() { } @Test - public void pressingBackspaceRemovesPreviousChar() { + public void pressing_backspace_removes_previous_char() { area.end(CLEAR); int pos = area.getCaretPosition(); diff --git a/richtextfx/src/integrationTest/java/org/fxmisc/richtext/keyboard/PageUpDownTests.java b/richtextfx/src/integrationTest/java/org/fxmisc/richtext/keyboard/PageUpDownTests.java index aef6f6552..a559267d5 100644 --- a/richtextfx/src/integrationTest/java/org/fxmisc/richtext/keyboard/PageUpDownTests.java +++ b/richtextfx/src/integrationTest/java/org/fxmisc/richtext/keyboard/PageUpDownTests.java @@ -14,23 +14,28 @@ public class PageUpDownTests extends InlineCssTextAreaAppTest { - @Override - public void start(Stage stage) throws Exception { - super.start(stage); - - // allow 6 lines to be displayed - stage.setHeight(90); + private static final String EIGHT_LINES; + static { StringBuilder sb = new StringBuilder(); for (int i = 0; i < 8; i++) { sb.append(i).append("\n"); } sb.append(9); - area.replaceText(sb.toString()); + EIGHT_LINES = sb.toString(); + } + + @Override + public void start(Stage stage) throws Exception { + super.start(stage); + + // allow 6 lines to be displayed + stage.setHeight(90); + area.replaceText(EIGHT_LINES); } @Test - public void testPageUp() { + public void page_up_moves_caret_to_top_of_viewport() { interact(() -> { area.moveTo(5, 0); area.requestFollowCaret(); @@ -48,7 +53,7 @@ public void testPageUp() { @Ignore("doesn't work despite 'testShiftPageDown' working fine using the same code") @Test - public void testPageDown() throws Exception { + public void page_down_moves_caret_to_bottom_of_viewport() throws Exception { interact(() -> { area.moveTo(0); area.requestFollowCaret(); @@ -65,7 +70,7 @@ public void testPageDown() throws Exception { } @Test - public void testShiftPageUp() { + public void shift_page_up_moves_caret_to_top_of_viewport_and_makes_selection() { interact(() -> { area.moveTo(5, 0); area.requestFollowCaret(); @@ -82,7 +87,7 @@ public void testShiftPageUp() { } @Test - public void testShiftPageDown() { + public void shift_page_down_moves_caret_to_bottom_of_viewport_and_makes_selection() { interact(() -> { area.moveTo(0); area.requestFollowCaret(); diff --git a/richtextfx/src/integrationTest/java/org/fxmisc/richtext/keyboard/TypingTests.java b/richtextfx/src/integrationTest/java/org/fxmisc/richtext/keyboard/TypingTests.java index cc8c81b5b..88d4e81e2 100644 --- a/richtextfx/src/integrationTest/java/org/fxmisc/richtext/keyboard/TypingTests.java +++ b/richtextfx/src/integrationTest/java/org/fxmisc/richtext/keyboard/TypingTests.java @@ -9,7 +9,7 @@ public class TypingTests extends InlineCssTextAreaAppTest { @Test - public void typingALetterMovesTheCaretAfterThatInsertedLetter() { + public void typing_a_letter_moves_caret_after_the_inserted_letter() { interact(() -> { area.moveTo(0); area.clear(); diff --git a/richtextfx/src/integrationTest/java/org/fxmisc/richtext/keyboard/navigation/MultiLineGridlikeTextTests.java b/richtextfx/src/integrationTest/java/org/fxmisc/richtext/keyboard/navigation/MultiLineGridlikeTextTests.java index 08d43cc11..88a5b6c32 100644 --- a/richtextfx/src/integrationTest/java/org/fxmisc/richtext/keyboard/navigation/MultiLineGridlikeTextTests.java +++ b/richtextfx/src/integrationTest/java/org/fxmisc/richtext/keyboard/navigation/MultiLineGridlikeTextTests.java @@ -74,7 +74,7 @@ public void start(Stage stage) throws Exception { ); } - public class WhenNoModifiersPressed { + public class When_No_Modifiers_Pressed { @Before public void setup() throws TimeoutException { @@ -127,7 +127,7 @@ public void end_moves_caret_to_end_of_current_line() { } - public class WhenShortcutIsPressed { + public class When_Shortcut_Is_Pressed { @Before public void setup() throws TimeoutException { @@ -183,7 +183,7 @@ public void end_moves_caret_to_end_of_current_paragraph() { } - public class WhenShiftIsPressed { + public class When_Shift_Is_Pressed { @Before public void setup() throws TimeoutException { @@ -238,7 +238,7 @@ public void end_selects_up_to_the_end_of_current_line() { } - public class ShortcutShiftDown { + public class When_Shortcut_And_Shift_Pressed { @Before public void setup() throws TimeoutException { diff --git a/richtextfx/src/integrationTest/java/org/fxmisc/richtext/keyboard/navigation/MultiLineJaggedTextTests.java b/richtextfx/src/integrationTest/java/org/fxmisc/richtext/keyboard/navigation/MultiLineJaggedTextTests.java index b2dd34d2f..9a76fc5af 100644 --- a/richtextfx/src/integrationTest/java/org/fxmisc/richtext/keyboard/navigation/MultiLineJaggedTextTests.java +++ b/richtextfx/src/integrationTest/java/org/fxmisc/richtext/keyboard/navigation/MultiLineJaggedTextTests.java @@ -38,7 +38,7 @@ private void waitForMultiLineRegistration() throws TimeoutException { } @Test - public void pressingDownMovesCaretToNextLine() throws TimeoutException { + public void pressing_down_moves_caret_to_next_line() throws TimeoutException { waitForMultiLineRegistration(); area.moveTo(27); @@ -49,7 +49,7 @@ public void pressingDownMovesCaretToNextLine() throws TimeoutException { } @Test - public void pressingUpMovesCaretToPrevLine() throws TimeoutException { + public void pressing_up_moves_caret_to_previous_line() throws TimeoutException { waitForMultiLineRegistration(); area.moveTo(66); diff --git a/richtextfx/src/integrationTest/java/org/fxmisc/richtext/keyboard/navigation/SingleLineTests.java b/richtextfx/src/integrationTest/java/org/fxmisc/richtext/keyboard/navigation/SingleLineTests.java index 5536960f8..365d28153 100644 --- a/richtextfx/src/integrationTest/java/org/fxmisc/richtext/keyboard/navigation/SingleLineTests.java +++ b/richtextfx/src/integrationTest/java/org/fxmisc/richtext/keyboard/navigation/SingleLineTests.java @@ -42,7 +42,7 @@ public void start(Stage stage) throws Exception { area.replaceText(fullText); } - public class WhenNoModifiersPressed { + public class When_No_Modifiers_Pressed { @Test public void left_moves_caret_one_position() { @@ -68,7 +68,7 @@ public void right_moves_caret_one_position() { } - public class WhenShortcutIsPressed { + public class When_Shortcut_Is_Pressed { @Before public void setup() { @@ -132,7 +132,7 @@ public void a_selects_all() { } - public class WhenShiftIsPressed { + public class When_Shift_Is_Pressed { @Before public void setup() { @@ -163,7 +163,7 @@ public void right_selects_next_character() { } - public class WhenShortcutShiftIsPressed { + public class When_Shortcut_And_Shift_Pressed { @Before public void setup() { diff --git a/richtextfx/src/integrationTest/java/org/fxmisc/richtext/mouse/ClickAndDragTests.java b/richtextfx/src/integrationTest/java/org/fxmisc/richtext/mouse/ClickAndDragTests.java index bc2a576bd..5ab298ea5 100644 --- a/richtextfx/src/integrationTest/java/org/fxmisc/richtext/mouse/ClickAndDragTests.java +++ b/richtextfx/src/integrationTest/java/org/fxmisc/richtext/mouse/ClickAndDragTests.java @@ -15,7 +15,7 @@ @RunWith(NestedRunner.class) public class ClickAndDragTests { - public class WhenAreaIsDisabled extends InlineCssTextAreaAppTest { + public class When_Area_Is_Disabled extends InlineCssTextAreaAppTest { @Override public void start(Stage stage) throws Exception { @@ -26,7 +26,7 @@ public void start(Stage stage) throws Exception { } @Test - public void shiftClickingAreaDoesNothing() { + public void shift_clicking_area_does_nothing() { moveTo(firstLineOfArea()) .moveBy(20, 0) .press(SHIFT) @@ -36,28 +36,28 @@ public void shiftClickingAreaDoesNothing() { } @Test - public void singleClickingAreaDoesNothing() { + public void single_clicking_area_does_nothing() { leftClickOnFirstLine(); assertFalse(area.isFocused()); } @Test - public void doubleClickingAreaDoesNothing() { + public void double_clicking_area_does_nothing() { doubleClickOnFirstLine(); assertFalse(area.isFocused()); } @Test - public void tripleClickingAreaDoesNothing() { + public void triple_clicking_area_does_nothing() { tripleClickOnFirstLine(); assertFalse(area.isFocused()); } @Test - public void draggingTheMouseDoesNotSelectText() { + public void dragging_the_mouse_does_not_select_text() { moveTo(firstLineOfArea()) .press(PRIMARY) .moveBy(20, 0); @@ -66,7 +66,7 @@ public void draggingTheMouseDoesNotSelectText() { } @Test - public void releasingTheMouseAfterDragDoesNothing() { + public void releasing_the_mouse_after_drag_does_nothing() { assertEquals(0, area.getCaretPosition()); moveTo(firstLineOfArea()) @@ -78,9 +78,9 @@ public void releasingTheMouseAfterDragDoesNothing() { } - public class WhenAreaIsEnabled { + public class When_Area_Is_Enabled { - public class AndTextIsNotSelected extends InlineCssTextAreaAppTest { + public class And_Text_Is_Not_Selected extends InlineCssTextAreaAppTest { private String firstWord = "Some"; private String firstParagraph = firstWord + " text goes here"; @@ -93,7 +93,7 @@ public void start(Stage stage) throws Exception { } @Test - public void singleClickingAreaMovesCaretToThatPosition() { + public void single_clicking_area_moves_caret_to_that_position() { assertEquals(0, area.getCaretPosition()); moveTo(firstLineOfArea()) @@ -104,21 +104,21 @@ public void singleClickingAreaMovesCaretToThatPosition() { } @Test - public void doubleClickingTextInAreaSelectsClosestWord() { + public void double_clicking_text_in_area_selects_closest_word() { doubleClickOnFirstLine(); assertEquals(firstWord, area.getSelectedText()); } @Test - public void tripleClickingLineInAreaSelectsParagraph() { + public void triple_clicking_line_in_area_selects_paragraph() { tripleClickOnFirstLine(); assertEquals(firstParagraph, area.getSelectedText()); } @Test - public void pressingMouseOverTextAndDraggingMouseSelectsText() { + public void pressing_mouse_over_text_and_dragging_mouse_selects_text() { moveTo(firstLineOfArea()) .press(PRIMARY) .moveBy(20, 0); @@ -128,14 +128,14 @@ public void pressingMouseOverTextAndDraggingMouseSelectsText() { } - public class AndTextIsSelected extends InlineCssTextAreaAppTest { + public class And_Text_Is_Selected extends InlineCssTextAreaAppTest { private String firstWord = "Some"; private String firstParagraph = firstWord + " text goes here"; private String extraText = "This is extra text"; @Test - public void singleClickingWithinSelectedTextMovesCaretToThatPosition() { + public void single_clicking_within_selected_text_moves_caret_to_that_position() { // setup interact(() -> { area.replaceText(firstParagraph); @@ -150,7 +150,7 @@ public void singleClickingWithinSelectedTextMovesCaretToThatPosition() { } @Test - public void doubleClickingWithinSelectedTextSelectsClosestWord() { + public void double_clicking_within_selected_text_selects_closest_word() { // setup interact(() -> { area.replaceText(firstParagraph); @@ -163,7 +163,7 @@ public void doubleClickingWithinSelectedTextSelectsClosestWord() { } @Test - public void tripleClickingWithinSelectedTextSelectsParagraph() { + public void triple_clicking_within_selected_text_selects_paragraph() { // setup interact(() -> { area.replaceText(firstParagraph); @@ -176,7 +176,7 @@ public void tripleClickingWithinSelectedTextSelectsParagraph() { } @Test - public void singleClickingOutsideOfSelectedTextMovesCaretToThatPosition() { + public void single_clicking_outside_of_selected_text_moves_caret_to_that_position() { // setup interact(() -> { area.replaceText(firstParagraph + "\n" + "this is the selected text"); @@ -193,7 +193,7 @@ public void singleClickingOutsideOfSelectedTextMovesCaretToThatPosition() { } @Test - public void doubleClickingOutsideOfSelectedTextSelectsClosestWord() { + public void double_clicking_outside_of_selected_text_selects_closest_word() { // setup interact(() -> { area.replaceText(firstParagraph + "\n" + "this is the selected text"); @@ -206,7 +206,7 @@ public void doubleClickingOutsideOfSelectedTextSelectsClosestWord() { } @Test - public void tripleClickingOutsideOfSelectedTextSelectsParagraph() { + public void triple_clicking_outside_of_selected_text_selects_paragraph() { // setup interact(() -> { area.replaceText(firstParagraph + "\n" + "this is the selected text"); @@ -219,7 +219,7 @@ public void tripleClickingOutsideOfSelectedTextSelectsParagraph() { } @Test - public void pressingMouseOnUnselectedTextAndDraggingMakesNewSelection() { + public void pressing_mouse_on_unselected_text_and_dragging_makes_new_selection() { // setup interact(() -> { area.replaceText(firstParagraph + "\n" + "this is the selected text"); @@ -236,7 +236,7 @@ public void pressingMouseOnUnselectedTextAndDraggingMakesNewSelection() { } @Test - public void pressingMouseOnSelectionAndDraggingDisplacesCaret() { + public void pressing_mouse_on_selection_and_dragging_displaces_caret() { // setup interact(() -> { area.replaceText(firstParagraph + "\n" + extraText); @@ -254,7 +254,7 @@ public void pressingMouseOnSelectionAndDraggingDisplacesCaret() { } @Test - public void pressingMouseOnSelectionAndDraggingAndReleasingMovesSelectedTextToThatPosition() { + public void pressing_mouse_on_selection_and_dragging_and_releasing_moves_selected_text_to_that_position() { // setup interact(() -> { area.replaceText(firstParagraph + "\n" + extraText); diff --git a/richtextfx/src/integrationTest/java/org/fxmisc/richtext/mouse/ContextMenuTests.java b/richtextfx/src/integrationTest/java/org/fxmisc/richtext/mouse/ContextMenuTests.java index 9851fdf18..010dde521 100644 --- a/richtextfx/src/integrationTest/java/org/fxmisc/richtext/mouse/ContextMenuTests.java +++ b/richtextfx/src/integrationTest/java/org/fxmisc/richtext/mouse/ContextMenuTests.java @@ -36,7 +36,7 @@ public void cleanup() { } @Test - public void clickingSecondaryShowsContextMenu() { + public void clicking_secondary_shows_context_menu() { // Linux passes; Mac fails; Windows untested // so for now, only run on Linux // TODO: See if tests pass on Windows @@ -50,7 +50,7 @@ public void clickingSecondaryShowsContextMenu() { } @Test - public void pressingSecondaryShowsContextMenu() { + public void pressing_secondary_shows_context_menu() { // Linux passes; Mac fails; Windows untested // so for now, only run on Linux // TODO: See if tests pass on Windows @@ -64,7 +64,7 @@ public void pressingSecondaryShowsContextMenu() { } @Test - public void pressingPrimaryMouseButtonHidesContextMenu() { + public void pressing_primary_mouse_button_hides_context_menu() { // given menu is showing showContextMenuAt(); @@ -74,7 +74,7 @@ public void pressingPrimaryMouseButtonHidesContextMenu() { } @Test - public void pressingMiddleMouseButtonHidesContextMenu() { + public void pressing_middle_mouse_button_hides_context_menu() { // given menu is showing showContextMenuAt(); @@ -84,7 +84,7 @@ public void pressingMiddleMouseButtonHidesContextMenu() { } @Test - public void requestingContextMenuViaKeyboardWorksOnWindows() { + public void requesting_context_nenu_via_keyboard_works_on_windows() { run_only_on_windows(); leftClickOnFirstLine(); From cff61a4e5f7fd6833e2197db1cc9df03c52b9352 Mon Sep 17 00:00:00 2001 From: Jordan Martinez Date: Sat, 30 Sep 2017 19:12:31 -0700 Subject: [PATCH 12/23] Copy test's testLogging config to integrationTest's config --- richtextfx/build.gradle | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) diff --git a/richtextfx/build.gradle b/richtextfx/build.gradle index 2aefded09..609f6bc7e 100644 --- a/richtextfx/build.gradle +++ b/richtextfx/build.gradle @@ -106,6 +106,35 @@ test { } } +integrationTest { + testLogging { + // Fancy formatting from http://stackoverflow.com/a/36130467/3634630 + // set options for log level LIFECYCLE + events TestLogEvent.PASSED, TestLogEvent.SKIPPED, + TestLogEvent.FAILED, TestLogEvent.STANDARD_OUT + showExceptions true + exceptionFormat TestExceptionFormat.FULL + showCauses true + showStackTraces true + + // set options for log level DEBUG and INFO + debug { + events TestLogEvent.STARTED, TestLogEvent.PASSED, + TestLogEvent.SKIPPED, TestLogEvent.FAILED, + TestLogEvent.STANDARD_OUT, TestLogEvent.STANDARD_ERROR + } + info.events = debug.events + afterSuite { desc, result -> + if (!desc.parent) { // will match the outermost suite + def output = "Results: ${result.resultType} (${result.testCount} tests, ${result.successfulTestCount} successes, ${result.failedTestCount} failures, ${result.skippedTestCount} skipped)" + def startItem = '| ', endItem = ' |' + def repeatLength = startItem.length() + output.length() + endItem.length() + println('\n' + ('-' * repeatLength) + '\n' + startItem + output + endItem + '\n' + ('-' * repeatLength)) + } + } + } +} + task javadocJar(type: Jar, dependsOn: javadoc) { classifier = 'javadoc' from 'build/docs/javadoc' From 8b6c7189853afeaa94132b6d3c56b10edba10ead Mon Sep 17 00:00:00 2001 From: Jordan Martinez Date: Sat, 30 Sep 2017 19:12:53 -0700 Subject: [PATCH 13/23] Allow builds to specify which robot to use --- richtextfx/build.gradle | 1 - 1 file changed, 1 deletion(-) diff --git a/richtextfx/build.gradle b/richtextfx/build.gradle index 609f6bc7e..d53d1a313 100644 --- a/richtextfx/build.gradle +++ b/richtextfx/build.gradle @@ -20,7 +20,6 @@ testSets { check.dependsOn integrationTest integrationTest.mustRunAfter test -integrationTest.systemProperty "testfx.robot", "glass" if (gradle.gradleVersion.substring(0, 1) >= "4") { // required for Gradle 4 to see custom integrationTest test suite integrationTest.testClassesDirs = sourceSets.integrationTest.output.classesDirs From 249d2971185bc120bb986f754fe7275f25db0b75 Mon Sep 17 00:00:00 2001 From: Jordan Martinez Date: Sat, 30 Sep 2017 19:27:43 -0700 Subject: [PATCH 14/23] Move test to more appropriate test file; include backspace counterpart --- .../richtext/api/MiscellaneousTests.java | 38 ------------------- .../richtext/keyboard/DeletionTests.java | 32 ++++++++++++++++ 2 files changed, 32 insertions(+), 38 deletions(-) delete mode 100644 richtextfx/src/integrationTest/java/org/fxmisc/richtext/api/MiscellaneousTests.java diff --git a/richtextfx/src/integrationTest/java/org/fxmisc/richtext/api/MiscellaneousTests.java b/richtextfx/src/integrationTest/java/org/fxmisc/richtext/api/MiscellaneousTests.java deleted file mode 100644 index 3ced319bf..000000000 --- a/richtextfx/src/integrationTest/java/org/fxmisc/richtext/api/MiscellaneousTests.java +++ /dev/null @@ -1,38 +0,0 @@ -package org.fxmisc.richtext.api; - -import com.nitorcreations.junit.runners.NestedRunner; -import javafx.stage.Stage; -import org.fxmisc.richtext.InlineCssTextAreaAppTest; -import org.junit.Before; -import org.junit.Test; -import org.junit.runner.RunWith; - -import static javafx.scene.input.KeyCode.DELETE; - -@RunWith(NestedRunner.class) -public class MiscellaneousTests { - - public class When_Area_Ends_With_Empty_Line extends InlineCssTextAreaAppTest { - - @Override - public void start(Stage stage) throws Exception { - super.start(stage); - area.replaceText(0, 0, "abc\n"); - } - - public class And_All_Text_Is_Selected { - - @Before - public void selectAllText() { - interact(() -> area.selectAll()); - } - - - @Test - public void pressing_delete_should_not_throw_exception() { - push(DELETE); - } - - } - } -} diff --git a/richtextfx/src/integrationTest/java/org/fxmisc/richtext/keyboard/DeletionTests.java b/richtextfx/src/integrationTest/java/org/fxmisc/richtext/keyboard/DeletionTests.java index fd0c1db8e..e90c9fcbb 100644 --- a/richtextfx/src/integrationTest/java/org/fxmisc/richtext/keyboard/DeletionTests.java +++ b/richtextfx/src/integrationTest/java/org/fxmisc/richtext/keyboard/DeletionTests.java @@ -3,6 +3,7 @@ import com.nitorcreations.junit.runners.NestedRunner; import javafx.stage.Stage; import org.fxmisc.richtext.InlineCssTextAreaAppTest; +import org.junit.Before; import org.junit.Test; import org.junit.runner.RunWith; @@ -95,4 +96,35 @@ public void pressing_backspace_removes_previous_char() { } } + + // miscellaneous cases + + public class When_Area_Ends_With_Empty_Line extends InlineCssTextAreaAppTest { + + @Override + public void start(Stage stage) throws Exception { + super.start(stage); + area.replaceText(0, 0, "abc\n"); + } + + public class And_All_Text_Is_Selected { + + @Before + public void selectAllText() { + interact(() -> area.selectAll()); + } + + + @Test + public void pressing_delete_should_not_throw_exception() { + push(DELETE); + } + + @Test + public void pressing_backspace_should_not_throw_exceptions() { + push(BACK_SPACE); + } + + } + } } From efe4239c14f7352057864d29c201a62265749573 Mon Sep 17 00:00:00 2001 From: Jordan Martinez Date: Sat, 30 Sep 2017 19:29:27 -0700 Subject: [PATCH 15/23] Move miscellaneous case to more appropriate test file --- .../fxmisc/richtext/api/ClipboardTests.java | 49 ------------------- .../richtext/keyboard/CutCopyPasteTests.java | 35 +++++++++++++ 2 files changed, 35 insertions(+), 49 deletions(-) delete mode 100644 richtextfx/src/integrationTest/java/org/fxmisc/richtext/api/ClipboardTests.java diff --git a/richtextfx/src/integrationTest/java/org/fxmisc/richtext/api/ClipboardTests.java b/richtextfx/src/integrationTest/java/org/fxmisc/richtext/api/ClipboardTests.java deleted file mode 100644 index 8d27c9bfe..000000000 --- a/richtextfx/src/integrationTest/java/org/fxmisc/richtext/api/ClipboardTests.java +++ /dev/null @@ -1,49 +0,0 @@ -package org.fxmisc.richtext.api; - -import com.nitorcreations.junit.runners.NestedRunner; -import javafx.scene.Scene; -import javafx.stage.Stage; -import org.fxmisc.flowless.VirtualizedScrollPane; -import org.fxmisc.richtext.CodeArea; -import org.junit.Before; -import org.junit.Test; -import org.junit.runner.RunWith; -import org.testfx.framework.junit.ApplicationTest; - -import static javafx.scene.input.KeyCode.*; - -@RunWith(NestedRunner.class) -public class ClipboardTests { - - public class CopyTests extends ApplicationTest { - - CodeArea area; - - @Override - public void start(Stage primaryStage) throws Exception { - area = new CodeArea("abc\ndef\nghi"); - VirtualizedScrollPane vsPane = new VirtualizedScrollPane<>(area); - - Scene scene = new Scene(vsPane, 400, 400); - primaryStage.setScene(scene); - primaryStage.show(); - } - - - public class When_User_Makes_Selection_Ending_In_Newline_Character { - - @Before - public void setup() { - area.selectRange(2, 4); - } - - @Test - public void copying_and_pasting_should_not_throw_exception() { - push(CONTROL, C); - - push(CONTROL, V); - } - } - } - -} diff --git a/richtextfx/src/integrationTest/java/org/fxmisc/richtext/keyboard/CutCopyPasteTests.java b/richtextfx/src/integrationTest/java/org/fxmisc/richtext/keyboard/CutCopyPasteTests.java index b27cb6a9a..2e179ca48 100644 --- a/richtextfx/src/integrationTest/java/org/fxmisc/richtext/keyboard/CutCopyPasteTests.java +++ b/richtextfx/src/integrationTest/java/org/fxmisc/richtext/keyboard/CutCopyPasteTests.java @@ -1,14 +1,18 @@ package org.fxmisc.richtext.keyboard; import com.nitorcreations.junit.runners.NestedRunner; +import javafx.scene.Scene; import javafx.scene.input.Clipboard; import javafx.scene.input.ClipboardContent; import javafx.stage.Stage; +import org.fxmisc.flowless.VirtualizedScrollPane; +import org.fxmisc.richtext.CodeArea; import org.fxmisc.richtext.InlineCssTextAreaAppTest; import org.junit.Before; import org.junit.Ignore; import org.junit.Test; import org.junit.runner.RunWith; +import org.testfx.framework.junit.ApplicationTest; import static javafx.scene.input.KeyCode.*; import static junit.framework.TestCase.assertEquals; @@ -271,4 +275,35 @@ public void shift_insert() { } } + + public class MiscellaneousCases extends ApplicationTest { + + CodeArea area; + + @Override + public void start(Stage primaryStage) throws Exception { + area = new CodeArea("abc\ndef\nghi"); + VirtualizedScrollPane vsPane = new VirtualizedScrollPane<>(area); + + Scene scene = new Scene(vsPane, 400, 400); + primaryStage.setScene(scene); + primaryStage.show(); + } + + public class When_User_Makes_Selection_Ending_In_Newline_Character { + + @Before + public void setup() { + area.selectRange(2, 4); + } + + @Test + public void copying_and_pasting_should_not_throw_exception() { + push(CONTROL, C); + + push(CONTROL, V); + } + } + } + } \ No newline at end of file From c2d2f97d4ed0cb48825062eb89da59dcd1dc8397 Mon Sep 17 00:00:00 2001 From: Jordan Martinez Date: Sat, 30 Sep 2017 19:34:16 -0700 Subject: [PATCH 16/23] Correct test name: care does not move when shortcut is down --- .../keyboard/navigation/MultiLineGridlikeTextTests.java | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/richtextfx/src/integrationTest/java/org/fxmisc/richtext/keyboard/navigation/MultiLineGridlikeTextTests.java b/richtextfx/src/integrationTest/java/org/fxmisc/richtext/keyboard/navigation/MultiLineGridlikeTextTests.java index 88a5b6c32..6afc0ba0e 100644 --- a/richtextfx/src/integrationTest/java/org/fxmisc/richtext/keyboard/navigation/MultiLineGridlikeTextTests.java +++ b/richtextfx/src/integrationTest/java/org/fxmisc/richtext/keyboard/navigation/MultiLineGridlikeTextTests.java @@ -136,9 +136,8 @@ public void setup() throws TimeoutException { press(SHORTCUT); } - // up/down do nothing @Test - public void up_moves_caret_to_previous_line() { + public void up_does_not_move_caret() { assertTrue(area.getSelectedText().isEmpty()); moveCaretTo(lineStart(2)); @@ -149,7 +148,7 @@ public void up_moves_caret_to_previous_line() { } @Test - public void down_moves_caret_to_next_line() { + public void down_does_not_move_caret() { assertTrue(area.getSelectedText().isEmpty()); moveCaretTo(lineStart(2)); @@ -248,7 +247,7 @@ public void setup() throws TimeoutException { } @Test - public void up() { + public void up_does_not_move_caret() { moveCaretTo(lineStart(2)); assertTrue(area.getSelectedText().isEmpty()); @@ -259,7 +258,7 @@ public void up() { } @Test - public void down() { + public void down_does_not_move_caret() { moveCaretTo(lineStart(1)); assertTrue(area.getSelectedText().isEmpty()); From fe65d3f6f9edf4306de23392255b4e67c26212fb Mon Sep 17 00:00:00 2001 From: Jordan Martinez Date: Sat, 30 Sep 2017 19:54:00 -0700 Subject: [PATCH 17/23] Clear clipboard before tests to insure no interference --- .../java/org/fxmisc/richtext/keyboard/CutCopyPasteTests.java | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/richtextfx/src/integrationTest/java/org/fxmisc/richtext/keyboard/CutCopyPasteTests.java b/richtextfx/src/integrationTest/java/org/fxmisc/richtext/keyboard/CutCopyPasteTests.java index 2e179ca48..8c3748019 100644 --- a/richtextfx/src/integrationTest/java/org/fxmisc/richtext/keyboard/CutCopyPasteTests.java +++ b/richtextfx/src/integrationTest/java/org/fxmisc/richtext/keyboard/CutCopyPasteTests.java @@ -156,9 +156,10 @@ public class When_Text_Is_Selected { int endMiddle = startMiddle + middle.length(); @Before - public void selectMiddle() { + public void selectMiddleAndClearClipboard() { area.selectRange(startMiddle, endMiddle); assertEquals(middle, area.getSelectedText()); + interact(() -> Clipboard.getSystemClipboard().clear()); } public class Selection_Is_Stored_In_Clipboard_When_Copy_Via { From 621626473ce4ce7b94b2b2e7144c9e2a9057898e Mon Sep 17 00:00:00 2001 From: Jordan Martinez Date: Sat, 30 Sep 2017 20:26:25 -0700 Subject: [PATCH 18/23] Add the right index number to the line of text --- .../java/org/fxmisc/richtext/keyboard/PageUpDownTests.java | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/richtextfx/src/integrationTest/java/org/fxmisc/richtext/keyboard/PageUpDownTests.java b/richtextfx/src/integrationTest/java/org/fxmisc/richtext/keyboard/PageUpDownTests.java index a559267d5..8f9c3fcf3 100644 --- a/richtextfx/src/integrationTest/java/org/fxmisc/richtext/keyboard/PageUpDownTests.java +++ b/richtextfx/src/integrationTest/java/org/fxmisc/richtext/keyboard/PageUpDownTests.java @@ -18,10 +18,11 @@ public class PageUpDownTests extends InlineCssTextAreaAppTest { static { StringBuilder sb = new StringBuilder(); - for (int i = 0; i < 8; i++) { + int totalLines = 8; + for (int i = 0; i < totalLines - 1; i++) { sb.append(i).append("\n"); } - sb.append(9); + sb.append(totalLines); EIGHT_LINES = sb.toString(); } From a9036e586cd1fc523ad7a26e5da46c40679a8cc7 Mon Sep 17 00:00:00 2001 From: Jordan Martinez Date: Sat, 30 Sep 2017 20:28:55 -0700 Subject: [PATCH 19/23] Use character bounds to test for more accurate caret position --- .../richtext/mouse/ClickAndDragTests.java | 63 ++++++++++++------- 1 file changed, 40 insertions(+), 23 deletions(-) diff --git a/richtextfx/src/integrationTest/java/org/fxmisc/richtext/mouse/ClickAndDragTests.java b/richtextfx/src/integrationTest/java/org/fxmisc/richtext/mouse/ClickAndDragTests.java index 5ab298ea5..7d2a4f715 100644 --- a/richtextfx/src/integrationTest/java/org/fxmisc/richtext/mouse/ClickAndDragTests.java +++ b/richtextfx/src/integrationTest/java/org/fxmisc/richtext/mouse/ClickAndDragTests.java @@ -1,6 +1,7 @@ package org.fxmisc.richtext.mouse; import com.nitorcreations.junit.runners.NestedRunner; +import javafx.geometry.Bounds; import javafx.stage.Stage; import org.fxmisc.richtext.InlineCssTextAreaAppTest; import org.junit.Test; @@ -96,11 +97,12 @@ public void start(Stage stage) throws Exception { public void single_clicking_area_moves_caret_to_that_position() { assertEquals(0, area.getCaretPosition()); - moveTo(firstLineOfArea()) - .moveBy(20, 0) - .clickOn(PRIMARY); + Bounds bounds = area.getCharacterBoundsOnScreen( + firstWord.length(), firstWord.length() + 1).get(); + + moveTo(bounds).clickOn(PRIMARY); - assertTrue(0 != area.getCaretPosition()); + assertEquals(firstWord.length(), area.getCaretPosition()); } @Test @@ -142,11 +144,12 @@ public void single_clicking_within_selected_text_moves_caret_to_that_position() area.selectAll(); }); - moveTo(firstLineOfArea()) - .moveBy(20, 0) - .clickOn(PRIMARY); + Bounds bounds = area.getCharacterBoundsOnScreen( + firstWord.length(), firstWord.length() + 1).get(); + + moveTo(bounds).clickOn(PRIMARY); - assertTrue(0 != area.getCaretPosition()); + assertEquals(firstWord.length(), area.getCaretPosition()); } @Test @@ -183,13 +186,12 @@ public void single_clicking_outside_of_selected_text_moves_caret_to_that_positio area.selectRange(1, 0, 2, -1); }); - int caretPos = area.getCaretPosition(); + Bounds bounds = area.getCharacterBoundsOnScreen( + firstWord.length(), firstWord.length() + 1).get(); - moveTo(firstLineOfArea()) - .moveBy(20, 0) - .clickOn(PRIMARY); + moveTo(bounds).clickOn(PRIMARY); - assertTrue(caretPos != area.getCaretPosition()); + assertEquals(firstWord.length(), area.getCaretPosition()); } @Test @@ -240,37 +242,52 @@ public void pressing_mouse_on_selection_and_dragging_displaces_caret() { // setup interact(() -> { area.replaceText(firstParagraph + "\n" + extraText); - area.selectRange(0, firstWord.length()); + area.selectRange(0, firstParagraph.length()); }); String selText = area.getSelectedText(); - moveTo(firstLineOfArea()) - .press(PRIMARY) - .moveBy(0, 22); + interact(() -> { + area.caretPositionProperty().addListener((obs, ov, nv) -> + System.out.println("Changed to: " + nv)); + }); + + Bounds firstLetterBounds = area.getCharacterBoundsOnScreen(1, 2).get(); + Bounds firstWordEndBounds = area.getCharacterBoundsOnScreen( + firstWord.length(), firstWord.length() + 1).get(); + + moveTo(firstLetterBounds) + .clickOn(PRIMARY) + .moveTo(firstWordEndBounds); - assertEquals(firstParagraph.length() + 1, area.getCaretPosition()); + assertEquals(firstWord.length(), area.getCaretPosition()); assertEquals(selText, area.getSelectedText()); } @Test public void pressing_mouse_on_selection_and_dragging_and_releasing_moves_selected_text_to_that_position() { // setup + String twoSpaces = " "; interact(() -> { - area.replaceText(firstParagraph + "\n" + extraText); + area.replaceText(firstParagraph + "\n" + twoSpaces + extraText); area.selectRange(0, firstWord.length()); }); String selText = area.getSelectedText(); - moveTo(firstLineOfArea()) + Bounds letterInFirstWord = area.getCharacterBoundsOnScreen(1, 2).get(); + + int insertionPosition = firstParagraph.length() + 2; + Bounds insertionBounds = area.getCharacterBoundsOnScreen(insertionPosition, insertionPosition + 1).get(); + + moveTo(letterInFirstWord) .press(PRIMARY) - .dropBy(0, 22); + .dropTo(insertionBounds); String expectedText = firstParagraph.substring(firstWord.length()) - + "\n" + firstWord + extraText; + + "\n" + " " + firstWord + " " + extraText; - assertEquals(firstParagraph.length() + 1, area.getCaretPosition()); + assertEquals(insertionPosition, area.getCaretPosition()); assertEquals(selText, area.getSelectedText()); assertEquals(expectedText, area.getText()); } From b7d57342b99ebce964e9846f0cb515eb35919dc5 Mon Sep 17 00:00:00 2001 From: Jordan Martinez Date: Sat, 30 Sep 2017 20:39:36 -0700 Subject: [PATCH 20/23] Fix bug in test code: mouse should not be released before moving again --- .../java/org/fxmisc/richtext/mouse/ClickAndDragTests.java | 7 +------ 1 file changed, 1 insertion(+), 6 deletions(-) diff --git a/richtextfx/src/integrationTest/java/org/fxmisc/richtext/mouse/ClickAndDragTests.java b/richtextfx/src/integrationTest/java/org/fxmisc/richtext/mouse/ClickAndDragTests.java index 7d2a4f715..0c7a23d18 100644 --- a/richtextfx/src/integrationTest/java/org/fxmisc/richtext/mouse/ClickAndDragTests.java +++ b/richtextfx/src/integrationTest/java/org/fxmisc/richtext/mouse/ClickAndDragTests.java @@ -247,17 +247,12 @@ public void pressing_mouse_on_selection_and_dragging_displaces_caret() { String selText = area.getSelectedText(); - interact(() -> { - area.caretPositionProperty().addListener((obs, ov, nv) -> - System.out.println("Changed to: " + nv)); - }); - Bounds firstLetterBounds = area.getCharacterBoundsOnScreen(1, 2).get(); Bounds firstWordEndBounds = area.getCharacterBoundsOnScreen( firstWord.length(), firstWord.length() + 1).get(); moveTo(firstLetterBounds) - .clickOn(PRIMARY) + .press(PRIMARY) .moveTo(firstWordEndBounds); assertEquals(firstWord.length(), area.getCaretPosition()); From 9ee5435322693bd55eb902f6b7592e5c7664be2c Mon Sep 17 00:00:00 2001 From: Jordan Martinez Date: Sat, 30 Sep 2017 20:55:06 -0700 Subject: [PATCH 21/23] Skip COPY test on Linux --- .../java/org/fxmisc/richtext/keyboard/CutCopyPasteTests.java | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/richtextfx/src/integrationTest/java/org/fxmisc/richtext/keyboard/CutCopyPasteTests.java b/richtextfx/src/integrationTest/java/org/fxmisc/richtext/keyboard/CutCopyPasteTests.java index 8c3748019..fa7291919 100644 --- a/richtextfx/src/integrationTest/java/org/fxmisc/richtext/keyboard/CutCopyPasteTests.java +++ b/richtextfx/src/integrationTest/java/org/fxmisc/richtext/keyboard/CutCopyPasteTests.java @@ -173,6 +173,11 @@ private void runAssert() { @Test public void copy() { + // this test fails on Linux; Windows is untested + // so for now, only run on Mac + // TODO: update if test succeeds on Windows, too + run_only_on_mac(); + press(COPY); runAssert(); From 7f4b1646e2c51da8cac75d8d9a049a61b7f31b1f Mon Sep 17 00:00:00 2001 From: Jordan Martinez Date: Sat, 30 Sep 2017 20:59:40 -0700 Subject: [PATCH 22/23] Skip test on Mac until bug/test is fixed --- .../java/org/fxmisc/richtext/mouse/ClickAndDragTests.java | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/richtextfx/src/integrationTest/java/org/fxmisc/richtext/mouse/ClickAndDragTests.java b/richtextfx/src/integrationTest/java/org/fxmisc/richtext/mouse/ClickAndDragTests.java index 0c7a23d18..727b69b83 100644 --- a/richtextfx/src/integrationTest/java/org/fxmisc/richtext/mouse/ClickAndDragTests.java +++ b/richtextfx/src/integrationTest/java/org/fxmisc/richtext/mouse/ClickAndDragTests.java @@ -261,6 +261,11 @@ public void pressing_mouse_on_selection_and_dragging_displaces_caret() { @Test public void pressing_mouse_on_selection_and_dragging_and_releasing_moves_selected_text_to_that_position() { + // Linux passes; Mac fails at "assertEquals(selText, area.getSelectedText())"; Windows is untested + // so only run on Linux + // TODO: update test to see if it works on Windows + run_only_on_linux(); + // setup String twoSpaces = " "; interact(() -> { From b105dc40e0b20da2549e0e4a368bcf55e97ab8e0 Mon Sep 17 00:00:00 2001 From: Jordan Martinez Date: Sat, 30 Sep 2017 21:32:47 -0700 Subject: [PATCH 23/23] No longer ignore some tests since they pass now; fix whitespace issue --- .../org/fxmisc/richtext/keyboard/CutCopyPasteTests.java | 6 ++---- .../java/org/fxmisc/richtext/keyboard/PageUpDownTests.java | 1 - 2 files changed, 2 insertions(+), 5 deletions(-) diff --git a/richtextfx/src/integrationTest/java/org/fxmisc/richtext/keyboard/CutCopyPasteTests.java b/richtextfx/src/integrationTest/java/org/fxmisc/richtext/keyboard/CutCopyPasteTests.java index fa7291919..bd4a65657 100644 --- a/richtextfx/src/integrationTest/java/org/fxmisc/richtext/keyboard/CutCopyPasteTests.java +++ b/richtextfx/src/integrationTest/java/org/fxmisc/richtext/keyboard/CutCopyPasteTests.java @@ -9,7 +9,6 @@ import org.fxmisc.richtext.CodeArea; import org.fxmisc.richtext.InlineCssTextAreaAppTest; import org.junit.Before; -import org.junit.Ignore; import org.junit.Test; import org.junit.runner.RunWith; import org.testfx.framework.junit.ApplicationTest; @@ -210,7 +209,7 @@ private void runAssert() { } @Test - public void cut() { + public void cut() { // this test fails on Linux; Windows is untested // so for now, only run on Mac // TODO: update if test succeeds on Windows, too @@ -252,9 +251,8 @@ private void runAssert() { assertEquals(beginning + text + end, area.getText()); } - @Ignore("Flaky test when all others of equivalent tests pass") @Test - public void paste() { + public void paste() { // this test fails on Linux; Windows is untested // so for now, only run on Mac // TODO: update if test succeeds on Windows, too diff --git a/richtextfx/src/integrationTest/java/org/fxmisc/richtext/keyboard/PageUpDownTests.java b/richtextfx/src/integrationTest/java/org/fxmisc/richtext/keyboard/PageUpDownTests.java index 8f9c3fcf3..782913d9e 100644 --- a/richtextfx/src/integrationTest/java/org/fxmisc/richtext/keyboard/PageUpDownTests.java +++ b/richtextfx/src/integrationTest/java/org/fxmisc/richtext/keyboard/PageUpDownTests.java @@ -52,7 +52,6 @@ public void page_up_moves_caret_to_top_of_viewport() { assertTrue(beforeBounds.getMinY() > afterBounds.getMinY()); } - @Ignore("doesn't work despite 'testShiftPageDown' working fine using the same code") @Test public void page_down_moves_caret_to_bottom_of_viewport() throws Exception { interact(() -> {