Skip to content

Commit 17f5565

Browse files
NafeelaNazhirnivetha-nagalingamLogishaSelvarajSF4525
authored
[Testing] Feature Matrix UITest Cases for CarouselView (#29548)
* Added the CarouselView FeatureMatrix to the hostapp * added test cases * added test cases * updated changes * updated the test cases * modified changes * added issue link * updated layout * updated changes * updated test cases * Changes updated * changes updated * Fix Formatting * Changes updated --------- Co-authored-by: nivetha-nagalingam <[email protected]> Co-authored-by: LogishaSelvarajSF4525 <[email protected]>
1 parent edba6d4 commit 17f5565

File tree

9 files changed

+2475
-0
lines changed

9 files changed

+2475
-0
lines changed

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,8 @@ public override string ToString()
7878
new GalleryPageFactory(() => new WebViewCoreGalleryPage(), "WebView Gallery"),
7979
new GalleryPageFactory(() => new SliderControlPage(), "Slider Feature Matrix"),
8080
new GalleryPageFactory(() => new CollectionViewFeaturePage(), "CollectionView Feature Matrix"),
81+
new GalleryPageFactory(() => new CarouselViewFeaturePage(), "CarouselView Feature Matrix"),
82+
8183
};
8284

8385
public CorePageView(Page rootPage)
Lines changed: 126 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,126 @@
1+
<ContentPage xmlns="http://schemas.microsoft.com/dotnet/2021/maui"
2+
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
3+
xmlns:local="clr-namespace:Maui.Controls.Sample"
4+
x:Class="Maui.Controls.Sample.CarouselViewControlPage"
5+
Title="CarouselViewControlPage">
6+
7+
<ContentPage.ToolbarItems>
8+
<ToolbarItem Text="Options"
9+
Clicked="NavigateToOptionsPage_Clicked"
10+
AutomationId="Options"/>
11+
</ContentPage.ToolbarItems>
12+
13+
<VerticalStackLayout Padding="10"
14+
Spacing="20">
15+
16+
<Grid RowDefinitions="Auto,*,Auto,Auto,Auto,Auto,Auto"
17+
ColumnDefinitions="Auto,*"
18+
RowSpacing="8"
19+
ColumnSpacing="10">
20+
21+
<!-- Add Button -->
22+
<Button Grid.Row="0"
23+
Grid.ColumnSpan="2"
24+
Text="Add"
25+
Command="{Binding AddItemCommand}"
26+
WidthRequest="150"
27+
HorizontalOptions="Center"
28+
AutomationId="AddButton"/>
29+
30+
<!-- CarouselView -->
31+
<local:CarouselView2 Grid.Row="1"
32+
Grid.ColumnSpan="2"
33+
x:Name="carouselView"
34+
HeightRequest="300"
35+
WidthRequest="300"
36+
ItemsSource="{Binding ItemsSource}"
37+
EmptyView="{Binding EmptyView}"
38+
EmptyViewTemplate="{Binding EmptyViewTemplate}"
39+
ItemTemplate="{Binding ItemTemplate}"
40+
Loop="{Binding Loop}"
41+
IsSwipeEnabled="{Binding IsSwipeEnabled}"
42+
PeekAreaInsets="{Binding PeekAreaInsets}"
43+
Position="{Binding Position}"
44+
CurrentItem="{Binding CurrentItem}"
45+
CurrentItemChanged="OnCarouselView_CurrentItemChanged"
46+
PositionChanged="OnCarouselView_PositionChanged"
47+
ItemsUpdatingScrollMode="{Binding ItemsUpdatingScrollMode}"
48+
IndicatorView="{x:Reference indicatorView}"
49+
ItemsLayout="{Binding ItemsLayout}"
50+
FlowDirection="{Binding FlowDirection}"
51+
AutomationId="CarouselViewControl"/>
52+
53+
<!-- IndicatorView -->
54+
<IndicatorView Grid.Row="2"
55+
Grid.ColumnSpan="2"
56+
x:Name="indicatorView"
57+
HorizontalOptions="Center"
58+
VerticalOptions="End"
59+
Margin="0,0,0,20"
60+
IndicatorColor="LightGray"
61+
FlowDirection="{Binding FlowDirection}"
62+
SelectedIndicatorColor="DarkGray"
63+
IndicatorSize="12"/>
64+
65+
<Label Grid.Row="3"
66+
Grid.Column="0"
67+
FontAttributes="Bold"
68+
Text="Current Item:"/>
69+
<Label Grid.Row="3"
70+
Grid.Column="1"
71+
Text="{Binding CurrentItemText}"
72+
TextColor="Blue"
73+
AutomationId="CurrentItemLabel"/>
74+
75+
<Label Grid.Row="4"
76+
Grid.Column="0"
77+
FontAttributes="Bold"
78+
Text="Previous Item:"/>
79+
<Label Grid.Row="4"
80+
Grid.Column="1"
81+
Text="{Binding PreviousItemText}"
82+
TextColor="Blue"
83+
AutomationId="PreviousItemLabel"/>
84+
85+
<Label Grid.Row="5"
86+
Grid.Column="0"
87+
FontAttributes="Bold"
88+
Text="Current Position:"/>
89+
<Label Grid.Row="5"
90+
Grid.Column="1"
91+
Text="{Binding CurrentPosition}"
92+
TextColor="Blue"
93+
AutomationId="CurrentPositionLabel"/>
94+
95+
<Label Grid.Row="6"
96+
Grid.Column="0"
97+
FontAttributes="Bold"
98+
Text="Previous Position:"/>
99+
<Label Grid.Row="6"
100+
Grid.Column="1"
101+
Text="{Binding PreviousItemPosition}"
102+
TextColor="Blue"
103+
AutomationId="PreviousPositionLabel"/>
104+
</Grid>
105+
106+
<!-- ScrollTo Controls (Outside Grid) -->
107+
<HorizontalStackLayout Spacing="10"
108+
HorizontalOptions="Start">
109+
<Label FontAttributes="Bold"
110+
VerticalOptions="Center"
111+
Text="Scroll To Index:"/>
112+
<local:UITestEntry Grid.Column="1"
113+
x:Name="scrollToIndexEntry"
114+
Placeholder="Enter index"
115+
IsCursorVisible="False"
116+
MaxLength="3"
117+
WidthRequest="100"
118+
AutomationId="ScrollToIndexEntry"/>
119+
<Button Text="Scroll To"
120+
Clicked="OnScrollToButtonClicked"
121+
HorizontalOptions="Center"
122+
WidthRequest="150"
123+
AutomationId="ScrollToButton"/>
124+
</HorizontalStackLayout>
125+
</VerticalStackLayout>
126+
</ContentPage>
Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
using System;
2+
using System.Collections.ObjectModel;
3+
using Microsoft.Maui.Controls;
4+
namespace Maui.Controls.Sample;
5+
6+
public partial class CarouselViewControlPage : ContentPage
7+
{
8+
private CarouselViewViewModel _viewModel;
9+
10+
public CarouselViewControlPage()
11+
{
12+
InitializeComponent();
13+
_viewModel = new CarouselViewViewModel();
14+
_viewModel.PreviousItemText = "No previous item";
15+
_viewModel.PreviousItemPosition = "No previous position";
16+
_viewModel.CurrentItem = _viewModel.Items.FirstOrDefault();
17+
BindingContext = _viewModel;
18+
}
19+
20+
private async void NavigateToOptionsPage_Clicked(object sender, EventArgs e)
21+
{
22+
BindingContext = _viewModel = new CarouselViewViewModel();
23+
_viewModel.PreviousItemText = "No previous item";
24+
_viewModel.PreviousItemPosition = "No previous position";
25+
_viewModel.CurrentItem = _viewModel.Items.FirstOrDefault();
26+
await Navigation.PushAsync(new CarouselViewOptionsPage(_viewModel));
27+
}
28+
29+
string _previousItem = null;
30+
31+
private void OnCarouselView_CurrentItemChanged(object sender, CurrentItemChangedEventArgs e)
32+
{
33+
if (BindingContext is CarouselViewViewModel viewModel)
34+
{
35+
var currentItem = e.CurrentItem?.ToString();
36+
37+
if (viewModel.CurrentItemText != currentItem)
38+
{
39+
_previousItem = viewModel.CurrentItemText;
40+
41+
viewModel.PreviousItemText = string.IsNullOrEmpty(_previousItem) ? "No previous item" : _previousItem;
42+
viewModel.CurrentItemText = currentItem;
43+
}
44+
}
45+
}
46+
47+
private void OnCarouselView_PositionChanged(object sender, PositionChangedEventArgs e)
48+
{
49+
if (BindingContext is CarouselViewViewModel viewModel)
50+
{
51+
viewModel.CurrentPosition = e.CurrentPosition;
52+
viewModel.PreviousItemPosition = e.PreviousPosition.ToString();
53+
}
54+
}
55+
56+
private void OnScrollToButtonClicked(object sender, EventArgs e)
57+
{
58+
if (int.TryParse(scrollToIndexEntry.Text, out int index) &&
59+
index >= 0 && index < carouselView.ItemsSource.Cast<object>().Count())
60+
{
61+
carouselView.ScrollTo(index);
62+
}
63+
}
64+
}
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
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+
x:Class="Maui.Controls.Sample.CarouselViewFeatureMainPage"
5+
Title="CarouselViewFeatureMainPage">
6+
<VerticalStackLayout Spacing="25"
7+
Padding="30">
8+
9+
<Button
10+
Text="CarouselView"
11+
Clicked="OnCarouselViewClicked"
12+
HorizontalOptions="Center"
13+
AutomationId="CarouselViewButton"/>
14+
</VerticalStackLayout>
15+
</ContentPage>
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
using System;
2+
using Microsoft.Maui.Controls;
3+
namespace Maui.Controls.Sample;
4+
5+
public class CarouselViewFeaturePage : NavigationPage
6+
{
7+
public CarouselViewFeaturePage()
8+
{
9+
PushAsync(new CarouselViewFeatureMainPage());
10+
}
11+
}
12+
13+
public partial class CarouselViewFeatureMainPage : ContentPage
14+
{
15+
public CarouselViewFeatureMainPage()
16+
{
17+
InitializeComponent();
18+
}
19+
20+
21+
private async void OnCarouselViewClicked(object sender, System.EventArgs e)
22+
{
23+
await Navigation.PushAsync(new CarouselViewControlPage());
24+
}
25+
26+
}

0 commit comments

Comments
 (0)