Skip to content

Commit

Permalink
feat(Expander): Add WinUI test page
Browse files Browse the repository at this point in the history
  • Loading branch information
robloo committed Nov 4, 2020
1 parent 9a8e925 commit 1279af8
Show file tree
Hide file tree
Showing 3 changed files with 139 additions and 1 deletion.
Original file line number Diff line number Diff line change
@@ -0,0 +1,92 @@
<!-- Copyright (c) Microsoft Corporation. All rights reserved. Licensed under the MIT License. See LICENSE in the project root for license information. -->
<UserControl
x:Class="UITests.Shared.Microsoft_UI_Xaml_Controls.ExpanderTests.WinUIExpanderPage"
x:Name="ExpanderTestPage"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:local="using:UITests.Shared.Microsoft_UI_Xaml_Controls.ExpanderTests"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:controls="using:Microsoft.UI.Xaml.Controls"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
mc:Ignorable="d">

<Grid Background="{ThemeResource ApplicationPageBackgroundThemeBrush}" Margin="12">
<ScrollViewer Grid.Column="0" Height="Auto">
<StackPanel Orientation="Vertical">
<StackPanel.ChildrenTransitions>
<TransitionCollection>
<RepositionThemeTransition IsStaggeringEnabled="False" />
</TransitionCollection>
</StackPanel.ChildrenTransitions>

<controls:Expander x:Name ="ExpandedExpander" AutomationProperties.Name="ExpandedExpander" HorizontalContentAlignment="Left" IsExpanded="True">
<controls:Expander.Header>
<TextBlock Style="{StaticResource HeaderTextBlockStyle}" Text="This expander is expanded by default." />
</controls:Expander.Header>
<TextBlock AutomationProperties.AutomationId="ExpandedExpanderContent">Content</TextBlock>
</controls:Expander>

<controls:Expander AutomationProperties.AutomationId="CollapsedExpander" AutomationProperties.Name="Expander2" HorizontalContentAlignment="Left" IsExpanded="False">
<controls:Expander.Header>
<TextBlock Style="{StaticResource HeaderTextBlockStyle}" Text="This expander is collapsed by default." />
</controls:Expander.Header>
<TextBlock AutomationProperties.AutomationId="CollapsedExpanderContent">Content</TextBlock>
</controls:Expander>

<controls:Expander AutomationProperties.Name="ParentExpander" HorizontalContentAlignment="Left" IsExpanded="False">
<controls:Expander.Header>
<TextBlock Style="{StaticResource HeaderTextBlockStyle}" Text="This expander has an expander inside" />
</controls:Expander.Header>
<controls:Expander AutomationProperties.Name="NestedExpander" HorizontalContentAlignment="Left" IsExpanded="False" Margin="30,0,0,0" >
<controls:Expander.Header>
<TextBlock Style="{StaticResource HeaderTextBlockStyle}" Text="Nested expander" />
</controls:Expander.Header>
<StackPanel HorizontalAlignment="Left">
<Button>Button1</Button>
<Button>Button2</Button>
</StackPanel>
</controls:Expander>
</controls:Expander>

<controls:Expander AutomationProperties.Name="ExpanderWithButtons" HorizontalContentAlignment="Left" IsExpanded="False">
<controls:Expander.Header>
<ToggleButton>This is a toggle button in the header</ToggleButton>
</controls:Expander.Header>
<StackPanel>
<TextBlock>Content</TextBlock>
</StackPanel>
</controls:Expander>

<controls:Expander AutomationProperties.Name="ExpanderWithUpwardsDirection" HorizontalContentAlignment="Left" ExpandDirection="Up" IsExpanded="False">
<controls:Expander.Header>
<TextBlock Style="{StaticResource HeaderTextBlockStyle}">This expander will expand upwards</TextBlock>
</controls:Expander.Header>
<StackPanel>
<TextBlock>Content</TextBlock>
</StackPanel>
</controls:Expander>

