using EnvelopeRenderer.Desktop.Core.Design; namespace EnvelopeRenderer.Desktop.Tests; public class AddressLineCollapserTests { [Fact] public void Resolve_NoLineCollapses_EveryLineVisibleAtOriginalY() { var lines = new[] { new AddressLineCollapser.Line(100, 300, false), new AddressLineCollapser.Line(100, 285, false), }; var resolved = AddressLineCollapser.Resolve(lines); Assert.All(resolved, r => Assert.True(r.Visible)); Assert.Equal(300, resolved[0].EffectiveY, precision: 6); Assert.Equal(285, resolved[1].EffectiveY, precision: 6); } [Fact] public void Resolve_SingleBlankLine_SubsequentLineShiftsUpByItsRowHeight() { var lines = new[] { new AddressLineCollapser.Line(100, 300, false), new AddressLineCollapser.Line(100, 285, true), new AddressLineCollapser.Line(100, 270, false), }; var resolved = AddressLineCollapser.Resolve(lines); Assert.True(resolved[0].Visible); Assert.False(resolved[1].Visible); Assert.True(resolved[2].Visible); Assert.Equal(285, resolved[2].EffectiveY, precision: 6); } [Fact] public void Resolve_MultipleConsecutiveBlankLines_CollapseWithoutLeavingExtraGaps() { var lines = new[] { new AddressLineCollapser.Line(100, 300, false), new AddressLineCollapser.Line(100, 285, true), new AddressLineCollapser.Line(100, 270, true), new AddressLineCollapser.Line(100, 255, false), }; var resolved = AddressLineCollapser.Resolve(lines); Assert.False(resolved[1].Visible); Assert.False(resolved[2].Visible); Assert.True(resolved[3].Visible); Assert.Equal(285, resolved[3].EffectiveY, precision: 6); } [Fact] public void Resolve_LinesAtDifferentX_DoNotAffectEachOther() { var lines = new[] { new AddressLineCollapser.Line(100, 300, false), new AddressLineCollapser.Line(100, 285, true), new AddressLineCollapser.Line(400, 300, false), new AddressLineCollapser.Line(400, 285, false), }; var resolved = AddressLineCollapser.Resolve(lines); Assert.False(resolved[1].Visible); Assert.True(resolved[3].Visible); Assert.Equal(285, resolved[3].EffectiveY, precision: 6); } [Fact] public void Resolve_LastLineBlank_IsANoOp() { var lines = new[] { new AddressLineCollapser.Line(100, 300, false), new AddressLineCollapser.Line(100, 285, true), }; var resolved = AddressLineCollapser.Resolve(lines); Assert.True(resolved[0].Visible); Assert.False(resolved[1].Visible); } }