| 1 | using CascadeIDE.Views.Chat.Skia; |
| 2 | using SkiaSharp; |
| 3 | using Xunit; |
| 4 | |
| 5 | namespace CascadeIDE.Tests; |
| 6 | |
| 7 | public sealed class SkiaRichTextKitMarkdownTests |
| 8 | { |
| 9 | [Fact] |
| 10 | public void TryMeasure_inline_subset_returns_positive_height() |
| 11 | { |
| 12 | var layout = SkiaRichTextKitMarkdown.TryMeasure( |
| 13 | "a **bold** `code` *italic*", |
| 14 | maxWidth: 400f, |
| 15 | fontSize: 11f, |
| 16 | contentColor: SKColors.White, |
| 17 | codeColor: SKColors.LightGray, |
| 18 | maxBodyLines: int.MaxValue, |
| 19 | lineHeight: 16f); |
| 20 | |
| 21 | Assert.NotNull(layout); |
| 22 | Assert.True(layout.BodyHeight > 8f); |
| 23 | Assert.Equal("a **bold** `code` *italic*", layout.Body); |
| 24 | } |
| 25 | |
| 26 | [Fact] |
| 27 | public void Feed_bubble_uses_rich_text_layout() |
| 28 | { |
| 29 | var ctx = new SkiaChatMeasureContext(60, 480); |
| 30 | var spec = new SkiaChatBubbleSpec( |
| 31 | Title: "agent", |
| 32 | Body: "Hello **world**", |
| 33 | Footer: null, |
| 34 | Kind: SkiaChatBubbleKind.Feed, |
| 35 | FillRole: SkiaBubbleFillRole.MessageAssistant, |
| 36 | BodyTone: SkiaChatBodyTone.Normal, |
| 37 | IsPending: false, |
| 38 | IsSelected: false, |
| 39 | StartsBranch: false, |
| 40 | MessageIndex: 1); |
| 41 | |
| 42 | var metrics = SkiaChatBubbleRenderer.Measure(ctx, spec); |
| 43 | Assert.NotNull(metrics.RichTextBody); |
| 44 | Assert.True(SkiaChatBubbleRenderer.MeasureHeight(spec, metrics) > 20f); |
| 45 | } |
| 46 | |
| 47 | [Fact] |
| 48 | public void TryMeasureDocument_heading2_returns_positive_height() |
| 49 | { |
| 50 | var layout = SkiaRichTextKitMarkdown.TryMeasureDocument( |
| 51 | "## Title\n\nBody **bold**", |
| 52 | maxWidth: 400f, |
| 53 | baseFontSize: 11f, |
| 54 | contentColor: SKColors.White, |
| 55 | codeColor: SKColors.LightGray, |
| 56 | maxRows: 64, |
| 57 | lineHeight: 15f, |
| 58 | forwardHost: false); |
| 59 | |
| 60 | Assert.NotNull(layout); |
| 61 | Assert.True(layout.IsDocument); |
| 62 | Assert.True(layout.BodyHeight > 15f); |
| 63 | } |
| 64 | } |
| 65 | |