mirror of
https://github.com/gui-cs/Terminal.Gui.git
synced 2025-12-26 15:57:56 +01:00
* Consider width2 chars that are not IsBmp
* Apply same fix in WindowsDriver
* Explicitly use type of local variable
* Revert changes to WindowsDriver
* Assume we are running in a terminal that supports true color by default unless user explicitly forces 16
* Switch to SetAttribute and WriteConsole instead of WriteConsoleOutput for 16 color mode
* Fix some cursor issues (WIP)
* Remove concept of 'dirty rows' from v2 as its never actually used
* Remove damageRegion as it does nothing
* Make string builder to console writing simpler
* Radically simplify Write method
* Simplify conditional logic
* Simplify restoring cursor position
* Reference local variable for console buffer
* Reduce calls to ConsoleWrite by accumulating till attribute changes
* When resizing v2 16 color mode on windows, recreate the back buffer to match its size
* Fixes for VTS enabled
* Fix _lastSize never being assigned
* Fixes VTS for Force16Colors
* Fixes force16Colors in VTS
* Fixes escape sequences always echoing in non-VTS
* Force Force16Colors in non-VTS. It have a bug in adding a newline in the last line
* WIP Add base class for NetOutput
* Abstract away how we change attribute
* WIP - Make WindowsOutput use base class
* WIP working to fix set cursor position
* Remove commented out code
* Fixes legacy output mode
* Fixes size with no alt buffer supported on VTS and size restore after maximized.
* Fix set cursor which also fixes the broken surrogate pairs
* Add force parameter
* Fixes an issue that only happens with Windows Terminal when paste surrogate pairs by press Ctrl+V
* In Windows escape sequences must be sent during the lifetime of the console which is created in input handle
* Ensure flush the input buffer before reset the console
* Flush input buffer before reset console in v2win
* Fixes issue in v2net not being refreshing the menu bar at start
* Only force layout and draw on size changed.
* Fix v2net issue not draw first line by forcing set cursor position
* Set _lastCursorPosition nullable and remove bool force from set cursor position
* Remove force parameter
* Add v2 version of fake driver attribute
* Make direct replacement and wire up window resizing events
* Update casts to use V2 fake driver instead
* Adjust interfaces to expose less internals
* Fix not raising iteration event in v2
* WIP investigate what it takes to do resize and redraw using TextAlignment_Centered as example
* Sketch adding component factory
* Create relevant fake component factories
* Add window size monitor into factory
* Fake size monitor injecting
* Add helper for faking console resize in AutoInitShutdown tests
* Fix size setting in FakeDriverV2
* Switch to new method
* Fix IsLegacy becoming false when using blank constructor
* Fix for Ready not being raised when showing same top twice also fixes garbage collection issue if running millions of top levels
* Fix tests
* Remove auto init
* Restore conditional compilation stuff
* Restore 'if running unit tests' logic
* Check only for the output being specific classes for the suppression
* Fix ShadowView blowing up with index out of bounds error
* Fix resize in fluent tests
* Fix for people using Iteration call directly
* Fix more calls to iteration to use
AutoInitShutdownAttribute.RunIteration ();
* Add comment
* Remove assumption that Run with prior view not disposed should throw
* Fix timings in Dialog_Opened_From_Another_Dialog
* Fix Zero_Buttons_Works
* Standardize and fix Button_IsDefault_True_Return_His_Index_On_Accepting
* Fix iteration counts on MessageBoxTests
* Fix WizartTests and DrawTests_Ruler
* Implement SendKeys into ConsoleDriverFacade
* Fix SendKeys in console driver facade such that FileDialogTests works
Fix when Clip is null in popover
* Add missing dispose call to test
* Fix support for Esc in facade SendKeys
* Fix AutocompleteTests
* Fix various tests
* Replace LayoutAndDraw with run iteration
* Fix draw issues
* fix draw order
* Fix run iteration calls
* Fix unit tests
* Fix SendKeys in facade.
* Manipulate upper and lower cases.
* Add IsValidInput method to the interface.
* Fix SendKeys scenario
* Fixes surrogate pairs in the label
* Make tests more sensible - they are testing draw functionality. Callbacks do not need to happen in Iteration method
* Fix tests and harden cleanup in AutoInitShutdownAttribute v2 lifecycle dispose
* Delete extra create input call
* Fix mocks and order of exceptions thrown in Run when things are not initialized
* Revert use of `MapConsoleKeyInfoToKeyCode`
* Ignore casing as it is not what test is really about
* Clear application top and top levels before each auto init shutdown test
* Fix for unstable tests
* Restore actually working SendKeys code
* option to pass logger in fluent ctor
* restore ToArray
* Fix SendKeys method and add extension to unit test
* Leverage the EscSeqUtils.MapConsoleKeyInfo method to avoid duplicate code
* Remove unnecessary hack
* Using only KeyCode for rKeys
* Recover modifier keys in surrogate pairs
* Reformat
* Remove iteration limit for benchmarking in v2
* remove iteration delay to identify bugs
* Remove nudge to unique key and make Then run on UI thread
* fix fluid assertions
* Ensure UI operations all happen on UI thread
* Add explicit error for WaitIteration during an invoke
* Remove timeout added for debug
* Catch failing asserts better
* Fix screenshot
* Fix null ref
* Fix race condition in processing input
* Test fixing
* Standardize asserts
* Remove calls to layout and draw, remove pointless lock and enable reading Cancelled from Dialog even if it is disposed
* fix bad merge
* Make logs access threadsafe
* add extra wait to remove race between iteration end and assert
* Code cleanup
* Remove test for crash on access Cancelled after dispose as this is no longer a restriction
* Change resize console to run on UI thread - fixing race condition with redrawing
* Restore original frame rate after test
* Restore nudge to unique key
* Code Cleanup
* Fix for cascading failures when an assert fails in a specific test
* fix for bad merge
* Address PR feedback
* Move classes to seperate files and add xmldoc
* xml doc warnings
* More xml comments docs
* Fix spelling
---------
Co-authored-by: BDisp <bd.bdisp@gmail.com>
724 lines
22 KiB
C#
724 lines
22 KiB
C#
using UnitTests;
|
|
using Xunit.Abstractions;
|
|
|
|
namespace Terminal.Gui.DialogTests;
|
|
|
|
public class WizardTests ()
|
|
{
|
|
// =========== Wizard Tests
|
|
[Fact]
|
|
public void DefaultConstructor_SizedProperly ()
|
|
{
|
|
var wizard = new Wizard ();
|
|
Assert.NotEqual (0, wizard.Width);
|
|
Assert.NotEqual (0, wizard.Height);
|
|
wizard.Dispose ();
|
|
}
|
|
|
|
[Fact]
|
|
[AutoInitShutdown]
|
|
public void Finish_Button_Closes ()
|
|
{
|
|
// https://github.com/gui-cs/Terminal.Gui/issues/1833
|
|
var wizard = new Wizard ();
|
|
var step1 = new WizardStep { Title = "step1" };
|
|
wizard.AddStep (step1);
|
|
|
|
var finishedFired = false;
|
|
wizard.Finished += (s, args) => { finishedFired = true; };
|
|
|
|
var closedFired = false;
|
|
wizard.Closed += (s, e) => { closedFired = true; };
|
|
|
|
RunState runstate = Application.Begin (wizard);
|
|
var firstIteration = true;
|
|
Application.RunIteration (ref runstate, firstIteration);
|
|
|
|
wizard.NextFinishButton.InvokeCommand (Command.Accept);
|
|
Application.RunIteration (ref runstate, firstIteration);
|
|
Application.End (runstate);
|
|
Assert.True (finishedFired);
|
|
Assert.True (closedFired);
|
|
step1.Dispose ();
|
|
wizard.Dispose ();
|
|
|
|
// Same test, but with two steps
|
|
wizard = new ();
|
|
firstIteration = false;
|
|
step1 = new() { Title = "step1" };
|
|
wizard.AddStep (step1);
|
|
var step2 = new WizardStep { Title = "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.RunIteration (ref runstate, firstIteration);
|
|
|
|
Assert.Equal (step1.Title, wizard.CurrentStep.Title);
|
|
wizard.NextFinishButton.InvokeCommand (Command.Accept);
|
|
Assert.False (finishedFired);
|
|
Assert.False (closedFired);
|
|
|
|
Assert.Equal (step2.Title, wizard.CurrentStep.Title);
|
|
Assert.Equal (wizard.GetLastStep ().Title, wizard.CurrentStep.Title);
|
|
wizard.NextFinishButton.InvokeCommand (Command.Accept);
|
|
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 ();
|
|
firstIteration = false;
|
|
step1 = new() { Title = "step1" };
|
|
wizard.AddStep (step1);
|
|
step2 = new() { Title = "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.RunIteration (ref runstate, firstIteration);
|
|
|
|
Assert.Equal (step2.Title, wizard.CurrentStep.Title);
|
|
Assert.Equal (wizard.GetLastStep ().Title, wizard.CurrentStep.Title);
|
|
wizard.NextFinishButton.InvokeCommand (Command.Accept);
|
|
Application.End (runstate);
|
|
Assert.True (finishedFired);
|
|
Assert.True (closedFired);
|
|
wizard.Dispose ();
|
|
}
|
|
|
|
[Fact]
|
|
public void Navigate_GetFirstStep_Works ()
|
|
{
|
|
var wizard = new Wizard ();
|
|
|
|
Assert.Null (wizard.GetFirstStep ());
|
|
|
|
var step1 = new WizardStep { Title = "step1" };
|
|
wizard.AddStep (step1);
|
|
Assert.Equal (step1.Title, wizard.GetFirstStep ().Title);
|
|
|
|
var step2 = new WizardStep { Title = "step2" };
|
|
wizard.AddStep (step2);
|
|
Assert.Equal (step1.Title, wizard.GetFirstStep ().Title);
|
|
|
|
var step3 = new WizardStep { Title = "step3" };
|
|
wizard.AddStep (step3);
|
|
Assert.Equal (step1.Title, wizard.GetFirstStep ().Title);
|
|
|
|
step1.Enabled = false;
|
|
Assert.Equal (step2.Title, wizard.GetFirstStep ().Title);
|
|
|
|
step1.Enabled = true;
|
|
Assert.Equal (step1.Title, wizard.GetFirstStep ().Title);
|
|
|
|
step1.Enabled = false;
|
|
step2.Enabled = false;
|
|
Assert.Equal (step3.Title, wizard.GetFirstStep ().Title);
|
|
wizard.Dispose ();
|
|
}
|
|
|
|
[Fact]
|
|
public void Navigate_GetLastStep_Works ()
|
|
{
|
|
var wizard = new Wizard ();
|
|
|
|
Assert.Null (wizard.GetLastStep ());
|
|
|
|
var step1 = new WizardStep { Title = "step1" };
|
|
wizard.AddStep (step1);
|
|
Assert.Equal (step1.Title, wizard.GetLastStep ().Title);
|
|
|
|
var step2 = new WizardStep { Title = "step2" };
|
|
wizard.AddStep (step2);
|
|
Assert.Equal (step2.Title, wizard.GetLastStep ().Title);
|
|
|
|
var step3 = new WizardStep { Title = "step3" };
|
|
wizard.AddStep (step3);
|
|
Assert.Equal (step3.Title, wizard.GetLastStep ().Title);
|
|
|
|
step3.Enabled = false;
|
|
Assert.Equal (step2.Title, wizard.GetLastStep ().Title);
|
|
|
|
step3.Enabled = true;
|
|
Assert.Equal (step3.Title, wizard.GetLastStep ().Title);
|
|
|
|
step3.Enabled = false;
|
|
step2.Enabled = false;
|
|
Assert.Equal (step1.Title, wizard.GetLastStep ().Title);
|
|
wizard.Dispose ();
|
|
}
|
|
|
|
[Fact]
|
|
[AutoInitShutdown]
|
|
public void Navigate_GetNextStep_Correct ()
|
|
{
|
|
var wizard = new Wizard ();
|
|
|
|
// If no steps should be null
|
|
Assert.Null (wizard.GetNextStep ());
|
|
|
|
var step1 = new WizardStep { Title = "step1" };
|
|
wizard.AddStep (step1);
|
|
|
|
// If no current step, should be first step
|
|
Assert.Equal (step1.Title, wizard.GetNextStep ().Title);
|
|
|
|
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 WizardStep { Title = "step2" };
|
|
wizard.AddStep (step2);
|
|
Assert.Equal (step2.Title, wizard.GetNextStep ().Title);
|
|
|
|
// 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 WizardStep { Title = "step3" };
|
|
wizard.AddStep (step3);
|
|
step1.Enabled = true;
|
|
wizard.CurrentStep = step1;
|
|
step2.Enabled = true;
|
|
step3.Enabled = true;
|
|
Assert.Equal (step2.Title, wizard.GetNextStep ().Title);
|
|
wizard.CurrentStep = step2;
|
|
Assert.Equal (step3.Title, wizard.GetNextStep ().Title);
|
|
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, wizard.GetNextStep ().Title);
|
|
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, wizard.GetNextStep ().Title);
|
|
|
|
step1.Enabled = false;
|
|
step2.Enabled = true;
|
|
step3.Enabled = true;
|
|
Assert.Equal (step2.Title, wizard.GetNextStep ().Title);
|
|
|
|
step1.Enabled = false;
|
|
step2.Enabled = false;
|
|
step3.Enabled = true;
|
|
Assert.Equal (step3.Title, wizard.GetNextStep ().Title);
|
|
|
|
step1.Enabled = false;
|
|
step2.Enabled = true;
|
|
step3.Enabled = false;
|
|
Assert.Equal (step2.Title, wizard.GetNextStep ().Title);
|
|
|
|
step1.Enabled = true;
|
|
step2.Enabled = false;
|
|
step3.Enabled = false;
|
|
Assert.Equal (step1.Title, wizard.GetNextStep ().Title);
|
|
wizard.Dispose ();
|
|
}
|
|
|
|
[Fact]
|
|
[AutoInitShutdown]
|
|
public void Navigate_GetPreviousStep_Correct ()
|
|
{
|
|
var wizard = new Wizard ();
|
|
|
|
// If no steps should be null
|
|
Assert.Null (wizard.GetPreviousStep ());
|
|
|
|
var step1 = new WizardStep { Title = "step1" };
|
|
wizard.AddStep (step1);
|
|
|
|
// If no current step, should be last step
|
|
Assert.Equal (step1.Title, wizard.GetPreviousStep ().Title);
|
|
|
|
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 WizardStep { Title = "step2" };
|
|
wizard.AddStep (step2);
|
|
wizard.CurrentStep = step2;
|
|
step1.Enabled = true;
|
|
Assert.Equal (step1.Title, wizard.GetPreviousStep ().Title);
|
|
|
|
// 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 WizardStep { Title = "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, wizard.GetPreviousStep ().Title);
|
|
wizard.CurrentStep = step3;
|
|
Assert.Equal (step2.Title, wizard.GetPreviousStep ().Title);
|
|
|
|
// 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, wizard.GetPreviousStep ().Title);
|
|
|
|
// 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, wizard.GetPreviousStep ().Title);
|
|
|
|
step1.Enabled = false;
|
|
step2.Enabled = true;
|
|
step3.Enabled = true;
|
|
Assert.Equal (step3.Title, wizard.GetPreviousStep ().Title);
|
|
|
|
step1.Enabled = false;
|
|
step2.Enabled = false;
|
|
step3.Enabled = true;
|
|
Assert.Equal (step3.Title, wizard.GetPreviousStep ().Title);
|
|
|
|
step1.Enabled = false;
|
|
step2.Enabled = true;
|
|
step3.Enabled = false;
|
|
Assert.Equal (step2.Title, wizard.GetPreviousStep ().Title);
|
|
|
|
step1.Enabled = true;
|
|
step2.Enabled = false;
|
|
step3.Enabled = false;
|
|
Assert.Equal (step1.Title, wizard.GetPreviousStep ().Title);
|
|
wizard.Dispose ();
|
|
}
|
|
|
|
[Fact]
|
|
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]
|
|
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]
|
|
|
|
// This test verifies that a single step wizard shows the correct buttons
|
|
// and that the title is correct
|
|
public void OneStepWizard_Shows ()
|
|
{
|
|
|
|
var title = "1234";
|
|
var stepTitle = "ABCD";
|
|
|
|
var width = 30;
|
|
var height = 7;
|
|
AutoInitShutdownAttribute.FakeResize (new Size (width, height));
|
|
|
|
// var btnBackText = "Back";
|
|
var btnBack = string.Empty; // $"{Glyphs.LeftBracket} {btnBackText} {Glyphs.RightBracket}";
|
|
var btnNextText = "Finish"; // "Next";
|
|
|
|
var btnNext =
|
|
$"{
|
|
Glyphs.LeftBracket
|
|
}{
|
|
Glyphs.LeftDefaultIndicator
|
|
} {
|
|
btnNextText
|
|
} {
|
|
Glyphs.RightDefaultIndicator
|
|
}{
|
|
Glyphs.RightBracket
|
|
}";
|
|
|
|
var topRow =
|
|
$"{
|
|
Glyphs.ULCornerDbl
|
|
}╡{
|
|
title
|
|
} - {
|
|
stepTitle
|
|
}╞{
|
|
new (Glyphs.HLineDbl.ToString () [0], width - title.Length - stepTitle.Length - 7)
|
|
}{
|
|
Glyphs.URCornerDbl
|
|
}";
|
|
var row2 = $"{Glyphs.VLineDbl}{new (' ', width - 2)}{Glyphs.VLineDbl}";
|
|
string row3 = row2;
|
|
string row4 = row3;
|
|
|
|
var separatorRow =
|
|
$"{Glyphs.VLineDbl}{new (Glyphs.HLine.ToString () [0], width - 2)}{Glyphs.VLineDbl}";
|
|
|
|
var buttonRow =
|
|
$"{
|
|
Glyphs.VLineDbl
|
|
}{
|
|
btnBack
|
|
}{
|
|
new (' ', width - btnBack.Length - btnNext.Length - 2)
|
|
}{
|
|
btnNext
|
|
}{
|
|
Glyphs.VLineDbl
|
|
}";
|
|
|
|
var bottomRow =
|
|
$"{
|
|
Glyphs.LLCornerDbl
|
|
}{
|
|
new (Glyphs.HLineDbl.ToString () [0], width - 2)
|
|
}{
|
|
Glyphs.LRCornerDbl
|
|
}";
|
|
|
|
var wizard = new Wizard { Title = title, Width = width, Height = height };
|
|
wizard.AddStep (new() { Title = stepTitle });
|
|
|
|
//wizard.LayoutSubViews ();
|
|
var firstIteration = false;
|
|
RunState runstate = Application.Begin (wizard);
|
|
Application.RunIteration (ref runstate, firstIteration);
|
|
|
|
// TODO: Disabled until Dim.Auto is used in Dialog
|
|
//DriverAsserts.AssertDriverContentsWithFrameAre (
|
|
// $"{topRow}\n{row2}\n{row3}\n{row4}\n{separatorRow}\n{buttonRow}\n{bottomRow}",
|
|
// _output
|
|
// );
|
|
Application.End (runstate);
|
|
wizard.Dispose ();
|
|
}
|
|
|
|
[Fact]
|
|
[AutoInitShutdown]
|
|
|
|
// this test is needed because Wizard overrides Dialog's title behavior ("Title - StepTitle")
|
|
public void Setting_Title_Works ()
|
|
{
|
|
var d = (IConsoleDriverFacade)Application.Driver;
|
|
|
|
var title = "1234";
|
|
var stepTitle = " - ABCD";
|
|
|
|
var width = 40;
|
|
var height = 4;
|
|
d.OutputBuffer.SetWindowSize (width,height);
|
|
|
|
var btnNextText = "Finish";
|
|
|
|
var btnNext =
|
|
$"{
|
|
Glyphs.LeftBracket
|
|
}{
|
|
Glyphs.LeftDefaultIndicator
|
|
} {
|
|
btnNextText
|
|
} {
|
|
Glyphs.RightDefaultIndicator
|
|
}{
|
|
Glyphs.RightBracket
|
|
}";
|
|
|
|
var topRow =
|
|
$"{
|
|
Glyphs.ULCornerDbl
|
|
}╡{
|
|
title
|
|
}{
|
|
stepTitle
|
|
}╞{
|
|
new (Glyphs.HLineDbl.ToString () [0], width - title.Length - stepTitle.Length - 4)
|
|
}{
|
|
Glyphs.URCornerDbl
|
|
}";
|
|
|
|
var separatorRow =
|
|
$"{Glyphs.VLineDbl}{new (Glyphs.HLine.ToString () [0], width - 2)}{Glyphs.VLineDbl}";
|
|
|
|
// Once this is fixed, revert to commented out line: https://github.com/gui-cs/Terminal.Gui/issues/1791
|
|
var buttonRow =
|
|
$"{Glyphs.VLineDbl}{new (' ', width - btnNext.Length - 2)}{btnNext}{Glyphs.VLineDbl}";
|
|
|
|
//var buttonRow = $"{Glyphs.VDLine}{new String (' ', width - btnNext.Length - 2)}{btnNext}{Glyphs.VDLine}";
|
|
var bottomRow =
|
|
$"{
|
|
Glyphs.LLCornerDbl
|
|
}{
|
|
new (Glyphs.HLineDbl.ToString () [0], width - 2)
|
|
}{
|
|
Glyphs.LRCornerDbl
|
|
}";
|
|
|
|
var wizard = new Wizard { Title = title, Width = width, Height = height };
|
|
wizard.AddStep (new() { Title = "ABCD" });
|
|
|
|
Application.End (Application.Begin (wizard));
|
|
wizard.Dispose ();
|
|
}
|
|
|
|
[Fact]
|
|
|
|
// 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]
|
|
|
|
// 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
|
|
}
|
|
|
|
// =========== WizardStep Tests
|
|
|
|
[Fact]
|
|
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_TitleChanged ()
|
|
{
|
|
var r = new Window ();
|
|
Assert.Equal (string.Empty, r.Title);
|
|
|
|
var expected = string.Empty;
|
|
r.TitleChanged += (s, args) => { Assert.Equal (r.Title, args.Value); };
|
|
|
|
expected = "title";
|
|
r.Title = expected;
|
|
Assert.Equal (expected, r.Title);
|
|
|
|
expected = "another title";
|
|
r.Title = expected;
|
|
Assert.Equal (expected, r.Title);
|
|
r.Dispose ();
|
|
}
|
|
|
|
[Fact]
|
|
public void WizardStep_Set_Title_Fires_TitleChanging ()
|
|
{
|
|
var r = new Window ();
|
|
Assert.Equal (string.Empty, r.Title);
|
|
|
|
var expectedAfter = string.Empty;
|
|
var expectedDuring = string.Empty;
|
|
var cancel = false;
|
|
|
|
r.TitleChanging += (s, args) =>
|
|
{
|
|
Assert.Equal (expectedDuring, args.NewValue);
|
|
args.Cancel = cancel;
|
|
};
|
|
|
|
r.Title = expectedDuring = expectedAfter = "title";
|
|
Assert.Equal (expectedAfter, r.Title);
|
|
|
|
r.Title = expectedDuring = expectedAfter = "a different title";
|
|
Assert.Equal (expectedAfter, r.Title);
|
|
|
|
// Now setup cancelling the change and change it back to "title"
|
|
cancel = true;
|
|
r.Title = expectedDuring = "title";
|
|
Assert.Equal (expectedAfter, r.Title);
|
|
r.Dispose ();
|
|
}
|
|
|
|
[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 title = "1234";
|
|
var stepTitle = "";
|
|
|
|
var width = 30;
|
|
var height = 6;
|
|
AutoInitShutdownAttribute.FakeResize (new Size (width, height));
|
|
|
|
var btnBackText = "Back";
|
|
var btnBack = $"{Glyphs.LeftBracket} {btnBackText} {Glyphs.RightBracket}";
|
|
var btnNextText = "Finish";
|
|
|
|
var btnNext =
|
|
$"{
|
|
Glyphs.LeftBracket
|
|
}{
|
|
Glyphs.LeftDefaultIndicator
|
|
} {
|
|
btnNextText
|
|
} {
|
|
Glyphs.RightDefaultIndicator
|
|
}{
|
|
Glyphs.RightBracket
|
|
}";
|
|
|
|
var topRow =
|
|
$"{
|
|
Glyphs.ULCornerDbl
|
|
}╡{
|
|
title
|
|
}{
|
|
stepTitle
|
|
}╞{
|
|
new (Glyphs.HLineDbl.ToString () [0], width - title.Length - stepTitle.Length - 4)
|
|
}{
|
|
Glyphs.URCornerDbl
|
|
}";
|
|
var row2 = $"{Glyphs.VLineDbl}{new (' ', width - 2)}{Glyphs.VLineDbl}";
|
|
string row3 = row2;
|
|
|
|
var separatorRow =
|
|
$"{Glyphs.VLineDbl}{new (Glyphs.HLine.ToString () [0], width - 2)}{Glyphs.VLineDbl}";
|
|
|
|
var buttonRow =
|
|
$"{
|
|
Glyphs.VLineDbl
|
|
}{
|
|
btnBack
|
|
}{
|
|
new (' ', width - btnBack.Length - btnNext.Length - 2)
|
|
}{
|
|
btnNext
|
|
}{
|
|
Glyphs.VLineDbl
|
|
}";
|
|
|
|
var bottomRow =
|
|
$"{
|
|
Glyphs.LLCornerDbl
|
|
}{
|
|
new (Glyphs.HLineDbl.ToString () [0], width - 2)
|
|
}{
|
|
Glyphs.LRCornerDbl
|
|
}";
|
|
|
|
var wizard = new Wizard { Title = title, Width = width, Height = height };
|
|
RunState runstate = Application.Begin (wizard);
|
|
|
|
// TODO: Disabled until Dim.Auto is used in Dialog
|
|
//DriverAsserts.AssertDriverContentsWithFrameAre (
|
|
// $"{topRow}\n{row2}\n{row3}\n{separatorRow}\n{buttonRow}\n{bottomRow}",
|
|
// _output
|
|
// );
|
|
Application.End (runstate);
|
|
wizard.Dispose ();
|
|
}
|
|
}
|