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 java.util.List; import java.util.concurrent.TimeUnit; import javafx.embed.swing.SwingFXUtils; import javafx.scene.control.*; import javafx.scene.image.ImageView; import javax.imageio.ImageIO; public final class FolderActionsWorkflowProbe extends FormWorkflowProbe { @Override void verify(Project project) throws Exception { checkForm(project, true); checkForm(project, false); Files.writeString(output.resolve("SUCCESS.txt"), Files.readString(output.resolve("steps.txt"))); } private void open(Project project, String name) throws Exception { var path = Path.of(project.getBasePath(), "src/main/resources/de/neitzel/archiver/ui", name + ".fxml"); file = edt(() -> LocalFileSystem.getInstance().refreshAndFindFileByNioFile(path)); pane = openDesigner(project, file); fx(pane::flush).toCompletableFuture().get(10, TimeUnit.SECONDS); } private void save() throws Exception { var text = source(); click(pane, "Save"); await( () -> Files.readString(Path.of(file.getPath())) .lines() .map(String::stripTrailing) .toList() .equals(text.lines().map(String::stripTrailing).toList())); } private void build(String id, String label) throws Exception { click(pane, "Form preview"); click(pane, "Build and Refresh"); await( () -> fx( () -> ((ComboBox) pane.lookup("#preview-example")) .getItems().stream().anyMatch(e -> e.toString().contains(id)))); choose("preview-example", id); await( () -> fx( () -> { String state = ((Label) pane.lookup("#preview-state")).getText(); if (state.startsWith("Preview failed") || state.startsWith("Preview blocked") || state.startsWith("Preview unavailable")) throw new AssertionError(state); return ((ImageView) pane.lookup("#full-preview-image")).getImage() != null && state.contains(label); })); } private void reset(String prop, String attribute) throws Exception { choose("form-property", prop); click(pane, "Reset property"); await(() -> !source().contains(attribute)); } private void checkForm(Project project, boolean details) throws Exception { String name = details ? "DocumentDetails" : "FolderTab"; String control = details ? "AutoCompleteTextField #input" : "ToolBarPane #find"; String prop = details ? "onAction" : "onDismiss"; String handler = details ? "#addTag" : "#closeFind"; String id = details ? "details-invoice" : "folder-actions"; String label = details ? "Dokumentdetails · Rechnung" : "Archivordner · Suche und Anzeigeprofile"; open(project, name); List bindings = source() .lines() .filter(s -> s.contains(" !source().contains("prefColumnCount=\"23\"")); click(pane, "Redo"); await(() -> source().equals(edited)); choose("form-property", "width"); if (fx(() -> ((TextArea) pane.lookup("#form-value")).isEditable())) throw new AssertionError("Writable width"); } reset(prop, prop + "=\"" + handler + "\""); save(); step(name + " · reset " + prop + " and saved"); build(id, label); controls(true); choose("form-control", control); choose("form-property", prop); await( () -> fx( () -> ((ComboBox) pane.lookup("#form-event-handlers")) .getItems() .contains(handler))); String before = source(); fx( () -> { ((TextArea) pane.lookup("#form-value")).setText("#falscherHandler"); return null; }); click(pane, "Set property"); var msg = fx(() -> ((Label) pane.lookup("#form-message")).getText()); if (!msg.contains("#falscherHandler") || !msg.contains("ActionEvent") || !before.equals(source())) throw new AssertionError(msg); if (!details) screenshot("folder-events.png"); choose("form-event-handlers", handler); click(pane, "Set property"); edited(before, prop + "=\"" + handler + "\""); save(); edt( () -> { FileEditorManager.getInstance(project).closeFile(file); return null; }); open(project, name); String saved = source(); if (!saved.contains(prop + "=\"" + handler + "\"") || !bindings.equals( saved .lines() .filter(s -> s.contains(" { ImageIO.write( SwingFXUtils.fromFXImage(pane.snapshot(null, null), null), "png", output.resolve(name).toFile()); return null; }); } }