| 1 | using CascadeIDE.Services.Presentation; |
| 2 | using Xunit; |
| 3 | |
| 4 | namespace CascadeIDE.Tests; |
| 5 | |
| 6 | public sealed class PresentationLayoutAnalyzerTests |
| 7 | { |
| 8 | private static PresentationGrammarTokens DefaultGrammar() => |
| 9 | PresentationGrammarTokens.FromSettings( |
| 10 | brackets: "()", |
| 11 | betweenScreens: " ", |
| 12 | betweenZones: "+", |
| 13 | pfdZoneIdentifier: "P", |
| 14 | forwardZoneIdentifier: "F", |
| 15 | mfdZoneIdentifier: "M"); |
| 16 | |
| 17 | [Fact] |
| 18 | public void IsPfdForwardCombinedOnFirstScreen_WhenXPYFAndM_True() |
| 19 | { |
| 20 | var r = PresentationParser.Parse("(0.25P + 0.75F) (M)", DefaultGrammar()); |
| 21 | Assert.True(r.IsSuccess); |
| 22 | Assert.True(PresentationLayoutAnalyzer.IsPfdForwardCombinedOnFirstScreen(r.Screens)); |
| 23 | } |
| 24 | |
| 25 | [Fact] |
| 26 | public void IsPfdForwardCombinedOnFirstScreen_WhenTripleScreensP_F_M_False() |
| 27 | { |
| 28 | var r = PresentationParser.Parse("(P) (F) (M)", DefaultGrammar()); |
| 29 | Assert.True(r.IsSuccess); |
| 30 | Assert.False(PresentationLayoutAnalyzer.IsPfdForwardCombinedOnFirstScreen(r.Screens)); |
| 31 | } |
| 32 | |
| 33 | [Fact] |
| 34 | public void ShouldMaximizeMainWindowAtStartup_WhenTripleP_F_M_True() |
| 35 | { |
| 36 | var r = PresentationParser.Parse("(P) (F) (M)", DefaultGrammar()); |
| 37 | Assert.True(r.IsSuccess); |
| 38 | Assert.True(PresentationLayoutAnalyzer.ShouldMaximizeMainWindowAtStartup(r.Screens)); |
| 39 | } |
| 40 | |
| 41 | [Fact] |
| 42 | public void ShouldMaximizeMainWindowAtStartup_WhenSingleScreenWeightedP_F_M_True() |
| 43 | { |
| 44 | var g = PresentationGrammarTokens.FromSettings("()", " ", "+", "P", "F", "M"); |
| 45 | var r = PresentationParser.Parse("(0.2P+0.3F+0.5M)", g); |
| 46 | Assert.True(r.IsSuccess); |
| 47 | Assert.True(PresentationLayoutAnalyzer.ShouldMaximizeMainWindowAtStartup(r.Screens)); |
| 48 | } |
| 49 | |
| 50 | [Fact] |
| 51 | public void IsPfdForwardCombinedOnFirstScreen_WhenOnlyP_False() |
| 52 | { |
| 53 | var r = PresentationParser.Parse("(P)", DefaultGrammar()); |
| 54 | Assert.True(r.IsSuccess); |
| 55 | Assert.False(PresentationLayoutAnalyzer.IsPfdForwardCombinedOnFirstScreen(r.Screens)); |
| 56 | } |
| 57 | |
| 58 | [Fact] |
| 59 | public void TryGetMainWindowPresentationScreenIndex_TripleP_F_M_ForwardIsScreen1() |
| 60 | { |
| 61 | var r = PresentationParser.Parse("(P) (F) (M)", DefaultGrammar()); |
| 62 | Assert.True(r.IsSuccess); |
| 63 | Assert.True(PresentationLayoutAnalyzer.TryGetMainWindowPresentationScreenIndex(r.Screens, out var idx)); |
| 64 | Assert.Equal(1, idx); |
| 65 | Assert.Equal(1, PresentationLayoutAnalyzer.GetMainWindowPresentationScreenIndexOrDefault(r)); |
| 66 | } |
| 67 | |
| 68 | [Fact] |
| 69 | public void TryGetMainWindowPresentationScreenIndex_TriplePermuted_M_F_P_ForwardIsScreen1() |
| 70 | { |
| 71 | var r = PresentationParser.Parse("(M) (F) (P)", DefaultGrammar()); |
| 72 | Assert.True(r.IsSuccess); |
| 73 | Assert.True(PresentationLayoutAnalyzer.TryGetMainWindowPresentationScreenIndex(r.Screens, out var idx)); |
| 74 | Assert.Equal(1, idx); |
| 75 | } |
| 76 | |
| 77 | [Fact] |
| 78 | public void IsForwardMfdTwoScreenPreset_WhenF_M_True() |
| 79 | { |
| 80 | var r = PresentationParser.Parse("(F) (M)", DefaultGrammar()); |
| 81 | Assert.True(r.IsSuccess); |
| 82 | Assert.True(PresentationLayoutAnalyzer.IsForwardMfdTwoScreenPreset(r.Screens)); |
| 83 | Assert.True(PresentationLayoutAnalyzer.ShouldMaximizeMainWindowAtStartup(r.Screens)); |
| 84 | Assert.True(PresentationLayoutAnalyzer.TryGetMainWindowPresentationScreenIndex(r.Screens, out var mainIdx)); |
| 85 | Assert.Equal(0, mainIdx); |
| 86 | Assert.True(PresentationLayoutAnalyzer.TryGetMfdHostPresentationScreenIndex(r.Screens, out var mfdIdx)); |
| 87 | Assert.Equal(1, mfdIdx); |
| 88 | } |
| 89 | |
| 90 | [Fact] |
| 91 | public void IsForwardMfdTwoScreenPreset_WhenM_F_Symmetric() |
| 92 | { |
| 93 | var r = PresentationParser.Parse("(M) (F)", DefaultGrammar()); |
| 94 | Assert.True(r.IsSuccess); |
| 95 | Assert.True(PresentationLayoutAnalyzer.IsForwardMfdTwoScreenPreset(r.Screens)); |
| 96 | Assert.True(PresentationLayoutAnalyzer.TryGetMainWindowPresentationScreenIndex(r.Screens, out var mainIdx)); |
| 97 | Assert.Equal(1, mainIdx); |
| 98 | Assert.True(PresentationLayoutAnalyzer.TryGetMfdHostPresentationScreenIndex(r.Screens, out var mfdIdx)); |
| 99 | Assert.Equal(0, mfdIdx); |
| 100 | } |
| 101 | } |
| 102 | |