Edit docking group constraints and qualify document tab behavior in IntelliJ
This commit is contained in:
@@ -0,0 +1,155 @@
|
||||
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 javafx.scene.control.*;
|
||||
import javafx.scene.image.ImageView;
|
||||
import org.w3c.dom.Element;
|
||||
|
||||
/** Shared actions for editing declarations and opening the resulting Archiver preview. */
|
||||
abstract class DeclarationWorkflowProbe extends FormWorkflowProbe {
|
||||
Project project;
|
||||
|
||||
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);
|
||||
}
|
||||
|
||||
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))));
|
||||
}
|
||||
|
||||
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");
|
||||
}
|
||||
|
||||
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);
|
||||
}
|
||||
|
||||
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;
|
||||
});
|
||||
}
|
||||
|
||||
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);
|
||||
});
|
||||
}
|
||||
|
||||
void combo(String name, String text) throws Exception {
|
||||
fx(
|
||||
() -> {
|
||||
var box = (ComboBox<String>) pane.lookup("#" + name);
|
||||
box.setValue(text);
|
||||
return null;
|
||||
});
|
||||
}
|
||||
|
||||
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);
|
||||
}
|
||||
|
||||
void applySetting(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 + "\"");
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,331 @@
|
||||
package qualification;
|
||||
|
||||
import java.nio.file.*;
|
||||
import java.util.*;
|
||||
import java.util.concurrent.*;
|
||||
import javafx.application.Platform;
|
||||
import javafx.geometry.Side;
|
||||
import javafx.scene.Parent;
|
||||
import javafx.scene.control.*;
|
||||
import javafx.stage.*;
|
||||
|
||||
/** Operates the document tabs' ordinary context menus in the interactive Archiver worker. */
|
||||
public final class DockRulesTargetProbe {
|
||||
public static void premain(String directory) {
|
||||
if (System.getProperty("sun.java.command", "")
|
||||
.startsWith("de.neitzel.fxdesigner.target.WorkerMain "))
|
||||
Thread.ofPlatform().daemon().start(() -> Worker.run(Path.of(directory)));
|
||||
}
|
||||
|
||||
private static final class Worker {
|
||||
private static final String INVOICE = "Rechnung.html", DELIVERY = "Lieferschein.html";
|
||||
|
||||
static <T> T fx(Callable<T> action) throws Exception {
|
||||
var task = new FutureTask<>(action);
|
||||
Platform.runLater(task);
|
||||
return task.get(10, TimeUnit.SECONDS);
|
||||
}
|
||||
|
||||
static void run(Path dir) {
|
||||
try {
|
||||
Stage stage = null;
|
||||
while (stage == null) {
|
||||
Thread.sleep(100);
|
||||
try {
|
||||
stage =
|
||||
fx(
|
||||
() ->
|
||||
Window.getWindows().stream()
|
||||
.filter(Stage.class::isInstance)
|
||||
.map(Stage.class::cast)
|
||||
.filter(
|
||||
s ->
|
||||
s.isShowing()
|
||||
&& s.getOpacity() > 0
|
||||
&& Objects.toString(s.getTitle(), "")
|
||||
.startsWith("Neitzel preview"))
|
||||
.findFirst()
|
||||
.orElse(null));
|
||||
} catch (IllegalStateException starting) {
|
||||
/* Await JavaFX startup. */
|
||||
}
|
||||
}
|
||||
Stage preview = stage;
|
||||
String attempt = Files.readString(dir.resolve("layout-case"));
|
||||
Parent root = fx(() -> preview.getScene().getRoot());
|
||||
String result;
|
||||
if (attempt.equals("defaults")) {
|
||||
result = fx(() -> defaults(root));
|
||||
} else {
|
||||
boolean horizontal = attempt.equals("horizontal");
|
||||
require(horizontal || attempt.equals("vertical"), attempt);
|
||||
resize(preview, 640, 440);
|
||||
String small = fx(() -> checkRules(root, horizontal, false));
|
||||
resize(preview, 1340, 760);
|
||||
String large = fx(() -> checkRules(root, horizontal, true));
|
||||
await(() -> tab(root, INVOICE).getTabPane() != tab(root, DELIVERY).getTabPane());
|
||||
String split = fx(() -> inspectSplit(root, horizontal, dir));
|
||||
fx(
|
||||
() -> {
|
||||
move(root, DELIVERY, "details");
|
||||
return null;
|
||||
});
|
||||
await(() -> tab(root, INVOICE).getTabPane().getTabs().size() == 1);
|
||||
fx(
|
||||
() -> {
|
||||
var invoice = tab(root, INVOICE);
|
||||
var menu = menu(invoice);
|
||||
item(menu.getItems(), "Close", "Schließen").fire();
|
||||
return null;
|
||||
});
|
||||
await(() -> tabs(root).stream().noneMatch(t -> t.getText().equals(INVOICE)));
|
||||
String empty = fx(() -> verifyEmpty(root, !horizontal, dir));
|
||||
result = small + "\n" + large + "\n" + split + "\n" + empty;
|
||||
}
|
||||
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 ex) {
|
||||
ex.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
static void await(Callable<Boolean> test) throws Exception {
|
||||
long end = System.nanoTime() + TimeUnit.SECONDS.toNanos(10);
|
||||
while (System.nanoTime() < end) {
|
||||
if (fx(test)) return;
|
||||
Thread.sleep(50);
|
||||
}
|
||||
throw new AssertionError("Preview state did not settle");
|
||||
}
|
||||
|
||||
static void resize(Stage stage, int width, int height) throws Exception {
|
||||
fx(
|
||||
() -> {
|
||||
stage.setWidth(width);
|
||||
stage.setHeight(height);
|
||||
return null;
|
||||
});
|
||||
await(
|
||||
() ->
|
||||
Math.abs(stage.getScene().getWidth() - width) < 12
|
||||
&& stage.getScene().getHeight() > height - 60
|
||||
&& stage.getScene().getHeight() <= height);
|
||||
fx(
|
||||
() -> {
|
||||
layout(stage.getScene().getRoot());
|
||||
return null;
|
||||
});
|
||||
}
|
||||
|
||||
static void layout(Parent root) {
|
||||
root.applyCss();
|
||||
root.layout();
|
||||
}
|
||||
|
||||
static void require(boolean ok, String reason) {
|
||||
if (!ok) throw new AssertionError(reason);
|
||||
}
|
||||
|
||||
static List<Tab> tabs(Parent root) {
|
||||
return root.lookupAll(".dock-group").stream()
|
||||
.map(TabPane.class::cast)
|
||||
.flatMap(p -> p.getTabs().stream())
|
||||
.toList();
|
||||
}
|
||||
|
||||
static Tab tab(Parent root, String name) {
|
||||
return tabs(root).stream().filter(t -> name.equals(t.getText())).findFirst().orElseThrow();
|
||||
}
|
||||
|
||||
static ContextMenu menu(Tab tab) {
|
||||
var m = tab.getContextMenu();
|
||||
m.show(tab.getTabPane(), Side.TOP, 0, 0);
|
||||
return m;
|
||||
}
|
||||
|
||||
static MenuItem item(List<MenuItem> items, String... labels) {
|
||||
return items.stream()
|
||||
.filter(
|
||||
i ->
|
||||
Arrays.stream(labels)
|
||||
.anyMatch(
|
||||
l ->
|
||||
l.equals(i.getText())
|
||||
|| i.getText().startsWith(l + " (")
|
||||
|| i.getText().startsWith(l + " —")))
|
||||
.findFirst()
|
||||
.orElseThrow(
|
||||
() ->
|
||||
new AssertionError(
|
||||
"Missing "
|
||||
+ Arrays.toString(labels)
|
||||
+ " in "
|
||||
+ items.stream().map(MenuItem::getText).toList()));
|
||||
}
|
||||
|
||||
static String checkRules(Parent root, boolean horizontal, boolean large) {
|
||||
var delivery = tab(root, DELIVERY);
|
||||
var group = delivery.getTabPane();
|
||||
require(tab(root, INVOICE).getTabPane() == group, "Initial document group");
|
||||
require(group.minWidth(-1) == 300 && group.minHeight(-1) == 225, "Effective minima");
|
||||
var m = menu(delivery);
|
||||
var choices = ((Menu) item(m.getItems(), "Split", "Teilen")).getItems();
|
||||
var right = item(choices, "Right", "Rechts");
|
||||
var below = item(choices, "Below", "Unten");
|
||||
var blocked = horizontal ? below : right;
|
||||
var allowed = horizontal ? right : below;
|
||||
require(
|
||||
blocked.isDisable()
|
||||
&& (blocked.getText().contains("direction")
|
||||
|| blocked.getText().contains("Richtung")),
|
||||
blocked.getText());
|
||||
// Exercise the checked operation as well as its disabled presentation.
|
||||
blocked.fire();
|
||||
require(
|
||||
tab(root, INVOICE).getTabPane() == tab(root, DELIVERY).getTabPane(),
|
||||
"Forbidden split changed layout");
|
||||
String size = Math.round(group.getWidth()) + " × " + Math.round(group.getHeight());
|
||||
if (!large) {
|
||||
require(
|
||||
allowed.isDisable()
|
||||
&& (horizontal
|
||||
? group.getWidth() < 2 * group.minWidth(-1) + 8
|
||||
: group.getHeight() < 2 * group.minHeight(-1) + 8)
|
||||
&& !allowed.getText().equals(blocked.getText()),
|
||||
size + " · " + allowed.getText());
|
||||
allowed.fire();
|
||||
require(
|
||||
tab(root, INVOICE).getTabPane() == tab(root, DELIVERY).getTabPane(),
|
||||
"Small split changed layout");
|
||||
} else {
|
||||
require(!allowed.isDisable(), size + " · " + allowed.getText());
|
||||
allowed.fire();
|
||||
}
|
||||
m.hide();
|
||||
return (large ? "1340 × 760" : "640 × 440")
|
||||
+ " · Gruppe "
|
||||
+ size
|
||||
+ " · "
|
||||
+ blocked.getText()
|
||||
+ " · "
|
||||
+ allowed.getText();
|
||||
}
|
||||
|
||||
static String inspectSplit(Parent root, boolean horizontal, Path dir) throws Exception {
|
||||
layout(root);
|
||||
var first = tab(root, INVOICE).getTabPane();
|
||||
var second = tab(root, DELIVERY).getTabPane();
|
||||
for (var group : List.of(first, second)) {
|
||||
require(group.getWidth() >= 300 && group.getHeight() >= 225, "Split child below minimum");
|
||||
require(
|
||||
group.minWidth(-1) == 300 && group.minHeight(-1) == 225,
|
||||
"Split did not inherit minima");
|
||||
}
|
||||
var a = first.localToScene(first.getLayoutBounds());
|
||||
var b = second.localToScene(second.getLayoutBounds());
|
||||
require(
|
||||
horizontal ? b.getMinX() >= a.getMaxX() - 1 : b.getMinY() >= a.getMaxY() - 1,
|
||||
"Geometric split direction");
|
||||
require(
|
||||
first.lookup("#html-document") != null && second.lookup("#html-document") != null,
|
||||
"Document viewers");
|
||||
image(root, dir.resolve(horizontal ? "dock-horizontal.png" : "dock-vertical.png"));
|
||||
return "Rechnung / Lieferschein · "
|
||||
+ Math.round(a.getWidth())
|
||||
+ " × "
|
||||
+ Math.round(a.getHeight())
|
||||
+ " und "
|
||||
+ Math.round(b.getWidth())
|
||||
+ " × "
|
||||
+ Math.round(b.getHeight());
|
||||
}
|
||||
|
||||
static void move(Parent root, String document, String destination) {
|
||||
var m = menu(tab(root, document));
|
||||
var targets = ((Menu) item(m.getItems(), "Move to", "Verschieben nach")).getItems();
|
||||
var action = item(targets, destination);
|
||||
require(!action.isDisable(), action.getText());
|
||||
action.fire();
|
||||
m.hide();
|
||||
}
|
||||
|
||||
static String verifyEmpty(Parent root, boolean persistent, Path dir) throws Exception {
|
||||
layout(root);
|
||||
var m = menu(tab(root, DELIVERY));
|
||||
var targets = ((Menu) item(m.getItems(), "Move to", "Verschieben nach")).getItems();
|
||||
require(
|
||||
targets.stream().anyMatch(i -> i.getText().startsWith("details")),
|
||||
"details destination gone");
|
||||
var messages = targets.stream().filter(i -> i.getText().equals("messages")).findFirst();
|
||||
require(
|
||||
messages.isPresent() == persistent,
|
||||
"messages target after close: " + targets.stream().map(MenuItem::getText).toList());
|
||||
m.hide();
|
||||
var empty =
|
||||
root.lookupAll(".dock-group").stream()
|
||||
.map(TabPane.class::cast)
|
||||
.filter(t -> t.getTabs().isEmpty() && t.isVisible() && t.isManaged())
|
||||
.toList();
|
||||
require(empty.size() == (persistent ? 1 : 0), "Empty groups: " + empty.size());
|
||||
image(root, dir.resolve(persistent ? "dock-empty-kept.png" : "dock-empty-removed.png"));
|
||||
if (persistent) {
|
||||
move(root, DELIVERY, "messages");
|
||||
require(tab(root, DELIVERY).getTabPane() == empty.getFirst(), "Return to persistent group");
|
||||
}
|
||||
return persistent
|
||||
? "persistent=true · messages bleibt leer sichtbar und nimmt den Lieferschein wieder auf"
|
||||
: "persistent=false · messages nach dem letzten Tab aus Layout und Zielmenü entfernt";
|
||||
}
|
||||
|
||||
static String defaults(Parent root) throws Exception {
|
||||
var pane = root.lookup("#dockPane");
|
||||
var layout = pane.getClass().getMethod("getInitialLayout").invoke(pane);
|
||||
var group = layout.getClass().getMethod("getCenter").invoke(layout);
|
||||
var type = group.getClass();
|
||||
require(
|
||||
Objects.equals(type.getMethod("getMinimumWidth").invoke(group), 80.0)
|
||||
&& Objects.equals(type.getMethod("getMinimumHeight").invoke(group), 80.0)
|
||||
&& (boolean) type.getMethod("isPersistent").invoke(group)
|
||||
&& type.getMethod("getSplitDirections").invoke(group).toString().equals("ALL"),
|
||||
"Effective defaults");
|
||||
var texts =
|
||||
root.lookupAll(".label").stream()
|
||||
.filter(Label.class::isInstance)
|
||||
.map(Label.class::cast)
|
||||
.map(Label::getText)
|
||||
.toList();
|
||||
require(
|
||||
texts.contains("Rechnungen / Musterrechnung.pdf")
|
||||
&& texts.contains("Belegnummer RE-2026-042"),
|
||||
"Original sample content");
|
||||
return "Defaults 80 × 80, true, ALL · Musterrechnung.pdf und Belegnummer RE-2026-042";
|
||||
}
|
||||
|
||||
static void image(Parent root, Path file) throws Exception {
|
||||
var image = root.snapshot(null, null);
|
||||
var pixels =
|
||||
new java.awt.image.BufferedImage(
|
||||
(int) image.getWidth(),
|
||||
(int) image.getHeight(),
|
||||
java.awt.image.BufferedImage.TYPE_INT_ARGB);
|
||||
var buffer = ((java.awt.image.DataBufferInt) pixels.getRaster().getDataBuffer()).getData();
|
||||
image
|
||||
.getPixelReader()
|
||||
.getPixels(
|
||||
0,
|
||||
0,
|
||||
pixels.getWidth(),
|
||||
pixels.getHeight(),
|
||||
javafx.scene.image.PixelFormat.getIntArgbInstance(),
|
||||
buffer,
|
||||
0,
|
||||
pixels.getWidth());
|
||||
javax.imageio.ImageIO.write(pixels, "png", file.toFile());
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,104 @@
|
||||
package qualification;
|
||||
|
||||
import static qualification.WorkflowProbe.*;
|
||||
|
||||
import com.intellij.openapi.project.Project;
|
||||
import java.nio.file.Files;
|
||||
import java.util.List;
|
||||
import javafx.embed.swing.SwingFXUtils;
|
||||
import javafx.scene.control.*;
|
||||
import javax.imageio.ImageIO;
|
||||
|
||||
/** Configures the same central group in three independently loaded preview sessions. */
|
||||
public final class DockRulesWorkflowProbe extends DeclarationWorkflowProbe {
|
||||
private static final String FORM = "ArchiveWindow";
|
||||
private static final String DOCUMENTS = "archive-window-documents";
|
||||
private static final List<String> FIELDS =
|
||||
List.of("minimumWidth", "minimumHeight", "persistent", "splitDirections");
|
||||
|
||||
@Override
|
||||
void verify(Project project) throws Exception {
|
||||
this.project = project;
|
||||
open(FORM);
|
||||
group();
|
||||
reject("minimumWidth", "-0.5");
|
||||
reject("minimumHeight", "Infinity");
|
||||
reject("splitDirections", "RIGHT");
|
||||
reject("persistent", "yes");
|
||||
applySetting("minimumWidth", "300");
|
||||
applySetting("minimumHeight", "225");
|
||||
applySetting("persistent", "false");
|
||||
applySetting("splitDirections", "HORIZONTAL");
|
||||
savedGroup("HORIZONTAL");
|
||||
fx(
|
||||
() -> {
|
||||
ImageIO.write(
|
||||
SwingFXUtils.fromFXImage(pane.snapshot(null, null), null),
|
||||
"png",
|
||||
output.resolve("intellij.png").toFile());
|
||||
return null;
|
||||
});
|
||||
build(DOCUMENTS);
|
||||
interactive(DOCUMENTS, "horizontal");
|
||||
|
||||
group();
|
||||
applySetting("persistent", "true");
|
||||
applySetting("splitDirections", "VERTICAL");
|
||||
savedGroup("VERTICAL");
|
||||
build(DOCUMENTS);
|
||||
interactive(DOCUMENTS, "vertical");
|
||||
|
||||
group();
|
||||
for (var field : FIELDS) {
|
||||
enter(field, "");
|
||||
click(pane, "Apply setting");
|
||||
await(() -> !source().contains(field + "=\""));
|
||||
fx(pane::flush).toCompletableFuture().get();
|
||||
}
|
||||
savedGroup("destinationId=\"messages\"");
|
||||
for (var field : FIELDS) {
|
||||
choose("declaration-property", field);
|
||||
if (!fx(
|
||||
() -> ((ComboBox<?>) pane.lookup("#declaration-value")).getEditor().getText().isEmpty()))
|
||||
throw new AssertionError("Reset " + field);
|
||||
}
|
||||
build("archive-window");
|
||||
interactive("archive-window", "defaults");
|
||||
Files.writeString(output.resolve("SUCCESS.txt"), Files.readString(output.resolve("steps.txt")));
|
||||
}
|
||||
|
||||
private void group() throws Exception {
|
||||
inspector(true);
|
||||
select("DockGroupDefinition", "messages");
|
||||
}
|
||||
|
||||
private void savedGroup(String value) throws Exception {
|
||||
String expected = source();
|
||||
reopen(FORM, expected);
|
||||
if (!source().equals(expected)) throw new AssertionError("Reopened FXML differs");
|
||||
group();
|
||||
select("DockGroupDefinition", "details");
|
||||
select("DockGroupDefinition", "messages");
|
||||
choose("declaration-property", "splitDirections");
|
||||
step("Save / reopen · messages, details · " + value);
|
||||
}
|
||||
|
||||
private void enter(String field, String value) throws Exception {
|
||||
choose("declaration-property", field);
|
||||
fx(
|
||||
() -> {
|
||||
((ComboBox<?>) pane.lookup("#declaration-value")).getEditor().setText(value);
|
||||
return null;
|
||||
});
|
||||
}
|
||||
|
||||
private void reject(String field, String value) throws Exception {
|
||||
String before = source();
|
||||
enter(field, value);
|
||||
click(pane, "Apply setting");
|
||||
if (!before.equals(source())
|
||||
|| fx(() -> ((Label) pane.lookup("#declaration-message")).getText().isBlank()))
|
||||
throw new AssertionError("Accepted " + field + "=" + value);
|
||||
step("Rejected · " + field + "=" + value);
|
||||
}
|
||||
}
|
||||
@@ -2,21 +2,15 @@ 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;
|
||||
public final class MediaLayoutGridWorkflowProbe extends DeclarationWorkflowProbe {
|
||||
|
||||
void verify(Project project) throws Exception {
|
||||
this.project = project;
|
||||
@@ -141,8 +135,8 @@ public final class MediaLayoutGridWorkflowProbe extends FormWorkflowProbe {
|
||||
inspector(true);
|
||||
var original = declarations();
|
||||
select("DataGrid", "grid");
|
||||
gridSet("setupId", "archiver-pruefung");
|
||||
gridSet("setupVersion", "2");
|
||||
applySetting("setupId", "archiver-pruefung");
|
||||
applySetting("setupVersion", "2");
|
||||
for (var pair :
|
||||
List.of(List.of("setupId", "archiver-pruefung"), List.of("setupVersion", "2"))) {
|
||||
String before = source();
|
||||
@@ -157,9 +151,9 @@ public final class MediaLayoutGridWorkflowProbe extends FormWorkflowProbe {
|
||||
click(pane, "Undo");
|
||||
await(() -> source().equals(before));
|
||||
}
|
||||
gridSet("groupBy", "folder");
|
||||
applySetting("groupBy", "folder");
|
||||
select("DataGridColumn", "folder");
|
||||
gridSet("fixedPosition", "1");
|
||||
applySetting("fixedPosition", "1");
|
||||
combo("declaration-property", "groupLabels");
|
||||
fx(
|
||||
() -> {
|
||||
@@ -195,142 +189,4 @@ public final class MediaLayoutGridWorkflowProbe extends FormWorkflowProbe {
|
||||
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