231 lines
9.7 KiB
Java
231 lines
9.7 KiB
Java
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.protocol.BindingMetadata.Target;
|
|
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");
|
|
if (source().contains("property=\"suggestionsSource\"")
|
|
|| source().contains("property=\"html\""))
|
|
throw new AssertionError("Expected two unbound targets before visual authoring");
|
|
String current = normalized(source());
|
|
click(pane, "Save");
|
|
await(() -> normalized(Files.readString(path)).equals(current));
|
|
edt(
|
|
() -> {
|
|
FileEditorManager.getInstance(project).closeFile(file);
|
|
return null;
|
|
});
|
|
pane = openDesigner(project, file);
|
|
if (!normalized(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));
|
|
bindFromModel("html", "article", "html");
|
|
bindFromModel("tags", "dynamic", "suggestionsSource");
|
|
String bound = normalized(source());
|
|
click(pane, "Save");
|
|
await(() -> normalized(Files.readString(path)).equals(bound));
|
|
edt(
|
|
() -> {
|
|
FileEditorManager.getInstance(project).closeFile(file);
|
|
return null;
|
|
});
|
|
pane = openDesigner(project, file);
|
|
if (!normalized(source()).equals(bound))
|
|
throw new AssertionError("Reopen lost direct bindings");
|
|
Files.copy(path, output.resolve("saved-bindings.fxml"));
|
|
checkSavedBinding("HtmlViewer #article", "html", "html");
|
|
checkSavedBinding("AutoCompleteTextField #dynamic", "suggestionsSource", "tags");
|
|
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");
|
|
}
|
|
|
|
// IntelliJ can strip indentation from empty lines left by element removal on save.
|
|
private static String normalized(String source) {
|
|
return source.replaceAll("(?m)^[ \t]+$", "");
|
|
}
|
|
|
|
private void checkSavedBinding(String control, String property, String path) throws Exception {
|
|
controls(true);
|
|
choose("form-control", control);
|
|
choose("form-property", property);
|
|
click(pane, "Bind property");
|
|
await(
|
|
() ->
|
|
fx(
|
|
() ->
|
|
((TextField) pane.lookup("#direct-property")).getText().equals(property)
|
|
&& ((TextField) pane.lookup("#direct-path")).getText().equals(path)
|
|
&& ((ComboBox<?>) pane.lookup("#direct-direction"))
|
|
.getValue()
|
|
.equals("view")));
|
|
}
|
|
|
|
private void bindFromModel(String path, String control, String property) throws Exception {
|
|
fx(
|
|
() -> {
|
|
var group =
|
|
(TitledPane)
|
|
pane.lookupAll(".titled-pane").stream()
|
|
.filter(n -> n instanceof TitledPane t && t.getText().equals("Bindings"))
|
|
.findFirst()
|
|
.orElseThrow();
|
|
group.setAnimated(false);
|
|
group.setExpanded(true);
|
|
var tabs = (TabPane) group.getContent();
|
|
tabs.getSelectionModel()
|
|
.select(
|
|
tabs.getTabs().stream()
|
|
.filter(t -> t.getText().equals("Discover targets"))
|
|
.findFirst()
|
|
.orElseThrow());
|
|
pane.applyCss();
|
|
pane.layout();
|
|
return null;
|
|
});
|
|
click(pane, "Discover bindings");
|
|
await(() -> fx(() -> !((ComboBox<?>) pane.lookup("#binding-path")).getItems().isEmpty()));
|
|
choose("binding-direction", "view");
|
|
await(
|
|
() ->
|
|
fx(
|
|
() ->
|
|
((ComboBox<?>) pane.lookup("#binding-path"))
|
|
.getItems().stream().anyMatch(a -> a.toString().startsWith(path + " : "))));
|
|
choose("binding-path", path + " : ");
|
|
await(
|
|
() ->
|
|
fx(
|
|
() -> {
|
|
@SuppressWarnings("unchecked")
|
|
var targets = (TableView<Target>) pane.lookup("#binding-targets");
|
|
var target =
|
|
targets.getItems().stream()
|
|
.filter(
|
|
t ->
|
|
t.control().equals(control)
|
|
&& t.property().equals(property)
|
|
&& t.status().equals("COMPATIBLE"))
|
|
.findFirst();
|
|
if (target.isEmpty()) return false;
|
|
targets.getSelectionModel().select(target.get());
|
|
return true;
|
|
}));
|
|
click(pane, "Use selected target");
|
|
if (!fx(
|
|
() ->
|
|
((TextField) pane.lookup("#direct-path")).getText().equals(path)
|
|
&& ((ComboBox<?>) pane.lookup("#direct-direction")).getValue().equals("view")))
|
|
throw new AssertionError("Wrong source or direction for " + property);
|
|
fx(
|
|
() -> {
|
|
var editor = pane.lookup("#direct-bindings").getParent();
|
|
ImageIO.write(
|
|
SwingFXUtils.fromFXImage(editor.snapshot(null, null), null),
|
|
"png",
|
|
output.resolve("binding-" + control + ".png").toFile());
|
|
return null;
|
|
});
|
|
click(pane, "Apply binding");
|
|
await(() -> source().contains("property=\"" + property + "\""));
|
|
step(
|
|
"Created " + control + "." + property + " from compatible source " + path + " toward view");
|
|
}
|
|
|
|
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");
|
|
}
|
|
}
|