| 1 | using CascadeIDE.Views.Chat; |
| 2 | using CascadeIDE.Views.SkiaKit; |
| 3 | using Xunit; |
| 4 | |
| 5 | namespace CascadeIDE.Tests; |
| 6 | |
| 7 | public sealed class SkiaIntercomComposerLayoutTests |
| 8 | { |
| 9 | private const float DefaultFontSize = 12f; |
| 10 | private const float DefaultLineHeight = 17f; |
| 11 | |
| 12 | [Fact] |
| 13 | public void MeasureBottomChrome_includes_composer_and_slash_popup() |
| 14 | { |
| 15 | var width = 420f; |
| 16 | var composerOnly = SkiaIntercomComposerLayout.MeasureBottomChromeHeight( |
| 17 | showComposer: true, |
| 18 | showSlashPopup: false, |
| 19 | slashRowCount: 0, |
| 20 | composerText: "hello", |
| 21 | surfaceWidth: width); |
| 22 | var minH = SkiaComposerStrip.MinHeightFor(DefaultLineHeight); |
| 23 | var maxH = SkiaComposerStrip.MaxHeightFor(DefaultLineHeight); |
| 24 | Assert.InRange(composerOnly, minH, maxH + 2); |
| 25 | |
| 26 | var withPopup = SkiaIntercomComposerLayout.MeasureBottomChromeHeight( |
| 27 | showComposer: true, |
| 28 | showSlashPopup: true, |
| 29 | slashRowCount: 3, |
| 30 | composerText: "hello", |
| 31 | surfaceWidth: width); |
| 32 | Assert.True(withPopup > composerOnly); |
| 33 | Assert.InRange(withPopup - composerOnly, SkiaPopupList.MeasureHeight(3), SkiaPopupList.MeasureHeight(3) + 8f); |
| 34 | } |
| 35 | |
| 36 | [Fact] |
| 37 | public void Composer_grows_with_multiline_text() |
| 38 | { |
| 39 | var width = 400f; |
| 40 | var min = SkiaComposerStrip.MeasureHeight("", null, width, DefaultFontSize, DefaultLineHeight); |
| 41 | var fourLines = SkiaComposerStrip.MeasureHeight( |
| 42 | "line one\nline two\nline three\nline four", |
| 43 | null, |
| 44 | width, |
| 45 | DefaultFontSize, |
| 46 | DefaultLineHeight); |
| 47 | Assert.Equal(SkiaComposerStrip.MinHeightFor(DefaultLineHeight), min); |
| 48 | Assert.True(fourLines > min); |
| 49 | } |
| 50 | |
| 51 | [Fact] |
| 52 | public void Composer_empty_uses_min_three_lines_height() |
| 53 | { |
| 54 | var height = SkiaComposerStrip.MeasureHeight("", null, 400f, DefaultFontSize, DefaultLineHeight); |
| 55 | Assert.Equal(SkiaComposerStrip.MinHeightFor(DefaultLineHeight), height); |
| 56 | Assert.True(height >= SkiaComposerStrip.VerticalPadding * 2 + SkiaComposerStrip.MinLines * DefaultLineHeight); |
| 57 | } |
| 58 | } |
| 59 | |