|
| 1 | +using Avalonia; |
| 2 | +using Avalonia.Controls; |
| 3 | +using Avalonia.Headless; |
| 4 | +using Avalonia.Headless.XUnit; |
| 5 | +using Avalonia.Input; |
| 6 | +using Avalonia.Threading; |
| 7 | +using FluentAvalonia.UI.Controls; |
| 8 | +using SecRandom.Core.Attributes; |
| 9 | +using SecRandom.Core.Enums; |
| 10 | +using SecRandom.Views; |
| 11 | + |
| 12 | +namespace SecRandom.Mobile.Tests; |
| 13 | + |
| 14 | +/// <summary> |
| 15 | +/// Issue #268: the settings sidebar entry opens a separate window/view, so it must not take the |
| 16 | +/// navigation highlight away from the main page that stays visible. |
| 17 | +/// </summary> |
| 18 | +public sealed class MainViewSettingsNavigationTests |
| 19 | +{ |
| 20 | + [AvaloniaFact] |
| 21 | + public void SettingsEntryKeepsItsPageMetadataWithoutSelectingItself() |
| 22 | + { |
| 23 | + var item = Assert.IsType<FANavigationViewItem>(MainView.CreateSettingsNavigationItem()); |
| 24 | + |
| 25 | + Assert.False(item.SelectsOnInvoked); |
| 26 | + var info = Assert.IsType<PageInfo>(item.Tag); |
| 27 | + Assert.Equal("settings", info.Id); |
| 28 | + Assert.Equal(PageLocation.Bottom, info.Location); |
| 29 | + } |
| 30 | + |
| 31 | + [AvaloniaFact] |
| 32 | + public void InvokingTheSettingsEntryKeepsTheSelectedMainPage() |
| 33 | + { |
| 34 | + var rollCall = new FANavigationViewItem { Content = "Roll call" }; |
| 35 | + var settings = MainView.CreateSettingsNavigationItem(); |
| 36 | + var navigation = new FANavigationView |
| 37 | + { |
| 38 | + MenuItemsSource = new object[] { rollCall }, |
| 39 | + FooterMenuItemsSource = new object[] { settings }, |
| 40 | + SelectedItem = rollCall |
| 41 | + }; |
| 42 | + |
| 43 | + var window = new Window |
| 44 | + { |
| 45 | + Width = 900, |
| 46 | + Height = 600, |
| 47 | + Content = navigation |
| 48 | + }; |
| 49 | + window.Show(); |
| 50 | + Dispatcher.UIThread.RunJobs(); |
| 51 | + |
| 52 | + PageInfo? invoked = null; |
| 53 | + navigation.ItemInvoked += (_, args) => |
| 54 | + { |
| 55 | + if (args.InvokedItemContainer is FANavigationViewItem { Tag: PageInfo info }) |
| 56 | + invoked = info; |
| 57 | + }; |
| 58 | + |
| 59 | + var settingsControl = (Control)settings; |
| 60 | + var center = settingsControl.TranslatePoint( |
| 61 | + new Point(settingsControl.Bounds.Width / 2, settingsControl.Bounds.Height / 2), window); |
| 62 | + Assert.NotNull(center); |
| 63 | + |
| 64 | + window.MouseDown(center.Value, MouseButton.Left); |
| 65 | + window.MouseUp(center.Value, MouseButton.Left); |
| 66 | + Dispatcher.UIThread.RunJobs(); |
| 67 | + |
| 68 | + Assert.NotNull(invoked); |
| 69 | + Assert.Equal("settings", invoked.Id); |
| 70 | + Assert.Same(rollCall, navigation.SelectedItem); |
| 71 | + |
| 72 | + window.Close(); |
| 73 | + } |
| 74 | +} |
0 commit comments