Render WebView content and qualify Archiver document previews in IntelliJ

This commit is contained in:
2026-11-24 17:54:36 +01:00
parent b04bd9d7ef
commit f9c3de2d2b
9 changed files with 653 additions and 175 deletions
@@ -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;
}