Files
OpenNest/OpenNest.WinForms.Tests/Forms/PlateReorderTests.cs
T
ajandClaude Opus 5.5 90a1a087f0 feat(plates): reorder plates by drag and drop in the Plates list
Operators want plates of the same size grouped together so material
doesn't need sorting when it arrives; there was no way to change plate
order. Rows can now be dragged to a new position (with a drop line and
edge auto-scroll), or moved with Alt+Up/Alt+Down. Each move is one
undoable "Move Plate" step and only reorders: quantities are untouched.

The trailing empty new-plate sentinel stays last. An empty plate moved
to the end becomes the sentinel, as the sentinel rule already does on
reload, so the order shown is the order saved.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-04 13:41:23 -05:00

49 lines
1.7 KiB
C#

using System.Drawing;
using System.Windows.Forms;
using OpenNest.Forms;
namespace OpenNest.WinForms.Tests.Forms;
public class PlateReorderTests
{
[Theory]
[InlineData(0, 2, 1)]
[InlineData(0, 3, 2)]
[InlineData(3, 0, 0)]
[InlineData(2, 2, 2)]
[InlineData(2, 3, 2)]
public void DropSlotMapsToTheLandingIndex(int from, int slot, int expected) =>
Assert.Equal(expected, EditNestForm.PlateDropTarget(from, slot));
[Fact]
public void DropSlotFollowsTheRowHalvesAndStopsBeforeTheSentinel() => UndoTestEnv.Run(env =>
{
var list = (ListView)Assert.Single(env.Editor.Controls.Find("platesListView", true));
var movable = env.Editor.PlateManager.MovableCount;
Assert.Equal(env.Nest.Plates.Count - 1, movable);
var first = list.Items[0].Bounds;
Assert.Equal(0, env.Editor.GetPlateDropSlot(new Point(5, first.Top + 1)));
Assert.Equal(1, env.Editor.GetPlateDropSlot(new Point(5, first.Bottom - 1)));
var sentinel = list.Items[movable].Bounds;
Assert.Equal(movable, env.Editor.GetPlateDropSlot(new Point(5, sentinel.Top + 1)));
Assert.Equal(movable, env.Editor.GetPlateDropSlot(new Point(5, list.ClientSize.Height - 1)));
});
[Fact]
public void MovingAPlateKeepsItCurrentAndSelected() => UndoTestEnv.Run(env =>
{
var plate = env.Nest.Plates[0];
env.Editor.PlateManager.LoadAt(0);
Assert.True(env.Editor.MovePlate(0, 1));
Assert.Same(plate, env.Nest.Plates[1]);
Assert.Same(plate, env.Editor.PlateManager.CurrentPlate);
var list = (ListView)Assert.Single(env.Editor.Controls.Find("platesListView", true));
Assert.True(list.Items[1].Selected);
Assert.Equal("2", list.Items[1].Text);
});
}