Files
Terminal.Gui/UnitTests/Views/SpinnerViewTests.cs
Tig b4552ee14b Fixes #2493. Move all layout code out of View (and Toplevel) into a layout helper class (#2544)
* Comment/warning clean up

* Moved Text and Drawing out

* Moved Layout out

* Removed extra lines

* Removed Mouse out

* Reorgainzed View

* API docs

* removed border.cs

* TopLevel.Resized -> TerminalResized

* Mdi -> Overlapped

* Removed confusing and un-needed WillPresent

* privates -> _

* Tweaked RunLoop API
2023-04-14 10:26:10 -06:00

99 lines
2.2 KiB
C#

using System.Threading.Tasks;
using Terminal.Gui;
using Xunit;
using Xunit.Abstractions;
namespace Terminal.Gui.ViewsTests {
public class SpinnerViewTests {
readonly ITestOutputHelper output;
public SpinnerViewTests (ITestOutputHelper output)
{
this.output = output;
}
[Fact, AutoInitShutdown]
public void TestSpinnerView_AutoSpin()
{
var view = GetSpinnerView ();
Assert.Empty (Application.MainLoop.timeouts);
view.AutoSpin ();
Assert.NotEmpty (Application.MainLoop.timeouts);
//More calls to AutoSpin do not add more timeouts
Assert.Single (Application.MainLoop.timeouts);
view.AutoSpin ();
view.AutoSpin ();
view.AutoSpin ();
Assert.Single (Application.MainLoop.timeouts);
// Dispose clears timeout
Assert.NotEmpty (Application.MainLoop.timeouts);
view.Dispose ();
Assert.Empty (Application.MainLoop.timeouts);
}
[Fact, AutoInitShutdown]
public void TestSpinnerView_ThrottlesAnimation ()
{
var view = GetSpinnerView ();
view.Redraw (view.Bounds);
var expected = "/";
TestHelpers.AssertDriverContentsWithFrameAre (expected, output);
view.SetNeedsDisplay ();
view.Redraw (view.Bounds);
expected = "/";
TestHelpers.AssertDriverContentsWithFrameAre (expected, output);
view.SetNeedsDisplay ();
view.Redraw (view.Bounds);
expected = "/";
TestHelpers.AssertDriverContentsWithFrameAre (expected, output);
Task.Delay (400).Wait();
view.SetNeedsDisplay ();
view.Redraw (view.Bounds);
expected = "─";
TestHelpers.AssertDriverContentsWithFrameAre (expected, output);
}
[Fact, AutoInitShutdown]
public void TestSpinnerView_NoThrottle ()
{
var view = GetSpinnerView ();
view.SpinDelayInMilliseconds = 0;
view.Redraw (view.Bounds);
var expected = @"─";
TestHelpers.AssertDriverContentsWithFrameAre (expected, output);
view.SetNeedsDisplay ();
view.Redraw (view.Bounds);
expected = @"\";
TestHelpers.AssertDriverContentsWithFrameAre (expected, output);
}
private SpinnerView GetSpinnerView ()
{
var view = new SpinnerView ();
Application.Top.Add (view);
Application.Begin (Application.Top);
Assert.Equal (1, view.Width);
Assert.Equal (1, view.Height);
return view;
}
}
}