-
Notifications
You must be signed in to change notification settings - Fork 95
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
AbstractValueIndicator: prevent label editing when setEditable(false)
- Affects XValueIndicator, YValueIndicator, YWatchValueIndicator
- Loading branch information
Benjamin Peter
authored and
Benjamin Peter
committed
Dec 12, 2024
1 parent
f8a5094
commit 1f6edaa
Showing
2 changed files
with
78 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
77 changes: 77 additions & 0 deletions
77
chartfx-chart/src/test/java/io/fair_acc/chartfx/plugins/XValueIndicatorTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,77 @@ | ||
package io.fair_acc.chartfx.plugins; | ||
|
||
import static org.hamcrest.MatcherAssert.assertThat; | ||
import static org.hamcrest.Matchers.hasSize; | ||
|
||
import java.util.Set; | ||
|
||
import org.junit.jupiter.api.Test; | ||
import org.junit.jupiter.api.extension.ExtendWith; | ||
import org.testfx.api.FxRobot; | ||
import org.testfx.framework.junit5.ApplicationExtension; | ||
import org.testfx.framework.junit5.Start; | ||
|
||
import io.fair_acc.chartfx.XYChart; | ||
import io.fair_acc.dataset.DataSet; | ||
import io.fair_acc.dataset.testdata.spi.CosineFunction; | ||
import javafx.scene.Node; | ||
import javafx.scene.Scene; | ||
import javafx.scene.input.MouseButton; | ||
import javafx.stage.Stage; | ||
|
||
@ExtendWith(ApplicationExtension.class) | ||
public class XValueIndicatorTest { | ||
|
||
private XYChart chart; | ||
private XValueIndicator indicator; | ||
|
||
@Start | ||
public void start(Stage stage) { | ||
chart = new XYChart(); | ||
indicator = new XValueIndicator(chart.getXAxis(), 5, "POI"); | ||
indicator.setLabelPosition(0.5); | ||
chart.getPlugins().add(indicator); | ||
chart.setPrefWidth(400); | ||
chart.setPrefHeight(300); | ||
|
||
DataSet ds = new CosineFunction("Cosine", 30); | ||
chart.getDatasets().add(ds); | ||
|
||
Scene scene = new Scene(chart, 400, 300); | ||
stage.setScene(scene); | ||
stage.show(); | ||
} | ||
|
||
@Test | ||
void testThatIndicatorEditLabelTextFieldIsShownWhenEditable(final FxRobot fxRobot) { // NOPMD JUnitTestsShouldIncludeAssert | ||
fxRobot.interrupt(); | ||
|
||
assertThat(lookupIndicatorTextFields(fxRobot), hasSize(0)); | ||
fxRobot.moveTo(lookupFirstIndicatorLabel(fxRobot)); | ||
fxRobot.clickOn(MouseButton.SECONDARY); | ||
|
||
assertThat(lookupIndicatorTextFields(fxRobot), hasSize(1)); | ||
} | ||
|
||
@Test | ||
void testThatIndicatorNoEditLabelTextFieldIsShownWhenNotEditable(final FxRobot fxRobot) { // NOPMD JUnitTestsShouldIncludeAssert | ||
fxRobot.interrupt(); | ||
|
||
indicator.setEditable(false); | ||
|
||
assertThat(lookupIndicatorTextFields(fxRobot), hasSize(0)); | ||
fxRobot.moveTo(lookupFirstIndicatorLabel(fxRobot)); | ||
fxRobot.clickOn(MouseButton.SECONDARY); | ||
|
||
assertThat(lookupIndicatorTextFields(fxRobot), hasSize(0)); | ||
} | ||
|
||
private Node lookupFirstIndicatorLabel(final FxRobot fxRobot) { | ||
return fxRobot.from(chart).lookup("." + AbstractSingleValueIndicator.STYLE_CLASS_LABEL).query(); | ||
} | ||
|
||
private Set<Node> lookupIndicatorTextFields(final FxRobot fxRobot) { | ||
return fxRobot.from(chart).lookup(".text-field").queryAll(); | ||
} | ||
|
||
} |