test: Adjust runtime test to use sample

This commit is contained in:
Martin Zikmund 2024-07-16 21:04:26 +02:00
Родитель 2805af6973
Коммит 40a6ce9e0a
4 изменённых файлов: 175 добавлений и 25 удалений

Просмотреть файл

@ -0,0 +1,53 @@
<Page
x:Class="RuntimeTests.Windows_UI_Xaml_Controls.Flyout.Flyout_ToggleMenu_IsEnabled"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
mc:Ignorable="d"
Background="{ThemeResource ApplicationPageBackgroundThemeBrush}"
d:DesignHeight="300"
d:DesignWidth="400">
<StackPanel Orientation="Vertical" Spacing="10" Margin="10">
<Button FontSize="24" Content="Click me" >
<Button.Flyout>
<MenuFlyout AutomationProperties.AutomationId="FileViewer_ViewMenu_MenuFlyout" Placement="Bottom">
<ToggleMenuFlyoutItem AutomationProperties.AutomationId="ToggleMenuFlyoutItem1"
IsChecked="{x:Bind ViewModel.IsChecked1, Mode=OneWay}"
IsEnabled="{x:Bind ViewModel.AreItemsEnabled, Mode=OneWay}"
Text="Toggle 1"/>
<ToggleMenuFlyoutItem AutomationProperties.AutomationId="ToggleMenuFlyoutItem2"
IsChecked="{x:Bind ViewModel.IsChecked2, Mode=OneWay}"
IsEnabled="{x:Bind ViewModel.AreItemsEnabled, Mode=OneWay}"
Text="Toggle 2"/>
<ToggleMenuFlyoutItem AutomationProperties.AutomationId="ToggleMenuFlyoutItem3"
IsChecked="{x:Bind ViewModel.IsChecked3, Mode=OneWay}"
IsEnabled="{x:Bind ViewModel.AreItemsEnabled, Mode=OneWay}"
Text="Toggle 3"/>
<MenuFlyoutItem
Text="Basic item 1"
AutomationProperties.AutomationId="FileViewer_ViewMenu_Item1"
IsEnabled="{x:Bind ViewModel.AreItemsEnabled, Mode=OneWay}"/>
<MenuFlyoutItem
Text="Basic item 2"
AutomationProperties.AutomationId="FileViewer_ViewMenu_Item1"
IsEnabled="{x:Bind ViewModel.AreItemsEnabled, Mode=OneWay}"/>
</MenuFlyout>
</Button.Flyout>
<ToolTipService.ToolTip>
<ToolTip Content="View" />
</ToolTipService.ToolTip>
</Button>
<CheckBox IsChecked="{x:Bind ViewModel.AreItemsEnabled, Mode=OneWay}" Content="Enabled?"/>
</StackPanel>
</Page>

Просмотреть файл

@ -0,0 +1,80 @@
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Runtime.InteropServices.WindowsRuntime;
using Windows.Foundation;
using Windows.Foundation.Collections;
using Microsoft.UI.Xaml;
using Microsoft.UI.Xaml.Controls;
using Microsoft.UI.Xaml.Controls.Primitives;
using Microsoft.UI.Xaml.Data;
using Microsoft.UI.Xaml.Input;
using Microsoft.UI.Xaml.Media;
using Microsoft.UI.Xaml.Navigation;
using Uno.UI.RuntimeTests.Helpers;
namespace RuntimeTests.Windows_UI_Xaml_Controls.Flyout;
public sealed partial class Flyout_ToggleMenu_IsEnabled : Page
{
public Flyout_ToggleMenu_IsEnabled()
{
this.InitializeComponent();
}
internal Flyout_ToggleMenu_IsEnabledViewModel ViewModel { get; } = new Flyout_ToggleMenu_IsEnabledViewModel();
}
internal class Flyout_ToggleMenu_IsEnabledViewModel : ViewModelBase
{
private bool _isChecked1;
private bool _isChecked2;
private bool _isChecked3;
private bool _areItemsEnabled;
public Flyout_ToggleMenu_IsEnabledViewModel()
{
}
public bool IsChecked1
{
get => _isChecked1;
set
{
_isChecked1 = value;
RaisePropertyChanged();
}
}
public bool IsChecked2
{
get => _isChecked2;
set
{
_isChecked2 = value;
RaisePropertyChanged();
}
}
public bool IsChecked3
{
get => _isChecked3;
set
{
_isChecked3 = value;
RaisePropertyChanged();
}
}
public bool AreItemsEnabled
{
get => _areItemsEnabled;
set
{
_areItemsEnabled = value;
RaisePropertyChanged();
}
}
}

Просмотреть файл

