Oliver-Loeffler / FXFileChooser

Custom JavaFX file chooser which allows quick manual filtering, which allows to add Path predicates as filter and which is testable using TestFX.
Apache License 2.0
44 stars 8 forks source link

Testing of change location functionality #42

Open Oliver-Loeffler opened 3 years ago

Oliver-Loeffler commented 3 years ago

It turned out, that the change location (or change directory) functionality implemented is hard to test. Therefore a rework is needed.

Points which turned out problematic:

ArchibaldBienetre commented 1 year ago

(Working with v0.0.9)

I think there is only working with selectors where you can, then choosing click coordinates based on it.

Here's what I got right now: Opening the directory dropdown for choosing the directory, then selecting the first location item there

image

    SplitMenuButton chooseDirectory = robot.lookup("#chooser").queryAs(SplitMenuButton.class);
    Bounds chooseAbsoluteBounds = chooseDirectory.localToScreen(chooseDirectory.getBoundsInLocal());

    // open dropdown with pre-programmed locations
    robot.clickOn(chooseAbsoluteBounds.getMaxX() - 10, chooseAbsoluteBounds.getMaxY() - 10);

    // choose first item in dropdown (user home)
    robot.clickOn(chooseAbsoluteBounds.getMinX() + 20, chooseAbsoluteBounds.getMaxY() + 20);

To then select the first in the list of listed files, I have this code:

private void chooseFirstInListOfFiles(FxRobot robot) {
    ListView<?> listOfFiles = robot.lookup("#listOfFiles").queryListView();
    // I cannot do this programmatically, it seems
    //        listOfFiles.getSelectionModel().selectFirst();
    //        listOfFiles.refresh();
    //        robot.clickOn(listOfFiles);

    clickOnUpperLeftPlusOffset(robot, listOfFiles, 30);
}

private void clickOnUpperLeftPlusOffset(FxRobot robot, Node node, int offset) {
    Bounds absoluteBounds = node.localToScreen(node.getBoundsInLocal());
    robot.clickOn(absoluteBounds.getMinX() + offset, absoluteBounds.getMinY() + offset);
}
ArchibaldBienetre commented 1 year ago

Something like this would be great: If the location menu items had IDs, we could use these selection (rather than absolute coordinates): https://github.com/TestFX/TestFX/issues/662#issuecomment-506352921

Oliver-Loeffler commented 1 year ago

Thanks for this very nice idea, I will look into this and see, if I get it working.