Browse Source

Trying to figure out aboutbox issue

Tig 1 year ago
parent
commit
6da8dab640
3 changed files with 75 additions and 46 deletions
  1. 40 31
      UICatalog/UICatalog.cs
  2. 7 0
      UnitTests/TestHelpers.cs
  3. 28 15
      UnitTests/Text/TextFormatterTests.cs

+ 40 - 31
UICatalog/UICatalog.cs

@@ -45,9 +45,8 @@ namespace UICatalog;
 ///         (https://github.com/gui-cs/Terminal.Gui/tree/master/UICatalog/README.md).
 ///     </para>
 /// </remarks>
-internal class UICatalogApp
+public class UICatalogApp
 {
-    private static StringBuilder? _aboutMessage;
     private static int _cachedCategoryIndex;
 
     // When a scenario is run, the main app is killed. These items
@@ -74,6 +73,30 @@ internal class UICatalogApp
     [JsonPropertyName ("UICatalog.StatusBar")]
     public static bool ShowStatusBar { get; set; } = true;
 
+    /// <summary>
+    /// Gets the message displayed in the About Box. `public` so it can be used from Unit tests.
+    /// </summary>
+    /// <returns></returns>
+    public static string GetAboutBoxMessage ()
+    {
+        StringBuilder msg = new ();
+        msg.AppendLine ($"UI Catalog: A comprehensive sample library for");
+        msg.AppendLine ();
+        msg.AppendLine (
+@" _______                  _             _   _____       _
+|__   __|                (_)           | | / ____|     (_)
+   | | ___ _ __ _ __ ___  _ _ __   __ _| || |  __ _   _ _
+   | |/ _ \ '__| '_ ` _ \| | '_ \ / _` | || | |_ | | | | |
+   | |  __/ |  | | | | | | | | | | (_| | || |__| | |_| | |
+   |_|\___|_|  |_| |_| |_|_|_| |_|\__,_|_(_)_____|\__,_|_|");
+        msg.AppendLine ();
+        msg.AppendLine (@"v2 - Pre-Alpha");
+        msg.AppendLine ();
+        msg.AppendLine (@"https://github.com/gui-cs/Terminal.Gui");
+
+        return msg.ToString ();
+    }
+
     private static void ConfigFileChanged (object sender, FileSystemEventArgs e)
     {
         if (Application.Top == null)
@@ -381,20 +404,6 @@ internal class UICatalogApp
             _themeMenuItems = CreateThemeMenuItems ();
             _themeMenuBarItem = new ("_Themes", _themeMenuItems);
 
-            _aboutMessage = new ();
-            _aboutMessage.AppendLine ($"UI Catalog: A comprehensive sample library for");
-            _aboutMessage.AppendLine (@"
- _______                  _             _   _____       _
-|__   __|                (_)           | | / ____|     (_)
-   | | ___ _ __ _ __ ___  _ _ __   __ _| || |  __ _   _ _
-   | |/ _ \ '__| '_ ` _ \| | '_ \ / _` | || | |_ | | | | |
-   | |  __/ |  | | | | | | | | | | (_| | || |__| | |_| | |
-   |_|\___|_|  |_| |_| |_|_|_| |_|\__,_|_(_)_____|\__,_|_|
-");
-            _aboutMessage.AppendLine (@"v2 - Pre-Alpha");
-            _aboutMessage.AppendLine (@"");
-            _aboutMessage.AppendLine (@"https://github.com/gui-cs/Terminal.Gui");
-
             MenuBar = new ()
             {
                 Menus =
@@ -437,7 +446,7 @@ internal class UICatalogApp
                                   "About UI Catalog",
                                   () => MessageBox.Query (
                                                           title: "",
-                                                          message: _aboutMessage!.ToString (),
+                                                          message: GetAboutBoxMessage (),
                                                           wrapMessage: false,
                                                           buttons: "_Ok"
                                                          ),
@@ -471,7 +480,7 @@ internal class UICatalogApp
                 };
                 statusBarShortcut.Accept += (sender, args) => { StatusBar.Visible = !StatusBar.Visible; };
 
-                ShForce16Colors = new()
+                ShForce16Colors = new ()
                 {
                     CommandView = new CheckBox
                     {
@@ -846,24 +855,24 @@ internal class UICatalogApp
             string GetDiagnosticsTitle (Enum diag)
             {
                 return Enum.GetName (_diagnosticFlags.GetType (), diag) switch
-                       {
-                           "Off" => OFF,
-                           "Ruler" => RULER,
-                           "Padding" => PADDING,
-                           "MouseEnter" => MOUSEENTER,
-                           _ => ""
-                       };
+                {
+                    "Off" => OFF,
+                    "Ruler" => RULER,
+                    "Padding" => PADDING,
+                    "MouseEnter" => MOUSEENTER,
+                    _ => ""
+                };
             }
 
             Enum GetDiagnosticsEnumValue (string title)
             {
                 return title switch
-                       {
-                           RULER => ViewDiagnosticFlags.Ruler,
-                           PADDING => ViewDiagnosticFlags.Padding,
-                           MOUSEENTER => ViewDiagnosticFlags.MouseEnter,
-                           _ => null!
-                       };
+                {
+                    RULER => ViewDiagnosticFlags.Ruler,
+                    PADDING => ViewDiagnosticFlags.Padding,
+                    MOUSEENTER => ViewDiagnosticFlags.MouseEnter,
+                    _ => null!
+                };
             }
 
             void SetDiagnosticsFlag (Enum diag, bool add)

+ 7 - 0
UnitTests/TestHelpers.cs

@@ -448,6 +448,13 @@ internal partial class TestHelpers
             expectedLook = expectedLook [..^Environment.NewLine.Length];
         }
 
+        // If test is about to fail show user what things looked like
+        if (!string.Equals (expectedLook, actualLook))
+        {
+            output?.WriteLine ("Expected:" + Environment.NewLine + expectedLook);
+            output?.WriteLine (" But Was:" + Environment.NewLine + actualLook);
+        }
+
         Assert.Equal (expectedLook, actualLook);
 
         return new (x > -1 ? x : 0, y > -1 ? y : 0, w > -1 ? w : 0, h > -1 ? h : 0);

+ 28 - 15
UnitTests/Text/TextFormatterTests.cs

@@ -7195,25 +7195,14 @@ B  ")]
     #endregion
 
     [Fact]
+    [SetupFakeDriver]
     public void UICatalog_AboutBox_Text ()
     {
-        StringBuilder _aboutMessage = new ();
-        _aboutMessage.AppendLine ($"UI Catalog: A comprehensive sample library for");
-        _aboutMessage.AppendLine (@"
- _______                  _             _   _____       _
-|__   __|                (_)           | | / ____|     (_)
-   | | ___ _ __ _ __ ___  _ _ __   __ _| || |  __ _   _ _
-   | |/ _ \ '__| '_ ` _ \| | '_ \ / _` | || | |_ | | | | |
-   | |  __/ |  | | | | | | | | | | (_| | || |__| | |_| | |
-   |_|\___|_|  |_| |_| |_|_|_| |_|\__,_|_(_)_____|\__,_|_|
-");
-        _aboutMessage.AppendLine (@"v2 - Pre-Alpha");
-        _aboutMessage.AppendLine (@"");
-        _aboutMessage.AppendLine (@"https://github.com/gui-cs/Terminal.Gui");
-
         TextFormatter tf = new ()
         {
-            Text = _aboutMessage.ToString(),
+            Text = UICatalog.UICatalogApp.GetAboutBoxMessage (),
+            Alignment = Alignment.Center,
+            VerticalAlignment = Alignment.Start,
             WordWrap = false,
             MultiLine = true,
             HotKeySpecifier = (Rune)0xFFFF
@@ -7221,5 +7210,29 @@ B  ")]
 
         Size tfSize = tf.FormatAndGetSize ();
         Assert.Equal (new Size (58, 13), tfSize);
+
+        ((FakeDriver)Application.Driver).SetBufferSize (tfSize.Width, tfSize.Height);
+
+        Application.Driver.FillRect (Application.Screen, (Rune)'*');
+        tf.Draw (Application.Screen, Attribute.Default, Attribute.Default);
+
+        string expectedText = """
+                              ******UI Catalog: A comprehensive sample library for******
+                              **********************************************************
+                               _______                  _             _   _____       _*
+                              |__   __|                (_)           | | / ____|     (_)
+                                 | | ___ _ __ _ __ ___  _ _ __   __ _| || |  __ _   _ _*
+                                 | |/ _ \ '__| '_ ` _ \| | '_ \ / _` | || | |_ | | | | |
+                                 | |  __/ |  | | | | | | | | | | (_| | || |__| | |_| | |
+                                 |_|\___|_|  |_| |_| |_|_|_| |_|\__,_|_(_)_____|\__,_|_|
+                              **********************************************************
+                              **********************v2 - Pre-Alpha**********************
+                              **********************************************************
+                              **********https://github.com/gui-cs/Terminal.Gui**********
+                              **********************************************************
+                              """;
+
+        TestHelpers.AssertDriverContentsAre (expectedText, _output);
+
     }
 }