test(ui): add automated button layout integrity test and multi-resolution preview captures
This commit is contained in:
+32
-2
@@ -28,7 +28,9 @@ import javafx.geometry.Insets;
|
||||
import javafx.geometry.Pos;
|
||||
import javafx.scene.Node;
|
||||
import javafx.scene.Scene;
|
||||
import javafx.scene.SnapshotParameters;
|
||||
import javafx.scene.control.Button;
|
||||
import javafx.scene.transform.Transform;
|
||||
import javafx.scene.control.Label;
|
||||
import javafx.scene.control.ScrollPane;
|
||||
import javafx.scene.image.PixelReader;
|
||||
@@ -108,13 +110,33 @@ public class UiPreviewGenerator extends Application {
|
||||
|
||||
private void captureHubScreenshots(Stage stage) throws Exception {
|
||||
MainAppView appView = new MainAppView(stage);
|
||||
|
||||
// 1. Resolução padrão 780x500
|
||||
stage.setWidth(780);
|
||||
stage.setHeight(500);
|
||||
stage.show();
|
||||
stage.getScene().getRoot().applyCss();
|
||||
stage.getScene().getRoot().layout();
|
||||
|
||||
saveNodeSnapshot(stage.getScene(), new File(OUTPUT_DIR, "01_hub.png"));
|
||||
saveNodeSnapshot(stage.getScene(), new File(OUTPUT_DIR, "01_hub_780x500.png"));
|
||||
saveNodeSnapshot(stage.getScene(), new File(OUTPUT_DIR, "01_hub_claro.png"));
|
||||
saveNodeSnapshot(stage.getScene(), new File(OUTPUT_DIR, "01_layout_claro.png"));
|
||||
|
||||
// 2. Escala 150% (High-DPI / Zoom 1.5x)
|
||||
saveNodeSnapshotScaled(stage.getScene(), new File(OUTPUT_DIR, "01_hub_scale150.png"), 1.5);
|
||||
|
||||
// 3. Resolução expandida 1024x768
|
||||
stage.setWidth(1024);
|
||||
stage.setHeight(768);
|
||||
stage.getScene().getRoot().applyCss();
|
||||
stage.getScene().getRoot().layout();
|
||||
|
||||
saveNodeSnapshot(stage.getScene(), new File(OUTPUT_DIR, "01_hub_1024x768.png"));
|
||||
|
||||
// Restaura tamanho padrão para os diálogos subsequentes
|
||||
stage.setWidth(780);
|
||||
stage.setHeight(500);
|
||||
}
|
||||
|
||||
private void captureDiagnosticsScreenshots(Stage stage) throws Exception {
|
||||
@@ -551,7 +573,15 @@ public class UiPreviewGenerator extends Application {
|
||||
}
|
||||
|
||||
private static void saveNodeSnapshot(Scene scene, File targetFile) throws Exception {
|
||||
WritableImage image = scene.snapshot(null);
|
||||
saveNodeSnapshotScaled(scene, targetFile, 1.0);
|
||||
}
|
||||
|
||||
private static void saveNodeSnapshotScaled(Scene scene, File targetFile, double scale) throws Exception {
|
||||
SnapshotParameters params = new SnapshotParameters();
|
||||
if (scale != 1.0) {
|
||||
params.setTransform(Transform.scale(scale, scale));
|
||||
}
|
||||
WritableImage image = scene.getRoot().snapshot(params, null);
|
||||
int width = (int) image.getWidth();
|
||||
int height = (int) image.getHeight();
|
||||
BufferedImage bufferedImage = new BufferedImage(width, height, BufferedImage.TYPE_INT_ARGB);
|
||||
@@ -562,6 +592,6 @@ public class UiPreviewGenerator extends Application {
|
||||
}
|
||||
}
|
||||
ImageIO.write(bufferedImage, "png", targetFile);
|
||||
System.out.println("Screenshot gerada: " + targetFile.getName());
|
||||
System.out.println("Screenshot gerada: " + targetFile.getName() + " (" + width + "x" + height + ")");
|
||||
}
|
||||
}
|
||||
|
||||
+406
@@ -0,0 +1,406 @@
|
||||
package br.com.cybercore.signer.ui.view;
|
||||
|
||||
import br.com.cybercore.signer.core.crypto.SigningService;
|
||||
import br.com.cybercore.signer.core.domain.CertificateStatus;
|
||||
import br.com.cybercore.signer.core.domain.CertificateType;
|
||||
import br.com.cybercore.signer.core.domain.ManagedCertificate;
|
||||
import br.com.cybercore.signer.core.domain.SigningContext;
|
||||
import br.com.cybercore.signer.core.pdf.PdfSigningService;
|
||||
import br.com.cybercore.signer.core.pdf.seal.CpfDisplayMode;
|
||||
import br.com.cybercore.signer.core.pdf.seal.PdfSealThemeRegistry;
|
||||
import br.com.cybercore.signer.core.provider.CertificateManager;
|
||||
import br.com.cybercore.signer.ui.components.SvgIcons;
|
||||
import javafx.application.Platform;
|
||||
import javafx.scene.Node;
|
||||
import javafx.scene.Parent;
|
||||
import javafx.scene.Scene;
|
||||
import javafx.scene.control.Button;
|
||||
import javafx.stage.Stage;
|
||||
import org.junit.jupiter.api.BeforeAll;
|
||||
import org.junit.jupiter.api.DisplayName;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import java.io.File;
|
||||
import java.time.Instant;
|
||||
import java.time.temporal.ChronoUnit;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.concurrent.CountDownLatch;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
import java.util.concurrent.atomic.AtomicReference;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
|
||||
/**
|
||||
* Teste automatizado de integridade de layout para telas e diálogos do CyberCore Signer.
|
||||
* Garante que nenhum botão tenha seu texto ou área comprimida/truncada (largura ou altura menor que pref).
|
||||
* Valida também as dimensões mínimas dos cartões do Hub (min 68px) e da lista lateral (min 40px).
|
||||
*/
|
||||
class ButtonLayoutIntegrityTest {
|
||||
|
||||
private static boolean javaFxAvailable = false;
|
||||
|
||||
@BeforeAll
|
||||
static void initJavaFx() {
|
||||
CountDownLatch latch = new CountDownLatch(1);
|
||||
try {
|
||||
Platform.startup(() -> {
|
||||
javaFxAvailable = true;
|
||||
latch.countDown();
|
||||
});
|
||||
if (!latch.await(5, TimeUnit.SECONDS)) {
|
||||
javaFxAvailable = false;
|
||||
}
|
||||
} catch (Throwable t) {
|
||||
if (t instanceof IllegalStateException && t.getMessage() != null
|
||||
&& t.getMessage().contains("Toolkit already initialized")) {
|
||||
javaFxAvailable = true;
|
||||
} else {
|
||||
javaFxAvailable = false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void runOnFxThread(ThrowingRunnable action) throws Throwable {
|
||||
org.junit.jupiter.api.Assumptions.assumeTrue(javaFxAvailable, "Ambiente gráfico JavaFX (X11/Xvfb) não disponível.");
|
||||
|
||||
CountDownLatch latch = new CountDownLatch(1);
|
||||
AtomicReference<Throwable> error = new AtomicReference<>();
|
||||
|
||||
Platform.runLater(() -> {
|
||||
try {
|
||||
action.run();
|
||||
} catch (Throwable t) {
|
||||
error.set(t);
|
||||
} finally {
|
||||
latch.countDown();
|
||||
}
|
||||
});
|
||||
|
||||
assertThat(latch.await(8, TimeUnit.SECONDS)).isTrue();
|
||||
if (error.get() != null) {
|
||||
throw error.get();
|
||||
}
|
||||
}
|
||||
|
||||
@FunctionalInterface
|
||||
interface ThrowingRunnable {
|
||||
void run() throws Throwable;
|
||||
}
|
||||
|
||||
private void layoutAndAssert(Stage stage, double width, double height, String screenName) {
|
||||
Scene scene = stage.getScene();
|
||||
if (width > 0 && height > 0) {
|
||||
stage.setWidth(width);
|
||||
stage.setHeight(height);
|
||||
}
|
||||
Parent root = scene.getRoot();
|
||||
root.applyCss();
|
||||
if (width > 0 && height > 0) {
|
||||
root.resizeRelocate(0, 0, width, height);
|
||||
}
|
||||
root.layout();
|
||||
|
||||
List<Button> buttons = new ArrayList<>();
|
||||
findButtons(root, buttons);
|
||||
|
||||
for (Button b : buttons) {
|
||||
if (!b.isVisible() || !b.isManaged()) {
|
||||
continue;
|
||||
}
|
||||
double w = b.getWidth();
|
||||
double h = b.getHeight();
|
||||
double prefW = b.prefWidth(-1);
|
||||
double prefH = b.prefHeight(-1);
|
||||
|
||||
assertThat(w)
|
||||
.withFailMessage("Botão '%s' na tela [%s] teve largura comprimida: w=%.1f < prefW=%.1f",
|
||||
b.getText(), screenName, w, prefW)
|
||||
.isGreaterThanOrEqualTo(prefW - 0.5);
|
||||
|
||||
assertThat(h)
|
||||
.withFailMessage("Botão '%s' na tela [%s] teve altura comprimida: h=%.1f < prefH=%.1f",
|
||||
b.getText(), screenName, h, prefH)
|
||||
.isGreaterThanOrEqualTo(prefH - 0.5);
|
||||
|
||||
if (b.getStyleClass().contains("cyber-action-card")) {
|
||||
assertThat(h)
|
||||
.withFailMessage("Cartão do Hub '%s' na tela [%s] teve altura menor que 68px: h=%.1f",
|
||||
b.getText(), screenName, h)
|
||||
.isGreaterThanOrEqualTo(68.0 - 0.5);
|
||||
}
|
||||
|
||||
if (b.getStyleClass().contains("cyber-side-card")) {
|
||||
assertThat(h)
|
||||
.withFailMessage("Item lateral do Hub '%s' na tela [%s] teve altura menor que 40px: h=%.1f",
|
||||
b.getText(), screenName, h)
|
||||
.isGreaterThanOrEqualTo(40.0 - 0.5);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void findButtons(Node node, List<Button> accumulator) {
|
||||
if (node instanceof Button btn) {
|
||||
accumulator.add(btn);
|
||||
}
|
||||
if (node instanceof Parent parent) {
|
||||
for (Node child : parent.getChildrenUnmodifiable()) {
|
||||
findButtons(child, accumulator);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private ManagedCertificate createSampleCertificate() {
|
||||
return new ManagedCertificate(
|
||||
"cert-test-id",
|
||||
"JOAO DA SILVA:12345678900",
|
||||
CertificateType.A1,
|
||||
CertificateStatus.AVAILABLE,
|
||||
"CN=JOAO DA SILVA:12345678900, OU=Autenticado por AR, O=ICP-Brasil, C=BR",
|
||||
"CN=AC SERPRO RFB v5, O=ICP-Brasil, C=BR",
|
||||
"1A2B3C4D5E",
|
||||
"11223344556677889900",
|
||||
"AABBCCDDEEFF00112233445566778899",
|
||||
Instant.now().minus(30, ChronoUnit.DAYS),
|
||||
Instant.now().plus(330, ChronoUnit.DAYS),
|
||||
"RSA",
|
||||
2048,
|
||||
"JOAO DA SILVA:12345678900",
|
||||
"12345678900",
|
||||
null,
|
||||
"SunJSSE",
|
||||
null
|
||||
);
|
||||
}
|
||||
|
||||
private static File getOrCreateSamplePdf() throws Exception {
|
||||
File pdf = new File("target/test-sample.pdf");
|
||||
if (!pdf.exists()) {
|
||||
if (pdf.getParentFile() != null) {
|
||||
pdf.getParentFile().mkdirs();
|
||||
}
|
||||
try (org.apache.pdfbox.pdmodel.PDDocument document = new org.apache.pdfbox.pdmodel.PDDocument()) {
|
||||
org.apache.pdfbox.pdmodel.PDPage page = new org.apache.pdfbox.pdmodel.PDPage();
|
||||
document.addPage(page);
|
||||
try (org.apache.pdfbox.pdmodel.PDPageContentStream cs = new org.apache.pdfbox.pdmodel.PDPageContentStream(document, page)) {
|
||||
cs.beginText();
|
||||
cs.setFont(new org.apache.pdfbox.pdmodel.font.PDType1Font(org.apache.pdfbox.pdmodel.font.Standard14Fonts.FontName.HELVETICA_BOLD), 14);
|
||||
cs.newLineAtOffset(50, 700);
|
||||
cs.showText("CyberCore Signer Test PDF");
|
||||
cs.endText();
|
||||
}
|
||||
document.save(pdf);
|
||||
}
|
||||
}
|
||||
return pdf;
|
||||
}
|
||||
|
||||
@Test
|
||||
@DisplayName("Hub Principal (MainAppView): nenhum botão deve truncar e os cartões devem ter altura >= 68px")
|
||||
void testMainAppViewButtons() throws Throwable {
|
||||
runOnFxThread(() -> {
|
||||
Stage stage = new Stage();
|
||||
MainAppView view = new MainAppView(stage);
|
||||
layoutAndAssert(stage, 780, 500, "MainAppView 780x500");
|
||||
layoutAndAssert(stage, 1024, 768, "MainAppView 1024x768");
|
||||
});
|
||||
}
|
||||
|
||||
@Test
|
||||
@DisplayName("ExitConfirmationDialog: botões Cancelar, Encerrar e Minimizar com tamanho preferencial")
|
||||
void testExitConfirmationDialogButtons() throws Throwable {
|
||||
runOnFxThread(() -> {
|
||||
ExitConfirmationDialog dialog = new ExitConfirmationDialog(null);
|
||||
layoutAndAssert(dialog.getStage(), 480, 220, "ExitConfirmationDialog");
|
||||
});
|
||||
}
|
||||
|
||||
@Test
|
||||
@DisplayName("ApplicationApprovalDialog: botões com tamanho preferencial e sem truncamento")
|
||||
void testApplicationApprovalDialogButtons() throws Throwable {
|
||||
runOnFxThread(() -> {
|
||||
Stage stage = new Stage();
|
||||
ApplicationApprovalDialog dialog = new ApplicationApprovalDialog(
|
||||
stage,
|
||||
"https://contratos.empresa.com.br",
|
||||
"Sistema de Contratos Online",
|
||||
"app-test-id"
|
||||
);
|
||||
layoutAndAssert(dialog.getStage(), 520, 360, "ApplicationApprovalDialog");
|
||||
});
|
||||
}
|
||||
|
||||
@Test
|
||||
@DisplayName("A1PasswordDialog: botões Cancelar e Desbloquear com tamanho preferencial")
|
||||
void testA1PasswordDialogButtons() throws Throwable {
|
||||
runOnFxThread(() -> {
|
||||
A1PasswordDialog dialog = new A1PasswordDialog(null, "certificado-empresa.pfx");
|
||||
layoutAndAssert(dialog.getStage(), 460, 260, "A1PasswordDialog");
|
||||
});
|
||||
}
|
||||
|
||||
@Test
|
||||
@DisplayName("SignaturePromptDialog: botões Cancelar e Confirmar com tamanho preferencial")
|
||||
void testSignaturePromptDialogButtons() throws Throwable {
|
||||
runOnFxThread(() -> {
|
||||
ManagedCertificate cert = createSampleCertificate();
|
||||
SigningContext ctx = new SigningContext(
|
||||
"req-1234",
|
||||
"app-web",
|
||||
new byte[32],
|
||||
"SHA256withRSA",
|
||||
null,
|
||||
Instant.now().plusSeconds(60)
|
||||
);
|
||||
SignaturePromptDialog dialog = new SignaturePromptDialog(
|
||||
null,
|
||||
"Portal Financeiro",
|
||||
"https://financeiro.gov.br",
|
||||
cert,
|
||||
ctx,
|
||||
"Ordem_Pagamento_2026.pdf",
|
||||
"PDF",
|
||||
false
|
||||
);
|
||||
layoutAndAssert(dialog.getStage(), 560, 420, "SignaturePromptDialog");
|
||||
});
|
||||
}
|
||||
|
||||
@Test
|
||||
@DisplayName("CertificatesManagerDialog: botões de ação e fechamento com tamanho preferencial")
|
||||
void testCertificatesManagerDialogButtons() throws Throwable {
|
||||
runOnFxThread(() -> {
|
||||
CertificateManager certManager = CertificateManager.createDefault();
|
||||
CertificatesManagerDialog dialog = new CertificatesManagerDialog(null, certManager);
|
||||
layoutAndAssert(dialog.getStage(), 760, 520, "CertificatesManagerDialog");
|
||||
});
|
||||
}
|
||||
|
||||
@Test
|
||||
@DisplayName("CertificateDetailsDialog: botão Fechar com tamanho preferencial")
|
||||
void testCertificateDetailsDialogButtons() throws Throwable {
|
||||
runOnFxThread(() -> {
|
||||
ManagedCertificate cert = createSampleCertificate();
|
||||
CertificateDetailsDialog dialog = new CertificateDetailsDialog(null, cert);
|
||||
layoutAndAssert(dialog.getStage(), 620, 500, "CertificateDetailsDialog");
|
||||
});
|
||||
}
|
||||
|
||||
@Test
|
||||
@DisplayName("FileSignDialog: botões com tamanho preferencial")
|
||||
void testFileSignDialogButtons() throws Throwable {
|
||||
runOnFxThread(() -> {
|
||||
CertificateManager certManager = CertificateManager.createDefault();
|
||||
SigningService signingService = new SigningService(certManager);
|
||||
FileSignDialog dialog = new FileSignDialog(
|
||||
null,
|
||||
"Assinar Arquivo",
|
||||
"*.*",
|
||||
SvgIcons.fileIcon(),
|
||||
certManager,
|
||||
signingService
|
||||
);
|
||||
layoutAndAssert(dialog.getStage(), 720, 500, "FileSignDialog");
|
||||
});
|
||||
}
|
||||
|
||||
@Test
|
||||
@DisplayName("LogsViewerDialog: botões Limpar, Exportar e Fechar com tamanho preferencial")
|
||||
void testLogsViewerDialogButtons() throws Throwable {
|
||||
runOnFxThread(() -> {
|
||||
LogsViewerDialog dialog = new LogsViewerDialog(null);
|
||||
layoutAndAssert(dialog.getStage(), 800, 520, "LogsViewerDialog");
|
||||
});
|
||||
}
|
||||
|
||||
@Test
|
||||
@DisplayName("TutorialDialog: botões de navegação e fechar com tamanho preferencial")
|
||||
void testTutorialDialogButtons() throws Throwable {
|
||||
runOnFxThread(() -> {
|
||||
TutorialDialog dialog = new TutorialDialog(null);
|
||||
layoutAndAssert(dialog.getStage(), 640, 480, "TutorialDialog");
|
||||
});
|
||||
}
|
||||
|
||||
@Test
|
||||
@DisplayName("XmlSignDialog: botões com tamanho preferencial")
|
||||
void testXmlSignDialogButtons() throws Throwable {
|
||||
runOnFxThread(() -> {
|
||||
CertificateManager certManager = CertificateManager.createDefault();
|
||||
XmlSignDialog dialog = new XmlSignDialog(null, certManager);
|
||||
layoutAndAssert(dialog.getStage(), 720, 500, "XmlSignDialog");
|
||||
});
|
||||
}
|
||||
|
||||
@Test
|
||||
@DisplayName("BatchSigningDialog: botões com tamanho preferencial")
|
||||
void testBatchSigningDialogButtons() throws Throwable {
|
||||
runOnFxThread(() -> {
|
||||
CertificateManager certManager = CertificateManager.createDefault();
|
||||
SigningService signingService = new SigningService(certManager);
|
||||
BatchSigningDialog dialog = new BatchSigningDialog(null, certManager, signingService);
|
||||
layoutAndAssert(dialog.getStage(), 760, 520, "BatchSigningDialog");
|
||||
});
|
||||
}
|
||||
|
||||
@Test
|
||||
@DisplayName("SealManagementDialog e SealDesignerDialog: botões com tamanho preferencial")
|
||||
void testSealDialogsButtons() throws Throwable {
|
||||
runOnFxThread(() -> {
|
||||
SealManagementDialog sealMgmt = new SealManagementDialog(null);
|
||||
layoutAndAssert(sealMgmt.getStage(), 700, 480, "SealManagementDialog");
|
||||
|
||||
SealDesignerDialog designer = new SealDesignerDialog(null, PdfSealThemeRegistry.getDefaultTheme(), saved -> {});
|
||||
layoutAndAssert(designer.getStage(), 880, 580, "SealDesignerDialog");
|
||||
});
|
||||
}
|
||||
|
||||
@Test
|
||||
@DisplayName("SignatureValidationDialog: botões com tamanho preferencial")
|
||||
void testSignatureValidationDialogButtons() throws Throwable {
|
||||
runOnFxThread(() -> {
|
||||
SignatureValidationDialog dialog = new SignatureValidationDialog(null);
|
||||
layoutAndAssert(dialog.getStage(), 680, 520, "SignatureValidationDialog");
|
||||
});
|
||||
}
|
||||
|
||||
@Test
|
||||
@DisplayName("PdfSignDialog e PdfCertificateSignDialog: botões com tamanho preferencial")
|
||||
void testPdfDialogsButtons() throws Throwable {
|
||||
runOnFxThread(() -> {
|
||||
File samplePdf = getOrCreateSamplePdf();
|
||||
CertificateManager certManager = CertificateManager.createDefault();
|
||||
PdfSigningService pdfSigningService = new PdfSigningService(certManager);
|
||||
|
||||
PdfSignDialog pdfSignDialog = new PdfSignDialog(null, certManager, samplePdf);
|
||||
layoutAndAssert(pdfSignDialog.getStage(), 980, 680, "PdfSignDialog");
|
||||
|
||||
PdfCertificateSignDialog.SealConfig config = new PdfCertificateSignDialog.SealConfig(
|
||||
true,
|
||||
PdfSealThemeRegistry.getDefaultTheme(),
|
||||
CpfDisplayMode.MASKED,
|
||||
true,
|
||||
"Assinado digitalmente",
|
||||
PdfSignDialog.PositionOption.BOTTOM_RIGHT,
|
||||
PdfSignDialog.PageOption.LAST_PAGE,
|
||||
false,
|
||||
null,
|
||||
null,
|
||||
null,
|
||||
"ICP-Brasil",
|
||||
"Brasília, DF",
|
||||
1.0
|
||||
);
|
||||
|
||||
PdfCertificateSignDialog certSignDialog = new PdfCertificateSignDialog(
|
||||
null,
|
||||
certManager,
|
||||
pdfSigningService,
|
||||
samplePdf,
|
||||
config,
|
||||
"Selo Padrão ICP-Brasil"
|
||||
);
|
||||
layoutAndAssert(certSignDialog.getStage(), 760, 520, "PdfCertificateSignDialog");
|
||||
});
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user