mirror of
https://github.com/ajisaacs/OpenNest.git
synced 2026-10-27 15:01:07 -04:00
The flat ten-row list squeezed the quadrant picker to 120x28 and gave no hint of units or where the defaults are saved. Group the fields (General, Plate Size, Quadrant, Spacing), lay the edge spacings out around a plate, show in/mm suffixes, and convert the values when the units switch so a 48 in plate does not silently become 48 mm. The footer says whether Save writes to this PC or the shared nest server, and Save is disabled while the shared copy is read-only instead of failing after the click. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
62 lines
2.4 KiB
C#
62 lines
2.4 KiB
C#
using System.Windows.Forms;
|
|
using OpenNest.Data;
|
|
using OpenNest.Forms;
|
|
using OpenNest.Geometry;
|
|
|
|
namespace OpenNest.WinForms.Tests.Forms;
|
|
|
|
public class NestDefaultsFormTests
|
|
{
|
|
[Fact]
|
|
public void SwitchingUnitsConvertsTheShownValues()
|
|
{
|
|
RunSta(() =>
|
|
{
|
|
var machine = new MachineConfig { Name = "Laser" };
|
|
var defaults = new NestDefaults
|
|
{
|
|
Units = Units.Inches,
|
|
Size = new Size(48, 96),
|
|
Quadrant = 3,
|
|
PartSpacing = 0.25,
|
|
EdgeSpacing = new Spacing(0.5, 1, 1.5, 2),
|
|
MachineId = machine.Id,
|
|
};
|
|
using var form = new NestDefaultsForm(defaults, new[] { machine }, ("Saved on this PC.", false));
|
|
Assert.Equal("in", Control<OpenNest.Controls.NumericUpDown>(form, "widthBox").Suffix);
|
|
|
|
Control<RadioButton>(form, "millimetersRadio").Checked = true;
|
|
|
|
var converted = form.GetDefaults();
|
|
Assert.Equal(Units.Millimeters, converted.Units);
|
|
Assert.Equal(new Size(1219.2, 2438.4), converted.Size);
|
|
Assert.Equal(6.35, converted.PartSpacing);
|
|
Assert.Equal(new Spacing(12.7, 25.4, 38.1, 50.8), converted.EdgeSpacing);
|
|
Assert.Equal(3, converted.Quadrant);
|
|
Assert.Equal(machine.Id, converted.MachineId);
|
|
Assert.Equal("mm", Control<OpenNest.Controls.NumericUpDown>(form, "edgeTopBox").Suffix);
|
|
|
|
Control<RadioButton>(form, "inchesRadio").Checked = true;
|
|
Assert.Equal(new Size(48, 96), form.GetDefaults().Size);
|
|
});
|
|
}
|
|
|
|
[Fact]
|
|
public void ReadOnlySourceDisablesSave()
|
|
{
|
|
RunSta(() =>
|
|
{
|
|
using var form = new NestDefaultsForm(new NestDefaults(), Array.Empty<MachineConfig>(),
|
|
("Shared, read-only: the server cannot be reached.", true));
|
|
Assert.False(Control<Button>(form, "saveButton").Enabled);
|
|
Assert.Equal("Shared, read-only: the server cannot be reached.", Control<Label>(form, "sourceLabel").Text);
|
|
});
|
|
}
|
|
|
|
private static T Control<T>(NestDefaultsForm form, string name) where T : Control =>
|
|
Assert.IsType<T>(form.Controls.Find(name, true).Single());
|
|
|
|
private static void RunSta(System.Action action) =>
|
|
StaTestThread.Run(action, Timeout.InfiniteTimeSpan, "The STA test did not complete.");
|
|
}
|