mirror of
https://github.com/gui-cs/Terminal.Gui.git
synced 2025-12-28 00:38:00 +01:00
* Removed resharper settings from editorconfig * Remove constructors with frame parameters from Button class. * Remove constructors with frame parameters from CheckBox class. * Cleanup code. * Remove constructors with frame parameters from ComboBox class. * @BDisp Remove constructors with frame parameters from FrameView class. * Remove constructors with frame parameters from Label class. * Remove constructors with frame parameters from ListView class. * Remove constructors with frame parameters from ScrollBarView class. * Remove constructors with frame parameters from ScrollView class. * Remove namespace braces. * Cleanup code. * Cleanup code. * Cleanup code. * Remove constructors with frame parameters from TextField class. * Remove constructors with frame parameters from TimeField class. * Fixes #3182. OnResizeNeeded returns int.MaxValue and int.MaxValue when Application.Top is null, should return Size.Empty. * Remove constructors with frame parameters from Toplevel class. * Remove constructors with frame parameters from Window class. * Fix merge errors. * Revert "Fixes #3182. OnResizeNeeded returns int.MaxValue and int.MaxValue when Application.Top is null, should return Size.Empty." This reverts commitcf9c24b846. * Revert unit test. * Fixes #2882. TabView: 'Frame.DrawFrame(Rect, bool)' is obsolete: 'This method is obsolete in v2. Use use LineCanvas or Frame (#2980) * Fixes #2882. TabView: 'Frame.DrawFrame(Rect, bool)' is obsolete: 'This method is obsolete in v2. Use use LineCanvas or Frame * Trying fix this unit test that sometimes fail. * Fixes #2983. View need a alternative DrawFrame for the v2. * Use new DrawFrame method. * Change _lines field to Lines property. * Add TabWindow unit test. * Add DrawIncompleteFrame method and unit tests. * Add more unit tests to LineCanvas. * Fix newline conflict errors. * Revert "Change _lines field to Lines property." This reverts commitab6c5f3094. * Add DrawIncompleteFrame method and unit tests. * Add more unit tests to LineCanvas. * Fix newline conflict errors. * Force render immediately instead of join. * I will never rely on zero-location-based unit test again. * Fix TestTreeViewColor unit test fail. * Using location of 3 to avoid be divisible by 2 and so avoiding bugs. * Revert "Using location of 3 to avoid be divisible by 2 and so avoiding bugs." This reverts commitdd3df135d8. * Revert "I will never rely on zero-location-based unit test again." This reverts commit62adf6f285. * Revert "Fix newline conflict errors." This reverts commit4acf72612d. * Revert "Add more unit tests to LineCanvas." This reverts commit66bc6f514e. * Revert "Add DrawIncompleteFrame method and unit tests." This reverts commit680ba264e1. * Resolving merge conflicts. * Revert "Use new DrawFrame method." This reverts commit69a7f17f19. * Revert "Fixes #2983. View need a alternative DrawFrame for the v2." This reverts commitdade9fd767. * Reverting this changes to start a new one. * Add horizontal and vertical support for combining glyphs. * Fix text and auto size behavior. * Add TabWidth property. * Add unit test for WordWrap. * Fixes #3017. View TextDirection returns incorrect size on a vertical direction instance with AutoSize as false. * Using Frame to force read from the get method. * Fix some issues with AutoSize and ForceValidatePosDim. * Fixing broken unit tests. * Restoring code I've broken. * Removing forgotten code. * Only LayoutStyle.Computed can change the Frame. * DateField and TimeField depends on LayoutStyle.Computed. * Fix unit tests related with LayoutStyle. * Implements tabs, left and right arrows as View. * Draws a minimum full border. * Adds missing XML parameter. * Adds assert tests for Frame. * Removes duplicates InlineData. * Adds more unit tests for minimum full border without Left and Right thickness. * Trying to fix the TestTreeViewColor unit test fail. * Prevents a user to set TextDirection to -1. * Prevents any invalid TextDirection value. * Removes (TextDirection)(-1). * Removes unnecessary TextDirection initialization. * Removes LayoutStyle. * Fixing unit tests with border. * Trying to fix TestTreeViewColor again. * Revert "Trying to fix TestTreeViewColor again." This reverts commitc2efa8e42e. * Trying to fix TestTreeViewColor again. * Fix merge errors. * Fix merge errors. * Restoring unit test. * Restores the right XML comment. * Fix Disposing unit tests that sometimes throws because some instances aren't cleared on others unit tests classes. * Fix Disposing unit tests that sometimes throws because some instances aren't cleared on others unit tests classes. * Only call OnResizeNeeded if it's LayoutStyle.Computed. * Fix merge errors. * Fix merge errors. * Fix unit tests fail. * Reformat. * Again. * Rename to OnDrawAdornments. * Fix failing unit tests. * Reduces indentation and cleanup code. * Cleanup code. * Fix bug done when cleanup. * Replace FrameHandledMouseEvent to AdornmentHandledMouseEvent. * Removes Tab constructor parameters. --------- Co-authored-by: Tig <tig@users.noreply.github.com> * Fix merge errors. * Remove constructors with parameters from Button. * Remove parenthesis on objects initializers from Button. * Remove constructors with parameters from CheckBox. * Remove parenthesis on objects initializers from CheckBox. * Remove constructors with parameters from ComboBox. * Remove constructors with parameters from FrameView. * Remove parenthesis on objects initializers from FrameView. * Initial commit * Renamed Direction enum for clarity in refactoring unit tests * Moved nav tests to NavigationTests * Moved view tests around * Cleaning up TextFormatter and View.AutoSize code * Fixed latent TextFormatter bug with \n * removed Application dependency on some autosize unit tests * Fixed Label tests to deal with auotsize overriding height/width * Fixed more label tests. WIP * Fixed all places where AutoSize = happend after setting Dims * Started adding new primitive View.Text tests * Code comments * WIP: Enforce that it makes no sense to set Width/Height if AutoSize = true. Update Unit tests to match. * WIP: Enforce that it makes no sense to set Width/Height if AutoSize = true. Update Unit tests to match. * Remove frame set from the View constructor and prevent SetRelativeLayout running if not yet initialized. * Changes needed for unit tests pass on remove parameters constructors from the Label class. * Remove constructors with parameters from Label. * Remove parenthesis on objects initializers from Label. * Prefix private fields with underscore. * Renamed to MaxLength. * Remove constructors with parameters from ListView. * MakeWrapper not needed anymore. * Remove parenthesis on objects initializers from ListView. * WIP: Enforce that it makes no sense to set Width/Height if AutoSize = true. Update Unit tests to match. * Massive code cleanup - use parameterless constructors and ensure AutoSize is set properly. Code reformat. * Massive code cleanup - use parameterless constructors and ensure AutoSize is set properly. Code reformat. * Fixed messagebox * Remove constructors with parameters from ScrollBarView and ScrollView. * Remove parenthesis on objects initializers from ScrollBarView and ScrollView. * Cleanup code. * Fix merge errors. * Add empty dotsettings for solution and projects. * Set ReSharper language analysis level for projects to C#12 * Make ReSharper consider itself the boss for style * Add rule to enforce property backing fields above the property * Disable auto-detection of naming rules so ReSharper doesn't change them by itself * Don't let someone's VS settings override the indent settings * Explicitly set tab width to 4 spaces and force spaces. * Rules to keep various multi-line constructs aligned within themselves * Curly brace rules (Using K&R style, per current project spec) * Blank line rules Mostly to add breaks in various situations, and also to enforce max of 1 blank line. * Increase auto-wrap to 160 from default of 120 * Line break at end of all files, to make Unixy systems happy * Keep attributes on their own lines except for methods and records that are themselves single-line * Increase attribute auto-wrap to 60 from default of 38 * Wrap/chop rules for long method signatures and record declarations Chop if either already multi-line or if over 8 parameters. Chop AFTER the left paren and BEFORE the first parameter. * Chop rules for generics For generics with multi-line type parameters or multiple type parameter constraints, chop in a way that has consistent alignment. * Always enforce enum members on their own lines * One-line functions completely on one line They're usually expression-bodied anyway, here, so this is almost irrelevant * Keep control flow statements on their own lines * Follow same chop rules for method invocation as method declaration * Chop long or multi-line method chains or patterns * Wrap rules for binary operators Operator at beginning of new lines Auto-chop if long or already multi-line * Spaces between keywords and their opening parentheses * Add file layout rules for organization of reorderable items like fields, properties, etc. Ugly XML, so load it up in the UI to look at it It's MOSTLY the ReSharper defaults, but with more aggressive sorting, generally by access modifier and name, within each grouping. * Deconstructors use per-member types * Use keywords for built-in types and increase severity of inspection for violations Also apply to IntPtr and similar, which should now be nint and similar * Apply syntax style on completion. * Use var when evident for built-in and simple types, but not elsewhere * Increase severity for some minor redundancy and clarity inspections * Enforce braces always required for blocks, and treat as error * Warn if a local function is not statement-bodied * Increase various inspection severities IF Condition => Severity: Attributes not wrapped property => Suggestion Constructors expression-bodied => Error default doesn't have type when it isn't clear => suggestion Namespaces not file-scoped => error Methods not statement-bodied => hint Null check pattern not the object property pattern => Error * Adjust preference order of null check patterns to make object pattern highest * XmlDoc rules to keep tags and contents aligned and wrapped * Add a few custom profiles for code cleanup and make the full profile default * Remove parts for languages not used in this solution * copied in v2_develop changes * Merged v2_develop * Added Begin/Init unit tests. Removed Application dependencey from AutoSizeFalse tests * TextFormatter.Lines -> GetLines () * Let ReSharper know we intend to localize things * TextFormatter code cleanup * copied in v2_develop changes * Merged v2_develop * Spaces aren't wanted here either. * Fix merge errors. * Fixes ContentBottomRightCorner related with https://github.com/gui-cs/Terminal.Gui/issues/3211#issue-2098878820 * Remove constructors with parameters from ContextMenu. * Remove commented code. * Remove constructors with parameters from OpenDialog. * Remove constructors with parameters from SaveDialog. * Remove constructors with parameters from TextField. * Remove constructors with parameters from TimeField. * Fix unit test. * Remove unnecessary SetInitialProperties method. * Remove unnecessary SetInitialProperties method. * Remove parenthesis on objects initializers from Toplevel and Window. * Remove constructors with parameters from RadioGroup. * Remove constructors with parameters from TextView. * Remove constructors with parameters from MenuBar. * TEMPORARY: Turn everything that was set to error down to warning or lower * Fixes #3219. MenuBar is opened by call OpenMenu even it's disabled. * Remove constructors with parameters from Menu. * Remove constructors with parameters from View. * Change constructor to internal because is mainly useful for testing. * ReSharper Cleanup Code. * Added format only r# config * Fixes #3224. TextFormatter.Lines should return a single string.Empty list even with Width or Height equal to zero. * Remove constructors with parameters from Dialog. * Remove constructors with parameters from TextValidateField. * Fixes https://github.com/gui-cs/Terminal.Gui/issues/3224#issuecomment-1924096038 * Fixes #3225. Press CursorDown on TabView doesn't move to the next view. * Fixes #3229. TextFormatter should have a FillRemaining property. * Testing formatting merge in bdisp * Testing formatting merge * Testing formatting merge bdisp * Testing formatting merge 2 * xmldoc format * R# Full Code Cleanup * R# Full Code Cleanup2 * R# Full Code Cleanup2 * Merged! But broke tests * Refixing... * Refixed DrawTests * Refixed ViewTests * Refixed Text Tests * Refixed more unit tests * Refixed scenarios * Refixed rest of scenarios * Refixed ViewsTests * Refixed rest of tests. All unit tests pass again! * Fixed warnings * Updated R# version. Added new code cleanup settings * Applied latest code cleanup to solution * Another code cleanup pass * Tweaked r# settings. .editorconfig now matches. * r# else on separate line * r# - update * r# - full solution * test commit * test commit * test commit * Removed extra profiles * Full cleanup following cleaning up profiles * Null checking pattern rules/inspections * Tabs and extra whitespace are evil * Attributes on their own lines * Code layout rules to put fields first and to put backing fields with their properties * Merged v2_develop * Full cleanup following dodexahedron's PR --------- Co-authored-by: BDisp <bd.bdisp@gmail.com> Co-authored-by: Brandon Thetford <github@snapsinazfs.com>
1335 lines
55 KiB
C#
1335 lines
55 KiB
C#
using Xunit.Abstractions;
|
|
using static Terminal.Gui.Application;
|
|
|
|
namespace Terminal.Gui.DialogTests;
|
|
|
|
public class DialogTests
|
|
{
|
|
private readonly ITestOutputHelper _output;
|
|
public DialogTests (ITestOutputHelper output) { _output = output; }
|
|
|
|
[Fact]
|
|
[AutoInitShutdown]
|
|
public void Add_Button_Works ()
|
|
{
|
|
RunState runstate = null;
|
|
|
|
var d = (FakeDriver)Driver;
|
|
|
|
var title = "1234";
|
|
var btn1Text = "yes";
|
|
var btn1 = $"{CM.Glyphs.LeftBracket} {btn1Text} {CM.Glyphs.RightBracket}";
|
|
var btn2Text = "no";
|
|
var btn2 = $"{CM.Glyphs.LeftBracket} {btn2Text} {CM.Glyphs.RightBracket}";
|
|
|
|
// We test with one button first, but do this to get the width right for 2
|
|
int width = $@"{CM.Glyphs.VLine} {btn1} {btn2} {CM.Glyphs.VLine}".Length;
|
|
d.SetBufferSize (width, 1);
|
|
|
|
// Default (center)
|
|
var dlg = new Dialog
|
|
{
|
|
Title = title,
|
|
Width = width,
|
|
Height = 1,
|
|
ButtonAlignment = Dialog.ButtonAlignments.Center,
|
|
Buttons = [new Button { Text = btn1Text }]
|
|
};
|
|
|
|
// Create with no top or bottom border to simplify testing button layout (no need to account for title etc..)
|
|
dlg.Border.Thickness = new Thickness (1, 0, 1, 0);
|
|
runstate = Begin (dlg);
|
|
var buttonRow = $"{CM.Glyphs.VLine} {btn1} {CM.Glyphs.VLine}";
|
|
TestHelpers.AssertDriverContentsWithFrameAre ($"{buttonRow}", _output);
|
|
|
|
// Now add a second button
|
|
buttonRow = $"{CM.Glyphs.VLine} {btn1} {btn2} {CM.Glyphs.VLine}";
|
|
dlg.AddButton (new Button { Text = btn2Text });
|
|
var first = false;
|
|
RunIteration (ref runstate, ref first);
|
|
TestHelpers.AssertDriverContentsWithFrameAre ($"{buttonRow}", _output);
|
|
End (runstate);
|
|
|
|
// Justify
|
|
dlg = new Dialog
|
|
{
|
|
Title = title,
|
|
Width = width,
|
|
Height = 1,
|
|
ButtonAlignment = Dialog.ButtonAlignments.Justify,
|
|
Buttons = [new Button { Text = btn1Text }]
|
|
};
|
|
|
|
// Create with no top or bottom border to simplify testing button layout (no need to account for title etc..)
|
|
dlg.Border.Thickness = new Thickness (1, 0, 1, 0);
|
|
runstate = Begin (dlg);
|
|
buttonRow = $"{CM.Glyphs.VLine} {btn1}{CM.Glyphs.VLine}";
|
|
TestHelpers.AssertDriverContentsWithFrameAre ($"{buttonRow}", _output);
|
|
|
|
// Now add a second button
|
|
buttonRow = $"{CM.Glyphs.VLine}{btn1} {btn2}{CM.Glyphs.VLine}";
|
|
dlg.AddButton (new Button { Text = btn2Text });
|
|
first = false;
|
|
RunIteration (ref runstate, ref first);
|
|
TestHelpers.AssertDriverContentsWithFrameAre ($"{buttonRow}", _output);
|
|
End (runstate);
|
|
|
|
// Right
|
|
dlg = new Dialog
|
|
{
|
|
Title = title,
|
|
Width = width,
|
|
Height = 1,
|
|
ButtonAlignment = Dialog.ButtonAlignments.Right,
|
|
Buttons = [new Button { Text = btn1Text }]
|
|
};
|
|
|
|
// Create with no top or bottom border to simplify testing button layout (no need to account for title etc..)
|
|
dlg.Border.Thickness = new Thickness (1, 0, 1, 0);
|
|
runstate = Begin (dlg);
|
|
buttonRow = $"{CM.Glyphs.VLine}{new string (' ', width - btn1.Length - 2)}{btn1}{CM.Glyphs.VLine}";
|
|
TestHelpers.AssertDriverContentsWithFrameAre ($"{buttonRow}", _output);
|
|
|
|
// Now add a second button
|
|
buttonRow = $"{CM.Glyphs.VLine} {btn1} {btn2}{CM.Glyphs.VLine}";
|
|
dlg.AddButton (new Button { Text = btn2Text });
|
|
first = false;
|
|
RunIteration (ref runstate, ref first);
|
|
TestHelpers.AssertDriverContentsWithFrameAre ($"{buttonRow}", _output);
|
|
End (runstate);
|
|
|
|
// Left
|
|
dlg = new Dialog
|
|
{
|
|
Title = title,
|
|
Width = width,
|
|
Height = 1,
|
|
ButtonAlignment = Dialog.ButtonAlignments.Left,
|
|
Buttons = [new Button { Text = btn1Text }]
|
|
};
|
|
|
|
// Create with no top or bottom border to simplify testing button layout (no need to account for title etc..)
|
|
dlg.Border.Thickness = new Thickness (1, 0, 1, 0);
|
|
runstate = Begin (dlg);
|
|
buttonRow = $"{CM.Glyphs.VLine}{btn1}{new string (' ', width - btn1.Length - 2)}{CM.Glyphs.VLine}";
|
|
TestHelpers.AssertDriverContentsWithFrameAre ($"{buttonRow}", _output);
|
|
|
|
// Now add a second button
|
|
buttonRow = $"{CM.Glyphs.VLine}{btn1} {btn2} {CM.Glyphs.VLine}";
|
|
dlg.AddButton (new Button { Text = btn2Text });
|
|
first = false;
|
|
RunIteration (ref runstate, ref first);
|
|
TestHelpers.AssertDriverContentsWithFrameAre ($"{buttonRow}", _output);
|
|
End (runstate);
|
|
}
|
|
|
|
[Fact]
|
|
[AutoInitShutdown]
|
|
public void ButtonAlignment_Four ()
|
|
{
|
|
RunState runstate = null;
|
|
|
|
var d = (FakeDriver)Driver;
|
|
|
|
var title = "1234";
|
|
|
|
// E.g "|[ yes ][ no ][ maybe ]|"
|
|
var btn1Text = "yes";
|
|
var btn1 = $"{CM.Glyphs.LeftBracket} {btn1Text} {CM.Glyphs.RightBracket}";
|
|
var btn2Text = "no";
|
|
var btn2 = $"{CM.Glyphs.LeftBracket} {btn2Text} {CM.Glyphs.RightBracket}";
|
|
var btn3Text = "maybe";
|
|
var btn3 = $"{CM.Glyphs.LeftBracket} {btn3Text} {CM.Glyphs.RightBracket}";
|
|
var btn4Text = "never";
|
|
var btn4 = $"{CM.Glyphs.LeftBracket} {btn4Text} {CM.Glyphs.RightBracket}";
|
|
|
|
var buttonRow = $"{CM.Glyphs.VLine} {btn1} {btn2} {btn3} {btn4} {CM.Glyphs.VLine}";
|
|
int width = buttonRow.Length;
|
|
d.SetBufferSize (buttonRow.Length, 3);
|
|
|
|
// Default - Center
|
|
(runstate, Dialog _) = RunButtonTestDialog (
|
|
title,
|
|
width,
|
|
Dialog.ButtonAlignments.Center,
|
|
new Button { Text = btn1Text },
|
|
new Button { Text = btn2Text },
|
|
new Button { Text = btn3Text },
|
|
new Button { Text = btn4Text }
|
|
);
|
|
TestHelpers.AssertDriverContentsWithFrameAre ($"{buttonRow}", _output);
|
|
End (runstate);
|
|
|
|
// Justify
|
|
buttonRow = $"{CM.Glyphs.VLine}{btn1} {btn2} {btn3} {btn4}{CM.Glyphs.VLine}";
|
|
Assert.Equal (width, buttonRow.Length);
|
|
|
|
(runstate, Dialog _) = RunButtonTestDialog (
|
|
title,
|
|
width,
|
|
Dialog.ButtonAlignments.Justify,
|
|
new Button { Text = btn1Text },
|
|
new Button { Text = btn2Text },
|
|
new Button { Text = btn3Text },
|
|
new Button { Text = btn4Text }
|
|
);
|
|
TestHelpers.AssertDriverContentsWithFrameAre ($"{buttonRow}", _output);
|
|
End (runstate);
|
|
|
|
// Right
|
|
buttonRow = $"{CM.Glyphs.VLine} {btn1} {btn2} {btn3} {btn4}{CM.Glyphs.VLine}";
|
|
Assert.Equal (width, buttonRow.Length);
|
|
|
|
(runstate, Dialog _) = RunButtonTestDialog (
|
|
title,
|
|
width,
|
|
Dialog.ButtonAlignments.Right,
|
|
new Button { Text = btn1Text },
|
|
new Button { Text = btn2Text },
|
|
new Button { Text = btn3Text },
|
|
new Button { Text = btn4Text }
|
|
);
|
|
TestHelpers.AssertDriverContentsWithFrameAre ($"{buttonRow}", _output);
|
|
End (runstate);
|
|
|
|
// Left
|
|
buttonRow = $"{CM.Glyphs.VLine}{btn1} {btn2} {btn3} {btn4} {CM.Glyphs.VLine}";
|
|
Assert.Equal (width, buttonRow.Length);
|
|
|
|
(runstate, Dialog _) = RunButtonTestDialog (
|
|
title,
|
|
width,
|
|
Dialog.ButtonAlignments.Left,
|
|
new Button { Text = btn1Text },
|
|
new Button { Text = btn2Text },
|
|
new Button { Text = btn3Text },
|
|
new Button { Text = btn4Text }
|
|
);
|
|
TestHelpers.AssertDriverContentsWithFrameAre ($"{buttonRow}", _output);
|
|
End (runstate);
|
|
}
|
|
|
|
[Fact]
|
|
[AutoInitShutdown]
|
|
public void ButtonAlignment_Four_On_Too_Small_Width ()
|
|
{
|
|
RunState runstate = null;
|
|
|
|
var d = (FakeDriver)Driver;
|
|
|
|
var title = "1234";
|
|
|
|
// E.g "|[ yes ][ no ][ maybe ][ never ]|"
|
|
var btn1Text = "yes";
|
|
var btn1 = $"{CM.Glyphs.LeftBracket} {btn1Text} {CM.Glyphs.RightBracket}";
|
|
var btn2Text = "no";
|
|
var btn2 = $"{CM.Glyphs.LeftBracket} {btn2Text} {CM.Glyphs.RightBracket}";
|
|
var btn3Text = "maybe";
|
|
var btn3 = $"{CM.Glyphs.LeftBracket} {btn3Text} {CM.Glyphs.RightBracket}";
|
|
var btn4Text = "never";
|
|
var btn4 = $"{CM.Glyphs.LeftBracket} {btn4Text} {CM.Glyphs.RightBracket}";
|
|
var buttonRow = string.Empty;
|
|
|
|
var width = 30;
|
|
d.SetBufferSize (width, 1);
|
|
|
|
// Default - Center
|
|
buttonRow =
|
|
$"{CM.Glyphs.VLine}es {CM.Glyphs.RightBracket} {btn2} {btn3} {CM.Glyphs.LeftBracket} neve{CM.Glyphs.VLine}";
|
|
|
|
(runstate, Dialog dlg) = RunButtonTestDialog (
|
|
title,
|
|
width,
|
|
Dialog.ButtonAlignments.Center,
|
|
new Button { Text = btn1Text },
|
|
new Button { Text = btn2Text },
|
|
new Button { Text = btn3Text },
|
|
new Button { Text = btn4Text }
|
|
);
|
|
Assert.Equal (new Size (width, 1), dlg.Frame.Size);
|
|
TestHelpers.AssertDriverContentsWithFrameAre ($"{buttonRow}", _output);
|
|
End (runstate);
|
|
|
|
// Justify
|
|
buttonRow =
|
|
$"{
|
|
CM.Glyphs.VLine
|
|
}{
|
|
CM.Glyphs.LeftBracket
|
|
} yes {
|
|
CM.Glyphs.LeftBracket
|
|
} no {
|
|
CM.Glyphs.LeftBracket
|
|
} maybe {
|
|
CM.Glyphs.LeftBracket
|
|
} never {
|
|
CM.Glyphs.RightBracket
|
|
}{
|
|
CM.Glyphs.VLine
|
|
}";
|
|
|
|
(runstate, Dialog _) = RunButtonTestDialog (
|
|
title,
|
|
width,
|
|
Dialog.ButtonAlignments.Justify,
|
|
new Button { Text = btn1Text },
|
|
new Button { Text = btn2Text },
|
|
new Button { Text = btn3Text },
|
|
new Button { Text = btn4Text }
|
|
);
|
|
TestHelpers.AssertDriverContentsWithFrameAre ($"{buttonRow}", _output);
|
|
End (runstate);
|
|
|
|
// Right
|
|
buttonRow = $"{CM.Glyphs.VLine}{CM.Glyphs.RightBracket} {btn2} {btn3} {btn4}{CM.Glyphs.VLine}";
|
|
|
|
(runstate, Dialog _) = RunButtonTestDialog (
|
|
title,
|
|
width,
|
|
Dialog.ButtonAlignments.Right,
|
|
new Button { Text = btn1Text },
|
|
new Button { Text = btn2Text },
|
|
new Button { Text = btn3Text },
|
|
new Button { Text = btn4Text }
|
|
);
|
|
TestHelpers.AssertDriverContentsWithFrameAre ($"{buttonRow}", _output);
|
|
End (runstate);
|
|
|
|
// Left
|
|
buttonRow = $"{CM.Glyphs.VLine}{btn1} {btn2} {btn3} {CM.Glyphs.LeftBracket} n{CM.Glyphs.VLine}";
|
|
|
|
(runstate, Dialog _) = RunButtonTestDialog (
|
|
title,
|
|
width,
|
|
Dialog.ButtonAlignments.Left,
|
|
new Button { Text = btn1Text },
|
|
new Button { Text = btn2Text },
|
|
new Button { Text = btn3Text },
|
|
new Button { Text = btn4Text }
|
|
);
|
|
TestHelpers.AssertDriverContentsWithFrameAre ($"{buttonRow}", _output);
|
|
End (runstate);
|
|
}
|
|
|
|
[Fact]
|
|
[AutoInitShutdown]
|
|
public void ButtonAlignment_Four_WideOdd ()
|
|
{
|
|
RunState runstate = null;
|
|
|
|
var d = (FakeDriver)Driver;
|
|
|
|
var title = "1234";
|
|
|
|
// E.g "|[ yes ][ no ][ maybe ]|"
|
|
var btn1Text = "really long button 1";
|
|
var btn1 = $"{CM.Glyphs.LeftBracket} {btn1Text} {CM.Glyphs.RightBracket}";
|
|
var btn2Text = "really long button 2";
|
|
var btn2 = $"{CM.Glyphs.LeftBracket} {btn2Text} {CM.Glyphs.RightBracket}";
|
|
var btn3Text = "really long button 3";
|
|
var btn3 = $"{CM.Glyphs.LeftBracket} {btn3Text} {CM.Glyphs.RightBracket}";
|
|
var btn4Text = "really long button 44"; // 44 is intentional to make length different than rest
|
|
var btn4 = $"{CM.Glyphs.LeftBracket} {btn4Text} {CM.Glyphs.RightBracket}";
|
|
|
|
// Note extra spaces to make dialog even wider
|
|
// 123456 1234567
|
|
var buttonRow = $"{CM.Glyphs.VLine} {btn1} {btn2} {btn3} {btn4} {CM.Glyphs.VLine}";
|
|
int width = buttonRow.Length;
|
|
d.SetBufferSize (buttonRow.Length, 1);
|
|
|
|
// Default - Center
|
|
(runstate, Dialog _) = RunButtonTestDialog (
|
|
title,
|
|
width,
|
|
Dialog.ButtonAlignments.Center,
|
|
new Button { Text = btn1Text },
|
|
new Button { Text = btn2Text },
|
|
new Button { Text = btn3Text },
|
|
new Button { Text = btn4Text }
|
|
);
|
|
TestHelpers.AssertDriverContentsWithFrameAre ($"{buttonRow}", _output);
|
|
End (runstate);
|
|
|
|
// Justify
|
|
buttonRow = $"{CM.Glyphs.VLine}{btn1} {btn2} {btn3} {btn4}{CM.Glyphs.VLine}";
|
|
Assert.Equal (width, buttonRow.Length);
|
|
|
|
(runstate, Dialog _) = RunButtonTestDialog (
|
|
title,
|
|
width,
|
|
Dialog.ButtonAlignments.Justify,
|
|
new Button { Text = btn1Text },
|
|
new Button { Text = btn2Text },
|
|
new Button { Text = btn3Text },
|
|
new Button { Text = btn4Text }
|
|
);
|
|
TestHelpers.AssertDriverContentsWithFrameAre ($"{buttonRow}", _output);
|
|
End (runstate);
|
|
|
|
// Right
|
|
buttonRow = $"{CM.Glyphs.VLine} {btn1} {btn2} {btn3} {btn4}{CM.Glyphs.VLine}";
|
|
Assert.Equal (width, buttonRow.Length);
|
|
|
|
(runstate, Dialog _) = RunButtonTestDialog (
|
|
title,
|
|
width,
|
|
Dialog.ButtonAlignments.Right,
|
|
new Button { Text = btn1Text },
|
|
new Button { Text = btn2Text },
|
|
new Button { Text = btn3Text },
|
|
new Button { Text = btn4Text }
|
|
);
|
|
TestHelpers.AssertDriverContentsWithFrameAre ($"{buttonRow}", _output);
|
|
End (runstate);
|
|
|
|
// Left
|
|
buttonRow = $"{CM.Glyphs.VLine}{btn1} {btn2} {btn3} {btn4} {CM.Glyphs.VLine}";
|
|
Assert.Equal (width, buttonRow.Length);
|
|
|
|
(runstate, Dialog _) = RunButtonTestDialog (
|
|
title,
|
|
width,
|
|
Dialog.ButtonAlignments.Left,
|
|
new Button { Text = btn1Text },
|
|
new Button { Text = btn2Text },
|
|
new Button { Text = btn3Text },
|
|
new Button { Text = btn4Text }
|
|
);
|
|
TestHelpers.AssertDriverContentsWithFrameAre ($"{buttonRow}", _output);
|
|
End (runstate);
|
|
}
|
|
|
|
[Fact]
|
|
[AutoInitShutdown]
|
|
public void ButtonAlignment_Four_Wider ()
|
|
{
|
|
RunState runstate = null;
|
|
|
|
var d = (FakeDriver)Driver;
|
|
|
|
var title = "1234";
|
|
|
|
// E.g "|[ yes ][ no ][ maybe ]|"
|
|
var btn1Text = "yes";
|
|
var btn1 = $"{CM.Glyphs.LeftBracket} {btn1Text} {CM.Glyphs.RightBracket}";
|
|
var btn2Text = "no";
|
|
var btn2 = $"{CM.Glyphs.LeftBracket} {btn2Text} {CM.Glyphs.RightBracket}";
|
|
var btn3Text = "你你你你你"; // This is a wide char
|
|
var btn3 = $"{CM.Glyphs.LeftBracket} {btn3Text} {CM.Glyphs.RightBracket}";
|
|
|
|
// Requires a Nerd Font
|
|
var btn4Text = "\uE36E\uE36F\uE370\uE371\uE372\uE373";
|
|
var btn4 = $"{CM.Glyphs.LeftBracket} {btn4Text} {CM.Glyphs.RightBracket}";
|
|
|
|
// Note extra spaces to make dialog even wider
|
|
// 123456 123456
|
|
var buttonRow = $"{CM.Glyphs.VLine} {btn1} {btn2} {btn3} {btn4} {CM.Glyphs.VLine}";
|
|
int width = buttonRow.GetColumns ();
|
|
d.SetBufferSize (width, 3);
|
|
|
|
// Default - Center
|
|
(runstate, Dialog _) = RunButtonTestDialog (
|
|
title,
|
|
width,
|
|
Dialog.ButtonAlignments.Center,
|
|
new Button { Text = btn1Text },
|
|
new Button { Text = btn2Text },
|
|
new Button { Text = btn3Text },
|
|
new Button { Text = btn4Text }
|
|
);
|
|
TestHelpers.AssertDriverContentsWithFrameAre ($"{buttonRow}", _output);
|
|
End (runstate);
|
|
|
|
// Justify
|
|
buttonRow = $"{CM.Glyphs.VLine}{btn1} {btn2} {btn3} {btn4}{CM.Glyphs.VLine}";
|
|
Assert.Equal (width, buttonRow.GetColumns ());
|
|
|
|
(runstate, Dialog _) = RunButtonTestDialog (
|
|
title,
|
|
width,
|
|
Dialog.ButtonAlignments.Justify,
|
|
new Button { Text = btn1Text },
|
|
new Button { Text = btn2Text },
|
|
new Button { Text = btn3Text },
|
|
new Button { Text = btn4Text }
|
|
);
|
|
TestHelpers.AssertDriverContentsWithFrameAre ($"{buttonRow}", _output);
|
|
End (runstate);
|
|
|
|
// Right
|
|
buttonRow = $"{CM.Glyphs.VLine} {btn1} {btn2} {btn3} {btn4}{CM.Glyphs.VLine}";
|
|
Assert.Equal (width, buttonRow.GetColumns ());
|
|
|
|
(runstate, Dialog _) = RunButtonTestDialog (
|
|
title,
|
|
width,
|
|
Dialog.ButtonAlignments.Right,
|
|
new Button { Text = btn1Text },
|
|
new Button { Text = btn2Text },
|
|
new Button { Text = btn3Text },
|
|
new Button { Text = btn4Text }
|
|
);
|
|
TestHelpers.AssertDriverContentsWithFrameAre ($"{buttonRow}", _output);
|
|
End (runstate);
|
|
|
|
// Left
|
|
buttonRow = $"{CM.Glyphs.VLine}{btn1} {btn2} {btn3} {btn4} {CM.Glyphs.VLine}";
|
|
Assert.Equal (width, buttonRow.GetColumns ());
|
|
|
|
(runstate, Dialog _) = RunButtonTestDialog (
|
|
title,
|
|
width,
|
|
Dialog.ButtonAlignments.Left,
|
|
new Button { Text = btn1Text },
|
|
new Button { Text = btn2Text },
|
|
new Button { Text = btn3Text },
|
|
new Button { Text = btn4Text }
|
|
);
|
|
TestHelpers.AssertDriverContentsWithFrameAre ($"{buttonRow}", _output);
|
|
End (runstate);
|
|
}
|
|
|
|
[Fact]
|
|
[AutoInitShutdown]
|
|
public void ButtonAlignment_One ()
|
|
{
|
|
var d = (FakeDriver)Driver;
|
|
RunState runstate = null;
|
|
|
|
var title = "1234";
|
|
|
|
// E.g "|[ ok ]|"
|
|
var btnText = "ok";
|
|
|
|
var buttonRow =
|
|
$"{CM.Glyphs.VLine} {CM.Glyphs.LeftBracket} {btnText} {CM.Glyphs.RightBracket} {CM.Glyphs.VLine}";
|
|
int width = buttonRow.Length;
|
|
|
|
d.SetBufferSize (width, 1);
|
|
|
|
(runstate, Dialog _) = RunButtonTestDialog (
|
|
title,
|
|
width,
|
|
Dialog.ButtonAlignments.Center,
|
|
new Button { Text = btnText }
|
|
);
|
|
|
|
// Center
|
|
TestHelpers.AssertDriverContentsWithFrameAre ($"{buttonRow}", _output);
|
|
End (runstate);
|
|
|
|
// Justify
|
|
buttonRow =
|
|
$"{CM.Glyphs.VLine} {CM.Glyphs.LeftBracket} {btnText} {CM.Glyphs.RightBracket}{CM.Glyphs.VLine}";
|
|
Assert.Equal (width, buttonRow.Length);
|
|
|
|
(runstate, Dialog _) = RunButtonTestDialog (
|
|
title,
|
|
width,
|
|
Dialog.ButtonAlignments.Justify,
|
|
new Button { Text = btnText }
|
|
);
|
|
TestHelpers.AssertDriverContentsWithFrameAre ($"{buttonRow}", _output);
|
|
End (runstate);
|
|
|
|
// Right
|
|
buttonRow =
|
|
$"{CM.Glyphs.VLine} {CM.Glyphs.LeftBracket} {btnText} {CM.Glyphs.RightBracket}{CM.Glyphs.VLine}";
|
|
Assert.Equal (width, buttonRow.Length);
|
|
|
|
(runstate, Dialog _) = RunButtonTestDialog (
|
|
title,
|
|
width,
|
|
Dialog.ButtonAlignments.Right,
|
|
new Button { Text = btnText }
|
|
);
|
|
TestHelpers.AssertDriverContentsWithFrameAre ($"{buttonRow}", _output);
|
|
End (runstate);
|
|
|
|
// Left
|
|
buttonRow =
|
|
$"{CM.Glyphs.VLine}{CM.Glyphs.LeftBracket} {btnText} {CM.Glyphs.RightBracket} {CM.Glyphs.VLine}";
|
|
Assert.Equal (width, buttonRow.Length);
|
|
|
|
(runstate, Dialog _) = RunButtonTestDialog (
|
|
title,
|
|
width,
|
|
Dialog.ButtonAlignments.Left,
|
|
new Button { Text = btnText }
|
|
);
|
|
TestHelpers.AssertDriverContentsWithFrameAre ($"{buttonRow}", _output);
|
|
End (runstate);
|
|
|
|
// Wider
|
|
buttonRow =
|
|
$"{CM.Glyphs.VLine} {CM.Glyphs.LeftBracket} {btnText} {CM.Glyphs.RightBracket} {CM.Glyphs.VLine}";
|
|
width = buttonRow.Length;
|
|
|
|
d.SetBufferSize (width, 1);
|
|
|
|
(runstate, Dialog _) = RunButtonTestDialog (
|
|
title,
|
|
width,
|
|
Dialog.ButtonAlignments.Center,
|
|
new Button { Text = btnText }
|
|
);
|
|
TestHelpers.AssertDriverContentsWithFrameAre ($"{buttonRow}", _output);
|
|
End (runstate);
|
|
|
|
// Justify
|
|
buttonRow =
|
|
$"{CM.Glyphs.VLine} {CM.Glyphs.LeftBracket} {btnText} {CM.Glyphs.RightBracket}{CM.Glyphs.VLine}";
|
|
Assert.Equal (width, buttonRow.Length);
|
|
|
|
(runstate, Dialog _) = RunButtonTestDialog (
|
|
title,
|
|
width,
|
|
Dialog.ButtonAlignments.Justify,
|
|
new Button { Text = btnText }
|
|
);
|
|
TestHelpers.AssertDriverContentsWithFrameAre ($"{buttonRow}", _output);
|
|
End (runstate);
|
|
|
|
// Right
|
|
buttonRow =
|
|
$"{CM.Glyphs.VLine} {CM.Glyphs.LeftBracket} {btnText} {CM.Glyphs.RightBracket}{CM.Glyphs.VLine}";
|
|
Assert.Equal (width, buttonRow.Length);
|
|
|
|
(runstate, Dialog _) = RunButtonTestDialog (
|
|
title,
|
|
width,
|
|
Dialog.ButtonAlignments.Right,
|
|
new Button { Text = btnText }
|
|
);
|
|
TestHelpers.AssertDriverContentsWithFrameAre ($"{buttonRow}", _output);
|
|
End (runstate);
|
|
|
|
// Left
|
|
buttonRow =
|
|
$"{CM.Glyphs.VLine}{CM.Glyphs.LeftBracket} {btnText} {CM.Glyphs.RightBracket} {CM.Glyphs.VLine}";
|
|
Assert.Equal (width, buttonRow.Length);
|
|
|
|
(runstate, Dialog _) = RunButtonTestDialog (
|
|
title,
|
|
width,
|
|
Dialog.ButtonAlignments.Left,
|
|
new Button { Text = btnText }
|
|
);
|
|
TestHelpers.AssertDriverContentsWithFrameAre ($"{buttonRow}", _output);
|
|
End (runstate);
|
|
}
|
|
|
|
[Fact]
|
|
[AutoInitShutdown]
|
|
public void ButtonAlignment_Three ()
|
|
{
|
|
RunState runstate = null;
|
|
|
|
var d = (FakeDriver)Driver;
|
|
|
|
var title = "1234";
|
|
|
|
// E.g "|[ yes ][ no ][ maybe ]|"
|
|
var btn1Text = "yes";
|
|
var btn1 = $"{CM.Glyphs.LeftBracket} {btn1Text} {CM.Glyphs.RightBracket}";
|
|
var btn2Text = "no";
|
|
var btn2 = $"{CM.Glyphs.LeftBracket} {btn2Text} {CM.Glyphs.RightBracket}";
|
|
var btn3Text = "maybe";
|
|
var btn3 = $"{CM.Glyphs.LeftBracket} {btn3Text} {CM.Glyphs.RightBracket}";
|
|
|
|
var buttonRow = $@"{CM.Glyphs.VLine} {btn1} {btn2} {btn3} {CM.Glyphs.VLine}";
|
|
int width = buttonRow.Length;
|
|
|
|
d.SetBufferSize (buttonRow.Length, 3);
|
|
|
|
(runstate, Dialog _) = RunButtonTestDialog (
|
|
title,
|
|
width,
|
|
Dialog.ButtonAlignments.Center,
|
|
new Button { Text = btn1Text },
|
|
new Button { Text = btn2Text },
|
|
new Button { Text = btn3Text }
|
|
);
|
|
TestHelpers.AssertDriverContentsWithFrameAre ($"{buttonRow}", _output);
|
|
End (runstate);
|
|
|
|
// Justify
|
|
buttonRow = $@"{CM.Glyphs.VLine}{btn1} {btn2} {btn3}{CM.Glyphs.VLine}";
|
|
Assert.Equal (width, buttonRow.Length);
|
|
|
|
(runstate, Dialog _) = RunButtonTestDialog (
|
|
title,
|
|
width,
|
|
Dialog.ButtonAlignments.Justify,
|
|
new Button { Text = btn1Text },
|
|
new Button { Text = btn2Text },
|
|
new Button { Text = btn3Text }
|
|
);
|
|
TestHelpers.AssertDriverContentsWithFrameAre ($"{buttonRow}", _output);
|
|
End (runstate);
|
|
|
|
// Right
|
|
buttonRow = $@"{CM.Glyphs.VLine} {btn1} {btn2} {btn3}{CM.Glyphs.VLine}";
|
|
Assert.Equal (width, buttonRow.Length);
|
|
|
|
(runstate, Dialog _) = RunButtonTestDialog (
|
|
title,
|
|
width,
|
|
Dialog.ButtonAlignments.Right,
|
|
new Button { Text = btn1Text },
|
|
new Button { Text = btn2Text },
|
|
new Button { Text = btn3Text }
|
|
);
|
|
TestHelpers.AssertDriverContentsWithFrameAre ($"{buttonRow}", _output);
|
|
End (runstate);
|
|
|
|
// Left
|
|
buttonRow = $@"{CM.Glyphs.VLine}{btn1} {btn2} {btn3} {CM.Glyphs.VLine}";
|
|
Assert.Equal (width, buttonRow.Length);
|
|
|
|
(runstate, Dialog _) = RunButtonTestDialog (
|
|
title,
|
|
width,
|
|
Dialog.ButtonAlignments.Left,
|
|
new Button { Text = btn1Text },
|
|
new Button { Text = btn2Text },
|
|
new Button { Text = btn3Text }
|
|
);
|
|
TestHelpers.AssertDriverContentsWithFrameAre ($"{buttonRow}", _output);
|
|
End (runstate);
|
|
}
|
|
|
|
[Fact]
|
|
[AutoInitShutdown]
|
|
public void ButtonAlignment_Two ()
|
|
{
|
|
RunState runstate = null;
|
|
|
|
var d = (FakeDriver)Driver;
|
|
|
|
var title = "1234";
|
|
|
|
// E.g "|[ yes ][ no ]|"
|
|
var btn1Text = "yes";
|
|
var btn1 = $"{CM.Glyphs.LeftBracket} {btn1Text} {CM.Glyphs.RightBracket}";
|
|
var btn2Text = "no";
|
|
var btn2 = $"{CM.Glyphs.LeftBracket} {btn2Text} {CM.Glyphs.RightBracket}";
|
|
|
|
var buttonRow = $@"{CM.Glyphs.VLine} {btn1} {btn2} {CM.Glyphs.VLine}";
|
|
int width = buttonRow.Length;
|
|
|
|
d.SetBufferSize (buttonRow.Length, 3);
|
|
|
|
(runstate, Dialog _) = RunButtonTestDialog (
|
|
title,
|
|
width,
|
|
Dialog.ButtonAlignments.Center,
|
|
new Button { Text = btn1Text },
|
|
new Button { Text = btn2Text }
|
|
);
|
|
TestHelpers.AssertDriverContentsWithFrameAre ($"{buttonRow}", _output);
|
|
End (runstate);
|
|
|
|
// Justify
|
|
buttonRow = $@"{CM.Glyphs.VLine}{btn1} {btn2}{CM.Glyphs.VLine}";
|
|
Assert.Equal (width, buttonRow.Length);
|
|
|
|
(runstate, Dialog _) = RunButtonTestDialog (
|
|
title,
|
|
width,
|
|
Dialog.ButtonAlignments.Justify,
|
|
new Button { Text = btn1Text },
|
|
new Button { Text = btn2Text }
|
|
);
|
|
TestHelpers.AssertDriverContentsWithFrameAre ($"{buttonRow}", _output);
|
|
End (runstate);
|
|
|
|
// Right
|
|
buttonRow = $@"{CM.Glyphs.VLine} {btn1} {btn2}{CM.Glyphs.VLine}";
|
|
Assert.Equal (width, buttonRow.Length);
|
|
|
|
(runstate, Dialog _) = RunButtonTestDialog (
|
|
title,
|
|
width,
|
|
Dialog.ButtonAlignments.Right,
|
|
new Button { Text = btn1Text },
|
|
new Button { Text = btn2Text }
|
|
);
|
|
TestHelpers.AssertDriverContentsWithFrameAre ($"{buttonRow}", _output);
|
|
End (runstate);
|
|
|
|
// Left
|
|
buttonRow = $@"{CM.Glyphs.VLine}{btn1} {btn2} {CM.Glyphs.VLine}";
|
|
Assert.Equal (width, buttonRow.Length);
|
|
|
|
(runstate, Dialog _) = RunButtonTestDialog (
|
|
title,
|
|
width,
|
|
Dialog.ButtonAlignments.Left,
|
|
new Button { Text = btn1Text },
|
|
new Button { Text = btn2Text }
|
|
);
|
|
TestHelpers.AssertDriverContentsWithFrameAre ($"{buttonRow}", _output);
|
|
End (runstate);
|
|
}
|
|
|
|
[Fact]
|
|
[AutoInitShutdown]
|
|
public void ButtonAlignment_Two_Hidden ()
|
|
{
|
|
RunState runstate = null;
|
|
var firstIteration = false;
|
|
|
|
var d = (FakeDriver)Driver;
|
|
|
|
var title = "1234";
|
|
|
|
// E.g "|[ yes ][ no ]|"
|
|
var btn1Text = "yes";
|
|
var btn1 = $"{CM.Glyphs.LeftBracket} {btn1Text} {CM.Glyphs.RightBracket}";
|
|
var btn2Text = "no";
|
|
var btn2 = $"{CM.Glyphs.LeftBracket} {btn2Text} {CM.Glyphs.RightBracket}";
|
|
|
|
var buttonRow = $@"{CM.Glyphs.VLine} {btn1} {btn2} {CM.Glyphs.VLine}";
|
|
int width = buttonRow.Length;
|
|
|
|
d.SetBufferSize (buttonRow.Length, 3);
|
|
|
|
Dialog dlg = null;
|
|
Button button1, button2;
|
|
|
|
// Default (Center)
|
|
button1 = new Button { Text = btn1Text };
|
|
button2 = new Button { Text = btn2Text };
|
|
(runstate, dlg) = RunButtonTestDialog (title, width, Dialog.ButtonAlignments.Center, button1, button2);
|
|
button1.Visible = false;
|
|
RunIteration (ref runstate, ref firstIteration);
|
|
buttonRow = $@"{CM.Glyphs.VLine} {btn2} {CM.Glyphs.VLine}";
|
|
TestHelpers.AssertDriverContentsWithFrameAre ($"{buttonRow}", _output);
|
|
End (runstate);
|
|
|
|
// Justify
|
|
Assert.Equal (width, buttonRow.Length);
|
|
button1 = new Button { Text = btn1Text };
|
|
button2 = new Button { Text = btn2Text };
|
|
(runstate, dlg) = RunButtonTestDialog (title, width, Dialog.ButtonAlignments.Justify, button1, button2);
|
|
button1.Visible = false;
|
|
RunIteration (ref runstate, ref firstIteration);
|
|
buttonRow = $@"{CM.Glyphs.VLine} {btn2}{CM.Glyphs.VLine}";
|
|
TestHelpers.AssertDriverContentsWithFrameAre ($"{buttonRow}", _output);
|
|
End (runstate);
|
|
|
|
// Right
|
|
Assert.Equal (width, buttonRow.Length);
|
|
button1 = new Button { Text = btn1Text };
|
|
button2 = new Button { Text = btn2Text };
|
|
(runstate, dlg) = RunButtonTestDialog (title, width, Dialog.ButtonAlignments.Right, button1, button2);
|
|
button1.Visible = false;
|
|
RunIteration (ref runstate, ref firstIteration);
|
|
TestHelpers.AssertDriverContentsWithFrameAre ($"{buttonRow}", _output);
|
|
End (runstate);
|
|
|
|
// Left
|
|
Assert.Equal (width, buttonRow.Length);
|
|
button1 = new Button { Text = btn1Text };
|
|
button2 = new Button { Text = btn2Text };
|
|
(runstate, dlg) = RunButtonTestDialog (title, width, Dialog.ButtonAlignments.Left, button1, button2);
|
|
button1.Visible = false;
|
|
RunIteration (ref runstate, ref firstIteration);
|
|
buttonRow = $@"{CM.Glyphs.VLine} {btn2} {CM.Glyphs.VLine}";
|
|
TestHelpers.AssertDriverContentsWithFrameAre ($"{buttonRow}", _output);
|
|
End (runstate);
|
|
}
|
|
|
|
[Fact]
|
|
[AutoInitShutdown]
|
|
public void Dialog_In_Window_With_Size_One_Button_Aligns ()
|
|
{
|
|
((FakeDriver)Driver).SetBufferSize (20, 5);
|
|
|
|
var win = new Window ();
|
|
|
|
var iterations = 0;
|
|
|
|
Iteration += (s, a) =>
|
|
{
|
|
if (++iterations > 2)
|
|
{
|
|
RequestStop ();
|
|
}
|
|
};
|
|
var btn = $"{CM.Glyphs.LeftBracket} Ok {CM.Glyphs.RightBracket}";
|
|
|
|
win.Loaded += (s, a) =>
|
|
{
|
|
var dlg = new Dialog { Width = 18, Height = 3, Buttons = [new Button { Text = "Ok" }] };
|
|
|
|
dlg.Loaded += (s, a) =>
|
|
{
|
|
Refresh ();
|
|
|
|
var expected = @$"
|
|
┌──────────────────┐
|
|
│┌────────────────┐│
|
|
││ {
|
|
btn
|
|
} ││
|
|
│└────────────────┘│
|
|
└──────────────────┘";
|
|
_ = TestHelpers.AssertDriverContentsWithFrameAre (expected, _output);
|
|
};
|
|
|
|
Run (dlg);
|
|
};
|
|
Run (win);
|
|
}
|
|
|
|
[Theory]
|
|
[AutoInitShutdown]
|
|
[InlineData (
|
|
5,
|
|
@"
|
|
┌┌───────────────┐─┐
|
|
││ │ │
|
|
││ ⟦ Ok ⟧ │ │
|
|
│└───────────────┘ │
|
|
└──────────────────┘"
|
|
)]
|
|
[InlineData (
|
|
6,
|
|
@"
|
|
┌┌───────────────┐─┐
|
|
││ │ │
|
|
││ │ │
|
|
││ ⟦ Ok ⟧ │ │
|
|
│└───────────────┘ │
|
|
└──────────────────┘"
|
|
)]
|
|
[InlineData (
|
|
7,
|
|
@"
|
|
┌──────────────────┐
|
|
│┌───────────────┐ │
|
|
││ │ │
|
|
││ │ │
|
|
││ ⟦ Ok ⟧ │ │
|
|
│└───────────────┘ │
|
|
└──────────────────┘"
|
|
)]
|
|
[InlineData (
|
|
8,
|
|
@"
|
|
┌──────────────────┐
|
|
│┌───────────────┐ │
|
|
││ │ │
|
|
││ │ │
|
|
││ │ │
|
|
││ ⟦ Ok ⟧ │ │
|
|
│└───────────────┘ │
|
|
└──────────────────┘"
|
|
)]
|
|
[InlineData (
|
|
9,
|
|
@"
|
|
┌──────────────────┐
|
|
│┌───────────────┐ │
|
|
││ │ │
|
|
││ │ │
|
|
││ │ │
|
|
││ │ │
|
|
││ ⟦ Ok ⟧ │ │
|
|
│└───────────────┘ │
|
|
└──────────────────┘"
|
|
)]
|
|
public void Dialog_In_Window_Without_Size_One_Button_Aligns (int height, string expected)
|
|
{
|
|
((FakeDriver)Driver).SetBufferSize (20, height);
|
|
var win = new Window ();
|
|
|
|
int iterations = -1;
|
|
|
|
Iteration += (s, a) =>
|
|
{
|
|
iterations++;
|
|
|
|
if (iterations == 0)
|
|
{
|
|
var dlg = new Dialog { Buttons = [new Button { Text = "Ok" }] };
|
|
Run (dlg);
|
|
}
|
|
else if (iterations == 1)
|
|
{
|
|
// BUGBUG: This seems wrong; is it a bug in Dim.Percent(85)?? No
|
|
_ = TestHelpers.AssertDriverContentsWithFrameAre (expected, _output);
|
|
}
|
|
else
|
|
{
|
|
RequestStop ();
|
|
}
|
|
};
|
|
|
|
Run (win);
|
|
}
|
|
|
|
[Fact]
|
|
[AutoInitShutdown]
|
|
public void Dialog_Opened_From_Another_Dialog ()
|
|
{
|
|
((FakeDriver)Driver).SetBufferSize (30, 10);
|
|
|
|
var btn1 = new Button { Text = "press me 1" };
|
|
Button btn2 = null;
|
|
Button btn3 = null;
|
|
string expected = null;
|
|
|
|
btn1.Clicked += (s, e) =>
|
|
{
|
|
btn2 = new Button { Text = "Show Sub" };
|
|
btn3 = new Button { Text = "Close" };
|
|
btn3.Clicked += (s, e) => RequestStop ();
|
|
|
|
btn2.Clicked += (s, e) =>
|
|
{
|
|
// Don't test MessageBox in Dialog unit tests!
|
|
var subBtn = new Button { Text = "Ok", IsDefault = true };
|
|
var subDlg = new Dialog { Text = "ya", Width = 20, Height = 5, Buttons = [subBtn] };
|
|
subBtn.Clicked += (s, e) => RequestStop (subDlg);
|
|
Run (subDlg);
|
|
};
|
|
var dlg = new Dialog { Buttons = [btn2, btn3] };
|
|
|
|
Run (dlg);
|
|
};
|
|
|
|
var btn =
|
|
$"{
|
|
CM.Glyphs.LeftBracket
|
|
}{
|
|
CM.Glyphs.LeftDefaultIndicator
|
|
} Ok {
|
|
CM.Glyphs.RightDefaultIndicator
|
|
}{
|
|
CM.Glyphs.RightBracket
|
|
}";
|
|
|
|
int iterations = -1;
|
|
|
|
Iteration += (s, a) =>
|
|
{
|
|
iterations++;
|
|
|
|
if (iterations == 0)
|
|
{
|
|
Assert.True (btn1.NewKeyDownEvent (new Key (KeyCode.Space)));
|
|
}
|
|
else if (iterations == 1)
|
|
{
|
|
expected = @$"
|
|
┌───────────────────────┐
|
|
│ │
|
|
│ │
|
|
│ │
|
|
│ │
|
|
│ │
|
|
│{
|
|
CM.Glyphs.LeftBracket
|
|
} Show Sub {
|
|
CM.Glyphs.RightBracket
|
|
} {
|
|
CM.Glyphs.LeftBracket
|
|
} Close {
|
|
CM.Glyphs.RightBracket
|
|
} │
|
|
└───────────────────────┘";
|
|
TestHelpers.AssertDriverContentsWithFrameAre (expected, _output);
|
|
|
|
Assert.True (btn2.NewKeyDownEvent (new Key (KeyCode.Space)));
|
|
}
|
|
else if (iterations == 2)
|
|
{
|
|
TestHelpers.AssertDriverContentsWithFrameAre (
|
|
@$"
|
|
┌───────────────────────┐
|
|
│ ┌──────────────────┐ │
|
|
│ │ya │ │
|
|
│ │ │ │
|
|
│ │ {
|
|
btn
|
|
} │ │
|
|
│ └──────────────────┘ │
|
|
│{
|
|
CM.Glyphs.LeftBracket
|
|
} Show Sub {
|
|
CM.Glyphs.RightBracket
|
|
} {
|
|
CM.Glyphs.LeftBracket
|
|
} Close {
|
|
CM.Glyphs.RightBracket
|
|
} │
|
|
└───────────────────────┘",
|
|
_output
|
|
);
|
|
|
|
Assert.True (Current.NewKeyDownEvent (new Key (KeyCode.Enter)));
|
|
}
|
|
else if (iterations == 3)
|
|
{
|
|
TestHelpers.AssertDriverContentsWithFrameAre (expected, _output);
|
|
|
|
Assert.True (btn3.NewKeyDownEvent (new Key (KeyCode.Space)));
|
|
}
|
|
else if (iterations == 4)
|
|
{
|
|
TestHelpers.AssertDriverContentsWithFrameAre ("", _output);
|
|
|
|
RequestStop ();
|
|
}
|
|
};
|
|
|
|
Run ();
|
|
Shutdown ();
|
|
|
|
Assert.Equal (4, iterations);
|
|
}
|
|
|
|
[Fact]
|
|
[AutoInitShutdown]
|
|
public void FileDialog_FileSystemWatcher ()
|
|
{
|
|
for (var i = 0; i < 8; i++)
|
|
{
|
|
var fd = new FileDialog ();
|
|
fd.Ready += (s, e) => RequestStop ();
|
|
Run (fd);
|
|
}
|
|
}
|
|
|
|
[Fact]
|
|
[AutoInitShutdown]
|
|
public void Location_Default ()
|
|
{
|
|
var d = new Dialog ();
|
|
Begin (d);
|
|
((FakeDriver)Driver).SetBufferSize (100, 100);
|
|
|
|
// Default location is centered, so 100 / 2 - 85 / 2 = 7
|
|
var expected = 7;
|
|
Assert.Equal (new Point (expected, expected), d.Frame.Location);
|
|
}
|
|
|
|
[Fact]
|
|
[AutoInitShutdown]
|
|
public void Location_Not_Default ()
|
|
{
|
|
var d = new Dialog { X = 1, Y = 1 };
|
|
Begin (d);
|
|
((FakeDriver)Driver).SetBufferSize (100, 100);
|
|
|
|
// Default location is centered, so 100 / 2 - 85 / 2 = 7
|
|
var expected = 1;
|
|
Assert.Equal (new Point (expected, expected), d.Frame.Location);
|
|
}
|
|
|
|
[Fact]
|
|
[AutoInitShutdown]
|
|
public void Location_When_Application_Top_Not_Default ()
|
|
{
|
|
var expected = 5;
|
|
var d = new Dialog { X = expected, Y = expected, Height = 5, Width = 5 };
|
|
Begin (d);
|
|
((FakeDriver)Driver).SetBufferSize (20, 10);
|
|
|
|
// Default location is centered, so 100 / 2 - 85 / 2 = 7
|
|
Assert.Equal (new Point (expected, expected), d.Frame.Location);
|
|
|
|
TestHelpers.AssertDriverContentsWithFrameAre (
|
|
@"
|
|
┌───┐
|
|
│ │
|
|
│ │
|
|
│ │
|
|
└───┘",
|
|
_output
|
|
);
|
|
}
|
|
|
|
[Fact]
|
|
[AutoInitShutdown]
|
|
public void Location_When_Not_Application_Top_Not_Default ()
|
|
{
|
|
Top.BorderStyle = LineStyle.Double;
|
|
|
|
int iterations = -1;
|
|
|
|
Iteration += (s, a) =>
|
|
{
|
|
iterations++;
|
|
|
|
if (iterations == 0)
|
|
{
|
|
var d = new Dialog { X = 5, Y = 5, Height = 3, Width = 5 };
|
|
Begin (d);
|
|
|
|
Assert.Equal (new Point (5, 5), d.Frame.Location);
|
|
|
|
TestHelpers.AssertDriverContentsWithFrameAre (
|
|
@"
|
|
╔══════════════════╗
|
|
║ ║
|
|
║ ║
|
|
║ ║
|
|
║ ║
|
|
║ ┌───┐ ║
|
|
║ │ │ ║
|
|
║ └───┘ ║
|
|
║ ║
|
|
╚══════════════════╝",
|
|
_output
|
|
);
|
|
|
|
d = new Dialog { X = 5, Y = 5 };
|
|
Begin (d);
|
|
|
|
// This is because of PostionTopLevels and EnsureVisibleBounds
|
|
Assert.Equal (new Point (3, 2), d.Frame.Location);
|
|
|
|
// #3127: Before
|
|
// Assert.Equal (new Size (17, 8), d.Frame.Size);
|
|
// TestHelpers.AssertDriverContentsWithFrameAre (@"
|
|
//╔══════════════════╗
|
|
//║ ║
|
|
//║ ┌───────────────┐
|
|
//║ │ │
|
|
//║ │ │
|
|
//║ │ │
|
|
//║ │ │
|
|
//║ │ │
|
|
//║ │ │
|
|
//╚══└───────────────┘", _output);
|
|
|
|
// #3127: After: Because Toplevel is now Width/Height = Dim.Filll
|
|
Assert.Equal (new Size (15, 6), d.Frame.Size);
|
|
|
|
TestHelpers.AssertDriverContentsWithFrameAre (
|
|
@"
|
|
╔══════════════════╗
|
|
║ ║
|
|
║ ┌─────────────┐ ║
|
|
║ │ │ ║
|
|
║ │ │ ║
|
|
║ │ │ ║
|
|
║ │ │ ║
|
|
║ └─────────────┘ ║
|
|
║ ║
|
|
╚══════════════════╝",
|
|
_output
|
|
);
|
|
}
|
|
else if (iterations > 0)
|
|
{
|
|
RequestStop ();
|
|
}
|
|
};
|
|
|
|
Begin (Top);
|
|
((FakeDriver)Driver).SetBufferSize (20, 10);
|
|
Run ();
|
|
}
|
|
|
|
[Fact]
|
|
[AutoInitShutdown]
|
|
public void One_Button_Works ()
|
|
{
|
|
RunState runstate = null;
|
|
|
|
var d = (FakeDriver)Driver;
|
|
|
|
var title = "";
|
|
var btnText = "ok";
|
|
|
|
var buttonRow =
|
|
$"{CM.Glyphs.VLine} {CM.Glyphs.LeftBracket} {btnText} {CM.Glyphs.RightBracket} {CM.Glyphs.VLine}";
|
|
|
|
int width = buttonRow.Length;
|
|
d.SetBufferSize (buttonRow.Length, 10);
|
|
|
|
(runstate, Dialog _) = RunButtonTestDialog (
|
|
title,
|
|
width,
|
|
Dialog.ButtonAlignments.Center,
|
|
new Button { Text = btnText }
|
|
);
|
|
TestHelpers.AssertDriverContentsWithFrameAre ($"{buttonRow}", _output);
|
|
End (runstate);
|
|
}
|
|
|
|
[Fact]
|
|
[AutoInitShutdown]
|
|
public void Size_Default ()
|
|
{
|
|
var d = new Dialog ();
|
|
Begin (d);
|
|
((FakeDriver)Driver).SetBufferSize (100, 100);
|
|
|
|
// Default size is Percent(85)
|
|
Assert.Equal (new Size ((int)(100 * .85), (int)(100 * .85)), d.Frame.Size);
|
|
}
|
|
|
|
[Fact]
|
|
[AutoInitShutdown]
|
|
public void Size_Not_Default ()
|
|
{
|
|
var d = new Dialog { Width = 50, Height = 50 };
|
|
|
|
Begin (d);
|
|
((FakeDriver)Driver).SetBufferSize (100, 100);
|
|
|
|
// Default size is Percent(85)
|
|
Assert.Equal (new Size (50, 50), d.Frame.Size);
|
|
}
|
|
|
|
[Fact]
|
|
[AutoInitShutdown]
|
|
public void Zero_Buttons_Works ()
|
|
{
|
|
RunState runstate = null;
|
|
|
|
var d = (FakeDriver)Driver;
|
|
|
|
var title = "1234";
|
|
|
|
var buttonRow = $"{CM.Glyphs.VLine} {CM.Glyphs.VLine}";
|
|
int width = buttonRow.Length;
|
|
d.SetBufferSize (buttonRow.Length, 3);
|
|
|
|
(runstate, Dialog _) = RunButtonTestDialog (title, width, Dialog.ButtonAlignments.Center, null);
|
|
TestHelpers.AssertDriverContentsWithFrameAre ($"{buttonRow}", _output);
|
|
|
|
End (runstate);
|
|
}
|
|
|
|
private (RunState, Dialog) RunButtonTestDialog (
|
|
string title,
|
|
int width,
|
|
Dialog.ButtonAlignments align,
|
|
params Button [] btns
|
|
)
|
|
{
|
|
var dlg = new Dialog
|
|
{
|
|
Title = title,
|
|
X = 0,
|
|
Y = 0,
|
|
Width = width,
|
|
Height = 1,
|
|
ButtonAlignment = align,
|
|
Buttons = btns
|
|
};
|
|
|
|
// Create with no top or bottom border to simplify testing button layout (no need to account for title etc..)
|
|
dlg.Border.Thickness = new Thickness (1, 0, 1, 0);
|
|
|
|
return (Begin (dlg), dlg);
|
|
}
|
|
}
|