Add enhancements to progress widget

* Adds TransferSpeedColumn
* Adds DownloadedColumn
* Adds ElapsedTimeColumn
* Minor enhancements to existing columns
This commit is contained in:
Patrik Svensson
2021-01-12 12:39:27 +01:00
committed by Patrik Svensson
parent d87d8e4422
commit 07db28bb6f
12 changed files with 342 additions and 3 deletions

View File

@ -0,0 +1,30 @@
using System.Globalization;
using Shouldly;
using Xunit;
namespace Spectre.Console.Tests.Unit
{
public sealed class DownloadedColumnTests
{
[Theory]
[InlineData(0, 1, "0/1 byte")]
[InlineData(37, 101, "37/101 bytes")]
[InlineData(101, 101, "101 bytes")]
[InlineData(512, 1024, "0.5/1.0 KB")]
[InlineData(1024, 1024, "1.0 KB")]
[InlineData(1024 * 512, 5 * 1024 * 1024, "0.5/5.0 MB")]
[InlineData(5 * 1024 * 1024, 5 * 1024 * 1024, "5.0 MB")]
public void Should_Return_Correct_Value(double value, double total, string expected)
{
// Given
var fixture = new ProgressColumnFixture<DownloadedColumn>(value, total);
fixture.Column.Culture = CultureInfo.InvariantCulture;
// When
var result = fixture.Render();
// Then
result.ShouldBe(expected);
}
}
}

View File

@ -0,0 +1,29 @@
using System;
using System.Text;
using Spectre.Console.Rendering;
using Spectre.Console.Testing;
namespace Spectre.Console.Tests.Unit
{
public sealed class ProgressColumnFixture<T>
where T : ProgressColumn, new()
{
public T Column { get; }
public ProgressTask Task { get; set; }
public ProgressColumnFixture(double completed, double total)
{
Column = new T();
Task = new ProgressTask(1, "Foo", total);
Task.Increment(completed);
}
public string Render()
{
var console = new FakeConsole();
var context = new RenderContext(Encoding.UTF8, false);
console.Render(Column.Render(context, Task, TimeSpan.Zero));
return console.Output;
}
}
}