<controls:Expander IsEnabled="False" AutomationProperties.Name="ExpanderNotEnabled" HorizontalContentAlignment="Left" ExpandDirection="Down" IsExpanded="False">
<controls:Expander.Header>
<TextBlock Style="{StaticResource HeaderTextBlockStyle}">This expander is not enabled</TextBlock>
</controls:Expander.Header>
<StackPanel>
<TextBlock>Content</TextBlock>
</StackPanel>
</controls:Expander>

<local:TestControl IsTabStop="True" x:Name="CustomControl" AutomationProperties.Name="CustomControl">
<controls:Expander x:Name="ExpanderWithCustomEventsSource" HorizontalContentAlignment="Left" ExpandDirection="Down" IsExpanded="False">
<controls:Expander.Header>
<TextBlock Style="{StaticResource HeaderTextBlockStyle}">This expander has a custom events source</TextBlock>
</controls:Expander.Header>
<StackPanel>
<TextBlock>Content</TextBlock>
</StackPanel>
</controls:Expander>
</local:TestControl>
</StackPanel>
</ScrollViewer>

</Grid>
</UserControl>
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
using Uno.UI.Samples.Controls;
using Windows.UI.Xaml.Automation.Peers;
using Windows.UI.Xaml.Controls;

namespace UITests.Shared.Microsoft_UI_Xaml_Controls.ExpanderTests
{
// We are going to test setting the events source of an expander to the customcontrol's
public sealed partial class TestControl : ContentControl
{
protected override AutomationPeer OnCreateAutomationPeer()
{
return new TestControlAutomationPeer(this);
}
}

public sealed partial class TestControlAutomationPeer : FrameworkElementAutomationPeer
{
public TestControlAutomationPeer(TestControl owner) : base(owner) { }
protected override AutomationControlType GetAutomationControlTypeCore()
{
return AutomationControlType.Custom;
}
}

[Sample("Expander", "WinUI", Name = "WinUIExpanderPage")]
public sealed partial class WinUIExpanderPage : UserControl
{
public WinUIExpanderPage()
{
this.InitializeComponent();
var customControlPeer = FrameworkElementAutomationPeer.FromElement(CustomControl);
var expanderPeer = FrameworkElementAutomationPeer.FromElement(ExpanderWithCustomEventsSource);

// Commenting because of MuxTestInfra bug:
// https://github.com/microsoft/microsoft-ui-xaml/issues/3491
//expanderPeer.EventsSource = customControlPeer;
}
}
}
9 changes: 8 additions & 1 deletion src/SamplesApp/UITests.Shared/UITests.Shared.projitems
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,10 @@
<SubType>Designer</SubType>
<Generator>MSBuild:Compile</Generator>
</Page>
<Page Include="$(MSBuildThisFileDirectory)Microsoft_UI_Xaml_Controls\ExpanderTests\WinUIExpanderPage.xaml">
<SubType>Designer</SubType>
<Generator>MSBuild:Compile</Generator>
</Page>
<Page Include="$(MSBuildThisFileDirectory)Msal\MsalLoginAndGraph.xaml">
<SubType>Designer</SubType>
<Generator>MSBuild:Compile</Generator>
Expand Down Expand Up @@ -3645,6 +3649,9 @@
<Compile Include="$(MSBuildThisFileDirectory)Microsoft_UI_Xaml_Controls\TwoPaneViewTests\TwoPaneViewPage.xaml.cs">
<DependentUpon>TwoPaneViewPage.xaml</DependentUpon>
</Compile>
<Compile Include="$(MSBuildThisFileDirectory)Microsoft_UI_Xaml_Controls\ExpanderTests\WinUIExpanderPage.xaml.cs">
<DependentUpon>WinUIExpanderPage.xaml</DependentUpon>
</Compile>
<Compile Include="$(MSBuildThisFileDirectory)Msal\MsalLoginAndGraph.xaml.cs">
<DependentUpon>MsalLoginAndGraph.xaml</DependentUpon>
</Compile>
Expand Down Expand Up @@ -6428,4 +6435,4 @@
<None Include="$(MSBuildThisFileDirectory)ItemExclusions.props" />
</ItemGroup>
<Import Project="ItemExclusions.props" />
</Project>
</Project>

0 comments on commit 1279af8

Please sign in to comment.