mirror of
https://github.com/gui-cs/Terminal.Gui.git
synced 2025-12-26 15:57:56 +01:00
* Initial plan * Add ScreenChanged event, SetScreenSize method, and fix FakeDriver buffer initialization Co-authored-by: tig <585482+tig@users.noreply.github.com> * Add comprehensive tests for ScreenChanged event and buffer integrity Co-authored-by: tig <585482+tig@users.noreply.github.com> * Replace obsolete SizeChanged usage with ScreenChanged in core and tests Co-authored-by: tig <585482+tig@users.noreply.github.com> * Refactor terminal size event handling Replaced `ScreenChanged` with `SizeChanged` across the codebase to standardize naming and improve clarity. Updated event handling logic, including subscriptions, unsubscriptions, and raising methods. Removed deprecated `ScreenChanged` event and backward compatibility code. Refactored driver initialization to handle legacy `IConsoleDriver` types separately. Updated tests and mock implementations to align with the new `SizeChanged` event. Improved documentation and comments to reflect these changes. These updates enhance maintainability, consistency, and modernize the architecture. * Refactor & Code Cleanup: Replace IWindowSizeMonitor with IConsoleSizeMonitor Renamed `IWindowSizeMonitor` to `IConsoleSizeMonitor` across the codebase, updating all references, method signatures, and event handlers. Replaced the `WindowSizeMonitor` class with the new `ConsoleSizeMonitor` implementation, which includes improved terminal size change handling via the `Poll` method. Enabled nullable reference types in several files to enhance code safety. Updated test cases to reflect the new `IConsoleSizeMonitor` interface. Removed redundant code, simplified null checks, and corrected minor typos in comments. Streamlined the codebase by removing the obsolete `WindowSizeMonitor` class and its interface. * Code cleanup - Refactor and enhance ShadowView and FakeDriverTests Updated ShadowView.cs to use null-conditional operators and added null checks for safer access to `ScreenContents`. Refined XML documentation in View.Layout.cs for clarity and consistency. Refactored FakeDriverTests.cs to leverage modern C# features, including shorthand object instantiation, inline lambdas, and tuple-like syntax for `Size` and `Rectangle`. Removed redundant tests and improved test readability and reliability. Enhanced error handling with null checks and ensured backward compatibility for deprecated events. Improved test coverage for resizing, clipboard operations, and invalid coordinates. Verified buffer integrity and screen updates after resizing. General improvements include replacing explicit type declarations with `var`, removing unused imports, and aligning code formatting for better readability. Refactor and improve code quality and test coverage Updated `ShadowView` for null safety using null-conditional operators. Simplified object initializations and modernized syntax across the codebase, including shorthand initializations and inline lambdas. Enhanced event handling logic and ensured compatibility with obsolete members. Refactored `FakeDriverTests` by removing redundant code, standardizing formatting, and improving test setup. Suppressed obsolete warnings where necessary. Improved XML documentation in `View.Layout.cs` for clarity and removed outdated references. Performed general cleanup, including removing unused namespaces, redundant comments, and ensuring consistent formatting. These changes enhance readability, maintainability, and runtime safety. * Code cleanup Refactor TimedEventsTests for readability and consistency Improved code readability and maintainability: - Enabled nullable reference types with `#nullable enable`. - Removed unused `using System.Diagnostics;`. - Updated namespace to `UnitTests.ApplicationTests`. - Replaced `Terminal.Gui.App.TimedEvents` with `TimedEvents`. - Reformatted XML documentation comments for alignment. - Used `var` and target-typed new expressions for consistency. - Reformatted `Parallel.For` loops and lambdas for clarity. - Added `Thread.Sleep(10)` to prevent excessive CPU usage in tests. - Improved assertions and event handler formatting in tests. Aligned with modern C# coding practices. * Code Cleanup - No more driver warnings. Refactor codebase and introduce FakeClipboard - Adjusted `.editorconfig` to change severity levels for CS0612, CS0618, and CS0672 diagnostics. - Replaced `FakeDriver.FakeClipboard` with a new `FakeClipboard` class for testing purposes, supporting exception handling and clipboard data manipulation. - Removed redundant methods (`MakeColor`, `MapKey`) and unused classes (`MockConsoleDriver`) to streamline the codebase. - Refactored `ConsoleDriverFacade` and `FakeDriver` to simplify logic and improve maintainability. - Updated tests to use `CreateFakeDriver` and removed or commented out obsolete tests. - Reformatted and cleaned up code for readability across multiple files. * Refactor FakeDriver - Code Cleanup Standardized console size management by replacing `WindowSizeMonitor` with `ConsoleSizeMonitor` across the codebase. Updated methods `GetWindowSize` and `SetWindowSize` to `GetSize` and `SetSize` for consistency. Refactored `FakeDriver` to use `SetScreenSize` and removed redundant methods. Simplified driver initialization by removing legacy `InternalInit` logic. Standardized ANSI escape sequences by replacing `CSI_ReportTerminalSizeInChars` with `CSI_ReportWindowSizeInChars`. Updated test cases to align with the new `ConsoleSizeMonitor` and `SetScreenSize` methods. Removed obsolete test utilities like `FakeSizeMonitor` and `FakeWindowSizeMonitor`. Performed general code cleanup, including removing unused classes, redundant code, and improving formatting. Fixed resizing logic issues and improved exception handling in driver methods. * Update Terminal.Gui/Drivers/OutputBuffer.cs Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> * Update Terminal.Gui/Drivers/MouseButtonStateEx.cs Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> * Update Terminal.Gui/App/MainLoop/IApplicationMainLoop.cs Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> * Update Tests/UnitTests/Views/ToplevelTests.cs Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> * Update Terminal.Gui/ViewBase/View.Layout.cs Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> * Moved all Drawing tests to Paralleizable - proving Fakedriver works Enhanced `Ruler` and `Thickness` classes by adding an optional `IConsoleDriver? driver` parameter to decouple rendering from the default `Application.Driver`, improving flexibility and testability. Updated `DriverAssert` to support nullable drivers and added defensive checks. Refactored and expanded test cases for `Ruler`, `Thickness`, `LineCanvas`, and `StraightLineExtensions` to ensure comprehensive coverage, including zero-length intersections, line rendering, and exclusion logic. Migrated rendering-dependent tests to a parallelizable namespace. Removed redundant tests, improved naming conventions, and updated documentation for better maintainability and clarity. * Fixed Run<T> startup hang. Refactor: Simplify driver logic and update SetSize methods Removed FakeDriver safeguard in unit tests to simplify CreateDriver logic. Updated SetSize methods in NetOutput, UnixOutput, and WindowsOutput to do nothing instead of throwing NotImplementedException. Modified SizeChanged event in ConsoleDriverFacade to call SetScreenSize directly. Commented out unnecessary debug validation in DimAuto. These changes improve maintainability and reduce complexity. * Fixed intermittent unit test bug. Refactored `_cachedRunStateToplevel` to `CachedRunStateToplevel` as an internal static property, delegating its management to `ApplicationImpl` for improved encapsulation. Updated all references to use the new property and centralized its handling in `ApplicationImpl`. Removed the `MouseGrabHandler` property from `ApplicationImpl` and simplified driver-related assignments by replacing `Application.ForceDriver` and `Application.Screen` with direct references. Reset `CachedRunStateToplevel` during cleanup to ensure proper state management. Updated the `Invoke` method to use `Top` directly, aligning with the refactored design. Improved debug assertions and performed general cleanup to enhance code readability and maintainability. * Fixed intermittent bug an massive code cleanup of warnings. Refactor and enhance codebase for maintainability - Applied null-conditional operator (`!`) to improve null-safety. - Refactored tests for clarity, added new cases, and removed redundancies. - Introduced `FakeApplicationFactory` and `FakeSizeMonitor` for testing. - Removed unused code, including legacy `DecodeEscSeq` logic. - Reformatted code for readability and consistency. - Updated assertions for more accurate validation in tests. - Fixed potential null reference issues across multiple files. - Improved event handling with proper null checks. - Enhanced documentation for new classes and methods. - Modernized code with C# features like `record struct` and `nullable enable`. --------- Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com> Co-authored-by: tig <585482+tig@users.noreply.github.com> Co-authored-by: Tig <tig@users.noreply.github.com> Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
618 lines
20 KiB
C#
618 lines
20 KiB
C#
namespace UnitTests.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
|
|
Wizard wizard = new ();
|
|
WizardStep step1 = new () { 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);
|
|
AutoInitShutdownAttribute.RunIteration ();
|
|
|
|
wizard.NextFinishButton.InvokeCommand (Command.Accept);
|
|
AutoInitShutdownAttribute.RunIteration ();
|
|
Application.End (runstate);
|
|
Assert.True (finishedFired);
|
|
Assert.True (closedFired);
|
|
step1.Dispose ();
|
|
wizard.Dispose ();
|
|
|
|
// Same test, but with two steps
|
|
wizard = new ();
|
|
step1 = new () { Title = "step1" };
|
|
wizard.AddStep (step1);
|
|
WizardStep step2 = new () { 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);
|
|
AutoInitShutdownAttribute.RunIteration ();
|
|
|
|
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 ();
|
|
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);
|
|
AutoInitShutdownAttribute.RunIteration ();
|
|
|
|
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;
|
|
Application.Driver?.SetScreenSize (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}";
|
|
|
|
Wizard wizard = new () { Title = title, Width = width, Height = height };
|
|
wizard.AddStep (new () { Title = stepTitle });
|
|
|
|
//wizard.LayoutSubViews ();
|
|
RunState runstate = Application.Begin (wizard);
|
|
AutoInitShutdownAttribute.RunIteration ();
|
|
|
|
// 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 = Application.Driver;
|
|
|
|
var title = "1234";
|
|
var stepTitle = " - ABCD";
|
|
|
|
var width = 40;
|
|
var height = 4;
|
|
d.SetScreenSize (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;
|
|
Application.Driver?.SetScreenSize (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 ();
|
|
}
|
|
}
|