Edit control properties and verify controller event handlers in IntelliJ

This commit is contained in:
2026-11-25 08:23:40 +01:00
parent ceb32166ff
commit 22ff06ea75
14 changed files with 699 additions and 16 deletions
@@ -0,0 +1,171 @@
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 java.nio.file.*;
import java.util.List;
import java.util.concurrent.TimeUnit;
import javafx.embed.swing.SwingFXUtils;
import javafx.scene.control.*;
import javafx.scene.image.ImageView;
import javax.imageio.ImageIO;
public final class FolderActionsWorkflowProbe extends FormWorkflowProbe {
@Override
void verify(Project project) throws Exception {
checkForm(project, true);
checkForm(project, false);
Files.writeString(output.resolve("SUCCESS.txt"), Files.readString(output.resolve("steps.txt")));
}
private void open(Project project, String name) throws Exception {
var path =
Path.of(project.getBasePath(), "src/main/resources/de/neitzel/archiver/ui", name + ".fxml");
file = edt(() -> LocalFileSystem.getInstance().refreshAndFindFileByNioFile(path));
pane = openDesigner(project, file);
fx(pane::flush).toCompletableFuture().get(10, TimeUnit.SECONDS);
}
private void save() throws Exception {
var text = source();
click(pane, "Save");
await(
() ->
Files.readString(Path.of(file.getPath()))
.lines()
.map(String::stripTrailing)
.toList()
.equals(text.lines().map(String::stripTrailing).toList()));
}
private void build(String id, String label) throws Exception {
click(pane, "Form preview");
click(pane, "Build and Refresh");
await(
() ->
fx(
() ->
((ComboBox<?>) pane.lookup("#preview-example"))
.getItems().stream().anyMatch(e -> e.toString().contains(id))));
choose("preview-example", id);
await(
() ->
fx(
() -> {
String state = ((Label) pane.lookup("#preview-state")).getText();
if (state.startsWith("Preview failed")
|| state.startsWith("Preview blocked")
|| state.startsWith("Preview unavailable")) throw new AssertionError(state);
return ((ImageView) pane.lookup("#full-preview-image")).getImage() != null
&& state.contains(label);
}));
}
private void reset(String prop, String attribute) throws Exception {
choose("form-property", prop);
click(pane, "Reset property");
await(() -> !source().contains(attribute));
}
private void checkForm(Project project, boolean details) throws Exception {
String name = details ? "DocumentDetails" : "FolderTab";
String control = details ? "AutoCompleteTextField #input" : "ToolBarPane #find";
String prop = details ? "onAction" : "onDismiss";
String handler = details ? "#addTag" : "#closeFind";
String id = details ? "details-invoice" : "folder-actions";
String label = details ? "Dokumentdetails · Rechnung" : "Archivordner · Suche und Anzeigeprofile";
open(project, name);
List<String> bindings =
source()
.lines()
.filter(s -> s.contains("<DirectBinding ") || s.contains("<CommandBinding "))
.toList();
controls(true);
choose("form-control", control);
if (details) {
reset("accessibleText", "accessibleText=\"Neuen Tag eingeben\"");
reset("prefColumnCount", "prefColumnCount=\"12\"");
set("accessibleText", "Belege verschlagworten", "accessibleText=\"Belege verschlagworten\"");
set("prefColumnCount", "23", "prefColumnCount=\"23\"");
String edited = source();
click(pane, "Undo");
await(() -> !source().contains("prefColumnCount=\"23\""));
click(pane, "Redo");
await(() -> source().equals(edited));
choose("form-property", "width");
if (fx(() -> ((TextArea) pane.lookup("#form-value")).isEditable()))
throw new AssertionError("Writable width");
}
reset(prop, prop + "=\"" + handler + "\"");
save();
step(name + " · reset " + prop + " and saved");
build(id, label);
controls(true);
choose("form-control", control);
choose("form-property", prop);
await(
() ->
fx(
() ->
((ComboBox<?>) pane.lookup("#form-event-handlers"))
.getItems()
.contains(handler)));
String before = source();
fx(
() -> {
((TextArea) pane.lookup("#form-value")).setText("#falscherHandler");
return null;
});
click(pane, "Set property");
var msg = fx(() -> ((Label) pane.lookup("#form-message")).getText());
if (!msg.contains("#falscherHandler")
|| !msg.contains("ActionEvent")
|| !before.equals(source())) throw new AssertionError(msg);
if (!details) screenshot("folder-events.png");
choose("form-event-handlers", handler);
click(pane, "Set property");
edited(before, prop + "=\"" + handler + "\"");
save();
edt(
() -> {
FileEditorManager.getInstance(project).closeFile(file);
return null;
});
open(project, name);
String saved = source();
if (!saved.contains(prop + "=\"" + handler + "\"")
|| !bindings.equals(
saved
.lines()
.filter(s -> s.contains("<DirectBinding ") || s.contains("<CommandBinding "))
.toList())) throw new AssertionError("Reopened declarations differ");
step(
name
+ " · rejected #falscherHandler, saved and reopened "
+ handler
+ " with "
+ bindings.size()
+ " unchanged bindings");
build(id, label);
if (!details) screenshot("intellij.png");
click(pane, "Interactive preview");
var result = details ? "result-detail-action" : "result-folder-actions";
awaitTarget(result);
step(Files.readString(output.resolve(result)));
click(pane, "Stop preview");
}
private void screenshot(String name) throws Exception {
fx(
() -> {
ImageIO.write(
SwingFXUtils.fromFXImage(pane.snapshot(null, null), null),
"png",
output.resolve(name).toFile());
return null;
});
}
}