Validate grid width bounds and qualify Archiver window and document states in IntelliJ
This commit is contained in:
@@ -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;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -80,7 +80,8 @@ public final class DocumentTabsTargetProbe {
|
||||
} else {
|
||||
result = checkDetails(dir, root, id);
|
||||
}
|
||||
Files.writeString(dir.resolve("result-" + id), result);
|
||||
var completed = Files.writeString(dir.resolve("result-" + id + ".tmp"), result);
|
||||
Files.move(completed, dir.resolve("result-" + id), StandardCopyOption.ATOMIC_MOVE);
|
||||
} catch (Throwable error) {
|
||||
var trace = new java.io.StringWriter();
|
||||
error.printStackTrace(new java.io.PrintWriter(trace));
|
||||
@@ -260,29 +261,25 @@ public final class DocumentTabsTargetProbe {
|
||||
long activateAfter = 0;
|
||||
while (System.nanoTime() < deadline) {
|
||||
if (System.nanoTime() >= activateAfter
|
||||
&& !fx(field::isFocused)
|
||||
&& !fx(() -> field.isFocused() && field.getScene().getWindow().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);
|
||||
var desktop = java.awt.Desktop.getDesktop();
|
||||
if (desktop.isSupported(java.awt.Desktop.Action.APP_REQUEST_FOREGROUND)) {
|
||||
// Request activation from the preview process itself, which owns the FX stage.
|
||||
desktop.requestForeground(true);
|
||||
}
|
||||
activateAfter = System.nanoTime() + TimeUnit.SECONDS.toNanos(3);
|
||||
}
|
||||
boolean matched =
|
||||
fx(
|
||||
() -> {
|
||||
var stage = (Stage) field.getScene().getWindow();
|
||||
if (!field.isFocused()) {
|
||||
if (!stage.isFocused() || !field.isFocused()) {
|
||||
stage.toFront();
|
||||
stage.requestFocus();
|
||||
field.requestFocus();
|
||||
}
|
||||
if (!field.isFocused()) return false;
|
||||
if (!stage.isFocused() || !field.isFocused()) return false;
|
||||
if (!suggestions(field).contains(suggestion))
|
||||
throw new AssertionError(
|
||||
"Missing " + suggestion + " in catalogue " + suggestions(field));
|
||||
@@ -315,6 +312,10 @@ public final class DocumentTabsTargetProbe {
|
||||
+ field.isFocused()
|
||||
+ ", stage focused="
|
||||
+ field.getScene().getWindow().isFocused()
|
||||
+ ", focus owner="
|
||||
+ field.getScene().getFocusOwner()
|
||||
+ ", field bounds="
|
||||
+ field.localToScreen(field.getBoundsInLocal())
|
||||
+ ", catalogue="
|
||||
+ suggestions(field)
|
||||
+ ", windows="
|
||||
|
||||
@@ -7,6 +7,7 @@ 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.List;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
import javafx.embed.swing.SwingFXUtils;
|
||||
import javafx.scene.control.*;
|
||||
@@ -24,17 +25,24 @@ public final class DocumentTabsWorkflowProbe extends FormWorkflowProbe {
|
||||
"AutoCompleteTextField #input",
|
||||
"promptText",
|
||||
"Belegtag wählen");
|
||||
build(4);
|
||||
for (String id :
|
||||
new String[] {"details-invoice", "details-delivery", "details-readonly", "details-busy"})
|
||||
preview(id);
|
||||
qualify("details-invoice", "details-delivery", "details-readonly", "details-busy");
|
||||
open(project, "HtmlDocument");
|
||||
build(2);
|
||||
preview("html-invoice");
|
||||
preview("html-delivery");
|
||||
qualify("html-invoice", "html-delivery");
|
||||
open(project, "ArchiveWindow");
|
||||
build(2);
|
||||
preview("archive-window-documents");
|
||||
qualify("archive-window-documents");
|
||||
var ids = fx(this::available);
|
||||
if (!ids.contains("archive-window-media"))
|
||||
throw new AssertionError("Missing media example: " + ids);
|
||||
try {
|
||||
awaitExamples(List.of("missing-required-example"));
|
||||
throw new AssertionError("Missing descriptor was accepted");
|
||||
} catch (IllegalStateException expected) {
|
||||
String diagnostic = expected.getMessage();
|
||||
if (!diagnostic.contains(
|
||||
"ArchiveWindow.fxml · required [missing-required-example] · available " + ids))
|
||||
throw expected;
|
||||
step(diagnostic);
|
||||
}
|
||||
Files.writeString(output.resolve("SUCCESS.txt"), Files.readString(output.resolve("steps.txt")));
|
||||
}
|
||||
|
||||
@@ -65,32 +73,84 @@ public final class DocumentTabsWorkflowProbe extends FormWorkflowProbe {
|
||||
step("Saved and reopened " + control + "." + property + " = " + value);
|
||||
}
|
||||
|
||||
private void build(int examples) throws Exception {
|
||||
private List<String> available() {
|
||||
return ((ComboBox<?>) pane.lookup("#preview-example"))
|
||||
.getItems().stream().map(Example.class::cast).map(Example::id).toList();
|
||||
}
|
||||
|
||||
private String state() {
|
||||
return ((Label) pane.lookup("#preview-state")).getText();
|
||||
}
|
||||
|
||||
private boolean failed() {
|
||||
String state = state();
|
||||
return state.startsWith("Preview failed")
|
||||
|| state.startsWith("Preview blocked")
|
||||
|| state.startsWith("Preview unavailable")
|
||||
|| state.contains("correct the build");
|
||||
}
|
||||
|
||||
private String diagnostic(List<String> required) {
|
||||
return file.getName()
|
||||
+ " · required "
|
||||
+ required
|
||||
+ " · available "
|
||||
+ available()
|
||||
+ " · "
|
||||
+ state();
|
||||
}
|
||||
|
||||
private void awaitExamples(List<String> required) throws Exception {
|
||||
try {
|
||||
// Discovery publishes the complete list at once. Additional providers may extend it.
|
||||
await(
|
||||
() ->
|
||||
fx(
|
||||
() ->
|
||||
failed()
|
||||
|| state().contains("register an example")
|
||||
|| !state().startsWith("Building") && !available().isEmpty()));
|
||||
} catch (AssertionError timeout) {
|
||||
throw new AssertionError(fx(() -> diagnostic(required)), timeout);
|
||||
}
|
||||
if (!fx(() -> !failed() && available().containsAll(required)))
|
||||
throw new IllegalStateException(fx(() -> diagnostic(required)));
|
||||
}
|
||||
|
||||
private void qualify(String... examples) throws Exception {
|
||||
var required = List.of(examples);
|
||||
click(pane, "Form preview");
|
||||
click(pane, "Build and Refresh");
|
||||
await(
|
||||
() ->
|
||||
fx(
|
||||
() ->
|
||||
((ComboBox<?>) pane.lookup("#preview-example")).getItems().size() == examples));
|
||||
awaitExamples(required);
|
||||
step(file.getName() + " · available " + fx(this::available));
|
||||
for (String id : required) preview(id);
|
||||
}
|
||||
|
||||
private void preview(String id) throws Exception {
|
||||
choose("preview-example", id);
|
||||
String label =
|
||||
fx(() -> ((Example) ((ComboBox<?>) pane.lookup("#preview-example")).getValue()).label());
|
||||
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(id + ": " + state);
|
||||
return ((ImageView) pane.lookup("#full-preview-image")).getImage() != null
|
||||
&& state.contains(label);
|
||||
}));
|
||||
fx(
|
||||
() -> {
|
||||
var choices = (ComboBox<Example>) pane.lookup("#preview-example");
|
||||
var selected =
|
||||
choices.getItems().stream()
|
||||
.filter(example -> example.id().equals(id))
|
||||
.findFirst()
|
||||
.orElseThrow(() -> new IllegalStateException(diagnostic(List.of(id))));
|
||||
choices.getSelectionModel().select(selected);
|
||||
return selected.label();
|
||||
});
|
||||
try {
|
||||
await(
|
||||
() ->
|
||||
fx(
|
||||
() ->
|
||||
failed()
|
||||
|| ((ImageView) pane.lookup("#full-preview-image")).getImage() != null
|
||||
&& state().contains(label)));
|
||||
} catch (AssertionError timeout) {
|
||||
throw new AssertionError(fx(() -> diagnostic(List.of(id))), timeout);
|
||||
}
|
||||
if (fx(this::failed)) throw new AssertionError(fx(() -> diagnostic(List.of(id))));
|
||||
fx(
|
||||
() -> {
|
||||
var frame = ((ImageView) pane.lookup("#full-preview-image")).getImage();
|
||||
|
||||
@@ -284,6 +284,28 @@ public final class MediaLayoutGridTargetProbe {
|
||||
var cols = (List<?>) get(setup, "columns");
|
||||
var order = new ArrayList<String>();
|
||||
for (var col : cols) order.add((String) get(col, "id"));
|
||||
var labels =
|
||||
grid.lookupAll(".label").stream().map(Label.class::cast).map(Label::getText).toList();
|
||||
require(
|
||||
labels.containsAll(List.of("Musterrechnung.pdf", "Lieferbrief.txt")),
|
||||
"Example rows: " + labels);
|
||||
var widthType =
|
||||
Class.forName("de.neitzel.grid.ColumnWidth", true, grid.getClass().getClassLoader());
|
||||
var resize = grid.getClass().getMethod("setColumnWidth", String.class, widthType);
|
||||
var explicit =
|
||||
Class.forName(widthType.getName() + "$Explicit", true, widthType.getClassLoader())
|
||||
.getConstructor(double.class);
|
||||
var defaultWidth = get(cols.getFirst(), "width");
|
||||
require(
|
||||
order.getFirst().equals("path")
|
||||
&& defaultWidth.getClass().getSimpleName().equals("Default"),
|
||||
"Initial path column");
|
||||
require(
|
||||
resize.invoke(grid, "path", defaultWidth).equals(230d)
|
||||
&& resize.invoke(grid, "path", explicit.newInstance(50d)).equals(150d)
|
||||
&& resize.invoke(grid, "path", explicit.newInstance(600d)).equals(300d)
|
||||
&& resize.invoke(grid, "path", defaultWidth).equals(230d),
|
||||
"Rendered path column width limits");
|
||||
require(order.get(1).equals("folder"), "Column position");
|
||||
Collections.swap(order, 0, 1);
|
||||
try {
|
||||
@@ -344,7 +366,8 @@ public final class MediaLayoutGridTargetProbe {
|
||||
: "Missing definition migration"),
|
||||
"Wrong setup restore " + error);
|
||||
}
|
||||
return "Setup archiver-pruefung/2 · fremde ID und alte Version abgewiesen · folder fest an"
|
||||
return "path start 230 px, resize to 50/600 clamped to 150/300 px, reset 230 px · Setup"
|
||||
+ " archiver-pruefung/2 · fremde ID und alte Version abgewiesen · folder fest an"
|
||||
+ " Index 1 · Posteingang sichtbar, Gruppenschlüssel Post";
|
||||
}
|
||||
|
||||
|
||||
@@ -130,10 +130,67 @@ public final class MediaLayoutGridWorkflowProbe extends DeclarationWorkflowProbe
|
||||
interactive("archive-window-media", "media");
|
||||
}
|
||||
|
||||
private void columnWidths() throws Exception {
|
||||
select("DataGridColumn", "path");
|
||||
for (var pair : List.of(List.of("minimumWidth", "300"), List.of("maximumWidth", "100"))) {
|
||||
String before = source();
|
||||
combo("declaration-property", pair.getFirst());
|
||||
fx(
|
||||
() -> {
|
||||
((ComboBox<?>) pane.lookup("#declaration-value")).getEditor().setText(pair.getLast());
|
||||
return null;
|
||||
});
|
||||
click(pane, "Apply setting");
|
||||
var message = fx(() -> ((Label) pane.lookup("#declaration-message")).getText());
|
||||
if (!source().equals(before)
|
||||
|| !message.contains(pair.getFirst() + "=" + pair.getLast())
|
||||
|| !message.contains("width=230"))
|
||||
throw new AssertionError("Invalid width edit: " + message);
|
||||
if (!fx(
|
||||
() ->
|
||||
((javafx.scene.image.ImageView) pane.lookup("#full-preview-image")).getImage() != null
|
||||
&& ((Label) pane.lookup("#preview-state")).getText().contains("Beispieldateien")))
|
||||
throw new AssertionError("Lost the valid example preview");
|
||||
step("Rejected · valid FXML and example preview retained · " + message);
|
||||
}
|
||||
applySetting("minimumWidth", "150");
|
||||
applySetting("maximumWidth", "300");
|
||||
applySetting("width", "240");
|
||||
for (String field : List.of("width", "minimumWidth", "maximumWidth")) {
|
||||
String before = source();
|
||||
combo("declaration-property", field);
|
||||
fx(
|
||||
() -> {
|
||||
((ComboBox<?>) pane.lookup("#declaration-value")).getEditor().clear();
|
||||
return null;
|
||||
});
|
||||
click(pane, "Apply setting");
|
||||
await(() -> !source().equals(before));
|
||||
String reset = source();
|
||||
history(before, reset);
|
||||
click(pane, "Undo");
|
||||
await(() -> source().equals(before));
|
||||
fx(pane::flush).toCompletableFuture().get();
|
||||
}
|
||||
applySetting("width", "230");
|
||||
}
|
||||
|
||||
private void folder() throws Exception {
|
||||
open("FolderTab");
|
||||
build("archive-folder");
|
||||
choose("preview-example", "archive-folder");
|
||||
await(
|
||||
() ->
|
||||
fx(
|
||||
() ->
|
||||
((javafx.scene.image.ImageView) pane.lookup("#full-preview-image")).getImage()
|
||||
!= null
|
||||
&& ((Label) pane.lookup("#preview-state"))
|
||||
.getText()
|
||||
.contains("Beispieldateien")));
|
||||
inspector(true);
|
||||
var original = declarations();
|
||||
columnWidths();
|
||||
select("DataGrid", "grid");
|
||||
applySetting("setupId", "archiver-pruefung");
|
||||
applySetting("setupVersion", "2");
|
||||
|
||||
Reference in New Issue
Block a user