using System.Windows.Forms;
using OpenNest.Data;
using OpenNest.Forms;
using static OpenNest.WinForms.Tests.FormTesting;
namespace OpenNest.WinForms.Tests.Forms;
///
/// Machine clamps and support beds in the desktop: the Clamps and Support Bed tabs of Machine
/// Configuration edit a machine's rail and bed,
/// and Nest > Clamps saves its machine defaults to the nest's machine.
///
public class MachineClampsFormsTests
{
[Fact]
public void ClampsTab_EditsTheMachineRail()
{
RunSta(() =>
{
var directory = Path.Combine(Path.GetTempPath(), "OpenNestTests", Guid.NewGuid().ToString());
Directory.CreateDirectory(directory);
try
{
var provider = new LocalJsonProvider(directory);
var machine = new MachineConfig { Name = "Laser" };
provider.SaveMachine(machine);
using var form = new MachineConfigForm(provider);
var node = Find(form, "_tree").Nodes.Cast().Single(n => n.Tag is MachineConfig);
// A hidden tree raises no AfterSelect, so show the machine as selecting it would.
typeof(MachineConfigForm)
.GetMethod("Tree_AfterSelect", System.Reflection.BindingFlags.Instance | System.Reflection.BindingFlags.NonPublic)!
.Invoke(form, new object[] { null, new TreeViewEventArgs(node) });
var shown = (MachineConfig)node.Tag;
Assert.Null(shown.Clamps);
var tab = All(form).Single().TabPages.Cast().Single(p => p.Text == "Clamps");
All(tab).Single(c => c.Text == "Give new nests these clamps").Checked = true;
var add = All