|
| 1 | +package com.demcha.testing.visual; |
| 2 | + |
| 3 | +import com.demcha.compose.GraphCompose; |
| 4 | +import com.demcha.compose.document.api.DocumentSession; |
| 5 | +import com.demcha.compose.document.style.DocumentInsets; |
| 6 | +import com.demcha.compose.document.theme.BusinessTheme; |
| 7 | +import com.demcha.testing.VisualTestOutputs; |
| 8 | +import org.junit.jupiter.api.Test; |
| 9 | + |
| 10 | +import java.nio.charset.StandardCharsets; |
| 11 | +import java.nio.file.Files; |
| 12 | +import java.nio.file.Path; |
| 13 | + |
| 14 | +import static org.assertj.core.api.Assertions.assertThat; |
| 15 | + |
| 16 | +/** |
| 17 | + * Personal sandbox / scratch test for manual GraphCompose API experimentation. |
| 18 | + * |
| 19 | + * <p>Renders a minimal document to |
| 20 | + * {@code target/visual-tests/develop/Develop.pdf}. Edit {@link #scratch()} |
| 21 | + * freely to try new helpers, layouts, theme tweaks, or upcoming v1.7+ APIs. |
| 22 | + * Open the rendered PDF in any viewer to see the result.</p> |
| 23 | + * |
| 24 | + * <p><b>Unicode safety</b>: until v1.6.2 ships (R1 glyph sanitizer), keep |
| 25 | + * to ASCII in the body. The current PDF font path crashes on any glyph |
| 26 | + * that Helvetica's WinAnsiEncoding cannot encode (arrows, dots, emoji). |
| 27 | + * After v1.6.2: replace ASCII placeholders with actual symbols freely.</p> |
| 28 | + * |
| 29 | + * <p>Run from repo root: |
| 30 | + * <pre>{@code |
| 31 | + * mvnw test -Dtest=DevelopTest -pl . |
| 32 | + * }</pre> |
| 33 | + * |
| 34 | + * <p>This file is intentionally committed as a working sandbox; rewrite the |
| 35 | + * body of {@link #scratch()} as needed — the only stable contract is that |
| 36 | + * the test produces a {@code Develop.pdf} starting with the {@code %PDF-} |
| 37 | + * header.</p> |
| 38 | + * |
| 39 | + * @author Artem Demchyshyn |
| 40 | + */ |
| 41 | +class DevelopTest { |
| 42 | + |
| 43 | + private static final BusinessTheme THEME = BusinessTheme.modern(); |
| 44 | + |
| 45 | + @Test |
| 46 | + void scratch() throws Exception { |
| 47 | + Path output = VisualTestOutputs.preparePdf("Develop", "develop"); |
| 48 | + |
| 49 | + try (DocumentSession document = GraphCompose.document() |
| 50 | + .pageSize(595, 842) |
| 51 | + .pageBackground(THEME.pageBackground()) |
| 52 | + .margin(DocumentInsets.of(28)) |
| 53 | + .create()) { |
| 54 | + |
| 55 | + document.pageFlow(page -> page |
| 56 | + .addSection("Hero", section -> section |
| 57 | + .softPanel(THEME.palette().surfaceMuted(), 10, 14) |
| 58 | + .accentLeft(THEME.palette().accent(), 4) |
| 59 | + .addParagraph(p -> p.text("DevelopTest") |
| 60 | + .textStyle(THEME.text().h1())) |
| 61 | + .addParagraph(p -> p.text( |
| 62 | + "Scratch space for manual API experiments. " |
| 63 | + + "Render -> open -> think -> iterate.") |
| 64 | + .textStyle(THEME.text().body()))) |
| 65 | + |
| 66 | + .addSection("Body", section -> section |
| 67 | + .addParagraph(p -> p.text( |
| 68 | + "Replace this body with anything you want to try. " |
| 69 | + + "After v1.6.2: emoji, dots, unicode are safe. " |
| 70 | + + "After v1.7+: .h1(), .addFieldRow(), .twoColumn(), " |
| 71 | + + ".addHeadingBar(), .ratingDots(), .pageTopBand().") |
| 72 | + .textStyle(THEME.text().body())))); |
| 73 | + |
| 74 | + Files.write(output, document.toPdfBytes()); |
| 75 | + } |
| 76 | + |
| 77 | + byte[] bytes = Files.readAllBytes(output); |
| 78 | + assertThat(bytes).isNotEmpty(); |
| 79 | + assertThat(new String(bytes, 0, 5, StandardCharsets.US_ASCII)).isEqualTo("%PDF-"); |
| 80 | + } |
| 81 | +} |
0 commit comments