diff --git a/OpenNest.WinForms.Tests/Forms/SavedNestsFormTests.cs b/OpenNest.WinForms.Tests/Forms/SavedNestsFormTests.cs new file mode 100644 index 0000000..2f89efa --- /dev/null +++ b/OpenNest.WinForms.Tests/Forms/SavedNestsFormTests.cs @@ -0,0 +1,169 @@ +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(plateQuantity: 2, partsOnPlate: 3); + repository.Files[second.Id] = NestFile(plateQuantity: 1, partsOnPlate: 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 MissingArchive_ShowsTheErrorInTheDetailsLine_AndEscapeCancels() + { + StaTestThread.Run( + () => + { + var gone = Record("Deleted elsewhere"); + using var form = new SavedNestsForm(new FakeRepository(gone)); + form.Show(); + var status = Field