|
- using EnvelopeRenderer.Desktop.Core.Design;
-
- namespace EnvelopeRenderer.Desktop.Tests;
-
- public class SelectionCyclerTests
- {
- private static readonly Guid A = Guid.Parse("00000000-0000-0000-0000-00000000000a");
- private static readonly Guid B = Guid.Parse("00000000-0000-0000-0000-00000000000b");
- private static readonly Guid C = Guid.Parse("00000000-0000-0000-0000-00000000000c");
-
- private static SelectionCycler.Item[] Items() => new[]
- {
- new SelectionCycler.Item(C, ZOrder: 2, X: 0, Y: 0),
- new SelectionCycler.Item(A, ZOrder: 0, X: 0, Y: 0),
- new SelectionCycler.Item(B, ZOrder: 1, X: 0, Y: 0),
- };
-
- [Fact]
- public void Forward_WalksBottomToTopByZOrder_AndWraps()
- {
- Assert.Equal(A, SelectionCycler.Next(Items(), null, forward: true));
- Assert.Equal(B, SelectionCycler.Next(Items(), A, forward: true));
- Assert.Equal(C, SelectionCycler.Next(Items(), B, forward: true));
- Assert.Equal(A, SelectionCycler.Next(Items(), C, forward: true));
- }
-
- [Fact]
- public void Backward_WalksTopToBottom_AndWraps_StartingAtTheLastItem()
- {
- Assert.Equal(C, SelectionCycler.Next(Items(), null, forward: false));
- Assert.Equal(B, SelectionCycler.Next(Items(), C, forward: false));
- Assert.Equal(A, SelectionCycler.Next(Items(), B, forward: false));
- Assert.Equal(C, SelectionCycler.Next(Items(), A, forward: false));
- }
-
- [Fact]
- public void SameZOrder_VisitsTopToBottomThenLeftToRight()
- {
- var items = new[]
- {
- new SelectionCycler.Item(A, 0, X: 50, Y: 10),
- new SelectionCycler.Item(B, 0, X: 10, Y: 100),
- new SelectionCycler.Item(C, 0, X: 10, Y: 10),
- };
-
- Assert.Equal(B, SelectionCycler.Next(items, null, forward: true)); // highest on the page first
- Assert.Equal(C, SelectionCycler.Next(items, B, forward: true)); // then the lower-left one
- Assert.Equal(A, SelectionCycler.Next(items, C, forward: true));
- }
-
- [Fact]
- public void UnknownCurrentSelection_BehavesLikeNoSelection()
- => Assert.Equal(A, SelectionCycler.Next(Items(), Guid.NewGuid(), forward: true));
-
- [Fact]
- public void NoItems_ReturnsNull()
- => Assert.Null(SelectionCycler.Next(Array.Empty<SelectionCycler.Item>(), null, forward: true));
-
- [Fact]
- public void SingleItem_StaysOnIt()
- {
- var items = new[] { new SelectionCycler.Item(A, 0, 0, 0) };
-
- Assert.Equal(A, SelectionCycler.Next(items, A, forward: true));
- Assert.Equal(A, SelectionCycler.Next(items, A, forward: false));
- }
- }
|