Skip to content
Merged
Prev Previous commit
Next Next commit
Add failing UI test
  • Loading branch information
nicolaihenriksen committed Feb 27, 2023
commit 6cb4c8b964b761ce1cad7b5cd44bd09cef02c19b
48 changes: 48 additions & 0 deletions MaterialDesignThemes.UITests/Samples/DialogHost/RestoreFocus.xaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
<UserControl x:Class="MaterialDesignThemes.UITests.Samples.DialogHost.RestoreFocus"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:local="clr-namespace:MaterialDesignThemes.UITests.Samples.DialogHost"
xmlns:materialDesign="http://materialdesigninxaml.net/winfx/xaml/themes"
mc:Ignorable="d"
d:DataContext="{d:DesignInstance Type=local:RestoreFocus}"
d:DesignHeight="450" d:DesignWidth="800">
<Grid>
<materialDesign:DialogHost x:Name="DialogHost">
<Grid>
<Grid.RowDefinitions>
<RowDefinition Height="Auto" />
<RowDefinition Height="*" />
</Grid.RowDefinitions>

<Menu x:Name="Menu" Grid.Row="0" HorizontalAlignment="Right">
<MenuItem x:Name="MenuItem1">
<MenuItem.Header>
<StackPanel Orientation="Horizontal">
<materialDesign:PackIcon Kind="User" Height="20" Width="20" Margin="0,0,5,0" />
<TextBlock Text="Menu" VerticalAlignment="Center" FontSize="16" />
</StackPanel>
</MenuItem.Header>
<MenuItem x:Name="MenuItem2" Header="Settings" Icon="{materialDesign:PackIcon Kind=Settings}" Command="{x:Static materialDesign:DialogHost.OpenDialogCommand}" />
</MenuItem>
</Menu>

<TabControl x:Name="TabControl" Grid.Row="1">
<TabItem x:Name="TabItem1" Header="Tab 1">
<TextBlock Text="Page 1" />
</TabItem>
<TabItem x:Name="TabItem2" Header="Tab 2">
<TextBlock Text="Page 2" />
</TabItem>
</TabControl>
</Grid>

<materialDesign:DialogHost.DialogContent>
<Grid Margin="50">
<Button x:Name="NavigateHomeButton" Content="Navigate to Tab 1" Click="NavigateHomeButton_OnClick" />
</Grid>
</materialDesign:DialogHost.DialogContent>
</materialDesign:DialogHost>
</Grid>
</UserControl>
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
namespace MaterialDesignThemes.UITests.Samples.DialogHost;

public partial class RestoreFocus : UserControl
{
public RestoreFocus()
{
InitializeComponent();
}

private void NavigateHomeButton_OnClick(object sender, RoutedEventArgs e)
{
Wpf.DialogHost.CloseDialogCommand.Execute(null, null);
TabControl.SelectedItem = TabItem1;
}
}
35 changes: 35 additions & 0 deletions MaterialDesignThemes.UITests/WPF/DialogHosts/DialogHostTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -349,5 +349,40 @@ await Wait.For(async () =>
await closeButton.LeftClick();
Assert.False(await dialogHost.GetIsOpen());
});

recorder.Success();
}

[Fact]
[Description("Issue 3094")]
public async Task DialogHost_ChangesSelectedTabItem_DoesNotPerformTabChangeWhenRestoringFocus()
{
await using var recorder = new TestRecorder(App);

IVisualElement<Grid> rootGrid = (await LoadUserControl<RestoreFocus>()).As<Grid>();
IVisualElement<TabItem> tabItem1 = await rootGrid.GetElement<TabItem>("TabItem1");
IVisualElement<TabItem> tabItem2 = await rootGrid.GetElement<TabItem>("TabItem2");
IVisualElement<Button> navigateHomeButton = await rootGrid.GetElement<Button>("NavigateHomeButton");

// Select TabItem2
await tabItem2.LeftClick();

// Open menu
IVisualElement<MenuItem> menuItem1 = await rootGrid.GetElement<MenuItem>("MenuItem1");
await menuItem1.LeftClick();
await Task.Delay(1000); // Wait for menu to open
IVisualElement<MenuItem> menuItem2 = await rootGrid.GetElement<MenuItem>("MenuItem2");
await menuItem2.LeftClick();
await Task.Delay(1000); // Wait for dialog content to show

// Click navigate button
await navigateHomeButton.LeftClick();
await Task.Delay(1000); // Wait for dialog content to close

Assert.True(await tabItem1.GetIsSelected());
Assert.False(await tabItem2.GetIsSelected());

recorder.Success();

}
}