Files
Terminal.Gui/UnitTests/MessageBoxTests.cs
BDisp ff1eb9bea1 Fixes #1979. MessageBox.Query not wrapping since 1.7.1 (#1995)
* Added MaxWidthLine into the TextFormatter class.

* Some more test line to better verifying the mainloop idle handlers.

* Fixes #1979. MessageBox.Query not wrapping since 1.7.1

* Added MessageBox unit tests.

* States a button centered issue on a lower fixed size.

* Fixed the centered button issue 4d0a4b6.
2022-09-14 18:11:12 -07:00

158 lines
5.6 KiB
C#

using System.Threading.Tasks;
using Xunit;
using Xunit.Abstractions;
using System.Text;
namespace Terminal.Gui.Views {
public class MessageBoxTests {
readonly ITestOutputHelper output;
public MessageBoxTests (ITestOutputHelper output)
{
this.output = output;
}
[Fact, AutoInitShutdown]
public void MessageBox_With_Empty_Size_Without_Buttons ()
{
var iterations = -1;
Application.Begin (Application.Top);
Application.Iteration += () => {
iterations++;
if (iterations == 0) {
MessageBox.Query ("Title", "Message");
Application.RequestStop ();
} else if (iterations == 1) {
Application.Top.Redraw (Application.Top.Bounds);
GraphViewTests.AssertDriverContentsWithFrameAre (@"
┌ Title ─────────────────────────────────────────┐
│ Message │
│ │
│ │
└────────────────────────────────────────────────┘
", output);
Application.RequestStop ();
}
};
Application.Run ();
}
[Fact, AutoInitShutdown]
public void MessageBox_With_Empty_Size_With_Button ()
{
var iterations = -1;
Application.Begin (Application.Top);
Application.Iteration += () => {
iterations++;
if (iterations == 0) {
StringBuilder aboutMessage = new StringBuilder ();
aboutMessage.AppendLine (@"A comprehensive sample library for");
aboutMessage.AppendLine (@"");
aboutMessage.AppendLine (@" _______ _ _ _____ _ ");
aboutMessage.AppendLine (@" |__ __| (_) | | / ____| (_) ");
aboutMessage.AppendLine (@" | | ___ _ __ _ __ ___ _ _ __ __ _| || | __ _ _ _ ");
aboutMessage.AppendLine (@" | |/ _ \ '__| '_ ` _ \| | '_ \ / _` | || | |_ | | | | | ");
aboutMessage.AppendLine (@" | | __/ | | | | | | | | | | | (_| | || |__| | |_| | | ");
aboutMessage.AppendLine (@" |_|\___|_| |_| |_| |_|_|_| |_|\__,_|_(_)_____|\__,_|_| ");
aboutMessage.AppendLine (@"");
aboutMessage.AppendLine (@"https://github.com/gui-cs/Terminal.Gui");
MessageBox.Query ("About UI Catalog", aboutMessage.ToString (), "_Ok");
Application.RequestStop ();
} else if (iterations == 1) {
Application.Top.Redraw (Application.Top.Bounds);
GraphViewTests.AssertDriverContentsWithFrameAre (@"
┌ About UI Catalog ──────────────────────────────────────────┐
│ A comprehensive sample library for │
│ │
│ _______ _ _ _____ _ │
│ |__ __| (_) | | / ____| (_) │
│ | | ___ _ __ _ __ ___ _ _ __ __ _| || | __ _ _ _ │
│ | |/ _ \ '__| '_ ` _ \| | '_ \ / _` | || | |_ | | | | | │
│ | | __/ | | | | | | | | | | | (_| | || |__| | |_| | | │
│ |_|\___|_| |_| |_| |_|_|_| |_|\__,_|_(_)_____|\__,_|_| │
│ │
│ https://github.com/gui-cs/Terminal.Gui │
│ │
│ [◦ Ok ◦] │
└────────────────────────────────────────────────────────────┘
", output);
Application.RequestStop ();
}
};
Application.Run ();
}
[Fact, AutoInitShutdown]
public void MessageBox_With_A_Lower_Fixed_Size ()
{
var iterations = -1;
Application.Begin (Application.Top);
Application.Iteration += () => {
iterations++;
if (iterations == 0) {
MessageBox.Query (7, 5, "Title", "Message", "_Ok");
Application.RequestStop ();
} else if (iterations == 1) {
Application.Top.Redraw (Application.Top.Bounds);
GraphViewTests.AssertDriverContentsWithFrameAre (@"
┌─────┐
│Messa│
│ ge │
│ Ok ◦│
└─────┘
", output);
Application.RequestStop ();
}
};
Application.Run ();
}
[Fact, AutoInitShutdown]
public void MessageBox_With_A_Enough_Fixed_Size ()
{
var iterations = -1;
Application.Begin (Application.Top);
Application.Iteration += () => {
iterations++;
if (iterations == 0) {
MessageBox.Query (11, 5, "Title", "Message", "_Ok");
Application.RequestStop ();
} else if (iterations == 1) {
Application.Top.Redraw (Application.Top.Bounds);
GraphViewTests.AssertDriverContentsWithFrameAre (@"
┌ Title ──┐
│ Message │
│ │
│[◦ Ok ◦] │
└─────────┘
", output);
Application.RequestStop ();
}
};
Application.Run ();
}
}
}