using System.Reflection; using System.Windows.Forms; using OpenNest.Forms; using OpenNest.Geometry; namespace OpenNest.WinForms.Tests.Forms; // The layout checks failed once on CI (Settings tab columns ~84 px wider than measured when the // window sized itself) and passed on the same commit and runner image before and after, never // locally. Run apart from the parallel tests so other forms on other threads cannot interfere. [CollectionDefinition("Cut simulator layout", DisableParallelization = true)] public class CutSimulatorLayoutCollection; [Collection("Cut simulator layout")] public class CutSimulatorFormTests { [Fact] public void InputsSitOnTheSettingsTabAndBothTabsFitWithoutResizing() => RunSta(() => { using var editor = Editor(); editor.Show(); editor.PlateManager.LoadAt(0); editor.SimulateCutting(); var simulator = (CutSimulatorForm)typeof(EditNestForm) .GetField("cutSimulatorForm", BindingFlags.Instance | BindingFlags.NonPublic)! .GetValue(editor)!; try { var tabs = Field(simulator, "tabs"); Assert.Equal(new[] { "Status", "Settings" }, tabs.TabPages.Cast().Select(p => p.Text)); var settings = tabs.TabPages[1]; foreach (var input in new[] { "feedBox", "holeFeedBox", "rapidBox", "pierceBox", "heatPowerBox", "skipEtchBox", "machineLabel" }) Assert.Same(settings, PageOf(Field(simulator, input))); Assert.Same(tabs.TabPages[0], PageOf(Field(simulator, "heatBox"))); // The time stays above the tabs so it can be read while settings change. Assert.Null(PageOf(Field(simulator, "timeLabel"))); var size = simulator.Size; foreach (TabPage page in tabs.TabPages) { tabs.SelectedTab = page; simulator.PerformLayout(); Application.DoEvents(); Assert.Equal(size, simulator.Size); foreach (var control in Descendants(page.Controls[0]).Where(c => c.Visible)) { var bounds = page.RectangleToClient(control.RectangleToScreen(control.ClientRectangle)); Assert.True(page.ClientRectangle.Contains(bounds), $"{control.GetType().Name} '{control.Text}' at {bounds} is clipped by the {page.Text} tab ({page.ClientRectangle}).\n" + DescribeLayout(tabs, page)); } } } finally { simulator.Close(); } }); [Fact] public void TheSliderLeadsAndTheJumpButtonsSpanItsTrackEvenly() => RunSta(() => { using var editor = Editor(); editor.Show(); editor.PlateManager.LoadAt(0); editor.SimulateCutting(); var simulator = (CutSimulatorForm)typeof(EditNestForm) .GetField("cutSimulatorForm", BindingFlags.Instance | BindingFlags.NonPublic)! .GetValue(editor)!; try { Application.DoEvents(); var track = Field(simulator, "trackBar"); var play = Field