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();
@@ -2,59 +2,112 @@ package qualification;
import static qualification.WorkflowProbe.*;
import com.intellij.openapi.fileEditor.FileEditorManager;
import com.intellij.openapi.project.Project;
import com.intellij.openapi.vfs.LocalFileSystem;
import de.neitzel.fxdesigner.workflow.DesignerWorkflow.Example;
import java.nio.file.*;
import java.util.concurrent.TimeUnit;
import javafx.embed.swing.SwingFXUtils;
import javafx.scene.control.*;
import javafx.scene.image.ImageView;
import javax.imageio.ImageIO;
/**
* Opens the production ArchiveWindow in the registered editor and selects its real document tabs.
*/
/** Edits the real chip template and opens both child resources and the archive window. */
public final class DocumentTabsWorkflowProbe extends FormWorkflowProbe {
@Override
void verify(Project project) throws Exception {
edit(project, "DocumentTag", "TagChip #chip", "style", "-fx-background-color: #f2d58a;");
edit(
project,
"DocumentDetails",
"AutoCompleteTextField #input",
"promptText",
"Belegtag wählen");
build(4);
for (String id :
new String[] {"details-invoice", "details-delivery", "details-readonly", "details-busy"})
preview(id);
open(project, "HtmlDocument");
build(2);
preview("html-invoice");
preview("html-delivery");
open(project, "ArchiveWindow");
build(2);
preview("archive-window-documents");
Files.writeString(output.resolve("SUCCESS.txt"), Files.readString(output.resolve("steps.txt")));
}
private void open(Project project, String form) throws Exception {
var path =
Path.of(
project.getBasePath(), "src/main/resources/de/neitzel/archiver/ui/ArchiveWindow.fxml");
Path.of(project.getBasePath(), "src/main/resources/de/neitzel/archiver/ui", form + ".fxml");
file = edt(() -> LocalFileSystem.getInstance().refreshAndFindFileByNioFile(path));
pane = openDesigner(project, file);
fx(pane::flush).toCompletableFuture().get(10, TimeUnit.SECONDS);
step("Opened " + form + ".fxml in Neitzel Designer");
}
private void edit(Project project, String form, String control, String property, String value)
throws Exception {
open(project, form);
controls(true);
choose("form-control", control);
set(property, value, value);
click(pane, "Save");
await(() -> Files.readString(Path.of(file.getPath())).contains(value));
edt(
() -> {
FileEditorManager.getInstance(project).closeFile(file);
return null;
});
open(project, form);
if (!source().contains(value)) throw new AssertionError(form + " lost " + property);
step("Saved and reopened " + control + "." + property + " = " + value);
}
private void build(int examples) throws Exception {
click(pane, "Form preview");
click(pane, "Build and Refresh");
await(
() ->
fx(
() ->
((ComboBox<?>) pane.lookup("#preview-example"))
.getItems().stream()
.anyMatch(
item -> item.toString().contains("archive-window-documents"))));
choose("preview-example", "archive-window-documents");
((ComboBox<?>) pane.lookup("#preview-example")).getItems().size() == examples));
}
private void preview(String id) throws Exception {
choose("preview-example", id);
String label =
fx(() -> ((Example) ((ComboBox<?>) pane.lookup("#preview-example")).getValue()).label());
await(
() ->
fx(
() -> {
var status = ((Label) pane.lookup("#preview-state")).getText();
if (status.startsWith("Preview failed") || status.startsWith("Preview blocked"))
throw new AssertionError(status);
String state = ((Label) pane.lookup("#preview-state")).getText();
if (state.startsWith("Preview failed")
|| state.startsWith("Preview blocked")
|| state.startsWith("Preview unavailable"))
throw new AssertionError(id + ": " + state);
return ((ImageView) pane.lookup("#full-preview-image")).getImage() != null
&& status.contains("HTML-Dokumenttabs");
&& state.contains(label);
}));
step("Production ArchiveWindow rendered the document tabs");
fx(
() -> {
var frame = ((ImageView) pane.lookup("#full-preview-image")).getImage();
ImageIO.write(
SwingFXUtils.fromFXImage(pane.snapshot(null, null), null),
"png",
output.resolve("intellij.png").toFile());
SwingFXUtils.fromFXImage(frame, null), "png", output.resolve(id + ".png").toFile());
if (id.equals("archive-window-documents"))
ImageIO.write(
SwingFXUtils.fromFXImage(pane.snapshot(null, null), null),
"png",
output.resolve("intellij.png").toFile());
return null;
});
Files.writeString(output.resolve("document-attempt"), id);
click(pane, "Interactive preview");
awaitTarget("document-tabs-result");
var result = "result-" + id;
awaitTarget(result);
step(Files.readString(output.resolve(result)));
click(pane, "Stop preview");
Files.writeString(
output.resolve("SUCCESS.txt"), Files.readString(output.resolve("document-tabs-result")));
}
}