Set max value for progress task properly

Also clamp the task value if it's greater than the max value.

Closes #163
This commit is contained in:
Patrik Svensson
2020-12-12 16:58:39 +01:00
committed by Patrik Svensson
parent acf01e056f
commit 63abcc92ba
3 changed files with 32 additions and 2 deletions

View File

@ -59,7 +59,7 @@ namespace Spectre.Console.Tests.Unit
}
[Fact]
public Task Foo()
public Task Should_Reduce_Width_If_Needed()
{
// Given
var console = new PlainConsole(width: 20);
@ -87,5 +87,29 @@ namespace Spectre.Console.Tests.Unit
// Then
return Verifier.Verify(console.Output);
}
[Fact]
public void Setting_Max_Value_Should_Set_The_MaxValue_And_Cap_Value()
{
// Given
var task = default(ProgressTask);
var console = new PlainConsole();
var progress = new Progress(console)
.Columns(new[] { new ProgressBarColumn() })
.AutoRefresh(false)
.AutoClear(false);
// When
progress.Start(ctx =>
{
task = ctx.AddTask("foo");
task.Increment(100);
task.MaxValue = 20;
});
// Then
task.MaxValue.ShouldBe(20);
task.Value.ShouldBe(20);
}
}
}