115 lines
4.8 KiB
Java
115 lines
4.8 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 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");
|
|
}
|
|
}
|