Files
NeitzelFXDesigner/integration-tests/idea/ManagementReadersWorkflowProbe.java
T

165 lines
5.6 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 com.oracle.javafx.scenebuilder.kit.fxom.FXOMFxIdIndex;
import de.neitzel.fxdesigner.workflow.DesignerWorkflow.Example;
import java.nio.file.*;
import javafx.embed.swing.SwingFXUtils;
import javafx.event.ActionEvent;
import javafx.scene.control.*;
import javafx.scene.image.ImageView;
import javax.imageio.ImageIO;
/** Changes the draft via the registered inspector, then exercises its managed worker. */
public final class ManagementReadersWorkflowProbe extends FormWorkflowProbe {
private Project project;
void verify(Project project) throws Exception {
this.project = project;
management(
"MailControls", "accounts-idle", "accounts-busy", "configure", "configure", "create", 9);
management(
"TrashPane",
"trash-full",
"trash-empty",
"delete",
"deleteSelection",
"restoreSelection",
2);
open("ReaderNavigation");
attribute("symbol", "VIEW");
attribute("accessibleText", "Bild zurück");
reopen("ReaderNavigation", "accessibleText=\"Bild zurück\"");
build("reader-images");
interactive("reader-images", "images");
for (String[] reader :
new String[][] {
{"PdfToolbar", "pdf"},
{"EpubToolbar", "epub"},
{"SlideshowToolbar", "slides"},
{"AttachmentToolbar", "attachment"}
}) {
open(reader[0]);
String id = "reader-" + reader[1];
build(id);
interactive(id, reader[1]);
}
Files.writeString(output.resolve("SUCCESS.txt"), Files.readString(output.resolve("steps.txt")));
}
private void open(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);
if (!source().contains("<?neitzel-model de.neitzel.archiver.ui."))
throw new AssertionError(name);
}
private void build(String id) throws Exception {
click(pane, "Form preview");
click(pane, "Build and Refresh");
await(
() ->
fx(
() ->
((ComboBox<?>) pane.lookup("#preview-example"))
.getItems().stream().anyMatch(item -> item.toString().contains(id))));
}
private void interactive(String id, String attempt) throws Exception {
choose("preview-example", id);
await(
() ->
fx(
() -> {
var 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);
var choice = (Example) ((ComboBox<?>) pane.lookup("#preview-example")).getValue();
return ((ImageView) pane.lookup("#full-preview-image")).getImage() != null
&& state.contains(choice.label());
}));
Files.writeString(output.resolve("management-case"), attempt);
click(pane, "Interactive preview");
String name = "result-" + attempt;
awaitTarget(name);
step(id + " · " + Files.readString(output.resolve(name)));
click(pane, "Stop preview");
}
private void reopen(String form, String saved) throws Exception {
click(pane, "Save");
await(() -> Files.readString(Path.of(file.getPath())).contains(saved));
edt(
() -> {
FileEditorManager.getInstance(project).closeFile(file);
return null;
});
open(form);
if (!source().contains(saved)) throw new AssertionError("Reopened " + form);
}
private void management(
String form,
String data,
String other,
String control,
String path,
String replacement,
int count)
throws Exception {
open(form);
build(data);
interactive(data, data);
interactive(other, other);
commands(control, path, count);
fx(
() -> {
((TextField) pane.lookup("#command-path")).setText(replacement);
return null;
});
click(pane, "Apply Command binding");
String edited = "control=\"" + control + "\" path=\"" + replacement + "\"";
await(() -> source().contains(edited));
reopen(form, edited);
commands(control, replacement, count);
if (form.equals("MailControls")) {
fx(
() -> {
ImageIO.write(
SwingFXUtils.fromFXImage(pane.snapshot(null, null), null),
"png",
output.resolve("intellij.png").toFile());
return null;
});
}
build(data);
interactive(data, data + "-edited");
}
private void attribute(String name, String value) throws Exception {
fx(
() -> {
var kit = pane.kit().editor();
kit.getSelection().select(new FXOMFxIdIndex(kit.getFxomDocument()).lookup("previous"));
return null;
});
await(() -> fx(() -> pane.lookup("#component-property-" + name) != null));
fx(
() -> {
var field = (TextField) pane.lookup("#component-property-" + name);
field.setText(value);
field.fireEvent(new ActionEvent());
return null;
});
await(() -> source().contains(name + "=\"" + value + "\""));
}
}