using System.Reflection; using System.Windows.Forms; using OpenNest.CNC; using OpenNest.Data; using OpenNest.Forms; using OpenNest.Geometry; using OpenNest.IO; 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); 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 PlatePreview_StepsThroughThePlates_AndFollowsThePlatesTable() { StaTestThread.Run( () => { var job = Record("Two plates"); var repository = new FakeRepository(job); repository.Files[job.Id] = NestFile((Quantity: 1, Parts: 3), (Quantity: 1, Parts: 1)); using var form = new SavedNestsForm(repository); form.Show(); var plates = Field(form, "platesGrid"); var preview = Field(form, "platePreview"); var label = Field