-
Notifications
You must be signed in to change notification settings - Fork 1.8k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[Windows] Add scrolling tests for virtualization w/ Datatemplates (#2…
…0954) * Add tests for scrolling w/ datatemplates * Forgot csproj * Add tests for scroll virtualization * Revert * Adjust ref image * Ensure items get hydrated before screenshot verify --------- Co-authored-by: Mike Corsaro <[email protected]>
- Loading branch information
Showing
4 changed files
with
167 additions
and
0 deletions.
There are no files selected for viewing
69 changes: 69 additions & 0 deletions
69
src/Controls/samples/Controls.Sample.UITests/Issues/Issue20842.xaml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
<?xml version="1.0" encoding="utf-8" ?> | ||
<ContentPage xmlns="http://schemas.microsoft.com/dotnet/2021/maui" | ||
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml" | ||
x:Class="Maui.Controls.Sample.Issues.Issue20842" | ||
xmlns:local="clr-namespace:Maui.Controls.Sample.Issues" | ||
Background="White"> | ||
<ContentPage.Resources> | ||
<DataTemplate x:Key="validPersonTemplate"> | ||
<Grid> | ||
<Grid.ColumnDefinitions> | ||
<ColumnDefinition Width="0.4*" /> | ||
<ColumnDefinition Width="0.3*" /> | ||
<ColumnDefinition Width="0.3*" /> | ||
</Grid.ColumnDefinitions> | ||
<Label Text="{Binding Name}" | ||
TextColor="Green" | ||
FontAttributes="Bold" /> | ||
<Label Grid.Column="1" | ||
Text="{Binding DateOfBirth, StringFormat='{0:d}'}" | ||
TextColor="Green" /> | ||
<Label Grid.Column="2" | ||
Text="{Binding Location}" | ||
TextColor="Green" | ||
HorizontalTextAlignment="End" /> | ||
</Grid> | ||
</DataTemplate> | ||
<DataTemplate x:Key="invalidPersonTemplate"> | ||
<Grid> | ||
<Grid.ColumnDefinitions> | ||
<ColumnDefinition Width="0.4*" /> | ||
<ColumnDefinition Width="0.3*" /> | ||
<ColumnDefinition Width="0.3*" /> | ||
</Grid.ColumnDefinitions> | ||
<Label Text="{Binding Name}" | ||
TextColor="Red" | ||
FontAttributes="Bold" /> | ||
<Label Grid.Column="1" | ||
Text="{Binding DateOfBirth, StringFormat='{0:d}'}" | ||
TextColor="Red" /> | ||
<Label Grid.Column="2" | ||
Text="{Binding Location}" | ||
TextColor="Red" | ||
HorizontalTextAlignment="End" /> | ||
</Grid> | ||
</DataTemplate> | ||
<local:PersonDataTemplateSelector x:Key="personDataTemplateSelector" | ||
ValidTemplate="{StaticResource validPersonTemplate}" | ||
InvalidTemplate="{StaticResource invalidPersonTemplate}" /> | ||
</ContentPage.Resources> | ||
|
||
<VerticalStackLayout> | ||
<CollectionView | ||
x:Name="PersonList" | ||
HeightRequest="400" | ||
ItemTemplate="{StaticResource personDataTemplateSelector}"/> | ||
|
||
<Button | ||
Text="Scroll To Top" | ||
Clicked="ScrollToTopButton_Clicked" | ||
x:Name="ScrollUpButton" | ||
AutomationId="ScrollUpButton"/> | ||
|
||
<Button | ||
Text="Scroll To Bottom" | ||
Clicked="ScrollToBottomButton_Clicked" | ||
x:Name="ScrollDownButton" | ||
AutomationId="ScrollDownButton"/> | ||
</VerticalStackLayout> | ||
</ContentPage> |
62 changes: 62 additions & 0 deletions
62
src/Controls/samples/Controls.Sample.UITests/Issues/Issue20842.xaml.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using Microsoft.Maui.Controls; | ||
|
||
namespace Maui.Controls.Sample.Issues | ||
{ | ||
internal class Person | ||
{ | ||
public string Name { get; set; } = ""; | ||
public int Age { get; set; } | ||
public DateTime DateOfBirth { get; set; } | ||
public string Location { get; set; } = ""; | ||
|
||
public override string ToString() | ||
=> Name; | ||
} | ||
|
||
public class PersonDataTemplateSelector : DataTemplateSelector | ||
{ | ||
public required DataTemplate ValidTemplate { get; set; } | ||
public required DataTemplate InvalidTemplate { get; set; } | ||
|
||
protected override DataTemplate OnSelectTemplate(object item, BindableObject container) | ||
{ | ||
return ((Person)item).DateOfBirth.Year >= 1980 ? ValidTemplate : InvalidTemplate; | ||
} | ||
} | ||
|
||
[Issue(IssueTracker.Github, "20842", "Verify data templates in CollectionView virtualize correctly", PlatformAffected.UWP)] | ||
public partial class Issue20842 : ContentPage | ||
{ | ||
private readonly List<Person> people = new(); | ||
|
||
public Issue20842() | ||
{ | ||
InitializeComponent(); | ||
|
||
for (int i = 0; i < 100; i++) | ||
{ | ||
people.Add(new Person { Name = $"Kath {i}", DateOfBirth = new DateTime(1985, 11, 20), Location = "France" }); | ||
people.Add(new Person { Name = $"Steve {i}", DateOfBirth = new DateTime(1975, 1, 15), Location = "USA" }); | ||
people.Add(new Person { Name = $"Lucas {i}", DateOfBirth = new DateTime(1988, 2, 5), Location = "Germany" }); | ||
people.Add(new Person { Name = $"John {i}", DateOfBirth = new DateTime(1976, 2, 20), Location = "USA" }); | ||
people.Add(new Person { Name = $"Tariq {i}", DateOfBirth = new DateTime(1987, 1, 10), Location = "UK" }); | ||
people.Add(new Person { Name = $"Jane {i}", DateOfBirth = new DateTime(1982, 8, 30), Location = "USA" }); | ||
people.Add(new Person { Name = $"Tom {i}", DateOfBirth = new DateTime(1977, 3, 10), Location = "UK" }); | ||
} | ||
|
||
PersonList.ItemsSource = people; | ||
} | ||
|
||
private void ScrollToTopButton_Clicked(object sender, EventArgs e) | ||
{ | ||
PersonList.ScrollTo(0, animate: false); | ||
} | ||
|
||
private void ScrollToBottomButton_Clicked(object sender, EventArgs e) | ||
{ | ||
PersonList.ScrollTo(people.Count - 1, animate: false); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
using NUnit.Framework; | ||
using UITest.Appium; | ||
using UITest.Core; | ||
|
||
namespace Microsoft.Maui.AppiumTests.Issues | ||
{ | ||
public class Issue20842 : _IssuesUITest | ||
{ | ||
const string scrollUpButton = "ScrollUpButton"; | ||
const string scrollDownButton = "ScrollDownButton"; | ||
|
||
public Issue20842(TestDevice device) : base(device) | ||
{ | ||
} | ||
|
||
public override string Issue => "Verify data templates in CollectionView virtualize correctly"; | ||
|
||
[Test] | ||
public async Task VerifyCollectionViewItemsAfterScrolling() | ||
{ | ||
this.IgnoreIfPlatforms([TestDevice.Android, TestDevice.iOS, TestDevice.Mac]); | ||
|
||
App.WaitForElement(scrollUpButton); | ||
|
||
App.Click(scrollDownButton); | ||
await Task.Delay(200); | ||
App.Click(scrollUpButton); | ||
await Task.Delay(200); | ||
App.Click(scrollDownButton); | ||
await Task.Delay(500); | ||
|
||
VerifyScreenshot(); | ||
} | ||
} | ||
} | ||
|
Binary file added
BIN
+33 KB
...ols/tests/UITests/snapshots/windows/VerifyCollectionViewItemsAfterScrolling.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.