114 lines
4.2 KiB
Java
114 lines
4.2 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.workflow.DesignerWorkflow.Example;
|
|
import java.nio.file.*;
|
|
import java.util.concurrent.TimeUnit;
|
|
import javafx.embed.swing.SwingFXUtils;
|
|
import javafx.scene.control.*;
|
|
import javafx.scene.image.ImageView;
|
|
import javax.imageio.ImageIO;
|
|
|
|
/** Edits the real chip template and opens both child resources and the archive window. */
|
|
public final class DocumentTabsWorkflowProbe extends FormWorkflowProbe {
|
|
@Override
|
|
void verify(Project project) throws Exception {
|
|
edit(project, "DocumentTag", "TagChip #chip", "style", "-fx-background-color: #f2d58a;");
|
|
edit(
|
|
project,
|
|
"DocumentDetails",
|
|
"AutoCompleteTextField #input",
|
|
"promptText",
|
|
"Belegtag wählen");
|
|
build(4);
|
|
for (String id :
|
|
new String[] {"details-invoice", "details-delivery", "details-readonly", "details-busy"})
|
|
preview(id);
|
|
open(project, "HtmlDocument");
|
|
build(2);
|
|
preview("html-invoice");
|
|
preview("html-delivery");
|
|
open(project, "ArchiveWindow");
|
|
build(2);
|
|
preview("archive-window-documents");
|
|
Files.writeString(output.resolve("SUCCESS.txt"), Files.readString(output.resolve("steps.txt")));
|
|
}
|
|
|
|
private void open(Project project, String form) throws Exception {
|
|
var path =
|
|
Path.of(project.getBasePath(), "src/main/resources/de/neitzel/archiver/ui", form + ".fxml");
|
|
file = edt(() -> LocalFileSystem.getInstance().refreshAndFindFileByNioFile(path));
|
|
pane = openDesigner(project, file);
|
|
fx(pane::flush).toCompletableFuture().get(10, TimeUnit.SECONDS);
|
|
step("Opened " + form + ".fxml in Neitzel Designer");
|
|
}
|
|
|
|
private void edit(Project project, String form, String control, String property, String value)
|
|
throws Exception {
|
|
open(project, form);
|
|
controls(true);
|
|
choose("form-control", control);
|
|
set(property, value, value);
|
|
click(pane, "Save");
|
|
await(() -> Files.readString(Path.of(file.getPath())).contains(value));
|
|
edt(
|
|
() -> {
|
|
FileEditorManager.getInstance(project).closeFile(file);
|
|
return null;
|
|
});
|
|
open(project, form);
|
|
if (!source().contains(value)) throw new AssertionError(form + " lost " + property);
|
|
step("Saved and reopened " + control + "." + property + " = " + value);
|
|
}
|
|
|
|
private void build(int examples) throws Exception {
|
|
click(pane, "Form preview");
|
|
click(pane, "Build and Refresh");
|
|
await(
|
|
() ->
|
|
fx(
|
|
() ->
|
|
((ComboBox<?>) pane.lookup("#preview-example")).getItems().size() == examples));
|
|
}
|
|
|
|
private void preview(String id) throws Exception {
|
|
choose("preview-example", id);
|
|
String label =
|
|
fx(() -> ((Example) ((ComboBox<?>) pane.lookup("#preview-example")).getValue()).label());
|
|
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(id + ": " + state);
|
|
return ((ImageView) pane.lookup("#full-preview-image")).getImage() != null
|
|
&& state.contains(label);
|
|
}));
|
|
fx(
|
|
() -> {
|
|
var frame = ((ImageView) pane.lookup("#full-preview-image")).getImage();
|
|
ImageIO.write(
|
|
SwingFXUtils.fromFXImage(frame, null), "png", output.resolve(id + ".png").toFile());
|
|
if (id.equals("archive-window-documents"))
|
|
ImageIO.write(
|
|
SwingFXUtils.fromFXImage(pane.snapshot(null, null), null),
|
|
"png",
|
|
output.resolve("intellij.png").toFile());
|
|
return null;
|
|
});
|
|
Files.writeString(output.resolve("document-attempt"), id);
|
|
click(pane, "Interactive preview");
|
|
var result = "result-" + id;
|
|
awaitTarget(result);
|
|
step(Files.readString(output.resolve(result)));
|
|
click(pane, "Stop preview");
|
|
}
|
|
}
|