@ -32,6 +32,7 @@ using Microsoft/* UWP don't rename */.UI.Xaml.Controls;
using MenuBar = Microsoft/* UWP don't rename */.UI.Xaml.Controls.MenuBar;
using MenuBarItem = Microsoft/* UWP don't rename */.UI.Xaml.Controls.MenuBarItem;
using MenuBarItemAutomationPeer = Microsoft/* UWP don't rename */.UI.Xaml.Automation.Peers.MenuBarItemAutomationPeer;
using RuntimeTests.Windows_UI_Xaml_Controls.Flyout;
namespace Uno.UI.RuntimeTests.Tests.Windows_UI_Xaml_Controls
{
@ -46,41 +47,45 @@ namespace Uno.UI.RuntimeTests.Tests.Windows_UI_Xaml_Controls
[RequiresFullWindow]
public async Task When_Toggle_IsEnabled_Via_Binding()
{
var menu = new MenuFlyout();
var toggleItem = new ToggleMenuFlyoutItem();
menu.Items.Add(toggleItem);
var button = new Button();
button.Flyout = menu;
var checkBox = new CheckBox();
// Bind the toggleItem.IsEnabled to checkbox.IsChecked
toggleItem.SetBinding(ToggleMenuFlyoutItem.IsEnabledProperty, new Binding { Source = checkBox, Path = "IsChecked", Mode = BindingMode.OneWay });
var page = new Flyout_ToggleMenu_IsEnabled();
WindowHelper.WindowContent = button;
await WindowHelper.WaitForLoaded(button);
WindowHelper.WindowContent = page;
await WindowHelper.WaitForLoaded(page);
button.Flyout.ShowAt(button);
var content = page.Content as StackPanel;
var button = content.Children.First() as Button;
var buttonPeer = FrameworkElementAutomationPeer.CreatePeerForElement(button) as ButtonAutomationPeer;
// The toggleItem should be disabled by default
Assert.IsFalse(toggleItem.IsEnabled);
var flyout = button.Flyout as MenuFlyout;
button.Flyout.Hide();
async Task AssertIsEnabled(bool expected)
{
buttonPeer.Invoke();
await TestServices.WindowHelper.WaitFor(() => VisualTreeHelper.GetOpenPopupsForXamlRoot(TestServices.WindowHelper.XamlRoot).Count > 0);
var popup = VisualTreeHelper.GetOpenPopupsForXamlRoot(TestServices.WindowHelper.XamlRoot).First();
foreach (var item in flyout.Items)
{
// The toggleItem should be disabled by default
Assert.AreEqual(expected, item.IsEnabled);
}
popup.IsOpen = false;
await WindowHelper.WaitForIdle();
}
await AssertIsEnabled(false);
// Enable the toggleItem
checkBox.IsChecked = true;
page.ViewModel.AreItemsEnabled = true;
button.Flyout.ShowAt(button);
// The toggleItem should be enabled
Assert.IsTrue(toggleItem.IsEnabled);
button.Flyout.Hide();
await AssertIsEnabled(true);
// Disable the toggleItem
checkBox.IsChecked = false;
page.ViewModel.AreItemsEnabled = false;
button.Flyout.ShowAt(button);
Assert.IsFalse(toggleItem.IsEnabled);
await AssertIsEnabled(false);
}
[TestMethod]

Просмотреть файл

@ -96,6 +96,12 @@
<Error Condition="!Exists('$(OutputPath)Uno.UI.RuntimeTests\Assets\TransientAsset01.txt')" Text="$(OutputPath)uno.ui.runtimetests\Assets\TransientAsset01.txt" />
</Target>
<ItemGroup>
<Compile Update="Tests\Windows_UI_Xaml_Controls\Flyout_ToggleMenu_IsEnabled.xaml.cs">
<DependentUpon>Flyout_ToggleMenu_IsEnabled.xaml</DependentUpon>
</Compile>
</ItemGroup>
<ItemGroup>
<Page Update="Tests\Windows_UI_Xaml_Controls\FlyoutPages\When_PlacementTarget_Binding.xaml">
<Generator>MSBuild:Compile</Generator>
@ -109,4 +115,10 @@
<PropertyGroup Condition="'$(UNO_UWP_BUILD)'=='true'">
<PageExclusions>$(MSBuildThisFileDirectory)Tests\Windows_UI_Xaml\Controls\Multiwindow\**\*.xaml</PageExclusions>
</PropertyGroup>
<ItemGroup>
<Page Update="Tests\Windows_UI_Xaml_Controls\Flyout_ToggleMenu_IsEnabled.xaml">
<SubType>Designer</SubType>
<Generator>MSBuild:Compile</Generator>
</Page>
</ItemGroup>
</Project>