Files
OpenNest/OpenNest.WinForms.Tests/Forms/AutoNestFormPlateSourceTests.cs
T
aj f88b1b37fa fix(autonest): keep the server choice once the dialog closes
AutoNestForm read "Nest on the server" through nestOnServerBox.Visible,
which WinForms reports as false whenever the form is hidden or another tab
is selected. AutoNestCommand reads NestOnServer after ShowDialog returns,
so a checked box never sent the job to the server, and the choice was not
saved when the dialog closed on a tab other than Plates. Availability now
lives in its own field.

Fixes AutoNestFormPlateSourceTests.CurrentPlatesAreNeverNestedOnTheServer
on windows-desktop (Cross-platform tests run 45732432564).
2026-11-26 10:49:22 -05:00

90 lines
3.2 KiB
C#

using System.Windows.Forms;
using OpenNest.Engine.Jobs;
using OpenNest.Forms;
using OpenNest.Geometry;
namespace OpenNest.WinForms.Tests.Forms;
public class AutoNestFormPlateSourceTests
{
[Fact]
public void OpensOnNewPlates() => RunSta(() =>
{
using var form = new AutoNestForm(new Nest());
Assert.Equal(NestPlateSource.New, form.PlateSource);
});
[Theory]
[InlineData(NestPlateSource.Current)]
[InlineData(NestPlateSource.Both)]
public void CurrentPlatesAreNeverNestedOnTheServer(NestPlateSource source) => RunSta(() =>
{
using var form = new AutoNestForm(new Nest()) { ServerNestingAvailable = true };
var box = Assert.IsType<CheckBox>(form.Controls.Find("nestOnServerBox", true).Single());
box.Checked = true;
form.PlateSource = source;
Assert.False(box.Enabled);
Assert.False(form.NestOnServer);
form.PlateSource = NestPlateSource.New;
Assert.Equal(box.Checked, form.NestOnServer);
});
[Fact]
public void NestOnServerIsReadableWhileTheFormIsHidden() => RunSta(() =>
{
// AutoNestCommand reads the choice after ShowDialog returns, when every control
// reports Visible == false.
using var form = new AutoNestForm(new Nest()) { ServerNestingAvailable = true };
var box = Assert.IsType<CheckBox>(form.Controls.Find("nestOnServerBox", true).Single());
box.Checked = true;
Assert.True(form.ServerNestingAvailable);
Assert.True(form.NestOnServer);
box.Checked = false;
Assert.False(form.NestOnServer);
form.ServerNestingAvailable = false;
box.Checked = true;
Assert.False(form.ServerNestingAvailable);
Assert.False(form.NestOnServer);
});
[Fact]
public void CurrentPlatesOnlyOffersNoStockOptions() => RunSta(() =>
{
using var form = new AutoNestForm(new Nest()) { OptimizePlateSize = true };
form.PlateSource = NestPlateSource.Current;
Assert.False(form.OptimizePlateSize);
form.PlateSource = NestPlateSource.Both;
Assert.True(form.OptimizePlateSize);
});
[Fact]
public void ReviewShowsPartsAlreadyPlacedWithoutCountingThem() => RunSta(() =>
{
var drawing = new Drawing("bracket", NestReviewFormTests.Rectangle());
var stock = new NestPlateStock("existing", new Size(48, 96), quantity: 1, partSpacing: 0.25);
var sheet = new ProposedPlate(0, stock, new[] { new Part(drawing, new Vector(20, 1)) })
{
Occupants = new[] { new Part(drawing, new Vector(1, 1)), new Part(drawing, new Vector(1, 30)) },
ExistingPlateNumber = 2,
};
using var form = new NestReviewForm("Review", new[] { sheet }, 0,
Array.Empty<NestUnplacedPart>(), ColorScheme.Default);
Assert.Equal(1, form.Strip.PartCount);
Assert.Equal(2, form.Strip.ExistingPartCount);
// Three 10 x 20 parts now fill the sheet's material.
Assert.Equal(600.0 / (48 * 96), form.Strip.Utilization, 6);
Assert.Contains("already on the plates (2)", form.Summary);
});
private static void RunSta(Action action) =>
StaTestThread.Run(action, TimeSpan.FromSeconds(15), "The STA test did not complete.");
}