refactor(desktop): move EngineSelection and JobEngineNest into OpenNest.Desktop

The engine selection and the whole-job progress adapter use only Engine
and Data, so they move into the toolkit-neutral library for the Avalonia
front end to share. The namespace stays OpenNest.Forms, so WinForms
callers are unchanged.

Linux tests now cover the adapter's stage routing, one-based plate
numbers and descriptions, and the fill-strategy mapping; the saved
selection is left out because it reads and writes the real per-user file.
This commit is contained in:
aj committed 2026-10-29 19:14:55 -04:00
1 parent 047174432f
commit 2db8f5f841
5 files changed
+129 -1

No files matched your search

@@ -0,0 +1,28 @@
using OpenNest.Forms;
namespace OpenNest.Desktop.Tests.Forms;
/// <summary>
/// Only the pure strategy mapping is covered here: setting EngineName or loading the saved
/// selection reads and writes the real per-user engine-selection.json.
/// </summary>
public class EngineSelectionTests
{
[Theory]
[InlineData("Fill")]
[InlineData("Strip")]
[InlineData("vertical remnant")]
[InlineData(" Horizontal Remnant ")]
public void BuiltInPlacementStrategies_AreFillStrategies(string name) =>
Assert.True(EngineSelection.IsFillStrategy(name));
[Theory]
[InlineData("Default")]
[InlineData("Irregular")]
[InlineData("Rectangles")]
[InlineData("")]
[InlineData(" ")]
[InlineData(null)]
public void JobsOnlyEnginesAndBlanks_AreNotFillStrategies(string? name) =>
Assert.False(EngineSelection.IsFillStrategy(name!));
}
@@ -0,0 +1,100 @@
using OpenNest.Engine;
using OpenNest.Engine.Jobs;
using OpenNest.Forms;
namespace OpenNest.Desktop.Tests.Forms;
public class JobEngineNestTests
{
private sealed class Sink<T> : IProgress<T>
{
public List<T> Reports { get; } = [];
public void Report(T value) => Reports.Add(value);
}
[Fact]
public void EvaluatingReport_BecomesAOneBasedPlateDescription()
{
var progress = new Sink<NestProgress>();
JobEngineNest.CreateProgress("Irregular", progress)
.Report(new NestJobProgress(NestJobStage.EvaluatingCandidate, "48x96", 2, 2, 30));
var report = Assert.Single(progress.Reports);
Assert.Equal(NestPhase.Custom, report.Phase);
Assert.Equal(3, report.PlateNumber);
Assert.Equal("Irregular: evaluating plate 3 on stock 48x96", report.Description);
}
[Fact]
public void UnknownPlateIndex_CountsFromTheCommittedPlates()
{
var progress = new Sink<NestProgress>();
JobEngineNest.CreateProgress("Fill", progress)
.Report(new NestJobProgress(NestJobStage.EvaluatingCandidate, "s", -1, 4, 0));
Assert.Equal(5, Assert.Single(progress.Reports).PlateNumber);
}
[Fact]
public void CommittedReport_NamesTheCommittedCounts()
{
var progress = new Sink<NestProgress>();
JobEngineNest.CreateProgress("Fill", progress)
.Report(new NestJobProgress(NestJobStage.PlateCommitted, "s", 0, 2, 17));
var report = Assert.Single(progress.Reports);
Assert.Equal(2, report.PlateNumber);
Assert.Equal("Fill: committed plate 2 (17 parts placed)", report.Description);
}
[Fact]
public void LegacyProgress_PassesThroughUnchanged()
{
var progress = new Sink<NestProgress>();
var legacy = new NestProgress { Phase = NestPhase.Linear, PlateNumber = 9 };
JobEngineNest.CreateProgress("Fill", progress)
.Report(new NestJobProgress(NestJobStage.EvaluatingCandidate, "s", 0, 0, 0, legacy));
Assert.Same(legacy, Assert.Single(progress.Reports));
}
[Fact]
public void ImprovedPlan_GoesToThePlanSinkOnly()
{
var progress = new Sink<NestProgress>();
var plans = new Sink<IReadOnlyList<ProposedPlate>>();
IReadOnlyList<ProposedPlate> sheets = [];
JobEngineNest.CreateProgress("Irregular", progress, plans)
.Report(new NestJobProgress(NestJobStage.PlanImproved, "s", 0, 0, 0) { PlanSheets = sheets });
Assert.Empty(progress.Reports);
Assert.Same(sheets, Assert.Single(plans.Reports));
}
[Fact]
public void ImprovedPlan_WithoutAPlanSink_IsDescribed()
{
var progress = new Sink<NestProgress>();
JobEngineNest.CreateProgress("Irregular", progress)
.Report(new NestJobProgress(NestJobStage.PlanImproved, "s", 0, 0, 0));
Assert.Equal("Irregular: found a better plan (0 sheets)", Assert.Single(progress.Reports).Description);
}
[Fact]
public void NullReport_IsIgnored()
{
var progress = new Sink<NestProgress>();
JobEngineNest.CreateProgress("Fill", progress).Report(null!);
Assert.Empty(progress.Reports);
}
}
File renamed without changes.
File renamed without changes.
+1 -1
View File
@@ -1,6 +1,6 @@
using System.Runtime.CompilerServices;
// The WinForms app drives undo recording through ChangeScope's internal root/nested factories
// and NestFingerprint.
// and NestFingerprint, and reports Auto Nest progress through the internal JobEngineNest.
[assembly: InternalsVisibleTo("OpenNest")]
[assembly: InternalsVisibleTo("OpenNest.Desktop.Tests")]