123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347 |
- using Avalonia.Animation;
- using Avalonia.Input;
- using Avalonia.UnitTests;
- using Moq;
- using Xunit;
- namespace Avalonia.Controls.UnitTests
- {
-
- public class SplitViewTests : ScopedTestBase
- {
- [Fact]
- public void SplitView_PaneOpening_Should_Fire_Before_PaneOpened()
- {
- var splitView = new SplitView();
- bool handledOpening = false;
- splitView.PaneOpening += (x, e) =>
- {
- handledOpening = true;
- };
- splitView.PaneOpened += (x, e) =>
- {
- Assert.True(handledOpening);
- };
- splitView.IsPaneOpen = true;
- }
- [Fact]
- public void SplitView_PaneClosing_Should_Fire_Before_PaneClosed()
- {
- var splitView = new SplitView();
- splitView.IsPaneOpen = true;
- bool handledClosing = false;
- splitView.PaneClosing += (x, e) =>
- {
- handledClosing = true;
- };
- splitView.PaneClosed += (x, e) =>
- {
- Assert.True(handledClosing);
- };
- splitView.IsPaneOpen = false;
- }
- [Fact]
- public void SplitView_Cancel_Close_Should_Prevent_Pane_From_Closing()
- {
- var splitView = new SplitView();
- splitView.IsPaneOpen = true;
- splitView.PaneClosing += (x, e) =>
- {
- e.Cancel = true;
- };
- splitView.IsPaneOpen = false;
- Assert.True(splitView.IsPaneOpen);
- }
- [Fact]
- public void SplitView_TemplateSettings_Are_Correct_For_Display_Modes()
- {
- using var app = UnitTestApplication.Start(TestServices.StyledWindow
- .With(globalClock: new MockGlobalClock()));
- var wnd = new Window
- {
- Width = 1280,
- Height = 720
- };
- var splitView = new SplitView();
- wnd.Content = splitView;
- wnd.Show();
- var zeroGridLength = new GridLength(0);
- var compactLength = splitView.CompactPaneLength;
- var compactGridLength = new GridLength(compactLength);
- // Overlay is default DisplayMode
- Assert.Equal(0, splitView.TemplateSettings.ClosedPaneWidth);
- Assert.Equal(zeroGridLength, splitView.TemplateSettings.PaneColumnGridLength);
- splitView.DisplayMode = SplitViewDisplayMode.CompactOverlay;
- Assert.Equal(compactLength, splitView.TemplateSettings.ClosedPaneWidth);
- Assert.Equal(compactGridLength, splitView.TemplateSettings.PaneColumnGridLength);
- splitView.DisplayMode = SplitViewDisplayMode.Inline;
- Assert.Equal(0, splitView.TemplateSettings.ClosedPaneWidth);
- Assert.Equal(GridLength.Auto, splitView.TemplateSettings.PaneColumnGridLength);
- splitView.DisplayMode = SplitViewDisplayMode.CompactInline;
- Assert.Equal(compactLength, splitView.TemplateSettings.ClosedPaneWidth);
- Assert.Equal(GridLength.Auto, splitView.TemplateSettings.PaneColumnGridLength);
- }
- [Fact]
- public void SplitView_TemplateSettings_Update_With_CompactPaneLength()
- {
- var splitView = new SplitView();
-
- // CompactInline:
- // - ClosedPaneWidth = CompactPaneLength
- // - PaneColumnGridLength = Auto
- splitView.DisplayMode = SplitViewDisplayMode.CompactInline;
- var compactLength = splitView.CompactPaneLength;
-
- Assert.Equal(GridLength.Auto, splitView.TemplateSettings.PaneColumnGridLength);
- Assert.Equal(compactLength, splitView.TemplateSettings.ClosedPaneWidth);
- splitView.CompactPaneLength = 100;
- Assert.Equal(GridLength.Auto, splitView.TemplateSettings.PaneColumnGridLength);
- Assert.Equal(100, splitView.TemplateSettings.ClosedPaneWidth);
- // CompactOverlay:
- // - ClosedPaneWidth = CompactPaneLength
- // - PaneColumnGridLength = GridLength { CompactPaneLength, Pixel }
- splitView.DisplayMode = SplitViewDisplayMode.CompactOverlay;
- splitView.CompactPaneLength = 50;
- Assert.Equal(new GridLength(50), splitView.TemplateSettings.PaneColumnGridLength);
- Assert.Equal(50, splitView.TemplateSettings.ClosedPaneWidth);
- // Value shouldn't change for these - changing the display mode will update
- // the template settings with the right value
- splitView.DisplayMode = SplitViewDisplayMode.Inline;
- splitView.CompactPaneLength = 1;
- Assert.Equal(GridLength.Auto, splitView.TemplateSettings.PaneColumnGridLength);
- Assert.Equal(0, splitView.TemplateSettings.ClosedPaneWidth);
- splitView.DisplayMode = SplitViewDisplayMode.Overlay;
- splitView.CompactPaneLength = 2;
- Assert.Equal(new GridLength(0), splitView.TemplateSettings.PaneColumnGridLength);
- Assert.Equal(0, splitView.TemplateSettings.ClosedPaneWidth);
- }
- [Fact]
- public void SplitView_Pointer_Closes_Pane_In_Overlay_Mode()
- {
- using var app = UnitTestApplication.Start(TestServices.StyledWindow
- .With(globalClock: new MockGlobalClock()));
- var wnd = new Window
- {
- Width = 1280,
- Height = 720
- };
- var splitView = new SplitView();
- wnd.Content = splitView;
- wnd.Show();
- splitView.IsPaneOpen = true;
- splitView.RaiseEvent(new PointerReleasedEventArgs(splitView,
- null, wnd, new Point(1270, 30), 0,
- new PointerPointProperties(),
- KeyModifiers.None,
- MouseButton.Left));
- Assert.False(splitView.IsPaneOpen);
- // Inline shouldn't close the pane
- splitView.DisplayMode = SplitViewDisplayMode.Inline;
- splitView.IsPaneOpen = true;
- splitView.RaiseEvent(new PointerReleasedEventArgs(splitView,
- null, wnd, new Point(1270, 30), 0,
- new PointerPointProperties(),
- KeyModifiers.None,
- MouseButton.Left));
- Assert.True(splitView.IsPaneOpen);
- }
- [Fact]
- public void SplitView_Pointer_Should_Not_Close_Pane_If_Over_Pane()
- {
- using var app = UnitTestApplication.Start(TestServices.StyledWindow
- .With(globalClock: new MockGlobalClock()));
- var wnd = new Window
- {
- Width = 1280,
- Height = 720
- };
- var clickBorder = new Border
- {
- Width = 100,
- Height = 100,
- HorizontalAlignment = Layout.HorizontalAlignment.Left,
- VerticalAlignment = Layout.VerticalAlignment.Top
- };
- var splitView = new SplitView
- {
- Pane = clickBorder
- };
- wnd.Content = splitView;
- wnd.Show();
- splitView.IsPaneOpen = true;
- clickBorder.RaiseEvent(new PointerReleasedEventArgs(splitView,
- null, wnd, new Point(5, 5), 0,
- new PointerPointProperties(),
- KeyModifiers.None,
- MouseButton.Left));
- Assert.True(splitView.IsPaneOpen);
- }
- [Fact]
- public void SplitView_Escape_Key_Closes_Light_Dismissable_Pane()
- {
- using var app = UnitTestApplication.Start(TestServices.StyledWindow
- .With(globalClock: new MockGlobalClock()));
- var wnd = new Window
- {
- Width = 1280,
- Height = 720
- };
- var button = new Button();
- var splitView = new SplitView
- {
- Pane = button
- };
- wnd.Content = splitView;
- wnd.Show();
- splitView.IsPaneOpen = true;
- button.RaiseEvent(new KeyEventArgs
- {
- Key = Key.Escape,
- RoutedEvent = InputElement.KeyDownEvent
- });
- Assert.False(splitView.IsPaneOpen);
- splitView.DisplayMode = SplitViewDisplayMode.Inline;
- splitView.IsPaneOpen = true;
- button.RaiseEvent(new KeyEventArgs
- {
- Key = Key.Escape,
- RoutedEvent = InputElement.KeyDownEvent
- });
- Assert.True(splitView.IsPaneOpen);
- }
- [Fact]
- public void Top_Level_Back_Requested_Closes_Light_Dismissable_Pane()
- {
- using var app = UnitTestApplication.Start(TestServices.StyledWindow
- .With(globalClock: new MockGlobalClock()));
- var wnd = new Window
- {
- Width = 1280,
- Height = 720
- };
- var splitView = new SplitView();
- wnd.Content = splitView;
- wnd.Show();
- splitView.IsPaneOpen = true;
- wnd.RaiseEvent(new Interactivity.RoutedEventArgs(TopLevel.BackRequestedEvent));
- Assert.False(splitView.IsPaneOpen);
- splitView.DisplayMode = SplitViewDisplayMode.Inline;
- splitView.IsPaneOpen = true;
- wnd.RaiseEvent(new Interactivity.RoutedEventArgs(TopLevel.BackRequestedEvent));
- Assert.True(splitView.IsPaneOpen);
- }
- [Fact]
- public void With_Default_IsPaneOpen_Value_Should_Have_Closed_Pseudo_Class_Set()
- {
- // Testing this control Pseudo Classes requires placing the SplitView on a window
- // prior to asserting them, because some of the pseudo classes are set either when
- // the template is applied or the control is attached to the visual tree
- using var app = UnitTestApplication.Start(TestServices.StyledWindow
- .With(globalClock: new MockGlobalClock()));
- var wnd = new Window
- {
- Width = 1280,
- Height = 720
- };
- var splitView = new SplitView();
- wnd.Content = splitView;
- wnd.Show();
- Assert.Contains(splitView.Classes, ":closed".Equals);
- }
-
- [Fact]
- public void SplitView_Shouldnt_Close_Panel_When_IsPaneOpen_True_Then_Display_Mode_Changed()
- {
- using var app = UnitTestApplication.Start(TestServices.StyledWindow
- .With(globalClock: new MockGlobalClock()));
- var wnd = new Window
- {
- Width = 1280,
- Height = 720
- };
- var splitView = new SplitView();
- splitView.DisplayMode = SplitViewDisplayMode.CompactOverlay;
- wnd.Content = splitView;
- wnd.Show();
- splitView.IsPaneOpen = true;
- splitView.RaiseEvent(new PointerReleasedEventArgs(splitView,
- null, wnd, new Point(1270, 30), 0,
- new PointerPointProperties(),
- KeyModifiers.None,
- MouseButton.Left));
- Assert.False(splitView.IsPaneOpen);
- // Inline shouldn't close the pane
- splitView.IsPaneOpen = true;
-
- // Change the display mode once the pane is already open.
- splitView.DisplayMode = SplitViewDisplayMode.Inline;
- splitView.RaiseEvent(new PointerReleasedEventArgs(splitView,
- null, wnd, new Point(1270, 30), 0,
- new PointerPointProperties(),
- KeyModifiers.None,
- MouseButton.Left));
- Assert.True(splitView.IsPaneOpen);
- }
- }
- }
|