Skip to content

Commit c449eba

Browse files
authored
Code Quality: Added hierarchical page navigation to UI Test app (#15879)
1 parent 114bff3 commit c449eba

File tree

9 files changed

+731
-546
lines changed

9 files changed

+731
-546
lines changed

tests/Files.App.UITests/App.xaml.cs

Lines changed: 3 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -5,33 +5,16 @@
55

66
namespace Files.App.UITests
77
{
8-
/// <summary>
9-
/// Provides application-specific behavior to supplement the default Application class.
10-
/// </summary>
118
public partial class App : Application
129
{
13-
/// <summary>
14-
/// Initializes the singleton application object. This is the first line of authored code
15-
/// executed, and as such is the logical equivalent of main() or WinMain().
16-
/// </summary>
1710
public App()
1811
{
19-
this.InitializeComponent();
12+
InitializeComponent();
2013
}
2114

22-
/// <summary>
23-
/// Invoked when the application is launched.
24-
/// </summary>
25-
/// <param name="args">Details about the launch request and process.</param>
26-
protected override void OnLaunched(Microsoft.UI.Xaml.LaunchActivatedEventArgs args)
15+
protected override void OnLaunched(LaunchActivatedEventArgs args)
2716
{
28-
m_window = new MainWindow();
29-
30-
m_window.ExtendsContentIntoTitleBar = true;
31-
32-
m_window.Activate();
17+
MainWindow.Instance.Activate();
3318
}
34-
35-
private Window m_window;
3619
}
3720
}

tests/Files.App.UITests/MainWindow.xaml

Lines changed: 48 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@
77
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
88
xmlns:local="using:Files.App.UITests"
99
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
10-
xmlns:uc="using:Files.App.UITests.UserControls"
1110
Title="Files.App.Controls.UITests"
1211
mc:Ignorable="d">
1312

@@ -21,6 +20,7 @@
2120
<RowDefinition Height="*" />
2221
</Grid.RowDefinitions>
2322

23+
<!-- Title bar -->
2424
<Grid
2525
x:Name="FauxTitleBar"
2626
Grid.Row="0"
@@ -59,10 +59,54 @@
5959

6060
</Grid>
6161

62-
<uc:ThemedIconsUC
62+
<NavigationView
63+
x:Name="MainNavigationView"
6364
Grid.Row="1"
64-
HorizontalAlignment="Stretch"
65-
VerticalAlignment="Stretch" />
65+
IsBackButtonVisible="Collapsed"
66+
IsSettingsVisible="False"
67+
OpenPaneLength="256"
68+
SelectionChanged="NavigationView_SelectionChanged">
69+
70+
<NavigationView.MenuItems>
71+
<NavigationViewItem Content="Controls">
72+
<NavigationViewItem.Icon>
73+
<FontIcon Glyph="&#xE73A;" />
74+
</NavigationViewItem.Icon>
75+
<NavigationViewItem.MenuItems>
76+
<NavigationViewItem Content="ThemedIcon" Tag="ThemedIconPage" />
77+
</NavigationViewItem.MenuItems>
78+
</NavigationViewItem>
79+
</NavigationView.MenuItems>
80+
81+
<NavigationView.Content>
82+
<ScrollViewer>
83+
<Frame x:Name="MainFrame" />
84+
</ScrollViewer>
85+
</NavigationView.Content>
86+
87+
<NavigationView.PaneFooter>
88+
<Grid
89+
Margin="8,2"
90+
Padding="12,8"
91+
Background="{ThemeResource CardBackgroundFillColorDefaultBrush}"
92+
CornerRadius="4"
93+
Visibility="{Binding MainNavigationView.IsPaneOpen, Mode=OneWay}">
94+
<TextBlock VerticalAlignment="Center" Text="Theme mode:" />
95+
<ComboBox
96+
x:Name="ThemeModeSelectorCombBox"
97+
HorizontalAlignment="Right"
98+
SelectedIndex="0"
99+
SelectionChanged="ThemeModeSelectorCombBox_SelectionChanged">
100+
<ComboBox.Items>
101+
<ComboBoxItem Content="Default" />
102+
<ComboBoxItem Content="Light" />
103+
<ComboBoxItem Content="Dark" />
104+
</ComboBox.Items>
105+
</ComboBox>
106+
</Grid>
107+
</NavigationView.PaneFooter>
108+
109+
</NavigationView>
66110
</Grid>
67111

68112
</Window>
Lines changed: 44 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,57 @@
11
// Copyright (c) 2024 Files Community
22
// Licensed under the MIT License. See the LICENSE.
33

4+
using Files.App.UITests.Views;
45
using Microsoft.UI.Xaml;
6+
using Microsoft.UI.Xaml.Controls;
57

68
namespace Files.App.UITests
79
{
8-
/// <summary>
9-
/// An empty window that can be used on its own or navigated to within a Frame.
10-
/// </summary>
1110
public sealed partial class MainWindow : Window
1211
{
13-
public MainWindow()
12+
private static MainWindow? _Instance;
13+
public static MainWindow Instance => _Instance ??= new();
14+
15+
private MainWindow()
16+
{
17+
InitializeComponent();
18+
19+
ExtendsContentIntoTitleBar = true;
20+
21+
MainFrame.Navigate(typeof(MainPage));
22+
}
23+
24+
private void NavigationView_SelectionChanged(NavigationView sender, NavigationViewSelectionChangedEventArgs args)
1425
{
15-
this.InitializeComponent();
26+
if (args.SelectedItem is not NavigationViewItem item || item.Tag is not string tag)
27+
return;
28+
29+
switch (tag)
30+
{
31+
case "ThemedIconPage":
32+
MainFrame.Navigate(typeof(ThemedIconPage));
33+
break;
34+
}
35+
}
36+
37+
private void ThemeModeSelectorCombBox_SelectionChanged(object sender, SelectionChangedEventArgs e)
38+
{
39+
if (sender is not ComboBox comboBox ||
40+
Content is not FrameworkElement element)
41+
return;
42+
43+
switch (comboBox.SelectedIndex)
44+
{
45+
case 0:
46+
element.RequestedTheme = ElementTheme.Default;
47+
break;
48+
case 1:
49+
element.RequestedTheme = ElementTheme.Light;
50+
break;
51+
case 2:
52+
element.RequestedTheme = ElementTheme.Dark;
53+
break;
54+
}
1655
}
1756
}
1857
}

0 commit comments

Comments
 (0)