174 lines
6.4 KiB
Java
174 lines
6.4 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.List;
|
|
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");
|
|
qualify("details-invoice", "details-delivery", "details-readonly", "details-busy");
|
|
open(project, "HtmlDocument");
|
|
qualify("html-invoice", "html-delivery");
|
|
open(project, "ArchiveWindow");
|
|
qualify("archive-window-documents");
|
|
var ids = fx(this::available);
|
|
if (!ids.contains("archive-window-media"))
|
|
throw new AssertionError("Missing media example: " + ids);
|
|
try {
|
|
awaitExamples(List.of("missing-required-example"));
|
|
throw new AssertionError("Missing descriptor was accepted");
|
|
} catch (IllegalStateException expected) {
|
|
String diagnostic = expected.getMessage();
|
|
if (!diagnostic.contains(
|
|
"ArchiveWindow.fxml · required [missing-required-example] · available " + ids))
|
|
throw expected;
|
|
step(diagnostic);
|
|
}
|
|
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 List<String> available() {
|
|
return ((ComboBox<?>) pane.lookup("#preview-example"))
|
|
.getItems().stream().map(Example.class::cast).map(Example::id).toList();
|
|
}
|
|
|
|
private String state() {
|
|
return ((Label) pane.lookup("#preview-state")).getText();
|
|
}
|
|
|
|
private boolean failed() {
|
|
String state = state();
|
|
return state.startsWith("Preview failed")
|
|
|| state.startsWith("Preview blocked")
|
|
|| state.startsWith("Preview unavailable")
|
|
|| state.contains("correct the build");
|
|
}
|
|
|
|
private String diagnostic(List<String> required) {
|
|
return file.getName()
|
|
+ " · required "
|
|
+ required
|
|
+ " · available "
|
|
+ available()
|
|
+ " · "
|
|
+ state();
|
|
}
|
|
|
|
private void awaitExamples(List<String> required) throws Exception {
|
|
try {
|
|
// Discovery publishes the complete list at once. Additional providers may extend it.
|
|
await(
|
|
() ->
|
|
fx(
|
|
() ->
|
|
failed()
|
|
|| state().contains("register an example")
|
|
|| !state().startsWith("Building") && !available().isEmpty()));
|
|
} catch (AssertionError timeout) {
|
|
throw new AssertionError(fx(() -> diagnostic(required)), timeout);
|
|
}
|
|
if (!fx(() -> !failed() && available().containsAll(required)))
|
|
throw new IllegalStateException(fx(() -> diagnostic(required)));
|
|
}
|
|
|
|
private void qualify(String... examples) throws Exception {
|
|
var required = List.of(examples);
|
|
click(pane, "Form preview");
|
|
click(pane, "Build and Refresh");
|
|
awaitExamples(required);
|
|
step(file.getName() + " · available " + fx(this::available));
|
|
for (String id : required) preview(id);
|
|
}
|
|
|
|
private void preview(String id) throws Exception {
|
|
String label =
|
|
fx(
|
|
() -> {
|
|
var choices = (ComboBox<Example>) pane.lookup("#preview-example");
|
|
var selected =
|
|
choices.getItems().stream()
|
|
.filter(example -> example.id().equals(id))
|
|
.findFirst()
|
|
.orElseThrow(() -> new IllegalStateException(diagnostic(List.of(id))));
|
|
choices.getSelectionModel().select(selected);
|
|
return selected.label();
|
|
});
|
|
try {
|
|
await(
|
|
() ->
|
|
fx(
|
|
() ->
|
|
failed()
|
|
|| ((ImageView) pane.lookup("#full-preview-image")).getImage() != null
|
|
&& state().contains(label)));
|
|
} catch (AssertionError timeout) {
|
|
throw new AssertionError(fx(() -> diagnostic(List.of(id))), timeout);
|
|
}
|
|
if (fx(this::failed)) throw new AssertionError(fx(() -> diagnostic(List.of(id))));
|
|
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");
|
|
}
|
|
}
|