Render WebView content and qualify Archiver document previews in IntelliJ
This commit is contained in:
@@ -2,13 +2,10 @@ package qualification;
|
||||
|
||||
import static qualification.WorkflowProbe.*;
|
||||
|
||||
import com.intellij.openapi.application.ApplicationManager;
|
||||
import com.intellij.openapi.command.WriteCommandAction;
|
||||
import com.intellij.openapi.fileEditor.*;
|
||||
import com.intellij.openapi.project.Project;
|
||||
import com.intellij.openapi.startup.StartupActivity;
|
||||
import com.intellij.openapi.vfs.*;
|
||||
import de.neitzel.fxdesigner.kit.DesignerPane;
|
||||
import java.nio.file.*;
|
||||
import java.util.*;
|
||||
import javafx.embed.swing.SwingFXUtils;
|
||||
@@ -16,112 +13,8 @@ import javafx.scene.control.*;
|
||||
import javafx.scene.image.*;
|
||||
import javax.imageio.ImageIO;
|
||||
|
||||
/** Drives the registered editor against a disposable copy of the real Archiver form. */
|
||||
public final class ConnectionWorkflowProbe implements StartupActivity.DumbAware {
|
||||
private DesignerPane pane;
|
||||
private VirtualFile file;
|
||||
|
||||
public void runActivity(Project project) {
|
||||
if (!started.compareAndSet(false, true)) return;
|
||||
ApplicationManager.getApplication()
|
||||
.executeOnPooledThread(
|
||||
() -> {
|
||||
try {
|
||||
verify(project);
|
||||
} catch (Throwable ex) {
|
||||
try {
|
||||
var trace = new java.io.StringWriter();
|
||||
ex.printStackTrace(new java.io.PrintWriter(trace));
|
||||
if (pane != null)
|
||||
trace.append(
|
||||
fx(
|
||||
() ->
|
||||
pane.lookupAll(".label").stream()
|
||||
.filter(Label.class::isInstance)
|
||||
.map(n -> Objects.toString(((Label) n).getText(), ""))
|
||||
.filter(s -> !s.isEmpty())
|
||||
.toList()
|
||||
.toString()));
|
||||
Files.writeString(output.resolve("FAILURE.txt"), trace.toString());
|
||||
} catch (Exception failure) {
|
||||
failure.printStackTrace();
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
private void step(String message) throws Exception {
|
||||
Files.writeString(
|
||||
output.resolve("steps.txt"),
|
||||
message + "\n",
|
||||
StandardOpenOption.CREATE,
|
||||
StandardOpenOption.APPEND);
|
||||
}
|
||||
|
||||
private String source() throws Exception {
|
||||
return edt(() -> FileDocumentManager.getInstance().getDocument(file).getText());
|
||||
}
|
||||
|
||||
private void controls(boolean expanded) throws Exception {
|
||||
fx(
|
||||
() -> {
|
||||
var panel =
|
||||
(TitledPane)
|
||||
pane.lookupAll(".titled-pane").stream()
|
||||
.filter(n -> n instanceof TitledPane t && t.getText().equals("Form controls"))
|
||||
.findFirst()
|
||||
.orElseThrow();
|
||||
panel.setAnimated(false);
|
||||
panel.setExpanded(expanded);
|
||||
pane.applyCss();
|
||||
pane.layout();
|
||||
return null;
|
||||
});
|
||||
}
|
||||
|
||||
private void choose(String selector, String text) throws Exception {
|
||||
fx(
|
||||
() -> {
|
||||
var combo = (ComboBox<?>) pane.lookup("#" + selector);
|
||||
for (int i = 0; i < combo.getItems().size(); i++) {
|
||||
if (combo.getItems().get(i).toString().equals(text)) {
|
||||
combo.getSelectionModel().select(i);
|
||||
return null;
|
||||
}
|
||||
}
|
||||
for (int i = 0; i < combo.getItems().size(); i++) {
|
||||
String label = combo.getItems().get(i).toString();
|
||||
if (label.equals(text) || label.contains(text)) {
|
||||
combo.getSelectionModel().select(i);
|
||||
return null;
|
||||
}
|
||||
}
|
||||
throw new AssertionError(selector + " missing " + text + " in " + combo.getItems());
|
||||
});
|
||||
}
|
||||
|
||||
private void edited(String before, String expected) throws Exception {
|
||||
await(
|
||||
() -> {
|
||||
String now = source();
|
||||
String error =
|
||||
fx(
|
||||
() -> {
|
||||
var label = (Label) pane.lookup("#form-message");
|
||||
return label == null ? "" : label.getText();
|
||||
});
|
||||
if (!error.isEmpty()) throw new AssertionError(error);
|
||||
return !before.equals(now)
|
||||
&& now.contains(expected)
|
||||
&& fx(
|
||||
() ->
|
||||
((TextArea) pane.lookup("#fxml-source")) == null
|
||||
|| ((TextArea) pane.lookup("#fxml-source")).getText().equals(now));
|
||||
});
|
||||
// Both the native document and visual selection are refreshed asynchronously.
|
||||
fx(pane::flush).toCompletableFuture().get(10, java.util.concurrent.TimeUnit.SECONDS);
|
||||
}
|
||||
|
||||
/** 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);
|
||||
@@ -151,18 +44,6 @@ public final class ConnectionWorkflowProbe implements StartupActivity.DumbAware
|
||||
step("Inserted " + type + " into " + destination);
|
||||
}
|
||||
|
||||
private void set(String name, String value, String expected) throws Exception {
|
||||
choose("form-property", name);
|
||||
fx(
|
||||
() -> {
|
||||
((TextArea) pane.lookup("#form-value")).setText(value);
|
||||
return null;
|
||||
});
|
||||
String before = source();
|
||||
click(pane, "Set property");
|
||||
edited(before, expected);
|
||||
}
|
||||
|
||||
private void bind(String name, String path) throws Exception {
|
||||
choose("form-property", name);
|
||||
click(pane, "Bind property");
|
||||
@@ -211,16 +92,8 @@ public final class ConnectionWorkflowProbe implements StartupActivity.DumbAware
|
||||
step("In-editor " + id + " target frame " + width + " × 720");
|
||||
}
|
||||
|
||||
private void awaitTarget(String name) throws Exception {
|
||||
await(
|
||||
() -> {
|
||||
var error = output.resolve("target-error.txt");
|
||||
if (Files.exists(error)) throw new AssertionError(Files.readString(error));
|
||||
return Files.exists(output.resolve(name));
|
||||
});
|
||||
}
|
||||
|
||||
private void verify(Project project) throws Exception {
|
||||
@Override
|
||||
void verify(Project project) throws Exception {
|
||||
var path =
|
||||
Path.of(
|
||||
project.getBasePath(), "src/main/resources/de/neitzel/archiver/ui/ConnectionForm.fxml");
|
||||
|
||||
@@ -0,0 +1,144 @@
|
||||
package qualification;
|
||||
|
||||
import static qualification.WorkflowProbe.*;
|
||||
|
||||
import com.intellij.openapi.application.ApplicationManager;
|
||||
import com.intellij.openapi.fileEditor.*;
|
||||
import com.intellij.openapi.project.Project;
|
||||
import com.intellij.openapi.startup.StartupActivity;
|
||||
import com.intellij.openapi.vfs.*;
|
||||
import de.neitzel.fxdesigner.kit.DesignerPane;
|
||||
import java.nio.file.*;
|
||||
import java.util.*;
|
||||
import javafx.scene.control.*;
|
||||
import javafx.scene.image.*;
|
||||
|
||||
/** Shared actions on the real form inspector in the registered editor. */
|
||||
abstract class FormWorkflowProbe implements StartupActivity.DumbAware {
|
||||
DesignerPane pane;
|
||||
VirtualFile file;
|
||||
|
||||
public void runActivity(Project project) {
|
||||
if (!started.compareAndSet(false, true)) return;
|
||||
ApplicationManager.getApplication()
|
||||
.executeOnPooledThread(
|
||||
() -> {
|
||||
try {
|
||||
verify(project);
|
||||
} catch (Throwable ex) {
|
||||
try {
|
||||
var trace = new java.io.StringWriter();
|
||||
ex.printStackTrace(new java.io.PrintWriter(trace));
|
||||
if (pane != null)
|
||||
trace.append(
|
||||
fx(
|
||||
() ->
|
||||
pane.lookupAll(".label").stream()
|
||||
.filter(Label.class::isInstance)
|
||||
.map(n -> Objects.toString(((Label) n).getText(), ""))
|
||||
.filter(s -> !s.isEmpty())
|
||||
.toList()
|
||||
.toString()));
|
||||
Files.writeString(output.resolve("FAILURE.txt"), trace.toString());
|
||||
} catch (Exception failure) {
|
||||
failure.printStackTrace();
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
void step(String message) throws Exception {
|
||||
Files.writeString(
|
||||
output.resolve("steps.txt"),
|
||||
message + "\n",
|
||||
StandardOpenOption.CREATE,
|
||||
StandardOpenOption.APPEND);
|
||||
}
|
||||
|
||||
String source() throws Exception {
|
||||
return edt(() -> FileDocumentManager.getInstance().getDocument(file).getText());
|
||||
}
|
||||
|
||||
void controls(boolean expanded) throws Exception {
|
||||
fx(
|
||||
() -> {
|
||||
var panel =
|
||||
(TitledPane)
|
||||
pane.lookupAll(".titled-pane").stream()
|
||||
.filter(n -> n instanceof TitledPane t && t.getText().equals("Form controls"))
|
||||
.findFirst()
|
||||
.orElseThrow();
|
||||
panel.setAnimated(false);
|
||||
panel.setExpanded(expanded);
|
||||
pane.applyCss();
|
||||
pane.layout();
|
||||
return null;
|
||||
});
|
||||
}
|
||||
|
||||
void choose(String selector, String text) throws Exception {
|
||||
fx(
|
||||
() -> {
|
||||
var combo = (ComboBox<?>) pane.lookup("#" + selector);
|
||||
for (int i = 0; i < combo.getItems().size(); i++) {
|
||||
if (combo.getItems().get(i).toString().equals(text)) {
|
||||
combo.getSelectionModel().select(i);
|
||||
return null;
|
||||
}
|
||||
}
|
||||
for (int i = 0; i < combo.getItems().size(); i++) {
|
||||
String label = combo.getItems().get(i).toString();
|
||||
if (label.equals(text) || label.contains(text)) {
|
||||
combo.getSelectionModel().select(i);
|
||||
return null;
|
||||
}
|
||||
}
|
||||
throw new AssertionError(selector + " missing " + text + " in " + combo.getItems());
|
||||
});
|
||||
}
|
||||
|
||||
void edited(String before, String expected) throws Exception {
|
||||
await(
|
||||
() -> {
|
||||
String now = source();
|
||||
String error =
|
||||
fx(
|
||||
() -> {
|
||||
var label = (Label) pane.lookup("#form-message");
|
||||
return label == null ? "" : label.getText();
|
||||
});
|
||||
if (!error.isEmpty()) throw new AssertionError(error);
|
||||
return !before.equals(now)
|
||||
&& now.contains(expected)
|
||||
&& fx(
|
||||
() ->
|
||||
((TextArea) pane.lookup("#fxml-source")) == null
|
||||
|| ((TextArea) pane.lookup("#fxml-source")).getText().equals(now));
|
||||
});
|
||||
// Both the native document and visual selection are refreshed asynchronously.
|
||||
fx(pane::flush).toCompletableFuture().get(10, java.util.concurrent.TimeUnit.SECONDS);
|
||||
}
|
||||
|
||||
void set(String name, String value, String expected) throws Exception {
|
||||
choose("form-property", name);
|
||||
fx(
|
||||
() -> {
|
||||
((TextArea) pane.lookup("#form-value")).setText(value);
|
||||
return null;
|
||||
});
|
||||
String before = source();
|
||||
click(pane, "Set property");
|
||||
edited(before, expected);
|
||||
}
|
||||
|
||||
void awaitTarget(String name) throws Exception {
|
||||
await(
|
||||
() -> {
|
||||
var error = output.resolve("target-error.txt");
|
||||
if (Files.exists(error)) throw new AssertionError(Files.readString(error));
|
||||
return Files.exists(output.resolve(name));
|
||||
});
|
||||
}
|
||||
|
||||
abstract void verify(Project project) throws Exception;
|
||||
}
|
||||
@@ -0,0 +1,224 @@
|
||||
package qualification;
|
||||
|
||||
import java.nio.file.*;
|
||||
import java.util.*;
|
||||
import java.util.concurrent.*;
|
||||
import javafx.application.Platform;
|
||||
import javafx.scene.Parent;
|
||||
import javafx.scene.control.*;
|
||||
import javafx.scene.input.*;
|
||||
import javafx.stage.*;
|
||||
import org.w3c.dom.Document;
|
||||
|
||||
/** Observes the target JVM launched by the IDE. No application or WebKit classes enter the IDE. */
|
||||
public final class SavedDocumentTargetProbe {
|
||||
public static void premain(String directory) {
|
||||
if (System.getProperty("sun.java.command", "")
|
||||
.startsWith("de.neitzel.fxdesigner.target.WorkerMain "))
|
||||
Thread.ofPlatform().daemon().start(() -> new Probe().run(Path.of(directory)));
|
||||
}
|
||||
|
||||
private static final class Probe {
|
||||
private Path evidence;
|
||||
private Parent root;
|
||||
private Object viewer, engine;
|
||||
private TextField fixed, dynamic;
|
||||
|
||||
private <T> T fx(Callable<T> action) throws Exception {
|
||||
var task = new FutureTask<>(action);
|
||||
Platform.runLater(task);
|
||||
return task.get(10, TimeUnit.SECONDS);
|
||||
}
|
||||
|
||||
private void await(Callable<Boolean> check) throws Exception {
|
||||
long end = System.nanoTime() + TimeUnit.SECONDS.toNanos(30);
|
||||
while (System.nanoTime() < end) {
|
||||
if (fx(check)) return;
|
||||
Thread.sleep(80);
|
||||
}
|
||||
throw new AssertionError("Timed out waiting for " + check);
|
||||
}
|
||||
|
||||
private void run(Path directory) {
|
||||
evidence = directory;
|
||||
try {
|
||||
// The same agent is present in discovery and off-screen render workers.
|
||||
while (true) {
|
||||
try {
|
||||
if (fx(
|
||||
() -> {
|
||||
var stage =
|
||||
Window.getWindows().stream()
|
||||
.filter(Stage.class::isInstance)
|
||||
.map(Stage.class::cast)
|
||||
.filter(
|
||||
w ->
|
||||
w.isShowing()
|
||||
&& w.getOpacity() > 0
|
||||
&& w.getTitle() != null
|
||||
&& w.getTitle().startsWith("Neitzel preview"))
|
||||
.findFirst();
|
||||
if (stage.isEmpty()) return false;
|
||||
stage.get().setWidth(800);
|
||||
stage.get().setHeight(580);
|
||||
stage.get().requestFocus();
|
||||
root = stage.get().getScene().getRoot();
|
||||
viewer = root.lookup("#article");
|
||||
return viewer != null;
|
||||
})) break;
|
||||
} catch (IllegalStateException starting) {
|
||||
}
|
||||
Thread.sleep(120);
|
||||
}
|
||||
fx(
|
||||
() -> {
|
||||
var browser = root.lookup("WebView");
|
||||
engine = browser.getClass().getMethod("getEngine").invoke(browser);
|
||||
fixed = (TextField) root.lookup("#fixed");
|
||||
dynamic = (TextField) root.lookup("#dynamic");
|
||||
var media = (Button) root.lookup(".html-viewer-media-load");
|
||||
require(
|
||||
media.getText().equals("Belegbilder laden")
|
||||
&& media.getTooltip().getText().equals("Keine externen Belegbilder")
|
||||
&& media.isDisabled(),
|
||||
"edited offline media labels");
|
||||
require(
|
||||
"Belegbilder erneut laden".equals(call("getMediaReloadText"))
|
||||
&& "Bilder dieses Belegs laden".equals(call("getMediaTooltipText")),
|
||||
"remaining media labels");
|
||||
require(!Boolean.TRUE.equals(call("isExternalImagesAllowed")), "offline viewer");
|
||||
return null;
|
||||
});
|
||||
body("Rechnung RE-042");
|
||||
popup(fixed, "Pr", List.of("Prüfung", "Privat"));
|
||||
popup(dynamic, "Re", List.of("Rechnung", "Reise"));
|
||||
fx(
|
||||
() -> {
|
||||
((Button) root.lookup("#next")).fire();
|
||||
return null;
|
||||
});
|
||||
body("Lieferschein LS-018");
|
||||
require(
|
||||
fx(() -> suggestions(dynamic).equals(List.of("Lieferung", "Lieferschein"))),
|
||||
"replacement removes old document tags");
|
||||
popup(dynamic, "Li", List.of("Lieferung", "Lieferschein"));
|
||||
popup(fixed, "Pr", List.of("Prüfung", "Privat"));
|
||||
fx(
|
||||
() -> {
|
||||
((TextArea) root.lookup("#source"))
|
||||
.setText("<html><body><h1>Geänderter Beleg</h1></body></html>");
|
||||
return null;
|
||||
});
|
||||
body("Geänderter Beleg");
|
||||
fx(
|
||||
() -> {
|
||||
viewer
|
||||
.getClass()
|
||||
.getMethod("load", Path.class)
|
||||
.invoke(viewer, directory.resolve("missing-preview.html"));
|
||||
return null;
|
||||
});
|
||||
await(() -> !Boolean.TRUE.equals(call("isLoading")) && call("getError") != null);
|
||||
fx(
|
||||
() -> {
|
||||
((Button) root.lookup("#next")).fire();
|
||||
return null;
|
||||
});
|
||||
body("Rechnung RE-042");
|
||||
Files.writeString(
|
||||
directory.resolve("saved-document-result"),
|
||||
"Rechnung RE-042 → Lieferschein LS-018 → Geänderter Beleg; load error and recovery;"
|
||||
+ " popup Pr: Prüfung, Privat; Re: Rechnung, Reise; Li: Lieferung, Lieferschein."
|
||||
+ " PID "
|
||||
+ ProcessHandle.current().pid());
|
||||
} catch (Throwable ex) {
|
||||
try {
|
||||
var trace = new java.io.StringWriter();
|
||||
ex.printStackTrace(new java.io.PrintWriter(trace));
|
||||
Files.writeString(directory.resolve("target-error.txt"), trace.toString());
|
||||
} catch (Exception ignored) {
|
||||
ex.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private Object call(String method) throws Exception {
|
||||
return viewer.getClass().getMethod(method).invoke(viewer);
|
||||
}
|
||||
|
||||
private void body(String text) throws Exception {
|
||||
await(
|
||||
() -> {
|
||||
if (call("getError") != null) throw new AssertionError(call("getError"));
|
||||
var doc = (Document) engine.getClass().getMethod("getDocument").invoke(engine);
|
||||
return !Boolean.TRUE.equals(call("isLoading"))
|
||||
&& doc != null
|
||||
&& doc.getDocumentElement().getTextContent().contains(text);
|
||||
});
|
||||
}
|
||||
|
||||
private List<?> suggestions(TextField field) throws Exception {
|
||||
return (List<?>) field.getClass().getMethod("getSuggestions").invoke(field);
|
||||
}
|
||||
|
||||
private void popup(TextField field, String prefix, List<String> expected) throws Exception {
|
||||
await(
|
||||
() -> {
|
||||
if (field.isFocused()) return true;
|
||||
var stage = (Stage) root.getScene().getWindow();
|
||||
stage.toFront();
|
||||
stage.requestFocus();
|
||||
field.requestFocus();
|
||||
return field.isFocused();
|
||||
});
|
||||
fx(
|
||||
() -> {
|
||||
field.setText("");
|
||||
field.setText(prefix);
|
||||
return null;
|
||||
});
|
||||
await(
|
||||
() -> {
|
||||
for (var window : Window.getWindows()) {
|
||||
if (!(window instanceof Popup)
|
||||
|| !window.isShowing()
|
||||
|| !(window.getScene().lookup(".list-view") instanceof ListView<?> list)
|
||||
|| !list.getItems().equals(expected)) continue;
|
||||
var image = window.getScene().snapshot(null);
|
||||
int w = (int) image.getWidth(), h = (int) image.getHeight();
|
||||
var png =
|
||||
new java.awt.image.BufferedImage(
|
||||
w, h, java.awt.image.BufferedImage.TYPE_INT_ARGB);
|
||||
var pixels = new int[w * h];
|
||||
image
|
||||
.getPixelReader()
|
||||
.getPixels(
|
||||
0,
|
||||
0,
|
||||
w,
|
||||
h,
|
||||
javafx.scene.image.PixelFormat.getIntArgbInstance(),
|
||||
pixels,
|
||||
0,
|
||||
w);
|
||||
png.setRGB(0, 0, w, h, pixels, 0, w);
|
||||
javax.imageio.ImageIO.write(
|
||||
png, "png", evidence.resolve("tags-" + prefix + ".png").toFile());
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
});
|
||||
fx(
|
||||
() -> {
|
||||
field.fireEvent(
|
||||
new KeyEvent(
|
||||
KeyEvent.KEY_PRESSED, "", "", KeyCode.ESCAPE, false, false, false, false));
|
||||
return null;
|
||||
});
|
||||
}
|
||||
|
||||
private static void require(boolean condition, String label) {
|
||||
if (!condition) throw new AssertionError(label);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,114 @@
|
||||
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 javafx.embed.swing.SwingFXUtils;
|
||||
import javafx.scene.control.*;
|
||||
import javafx.scene.image.ImageView;
|
||||
import javax.imageio.ImageIO;
|
||||
|
||||
/** Configures the Archiver HTML viewer and both tag fields in the registered form inspector. */
|
||||
public final class SavedDocumentWorkflowProbe extends FormWorkflowProbe {
|
||||
@Override
|
||||
void verify(Project project) throws Exception {
|
||||
var path =
|
||||
Path.of(
|
||||
project.getBasePath(),
|
||||
"src/designer/resources/de/neitzel/archiver/preview/SavedDocument.fxml");
|
||||
file = edt(() -> LocalFileSystem.getInstance().refreshAndFindFileByNioFile(path));
|
||||
pane = openDesigner(project, file);
|
||||
controls(true);
|
||||
choose("form-control", "HtmlViewer #article");
|
||||
set("mediaLoadText", "Belegbilder laden", "mediaLoadText=\"Belegbilder laden\"");
|
||||
set(
|
||||
"mediaReloadText",
|
||||
"Belegbilder erneut laden",
|
||||
"mediaReloadText=\"Belegbilder erneut laden\"");
|
||||
set(
|
||||
"mediaTooltipText",
|
||||
"Bilder dieses Belegs laden",
|
||||
"mediaTooltipText=\"Bilder dieses Belegs laden\"");
|
||||
set(
|
||||
"noExternalMediaText",
|
||||
"Keine externen Belegbilder",
|
||||
"noExternalMediaText=\"Keine externen Belegbilder\"");
|
||||
set("mediaButtonVisible", "false", "mediaButtonVisible=\"false\"");
|
||||
click(pane, "Undo");
|
||||
await(() -> source().contains("mediaButtonVisible=\"true\""));
|
||||
choose("form-control", "AutoCompleteTextField #fixed");
|
||||
set("suggestions", "Prüfung\nPrivat", "fx:value=\"Prüfung\"");
|
||||
click(pane, "Bind property");
|
||||
if (!fx(
|
||||
() ->
|
||||
((Label) pane.lookup("#form-message"))
|
||||
.getText()
|
||||
.contains("no writable JavaFX property")))
|
||||
throw new AssertionError("Static collection was offered as a direct binding target");
|
||||
var current = source();
|
||||
click(pane, "Save");
|
||||
await(() -> Files.readString(path).equals(current));
|
||||
edt(
|
||||
() -> {
|
||||
FileEditorManager.getInstance(project).closeFile(file);
|
||||
return null;
|
||||
});
|
||||
pane = openDesigner(project, file);
|
||||
if (!source().equals(current)) throw new AssertionError("Reopen lost document settings");
|
||||
step("Edited four media labels, visibility and fixed suggestions; saved and reopened");
|
||||
click(pane, "Form preview");
|
||||
click(pane, "Build and Refresh");
|
||||
await(() -> fx(() -> ((ComboBox<?>) pane.lookup("#preview-example")).getItems().size() == 2));
|
||||
choose("preview-example", "saved-invoice");
|
||||
frame("invoice", "Rechnung", 0xff294973);
|
||||
click(pane, "Interactive preview");
|
||||
awaitTarget("saved-document-result");
|
||||
click(pane, "Stop preview");
|
||||
choose("preview-example", "saved-delivery");
|
||||
frame("delivery", "Lieferschein", 0xff38643e);
|
||||
fx(
|
||||
() -> {
|
||||
ImageIO.write(
|
||||
SwingFXUtils.fromFXImage(pane.snapshot(null, null), null),
|
||||
"png",
|
||||
output.resolve("intellij.png").toFile());
|
||||
return null;
|
||||
});
|
||||
Files.writeString(
|
||||
output.resolve("SUCCESS.txt"),
|
||||
"PASS registered IntelliJ Archiver saved documents: inspector configuration, two WebView"
|
||||
+ " frames, document replacement, error recovery and live suggestion popups.\n");
|
||||
}
|
||||
|
||||
private void frame(String id, String title, int accent) throws Exception {
|
||||
await(
|
||||
() ->
|
||||
fx(
|
||||
() -> {
|
||||
var image = ((ImageView) pane.lookup("#full-preview-image")).getImage();
|
||||
var state = ((Label) pane.lookup("#preview-state")).getText();
|
||||
if (state.startsWith("Preview failed")
|
||||
|| state.startsWith("Preview unavailable")
|
||||
|| state.startsWith("Preview blocked")) throw new AssertionError(state);
|
||||
if (image == null || !state.contains(title)) return false;
|
||||
ImageIO.write(
|
||||
SwingFXUtils.fromFXImage(image, null),
|
||||
"png",
|
||||
output.resolve(id + ".png").toFile());
|
||||
int ink = 0;
|
||||
for (int y = 0; y < (int) image.getHeight(); y++)
|
||||
for (int x = 0; x < (int) image.getWidth(); x++)
|
||||
if (image.getPixelReader().getArgb(x, y) == accent) ink++;
|
||||
if (ink < 1800
|
||||
|| image.getPixelReader().getArgb((int) image.getWidth() - 32, 104)
|
||||
!= 0xffffffff)
|
||||
throw new AssertionError(
|
||||
title + " missing HTML accent in the embedded frame: " + ink);
|
||||
return true;
|
||||
}));
|
||||
step("Embedded " + title + " rendered its document-specific HTML colour");
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user