Fixes #2469 - Revamp file structure and namespace (#2471)

* initial commit

* All tests pass

* Updated readme

* Revert "All tests pass"

This reverts commit 94ac462350.

* Revert "initial commit"

This reverts commit 36d92cc4e5.

* Moved Terminal.Gui files around

* Nuked .Graphs namespace

* Nuked .Graphs namespace

* Nuked .Trees namespace

* Nuked .Configuration namespace

* Nuked .Configuration namespace

* All tests pass

* tweaked tests

* removed unneeded usings

* re-enabled scrollview tests

* move scrollview test to ScrollViewTests

* Moved view navigation related tests to separate cs file

* Moved view scrollbarview related tests ScrollBarTestse

* Refactored View tests into smaller files

* Refactored driver tests

* Fixed a ton of BUGBUGs
This commit is contained in:
Tig
2023-04-06 10:09:21 -06:00
committed by GitHub
parent ec08c12162
commit 574ed8fec7
187 changed files with 6591 additions and 6541 deletions

View File

@@ -0,0 +1,790 @@
using System;
using System.Collections.Generic;
using System.Data;
using System.Linq;
using System.Threading.Tasks;
using Terminal.Gui;
using Xunit;
using System.Globalization;
using Xunit.Abstractions;
using NStack;
using static Terminal.Gui.Application;
namespace Terminal.Gui.DialogTests {
public class DialogTests {
readonly ITestOutputHelper output;
public DialogTests (ITestOutputHelper output)
{
this.output = output;
}
//[Fact]
//[AutoInitShutdown]
//public void Default_Has_Border ()
//{
// var d = (FakeDriver)Application.Driver;
// d.SetBufferSize (20, 5);
// Application.RunState runstate = null;
// var title = "Title";
// var btnText = "ok";
// var buttonRow = $"{d.VLine}{d.LeftBracket} {btnText} {d.RightBracket}{d.VLine}";
// var width = buttonRow.Length;
// var topRow = $"┌┤{title} {new string (d.HLine.ToString () [0], width - title.Length - 2)}├┐";
// var bottomRow = $"└{new string (d.HLine.ToString () [0], width - 2)}┘";
// var dlg = new Dialog (title, new Button (btnText));
// Application.Begin (dlg);
// TestHelpers.AssertDriverContentsWithFrameAre ($"{topRow}\n{buttonRow}\n{bottomRow}", output);
// Application.End (runstate);
//}
private (Application.RunState, Dialog) RunButtonTestDialog (string title, int width, Dialog.ButtonAlignments align, params Button [] btns)
{
var dlg = new Dialog (title, width, 1, btns) {
ButtonAlignment = align,
};
// Create with no top or bottom border to simplify testing button layout (no need to account for title etc..)
dlg.BorderFrame.Thickness = new Thickness (1, 0, 1, 0);
return (Application.Begin (dlg), dlg);
}
[Fact]
[AutoInitShutdown]
public void ButtonAlignment_One ()
{
var d = (FakeDriver)Application.Driver;
Application.RunState runstate = null;
var title = "1234";
// E.g "|[ ok ]|"
var btnText = "ok";
var buttonRow = $"{d.VLine} {d.LeftBracket} {btnText} {d.RightBracket} {d.VLine}";
var width = buttonRow.Length;
d.SetBufferSize (width, 1);
(runstate, var _) = RunButtonTestDialog (title, width, Dialog.ButtonAlignments.Center, new Button (btnText));
TestHelpers.AssertDriverContentsWithFrameAre ($"{buttonRow}", output);
Application.End (runstate);
// Justify
buttonRow = $"{d.VLine} {d.LeftBracket} {btnText} {d.RightBracket}{d.VLine}";
Assert.Equal (width, buttonRow.Length);
(runstate, var _) = RunButtonTestDialog (title, width, Dialog.ButtonAlignments.Justify, new Button (btnText));
TestHelpers.AssertDriverContentsWithFrameAre ($"{buttonRow}", output);
Application.End (runstate);
// Right
buttonRow = $"{d.VLine} {d.LeftBracket} {btnText} {d.RightBracket}{d.VLine}";
Assert.Equal (width, buttonRow.Length);
(runstate, var _) = RunButtonTestDialog (title, width, Dialog.ButtonAlignments.Right, new Button (btnText));
TestHelpers.AssertDriverContentsWithFrameAre ($"{buttonRow}", output);
Application.End (runstate);
// Left
buttonRow = $"{d.VLine}{d.LeftBracket} {btnText} {d.RightBracket} {d.VLine}";
Assert.Equal (width, buttonRow.Length);
(runstate, var _) = RunButtonTestDialog (title, width, Dialog.ButtonAlignments.Left, new Button (btnText));
TestHelpers.AssertDriverContentsWithFrameAre ($"{buttonRow}", output);
Application.End (runstate);
// Wider
buttonRow = $"{d.VLine} {d.LeftBracket} {btnText} {d.RightBracket} {d.VLine}";
width = buttonRow.Length;
d.SetBufferSize (width, 1);
(runstate, var _) = RunButtonTestDialog (title, width, Dialog.ButtonAlignments.Center, new Button (btnText));
TestHelpers.AssertDriverContentsWithFrameAre ($"{buttonRow}", output);
Application.End (runstate);
// Justify
buttonRow = $"{d.VLine} {d.LeftBracket} {btnText} {d.RightBracket}{d.VLine}";
Assert.Equal (width, buttonRow.Length);
(runstate, var _) = RunButtonTestDialog (title, width, Dialog.ButtonAlignments.Justify, new Button (btnText));
TestHelpers.AssertDriverContentsWithFrameAre ($"{buttonRow}", output);
Application.End (runstate);
// Right
buttonRow = $"{d.VLine} {d.LeftBracket} {btnText} {d.RightBracket}{d.VLine}";
Assert.Equal (width, buttonRow.Length);
(runstate, var _) = RunButtonTestDialog (title, width, Dialog.ButtonAlignments.Right, new Button (btnText));
TestHelpers.AssertDriverContentsWithFrameAre ($"{buttonRow}", output);
Application.End (runstate);
// Left
buttonRow = $"{d.VLine}{d.LeftBracket} {btnText} {d.RightBracket} {d.VLine}";
Assert.Equal (width, buttonRow.Length);
(runstate, var _) = RunButtonTestDialog (title, width, Dialog.ButtonAlignments.Left, new Button (btnText));
TestHelpers.AssertDriverContentsWithFrameAre ($"{buttonRow}", output);
Application.End (runstate);
}
[Fact]
[AutoInitShutdown]
public void ButtonAlignment_Two ()
{
Application.RunState runstate = null;
var d = (FakeDriver)Application.Driver;
var title = "1234";
// E.g "|[ yes ][ no ]|"
var btn1Text = "yes";
var btn1 = $"{d.LeftBracket} {btn1Text} {d.RightBracket}";
var btn2Text = "no";
var btn2 = $"{d.LeftBracket} {btn2Text} {d.RightBracket}";
var buttonRow = $@"{d.VLine} {btn1} {btn2} {d.VLine}";
var width = buttonRow.Length;
d.SetBufferSize (buttonRow.Length, 3);
(runstate, var _) = RunButtonTestDialog (title, width, Dialog.ButtonAlignments.Center, new Button (btn1Text), new Button (btn2Text));
TestHelpers.AssertDriverContentsWithFrameAre ($"{buttonRow}", output);
Application.End (runstate);
// Justify
buttonRow = $@"{d.VLine}{btn1} {btn2}{d.VLine}";
Assert.Equal (width, buttonRow.Length);
(runstate, var _) = RunButtonTestDialog (title, width, Dialog.ButtonAlignments.Justify, new Button (btn1Text), new Button (btn2Text));
TestHelpers.AssertDriverContentsWithFrameAre ($"{buttonRow}", output);
Application.End (runstate);
// Right
buttonRow = $@"{d.VLine} {btn1} {btn2}{d.VLine}";
Assert.Equal (width, buttonRow.Length);
(runstate, var _) = RunButtonTestDialog (title, width, Dialog.ButtonAlignments.Right, new Button (btn1Text), new Button (btn2Text));
TestHelpers.AssertDriverContentsWithFrameAre ($"{buttonRow}", output);
Application.End (runstate);
// Left
buttonRow = $@"{d.VLine}{btn1} {btn2} {d.VLine}";
Assert.Equal (width, buttonRow.Length);
(runstate, var _) = RunButtonTestDialog (title, width, Dialog.ButtonAlignments.Left, new Button (btn1Text), new Button (btn2Text));
TestHelpers.AssertDriverContentsWithFrameAre ($"{buttonRow}", output);
Application.End (runstate);
}
[Fact]
[AutoInitShutdown]
public void ButtonAlignment_Two_Hidden ()
{
Application.RunState runstate = null;
bool firstIteration = false;
var d = (FakeDriver)Application.Driver;
var title = "1234";
// E.g "|[ yes ][ no ]|"
var btn1Text = "yes";
var btn1 = $"{d.LeftBracket} {btn1Text} {d.RightBracket}";
var btn2Text = "no";
var btn2 = $"{d.LeftBracket} {btn2Text} {d.RightBracket}";
var buttonRow = $@"{d.VLine} {btn1} {btn2} {d.VLine}";
var width = buttonRow.Length;
d.SetBufferSize (buttonRow.Length, 3);
Dialog dlg = null;
Button button1, button2;
// Default (Center)
button1 = new Button (btn1Text);
button2 = new Button (btn2Text);
(runstate, dlg) = RunButtonTestDialog (title, width, Dialog.ButtonAlignments.Center, button1, button2);
button1.Visible = false;
Application.RunMainLoopIteration (ref runstate, true, ref firstIteration);
buttonRow = $@"{d.VLine} {btn2} {d.VLine}";
TestHelpers.AssertDriverContentsWithFrameAre ($"{buttonRow}", output);
Application.End (runstate);
// Justify
Assert.Equal (width, buttonRow.Length);
button1 = new Button (btn1Text);
button2 = new Button (btn2Text);
(runstate, dlg) = RunButtonTestDialog (title, width, Dialog.ButtonAlignments.Justify, button1, button2);
button1.Visible = false;
Application.RunMainLoopIteration (ref runstate, true, ref firstIteration);
buttonRow = $@"{d.VLine} {btn2}{d.VLine}";
TestHelpers.AssertDriverContentsWithFrameAre ($"{buttonRow}", output);
Application.End (runstate);
// Right
Assert.Equal (width, buttonRow.Length);
button1 = new Button (btn1Text);
button2 = new Button (btn2Text);
(runstate, dlg) = RunButtonTestDialog (title, width, Dialog.ButtonAlignments.Right, button1, button2);
button1.Visible = false;
Application.RunMainLoopIteration (ref runstate, true, ref firstIteration);
TestHelpers.AssertDriverContentsWithFrameAre ($"{buttonRow}", output);
Application.End (runstate);
// Left
Assert.Equal (width, buttonRow.Length);
button1 = new Button (btn1Text);
button2 = new Button (btn2Text);
(runstate, dlg) = RunButtonTestDialog (title, width, Dialog.ButtonAlignments.Left, button1, button2);
button1.Visible = false;
Application.RunMainLoopIteration (ref runstate, true, ref firstIteration);
buttonRow = $@"{d.VLine} {btn2} {d.VLine}";
TestHelpers.AssertDriverContentsWithFrameAre ($"{buttonRow}", output);
Application.End (runstate);
}
[Fact]
[AutoInitShutdown]
public void ButtonAlignment_Three ()
{
Application.RunState runstate = null;
var d = (FakeDriver)Application.Driver;
var title = "1234";
// E.g "|[ yes ][ no ][ maybe ]|"
var btn1Text = "yes";
var btn1 = $"{d.LeftBracket} {btn1Text} {d.RightBracket}";
var btn2Text = "no";
var btn2 = $"{d.LeftBracket} {btn2Text} {d.RightBracket}";
var btn3Text = "maybe";
var btn3 = $"{d.LeftBracket} {btn3Text} {d.RightBracket}";
var buttonRow = $@"{d.VLine} {btn1} {btn2} {btn3} {d.VLine}";
var width = buttonRow.Length;
d.SetBufferSize (buttonRow.Length, 3);
(runstate, var _) = RunButtonTestDialog (title, width, Dialog.ButtonAlignments.Center, new Button (btn1Text), new Button (btn2Text), new Button (btn3Text));
TestHelpers.AssertDriverContentsWithFrameAre ($"{buttonRow}", output);
Application.End (runstate);
// Justify
buttonRow = $@"{d.VLine}{btn1} {btn2} {btn3}{d.VLine}";
Assert.Equal (width, buttonRow.Length);
(runstate, var _) = RunButtonTestDialog (title, width, Dialog.ButtonAlignments.Justify, new Button (btn1Text), new Button (btn2Text), new Button (btn3Text));
TestHelpers.AssertDriverContentsWithFrameAre ($"{buttonRow}", output);
Application.End (runstate);
// Right
buttonRow = $@"{d.VLine} {btn1} {btn2} {btn3}{d.VLine}";
Assert.Equal (width, buttonRow.Length);
(runstate, var _) = RunButtonTestDialog (title, width, Dialog.ButtonAlignments.Right, new Button (btn1Text), new Button (btn2Text), new Button (btn3Text));
TestHelpers.AssertDriverContentsWithFrameAre ($"{buttonRow}", output);
Application.End (runstate);
// Left
buttonRow = $@"{d.VLine}{btn1} {btn2} {btn3} {d.VLine}";
Assert.Equal (width, buttonRow.Length);
(runstate, var _) = RunButtonTestDialog (title, width, Dialog.ButtonAlignments.Left, new Button (btn1Text), new Button (btn2Text), new Button (btn3Text));
TestHelpers.AssertDriverContentsWithFrameAre ($"{buttonRow}", output);
Application.End (runstate);
}
[Fact]
[AutoInitShutdown]
public void ButtonAlignment_Four ()
{
Application.RunState runstate = null;
var d = (FakeDriver)Application.Driver;
var title = "1234";
// E.g "|[ yes ][ no ][ maybe ]|"
var btn1Text = "yes";
var btn1 = $"{d.LeftBracket} {btn1Text} {d.RightBracket}";
var btn2Text = "no";
var btn2 = $"{d.LeftBracket} {btn2Text} {d.RightBracket}";
var btn3Text = "maybe";
var btn3 = $"{d.LeftBracket} {btn3Text} {d.RightBracket}";
var btn4Text = "never";
var btn4 = $"{d.LeftBracket} {btn4Text} {d.RightBracket}";
var buttonRow = $"{d.VLine} {btn1} {btn2} {btn3} {btn4} {d.VLine}";
var width = buttonRow.Length;
d.SetBufferSize (buttonRow.Length, 3);
// Default - Center
(runstate, var _) = RunButtonTestDialog (title, width, Dialog.ButtonAlignments.Center, new Button (btn1Text), new Button (btn2Text), new Button (btn3Text), new Button (btn4Text));
TestHelpers.AssertDriverContentsWithFrameAre ($"{buttonRow}", output);
Application.End (runstate);
// Justify
buttonRow = $"{d.VLine}{btn1} {btn2} {btn3} {btn4}{d.VLine}";
Assert.Equal (width, buttonRow.Length);
(runstate, var _) = RunButtonTestDialog (title, width, Dialog.ButtonAlignments.Justify, new Button (btn1Text), new Button (btn2Text), new Button (btn3Text), new Button (btn4Text));
TestHelpers.AssertDriverContentsWithFrameAre ($"{buttonRow}", output);
Application.End (runstate);
// Right
buttonRow = $"{d.VLine} {btn1} {btn2} {btn3} {btn4}{d.VLine}";
Assert.Equal (width, buttonRow.Length);
(runstate, var _) = RunButtonTestDialog (title, width, Dialog.ButtonAlignments.Right, new Button (btn1Text), new Button (btn2Text), new Button (btn3Text), new Button (btn4Text));
TestHelpers.AssertDriverContentsWithFrameAre ($"{buttonRow}", output);
Application.End (runstate);
// Left
buttonRow = $"{d.VLine}{btn1} {btn2} {btn3} {btn4} {d.VLine}";
Assert.Equal (width, buttonRow.Length);
(runstate, var _) = RunButtonTestDialog (title, width, Dialog.ButtonAlignments.Left, new Button (btn1Text), new Button (btn2Text), new Button (btn3Text), new Button (btn4Text));
TestHelpers.AssertDriverContentsWithFrameAre ($"{buttonRow}", output);
Application.End (runstate);
}
[Fact]
[AutoInitShutdown]
public void ButtonAlignment_Four_On_Smaller_Width ()
{
Application.RunState runstate = null;
var d = (FakeDriver)Application.Driver;
var title = "1234";
// E.g "|[ yes ][ no ][ maybe ][ never ]|"
var btn1Text = "yes";
var btn1 = $"{d.LeftBracket} {btn1Text} {d.RightBracket}";
var btn2Text = "no";
var btn2 = $"{d.LeftBracket} {btn2Text} {d.RightBracket}";
var btn3Text = "maybe";
var btn3 = $"{d.LeftBracket} {btn3Text} {d.RightBracket}";
var btn4Text = "never";
var btn4 = $"{d.LeftBracket} {btn4Text} {d.RightBracket}";
var buttonRow = $"{d.VLine} {btn1} {btn2} {btn3} {btn4} {d.VLine}";
var width = buttonRow.Length;
d.SetBufferSize (30, 1);
// Default - Center
buttonRow = $"yes ] {btn2} {btn3} [ never";
Assert.NotEqual (width, buttonRow.Length);
(runstate, var _) = RunButtonTestDialog (title, width, Dialog.ButtonAlignments.Center, new Button (btn1Text), new Button (btn2Text), new Button (btn3Text), new Button (btn4Text));
TestHelpers.AssertDriverContentsWithFrameAre ($"{buttonRow}", output);
Application.End (runstate);
// Justify
buttonRow = $"es ] {btn2} {btn3} [ neve";
Assert.NotEqual (width, buttonRow.Length);
(runstate, var _) = RunButtonTestDialog (title, width, Dialog.ButtonAlignments.Justify, new Button (btn1Text), new Button (btn2Text), new Button (btn3Text), new Button (btn4Text));
TestHelpers.AssertDriverContentsWithFrameAre ($"{buttonRow}", output); Application.End (runstate);
// Right
buttonRow = $" yes ] {btn2} {btn3} [ neve";
Assert.NotEqual (width, buttonRow.Length);
(runstate, var _) = RunButtonTestDialog (title, width, Dialog.ButtonAlignments.Right, new Button (btn1Text), new Button (btn2Text), new Button (btn3Text), new Button (btn4Text));
TestHelpers.AssertDriverContentsWithFrameAre ($"{buttonRow}", output); Application.End (runstate);
// Left
buttonRow = $"es ] {btn2} {btn3} [ never";
Assert.NotEqual (width, buttonRow.Length);
(runstate, var _) = RunButtonTestDialog (title, width, Dialog.ButtonAlignments.Left, new Button (btn1Text), new Button (btn2Text), new Button (btn3Text), new Button (btn4Text));
TestHelpers.AssertDriverContentsWithFrameAre ($"{buttonRow}", output); Application.End (runstate);
}
[Fact]
[AutoInitShutdown]
public void ButtonAlignment_Four_Wider ()
{
Application.RunState runstate = null;
var d = (FakeDriver)Application.Driver;
var title = "1234";
// E.g "|[ yes ][ no ][ maybe ]|"
var btn1Text = "yes";
var btn1 = $"{d.LeftBracket} {btn1Text} {d.RightBracket}";
var btn2Text = "no";
var btn2 = $"{d.LeftBracket} {btn2Text} {d.RightBracket}";
var btn3Text = "你你你你你"; // This is a wide char
var btn3 = $"{d.LeftBracket} {btn3Text} {d.RightBracket}";
// Requires a Nerd Font
var btn4Text = "\uE36E\uE36F\uE370\uE371\uE372\uE373";
var btn4 = $"{d.LeftBracket} {btn4Text} {d.RightBracket}";
// Note extra spaces to make dialog even wider
// 123456 123456
var buttonRow = $"{d.VLine} {btn1} {btn2} {btn3} {btn4} {d.VLine}";
var width = ustring.Make (buttonRow).ConsoleWidth;
d.SetBufferSize (width, 3);
// Default - Center
(runstate, var _) = RunButtonTestDialog (title, width, Dialog.ButtonAlignments.Center, new Button (btn1Text), new Button (btn2Text), new Button (btn3Text), new Button (btn4Text));
TestHelpers.AssertDriverContentsWithFrameAre ($"{buttonRow}", output);
Application.End (runstate);
// Justify
buttonRow = $"{d.VLine}{btn1} {btn2} {btn3} {btn4}{d.VLine}";
Assert.Equal (width, ustring.Make (buttonRow).ConsoleWidth);
(runstate, var _) = RunButtonTestDialog (title, width, Dialog.ButtonAlignments.Justify, new Button (btn1Text), new Button (btn2Text), new Button (btn3Text), new Button (btn4Text));
TestHelpers.AssertDriverContentsWithFrameAre ($"{buttonRow}", output);
Application.End (runstate);
// Right
buttonRow = $"{d.VLine} {btn1} {btn2} {btn3} {btn4}{d.VLine}";
Assert.Equal (width, ustring.Make (buttonRow).ConsoleWidth);
(runstate, var _) = RunButtonTestDialog (title, width, Dialog.ButtonAlignments.Right, new Button (btn1Text), new Button (btn2Text), new Button (btn3Text), new Button (btn4Text));
TestHelpers.AssertDriverContentsWithFrameAre ($"{buttonRow}", output);
Application.End (runstate);
// Left
buttonRow = $"{d.VLine}{btn1} {btn2} {btn3} {btn4} {d.VLine}";
Assert.Equal (width, ustring.Make (buttonRow).ConsoleWidth);
(runstate, var _) = RunButtonTestDialog (title, width, Dialog.ButtonAlignments.Left, new Button (btn1Text), new Button (btn2Text), new Button (btn3Text), new Button (btn4Text));
TestHelpers.AssertDriverContentsWithFrameAre ($"{buttonRow}", output);
Application.End (runstate);
}
[Fact]
[AutoInitShutdown]
public void ButtonAlignment_Four_WideOdd ()
{
Application.RunState runstate = null;
var d = (FakeDriver)Application.Driver;
var title = "1234";
// E.g "|[ yes ][ no ][ maybe ]|"
var btn1Text = "really long button 1";
var btn1 = $"{d.LeftBracket} {btn1Text} {d.RightBracket}";
var btn2Text = "really long button 2";
var btn2 = $"{d.LeftBracket} {btn2Text} {d.RightBracket}";
var btn3Text = "really long button 3";
var btn3 = $"{d.LeftBracket} {btn3Text} {d.RightBracket}";
var btn4Text = "really long button 44"; // 44 is intentional to make length different than rest
var btn4 = $"{d.LeftBracket} {btn4Text} {d.RightBracket}";
// Note extra spaces to make dialog even wider
// 123456 1234567
var buttonRow = $"{d.VLine} {btn1} {btn2} {btn3} {btn4} {d.VLine}";
var width = buttonRow.Length;
d.SetBufferSize (buttonRow.Length, 1);
// Default - Center
(runstate, var _) = RunButtonTestDialog (title, width, Dialog.ButtonAlignments.Center, new Button (btn1Text), new Button (btn2Text), new Button (btn3Text), new Button (btn4Text));
TestHelpers.AssertDriverContentsWithFrameAre ($"{buttonRow}", output);
Application.End (runstate);
// Justify
buttonRow = $"{d.VLine}{btn1} {btn2} {btn3} {btn4}{d.VLine}";
Assert.Equal (width, buttonRow.Length);
(runstate, var _) = RunButtonTestDialog (title, width, Dialog.ButtonAlignments.Justify, new Button (btn1Text), new Button (btn2Text), new Button (btn3Text), new Button (btn4Text));
TestHelpers.AssertDriverContentsWithFrameAre ($"{buttonRow}", output);
Application.End (runstate);
// Right
buttonRow = $"{d.VLine} {btn1} {btn2} {btn3} {btn4}{d.VLine}";
Assert.Equal (width, buttonRow.Length);
(runstate, var _) = RunButtonTestDialog (title, width, Dialog.ButtonAlignments.Right, new Button (btn1Text), new Button (btn2Text), new Button (btn3Text), new Button (btn4Text));
TestHelpers.AssertDriverContentsWithFrameAre ($"{buttonRow}", output);
Application.End (runstate);
// Left
buttonRow = $"{d.VLine}{btn1} {btn2} {btn3} {btn4} {d.VLine}";
Assert.Equal (width, buttonRow.Length);
(runstate, var _) = RunButtonTestDialog (title, width, Dialog.ButtonAlignments.Left, new Button (btn1Text), new Button (btn2Text), new Button (btn3Text), new Button (btn4Text));
TestHelpers.AssertDriverContentsWithFrameAre ($"{buttonRow}", output);
Application.End (runstate);
}
[Fact]
[AutoInitShutdown]
public void Zero_Buttons_Works ()
{
Application.RunState runstate = null;
var d = (FakeDriver)Application.Driver;
var title = "1234";
var buttonRow = $"{d.VLine} {d.VLine}";
var width = buttonRow.Length;
d.SetBufferSize (buttonRow.Length, 3);
(runstate, var _) = RunButtonTestDialog (title, width, Dialog.ButtonAlignments.Center, null);
TestHelpers.AssertDriverContentsWithFrameAre ($"{buttonRow}", output);
Application.End (runstate);
}
[Fact]
[AutoInitShutdown]
public void One_Button_Works ()
{
Application.RunState runstate = null;
var d = (FakeDriver)Application.Driver;
var title = "1234";
var btnText = "ok";
var buttonRow = $"{d.VLine} {d.LeftBracket} {btnText} {d.RightBracket} {d.VLine}";
var width = buttonRow.Length;
d.SetBufferSize (buttonRow.Length, 3);
(runstate, var _) = RunButtonTestDialog (title, width, Dialog.ButtonAlignments.Center, new Button (btnText));
TestHelpers.AssertDriverContentsWithFrameAre ($"{buttonRow}", output);
Application.End (runstate);
}
[Fact]
[AutoInitShutdown]
public void Add_Button_Works ()
{
Application.RunState runstate = null;
var d = (FakeDriver)Application.Driver;
var title = "1234";
var btn1Text = "yes";
var btn1 = $"{d.LeftBracket} {btn1Text} {d.RightBracket}";
var btn2Text = "no";
var btn2 = $"{d.LeftBracket} {btn2Text} {d.RightBracket}";
// We test with one button first, but do this to get the width right for 2
var width = $@"{d.VLine} {btn1} {btn2} {d.VLine}".Length;
d.SetBufferSize (width, 1);
// Default (center)
var dlg = new Dialog (title, width, 1, new Button (btn1Text)) { ButtonAlignment = Dialog.ButtonAlignments.Center };
// Create with no top or bottom border to simplify testing button layout (no need to account for title etc..)
dlg.BorderFrame.Thickness = new Thickness (1, 0, 1, 0);
runstate = Application.Begin (dlg);
var buttonRow = $"{d.VLine} {btn1} {d.VLine}";
TestHelpers.AssertDriverContentsWithFrameAre ($"{buttonRow}", output);
// Now add a second button
buttonRow = $"{d.VLine} {btn1} {btn2} {d.VLine}";
dlg.AddButton (new Button (btn2Text));
bool first = false;
Application.RunMainLoopIteration (ref runstate, true, ref first);
TestHelpers.AssertDriverContentsWithFrameAre ($"{buttonRow}", output);
Application.End (runstate);
// Justify
dlg = new Dialog (title, width, 1, new Button (btn1Text)) { ButtonAlignment = Dialog.ButtonAlignments.Justify };
// Create with no top or bottom border to simplify testing button layout (no need to account for title etc..)
dlg.BorderFrame.Thickness = new Thickness (1, 0, 1, 0);
runstate = Application.Begin (dlg);
buttonRow = $"{d.VLine} {btn1}{d.VLine}";
TestHelpers.AssertDriverContentsWithFrameAre ($"{buttonRow}", output);
// Now add a second button
buttonRow = $"{d.VLine}{btn1} {btn2}{d.VLine}";
dlg.AddButton (new Button (btn2Text));
first = false;
Application.RunMainLoopIteration (ref runstate, true, ref first);
TestHelpers.AssertDriverContentsWithFrameAre ($"{buttonRow}", output);
Application.End (runstate);
// Right
dlg = new Dialog (title, width, 1, new Button (btn1Text)) { ButtonAlignment = Dialog.ButtonAlignments.Right };
// Create with no top or bottom border to simplify testing button layout (no need to account for title etc..)
dlg.BorderFrame.Thickness = new Thickness (1, 0, 1, 0);
runstate = Application.Begin (dlg);
buttonRow = $"{d.VLine}{new string (' ', width - btn1.Length - 2)}{btn1}{d.VLine}";
TestHelpers.AssertDriverContentsWithFrameAre ($"{buttonRow}", output);
// Now add a second button
buttonRow = $"{d.VLine} {btn1} {btn2}{d.VLine}";
dlg.AddButton (new Button (btn2Text));
first = false;
Application.RunMainLoopIteration (ref runstate, true, ref first);
TestHelpers.AssertDriverContentsWithFrameAre ($"{buttonRow}", output);
Application.End (runstate);
// Left
dlg = new Dialog (title, width, 1, new Button (btn1Text)) { ButtonAlignment = Dialog.ButtonAlignments.Left };
// Create with no top or bottom border to simplify testing button layout (no need to account for title etc..)
dlg.BorderFrame.Thickness = new Thickness (1, 0, 1, 0);
runstate = Application.Begin (dlg);
buttonRow = $"{d.VLine}{btn1}{new string (' ', width - btn1.Length - 2)}{d.VLine}";
TestHelpers.AssertDriverContentsWithFrameAre ($"{buttonRow}", output);
// Now add a second button
buttonRow = $"{d.VLine}{btn1} {btn2} {d.VLine}";
dlg.AddButton (new Button (btn2Text));
first = false;
Application.RunMainLoopIteration (ref runstate, true, ref first);
TestHelpers.AssertDriverContentsWithFrameAre ($"{buttonRow}", output);
Application.End (runstate);
}
[Fact]
[AutoInitShutdown]
public void FileDialog_FileSystemWatcher ()
{
for (int i = 0; i < 8; i++) {
var fd = new FileDialog ();
fd.Ready += (s, e) => Application.RequestStop ();
Application.Run (fd);
}
}
[Fact, AutoInitShutdown]
public void Dialog_Opened_From_Another_Dialog ()
{
var btn1 = new Button ("press me 1");
Button btn2 = null;
Button btn3 = null;
string expected = null;
btn1.Clicked += (s, e) => {
btn2 = new Button ("Show Sub");
btn3 = new Button ("Close");
btn3.Clicked += (s, e) => Application.RequestStop ();
btn2.Clicked += (s, e) => { MessageBox.Query ("hey", "ya", "ok"); };
var dlg = new Dialog ("Hey", btn2, btn3);
Application.Run (dlg);
};
var iterations = -1;
Application.Iteration += () => {
iterations++;
if (iterations == 0) {
Assert.True (btn1.ProcessKey (new KeyEvent (Key.Enter, new KeyModifiers ())));
} else if (iterations == 1) {
expected = @"
┌┤Hey├─────────────────────────────────────────────────────────────┐
│ │
│ │
│ │
│ │
│ │
│ │
│ │
│ │
│ │
│ │
│ │
│ │
│ │
│ │
│ │
│ │
│ │
│ │
│ [ Show Sub ] [ Close ] │
└──────────────────────────────────────────────────────────────────┘";
TestHelpers.AssertDriverContentsWithFrameAre (expected, output);
Assert.True (btn2.ProcessKey (new KeyEvent (Key.Enter, new KeyModifiers ())));
} else if (iterations == 2) {
TestHelpers.AssertDriverContentsWithFrameAre (@"
┌┤Hey├─────────────────────────────────────────────────────────────┐
│ │
│ │
│ │
│ │
│ │
│ │
│ │
│ ┌┤hey├─────────────────────────────────────────┐ │
│ │ ya │ │
│ │ │ │
│ │ [◦ ok ◦] │ │
│ └──────────────────────────────────────────────┘ │
│ │
│ │
│ │
│ │
│ │
│ │
│ [ Show Sub ] [ Close ] │
└──────────────────────────────────────────────────────────────────┘", output);
Assert.True (Application.Current.ProcessKey (new KeyEvent (Key.Enter, new KeyModifiers ())));
} else if (iterations == 3) {
TestHelpers.AssertDriverContentsWithFrameAre (expected, output);
Assert.True (btn3.ProcessKey (new KeyEvent (Key.Enter, new KeyModifiers ())));
} else if (iterations == 4) {
TestHelpers.AssertDriverContentsWithFrameAre ("", output);
Application.RequestStop ();
}
};
Application.Run ();
Application.Shutdown ();
Assert.Equal (4, iterations);
}
[Fact, AutoInitShutdown]
public void Dialog_In_Window_With_Size_One_Button_Aligns ()
{
((FakeDriver)Application.Driver).SetBufferSize (20, 5);
var win = new Window ();
int iterations = 0;
Application.Iteration += () => {
if (++iterations > 2) {
Application.RequestStop ();
}
};
win.Loaded += (s, a) => {
var dlg = new Dialog ("Test", 18, 3, new Button ("Ok"));
dlg.Loaded += (s, a) => {
Application.Refresh ();
var expected = @"
┌──────────────────┐
│┌┤Test├──────────┐│
││ [ Ok ] ││
│└────────────────┘│
└──────────────────┘";
_ = TestHelpers.AssertDriverContentsWithFrameAre (expected, output);
};
Application.Run (dlg);
};
Application.Run (win);
}
// [Theory, AutoInitShutdown]
// [InlineData (5)]
// //[InlineData (6)]
// //[InlineData (7)]
// //[InlineData (8)]
// //[InlineData (9)]
// public void Dialog_In_Window_Without_Size_One_Button_Aligns (int height)
// {
// ((FakeDriver)Application.Driver).SetBufferSize (20, height);
// var win = new Window ();
// Application.Iteration += () => {
// var dlg = new Dialog ("Test", new Button ("Ok"));
// dlg.LayoutComplete += (s, a) => {
// Application.Refresh ();
// // BUGBUG: This seems wrong; is it a bug in Dim.Percent(85)??
// var expected = @"
//┌┌┤Test├─────────┐─┐
//││ │ │
//││ [ Ok ] │ │
//│└───────────────┘ │
//└──────────────────┘";
// _ = TestHelpers.AssertDriverContentsWithFrameAre (expected, output);
// dlg.RequestStop ();
// win.RequestStop ();
// };
// Application.Run (dlg);
// };
// Application.Run (win);
// Application.Shutdown ();
// }
}
}

View File

@@ -0,0 +1,356 @@
using System.Threading.Tasks;
using Xunit;
using Xunit.Abstractions;
using System.Text;
using Terminal.Gui;
namespace Terminal.Gui.DialogTests {
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.Refresh ();
TestHelpers.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) {
var 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.Refresh ();
TestHelpers.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_Smaller_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.Refresh ();
TestHelpers.AssertDriverContentsWithFrameAre (@"
┌┤Tit├┐
│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.Refresh ();
TestHelpers.AssertDriverContentsWithFrameAre (@"
┌┤Title├──┐
│ Message │
│ │
│[◦ Ok ◦] │
└─────────┘
", output);
Application.RequestStop ();
}
};
Application.Run ();
}
[Fact, AutoInitShutdown]
public void MessageBox_With_A_Label_Without_Spaces_WrapMessagge_True ()
{
var iterations = -1;
Application.Begin (Application.Top);
Application.Iteration += () => {
iterations++;
if (iterations == 0) {
MessageBox.Query ("mywindow", new string ('f', 2000), "ok");
Application.RequestStop ();
} else if (iterations == 1) {
Application.Refresh ();
TestHelpers.AssertDriverContentsWithFrameAre (@"
┌┤mywindow├────────────────────────────────────────────────────────────────────┐
│ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff│
│ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff│
│ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff│
│ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff│
│ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff│
│ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff│
│ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff│
│ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff│
│ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff│
│ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff│
│ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff│
│ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff│
│ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff│
│ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff│
│ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff│
│ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff│
│ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff│
│ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff│
│ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff│
│ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff│
│ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff│
│ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff│
│ [◦ ok ◦] │
└──────────────────────────────────────────────────────────────────────────────┘", output);
Application.RequestStop ();
}
};
Application.Run ();
}
[Fact, AutoInitShutdown]
public void MessageBox_With_A_Label_With_Spaces_WrapMessagge_True ()
{
var iterations = -1;
Application.Begin (Application.Top);
Application.Iteration += () => {
iterations++;
if (iterations == 0) {
var sb = new StringBuilder ();
for (int i = 0; i < 1000; i++)
sb.Append ("ff ");
MessageBox.Query ("mywindow", sb.ToString (), "ok");
Application.RequestStop ();
} else if (iterations == 1) {
Application.Refresh ();
TestHelpers.AssertDriverContentsWithFrameAre (@"
┌┤mywindow├────────────────────────────────────────────────────────────────────┐
│ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff │
│ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff │
│ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff │
│ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff │
│ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff │
│ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff │
│ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff │
│ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff │
│ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff │
│ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff │
│ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff │
│ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff │
│ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff │
│ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff │
│ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff │
│ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff │
│ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff │
│ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff │
│ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff │
│ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff │
│ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff │
│ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff │
│ [◦ ok ◦] │
└──────────────────────────────────────────────────────────────────────────────┘", output);
Application.RequestStop ();
}
};
Application.Run ();
}
[Fact, AutoInitShutdown]
public void MessageBox_With_A_Label_Without_Spaces_WrapMessagge_False ()
{
var iterations = -1;
Application.Begin (Application.Top);
Application.Iteration += () => {
iterations++;
if (iterations == 0) {
MessageBox.Query ("mywindow", new string ('f', 2000), 0, false, "ok");
Application.RequestStop ();
} else if (iterations == 1) {
Application.Refresh ();
TestHelpers.AssertDriverContentsWithFrameAre (@"
────────────────────────────────────────────────────────────────────────────────
ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff
[◦ ok ◦]
────────────────────────────────────────────────────────────────────────────────", output);
Application.RequestStop ();
}
};
Application.Run ();
}
[Fact, AutoInitShutdown]
public void MessageBox_With_A_Label_With_Spaces_WrapMessagge_False ()
{
var iterations = -1;
Application.Begin (Application.Top);
Application.Iteration += () => {
iterations++;
if (iterations == 0) {
var sb = new StringBuilder ();
for (int i = 0; i < 1000; i++)
sb.Append ("ff ");
MessageBox.Query ("mywindow", sb.ToString (), 0, false, "ok");
Application.RequestStop ();
} else if (iterations == 1) {
Application.Refresh ();
TestHelpers.AssertDriverContentsWithFrameAre (@"
────────────────────────────────────────────────────────────────────────────────
ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff f
[◦ ok ◦]
────────────────────────────────────────────────────────────────────────────────", output);
Application.RequestStop ();
}
};
Application.Run ();
}
[Theory, AutoInitShutdown]
[InlineData ("", true)]
[InlineData ("", false)]
[InlineData ("\n", true)]
[InlineData ("\n", false)]
public void MessageBox_With_A_Empty_Message_Or_A_NewLline_WrapMessagge_True_Or_False (string message, bool wrapMessage)
{
var iterations = -1;
Application.Begin (Application.Top);
Application.Iteration += () => {
iterations++;
if (iterations == 0) {
MessageBox.Query ("mywindow", message, 0, wrapMessage, "ok");
Application.RequestStop ();
} else if (iterations == 1) {
Application.Refresh ();
TestHelpers.AssertDriverContentsWithFrameAre (@"
┌┤mywindow├────────────────────────────────────┐
│ │
│ │
│ [◦ ok ◦] │
└──────────────────────────────────────────────┘", output);
Application.RequestStop ();
}
};
Application.Run ();
}
}
}

View File

@@ -0,0 +1,612 @@
using System;
using System.Collections.Generic;
using System.Data;
using System.Linq;
using System.Threading.Tasks;
using Terminal.Gui;
using Xunit;
using System.Globalization;
using Xunit.Abstractions;
using NStack;
using static Terminal.Gui.Application;
namespace Terminal.Gui.DialogTests {
public class WizardTests {
readonly ITestOutputHelper output;
public WizardTests (ITestOutputHelper output)
{
this.output = output;
}
private void RunButtonTestWizard (string title, int width, int height)
{
var wizard = new Wizard (title) { Width = width, Height = height };
Application.End (Application.Begin (wizard));
}
// =========== WizardStep Tests
[Fact, AutoInitShutdown]
public void WizardStep_ButtonText ()
{
// Verify default button text
// Verify set actually changes property
// Verify set actually changes buttons for the current step
}
[Fact]
public void WizardStep_Set_Title_Fires_TitleChanging ()
{
var r = new Window ();
Assert.Equal (ustring.Empty, r.Title);
string expectedAfter = string.Empty;
string expectedDuring = string.Empty;
bool cancel = false;
r.TitleChanging += (s,args) => {
Assert.Equal (expectedDuring, args.NewTitle);
args.Cancel = cancel;
};
r.Title = expectedDuring = expectedAfter = "title";
Assert.Equal (expectedAfter, r.Title.ToString ());
r.Title = expectedDuring = expectedAfter = "a different title";
Assert.Equal (expectedAfter, r.Title.ToString ());
// Now setup cancelling the change and change it back to "title"
cancel = true;
r.Title = expectedDuring = "title";
Assert.Equal (expectedAfter, r.Title.ToString ());
r.Dispose ();
}
[Fact]
public void WizardStep_Set_Title_Fires_TitleChanged ()
{
var r = new Window ();
Assert.Equal (ustring.Empty, r.Title);
string expected = string.Empty;
r.TitleChanged += (s,args) => {
Assert.Equal (r.Title, args.NewTitle);
};
expected = "title";
r.Title = expected;
Assert.Equal (expected, r.Title.ToString ());
expected = "another title";
r.Title = expected;
Assert.Equal (expected, r.Title.ToString ());
r.Dispose ();
}
// =========== Wizard Tests
[Fact, AutoInitShutdown]
public void DefaultConstructor_SizedProperly ()
{
var d = (FakeDriver)Application.Driver;
var wizard = new Wizard ();
Assert.NotEqual (0, wizard.Width);
Assert.NotEqual (0, wizard.Height);
}
[Fact, AutoInitShutdown]
// Verify a zero-step wizard doesn't crash and shows a blank wizard
// and that the title is correct
public void ZeroStepWizard_Shows ()
{
var d = (FakeDriver)Application.Driver;
var title = "1234";
var stepTitle = "";
int width = 30;
int height = 6;
d.SetBufferSize (width, height);
var btnBackText = "Back";
var btnBack = $"{d.LeftBracket} {btnBackText} {d.RightBracket}";
var btnNextText = "Finish";
var btnNext = $"{d.LeftBracket}{d.LeftDefaultIndicator} {btnNextText} {d.RightDefaultIndicator}{d.RightBracket}";
var topRow = $"{d.ULDCorner}╡{title}{stepTitle}╞{new string (d.HDLine.ToString () [0], width - title.Length - stepTitle.Length - 4)}{d.URDCorner}";
var row2 = $"{d.VDLine}{new string (' ', width - 2)}{d.VDLine}";
var row3 = row2;
var separatorRow = $"{d.VDLine}{new string (' ', width - 2)}{d.VDLine}";
var buttonRow = $"{d.VDLine}{btnBack}{new string (' ', width - btnBack.Length - btnNext.Length - 2)}{btnNext}{d.VDLine}";
var bottomRow = $"{d.LLDCorner}{new string (d.HDLine.ToString () [0], width - 2)}{d.LRDCorner}";
var wizard = new Wizard (title) { Width = width, Height = height };
var runstate = Application.Begin (wizard);
TestHelpers.AssertDriverContentsWithFrameAre ($"{topRow}\n{row2}\n{row3}\n{separatorRow}\n{buttonRow}\n{bottomRow}", output);
Application.End (runstate);
}
[Fact, AutoInitShutdown]
// This test verifies that a single step wizard shows the correct buttons
// and that the title is correct
public void OneStepWizard_Shows ()
{
var d = (FakeDriver)Application.Driver;
var title = "1234";
var stepTitle = "ABCD";
int width = 30;
int height = 7;
d.SetBufferSize (width, height);
// var btnBackText = "Back";
var btnBack = string.Empty; // $"{d.LeftBracket} {btnBackText} {d.RightBracket}";
var btnNextText = "Finish"; // "Next";
var btnNext = $"{d.LeftBracket}{d.LeftDefaultIndicator} {btnNextText} {d.RightDefaultIndicator}{d.RightBracket}";
var topRow = $"{d.ULDCorner}╡{title} - {stepTitle}╞{new string (d.HDLine.ToString () [0], width - title.Length - stepTitle.Length - 7)}{d.URDCorner}";
var row2 = $"{d.VDLine}{new string (' ', width - 2)}{d.VDLine}";
var row3 = row2;
var row4 = row3;
var separatorRow = $"{d.VDLine}{new string (d.HLine.ToString () [0], width - 2)}{d.VDLine}";
var buttonRow = $"{d.VDLine}{btnBack}{new string (' ', width - btnBack.Length - btnNext.Length - 2)}{btnNext}{d.VDLine}";
var bottomRow = $"{d.LLDCorner}{new string (d.HDLine.ToString () [0], width - 2)}{d.LRDCorner}";
var wizard = new Wizard (title) { Width = width, Height = height };
wizard.AddStep (new Wizard.WizardStep (stepTitle));
//wizard.LayoutSubviews ();
var firstIteration = false;
var runstate = Application.Begin (wizard);
Application.RunMainLoopIteration (ref runstate, true, ref firstIteration);
TestHelpers.AssertDriverContentsWithFrameAre ($"{topRow}\n{row2}\n{row3}\n{row4}\n{separatorRow}\n{buttonRow}\n{bottomRow}", output);
Application.End (runstate);
}
[Fact, AutoInitShutdown]
// This test verifies that the 2nd step in a wizard with 2 steps
// shows the correct buttons on both steps
// and that the title is correct
public void TwoStepWizard_Next_Shows_SecondStep ()
{
// verify step one
// Next
// verify step two
// Back
// verify step one again
}
[Fact, AutoInitShutdown]
// This test verifies that the 2nd step in a wizard with more than 2 steps
// shows the correct buttons on all steps
// and that the title is correct
public void ThreeStepWizard_Next_Shows_Steps ()
{
// verify step one
// Next
// verify step two
// Back
// verify step one again
}
[Fact, AutoInitShutdown]
// this test is needed because Wizard overrides Dialog's title behavior ("Title - StepTitle")
public void Setting_Title_Works ()
{
var d = (FakeDriver)Application.Driver;
var title = "1234";
var stepTitle = " - ABCD";
int width = 40;
int height = 4;
d.SetBufferSize (width, height);
var btnNextText = "Finish";
var btnNext = $"{d.LeftBracket}{d.LeftDefaultIndicator} {btnNextText} {d.RightDefaultIndicator}{d.RightBracket}";
var topRow = $"{d.ULDCorner}╡{title}{stepTitle}╞{new string (d.HDLine.ToString () [0], width - title.Length - stepTitle.Length - 4)}{d.URDCorner}";
var separatorRow = $"{d.VDLine}{new string (d.HLine.ToString () [0], width - 2)}{d.VDLine}";
// Once this is fixed, revert to commented out line: https://github.com/gui-cs/Terminal.Gui/issues/1791
var buttonRow = $"{d.VDLine}{new string (' ', width - btnNext.Length - 2)}{btnNext}{d.VDLine}";
//var buttonRow = $"{d.VDLine}{new String (' ', width - btnNext.Length - 2)}{btnNext}{d.VDLine}";
var bottomRow = $"{d.LLDCorner}{new string (d.HDLine.ToString () [0], width - 2)}{d.LRDCorner}";
var wizard = new Wizard (title) { Width = width, Height = height };
wizard.AddStep (new Wizard.WizardStep ("ABCD"));
Application.End (Application.Begin (wizard));
TestHelpers.AssertDriverContentsWithFrameAre ($"{topRow}\n{separatorRow}\n{buttonRow}\n{bottomRow}", output);
}
[Fact, AutoInitShutdown]
public void Navigate_GetPreviousStep_Correct ()
{
var wizard = new Wizard ();
// If no steps should be null
Assert.Null (wizard.GetPreviousStep ());
var step1 = new Wizard.WizardStep ("step1");
wizard.AddStep (step1);
// If no current step, should be last step
Assert.Equal (step1.Title.ToString (), wizard.GetPreviousStep ().Title.ToString ());
wizard.CurrentStep = step1;
// If there is 1 step it's current step should be null
Assert.Null (wizard.GetPreviousStep ());
// If one disabled step should be null
step1.Enabled = false;
Assert.Null (wizard.GetPreviousStep ());
// If two steps and at 2 and step 1 is `Enabled = true`should be step1
var step2 = new Wizard.WizardStep ("step2");
wizard.AddStep (step2);
wizard.CurrentStep = step2;
step1.Enabled = true;
Assert.Equal (step1.Title.ToString (), wizard.GetPreviousStep ().Title.ToString ());
// If two steps and at 2 and step 1 is `Enabled = false` should be null
step1.Enabled = false;
Assert.Null (wizard.GetPreviousStep ());
// If three steps with Step2.Enabled = true
// At step 1 should be null
// At step 2 should be step 1
// At step 3 should be step 2
var step3 = new Wizard.WizardStep ("step3");
wizard.AddStep (step3);
step1.Enabled = true;
wizard.CurrentStep = step1;
step2.Enabled = true;
step3.Enabled = true;
Assert.Null (wizard.GetPreviousStep ());
wizard.CurrentStep = step2;
Assert.Equal (step1.Title.ToString (), wizard.GetPreviousStep ().Title.ToString ());
wizard.CurrentStep = step3;
Assert.Equal (step2.Title.ToString (), wizard.GetPreviousStep ().Title.ToString ());
// If three steps with Step2.Enabled = false
// At step 1 should be null
// At step 3 should be step1
step1.Enabled = true;
step2.Enabled = false;
step3.Enabled = true;
wizard.CurrentStep = step1;
Assert.Null (wizard.GetPreviousStep ());
wizard.CurrentStep = step3;
Assert.Equal (step1.Title.ToString (), wizard.GetPreviousStep ().Title.ToString ());
// If three steps with Step1.Enabled = false & Step2.Enabled = false
// At step 3 should be null
// If no current step, GetPreviousStep provides equivalent to GetLastStep
wizard.CurrentStep = null;
step1.Enabled = true;
step2.Enabled = true;
step3.Enabled = true;
Assert.Equal (step3.Title.ToString (), wizard.GetPreviousStep ().Title.ToString ());
step1.Enabled = false;
step2.Enabled = true;
step3.Enabled = true;
Assert.Equal (step3.Title.ToString (), wizard.GetPreviousStep ().Title.ToString ());
step1.Enabled = false;
step2.Enabled = false;
step3.Enabled = true;
Assert.Equal (step3.Title.ToString (), wizard.GetPreviousStep ().Title.ToString ());
step1.Enabled = false;
step2.Enabled = true;
step3.Enabled = false;
Assert.Equal (step2.Title.ToString (), wizard.GetPreviousStep ().Title.ToString ());
step1.Enabled = true;
step2.Enabled = false;
step3.Enabled = false;
Assert.Equal (step1.Title.ToString (), wizard.GetPreviousStep ().Title.ToString ());
}
[Fact, AutoInitShutdown]
public void Navigate_GetNextStep_Correct ()
{
var wizard = new Wizard ();
// If no steps should be null
Assert.Null (wizard.GetNextStep ());
var step1 = new Wizard.WizardStep ("step1");
wizard.AddStep (step1);
// If no current step, should be first step
Assert.Equal (step1.Title.ToString (), wizard.GetNextStep ().Title.ToString ());
wizard.CurrentStep = step1;
// If there is 1 step it's current step should be null
Assert.Null (wizard.GetNextStep ());
// If one disabled step should be null
step1.Enabled = false;
Assert.Null (wizard.GetNextStep ());
// If two steps and at 1 and step 2 is `Enabled = true`should be step 2
var step2 = new Wizard.WizardStep ("step2");
wizard.AddStep (step2);
Assert.Equal (step2.Title.ToString (), wizard.GetNextStep ().Title.ToString ());
// If two steps and at 1 and step 2 is `Enabled = false` should be null
step1.Enabled = true;
wizard.CurrentStep = step1;
step2.Enabled = false;
Assert.Null (wizard.GetNextStep ());
// If three steps with Step2.Enabled = true
// At step 1 should be step 2
// At step 2 should be step 3
// At step 3 should be null
var step3 = new Wizard.WizardStep ("step3");
wizard.AddStep (step3);
step1.Enabled = true;
wizard.CurrentStep = step1;
step2.Enabled = true;
step3.Enabled = true;
Assert.Equal (step2.Title.ToString (), wizard.GetNextStep ().Title.ToString ());
wizard.CurrentStep = step2;
Assert.Equal (step3.Title.ToString (), wizard.GetNextStep ().Title.ToString ());
wizard.CurrentStep = step3;
Assert.Null (wizard.GetNextStep ());
// If three steps with Step2.Enabled = false
// At step 1 should be step 3
// At step 3 should be null
step1.Enabled = true;
wizard.CurrentStep = step1;
step2.Enabled = false;
step3.Enabled = true;
Assert.Equal (step3.Title.ToString (), wizard.GetNextStep ().Title.ToString ());
wizard.CurrentStep = step3;
Assert.Null (wizard.GetNextStep ());
// If three steps with Step2.Enabled = false & Step3.Enabled = false
// At step 1 should be null
step1.Enabled = true;
wizard.CurrentStep = step1;
step2.Enabled = false;
step3.Enabled = false;
Assert.Null (wizard.GetNextStep ());
// If no current step, GetNextStep provides equivalent to GetFirstStep
wizard.CurrentStep = null;
step1.Enabled = true;
step2.Enabled = true;
step3.Enabled = true;
Assert.Equal (step1.Title.ToString (), wizard.GetNextStep ().Title.ToString ());
step1.Enabled = false;
step2.Enabled = true;
step3.Enabled = true;
Assert.Equal (step2.Title.ToString (), wizard.GetNextStep ().Title.ToString ());
step1.Enabled = false;
step2.Enabled = false;
step3.Enabled = true;
Assert.Equal (step3.Title.ToString (), wizard.GetNextStep ().Title.ToString ());
step1.Enabled = false;
step2.Enabled = true;
step3.Enabled = false;
Assert.Equal (step2.Title.ToString (), wizard.GetNextStep ().Title.ToString ());
step1.Enabled = true;
step2.Enabled = false;
step3.Enabled = false;
Assert.Equal (step1.Title.ToString (), wizard.GetNextStep ().Title.ToString ());
}
[Fact, AutoInitShutdown]
public void Navigate_GoNext_Works ()
{
// If zero steps do nothing
// If one step do nothing (enabled or disabled)
// If two steps
// If current is 1
// If 2 is enabled 2 becomes current
// If 2 is disabled 1 stays current
// If current is 2 does nothing
}
[Fact, AutoInitShutdown]
public void Navigate_GoBack_Works ()
{
// If zero steps do nothing
// If one step do nothing (enabled or disabled)
// If two steps
// If current is 1 does nothing
// If current is 2 does nothing
// If 1 is enabled 2 becomes current
// If 1 is disabled 1 stays current
}
[Fact, AutoInitShutdown]
public void Navigate_GetFirstStep_Works ()
{
var wizard = new Wizard ();
Assert.Null (wizard.GetFirstStep ());
var step1 = new Wizard.WizardStep ("step1");
wizard.AddStep (step1);
Assert.Equal (step1.Title.ToString (), wizard.GetFirstStep ().Title.ToString ());
var step2 = new Wizard.WizardStep ("step2");
wizard.AddStep (step2);
Assert.Equal (step1.Title.ToString (), wizard.GetFirstStep ().Title.ToString ());
var step3 = new Wizard.WizardStep ("step3");
wizard.AddStep (step3);
Assert.Equal (step1.Title.ToString (), wizard.GetFirstStep ().Title.ToString ());
step1.Enabled = false;
Assert.Equal (step2.Title.ToString (), wizard.GetFirstStep ().Title.ToString ());
step1.Enabled = true;
Assert.Equal (step1.Title.ToString (), wizard.GetFirstStep ().Title.ToString ());
step1.Enabled = false;
step2.Enabled = false;
Assert.Equal (step3.Title.ToString (), wizard.GetFirstStep ().Title.ToString ());
}
[Fact, AutoInitShutdown]
public void Navigate_GetLastStep_Works ()
{
var wizard = new Wizard ();
Assert.Null (wizard.GetLastStep ());
var step1 = new Wizard.WizardStep ("step1");
wizard.AddStep (step1);
Assert.Equal (step1.Title.ToString (), wizard.GetLastStep ().Title.ToString ());
var step2 = new Wizard.WizardStep ("step2");
wizard.AddStep (step2);
Assert.Equal (step2.Title.ToString (), wizard.GetLastStep ().Title.ToString ());
var step3 = new Wizard.WizardStep ("step3");
wizard.AddStep (step3);
Assert.Equal (step3.Title.ToString (), wizard.GetLastStep ().Title.ToString ());
step3.Enabled = false;
Assert.Equal (step2.Title.ToString (), wizard.GetLastStep ().Title.ToString ());
step3.Enabled = true;
Assert.Equal (step3.Title.ToString (), wizard.GetLastStep ().Title.ToString ());
step3.Enabled = false;
step2.Enabled = false;
Assert.Equal (step1.Title.ToString (), wizard.GetLastStep ().Title.ToString ());
}
[Fact, AutoInitShutdown]
public void Finish_Button_Closes ()
{
// https://github.com/gui-cs/Terminal.Gui/issues/1833
var wizard = new Wizard ();
var step1 = new Wizard.WizardStep ("step1") { };
wizard.AddStep (step1);
var finishedFired = false;
wizard.Finished += (s, args) => {
finishedFired = true;
};
var closedFired = false;
wizard.Closed += (s, e) => {
closedFired = true;
};
var runstate = Application.Begin (wizard);
var firstIteration = true;
Application.RunMainLoopIteration (ref runstate, true, ref firstIteration);
wizard.NextFinishButton.OnClicked ();
Application.RunMainLoopIteration (ref runstate, true, ref firstIteration);
Application.End (runstate);
Assert.True (finishedFired);
Assert.True (closedFired);
step1.Dispose ();
wizard.Dispose ();
// Same test, but with two steps
wizard = new Wizard ();
firstIteration = false;
step1 = new Wizard.WizardStep ("step1") { };
wizard.AddStep (step1);
var step2 = new Wizard.WizardStep ("step2") { };
wizard.AddStep (step2);
finishedFired = false;
wizard.Finished += (s, args) => {
finishedFired = true;
};
closedFired = false;
wizard.Closed += (s,e) => {
closedFired = true;
};
runstate = Application.Begin (wizard);
Application.RunMainLoopIteration (ref runstate, true, ref firstIteration);
Assert.Equal (step1.Title.ToString (), wizard.CurrentStep.Title.ToString ());
wizard.NextFinishButton.OnClicked ();
Assert.False (finishedFired);
Assert.False (closedFired);
Assert.Equal (step2.Title.ToString (), wizard.CurrentStep.Title.ToString ());
Assert.Equal (wizard.GetLastStep ().Title.ToString (), wizard.CurrentStep.Title.ToString ());
wizard.NextFinishButton.OnClicked ();
Application.End (runstate);
Assert.True (finishedFired);
Assert.True (closedFired);
step1.Dispose ();
step2.Dispose ();
wizard.Dispose ();
// Same test, but with two steps but the 1st one disabled
wizard = new Wizard ();
firstIteration = false;
step1 = new Wizard.WizardStep ("step1") { };
wizard.AddStep (step1);
step2 = new Wizard.WizardStep ("step2") { };
wizard.AddStep (step2);
step1.Enabled = false;
finishedFired = false;
wizard.Finished += (s, args) => {
finishedFired = true;
};
closedFired = false;
wizard.Closed += (s,e) => {
closedFired = true;
};
runstate = Application.Begin (wizard);
Application.RunMainLoopIteration (ref runstate, true, ref firstIteration);
Assert.Equal (step2.Title.ToString (), wizard.CurrentStep.Title.ToString ());
Assert.Equal (wizard.GetLastStep ().Title.ToString (), wizard.CurrentStep.Title.ToString ());
wizard.NextFinishButton.OnClicked ();
Application.End (runstate);
Assert.True (finishedFired);
Assert.True (closedFired);
}
}
}