Offer grid row attributes and qualify Archiver folder profile editing
This commit is contained in:
@@ -0,0 +1,328 @@
|
||||
package qualification;
|
||||
|
||||
import static qualification.FolderActionsTargetProbe.Worker.*;
|
||||
|
||||
import java.nio.file.*;
|
||||
import java.time.*;
|
||||
import java.time.format.*;
|
||||
import java.util.*;
|
||||
import java.util.concurrent.Callable;
|
||||
import java.util.concurrent.atomic.AtomicInteger;
|
||||
import javafx.application.Platform;
|
||||
import javafx.collections.ListChangeListener;
|
||||
import javafx.scene.*;
|
||||
import javafx.scene.control.*;
|
||||
import javafx.stage.Window;
|
||||
|
||||
/** Checks rendered folder rows and the ordinary modal profile dialogs in the preview worker. */
|
||||
public final class FolderProfilesTargetProbe {
|
||||
public static void premain(String directory) {
|
||||
if (System.getProperty("sun.java.command", "")
|
||||
.startsWith("de.neitzel.fxdesigner.target.WorkerMain "))
|
||||
Thread.ofPlatform().daemon().start(() -> Checks.run(Path.of(directory)));
|
||||
}
|
||||
|
||||
private static final class Checks {
|
||||
private static void run(Path dir) {
|
||||
try {
|
||||
var stage = previewStage();
|
||||
var root =
|
||||
fx(
|
||||
() -> {
|
||||
stage.setWidth(1360);
|
||||
stage.setHeight(700);
|
||||
var r = stage.getScene().getRoot();
|
||||
r.applyCss();
|
||||
r.layout();
|
||||
return r;
|
||||
});
|
||||
var attempt = Files.readString(dir.resolve("layout-case"));
|
||||
var result =
|
||||
switch (attempt) {
|
||||
case "profiles", "readonly", "rebound" -> profiles(root, attempt);
|
||||
case "metadata", "renamed", "recovered" -> metadata(root, attempt, dir);
|
||||
default -> throw new AssertionError(attempt);
|
||||
};
|
||||
Files.writeString(dir.resolve("result-" + attempt), result);
|
||||
} catch (Throwable failure) {
|
||||
var trace = new java.io.StringWriter();
|
||||
failure.printStackTrace(new java.io.PrintWriter(trace));
|
||||
try {
|
||||
Files.writeString(dir.resolve("target-error.txt"), trace.toString());
|
||||
} catch (Exception error) {
|
||||
error.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private static DialogPane dialog(String title) {
|
||||
return Window.getWindows().stream()
|
||||
.filter(javafx.stage.Stage.class::isInstance)
|
||||
.map(javafx.stage.Stage.class::cast)
|
||||
.filter(s -> s.isShowing() && title.equals(s.getTitle()))
|
||||
.map(s -> (DialogPane) s.getScene().getRoot())
|
||||
.findFirst()
|
||||
.orElse(null);
|
||||
}
|
||||
|
||||
private static Button change(DialogPane d) {
|
||||
return (Button)
|
||||
d.lookupButton(
|
||||
d.getButtonTypes().stream()
|
||||
.filter(t -> t.getButtonData() == ButtonBar.ButtonData.OTHER)
|
||||
.findFirst()
|
||||
.orElseThrow());
|
||||
}
|
||||
|
||||
private static void toggle(Node grid, String header) {
|
||||
var menu = (MenuButton) grid.lookup(".data-grid-column-menu");
|
||||
menu.show();
|
||||
var item =
|
||||
(CheckMenuItem)
|
||||
menu.getItems().stream()
|
||||
.filter(i -> header.equals(i.getText()))
|
||||
.findFirst()
|
||||
.orElseThrow();
|
||||
item.setSelected(!item.isSelected());
|
||||
item.fire();
|
||||
menu.hide();
|
||||
}
|
||||
|
||||
private static String profiles(Parent root, String attempt) throws Exception {
|
||||
var grid = fx(() -> root.lookup("#grid"));
|
||||
var profiles = fx(() -> (ComboBox<String>) root.lookup("#folder-view-profile"));
|
||||
var save = fx(() -> (Button) root.lookup("#save-folder-view-profile"));
|
||||
var clear = fx(() -> (Button) root.lookup("#clear-folder-view-layout"));
|
||||
var manage = fx(() -> (Button) root.lookup("#manage-folder-view-profiles"));
|
||||
boolean readonly = attempt.equals("readonly"), rebound = attempt.equals("rebound");
|
||||
await(
|
||||
"Initial profile",
|
||||
() -> !manage.isDisabled() && profiles.isDisabled() == readonly && clear.isDisabled());
|
||||
String name = readonly ? "Metadaten" : "Prüfprofil";
|
||||
fx(
|
||||
() -> {
|
||||
require(
|
||||
!profiles.getItems().contains("Prüfprofil"),
|
||||
"New session inherited previous profile");
|
||||
if (!readonly) profiles.getEditor().setText(name);
|
||||
require(readonly == save.isDisabled(), "Save availability");
|
||||
if (!readonly && !rebound) {
|
||||
save.fire();
|
||||
require(profiles.getItems().contains(name), "Profile not saved");
|
||||
}
|
||||
toggle(grid, "Dateityp");
|
||||
return null;
|
||||
});
|
||||
await("Changed local layout", () -> !clear.isDisabled() && !visible(grid, "type"));
|
||||
fx(
|
||||
() -> {
|
||||
clear.fire();
|
||||
return null;
|
||||
});
|
||||
await("Restored local layout", () -> clear.isDisabled() && visible(grid, "type"));
|
||||
var openings = new AtomicInteger();
|
||||
String title = "Anzeigeprofile verwalten";
|
||||
ListChangeListener<Window> shown =
|
||||
changes -> {
|
||||
while (changes.next())
|
||||
for (Window w : changes.getAddedSubList())
|
||||
if (w instanceof javafx.stage.Stage s && title.equals(s.getTitle()))
|
||||
openings.incrementAndGet();
|
||||
};
|
||||
fx(
|
||||
() -> {
|
||||
Window.getWindows().addListener(shown);
|
||||
Platform.runLater((rebound ? save : manage)::fire);
|
||||
return null;
|
||||
});
|
||||
await("Profile manager opened", () -> dialog(title) != null);
|
||||
fx(
|
||||
() -> {
|
||||
var d = dialog(title);
|
||||
var list = (ListView<String>) d.lookup("#archive-display-profiles");
|
||||
if (rebound) require(!list.getItems().contains(name), "Old save handler also ran");
|
||||
else {
|
||||
list.getSelectionModel().select(name);
|
||||
var action = change(d);
|
||||
require(action.isDisabled() == readonly, "Profile deletion availability");
|
||||
if (!readonly) Platform.runLater(action::fire);
|
||||
}
|
||||
return null;
|
||||
});
|
||||
if (!readonly && !rebound) {
|
||||
Callable<DialogPane> confirm =
|
||||
() ->
|
||||
Window.getWindows().stream()
|
||||
.filter(Window::isShowing)
|
||||
.map(w -> w.getScene().getRoot())
|
||||
.filter(DialogPane.class::isInstance)
|
||||
.map(DialogPane.class::cast)
|
||||
.filter(d -> d.getButtonTypes().contains(ButtonType.OK))
|
||||
.findFirst()
|
||||
.orElse(null);
|
||||
await("Delete confirmation", () -> confirm.call() != null);
|
||||
fx(
|
||||
() -> {
|
||||
((Button) confirm.call().lookupButton(ButtonType.OK)).fire();
|
||||
return null;
|
||||
});
|
||||
await("Deleted own profile", () -> !profiles.getItems().contains(name));
|
||||
}
|
||||
fx(
|
||||
() -> {
|
||||
((Button) dialog(title).lookupButton(ButtonType.CLOSE)).fire();
|
||||
return null;
|
||||
});
|
||||
fx(
|
||||
() -> {
|
||||
Window.getWindows().removeListener(shown);
|
||||
require(
|
||||
openings.get() == 1 && dialog(title) == null,
|
||||
"Expected exactly one profile dialog: " + openings);
|
||||
return null;
|
||||
});
|
||||
if (rebound)
|
||||
return "Fresh session. Rebound Save opened exactly one management dialog, without saving a"
|
||||
+ " profile.";
|
||||
if (readonly)
|
||||
return "Read-only: archive save, selection and deletion disabled. Management and local"
|
||||
+ " layout change/reset succeeded.";
|
||||
return "Saved Prüfprofil, hid and restored Dateityp, deleted own profile after confirmation.";
|
||||
}
|
||||
|
||||
private static Label cell(Node grid, String text) {
|
||||
return grid.lookupAll(".label").stream()
|
||||
.filter(Label.class::isInstance)
|
||||
.map(Label.class::cast)
|
||||
.filter(l -> text.equals(l.getText()))
|
||||
.findFirst()
|
||||
.orElseThrow(() -> new AssertionError(text));
|
||||
}
|
||||
|
||||
private static List<Label> row(Node grid, String file) {
|
||||
return cell(grid, file).getParent().getChildrenUnmodifiable().stream()
|
||||
.filter(Label.class::isInstance)
|
||||
.map(Label.class::cast)
|
||||
.toList();
|
||||
}
|
||||
|
||||
private static String date(String day) {
|
||||
return DateTimeFormatter.ofLocalizedDateTime(FormatStyle.SHORT)
|
||||
.withZone(ZoneId.systemDefault())
|
||||
.format(Instant.parse(day + "T11:00:00Z"));
|
||||
}
|
||||
|
||||
private static void cells(Node grid, String file, String... expected) {
|
||||
var labels = row(grid, file);
|
||||
var actual = labels.stream().limit(10).map(Label::getText).toList();
|
||||
var values = new ArrayList<>(List.of(file));
|
||||
values.addAll(List.of(expected));
|
||||
require(actual.equals(values), file + " rendered " + actual + " expected " + values);
|
||||
require(
|
||||
labels.get(4).getPrefWidth() == 182 && labels.get(5).getPrefWidth() == 168,
|
||||
"Profile widths: " + labels.get(4).getPrefWidth() + ", " + labels.get(5).getPrefWidth());
|
||||
}
|
||||
|
||||
private static String metadata(Parent root, String attempt, Path dir) throws Exception {
|
||||
var grid = fx(() -> root.lookup("#grid"));
|
||||
var profiles = fx(() -> (ComboBox<String>) root.lookup("#folder-view-profile"));
|
||||
boolean renamed = !attempt.equals("metadata");
|
||||
String sent = renamed ? "versand" : "mailSent";
|
||||
await(
|
||||
"Loaded saved metadata profile",
|
||||
() -> visible(grid, sent) && visible(grid, "bookTitle") && !profiles.isDisabled());
|
||||
fx(
|
||||
() -> {
|
||||
require(
|
||||
"Metadaten".equals(profiles.getValue()), "Initial profile " + profiles.getValue());
|
||||
String january = "Z-Anfrage.eml", december = "A-Zusage.eml";
|
||||
cells(
|
||||
grid,
|
||||
january,
|
||||
"Anfrage",
|
||||
"ada@example.org",
|
||||
"archiv@example.org",
|
||||
"kopie@example.org",
|
||||
date("2026-01-01"),
|
||||
"",
|
||||
"",
|
||||
"",
|
||||
"");
|
||||
cells(
|
||||
grid,
|
||||
december,
|
||||
"Zusage",
|
||||
"ada@example.org",
|
||||
"archiv@example.org",
|
||||
"kopie@example.org",
|
||||
date("2026-12-01"),
|
||||
"",
|
||||
"",
|
||||
"",
|
||||
"");
|
||||
cells(
|
||||
grid,
|
||||
"Lesebuch.epub",
|
||||
"",
|
||||
"",
|
||||
"",
|
||||
"",
|
||||
"",
|
||||
renamed ? "Nordverlag" : "Das Lesebuch",
|
||||
"Ada Berg, Eva Tal",
|
||||
"Nordverlag",
|
||||
"de");
|
||||
cells(grid, "Notiz.txt", "", "", "", "", "", "", "", "", "");
|
||||
require(
|
||||
cell(grid, january).localToScene(0, 0).getY()
|
||||
< cell(grid, december).localToScene(0, 0).getY(),
|
||||
"Mail date sort order");
|
||||
var setup = grid.getClass().getMethod("snapshotSetup").invoke(grid);
|
||||
require(
|
||||
setup
|
||||
.getClass()
|
||||
.getMethod("sort")
|
||||
.invoke(setup)
|
||||
.toString()
|
||||
.contains(sent + ", direction=ASCENDING"),
|
||||
"Sort after restoration: " + setup);
|
||||
if (renamed) {
|
||||
cell(grid, "Buchverlag");
|
||||
require(
|
||||
root.lookupAll(".label").stream()
|
||||
.anyMatch(
|
||||
n -> n instanceof Label l && l.getText().contains("mailSent → versand")),
|
||||
"Missing profile mapping");
|
||||
image(root, dir.resolve("folder-metadata.png"));
|
||||
}
|
||||
profiles.getSelectionModel().select("\0STANDARD");
|
||||
return null;
|
||||
});
|
||||
await(
|
||||
"Standard hides metadata",
|
||||
() -> !visible(grid, sent) && !visible(grid, "mailCc") && !profiles.isDisabled());
|
||||
fx(
|
||||
() -> {
|
||||
profiles.getSelectionModel().select("\0EMAIL");
|
||||
return null;
|
||||
});
|
||||
await(
|
||||
"Email shows date and CC",
|
||||
() ->
|
||||
visible(grid, sent)
|
||||
&& visible(grid, "mailCc")
|
||||
&& !visible(grid, "bookTitle")
|
||||
&& !profiles.isDisabled());
|
||||
fx(
|
||||
() -> {
|
||||
profiles.getSelectionModel().select("Metadaten");
|
||||
return null;
|
||||
});
|
||||
await("Return to saved profile", () -> visible(grid, "bookTitle") && !profiles.isDisabled());
|
||||
return "Rendered two mails, EPUB and plain text. Nine metadata cells per row; sort "
|
||||
+ sent
|
||||
+ " ascending, CC 182 px, date 168 px. Standard → Email → Metadaten."
|
||||
+ (renamed ? " Retained date source and bookPublisher in Buchverlag." : "");
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user