|
| 1 | +package com.aresstack.enterpriseai.ui.comic.bubble; |
| 2 | + |
| 3 | +import org.junit.Test; |
| 4 | + |
| 5 | +import javax.swing.BoxLayout; |
| 6 | +import javax.swing.JPanel; |
| 7 | +import javax.swing.JTextArea; |
| 8 | +import javax.swing.SwingUtilities; |
| 9 | +import java.awt.Component; |
| 10 | +import java.awt.Container; |
| 11 | + |
| 12 | +import static org.junit.Assert.assertTrue; |
| 13 | + |
| 14 | +/** Die gelbe Aktivitätsblase wächst mit ihren Zeilen: die letzte Zeile wird nie abgeschnitten. */ |
| 15 | +public class ActivityBubbleHeightTest { |
| 16 | + |
| 17 | + @Test |
| 18 | + public void everyLineOfTheActivityFitsWithAndWithoutProgressBar() throws Exception { |
| 19 | + SwingUtilities.invokeAndWait(new Runnable() { |
| 20 | + public void run() { |
| 21 | + AgentActivityBubblePanel bubble = new AgentActivityBubblePanel(BubbleSide.LEFT, |
| 22 | + BubblePalette.windowsPhoneInspired(), "Antwort wird vorbereitet", "Überlegt …"); |
| 23 | + bubble.setHeaderTimestamp(0L); |
| 24 | + bubble.setMaximumBubbleWidth(640); |
| 25 | + JPanel transcript = new JPanel(); |
| 26 | + transcript.setLayout(new BoxLayout(transcript, BoxLayout.Y_AXIS)); |
| 27 | + BubbleMessageRow row = new BubbleMessageRow(bubble, BubbleSide.LEFT); |
| 28 | + transcript.add(row); |
| 29 | + transcript.setSize(800, 2000); |
| 30 | + StringBuilder body = new StringBuilder("Erster Schritt"); |
| 31 | + try { |
| 32 | + for (int line = 2; line <= 8; line++) { |
| 33 | + body.append("\nSchritt ").append(line); |
| 34 | + for (String marker : new String[]{"", " [[bar:1/3]]"}) { |
| 35 | + bubble.updateActivity("Antwort wird vorbereitet", body + marker); |
| 36 | + layOut(transcript); |
| 37 | + JTextArea text = textOf(bubble); |
| 38 | + assertTrue(line + " Zeilen" + marker + ": Text " + text.getHeight() + " px, braucht " |
| 39 | + + text.getPreferredSize().height + " px", |
| 40 | + text.getHeight() >= text.getPreferredSize().height); |
| 41 | + } |
| 42 | + } |
| 43 | + } finally { |
| 44 | + bubble.stopAnimation(); |
| 45 | + } |
| 46 | + } |
| 47 | + }); |
| 48 | + } |
| 49 | + |
| 50 | + private static JTextArea textOf(Container bubble) { |
| 51 | + for (Component child : bubble.getComponents()) { |
| 52 | + if (child instanceof JTextArea) { |
| 53 | + return (JTextArea) child; |
| 54 | + } |
| 55 | + } |
| 56 | + throw new AssertionError("kein Text in der Blase"); |
| 57 | + } |
| 58 | + |
| 59 | + private static void layOut(Component component) { |
| 60 | + component.doLayout(); |
| 61 | + if (component instanceof Container) { |
| 62 | + for (Component child : ((Container) component).getComponents()) { |
| 63 | + layOut(child); |
| 64 | + } |
| 65 | + } |
| 66 | + } |
| 67 | +} |
0 commit comments