using CentronSoftware.Centron.Controls.PositionGrid.Helpers; using CentronSoftware.Centron.Controls.PositionGrid.Interfaces; namespace Centron.Tests.Controls.PositionGrid { /// /// Tests for the indent normalization of a cut-out of positions that is pasted into the receipt /// public class PasteIndentNormalizerTests { private static (ReceiptArticleKind kind, bool? isExpanded, int indent) Position(int indent) => (ReceiptArticleKind.Article, null, indent); private static (ReceiptArticleKind kind, bool? isExpanded, int indent) PartListHead(int indent) => (ReceiptArticleKind.Article, true, indent); private static (ReceiptArticleKind kind, bool? isExpanded, int indent) Title(int indent) => (ReceiptArticleKind.Titleposition, true, indent); [Fact] public void CalculateIndents_TitleIndentDoesNotAffectFollowingPartList() { // A title with a non-zero source indent must not stay the indent reference for the // positions after it, otherwise the following part-list head pushes currentIndent below // zero and its child ends up at indent 0 instead of 1. var positions = new[] { Title(2), PartListHead(0), Position(1), }; var indents = PasteIndentNormalizer.CalculateIndents(positions); Assert.Equal(new[] { 0, 0, 1 }, indents); } [Fact] public void CalculateIndents_TitleResetsIndentOfPrecedingPartList() { var positions = new[] { PartListHead(0), Position(1), Title(0), Position(0), }; var indents = PasteIndentNormalizer.CalculateIndents(positions); Assert.Equal(new[] { 0, 1, 0, 0 }, indents); } [Fact] public void CalculateIndents_RebasesCutOutTakenFromInsideAPartList() { // Cut-out starts at indent 2 because it was copied out of a nested part-list. var positions = new[] { PartListHead(2), Position(3), Position(3), Position(2), }; var indents = PasteIndentNormalizer.CalculateIndents(positions); Assert.Equal(new[] { 0, 1, 1, 0 }, indents); } [Fact] public void CalculateIndents_KeepsNestedPartLists() { var positions = new[] { PartListHead(0), PartListHead(1), Position(2), Position(1), }; var indents = PasteIndentNormalizer.CalculateIndents(positions); Assert.Equal(new[] { 0, 1, 2, 1 }, indents); } [Fact] public void CalculateIndents_ClosesAllPartListsLeftAtOnce() { // The last position leaves three part-lists at the same time and therefore belongs back // on the top level. var positions = new[] { PartListHead(0), PartListHead(1), PartListHead(2), Position(0), }; var indents = PasteIndentNormalizer.CalculateIndents(positions); Assert.Equal(new[] { 0, 1, 2, 0 }, indents); } [Fact] public void CalculateIndents_ClosesPartListsUpToTheRemainingLevel() { // The cut-out drops from indent 3 back to indent 1, so only the two inner part-lists are // closed and the position stays inside the outermost one. var positions = new[] { PartListHead(0), PartListHead(1), PartListHead(2), Position(3), Position(1), }; var indents = PasteIndentNormalizer.CalculateIndents(positions); Assert.Equal(new[] { 0, 1, 2, 3, 1 }, indents); } [Fact] public void CalculateIndents_FlatPositionsStayAtZero() { var positions = new[] { Position(0), Position(0), Position(0), }; var indents = PasteIndentNormalizer.CalculateIndents(positions); Assert.Equal(new[] { 0, 0, 0 }, indents); } } }