Validate grid width bounds and qualify Archiver window and document states in IntelliJ

This commit is contained in:
2026-11-25 12:08:18 +01:00
parent 2df25985ce
commit ff6ba0a745
12 changed files with 429 additions and 65 deletions
+92 -6
View File
@@ -1,6 +1,7 @@
package qualification;
import java.nio.file.*;
import java.util.*;
import java.util.concurrent.*;
import javafx.application.Platform;
import javafx.scene.control.*;
@@ -42,10 +43,32 @@ public final class ArchiveTargetProbe {
}
}
static void verify(
String state,
String expected,
Map<String, MenuItem> commands,
Button trash,
StringBuilder evidence) {
var active = new TreeSet<String>();
commands.forEach(
(name, item) -> {
if (!item.isDisable()) active.add(name);
});
if (!trash.isDisabled()) active.add("trash");
if (commands.size() != 21 || !active.equals(Set.of(expected.trim().split(" +"))))
throw new AssertionError(state + " expected [" + expected + "] actual " + active);
evidence.append(state).append(" · enabled ").append(active).append("\n");
}
static boolean inspect(Path directory) throws Exception {
var stage =
Window.getWindows().stream()
.filter(Window::isShowing)
.filter(
w ->
w.isShowing()
&& w.getOpacity() > 0
&& w instanceof javafx.stage.Stage s
&& Objects.toString(s.getTitle(), "").startsWith("Neitzel preview"))
.filter(w -> w.getScene().lookup("#trash-button") instanceof Button)
.findFirst();
if (stage.isEmpty()) return false;
@@ -73,11 +96,23 @@ public final class ArchiveTargetProbe {
trash.fire();
if (!status.getText().equals("Vorschau · Bereit"))
throw new AssertionError("Disabled command ran");
if (((TreeView<?>) root.lookup("#folders")).getRoot() == null
|| root.lookup("#dockPane").lookupAll(".label").stream()
.noneMatch(
n -> n instanceof Label l && l.getText().equals("Dokument im Beispielarchiv")))
if (root.lookup("#dockPane").lookupAll(".label").stream()
.noneMatch(n -> n instanceof Label l && l.getText().equals("Dokument im Beispielarchiv")))
return false;
var commands = new LinkedHashMap<String, MenuItem>();
for (var group : ((MenuBar) root.lookup(".menu-bar")).getMenus()) {
for (var item : group.getItems()) {
if (!(item instanceof Menu) && item.getOnAction() != null)
commands.put(item == open ? "open" : item.getId(), item);
}
}
var evidence = new StringBuilder();
String idle = "open openReadOnly overview preferences";
String ready = idle + " closeArchive refresh rebuild trash find slideshow";
String write = " importFile singleFile naming pending manageMail";
String readEntry = " showFile showPlace openFile";
String editEntry = " tags move duplicate";
verify("closed", idle, commands, trash, evidence);
open.fire();
String afterOpen = status.getText();
if (trash.isDisabled() || !afterOpen.endsWith(" · 1")) throw new AssertionError(afterOpen);
@@ -85,6 +120,57 @@ public final class ArchiveTargetProbe {
String afterTrash = status.getText();
if (!afterTrash.equals("Vorschau · Beispielpapierkorb geöffnet · 2"))
throw new AssertionError(afterTrash);
var dialog =
Window.getWindows().stream()
.filter(w -> w.isShowing() && w.getScene().lookup("#archive-trash") != null)
.findFirst()
.orElseThrow();
var content = dialog.getScene().getRoot();
var items = (TableView<?>) content.lookup("#trash-items");
String summary = ((Label) content.lookup("#summary")).getText();
boolean writable = afterOpen.equals("Vorschau · Beispielarchiv geöffnet · 1");
if (items.getItems().size() != 2
|| !summary.contains("3 Dateien")
|| ((Button) content.lookup("#trash-delete")).isDisabled() == writable)
throw new AssertionError(summary);
((Button) ((DialogPane) content).lookupButton(ButtonType.CLOSE)).fire();
if (dialog.isShowing()) throw new AssertionError("Trash dialog did not close");
evidence.append(summary).append("\n");
var folders = (TreeView<?>) root.lookup("#folders");
var entries = (ChoiceBox<?>) root.lookup("#example-entry");
var phase = (ChoiceBox<?>) root.lookup("#example-activity");
String mode = writable ? "writable" : "read-only";
String opened = writable ? ready + write : ready;
verify(mode, opened, commands, trash, evidence);
folders.getSelectionModel().select(0);
entries.getSelectionModel().select(0);
String selected = opened + " rules" + readEntry + (writable ? editEntry : "");
verify(mode + ", invoice selected", selected, commands, trash, evidence);
entries.getSelectionModel().select(1);
verify("server-bound mail", selected.replace(" move", ""), commands, trash, evidence);
entries.getSelectionModel().select(0);
phase.getSelectionModel().select(1);
verify("initial scan", "slideshow" + readEntry, commands, trash, evidence);
phase.getSelectionModel().select(2);
verify("background scan", "find slideshow" + readEntry, commands, trash, evidence);
phase.getSelectionModel().select(3);
verify("busy", "find", commands, trash, evidence);
commands.get("importFile").fire();
if (!status.getText().equals(afterTrash)) throw new AssertionError("Blocked import executed");
phase.getSelectionModel().select(4);
verify("foreground read", selected.replace(" closeArchive", ""), commands, trash, evidence);
phase.getSelectionModel().select(0);
entries.getSelectionModel().clearSelection();
folders.getSelectionModel().clearSelection();
verify("selection cleared", opened, commands, trash, evidence);
commands.get("closeArchive").fire();
verify("archive closed", idle, commands, trash, evidence);
String closedStatus = status.getText();
trash.fire();
if (!status.getText().equals(closedStatus) || folders.getRoot() != null)
throw new AssertionError(closedStatus);
commands.get("openReadOnly").fire();
verify("read-only reopened", ready, commands, trash, evidence);
String run = Files.readString(directory.resolve("attempt")).trim();
var image = root.snapshot(null, null);
int width = (int) image.getWidth(), height = (int) image.getHeight();
@@ -108,7 +194,7 @@ public final class ArchiveTargetProbe {
screenshot, "png", directory.resolve("preview-" + run + ".png").toFile());
Files.writeString(
directory.resolve("result-" + run),
afterOpen + "\n" + afterTrash + "\n" + ProcessHandle.current().pid());
afterOpen + "\n" + afterTrash + "\n" + evidence + ProcessHandle.current().pid());
return true;
}
}