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());
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -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;
|
||||
});
|
||||
}
|
||||
}
|
||||
@@ -22,7 +22,7 @@ public final class ImportWorkflowProbe extends FormWorkflowProbe {
|
||||
target("protocol", "both", "protocol", "value", "COMPATIBLE");
|
||||
target("security", "both", "security", "value", "COMPATIBLE");
|
||||
|
||||
open(project, "FolderTab", 1);
|
||||
open(project, "FolderTab", 2);
|
||||
discover();
|
||||
target("view", "both", "view", "value", "COMPATIBLE");
|
||||
target("grouping", "both", "grouping", "value", "COMPATIBLE");
|
||||
@@ -31,7 +31,7 @@ public final class ImportWorkflowProbe extends FormWorkflowProbe {
|
||||
target("rows", "view", "clearLayout", "accessibleHelp", "INCOMPATIBLE");
|
||||
target("view", "both", "untypedPick", "value", "UNRESOLVED");
|
||||
target("rows", "view", "grid", "items", "COMPATIBLE");
|
||||
applyAndReopen(project, "FolderTab", 1, "grid", "items", "rows", "view");
|
||||
applyAndReopen(project, "FolderTab", 2, "grid", "items", "rows", "view");
|
||||
preview("archive-folder", "import-grid");
|
||||
|
||||
open(project, "ImportForm", 3);
|
||||
|
||||
Reference in New Issue
Block a user