Files
OpenNest/OpenNest.Desktop.Tests/Forms/NestDefaultsChoicesTests.cs
T
ajandClaude Opus 5.5 6f1d21173d feat(desktop): share nest info, Clear Nest and the nest defaults choices
NestInfoValues is what Nest > Edit edits (name, dates, thickness,
material and grade, customer, status, author, units, notes and the plate
defaults): read from a nest, when Done is enabled, how it writes the
nest, which Made By to remember, the material and grade lists and the
fields undo puts back. NestCommands holds its commit as one "Nest Info"
step (a changed material or thickness takes the machine's spacing and an
untouched trailing sheet follows), the defaults "Use these defaults for
new nests" saves, and Clear Nest as one "Clear Nest" step with its
question and busy message. NestDefaultsChoices holds the Tools > Nest
Defaults dialog's machine order, common-line list and box ranges.

The WinForms Edit Nest dialog, nest window and Nest Defaults dialog
delegate to them with unchanged behavior.

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

47 lines
1.6 KiB
C#

using OpenNest.CommonLines;
using OpenNest.Data;
namespace OpenNest.Desktop.Tests.Forms;
public class NestDefaultsChoicesTests
{
[Theory]
[InlineData(CommonLineUsage.Off, 0)]
[InlineData(CommonLineUsage.WhenItAddsParts, 1)]
[InlineData(CommonLineUsage.Whenever, 2)]
public void CommonLineUsages_MapBothWays(CommonLineUsage usage, int index)
{
Assert.Equal(index, NestDefaultsChoices.CommonLineIndex(usage));
Assert.Equal(usage, NestDefaultsChoices.CommonLineAt(index));
}
[Fact]
public void CommonLineAt_NoneSelected_IsOff()
{
Assert.Equal(CommonLineUsage.Off, NestDefaultsChoices.CommonLineAt(-1));
Assert.Equal(["Off", "When it adds parts", "Whenever available"],
NestDefaultsChoices.CommonLineUsages.Select(c => c.Text));
}
[Fact]
public void SortedMachines_AreByName_AndTheSavedChoiceStaysWithoutAny()
{
var b = new MachineConfig { Name = "beta" };
var a = new MachineConfig { Name = "Alpha" };
Assert.Equal([a, b], NestDefaultsChoices.SortedMachines([b, a]));
var saved = Guid.NewGuid();
Assert.Equal(saved, NestDefaultsChoices.MachineIdToSave(null, saved));
Assert.Equal(a.Id, NestDefaultsChoices.MachineIdToSave(a, saved));
}
[Theory]
[InlineData(5, 5)]
[InlineData(-1, 0.001)]
[InlineData(2e6, 1e6)]
[InlineData(double.NaN, 0.001)]
[InlineData(double.PositiveInfinity, 0.001)]
public void Clamp_ShowsAValueInTheBoxRange(double value, double expected) =>
Assert.Equal(expected, NestDefaultsChoices.Clamp(value, NestDefaultsChoices.SizeMinimum, NestDefaultsChoices.Maximum));
}