Skip to content

Commit 1a08b10

Browse files
TamilarasanSF4853PureWeen
authored andcommitted
[Testing] Feature Matrix UITest Cases for Switch Control (#29950)
* added test cases * added new test cases * added new test cases * added android and iOS snapshots * modified test case and added snapshots * added failing condition
1 parent b5a25d5 commit 1a08b10

File tree

37 files changed

+660
-0
lines changed

37 files changed

+660
-0
lines changed

src/Controls/tests/TestCases.HostApp/CoreViews/CorePageView.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,7 @@ public override string ToString()
7878
new GalleryPageFactory(() => new SliderCoreGalleryPage(), "Slider Gallery"),
7979
new GalleryPageFactory(() => new StepperControlPage(), "Stepper Feature Matrix"),
8080
new GalleryPageFactory(() => new StepperCoreGalleryPage(), "Stepper Gallery"),
81+
new GalleryPageFactory(() => new SwitchControlPage(), "Switch Feature Matrix"),
8182
new GalleryPageFactory(() => new SwitchCoreGalleryPage(), "Switch Gallery"),
8283
new GalleryPageFactory(() => new SwipeViewCoreGalleryPage(), "SwipeView Gallery"),
8384
new GalleryPageFactory(() => new TimePickerCoreGalleryPage(), "Time Picker Gallery"),
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
<?xml version="1.0" encoding="utf-8" ?>
2+
<ContentPage xmlns="http://schemas.microsoft.com/dotnet/2021/maui"
3+
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
4+
xmlns:local="clr-namespace:Maui.Controls.Sample"
5+
x:Class="Maui.Controls.Sample.SwitchControlMainPage"
6+
x:DataType="local:SwitchViewModel"
7+
Title="SwitchControlPage">
8+
<ContentPage.ToolbarItems>
9+
<ToolbarItem Text="Options"
10+
Clicked="NavigateToOptionsPage_Clicked"
11+
AutomationId="Options"/>
12+
</ContentPage.ToolbarItems>
13+
14+
<Grid RowDefinitions="*,Auto">
15+
<Grid x:Name="SwitchGrid"
16+
Grid.Row="0">
17+
<Switch AutomationId="SwitchControl"
18+
FlowDirection="{Binding FlowDirection}"
19+
IsEnabled="{Binding IsEnabled}"
20+
IsVisible="{Binding IsVisible}"
21+
IsToggled="{Binding IsToggled}"
22+
OnColor="{Binding OnColor}"
23+
Shadow="{Binding Shadow}"
24+
ThumbColor="{Binding ThumbColor}"
25+
HorizontalOptions="Center"
26+
VerticalOptions="Center"
27+
Toggled="Switch_Toggled">
28+
</Switch>
29+
</Grid>
30+
<HorizontalStackLayout Grid.Row="1"
31+
HorizontalOptions="Center"
32+
Padding="0,0,0,40"
33+
Spacing="10">
34+
<Label Text="Toggled Event: "/>
35+
<Label x:Name="EventLabel"
36+
AutomationId="ToggledEventLabel"
37+
Text="False"/>
38+
</HorizontalStackLayout>
39+
</Grid>
40+
</ContentPage>
Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
namespace Maui.Controls.Sample;
2+
3+
public class SwitchControlPage : NavigationPage
4+
{
5+
private SwitchViewModel _viewModel;
6+
public SwitchControlPage()
7+
{
8+
_viewModel = new SwitchViewModel();
9+
PushAsync(new SwitchControlMainPage(_viewModel));
10+
}
11+
}
12+
13+
public partial class SwitchControlMainPage : ContentPage
14+
{
15+
private SwitchViewModel _viewModel;
16+
17+
public SwitchControlMainPage(SwitchViewModel viewModel)
18+
{
19+
InitializeComponent();
20+
_viewModel = viewModel;
21+
BindingContext = _viewModel;
22+
}
23+
24+
private async void NavigateToOptionsPage_Clicked(object sender, EventArgs e)
25+
{
26+
BindingContext = _viewModel = new SwitchViewModel();
27+
ReinitializeSwitch();
28+
await Navigation.PushAsync(new SwitchOptionsPage(_viewModel));
29+
}
30+
31+
private void Switch_Toggled(object sender, ToggledEventArgs e)
32+
{
33+
EventLabel.Text = $"{e.Value}";
34+
}
35+
36+
private void ReinitializeSwitch()
37+
{
38+
SwitchGrid.Children.Clear();
39+
var switchControl = new Switch
40+
{
41+
AutomationId = "SwitchControl",
42+
HorizontalOptions = LayoutOptions.Center,
43+
VerticalOptions = LayoutOptions.Center
44+
};
45+
46+
switchControl.Toggled += Switch_Toggled;
47+
48+
switchControl.SetBinding(Switch.FlowDirectionProperty, new Binding(nameof(SwitchViewModel.FlowDirection)));
49+
switchControl.SetBinding(Switch.IsEnabledProperty, new Binding(nameof(SwitchViewModel.IsEnabled)));
50+
switchControl.SetBinding(Switch.IsVisibleProperty, new Binding(nameof(SwitchViewModel.IsVisible)));
51+
switchControl.SetBinding(Switch.IsToggledProperty, new Binding(nameof(SwitchViewModel.IsToggled)));
52+
switchControl.SetBinding(Switch.OnColorProperty, new Binding(nameof(SwitchViewModel.OnColor)));
53+
switchControl.SetBinding(Switch.ShadowProperty, new Binding(nameof(SwitchViewModel.Shadow)));
54+
switchControl.SetBinding(Switch.ThumbColorProperty, new Binding(nameof(SwitchViewModel.ThumbColor)));
55+
SwitchGrid.Children.Add(switchControl);
56+
}
57+
}
Lines changed: 142 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,142 @@
1+
<?xml version="1.0" encoding="utf-8" ?>
2+
<ContentPage xmlns="http://schemas.microsoft.com/dotnet/2021/maui"
3+
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
4+
xmlns:local="clr-namespace:Maui.Controls.Sample"
5+
x:Class="Maui.Controls.Sample.SwitchOptionsPage"
6+
x:DataType="local:SwitchViewModel"
7+
Title="SwitchOptionsPage">
8+
<ContentPage.ToolbarItems>
9+
<ToolbarItem Text="Apply"
10+
Clicked="ApplyButton_Clicked"
11+
AutomationId="Apply"/>
12+
</ContentPage.ToolbarItems>
13+
14+
<Grid ColumnSpacing="10"
15+
RowSpacing="10"
16+
RowDefinitions="Auto,Auto,Auto,Auto,Auto,Auto,Auto"
17+
ColumnDefinitions="Auto,Auto"
18+
HorizontalOptions="Center"
19+
VerticalOptions="Center">
20+
21+
<!-- FlowDirection -->
22+
<Label Grid.Row="0"
23+
Grid.Column="0"
24+
Text="FlowDirection:"
25+
VerticalOptions="Center"/>
26+
<StackLayout Grid.Row="0"
27+
Grid.Column="1"
28+
Orientation="Horizontal"
29+
Spacing="5"
30+
VerticalOptions="Center">
31+
<CheckBox x:Name="FlowDirectionLeftToRightCheckBox"
32+
AutomationId="FlowDirectionLeftToRightCheckBox"
33+
IsChecked="True"
34+
CheckedChanged="OnFlowDirectionCheckBoxCheckedChanged"/>
35+
<Label Text="LeftToRight"
36+
VerticalOptions="Center"/>
37+
<CheckBox x:Name="FlowDirectionRightToLeftCheckBox"
38+
AutomationId="FlowDirectionRightToLeftCheckBox"
39+
CheckedChanged="OnFlowDirectionCheckBoxCheckedChanged"/>
40+
<Label Text="RightToLeft"
41+
VerticalOptions="Center"/>
42+
</StackLayout>
43+
44+
<!-- IsEnabled -->
45+
<Label Grid.Row="1"
46+
Grid.Column="0"
47+
Text="IsEnabled:"
48+
VerticalOptions="Center"/>
49+
<StackLayout Grid.Row="1"
50+
Grid.Column="1"
51+
Orientation="Horizontal"
52+
Spacing="10"
53+
VerticalOptions="Center">
54+
<CheckBox AutomationId="IsEnabledFalseCheckBox"
55+
CheckedChanged="OnEnabledCheckBoxCheckedChanged"/>
56+
</StackLayout>
57+
58+
<!-- IsVisible -->
59+
<Label Grid.Row="2"
60+
Grid.Column="0"
61+
Text="IsVisible:"
62+
VerticalOptions="Center"/>
63+
<StackLayout Grid.Row="2"
64+
Grid.Column="1"
65+
Orientation="Horizontal"
66+
Spacing="10"
67+
VerticalOptions="Center">
68+
<CheckBox AutomationId="IsVisibleFalseCheckBox"
69+
CheckedChanged="OnVisibleCheckBoxCheckedChanged"/>
70+
</StackLayout>
71+
72+
<!-- IsToggled -->
73+
<Label Grid.Row="3"
74+
Grid.Column="0"
75+
Text="IsToggled:"
76+
VerticalOptions="Center"/>
77+
<StackLayout Grid.Row="3"
78+
Grid.Column="1"
79+
Orientation="Horizontal"
80+
Spacing="10"
81+
VerticalOptions="Center">
82+
<CheckBox AutomationId="IsToggledTrueCheckBox"
83+
CheckedChanged="OnToggledCheckBoxCheckedChanged"/>
84+
</StackLayout>
85+
86+
<!-- OnColor -->
87+
<Label Grid.Row="4"
88+
Grid.Column="0"
89+
Text="OnColor:"
90+
VerticalOptions="Center"/>
91+
<StackLayout Grid.Row="4"
92+
Grid.Column="1"
93+
Orientation="Horizontal"
94+
Spacing="5"
95+
VerticalOptions="Center">
96+
<CheckBox x:Name="OnColorRedCheckBox"
97+
AutomationId="OnColorRedCheckBox"
98+
CheckedChanged="OnOnColorCheckBoxCheckedChanged"/>
99+
<Label Text="Red"
100+
VerticalOptions="Center"/>
101+
<CheckBox x:Name="OnColorGreenCheckBox"
102+
AutomationId="OnColorGreenCheckBox"
103+
CheckedChanged="OnOnColorCheckBoxCheckedChanged"/>
104+
<Label Text="Green"
105+
VerticalOptions="Center"/>
106+
</StackLayout>
107+
108+
<!-- Shadow -->
109+
<Label Grid.Row="5"
110+
Grid.Column="0"
111+
Text="Shadow:"
112+
VerticalOptions="Center"/>
113+
<HorizontalStackLayout Grid.Row="5"
114+
Grid.Column="1"
115+
VerticalOptions="Center">
116+
<CheckBox AutomationId="ShadowTrueCheckBox"
117+
CheckedChanged="OnShadowCheckBoxCheckedChanged"/>
118+
</HorizontalStackLayout>
119+
120+
<!-- ThumbColor -->
121+
<Label Grid.Row="6"
122+
Grid.Column="0"
123+
Text="ThumbColor:"
124+
VerticalOptions="Center"/>
125+
<StackLayout Grid.Row="6"
126+
Grid.Column="1"
127+
Orientation="Horizontal"
128+
Spacing="5"
129+
VerticalOptions="Center">
130+
<CheckBox x:Name="ThumbColorRedCheckBox"
131+
AutomationId="ThumbColorRedCheckBox"
132+
CheckedChanged="OnThumbColorCheckBoxCheckedChanged"/>
133+
<Label Text="Red"
134+
VerticalOptions="Center"/>
135+
<CheckBox x:Name="ThumbColorGreenCheckBox"
136+
AutomationId="ThumbColorGreenCheckBox"
137+
CheckedChanged="OnThumbColorCheckBoxCheckedChanged"/>
138+
<Label Text="Green"
139+
VerticalOptions="Center"/>
140+
</StackLayout>
141+
</Grid>
142+
</ContentPage>

0 commit comments

Comments
 (0)