Add reviewed FXML View generation in both hosts
This commit is contained in:
@@ -38,11 +38,7 @@ public final class ProjectionHostChecks {
|
||||
}
|
||||
|
||||
private static TextArea source(DesignerPane pane) {
|
||||
return (TextArea)
|
||||
pane.lookupAll(".text-area").stream()
|
||||
.filter(n -> n instanceof TextArea t && t.isEditable())
|
||||
.findFirst()
|
||||
.orElseThrow();
|
||||
return (TextArea) pane.lookup("#fxml-source");
|
||||
}
|
||||
|
||||
private static FXOMInstance object(DesignerPane pane, String id) {
|
||||
@@ -1668,6 +1664,323 @@ public final class ProjectionHostChecks {
|
||||
}
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
private static void generationSelect(DesignerPane pane, String path) throws Exception {
|
||||
fx(
|
||||
() -> {
|
||||
var list =
|
||||
(ListView<de.neitzel.fxdesigner.generation.ViewGeneration.Field>)
|
||||
pane.lookup("#generate-fields");
|
||||
list.getSelectionModel()
|
||||
.select(
|
||||
list.getItems().stream()
|
||||
.filter(f -> f.path().equals(path))
|
||||
.findFirst()
|
||||
.orElseThrow());
|
||||
return null;
|
||||
});
|
||||
}
|
||||
|
||||
private static void generationText(DesignerPane pane, String id, String text) throws Exception {
|
||||
fx(
|
||||
() -> {
|
||||
var node = pane.lookup("#generate-" + id);
|
||||
if (node instanceof ComboBox<?> box) box.getEditor().setText(text);
|
||||
else ((TextInputControl) node).setText(text);
|
||||
return null;
|
||||
});
|
||||
}
|
||||
|
||||
private static void generationReady(DesignerPane pane) throws Exception {
|
||||
click(pane, "Review generated View");
|
||||
await(
|
||||
() ->
|
||||
fx(
|
||||
() ->
|
||||
((Label) pane.lookup("#generate-status"))
|
||||
.getText()
|
||||
.startsWith("Review ready")));
|
||||
check(fx(() -> !pane.lookup("#generate-create").isDisabled()), "Reviewed creation unavailable");
|
||||
}
|
||||
|
||||
public static void generation(DesignerPane pane, DocumentSession document) throws Exception {
|
||||
String original = documentText(document);
|
||||
bindingTab(pane, "Generate View");
|
||||
generationText(pane, "model", "fixture.model.Person");
|
||||
generationText(pane, "controller", "");
|
||||
click(pane, "Load Model fields");
|
||||
await(() -> fx(() -> ((ListView<?>) pane.lookup("#generate-fields")).getItems().size() == 4));
|
||||
check(
|
||||
fx(
|
||||
() ->
|
||||
((Label) pane.lookup("#generate-status"))
|
||||
.getText()
|
||||
.contains("Generated Model metadata")),
|
||||
"Generator did not use shared generated metadata");
|
||||
click(pane, "Review generated View");
|
||||
check(
|
||||
fx(() -> pane.lookup("#generate-create").isDisabled()),
|
||||
"Unconfigured nested field allowed creation");
|
||||
generationSelect(pane, "home");
|
||||
click(pane, "Discover field choices");
|
||||
await(
|
||||
() ->
|
||||
fx(
|
||||
() ->
|
||||
((TextArea) pane.lookup("#generate-choices"))
|
||||
.getText()
|
||||
.contains(
|
||||
"fixture.components.AddressForm : fixture.model.Address —"
|
||||
+ " COMPATIBLE")));
|
||||
generationText(pane, "component", "fixture.components.AddressForm");
|
||||
generationSelect(pane, "visits");
|
||||
generationText(pane, "component", "fixture.components.AddressForm");
|
||||
generationSelect(pane, "name");
|
||||
generationText(pane, "label", "Name & <display>");
|
||||
click(pane, "Move field up");
|
||||
generationSelect(pane, "rank");
|
||||
click(pane, "Discover field choices");
|
||||
await(
|
||||
() ->
|
||||
fx(
|
||||
() ->
|
||||
((TextArea) pane.lookup("#generate-choices"))
|
||||
.getText()
|
||||
.contains("fixture.components.RankConverter")));
|
||||
click(pane, "Review generated View");
|
||||
await(
|
||||
() ->
|
||||
fx(
|
||||
() ->
|
||||
((Label) pane.lookup("#generate-status"))
|
||||
.getText()
|
||||
.startsWith("Review blocked")));
|
||||
check(
|
||||
fx(() -> pane.lookup("#generate-create").isDisabled()),
|
||||
"Numeric text without a Converter accepted");
|
||||
generationText(pane, "converter", "fixture.components.LegacyRankConverter");
|
||||
generationReady(pane);
|
||||
check(
|
||||
fx(() -> ((Label) pane.lookup("#generate-status")).getText().contains("WARNING")),
|
||||
"Unverified Converter warning hidden");
|
||||
generationText(pane, "converter", "fixture.components.RankConverter");
|
||||
generationReady(pane);
|
||||
String repeat = fx(() -> ((TextArea) pane.lookup("#generate-preview")).getText());
|
||||
check(
|
||||
repeat.contains("<Repeat") && repeat.contains("Name & <display>"),
|
||||
"Repeat/label generation lost choices");
|
||||
check(documentText(document).equals(original), "Review modified the parent View");
|
||||
generationText(pane, "label", "Rank reviewed");
|
||||
check(
|
||||
fx(() -> pane.lookup("#generate-create").isDisabled()),
|
||||
"Edited proposal retained creation approval");
|
||||
generationText(pane, "converter", "missing.Converter");
|
||||
fx(
|
||||
() -> {
|
||||
((CheckBox) pane.lookup("#generate-include")).setSelected(false);
|
||||
return null;
|
||||
});
|
||||
generationReady(pane);
|
||||
check(
|
||||
!fx(() -> ((TextArea) pane.lookup("#generate-preview")).getText())
|
||||
.contains("path=\"rank\""),
|
||||
"Omitted invalid field emitted");
|
||||
generationText(pane, "converter", "fixture.components.RankConverter");
|
||||
fx(
|
||||
() -> {
|
||||
((CheckBox) pane.lookup("#generate-include")).setSelected(true);
|
||||
return null;
|
||||
});
|
||||
generationSelect(pane, "visits");
|
||||
fx(
|
||||
() -> {
|
||||
@SuppressWarnings("unchecked")
|
||||
var control =
|
||||
(ComboBox<de.neitzel.fxdesigner.generation.ViewGeneration.Control>)
|
||||
pane.lookup("#generate-control");
|
||||
control.setValue(de.neitzel.fxdesigner.generation.ViewGeneration.Control.Table);
|
||||
return null;
|
||||
});
|
||||
generationText(pane, "component", "fixture.components.VisitRow");
|
||||
generationText(pane, "columns", "street | Street & road | 160");
|
||||
click(pane, "Discover field choices");
|
||||
await(
|
||||
() ->
|
||||
fx(
|
||||
() ->
|
||||
((TextArea) pane.lookup("#generate-choices"))
|
||||
.getText()
|
||||
.contains("fixture.components.VisitRow")));
|
||||
generationReady(pane);
|
||||
String table = fx(() -> ((TextArea) pane.lookup("#generate-preview")).getText());
|
||||
check(
|
||||
table.contains("<Table") && table.contains("attribute=\"street\""),
|
||||
"Table generation lost Columns");
|
||||
// Load both reviewed variants through the actual target-runtime sample provider.
|
||||
for (String xml : List.of(repeat, table)) {
|
||||
set(document, xml);
|
||||
await(() -> fx(() -> source(pane).getText().equals(xml)));
|
||||
fx(
|
||||
() -> {
|
||||
for (var n : pane.lookupAll(".combo-box"))
|
||||
if (n instanceof ComboBox<?> box) {
|
||||
for (Object value : box.getItems())
|
||||
if (value
|
||||
instanceof de.neitzel.fxdesigner.workflow.DesignerWorkflow.Example example
|
||||
&& example.id().equals("standard")) {
|
||||
@SuppressWarnings("unchecked")
|
||||
var examples = (ComboBox<Object>) box;
|
||||
examples.setValue(example);
|
||||
break;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
});
|
||||
click(pane, "Interactive preview");
|
||||
await(
|
||||
() ->
|
||||
fx(
|
||||
() ->
|
||||
pane.lookupAll(".label").stream()
|
||||
.anyMatch(
|
||||
n ->
|
||||
n instanceof Label l
|
||||
&& "Interactive preview running from captured drafts"
|
||||
.equals(l.getText()))));
|
||||
check(pane.interactivePid() > 0, "Generated View did not load in target worker");
|
||||
click(pane, "Stop preview");
|
||||
await(() -> pane.interactivePid() < 0);
|
||||
}
|
||||
set(document, original);
|
||||
await(() -> fx(() -> source(pane).getText().equals(original)));
|
||||
document
|
||||
.save(document.snapshot().toCompletableFuture().get().revision())
|
||||
.toCompletableFuture()
|
||||
.get();
|
||||
bindingTab(pane, "Generate View");
|
||||
generationText(pane, "file", "../escape.fxml");
|
||||
click(pane, "Review generated View");
|
||||
check(fx(() -> pane.lookup("#generate-create").isDisabled()), "Traversal filename accepted");
|
||||
generationText(pane, "file", "ReviewedView.fxml");
|
||||
generationReady(pane);
|
||||
set(document, original + "<!-- review invalidation -->");
|
||||
await(() -> fx(() -> pane.lookup("#generate-create").isDisabled()));
|
||||
set(document, original);
|
||||
await(() -> fx(() -> source(pane).getText().equals(original)));
|
||||
document
|
||||
.save(document.snapshot().toCompletableFuture().get().revision())
|
||||
.toCompletableFuture()
|
||||
.get();
|
||||
generationReady(pane);
|
||||
String reviewed = fx(() -> ((TextArea) pane.lookup("#generate-preview")).getText());
|
||||
click(pane, "Create reviewed View");
|
||||
await(
|
||||
() ->
|
||||
fx(
|
||||
() ->
|
||||
((Label) pane.lookup("#generate-status"))
|
||||
.getText()
|
||||
.startsWith("Created and opened ReviewedView.fxml")));
|
||||
var path =
|
||||
java.nio.file.Path.of(document.snapshot().toCompletableFuture().get().document())
|
||||
.resolveSibling("ReviewedView.fxml");
|
||||
check(
|
||||
java.nio.file.Files.readString(path).equals(reviewed),
|
||||
"Created bytes differ from reviewed FXML");
|
||||
check(documentText(document).equals(original), "Creation changed parent");
|
||||
try (var created =
|
||||
pane.kit().host().documents().open(path.toUri()).toCompletableFuture().get()) {
|
||||
var before = created.snapshot().toCompletableFuture().get();
|
||||
String edited = before.text() + "<!-- normal generated-View edit -->";
|
||||
set(created, edited);
|
||||
check(
|
||||
created.undo().toCompletableFuture().get().text().equals(before.text()),
|
||||
"Generated View Undo lost source");
|
||||
check(
|
||||
created.redo().toCompletableFuture().get().text().equals(edited),
|
||||
"Generated View Redo lost source");
|
||||
created
|
||||
.save(created.snapshot().toCompletableFuture().get().revision())
|
||||
.toCompletableFuture()
|
||||
.get();
|
||||
try {
|
||||
pane.kit().host().documents().create(path.toUri(), "overwrite").toCompletableFuture().get();
|
||||
throw new AssertionError("Generated View overwritten");
|
||||
} catch (ExecutionException expected) {
|
||||
check(
|
||||
expected.getCause() instanceof java.nio.file.FileAlreadyExistsException,
|
||||
"Wrong collision failure");
|
||||
}
|
||||
check(java.nio.file.Files.readString(path).equals(edited), "Collision changed existing file");
|
||||
}
|
||||
// Add an ordinary sample descriptor in this disposable fixture, so the newly
|
||||
// created resource itself (not only an overlay at the parent URI) is loaded.
|
||||
var launch = (de.neitzel.fxdesigner.workflow.HostLaunch) field(pane, "launch");
|
||||
var root = launch.configuration().getParent();
|
||||
var catalog =
|
||||
root.resolve("app/src/test/resources/META-INF/neitzel-fx-designer/examples.properties");
|
||||
if (!java.nio.file.Files.exists(catalog))
|
||||
catalog =
|
||||
root.resolve(
|
||||
"preview/src/main/resources/META-INF/neitzel-fx-designer/examples.properties");
|
||||
String catalogText = java.nio.file.Files.readString(catalog);
|
||||
var properties = new java.util.Properties();
|
||||
properties.load(new java.io.StringReader(catalogText));
|
||||
int count = Integer.parseInt(properties.getProperty("count"));
|
||||
String key = "example." + count + ".";
|
||||
catalogText =
|
||||
catalogText.replaceFirst("(?m)^count=\\d+", "count=" + (count + 1))
|
||||
+ "\n"
|
||||
+ key
|
||||
+ "id=reviewed\n"
|
||||
+ key
|
||||
+ "label=Reviewed View\n"
|
||||
+ key
|
||||
+ "modelType=fixture.model.Person\n"
|
||||
+ key
|
||||
+ "providerClass=fixture.preview.Examples\n"
|
||||
+ key
|
||||
+ "viewResource=fixture/components/ReviewedView.fxml\n"
|
||||
+ key
|
||||
+ "componentPackage=fixture.components\n";
|
||||
java.nio.file.Files.writeString(catalog, catalogText);
|
||||
click(pane, "Build and Refresh");
|
||||
var build = (de.neitzel.fxdesigner.build.BuildRefresh.Run) fx(() -> field(pane, "buildRun"));
|
||||
check(
|
||||
build.completion().toCompletableFuture().get(90, TimeUnit.SECONDS).status()
|
||||
== de.neitzel.fxdesigner.build.BuildRefresh.Status.READY,
|
||||
"Build after new View failed");
|
||||
await(
|
||||
() ->
|
||||
fx(
|
||||
() ->
|
||||
object(pane, "card").getSceneGraphObject() instanceof SnapshotRegion r
|
||||
&& r.image() != null
|
||||
&& r.statusText().equals("Target runtime")));
|
||||
try (var generatedWorkflow =
|
||||
new de.neitzel.fxdesigner.workflow.DesignerWorkflow(
|
||||
pane.kit().host(),
|
||||
launch.configuration(),
|
||||
launch.context(),
|
||||
launch.maven(),
|
||||
launch.tools(),
|
||||
s -> {});
|
||||
var created =
|
||||
pane.kit().host().documents().open(path.toUri()).toCompletableFuture().get()) {
|
||||
generatedWorkflow
|
||||
.interactive(false, "reviewed", List.of(created.snapshot().toCompletableFuture().get()))
|
||||
.toCompletableFuture()
|
||||
.get(30, TimeUnit.SECONDS);
|
||||
check(
|
||||
generatedWorkflow.renderingPid() > 0,
|
||||
"New generated resource did not load through NeitzelLib");
|
||||
}
|
||||
System.out.println(
|
||||
"PASS reviewed View generation: metadata, choices, invalid/omitted fields, Repeat/Table"
|
||||
+ " target loading, immutable review, create/open, collision protection, normal"
|
||||
+ " Undo/Redo and rebuild");
|
||||
}
|
||||
|
||||
public static void run(DesignerPane pane, DocumentSession document) throws Exception {
|
||||
renderRevisionRace(pane, document);
|
||||
String original = document.snapshot().toCompletableFuture().get().text();
|
||||
@@ -2046,6 +2359,7 @@ public final class ProjectionHostChecks {
|
||||
object(pane, "card").getSceneGraphObject() instanceof SnapshotRegion r
|
||||
&& r.image() != null
|
||||
&& r.statusText().equals("Target runtime")));
|
||||
generation(pane, document);
|
||||
System.out.println(
|
||||
"PASS shared projection: exact source, picking/resize/relocation, nested/FQ/anonymous"
|
||||
+ " Components, declared properties, selection, undo/redo, modes, target load,"
|
||||
|
||||
Reference in New Issue
Block a user