Files
NeitzelFXDesigner/integration-tests/idea/ConnectionWorkflowProbe.java
T

260 lines
10 KiB
Java
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
package qualification;
import static qualification.WorkflowProbe.*;
import com.intellij.openapi.command.WriteCommandAction;
import com.intellij.openapi.fileEditor.*;
import com.intellij.openapi.project.Project;
import com.intellij.openapi.vfs.*;
import java.nio.file.*;
import java.util.*;
import javafx.embed.swing.SwingFXUtils;
import javafx.scene.control.*;
import javafx.scene.image.*;
import javax.imageio.ImageIO;
/** Drives the registered editor against a disposable copy of the real Archiver connection form. */
public final class ConnectionWorkflowProbe extends FormWorkflowProbe {
private void add(String type, String destination, String id) throws Exception {
step("Inserting " + type + " as " + id);
choose("form-palette", type);
choose("form-destination", destination);
String before = source();
fx(
() -> {
var b =
(Button)
pane.lookupAll(".button").stream()
.filter(n -> n instanceof Button bt && bt.getText().equals("Insert control"))
.findFirst()
.orElseThrow();
if (b.isDisabled())
throw new AssertionError("Insert control disabled for " + destination);
step(
"Selected insert "
+ ((ComboBox<?>) pane.lookup("#form-palette")).getValue()
+ " / "
+ ((ComboBox<?>) pane.lookup("#form-destination")).getValue()
+ " at "
+ ((Spinner<?>) pane.lookup("#form-position")).getValue());
return null;
});
click(pane, "Insert control");
edited(before, "fx:id=\"" + id + "\"");
step("Inserted " + type + " into " + destination);
}
private void bind(String name, String path) throws Exception {
choose("form-property", name);
click(pane, "Bind property");
fx(
() -> {
pane.applyCss();
pane.layout();
return null;
});
fx(
() -> {
((TextField) pane.lookup("#direct-path")).setText(path);
return null;
});
String before = source();
click(pane, "Apply binding");
edited(before, "path=\"" + path + "\"");
controls(true);
}
private void example(String id) throws Exception {
choose("preview-example", "connection-" + id);
}
private void frame(String id, int width) throws Exception {
await(
() ->
fx(
() -> {
var image = (ImageView) pane.lookup("#full-preview-image");
var status = ((Label) pane.lookup("#preview-state")).getText();
return image.getImage() != null
&& image.getImage().getWidth() == width
&& image.getImage().getHeight() == 720
&& status.contains(id.toUpperCase(Locale.ROOT));
}));
fx(
() -> {
ImageIO.write(
SwingFXUtils.fromFXImage(
((ImageView) pane.lookup("#full-preview-image")).getImage(), null),
"png",
output.resolve(id + ".png").toFile());
return null;
});
step("In-editor " + id + " target frame " + width + " × 720");
}
@Override
void verify(Project project) throws Exception {
var path =
Path.of(
project.getBasePath(), "src/main/resources/de/neitzel/archiver/ui/ConnectionForm.fxml");
file = edt(() -> LocalFileSystem.getInstance().refreshAndFindFileByNioFile(path));
pane = openDesigner(project, file);
step("Opened registered Neitzel Designer");
fx(
() -> {
for (var n : pane.lookupAll(".label"))
if (n instanceof Label label
&& (label.getText() != null && label.getText().startsWith("Context ")
|| "form-message".equals(label.getId()))) {
label
.textProperty()
.addListener(
(o, a, b) -> {
try {
step("Editor: " + b);
} catch (Exception e) {
throw new IllegalStateException(e);
}
});
}
return null;
});
controls(true);
String grid = "GridPane [0] / children";
add("StatusBar", grid, "statusBar");
add("Label", "StatusBar #statusBar / leftItems", "label");
bind("text", "user");
add("Label", "StatusBar #statusBar / rightItems", "label2");
set("text", "Kontostatus", "Kontostatus");
choose("form-destination", "StatusBar #statusBar / leftItems");
String before = source();
click(pane, "Move to destination");
edited(before, "Kontostatus");
String moved = source();
click(pane, "Undo");
await(() -> source().equals(before));
click(pane, "Redo");
await(() -> source().equals(moved));
add("TextField", grid, "textField");
fx(
() -> {
var index =
new com.oracle.javafx.scenebuilder.kit.fxom.FXOMFxIdIndex(
pane.kit().editor().getFxomDocument());
pane.kit().editor().getSelection().select(index.lookup("endpoint"));
pane.kit().editor().getSelection().select(index.lookup("textField"));
if (!((ComboBox<?>) pane.lookup("#form-control"))
.getValue()
.toString()
.equals("TextField #textField"))
throw new AssertionError("Canvas selection did not reach the form inspector");
return null;
});
set("promptText", "Verbindung prüfen", "Verbindung prüfen");
set("styleClass", "connection-input", "connection-input");
set("padding", "2 3 4 5", "right=\"3.0\"");
set("GridPane.columnIndex", "1", "GridPane.columnIndex=\"1\"");
add("NonNegativeIntegerSpinner", grid, "nonNegativeIntegerSpinner");
set("maximum", "365", "maximum=\"365\"");
set("initialValue", "14", "initialValue=\"14\"");
set("minimum", "1", "minimum=\"1\"");
add("TagChip", grid, "tagChip");
set("removable", "true", "removable=\"true\"");
set("onRemove", "#removeTag", "onRemove=\"#removeTag\"");
click(pane, "Reset property");
await(() -> !source().contains("onRemove="));
add("ToolBarPane", grid, "toolBarPane");
set("dismissible", "true", "dismissible=\"true\"");
set("dismissText", "Schließen", "dismissText=\"Schließen\"");
set("onDismiss", "#dismiss", "onDismiss=\"#dismiss\"");
click(pane, "Reset property");
await(() -> !source().contains("onDismiss="));
add("ToolBar", grid, "toolBar");
add("Button", "ToolBarPane #toolBarPane / items", "button");
choose("form-destination", "ToolBar #toolBar / items");
String toolbar = source();
click(pane, "Move to destination");
edited(toolbar, "fx:id=\"button\"");
add("AutoCompleteTextField", grid, "autoCompleteTextField");
set("suggestions", "INBOX\nRechnungen", "fx:value=\"Rechnungen\"");
bind("text", "user");
String edited = source();
click(pane, "Save");
await(() -> Files.readString(path).equals(edited));
if (!edited.contains("%server.protocol"))
throw new AssertionError("Resource key was overwritten");
edt(
() -> {
FileEditorManager.getInstance(project).closeFile(file);
return null;
});
pane = openDesigner(project, file);
if (!source().equals(edited)) throw new AssertionError("Reopen changed source");
step("Native undo, redo, save and reopen preserved form, lists and bindings");
click(pane, "Form preview");
click(pane, "Build and Refresh");
await(() -> fx(() -> ((ComboBox<?>) pane.lookup("#preview-example")).getItems().size() == 2));
step("Built and discovered both connection examples");
example("imap");
fx(
() -> {
((Spinner<?>) pane.lookup("#preview-height")).increment(5);
return null;
});
frame("imap", 760);
byte[] initialImage = Files.readAllBytes(output.resolve("imap.png"));
controls(true);
choose("form-control", "Label #label2");
set("text", "Kontoprüfung", "Kontoprüfung");
controls(false);
frame("imap", 760);
if (java.util.Arrays.equals(initialImage, Files.readAllBytes(output.resolve("imap.png"))))
throw new AssertionError("Visual label edit produced the previous frame");
step("Current draft rendered a changed status label without a Save action");
Files.writeString(output.resolve("attempt"), "imap");
click(pane, "Interactive preview");
awaitTarget("result-imap");
var otherPath = path.resolveSibling("ArchiveWindow.fxml");
var other = edt(() -> LocalFileSystem.getInstance().refreshAndFindFileByNioFile(otherPath));
edt(
() -> {
FileEditorManager.getInstance(project).openFile(other, false);
var doc = FileDocumentManager.getInstance().getDocument(other);
WriteCommandAction.runWriteCommandAction(
project, () -> doc.insertString(doc.getTextLength(), "\n"));
FileDocumentManager.getInstance().saveDocument(doc);
return null;
});
Files.writeString(output.resolve("unrelated-saved"), "yes");
awaitTarget("retained-imap");
long originalPid = Long.parseLong(Files.readString(output.resolve("retained-imap")));
if (!ProcessHandle.of(originalPid).map(ProcessHandle::isAlive).orElse(false))
throw new AssertionError("Saving a different view stopped the IMAP worker");
step("Interactive IMAP input reached bound Label and survived unrelated save");
Files.writeString(output.resolve("attempt"), "jmap");
example("jmap");
fx(
() -> {
((Spinner<?>) pane.lookup("#preview-width")).increment();
return null;
});
frame("jmap", 800);
awaitTarget("result-jmap");
step("Interactive JMAP started with fresh sample data and reversed account/port enablement");
fx(
() -> {
ImageIO.write(
SwingFXUtils.fromFXImage(pane.snapshot(null, null), null),
"png",
output.resolve("intellij.png").toFile());
return null;
});
click(pane, "Stop preview");
Files.writeString(
output.resolve("SUCCESS.txt"),
"PASS registered IntelliJ connection form, palette and inspector edits, named lists,"
+ " bindings, native undo/redo/reopen, localized IMAP/JMAP frames and interactive"
+ " write-back\n");
}
}