Files
OpenNest/OpenNest.WinForms.Tests/Forms/PlateReorderTests.cs
T
ajandClaude Opus 5.5 c82a4afc7a feat(desktop): show plate previews in the Plates list
The Plates tab becomes a card list like the drawings list: each row shows a
picture of the sheet with its parts in their drawing colors, beside the plate
number, size, quantity, part count and utilization. Pictures are cached per
plate and redrawn only when the sheet or a part's placement changes; the list
repaints after each recorded edit so moves and rotations show.

Drag and Ctrl+drag reordering, Alt+Up/Down, the row menu (a right-click now
selects its row), double-click to edit and the stock tooltip carry over.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-26 21:20:10 -05:00

96 lines
3.6 KiB
C#

using System.Drawing;
using System.Windows.Forms;
using OpenNest.Controls;
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 = (PlateListBox)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.GetItemRectangle(0);
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.GetItemRectangle(movable);
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 = (PlateListBox)Assert.Single(env.Editor.Controls.Find("platesListView", true));
Assert.Equal(1, list.SelectedIndex);
Assert.Same(plate, list.Items[1]);
});
[Fact]
public void DuplicatingTheCurrentPlateInsertsItsCopyAfterItAndSelectsIt() => UndoTestEnv.Run(env =>
{
env.Editor.PlateManager.LoadAt(0);
var source = env.Nest.Plates[0];
var count = env.Nest.Plates.Count;
Assert.True(env.Editor.DuplicateCurrentPlate());
Assert.Equal(count + 1, env.Nest.Plates.Count);
Assert.Same(source, env.Nest.Plates[0]);
var copy = env.Nest.Plates[1];
Assert.NotSame(source, copy);
Assert.Equal(source.Parts.Count, copy.Parts.Count);
Assert.Same(copy, env.Editor.PlateManager.CurrentPlate);
if (source.CuttingParameters != null)
Assert.NotSame(source.CuttingParameters, copy.CuttingParameters);
var list = (PlateListBox)Assert.Single(env.Editor.Controls.Find("platesListView", true));
Assert.Equal(1, list.SelectedIndex);
Assert.NotNull(list.ContextMenuStrip);
});
[Fact]
public void DeletePlateOnTheRowMenuRemovesTheCurrentPlate() => UndoTestEnv.Run(env =>
{
env.Editor.PlateManager.LoadAt(0);
var plate = env.Nest.Plates[0];
var count = env.Nest.Plates.Count;
var list = (PlateListBox)Assert.Single(env.Editor.Controls.Find("platesListView", true));
var item = Assert.IsType<ToolStripMenuItem>(list.ContextMenuStrip!.Items["deletePlateMenuItem"]);
Assert.Equal("Delete Plate", item.Text);
item.PerformClick();
Assert.Equal(count - 1, env.Nest.Plates.Count);
Assert.DoesNotContain(plate, env.Nest.Plates);
});
[Fact]
public void TheEmptySentinelCannotBeDuplicated() => UndoTestEnv.Run(env =>
{
var count = env.Nest.Plates.Count;
Assert.False(env.Editor.DuplicatePlate(count - 1, 0));
Assert.Equal(count, env.Nest.Plates.Count);
});
}