Files
OpenNest/OpenNest.Desktop.Tests/Forms/OperationProgressTests.cs
T
ajandClaude Opus 5.5 99c440b215 feat(desktop): share the plate command progress window's rules
OperationProgress holds what the WinForms Cancel window for Expand and
Fix Spacing does apart from drawing itself: a run that finishes within
300 ms never shows it, the caller blocks until then, the elapsed time
updates every half second, and after Cancel it reads "Canceling...
waiting for the current step to stop". The WinForms window now uses it
with unchanged behavior.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-29 20:11:35 -05:00

36 lines
1.3 KiB
C#

using System;
using System.Threading;
using System.Threading.Tasks;
using OpenNest.Forms;
namespace OpenNest.Desktop.Tests.Forms;
public class OperationProgressTests
{
[Theory]
[InlineData(0, false, "Elapsed 0:00")]
[InlineData(65.9, false, "Elapsed 1:05")]
[InlineData(3601, true, "Canceling... waiting for the current step to stop (60:01)")]
public void Status_text_shows_the_elapsed_minutes_and_seconds(double seconds, bool canceling, string expected) =>
Assert.Equal(expected, OperationProgress.StatusText(TimeSpan.FromSeconds(seconds), canceling));
[Fact]
public void A_finished_or_faulted_run_finishes_within_the_delay()
{
Assert.True(OperationProgress.FinishesWithin(Task.CompletedTask, TimeSpan.Zero));
Assert.True(OperationProgress.FinishesWithin(Task.FromException(new InvalidOperationException()), TimeSpan.Zero));
}
[Fact]
public void A_run_still_going_does_not_finish_within_the_delay()
{
using var release = new ManualResetEventSlim();
var task = Task.Run(release.Wait);
Assert.False(OperationProgress.FinishesWithin(task, TimeSpan.FromMilliseconds(20)));
release.Set();
Assert.True(OperationProgress.FinishesWithin(task, TimeSpan.FromSeconds(10)));
}
}