Files
OpenNest/OpenNest.Tests/Data/DrawingLibraryFilterTests.cs
T
ajandClaude Opus 5.5 b9fc618a50 feat(library): filter the drawing library by thickness, size, holes, date and customer
Finding a part on the nest server meant scrolling 40k drawings: the library
could only match an exact thickness or customer and knew nothing about a
drawing's size or holes. The library browser gets a Filter dialog with
inclusive ranges, and the query API takes them.

The server never parses packages and stays off IO, so the server worker now
measures each package beside its nest jobs (bounding sides, net area, closed
cutouts inside the outline) and stores the summary keyed by package hash
(schema v19). Identical geometry is measured once, an unreadable package is
recorded once instead of retried forever, and size or hole limits match only
measured drawings. Thickness ranges compare in inches across units and keep
the library's rule that a drawing saved without a thickness suits any.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-12 16:47:51 -05:00

63 lines
2.4 KiB
C#

using OpenNest.Data;
namespace OpenNest.Tests.Data;
public class DrawingLibraryFilterTests
{
[Fact]
public void None_IsEmptyAndNeedsNoGeometry()
{
Assert.True(new DrawingLibraryFilter().IsEmpty);
Assert.False(DrawingLibraryFilter.None.NeedsGeometry);
Assert.Equal("", DrawingLibraryFilter.None.Describe());
Assert.Null(DrawingLibraryFilter.None.GetValidationError());
Assert.False(new DrawingLibraryFilter { IncludeBlankThickness = false }.IsEmpty);
Assert.True(new DrawingLibraryFilter { MinHoles = 0 }.NeedsGeometry);
}
public static TheoryData<DrawingLibraryFilter> InvalidFilters() => new()
{
new DrawingLibraryFilter { MinThickness = 0.25, MaxThickness = 0.1 },
new DrawingLibraryFilter { MinThickness = -0.1 },
new DrawingLibraryFilter { MaxLength = double.PositiveInfinity },
new DrawingLibraryFilter { MinWidth = 2, MaxWidth = 1 },
new DrawingLibraryFilter { MinHoles = 3, MaxHoles = 2 },
new DrawingLibraryFilter { MaxHoles = -1 },
new DrawingLibraryFilter { SavedFrom = new DateOnly(2026, 2, 1), SavedTo = new DateOnly(2026, 1, 1) },
new DrawingLibraryFilter { Customer = new string('x', DrawingLibraryRules.MaxTextLength + 1) },
};
[Theory]
[MemberData(nameof(InvalidFilters))]
public void InvalidRanges_AreReported(DrawingLibraryFilter filter) =>
Assert.NotNull(filter.GetValidationError());
[Fact]
public void Describe_SummarizesEachLimit()
{
var filter = new DrawingLibraryFilter
{
Customer = " Synthetic Co ",
MinThickness = 0.0598,
MaxThickness = 0.1875,
MaxLength = 4,
MinWidth = 1,
MaxWidth = 1,
MinHoles = 2,
};
Assert.Equal("Customer Synthetic Co; Thickness 0.0598-0.1875 in (or none); Length up to 4 in; Width 1 in; Holes 2+",
filter.Describe());
Assert.Equal("Has a thickness", new DrawingLibraryFilter { IncludeBlankThickness = false }.Describe());
}
[Fact]
public void EffectiveCustomer_PrefersTheQueryCustomer()
{
var filter = new DrawingLibraryFilter { Customer = "Filter Co" };
Assert.Equal("Filter Co", new DrawingLibraryQuery { Filter = filter }.EffectiveCustomer);
Assert.Equal("Query Co", new DrawingLibraryQuery { Customer = "Query Co", Filter = filter }.EffectiveCustomer);
}
}