Edit single content slots, tab and split layouts, and grid setup declarations
This commit is contained in:
@@ -0,0 +1,362 @@
|
||||
package qualification;
|
||||
|
||||
import java.lang.reflect.*;
|
||||
import java.nio.file.*;
|
||||
import java.util.*;
|
||||
import java.util.concurrent.*;
|
||||
import java.util.concurrent.atomic.AtomicBoolean;
|
||||
import javafx.application.Platform;
|
||||
import javafx.beans.value.*;
|
||||
import javafx.event.ActionEvent;
|
||||
import javafx.scene.*;
|
||||
import javafx.scene.control.*;
|
||||
import javafx.scene.layout.*;
|
||||
import javafx.stage.*;
|
||||
import javax.imageio.ImageIO;
|
||||
|
||||
/** Acts on the actual controls in the interactive Archiver worker. */
|
||||
public final class MediaLayoutGridTargetProbe {
|
||||
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 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 attempt = Files.readString(dir.resolve("layout-case"));
|
||||
fx(
|
||||
() -> {
|
||||
shown.setWidth(1180);
|
||||
shown.setHeight(660);
|
||||
return null;
|
||||
});
|
||||
await(
|
||||
"Resized interactive preview",
|
||||
() -> shown.getScene().getWidth() >= 1100 && shown.getScene().getHeight() >= 550);
|
||||
var root =
|
||||
fx(
|
||||
() -> {
|
||||
var node = shown.getScene().getRoot();
|
||||
node.applyCss();
|
||||
node.layout();
|
||||
return node;
|
||||
});
|
||||
String result =
|
||||
switch (attempt) {
|
||||
case "offline" -> fx(() -> offline(root));
|
||||
case "details" -> fx(() -> details(root, dir));
|
||||
case "trash" -> fx(() -> trash(root, dir));
|
||||
case "media" -> media(root, dir);
|
||||
case "grid" -> fx(() -> grid(root, dir));
|
||||
default -> throw new IllegalArgumentException(attempt);
|
||||
};
|
||||
Files.writeString(dir.resolve("result-" + attempt), result);
|
||||
} 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 String offline(Node root) {
|
||||
var media = (Button) root.lookup("#external-media-load");
|
||||
require(
|
||||
media.isDisabled() && media.getAccessibleText().equals("Belegbilder laden"),
|
||||
"Offline: " + media.getAccessibleText());
|
||||
require(media.getTooltip().getText().contains("Keine auflösbaren"), "Offline tooltip");
|
||||
return "Rechnung ohne Medien · gespeicherter Aktionsname, Tooltip und gesperrter Button";
|
||||
}
|
||||
|
||||
private static String details(Parent root, Path dir) throws Exception {
|
||||
var tabs = (TabPane) root;
|
||||
require(
|
||||
tabs.getTabs().stream()
|
||||
.map(Tab::getText)
|
||||
.toList()
|
||||
.equals(List.of("Tags", "Datei", "Belegprüfung")),
|
||||
"Tab order");
|
||||
var moved = tabs.getTabs().getLast();
|
||||
tabs.getSelectionModel().select(moved);
|
||||
root.applyCss();
|
||||
root.layout();
|
||||
var scroll = (ScrollPane) moved.getContent();
|
||||
var box = (HBox) scroll.getContent();
|
||||
var input = (TextField) box.lookup("#tag-input");
|
||||
require(input != null && tabs.getTabs().getFirst().getContent() == null, "Moved HBox");
|
||||
require(
|
||||
((List<?>) input.getClass().getMethod("getSuggestionsSource").invoke(input))
|
||||
.contains("Beleg geprüft"),
|
||||
"Bound suggestions");
|
||||
input.setText("Beleg geprüft");
|
||||
input.fireEvent(new ActionEvent());
|
||||
require(box.lookupAll(".tag-chip").size() == 2, "Moved tag handler and Repeat");
|
||||
image(root, dir.resolve("details-moved.png"));
|
||||
return "Dritter Tab → ScrollPane → ursprüngliche HBox · Vorschlagsquelle, onAction und beide"
|
||||
+ " TagChips wirksam";
|
||||
}
|
||||
|
||||
private static String trash(Parent root, Path dir) throws Exception {
|
||||
var split = (SplitPane) root.lookup(".split-pane");
|
||||
require(
|
||||
split.getItems().size() == 3
|
||||
&& "trash-items".equals(split.getItems().getFirst().getId())
|
||||
&& split.getItems().get(1) instanceof Label l
|
||||
&& "Dateien der Auswahl".equals(l.getText())
|
||||
&& "trash-files".equals(split.getItems().getLast().getId()),
|
||||
"SplitPane order");
|
||||
require(
|
||||
((TableView<?>) split.getItems().getLast()).getItems().size() == 2,
|
||||
"Selected folder files");
|
||||
image(root, dir.resolve("trash-split.png"));
|
||||
return "Beschriftung an Position 2 zwischen beiden Tabellen · zwei Dateien im markierten"
|
||||
+ " Ordner";
|
||||
}
|
||||
|
||||
private static void await(String name, Callable<Boolean> test) throws Exception {
|
||||
long end = System.nanoTime() + TimeUnit.SECONDS.toNanos(14);
|
||||
while (System.nanoTime() < end) {
|
||||
if (fx(test)) return;
|
||||
Thread.sleep(60);
|
||||
}
|
||||
throw new AssertionError(name);
|
||||
}
|
||||
|
||||
private static Object get(Object target, String method) throws Exception {
|
||||
return target.getClass().getMethod(method).invoke(target);
|
||||
}
|
||||
|
||||
private static String media(Parent root, Path dir) throws Exception {
|
||||
var group =
|
||||
fx(
|
||||
() ->
|
||||
root.lookupAll(".tab-pane").stream()
|
||||
.map(TabPane.class::cast)
|
||||
.filter(
|
||||
p ->
|
||||
p.getTabs().stream()
|
||||
.anyMatch(t -> t.getText().equals("Rechnung.html")))
|
||||
.findFirst()
|
||||
.orElseThrow());
|
||||
fx(
|
||||
() -> {
|
||||
require(
|
||||
root instanceof BorderPane p
|
||||
&& p.getLeft() instanceof Label l
|
||||
&& l.getText().equals("Medienprüfung")
|
||||
&& p.getCenter().lookup("#dockPane") != null,
|
||||
"BorderPane and docking");
|
||||
return null;
|
||||
});
|
||||
var invoice = select(group, "Rechnung.html");
|
||||
fx(() -> offline(invoice));
|
||||
var delivery = select(group, "Lieferschein.html");
|
||||
var viewer = fx(() -> delivery.lookup("#html-document"));
|
||||
var button = fx(() -> (Button) delivery.lookup("#external-media-load"));
|
||||
var blockedDuringLoad = new AtomicBoolean();
|
||||
fx(
|
||||
() -> {
|
||||
require(
|
||||
((Label) root.lookup("#status")).getText().equals("Lokale Bildanfragen · 0"),
|
||||
"Request before grant");
|
||||
require(
|
||||
!button.isDisabled()
|
||||
&& button.getAccessibleText().equals("Belegbilder laden")
|
||||
&& button.getTooltip().getText().contains("Belegbilder laden")
|
||||
&& button.getTooltip().getText().contains("Kontaktiert die Bildserver"),
|
||||
"Delivery action");
|
||||
var loading = (ObservableBooleanValue) get(viewer, "loadingProperty");
|
||||
loading.addListener(
|
||||
(obs, old, active) -> {
|
||||
if (active && button.isDisabled()) blockedDuringLoad.set(true);
|
||||
});
|
||||
button.fire();
|
||||
return null;
|
||||
});
|
||||
await(
|
||||
"Granted image and request",
|
||||
() -> {
|
||||
var engine = get(viewer.lookup("WebView"), "getEngine");
|
||||
var pixels =
|
||||
engine
|
||||
.getClass()
|
||||
.getMethod("executeScript", String.class)
|
||||
.invoke(engine, "document.images.length ? document.images[0].naturalWidth : 0");
|
||||
return ((Label) root.lookup("#status")).getText().equals("Lokale Bildanfragen · 1")
|
||||
&& !button.isDisabled()
|
||||
&& ((Number) pixels).intValue() == 24;
|
||||
});
|
||||
fx(
|
||||
() -> {
|
||||
require(
|
||||
blockedDuringLoad.get()
|
||||
&& (boolean) get(viewer, "isExternalImagesAllowed")
|
||||
&& button.getAccessibleText().equals("Externe Medien erneut laden"),
|
||||
"Loading / reload states");
|
||||
image(root, dir.resolve("media-granted.png"));
|
||||
return null;
|
||||
});
|
||||
var other = select(group, "Rechnung.html");
|
||||
fx(
|
||||
() -> {
|
||||
offline(other);
|
||||
require(
|
||||
!(boolean) get(other.lookup("#html-document"), "isExternalImagesAllowed"),
|
||||
"Invoice inherited grant");
|
||||
return null;
|
||||
});
|
||||
select(group, "Lieferschein.html");
|
||||
fx(
|
||||
() -> {
|
||||
require(
|
||||
!button.isDisabled() && button.getAccessibleText().contains("erneut"),
|
||||
"Return to delivery");
|
||||
button.fire();
|
||||
return null;
|
||||
});
|
||||
await(
|
||||
"Reload reached loopback",
|
||||
() ->
|
||||
((Label) root.lookup("#status")).getText().equals("Lokale Bildanfragen · 2")
|
||||
&& !button.isDisabled());
|
||||
return "BorderPane.left mit intaktem Docking · HTTP-Anfragen 0 → 1 → 2 · Bildbreite 24 px,"
|
||||
+ " Ladesperre, erneutes Laden und tabbezogene Freigabe geprüft";
|
||||
}
|
||||
|
||||
private static Node select(TabPane tabs, String title) throws Exception {
|
||||
return fx(
|
||||
() -> {
|
||||
var tab =
|
||||
tabs.getTabs().stream()
|
||||
.filter(t -> title.equals(t.getText()))
|
||||
.findFirst()
|
||||
.orElseThrow();
|
||||
tabs.getSelectionModel().select(tab);
|
||||
tabs.applyCss();
|
||||
tabs.layout();
|
||||
return tab.getContent();
|
||||
});
|
||||
}
|
||||
|
||||
private static String grid(Parent root, Path dir) throws Exception {
|
||||
Node grid = root.lookup("#grid");
|
||||
var setup = get(grid, "snapshotSetup");
|
||||
require(
|
||||
get(setup, "definitionId").equals("archiver-pruefung")
|
||||
&& get(setup, "definitionVersion").equals(2),
|
||||
"Setup identity");
|
||||
var cols = (List<?>) get(setup, "columns");
|
||||
var order = new ArrayList<String>();
|
||||
for (var col : cols) order.add((String) get(col, "id"));
|
||||
require(order.get(1).equals("folder"), "Column position");
|
||||
Collections.swap(order, 0, 1);
|
||||
try {
|
||||
grid.getClass().getMethod("setColumnOrder", List.class).invoke(grid, order);
|
||||
throw new AssertionError("Fixed column displaced");
|
||||
} catch (InvocationTargetException ex) {
|
||||
require(
|
||||
ex.getCause() instanceof IllegalArgumentException
|
||||
&& ex.getCause().getMessage().contains("Fixed"),
|
||||
"Fixed position check");
|
||||
}
|
||||
var heading =
|
||||
grid.lookupAll(".group-heading").stream()
|
||||
.map(Button.class::cast)
|
||||
.filter(b -> b.getText().contains("Posteingang"))
|
||||
.findFirst()
|
||||
.orElseThrow();
|
||||
require(
|
||||
grid.lookupAll(".group-heading").stream()
|
||||
.map(Button.class::cast)
|
||||
.anyMatch(b -> b.getText().contains("Rechnungen")),
|
||||
"Other group");
|
||||
image(root, dir.resolve("grid-group.png"));
|
||||
heading.fire();
|
||||
var grouping = get(get(grid, "snapshotSetup"), "grouping");
|
||||
var choice = ((List<?>) get(grouping, "choices")).getFirst();
|
||||
var segment = ((List<?>) get(get(choice, "path"), "segments")).getFirst();
|
||||
require(
|
||||
get(segment, "columnId").equals("folder")
|
||||
&& get(get(segment, "value"), "value").equals("Post"),
|
||||
"Changed group key");
|
||||
for (String id : List.of("archive-folder", "archiver-pruefung")) {
|
||||
var fields = setup.getClass().getRecordComponents();
|
||||
Object[] values = new Object[fields.length];
|
||||
for (int i = 0; i < fields.length; i++)
|
||||
values[i] =
|
||||
switch (fields[i].getName()) {
|
||||
case "definitionId" -> id;
|
||||
case "definitionVersion" -> 1;
|
||||
default -> fields[i].getAccessor().invoke(setup);
|
||||
};
|
||||
var old =
|
||||
setup
|
||||
.getClass()
|
||||
.getConstructor(
|
||||
Arrays.stream(fields).map(RecordComponent::getType).toArray(Class<?>[]::new))
|
||||
.newInstance(values);
|
||||
grid.getClass().getMethod("restoreSetup", setup.getClass()).invoke(grid, old);
|
||||
var state = ((ObservableValue<?>) get(grid, "stateProperty")).getValue();
|
||||
var error = (Throwable) get(state, "error");
|
||||
require(
|
||||
error != null
|
||||
&& error
|
||||
.getMessage()
|
||||
.contains(
|
||||
id.equals("archive-folder")
|
||||
? "another grid definition"
|
||||
: "Missing definition migration"),
|
||||
"Wrong setup restore " + error);
|
||||
}
|
||||
return "Setup archiver-pruefung/2 · fremde ID und alte Version abgewiesen · folder fest an"
|
||||
+ " Index 1 · Posteingang sichtbar, Gruppenschlüssel Post";
|
||||
}
|
||||
|
||||
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,336 @@
|
||||
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.*;
|
||||
import javafx.embed.swing.SwingFXUtils;
|
||||
import javafx.scene.control.*;
|
||||
import javafx.scene.image.ImageView;
|
||||
import javax.imageio.ImageIO;
|
||||
import org.w3c.dom.Element;
|
||||
|
||||
/** Edits original Archiver forms in the registered IntelliJ designer. */
|
||||
public final class MediaLayoutGridWorkflowProbe extends FormWorkflowProbe {
|
||||
private Project project;
|
||||
|
||||
void verify(Project project) throws Exception {
|
||||
this.project = project;
|
||||
open("HtmlDocument");
|
||||
controls(true);
|
||||
choose("form-control", "HtmlViewer #article");
|
||||
set("mediaLoadText", "Belegbilder laden", "mediaLoadText=\"Belegbilder laden\"");
|
||||
reopen("HtmlDocument", "Belegbilder laden");
|
||||
build("html-invoice");
|
||||
interactive("html-invoice", "offline");
|
||||
details();
|
||||
trash();
|
||||
window();
|
||||
folder();
|
||||
Files.writeString(output.resolve("SUCCESS.txt"), Files.readString(output.resolve("steps.txt")));
|
||||
}
|
||||
|
||||
private void insert(String type, String slot, int position, String id) throws Exception {
|
||||
choose("form-palette", type);
|
||||
choose("form-destination", slot);
|
||||
if (position >= 0)
|
||||
fx(
|
||||
() -> {
|
||||
((Spinner<Integer>) pane.lookup("#form-position")).getValueFactory().setValue(position);
|
||||
return null;
|
||||
});
|
||||
String before = source();
|
||||
click(pane, "Insert control");
|
||||
edited(before, "fx:id=\"" + id + "\"");
|
||||
}
|
||||
|
||||
private void reject(String type, String slot, String reason) throws Exception {
|
||||
choose("form-palette", type);
|
||||
choose("form-destination", slot);
|
||||
String before = source();
|
||||
click(pane, "Insert control");
|
||||
if (!before.equals(source())
|
||||
|| !fx(() -> ((Label) pane.lookup("#form-message")).getText()).contains(reason))
|
||||
throw new AssertionError("Expected " + reason);
|
||||
}
|
||||
|
||||
private void history(String before, String after) throws Exception {
|
||||
click(pane, "Undo");
|
||||
await(() -> source().equals(before));
|
||||
click(pane, "Redo");
|
||||
await(() -> source().equals(after));
|
||||
fx(pane::flush).toCompletableFuture().get();
|
||||
}
|
||||
|
||||
private List<String> declarations() throws Exception {
|
||||
return source()
|
||||
.lines()
|
||||
.map(String::trim)
|
||||
.filter(
|
||||
l ->
|
||||
l.startsWith("<DirectBinding ")
|
||||
|| l.startsWith("<CommandBinding ")
|
||||
|| l.startsWith("<Repeat "))
|
||||
.toList();
|
||||
}
|
||||
|
||||
private void details() throws Exception {
|
||||
open("DocumentDetails");
|
||||
controls(true);
|
||||
var original = declarations();
|
||||
reject("Label", "TabPane [", "TabPane.tabs accepts Tab");
|
||||
reject("Label", "ScrollPane [", "Occupied");
|
||||
insert("Tab", "TabPane [", -1, "tab");
|
||||
choose("form-control", "Tab #tab");
|
||||
set("text", "Belegprüfung", "text=\"Belegprüfung\"");
|
||||
insert("ScrollPane", "Tab #tab / content", 0, "scrollPane");
|
||||
choose("form-control", "HBox [");
|
||||
choose("form-destination", "ScrollPane #scrollPane / content");
|
||||
String before = source();
|
||||
click(pane, "Move to destination");
|
||||
edited(before, "onAction=\"#addTag\"");
|
||||
history(before, source());
|
||||
reopen("DocumentDetails", "Belegprüfung");
|
||||
if (!original.equals(declarations())) throw new AssertionError("Moved bindings");
|
||||
build("details-invoice");
|
||||
interactive("details-invoice", "details");
|
||||
}
|
||||
|
||||
private void trash() throws Exception {
|
||||
open("TrashPane");
|
||||
controls(true);
|
||||
insert("Label", "SplitPane [", 1, "label");
|
||||
choose("form-control", "Label #label");
|
||||
set("text", "Dateien der Auswahl", "text=\"Dateien der Auswahl\"");
|
||||
reopen("TrashPane", "Dateien der Auswahl");
|
||||
build("trash-full");
|
||||
interactive("trash-full", "trash");
|
||||
}
|
||||
|
||||
private void window() throws Exception {
|
||||
open("ArchiveWindow");
|
||||
controls(true);
|
||||
String left =
|
||||
fx(
|
||||
() ->
|
||||
((ComboBox<?>) pane.lookup("#form-destination"))
|
||||
.getItems().stream()
|
||||
.map(Object::toString)
|
||||
.filter(v -> v.startsWith("BorderPane [") && v.endsWith(" / left"))
|
||||
.findFirst()
|
||||
.orElseThrow());
|
||||
String owner = left.substring(0, left.lastIndexOf(" / "));
|
||||
for (String region : List.of("center", "top", "bottom", "left", "right")) {
|
||||
choose("form-destination", owner + " / " + region);
|
||||
}
|
||||
reject("Label", owner + " / center", "Occupied");
|
||||
insert("Label", left, 0, "label");
|
||||
choose("form-control", "Label #label");
|
||||
set("text", "Medienprüfung", "text=\"Medienprüfung\"");
|
||||
reopen("ArchiveWindow", "Medienprüfung");
|
||||
build("archive-window-media");
|
||||
interactive("archive-window-media", "media");
|
||||
}
|
||||
|
||||
private void folder() throws Exception {
|
||||
open("FolderTab");
|
||||
inspector(true);
|
||||
var original = declarations();
|
||||
select("DataGrid", "grid");
|
||||
gridSet("setupId", "archiver-pruefung");
|
||||
gridSet("setupVersion", "2");
|
||||
for (var pair :
|
||||
List.of(List.of("setupId", "archiver-pruefung"), List.of("setupVersion", "2"))) {
|
||||
String before = source();
|
||||
combo("declaration-property", pair.getFirst());
|
||||
fx(
|
||||
() -> {
|
||||
((ComboBox<?>) pane.lookup("#declaration-value")).getEditor().clear();
|
||||
return null;
|
||||
});
|
||||
click(pane, "Apply setting");
|
||||
await(() -> !source().contains(pair.getFirst() + "=\""));
|
||||
click(pane, "Undo");
|
||||
await(() -> source().equals(before));
|
||||
}
|
||||
gridSet("groupBy", "folder");
|
||||
select("DataGridColumn", "folder");
|
||||
gridSet("fixedPosition", "1");
|
||||
combo("declaration-property", "groupLabels");
|
||||
fx(
|
||||
() -> {
|
||||
((ComboBox<?>) pane.lookup("#group-label-key")).getEditor().setText("Post");
|
||||
((TextField) pane.lookup("#group-label-text")).setText("Posteingang");
|
||||
return null;
|
||||
});
|
||||
String before = source();
|
||||
edit("Set group label", "Post=\"Posteingang\"");
|
||||
String grouped = source();
|
||||
history(before, grouped);
|
||||
combo("declaration-property", "groupLabels");
|
||||
choose("group-label-key", "Post");
|
||||
click(pane, "Remove group label");
|
||||
await(() -> !source().contains("Post=\"Posteingang\""));
|
||||
click(pane, "Undo");
|
||||
await(() -> source().equals(grouped));
|
||||
reopen("FolderTab", "Posteingang");
|
||||
if (!original.equals(declarations())) throw new AssertionError("Grid bindings");
|
||||
inspector(true);
|
||||
select("DataGridColumn", "folder");
|
||||
combo("declaration-property", "groupLabels");
|
||||
if (!fx(() -> ((TextField) pane.lookup("#group-label-text")).getText().equals("Posteingang")))
|
||||
throw new AssertionError("Reopened mapping");
|
||||
fx(
|
||||
() -> {
|
||||
ImageIO.write(
|
||||
SwingFXUtils.fromFXImage(pane.snapshot(null, null), null),
|
||||
"png",
|
||||
output.resolve("intellij.png").toFile());
|
||||
return null;
|
||||
});
|
||||
build("archive-folder");
|
||||
interactive("archive-folder", "grid");
|
||||
}
|
||||
|
||||
private void open(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);
|
||||
if (!source().contains("<?neitzel-model de.neitzel.archiver.ui."))
|
||||
throw new AssertionError(name);
|
||||
}
|
||||
|
||||
private void build(String id) 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(id))));
|
||||
}
|
||||
|
||||
private void interactive(String id, String attempt) throws Exception {
|
||||
choose("preview-example", id);
|
||||
await(
|
||||
() ->
|
||||
fx(
|
||||
() -> {
|
||||
var 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);
|
||||
var choice = (Example) ((ComboBox<?>) pane.lookup("#preview-example")).getValue();
|
||||
return ((ImageView) pane.lookup("#full-preview-image")).getImage() != null
|
||||
&& state.contains(choice.label());
|
||||
}));
|
||||
Files.writeString(output.resolve("layout-case"), attempt);
|
||||
click(pane, "Interactive preview");
|
||||
String name = "result-" + attempt;
|
||||
awaitTarget(name);
|
||||
step(id + " · " + Files.readString(output.resolve(name)));
|
||||
click(pane, "Stop preview");
|
||||
}
|
||||
|
||||
private void reopen(String form, String saved) throws Exception {
|
||||
click(pane, "Save");
|
||||
await(() -> Files.readString(Path.of(file.getPath())).contains(saved));
|
||||
edt(
|
||||
() -> {
|
||||
FileEditorManager.getInstance(project).closeFile(file);
|
||||
return null;
|
||||
});
|
||||
open(form);
|
||||
if (!source().contains(saved)) throw new AssertionError("Reopened " + form);
|
||||
}
|
||||
|
||||
private void inspector(boolean expanded) throws Exception {
|
||||
fx(
|
||||
() -> {
|
||||
var panel =
|
||||
(TitledPane)
|
||||
pane.lookupAll(".titled-pane").stream()
|
||||
.filter(n -> n instanceof TitledPane t && t.getText().equals("Bindings"))
|
||||
.findFirst()
|
||||
.orElseThrow();
|
||||
panel.setAnimated(false);
|
||||
panel.setExpanded(expanded);
|
||||
var tabs = (TabPane) panel.getContent();
|
||||
tabs.getSelectionModel()
|
||||
.select(
|
||||
tabs.getTabs().stream()
|
||||
.filter(t -> t.getText().equals("DataGrid / Docking"))
|
||||
.findFirst()
|
||||
.orElseThrow());
|
||||
pane.applyCss();
|
||||
pane.layout();
|
||||
return null;
|
||||
});
|
||||
}
|
||||
|
||||
private void select(String name, String id) throws Exception {
|
||||
fx(
|
||||
() -> {
|
||||
var tree = (TreeView<Element>) pane.lookup("#declaration-tree");
|
||||
for (int i = 0; i < tree.getExpandedItemCount(); i++) {
|
||||
var item = tree.getTreeItem(i);
|
||||
var e = item.getValue();
|
||||
String tag = e.getTagName();
|
||||
if ((tag.equals(name) || tag.endsWith("." + name))
|
||||
&& (id.isEmpty()
|
||||
|| e.getAttribute("fx:id").equals(id)
|
||||
|| e.getAttribute("id").equals(id)
|
||||
|| e.getAttribute("destinationId").equals(id))) {
|
||||
tree.getSelectionModel().select(item);
|
||||
return null;
|
||||
}
|
||||
}
|
||||
throw new AssertionError("Missing " + name + " " + id);
|
||||
});
|
||||
}
|
||||
|
||||
private void combo(String name, String text) throws Exception {
|
||||
fx(
|
||||
() -> {
|
||||
var box = (ComboBox<String>) pane.lookup("#" + name);
|
||||
box.setValue(text);
|
||||
return null;
|
||||
});
|
||||
}
|
||||
|
||||
private void edit(String button, String expected) throws Exception {
|
||||
String before = source();
|
||||
click(pane, button);
|
||||
await(
|
||||
() -> {
|
||||
String now = source();
|
||||
var msg = fx(() -> ((Label) pane.lookup("#declaration-message")).getText());
|
||||
if (!msg.isEmpty()) throw new AssertionError(msg);
|
||||
return !now.equals(before)
|
||||
&& now.contains(expected)
|
||||
&& fx(
|
||||
() ->
|
||||
((TextArea) pane.lookup("#fxml-source")) == null
|
||||
|| ((TextArea) pane.lookup("#fxml-source")).getText().equals(now));
|
||||
});
|
||||
fx(pane::flush).toCompletableFuture().get();
|
||||
step(button + " · " + expected);
|
||||
}
|
||||
|
||||
private void gridSet(String field, String value) throws Exception {
|
||||
combo("declaration-property", field);
|
||||
fx(
|
||||
() -> {
|
||||
((ComboBox<?>) pane.lookup("#declaration-value")).getEditor().setText(value);
|
||||
return null;
|
||||
});
|
||||
edit("Apply setting", field + "=\"" + value + "\"");
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user