|
1 | 1 | /* |
2 | | - * Copyright (c) 2024, Gluon |
| 2 | + * Copyright (c) 2024, 2025, Gluon |
3 | 3 | * |
4 | 4 | * This program is free software: you can redistribute it and/or modify |
5 | 5 | * it under the terms of the GNU General Public License as published by |
|
41 | 41 | import com.gluonhq.richtextarea.model.TextDecoration; |
42 | 42 | import javafx.application.Platform; |
43 | 43 | import javafx.event.ActionEvent; |
| 44 | +import javafx.geometry.Orientation; |
| 45 | +import javafx.scene.Node; |
44 | 46 | import javafx.scene.Scene; |
| 47 | +import javafx.scene.control.ScrollBar; |
45 | 48 | import javafx.scene.control.ToggleButton; |
46 | 49 | import javafx.scene.image.ImageView; |
47 | 50 | import javafx.scene.input.Clipboard; |
|
92 | 95 | import static org.junit.jupiter.api.Assertions.assertFalse; |
93 | 96 | import static org.junit.jupiter.api.Assertions.assertInstanceOf; |
94 | 97 | import static org.junit.jupiter.api.Assertions.assertNotNull; |
| 98 | +import static org.junit.jupiter.api.Assertions.assertNull; |
95 | 99 | import static org.junit.jupiter.api.Assertions.assertTrue; |
96 | 100 | import static org.testfx.api.FxAssert.verifyThat; |
97 | | -import static org.testfx.util.WaitForAsyncUtils.sleep; |
98 | 101 | import static org.testfx.util.WaitForAsyncUtils.waitForFxEvents; |
99 | 102 |
|
100 | 103 | @ExtendWith(ApplicationExtension.class) |
@@ -891,6 +894,7 @@ public void copyPaste3Test(FxRobot robot) { |
891 | 894 | assertEquals(NORMAL, ((TextDecoration) dm4.getDecoration()).getFontWeight()); |
892 | 895 | assertEquals("black", ((TextDecoration) dm4.getDecoration()).getForeground()); |
893 | 896 | } |
| 897 | + |
894 | 898 | @Test |
895 | 899 | public void multiLineDocumentTest(FxRobot robot) { |
896 | 900 | run(() -> { |
@@ -923,7 +927,54 @@ public void multiLineDocumentTest(FxRobot robot) { |
923 | 927 | assertInstanceOf(Text.class, tf.getChildren().get(0)); |
924 | 928 | assertFalse(((Text) tf.getChildren().get(0)).getText().contains("\n")); |
925 | 929 | } |
926 | | - sleep(4, TimeUnit.SECONDS); |
| 930 | + } |
| 931 | + |
| 932 | + @Test |
| 933 | + public void longLineWrapDocumentTest(FxRobot robot) { |
| 934 | + run(() -> { |
| 935 | + String text = "Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book."; |
| 936 | + TextDecoration textDecoration = TextDecoration.builder().presets().fontFamily("Arial").build(); |
| 937 | + ParagraphDecoration paragraphDecoration = ParagraphDecoration.builder().presets().build(); |
| 938 | + Document document = new Document(text, |
| 939 | + List.of(new DecorationModel(0, text.length(), textDecoration, paragraphDecoration)), text.length()); |
| 940 | + richTextArea.getActionFactory().open(document).execute(new ActionEvent()); |
| 941 | + }); |
| 942 | + waitForFxEvents(); |
| 943 | + |
| 944 | + verifyThat(".rich-text-area", node -> node instanceof RichTextArea); |
| 945 | + assertEquals(2, robot.lookup(".scroll-bar").queryAll().size()); |
| 946 | + ScrollBar scrollBar = (ScrollBar) robot.lookup(".scroll-bar").queryAll().stream().filter(Node::isVisible).findFirst().orElse(null); |
| 947 | + assertNull(scrollBar); |
| 948 | + assertEquals(1, robot.lookup(".text-flow").queryAll().size()); |
| 949 | + assertInstanceOf(TextFlow.class, robot.lookup(".text-flow").query()); |
| 950 | + TextFlow tf = robot.lookup(".text-flow").query(); |
| 951 | + assertEquals(3, tf.getLayoutInfo().getTextLineCount()); |
| 952 | + } |
| 953 | + |
| 954 | + @Test |
| 955 | + public void longLineNoWrapDocumentTest(FxRobot robot) { |
| 956 | + run(() -> { |
| 957 | + String text = "Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book."; |
| 958 | + TextDecoration textDecoration = TextDecoration.builder().presets().fontFamily("Arial").build(); |
| 959 | + ParagraphDecoration paragraphDecoration = ParagraphDecoration.builder().presets().build(); |
| 960 | + Document document = new Document(text, |
| 961 | + List.of(new DecorationModel(0, text.length(), textDecoration, paragraphDecoration)), text.length()); |
| 962 | + richTextArea.setContentAreaWidth(2000); |
| 963 | + richTextArea.getActionFactory().open(document).execute(new ActionEvent()); |
| 964 | + }); |
| 965 | + waitForFxEvents(); |
| 966 | + |
| 967 | + verifyThat(".rich-text-area", node -> node instanceof RichTextArea); |
| 968 | + assertEquals(2, robot.lookup(".scroll-bar").queryAll().size()); |
| 969 | + ScrollBar scrollBar = (ScrollBar) robot.lookup(".scroll-bar").queryAll().stream().filter(Node::isVisible).findFirst().orElse(null); |
| 970 | + assertNotNull(scrollBar); |
| 971 | + assertEquals(Orientation.HORIZONTAL, scrollBar.getOrientation()); |
| 972 | + assertEquals(0, scrollBar.getValue()); |
| 973 | + assertEquals(1, robot.lookup(".text-flow").queryAll().size()); |
| 974 | + assertInstanceOf(TextFlow.class, robot.lookup(".text-flow").query()); |
| 975 | + TextFlow tf = robot.lookup(".text-flow").query(); |
| 976 | + assertEquals(2000, tf.prefWidth(tf.getHeight())); |
| 977 | + assertEquals(1, tf.getLayoutInfo().getTextLineCount()); |
927 | 978 | } |
928 | 979 |
|
929 | 980 | @Test |
|
0 commit comments