Edit control properties and verify controller event handlers in IntelliJ
This commit is contained in:
@@ -0,0 +1,297 @@
|
||||
package qualification;
|
||||
|
||||
import java.nio.file.*;
|
||||
import java.util.*;
|
||||
import java.util.concurrent.*;
|
||||
import javafx.application.Platform;
|
||||
import javafx.event.ActionEvent;
|
||||
import javafx.scene.*;
|
||||
import javafx.scene.control.*;
|
||||
import javafx.scene.input.ContextMenuEvent;
|
||||
import javafx.stage.*;
|
||||
import javax.imageio.ImageIO;
|
||||
|
||||
/** Acts on the actual controls in the interactive Archiver worker. */
|
||||
public final class FolderActionsTargetProbe {
|
||||
public static void premain(String dir) {
|
||||
if (System.getProperty("sun.java.command", "")
|
||||
.startsWith("de.neitzel.fxdesigner.target.WorkerMain "))
|
||||
Thread.ofPlatform().daemon().start(() -> Worker.run(Path.of(dir)));
|
||||
}
|
||||
|
||||
private static final class Worker {
|
||||
private static <T> T fx(Callable<T> action) throws Exception {
|
||||
var task = new FutureTask<>(action);
|
||||
Platform.runLater(task);
|
||||
return task.get(10, TimeUnit.SECONDS);
|
||||
}
|
||||
|
||||
private static void await(String description, Callable<Boolean> test) throws Exception {
|
||||
long end = System.nanoTime() + TimeUnit.SECONDS.toNanos(22);
|
||||
while (System.nanoTime() < end) {
|
||||
if (fx(test)) return;
|
||||
Thread.sleep(90);
|
||||
}
|
||||
throw new AssertionError(description);
|
||||
}
|
||||
|
||||
private static void require(boolean value, String message) {
|
||||
if (!value) throw new AssertionError(message);
|
||||
}
|
||||
|
||||
private static void run(Path dir) {
|
||||
try {
|
||||
Stage stage = null;
|
||||
while (stage == null) {
|
||||
Thread.sleep(120);
|
||||
try {
|
||||
stage =
|
||||
fx(
|
||||
() ->
|
||||
Window.getWindows().stream()
|
||||
.filter(
|
||||
w ->
|
||||
w instanceof Stage s
|
||||
&& s.isShowing()
|
||||
&& s.getOpacity() > 0
|
||||
&& s.getTitle() != null
|
||||
&& s.getTitle().startsWith("Neitzel preview"))
|
||||
.map(Stage.class::cast)
|
||||
.findFirst()
|
||||
.orElse(null));
|
||||
} catch (IllegalStateException starting) {
|
||||
}
|
||||
}
|
||||
Stage shown = stage;
|
||||
var root =
|
||||
fx(
|
||||
() -> {
|
||||
shown.setWidth(1250);
|
||||
shown.setHeight(640);
|
||||
var r = shown.getScene().getRoot();
|
||||
r.applyCss();
|
||||
r.layout();
|
||||
return r;
|
||||
});
|
||||
if (fx(() -> root.lookup("#tag-input") != null)) {
|
||||
fx(
|
||||
() -> {
|
||||
var input = (TextField) root.lookup("#tag-input");
|
||||
require(
|
||||
input.getPrefColumnCount() == 23
|
||||
&& "Belege verschlagworten".equals(input.getAccessibleText()),
|
||||
"Saved text field properties");
|
||||
input.setText("Inspektorprobe");
|
||||
input.fireEvent(new ActionEvent());
|
||||
require(
|
||||
root.lookupAll(".tag-chip").stream()
|
||||
.anyMatch(
|
||||
chip ->
|
||||
chip.lookup(".label") instanceof Label l
|
||||
&& l.getText().equals("Inspektorprobe")),
|
||||
"onAction did not add tag");
|
||||
return null;
|
||||
});
|
||||
Files.writeString(
|
||||
dir.resolve("result-detail-action"),
|
||||
"23 columns and accessible name restored; #addTag added Inspektorprobe");
|
||||
} else checkFolder(dir, root);
|
||||
} catch (Throwable failure) {
|
||||
var trace = new java.io.StringWriter();
|
||||
failure.printStackTrace(new java.io.PrintWriter(trace));
|
||||
try {
|
||||
Files.writeString(dir.resolve("target-error.txt"), trace.toString());
|
||||
} catch (Exception ignored) {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private static List<?> rows(Node grid) throws Exception {
|
||||
return (List<?>) grid.getClass().getMethod("getItems").invoke(grid);
|
||||
}
|
||||
|
||||
private static String attr(Object row, String name) throws Exception {
|
||||
return (String) row.getClass().getMethod(name).invoke(row);
|
||||
}
|
||||
|
||||
private static void select(Node grid, List<String> keys) throws Exception {
|
||||
grid.getClass().getMethod("selectKeys", Collection.class).invoke(grid, keys);
|
||||
}
|
||||
|
||||
private static MenuItem move(Node grid, String file) {
|
||||
Node anchor =
|
||||
grid.lookupAll(".label").stream()
|
||||
.filter(n -> n instanceof Label l && l.getText().equals(file))
|
||||
.findFirst()
|
||||
.orElseThrow();
|
||||
while (anchor != null && anchor.getOnContextMenuRequested() == null)
|
||||
anchor = anchor.getParent();
|
||||
Objects.requireNonNull(anchor, "Product row context menu");
|
||||
var p = anchor.localToScreen(0, 0);
|
||||
anchor.fireEvent(
|
||||
new ContextMenuEvent(
|
||||
ContextMenuEvent.CONTEXT_MENU_REQUESTED, 0, 0, p.getX(), p.getY(), false, null));
|
||||
return Window.getWindows().stream()
|
||||
.filter(w -> w instanceof ContextMenu m && m.isShowing())
|
||||
.map(ContextMenu.class::cast)
|
||||
.flatMap(m -> m.getItems().stream())
|
||||
.filter(i -> "Verschieben …".equals(i.getText()))
|
||||
.findFirst()
|
||||
.orElseThrow();
|
||||
}
|
||||
|
||||
private static boolean visible(Node grid, String column) throws Exception {
|
||||
return (boolean)
|
||||
grid.getClass().getMethod("isColumnVisible", String.class).invoke(grid, column);
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
private static void checkFolder(Path dir, Parent root) throws Exception {
|
||||
Node grid = fx(() -> root.lookup("#grid"));
|
||||
var search = fx(() -> (TextField) root.lookup("#search"));
|
||||
var feedback = fx(() -> (Label) root.lookup("#example-folder-result"));
|
||||
var places = fx(() -> (Button) root.lookup("#places"));
|
||||
var profiles = fx(() -> (ComboBox<String>) root.lookup("#folder-view-profile"));
|
||||
var save = fx(() -> (Button) root.lookup("#save-folder-view-profile"));
|
||||
fx(
|
||||
() -> {
|
||||
search.setText("Archivbeleg");
|
||||
search.fireEvent(new ActionEvent());
|
||||
return null;
|
||||
});
|
||||
await(
|
||||
"Two distinguishable full-text hits for Archivbeleg",
|
||||
() -> {
|
||||
if (rows(grid).size() != 2) return false;
|
||||
for (var row : rows(grid))
|
||||
if (!attr(row, "snippet").toLowerCase(Locale.ROOT).contains("archivbeleg"))
|
||||
return false;
|
||||
return grid.lookupAll(".label").stream()
|
||||
.anyMatch(n -> n instanceof Label l && l.getText().equals("Lieferbrief.md"));
|
||||
});
|
||||
var keys =
|
||||
fx(
|
||||
() -> {
|
||||
var result = new TreeMap<String, String>();
|
||||
for (var row : rows(grid)) result.put(attr(row, "path"), attr(row, "key"));
|
||||
return result;
|
||||
});
|
||||
var invoice = keys.get("Musterrechnung.pdf");
|
||||
var letter = keys.get("Lieferbrief.md");
|
||||
require(
|
||||
invoice != null && letter != null && !invoice.equals(letter),
|
||||
"Distinct archive entry keys: " + keys);
|
||||
fx(
|
||||
() -> {
|
||||
var action = move(grid, "Lieferbrief.md");
|
||||
select(grid, List.of());
|
||||
require(action.isDisable() && places.isDisabled(), "Empty selection enabled actions");
|
||||
select(grid, List.of(letter));
|
||||
require(!action.isDisable() && !places.isDisabled(), "Single selection blocked");
|
||||
places.fire();
|
||||
require(
|
||||
feedback.getText().contains("Lieferbrief.md")
|
||||
&& feedback.getText().contains("Wareneingang"),
|
||||
"Wrong place: " + feedback.getText());
|
||||
action.fire();
|
||||
require(feedback.getText().equals("Verschieben · " + letter), "Wrong single key");
|
||||
select(grid, List.of(invoice, letter));
|
||||
require(!action.isDisable() && places.isDisabled(), "Multiple selection availability");
|
||||
action.fire();
|
||||
String message = feedback.getText();
|
||||
require(
|
||||
message.startsWith("Verschieben · ")
|
||||
&& Set.copyOf(
|
||||
Arrays.asList(message.substring("Verschieben · ".length()).split(", ")))
|
||||
.equals(Set.of(invoice, letter)),
|
||||
"Wrong affected keys: " + message);
|
||||
image(root, dir.resolve("folder-search.png"));
|
||||
search.setText("Wareneingang");
|
||||
search.fireEvent(new ActionEvent());
|
||||
String before = feedback.getText();
|
||||
action.fire();
|
||||
require(
|
||||
places.isDisabled() && before.equals(feedback.getText()),
|
||||
"Stale action during new search");
|
||||
return null;
|
||||
});
|
||||
await(
|
||||
"Only Lieferbrief matches Wareneingang",
|
||||
() -> rows(grid).size() == 1 && attr(rows(grid).getFirst(), "key").equals(letter));
|
||||
fx(
|
||||
() -> {
|
||||
((Button) root.lookup(".tool-bar-dismiss")).fire();
|
||||
Node bar = root.lookup("#search-toolbar");
|
||||
require(
|
||||
!bar.isVisible() && !bar.isManaged() && search.getText().isEmpty(),
|
||||
"onDismiss did not close/reset the search");
|
||||
return null;
|
||||
});
|
||||
await(
|
||||
"Normal folder rows and profiles ready",
|
||||
() -> rows(grid).size() == 2 && !profiles.isDisabled());
|
||||
fx(
|
||||
() -> {
|
||||
var menu = (MenuButton) grid.lookup(".data-grid-column-menu");
|
||||
menu.show();
|
||||
var type =
|
||||
(CheckMenuItem)
|
||||
menu.getItems().stream()
|
||||
.filter(it -> "Dateityp".equals(it.getText()))
|
||||
.findFirst()
|
||||
.orElseThrow();
|
||||
require(type.isSelected(), "Initially hidden type");
|
||||
type.setSelected(false);
|
||||
type.fire();
|
||||
menu.hide();
|
||||
profiles.getEditor().setText("Kurzansicht");
|
||||
require(!save.isDisabled(), "Save unavailable");
|
||||
save.fire();
|
||||
require(profiles.getItems().contains("Kurzansicht"), "Profile not saved");
|
||||
String standard =
|
||||
profiles.getItems().stream()
|
||||
.filter(it -> it.endsWith("STANDARD"))
|
||||
.findFirst()
|
||||
.orElseThrow();
|
||||
profiles.getSelectionModel().select(standard);
|
||||
return null;
|
||||
});
|
||||
await(
|
||||
"Standard restores visible type", () -> visible(grid, "type") && !profiles.isDisabled());
|
||||
fx(
|
||||
() -> {
|
||||
profiles.getSelectionModel().select("Kurzansicht");
|
||||
return null;
|
||||
});
|
||||
await(
|
||||
"Reapplied profile hides type",
|
||||
() ->
|
||||
!visible(grid, "type")
|
||||
&& !profiles.isDisabled()
|
||||
&& "Kurzansicht".equals(profiles.getEditor().getText()));
|
||||
fx(
|
||||
() -> {
|
||||
image(root, dir.resolve("folder-profile.png"));
|
||||
return null;
|
||||
});
|
||||
Files.writeString(
|
||||
dir.resolve("result-folder-actions"),
|
||||
"Archivbeleg → two hits; Wareneingang → Lieferbrief. Fundstelle and move verified for"
|
||||
+ " zero, one, both keys "
|
||||
+ keys
|
||||
+ "; new search invalidated actions. Dismiss cleared search. Standard showed"
|
||||
+ " Dateityp; Kurzansicht restored hidden Dateityp.");
|
||||
}
|
||||
|
||||
private static void image(Node node, Path path) throws Exception {
|
||||
var img = node.snapshot(null, null);
|
||||
int w = (int) img.getWidth(), h = (int) img.getHeight();
|
||||
var out = new java.awt.image.BufferedImage(w, h, java.awt.image.BufferedImage.TYPE_INT_ARGB);
|
||||
int[] pixels = new int[w * h];
|
||||
img.getPixelReader()
|
||||
.getPixels(0, 0, w, h, javafx.scene.image.PixelFormat.getIntArgbInstance(), pixels, 0, w);
|
||||
out.setRGB(0, 0, w, h, pixels, 0, w);
|
||||
ImageIO.write(out, "png", path.toFile());
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user