| 1 | using CascadeIDE.Services.Presentation; |
| 2 | using Xunit; |
| 3 | |
| 4 | namespace CascadeIDE.Tests; |
| 5 | |
| 6 | public sealed class PresentationMainGridLayoutFrameBuilderTests |
| 7 | { |
| 8 | private static readonly PresentationGrammarTokens ShortGrammar = |
| 9 | PresentationGrammarTokens.FromSettings("()", " ", "+", "P", "F", "M"); |
| 10 | |
| 11 | [Fact] |
| 12 | public void TripleWeighted_BuildsWeightedColumns() |
| 13 | { |
| 14 | var parse = PresentationParser.Parse("(0.2P+0.3F+0.5M)", ShortGrammar); |
| 15 | Assert.True(parse.IsSuccess); |
| 16 | |
| 17 | var frame = PresentationMainGridLayoutFrameBuilder.Build( |
| 18 | parse, |
| 19 | dedicatedMfdSecondScreen: false, |
| 20 | mfdColumnSuppressedForHost: false, |
| 21 | tripleOneAnchorPerZone: false, |
| 22 | suppressPfdColumnForPfdHostWindow: false); |
| 23 | |
| 24 | Assert.Equal("0.2*,4,0.3*,4,0.5*", frame.ColumnDefinitions); |
| 25 | Assert.Equal(3, frame.ContentZoneCount); |
| 26 | Assert.True(frame.HasExplicitWeights); |
| 27 | Assert.Equal(3, frame.NormalizedZoneWeights.Count); |
| 28 | Assert.Equal(3, frame.ZoneBounds.Count); |
| 29 | Assert.Equal(PresentationAnchorKind.Pfd, frame.ZoneBounds[0].Zone); |
| 30 | Assert.Equal(0.0, frame.ZoneBounds[0].StartNormalized, 8); |
| 31 | Assert.Equal(0.2, frame.ZoneBounds[0].WidthNormalized, 8); |
| 32 | Assert.Equal(PresentationAnchorKind.Forward, frame.ZoneBounds[1].Zone); |
| 33 | Assert.Equal(0.2, frame.ZoneBounds[1].StartNormalized, 8); |
| 34 | Assert.Equal(0.3, frame.ZoneBounds[1].WidthNormalized, 8); |
| 35 | Assert.Equal(PresentationAnchorKind.Mfd, frame.ZoneBounds[2].Zone); |
| 36 | Assert.Equal(0.5, frame.ZoneBounds[2].StartNormalized, 8); |
| 37 | Assert.Equal(0.5, frame.ZoneBounds[2].WidthNormalized, 8); |
| 38 | } |
| 39 | |
| 40 | [Fact] |
| 41 | public void DualWeighted_DedicatedAndSuppressed_UsesZeroTail() |
| 42 | { |
| 43 | var parse = PresentationParser.Parse("(0.25P+0.75F)(M)", ShortGrammar); |
| 44 | Assert.True(parse.IsSuccess); |
| 45 | |
| 46 | var frame = PresentationMainGridLayoutFrameBuilder.Build( |
| 47 | parse, |
| 48 | dedicatedMfdSecondScreen: true, |
| 49 | mfdColumnSuppressedForHost: true, |
| 50 | tripleOneAnchorPerZone: false, |
| 51 | suppressPfdColumnForPfdHostWindow: false); |
| 52 | |
| 53 | Assert.Equal("0.25*,4,0.75*,4,0", frame.ColumnDefinitions); |
| 54 | Assert.Equal(2, frame.ContentZoneCount); |
| 55 | Assert.True(frame.HasExplicitWeights); |
| 56 | Assert.Equal(2, frame.ZoneBounds.Count); |
| 57 | Assert.Equal(PresentationAnchorKind.Pfd, frame.ZoneBounds[0].Zone); |
| 58 | Assert.Equal(0.0, frame.ZoneBounds[0].StartNormalized, 8); |
| 59 | Assert.Equal(0.25, frame.ZoneBounds[0].WidthNormalized, 8); |
| 60 | Assert.Equal(PresentationAnchorKind.Forward, frame.ZoneBounds[1].Zone); |
| 61 | Assert.Equal(0.25, frame.ZoneBounds[1].StartNormalized, 8); |
| 62 | Assert.Equal(0.75, frame.ZoneBounds[1].WidthNormalized, 8); |
| 63 | } |
| 64 | |
| 65 | [Fact] |
| 66 | public void NoWeights_UsesDefaultColumns_AndProvidesNormalizedShares() |
| 67 | { |
| 68 | var parse = PresentationParser.Parse("(P+F+M)", ShortGrammar); |
| 69 | Assert.True(parse.IsSuccess); |
| 70 | |
| 71 | var frame = PresentationMainGridLayoutFrameBuilder.Build( |
| 72 | parse, |
| 73 | dedicatedMfdSecondScreen: false, |
| 74 | mfdColumnSuppressedForHost: false, |
| 75 | tripleOneAnchorPerZone: false, |
| 76 | suppressPfdColumnForPfdHostWindow: false); |
| 77 | |
| 78 | Assert.Equal(PresentationMainGridLayoutFrameBuilder.DefaultColumnDefinitions, frame.ColumnDefinitions); |
| 79 | Assert.Equal(3, frame.ContentZoneCount); |
| 80 | Assert.False(frame.HasExplicitWeights); |
| 81 | Assert.Equal(1.0 / 3.0, frame.NormalizedZoneWeights[0], 8); |
| 82 | Assert.Equal(1.0 / 3.0, frame.NormalizedZoneWeights[1], 8); |
| 83 | Assert.Equal(1.0 / 3.0, frame.NormalizedZoneWeights[2], 8); |
| 84 | Assert.Equal(3, frame.ZoneBounds.Count); |
| 85 | } |
| 86 | |
| 87 | [Fact] |
| 88 | public void ForwardMfdTwoScreen_MainWindowOnF_UsesForwardOnlyColumns() |
| 89 | { |
| 90 | var parse = PresentationParser.Parse("(F) (M)", ShortGrammar); |
| 91 | Assert.True(parse.IsSuccess); |
| 92 | |
| 93 | var frame = PresentationMainGridLayoutFrameBuilder.Build( |
| 94 | parse, |
| 95 | dedicatedMfdSecondScreen: false, |
| 96 | mfdColumnSuppressedForHost: true, |
| 97 | tripleOneAnchorPerZone: false, |
| 98 | suppressPfdColumnForPfdHostWindow: false, |
| 99 | mainWindowPresentationScreenIndex: 0); |
| 100 | |
| 101 | Assert.Equal("0,4,*,4,0", frame.ColumnDefinitions); |
| 102 | Assert.Equal(1, frame.ContentZoneCount); |
| 103 | } |
| 104 | } |
| 105 | |
| 106 | |