Qualify direct document previews and tag edits in IntelliJ

This commit is contained in:
2026-11-25 07:45:08 +01:00
parent c980d0c6f5
commit ceb32166ff
5 changed files with 307 additions and 129 deletions
@@ -62,48 +62,25 @@ public final class DocumentTabsTargetProbe {
}
}
final Stage window = stage;
TabPane group =
fx(
() ->
window.getScene().getRoot().lookupAll(".tab-pane").stream()
.map(TabPane.class::cast)
.filter(
p ->
p.getTabs().stream()
.anyMatch(t -> "Rechnung.html".equals(t.getText())))
.findFirst()
.orElseThrow());
check(
dir,
group,
"Rechnung.html",
"Rechnung RE-042",
"Büromaterial · 48,00 €",
"Beleg offen",
"Beleg geprüft",
"rechnung-tab");
check(
dir,
group,
"Lieferschein.html",
"Lieferschein LS-018",
"Wareneingang · 3 Archivkartons",
"Beleg geprüft",
"Beleg offen",
"lieferschein-tab");
check(
dir,
group,
"Rechnung.html",
"Rechnung RE-042",
"Büromaterial · 48,00 €",
"Beleg offen",
"Beleg geprüft",
"rechnung-tab");
Files.writeString(
dir.resolve("document-tabs-result"),
"PASS Rechnung → Lieferschein → Rechnung: HTML content, assigned tag and filtered"
+ " suggestion in each production tab.\n");
String id = Files.readString(dir.resolve("document-attempt"));
var root = fx(() -> window.getScene().getRoot());
String result;
if (id.equals("archive-window-documents")) {
checkWindow(dir, root);
result =
"Rechnung → Lieferschein → Rechnung: HTML, chips and popup matched each document."
+ " Adding Beleg geprüft affected only Rechnung; removing it restored its"
+ " suggestion.";
} else if (id.startsWith("html-")) {
boolean invoice = id.equals("html-invoice");
String heading = invoice ? "Rechnung RE-042" : "Lieferschein LS-018";
checkHtml(
root, heading, invoice ? "Büromaterial · 48,00 €" : "Wareneingang · 3 Archivkartons");
result = id + ": WebKit displayed " + heading;
} else {
result = checkDetails(dir, root, id);
}
Files.writeString(dir.resolve("result-" + id), result);
} catch (Throwable error) {
var trace = new java.io.StringWriter();
error.printStackTrace(new java.io.PrintWriter(trace));
@@ -115,16 +92,95 @@ public final class DocumentTabsTargetProbe {
}
}
private static void check(
Path dir,
TabPane group,
String name,
String heading,
String body,
String assigned,
String suggestion,
String image)
throws Exception {
private static String checkDetails(Path dir, Node root, String id) throws Exception {
String assigned = id.equals("details-delivery") ? "Beleg geprüft" : "Beleg offen";
String suggestion = id.equals("details-delivery") ? "Beleg offen" : "Beleg geprüft";
boolean readonly = id.equals("details-readonly"), busy = id.equals("details-busy");
var field = fx(() -> (TextField) root.lookup("#tag-input"));
fx(
() -> {
if (!field.getPromptText().equals("Belegtag wählen")
|| field.isDisabled() != (readonly || busy))
throw new AssertionError("Saved prompt or edit state: " + id);
var remove = removeButton(root, assigned);
if (remove.isVisible() == readonly || remove.isDisabled() != busy)
throw new AssertionError("Removal state: " + id);
if (readonly || busy) {
remove.fire();
requireChips(root, assigned);
}
return null;
});
if (!readonly && !busy) popup(field, suggestion, dir.resolve(id + "-tags.png"));
return id
+ ": "
+ assigned
+ (readonly ? ", removal hidden" : busy ? ", removal disabled" : ", Be → " + suggestion);
}
private static void checkWindow(Path dir, Node root) throws Exception {
var group =
fx(
() ->
root.lookupAll(".tab-pane").stream()
.map(TabPane.class::cast)
.filter(
p ->
p.getTabs().stream()
.anyMatch(t -> "Rechnung.html".equals(t.getText())))
.findFirst()
.orElseThrow());
var invoice = select(group, "Rechnung.html");
checkHtml(invoice, "Rechnung RE-042", "Büromaterial · 48,00 €");
var input = fx(() -> (TextField) invoice.lookup("#tag-input"));
fx(
() -> {
requireChips(invoice, "Beleg offen");
save(invoice, dir.resolve("rechnung-tab.png"));
return null;
});
popup(input, "Beleg geprüft", dir.resolve("rechnung-tab-tags.png"));
fx(
() -> {
input.setText("Beleg geprüft");
((Button) invoice.lookup("#add")).fire();
requireChips(invoice, "Beleg offen", "Beleg geprüft");
if (suggestions(input).contains("Beleg geprüft"))
throw new AssertionError("Assigned tag still suggested");
return null;
});
fx(
() -> {
invoice.applyCss();
((javafx.scene.Parent) invoice).layout();
save(invoice, dir.resolve("rechnung-zwei-tags.png"));
return null;
});
var delivery = select(group, "Lieferschein.html");
checkHtml(delivery, "Lieferschein LS-018", "Wareneingang · 3 Archivkartons");
fx(
() -> {
requireChips(delivery, "Beleg geprüft");
save(delivery, dir.resolve("lieferschein-tab.png"));
return null;
});
popup(
fx(() -> (TextField) delivery.lookup("#tag-input")),
"Beleg offen",
dir.resolve("lieferschein-tab-tags.png"));
select(group, "Rechnung.html");
checkHtml(invoice, "Rechnung RE-042", "Büromaterial · 48,00 €");
fx(
() -> {
requireChips(invoice, "Beleg offen", "Beleg geprüft");
removeButton(invoice, "Beleg geprüft").fire();
requireChips(invoice, "Beleg offen");
return null;
});
popup(input, "Beleg geprüft", dir.resolve("rechnung-tab-tags.png"));
}
private static Node select(TabPane group, String name) throws Exception {
var tab =
fx(
() -> {
@@ -137,67 +193,134 @@ public final class DocumentTabsTargetProbe {
return target;
});
await(
"HTML in " + name,
"Selected " + name,
() -> group.getSelectionModel().getSelectedItem() == tab && tab.getContent().isVisible());
return fx(tab::getContent);
}
private static void checkHtml(Node root, String heading, String text) throws Exception {
await(
heading,
() -> {
var content = tab.getContent();
var viewer = content.lookup("#html-document");
if (viewer == null
|| group.getSelectionModel().getSelectedItem() != tab
|| !content.isVisible()) return false;
var browser = viewer.lookup("WebView");
Object engine = browser.getClass().getMethod("getEngine").invoke(browser);
var browser = root.lookup("WebView");
if (browser == null) return false;
var engine = browser.getClass().getMethod("getEngine").invoke(browser);
var doc = (Document) engine.getClass().getMethod("getDocument").invoke(engine);
return doc != null
&& doc.getElementsByTagName("h1").getLength() == 1
&& heading.equals(doc.getElementsByTagName("h1").item(0).getTextContent())
&& doc.getDocumentElement().getTextContent().contains(body);
});
var field = fx(() -> (TextField) tab.getContent().lookup("#tag-input"));
await(
"Focus in " + name,
() -> {
var stage = (Stage) group.getScene().getWindow();
if (!field.isFocused()) {
stage.toFront();
stage.requestFocus();
field.requestFocus();
}
return field.isFocused();
});
fx(
() -> {
var chips = tab.getContent().lookupAll(".tag-chip");
if (chips.size() != 1) throw new AssertionError("Expected one assigned tag in " + name);
var chip = chips.iterator().next();
if (!assigned.equals(chip.getClass().getMethod("getText").invoke(chip)))
throw new AssertionError("Wrong assigned tag in " + name);
field.setText("");
field.setText("Be");
return null;
});
await(
"Popup with " + suggestion,
() -> {
for (var window : Window.getWindows()) {
if (window instanceof Popup popup
&& popup.isShowing()
&& popup.getOwnerNode() == field
&& popup.getScene().lookup(".list-view") instanceof ListView<?> list
&& list.getItems().equals(List.of(suggestion))) {
save(list, dir.resolve(image + "-tags.png"));
return true;
}
}
return false;
});
fx(
() -> {
save(tab.getContent(), dir.resolve(image + ".png"));
field.setText("");
return null;
&& doc.getElementsByTagName("h1").item(0).getTextContent().equals(heading)
&& doc.getDocumentElement().getTextContent().contains(text);
});
}
private static List<?> suggestions(TextField field) throws Exception {
return (List<?>) field.getClass().getMethod("getSuggestionsSource").invoke(field);
}
private static Map<String, Node> chips(Node root) throws Exception {
var named = new TreeMap<String, Node>();
var pane = (javafx.scene.layout.FlowPane) root.lookup("#tags");
for (var row : pane.getChildren()) {
var chip = (javafx.scene.layout.Region) row.lookup(".tag-chip");
String text = (String) chip.getClass().getMethod("getText").invoke(chip);
chip.applyCss();
var fills = chip.getBackground().getFills();
if (fills.stream()
.noneMatch(f -> javafx.scene.paint.Color.web("#f2d58a").equals(f.getFill())))
throw new AssertionError(
"Chip "
+ text
+ " style="
+ chip.getStyle()
+ ", background="
+ fills.stream().map(f -> f.getFill()).toList()
+ ", component="
+ row.getClass().getResource("DocumentTag.fxml"));
if (named.put(text, chip) != null)
throw new AssertionError("Duplicate assigned chip: " + text);
}
return named;
}
private static void requireChips(Node root, String... expected) throws Exception {
var actual = chips(root).keySet();
if (!actual.equals(Set.of(expected)))
throw new AssertionError("Assigned tags " + actual + " vs " + Arrays.toString(expected));
}
private static Button removeButton(Node root, String text) throws Exception {
return (Button)
Objects.requireNonNull(chips(root).get(text), text).lookup(".tag-chip-remove");
}
private static void popup(TextField field, String suggestion, Path file) throws Exception {
// Each interactive target is a separate macOS app. Keep focus acquisition and typing in
// one FX event so an IDE activation between them cannot suppress the real popup.
long deadline = System.nanoTime() + TimeUnit.SECONDS.toNanos(45);
long activateAfter = 0;
while (System.nanoTime() < deadline) {
if (System.nanoTime() >= activateAfter
&& !fx(field::isFocused)
&& System.getProperty("os.name").startsWith("Mac")) {
String activate =
"ObjC.import('AppKit');"
+ " $.NSRunningApplication.runningApplicationWithProcessIdentifier("
+ ProcessHandle.current().pid()
+ ").activateWithOptions(2)";
new ProcessBuilder("/usr/bin/osascript", "-l", "JavaScript", "-e", activate)
.redirectErrorStream(true)
.start()
.waitFor(5, TimeUnit.SECONDS);
activateAfter = System.nanoTime() + TimeUnit.SECONDS.toNanos(3);
}
boolean matched =
fx(
() -> {
var stage = (Stage) field.getScene().getWindow();
if (!field.isFocused()) {
stage.toFront();
stage.requestFocus();
field.requestFocus();
}
if (!field.isFocused()) return false;
if (!suggestions(field).contains(suggestion))
throw new AssertionError(
"Missing " + suggestion + " in catalogue " + suggestions(field));
field.setText("");
field.setText("Be");
for (var window : Window.getWindows()) {
if (window instanceof Popup popup
&& popup.isShowing()
&& popup.getOwnerNode() == field
&& popup.getScene().lookup(".list-view") instanceof ListView<?> list) {
if (!list.getItems().equals(List.of(suggestion)))
throw new AssertionError(
"Expected " + suggestion + " but saw " + list.getItems());
save(list, file);
field.setText("");
return true;
}
}
return false;
});
if (matched) return;
Thread.sleep(150);
}
throw new AssertionError(
fx(
() ->
"No popup for "
+ suggestion
+ ", field focused="
+ field.isFocused()
+ ", stage focused="
+ field.getScene().getWindow().isFocused()
+ ", catalogue="
+ suggestions(field)
+ ", windows="
+ Window.getWindows()));
}
private static void save(Node node, Path file) throws Exception {
var image = node.snapshot(null, null);
int width = (int) image.getWidth(), height = (int) image.getHeight();