|
44 | 44 | import javafx.geometry.Orientation; |
45 | 45 | import javafx.scene.Node; |
46 | 46 | import javafx.scene.Scene; |
| 47 | +import javafx.scene.control.Label; |
47 | 48 | import javafx.scene.control.ScrollBar; |
48 | 49 | import javafx.scene.control.ToggleButton; |
49 | 50 | import javafx.scene.image.ImageView; |
|
65 | 66 | import org.testfx.matcher.base.NodeMatchers; |
66 | 67 |
|
67 | 68 | import java.nio.CharBuffer; |
| 69 | +import java.util.Comparator; |
68 | 70 | import java.util.List; |
69 | 71 | import java.util.Locale; |
70 | 72 | import java.util.concurrent.CountDownLatch; |
@@ -1148,6 +1150,66 @@ public void findMarkdownTest(FxRobot robot) { |
1148 | 1150 | assertEquals(2, rta.getDocument().getDecorations().size()); |
1149 | 1151 | } |
1150 | 1152 |
|
| 1153 | + @Test |
| 1154 | + public void defaultNumberedListTest(FxRobot robot) { |
| 1155 | + run(() -> { |
| 1156 | + String text = "Hello\nRTA"; |
| 1157 | + TextDecoration textDecoration = TextDecoration.builder().presets().fontFamily("Arial").build(); |
| 1158 | + ParagraphDecoration paragraphDecoration = ParagraphDecoration.builder().presets() |
| 1159 | + .graphicType(ParagraphDecoration.GraphicType.NUMBERED_LIST) |
| 1160 | + .indentationLevel(1).build(); |
| 1161 | + Document document = new Document(text, |
| 1162 | + List.of(new DecorationModel(0, text.length(), textDecoration, paragraphDecoration)), text.length()); |
| 1163 | + richTextArea.getActionFactory().open(document).execute(new ActionEvent()); |
| 1164 | + }); |
| 1165 | + waitForFxEvents(); |
| 1166 | + |
| 1167 | + verifyThat(".rich-text-area", node -> node instanceof RichTextArea); |
| 1168 | + List<Node> nodes = getSortedNodes(robot, ".numbered-list-label"); |
| 1169 | + assertEquals(2, nodes.size()); |
| 1170 | + for (int i = 0; i < 2; i++) { |
| 1171 | + assertInstanceOf(Label.class, nodes.get(i)); |
| 1172 | + Label label = (Label) nodes.get(i); |
| 1173 | + assertNotNull(label); |
| 1174 | + assertNotNull(label.getText()); |
| 1175 | + assertEquals(i + 1 + ".", label.getText()); |
| 1176 | + } |
| 1177 | + } |
| 1178 | + |
| 1179 | + @Test |
| 1180 | + public void customNumberedListTest(FxRobot robot) { |
| 1181 | + run(() -> { |
| 1182 | + String text = "Hello\nRTA"; |
| 1183 | + TextDecoration textDecoration = TextDecoration.builder().presets().fontFamily("Arial").build(); |
| 1184 | + ParagraphDecoration paragraphDecoration = ParagraphDecoration.builder().presets() |
| 1185 | + .graphicType(ParagraphDecoration.GraphicType.NUMBERED_LIST) |
| 1186 | + .indentationLevel(1).build(); |
| 1187 | + Document document = new Document(text, |
| 1188 | + List.of(new DecorationModel(0, text.length(), textDecoration, paragraphDecoration)), text.length()); |
| 1189 | + richTextArea.setParagraphGraphicFactory((i, t) -> { |
| 1190 | + if (i < 1) { |
| 1191 | + return null; |
| 1192 | + } |
| 1193 | + Text textNode = new Text("#"); |
| 1194 | + textNode.getStyleClass().add("numbered-list-text"); |
| 1195 | + return textNode; |
| 1196 | + }); |
| 1197 | + richTextArea.getActionFactory().open(document).execute(new ActionEvent()); |
| 1198 | + }); |
| 1199 | + waitForFxEvents(); |
| 1200 | + |
| 1201 | + verifyThat(".rich-text-area", node -> node instanceof RichTextArea); |
| 1202 | + List<Node> nodes = getSortedNodes(robot, ".numbered-list-text"); |
| 1203 | + assertEquals(2, nodes.size()); |
| 1204 | + for (int i = 0; i < 2; i++) { |
| 1205 | + assertInstanceOf(Text.class, nodes.get(i)); |
| 1206 | + Text textNode = (Text) nodes.get(i); |
| 1207 | + assertNotNull(textNode); |
| 1208 | + assertNotNull(textNode.getText()); |
| 1209 | + assertEquals(String.valueOf(i + 1), textNode.getText()); |
| 1210 | + } |
| 1211 | + } |
| 1212 | + |
1151 | 1213 | private static void findEmoji(String text, BiConsumer<Emoji, Integer> onCodeNameFound) { |
1152 | 1214 | if (text.endsWith(" ")) { |
1153 | 1215 | return; |
@@ -1208,6 +1270,12 @@ private String getInternalText(Document document, int end) { |
1208 | 1270 | return internalSb.toString(); |
1209 | 1271 | } |
1210 | 1272 |
|
| 1273 | + private static List<Node> getSortedNodes(FxRobot robot, String query) { |
| 1274 | + return robot.lookup(query).queryAllAs(Node.class).stream() |
| 1275 | + .sorted(Comparator.comparingDouble(s -> s.localToScene(s.getLayoutBounds()).getMinY())) |
| 1276 | + .collect(Collectors.toList()); |
| 1277 | + } |
| 1278 | + |
1211 | 1279 | private void run(Runnable runnable) { |
1212 | 1280 | CountDownLatch countDownLatch = new CountDownLatch(1); |
1213 | 1281 | Platform.runLater(() -> { |
|
0 commit comments