using System.Reflection; using System.Windows.Forms; using OpenNest.CNC; using OpenNest.Data; using OpenNest.Forms; using OpenNest.Geometry; using OpenNest.IO; using static OpenNest.WinForms.Tests.FormTesting; using static OpenNest.WinForms.Tests.TestReflection; namespace OpenNest.WinForms.Tests.Forms; public class SavedNestsFormTests { private static readonly TimeSpan TestTimeout = TimeSpan.FromSeconds(60); [Fact] public void HighlightedNestShowsItsPlatesAndDrawings_AndEnterOpensIt() { StaTestThread.Run( () => { var first = Record("First job"); var second = Record("Second job"); var repository = new FakeRepository(first, second); repository.Files[first.Id] = NestFile((Quantity: 2, Parts: 3)); repository.Files[second.Id] = NestFile((Quantity: 1, Parts: 1)); using var form = new SavedNestsForm(repository, "http://nest-server:5000"); form.Show(); var nests = Field(form, "nestGrid"); var plates = Field(form, "platesGrid"); var drawings = Field(form, "drawingsGrid"); PumpUntil(() => nests.Rows.Count == 2, "the nest page"); Assert.Equal("First job", nests.Rows[0].Cells[0].Value); Assert.Equal("1", nests.Rows[0].HeaderCell.Value); Assert.Contains("http://nest-server:5000", form.Text); Assert.Contains("Showing 1-2 of 2 nests", form.Text); PumpUntil(() => plates.Rows.Count == 1, "the first nest's plates"); Assert.Equal(2, plates.Rows[0].Cells["Duplicates"].Value); Assert.Equal(3, plates.Rows[0].Cells["Parts"].Value); Assert.Equal("Plate size (in)", plates.Columns["PlateSize"].HeaderText); Assert.Equal(6, drawings.Rows[0].Cells["Nested"].Value); nests.CurrentCell = nests.Rows[1].Cells[0]; PumpUntil( () => plates.Rows.Count == 1 && Equals(plates.Rows[0].Cells["Duplicates"].Value, 1), "the second nest's plates"); Assert.Equal(1, drawings.Rows[0].Cells["Nested"].Value); // Selecting a row does not guarantee keyboard focus after pumping UI events. Assert.True(nests.Focus()); Assert.True(nests.Focused); Assert.True(ProcessKey(form, Keys.Enter)); Assert.Equal(DialogResult.OK, form.DialogResult); Assert.Equal(second.Id, form.SelectedId); }, TestTimeout, "The saved-nest dialog test did not complete."); } [Fact] public void SelectingAHistoricalVersion_ShowsItsPlatesInTheDetailsAndPreview() { StaTestThread.Run( () => { var job = Record("Versioned job"); var current = NestFile((Quantity: 1, Parts: 1)); var earlier = NestFile((Quantity: 1, Parts: 3), (Quantity: 1, Parts: 2)); job.Revision = 3; job.FileSize = current.Length; var repository = new FakeRepository(job); repository.Files[job.Id] = current; repository.RevisionFiles[(job.Id, 2)] = earlier; repository.Revisions[job.Id] = [ new NestRecord { Id = job.Id, Revision = 3, Name = job.Name, FileSize = current.Length }, new NestRecord { Id = job.Id, Revision = 2, Name = job.Name, FileSize = earlier.Length }, ]; using var form = new SavedNestsForm(repository); form.Show(); var plates = Field(form, "platesGrid"); var preview = Field(form, "platePreview"); var status = Field