| 1 | using CascadeIDE.Views.Chat; |
| 2 | using CascadeIDE.Views.SkiaKit; |
| 3 | using SkiaSharp; |
| 4 | using Xunit; |
| 5 | |
| 6 | namespace CascadeIDE.Tests; |
| 7 | |
| 8 | public sealed class SkiaIntercomCommandDeckLayoutTests |
| 9 | { |
| 10 | [Fact] |
| 11 | public void Deck_popup_stays_inside_deck_not_above_composer_only_stack() |
| 12 | { |
| 13 | const float width = 480f; |
| 14 | const float bottom = 600f; |
| 15 | var deck = SkiaIntercomCommandDeckLayout.Compute( |
| 16 | width, |
| 17 | bottom, |
| 18 | showComposer: true, |
| 19 | showCommandLine: true, |
| 20 | commandLinePreview: "preview", |
| 21 | composerText: "hi", |
| 22 | showSlashPopup: true, |
| 23 | slashRowCount: 4); |
| 24 | |
| 25 | Assert.True(deck.HasDeck); |
| 26 | Assert.True(deck.DeckBounds.Bottom <= bottom + 0.01f); |
| 27 | Assert.True(deck.DeckBounds.Top >= deck.SlashPopupBounds.Top - 0.01f); |
| 28 | Assert.True(deck.SlashPopupBounds.Bottom <= deck.CommandLineBounds.Top + 0.01f); |
| 29 | Assert.True(deck.CommandLineBounds.Bottom <= deck.ComposerBounds.Top + 0.01f); |
| 30 | Assert.InRange(deck.TotalHeight, deck.DeckBounds.Height - 0.01f, deck.DeckBounds.Height + 0.01f); |
| 31 | } |
| 32 | |
| 33 | [Fact] |
| 34 | public void MeasureTotalHeight_matches_deck_layout_on_surface() |
| 35 | { |
| 36 | const float width = 420f; |
| 37 | const float bottom = 800f; |
| 38 | var measured = SkiaIntercomCommandDeckLayout.MeasureTotalHeight( |
| 39 | width, |
| 40 | showComposer: true, |
| 41 | showCommandLine: true, |
| 42 | commandLinePreview: null, |
| 43 | composerText: "/intercom anchor list", |
| 44 | showSlashPopup: true, |
| 45 | slashRowCount: 2); |
| 46 | var deck = SkiaIntercomCommandDeckLayout.Compute( |
| 47 | width, |
| 48 | bottom, |
| 49 | showComposer: true, |
| 50 | showCommandLine: true, |
| 51 | commandLinePreview: null, |
| 52 | composerText: "/intercom anchor list", |
| 53 | showSlashPopup: true, |
| 54 | slashRowCount: 2); |
| 55 | |
| 56 | Assert.Equal(measured, deck.TotalHeight, precision: 2); |
| 57 | Assert.Equal(bottom - measured, deck.DeckBounds.Top, precision: 2); |
| 58 | } |
| 59 | |
| 60 | [Fact] |
| 61 | public void Composer_layout_wrapper_includes_command_line_and_popup() |
| 62 | { |
| 63 | var width = 420f; |
| 64 | var composerOnly = SkiaIntercomComposerLayout.MeasureBottomChromeHeight( |
| 65 | showComposer: true, |
| 66 | showSlashPopup: false, |
| 67 | slashRowCount: 0, |
| 68 | composerText: "hello", |
| 69 | surfaceWidth: width); |
| 70 | var fullDeck = SkiaIntercomComposerLayout.MeasureBottomChromeHeight( |
| 71 | showComposer: true, |
| 72 | showSlashPopup: true, |
| 73 | slashRowCount: 3, |
| 74 | composerText: "hello", |
| 75 | surfaceWidth: width, |
| 76 | showCommandLine: true, |
| 77 | commandLinePreview: "x"); |
| 78 | |
| 79 | Assert.True(fullDeck > composerOnly); |
| 80 | } |
| 81 | } |
| 82 | |