Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Enable RefreshView Tests #23181

Merged
merged 7 commits into from
Jul 1, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ void OnInitialPageAppearing(object sender, EventArgs e)

_ = new TestWindow(nav);

await waitForFirstAppearing.Task;
await waitForFirstAppearing.Task.WaitAsync(TimeSpan.FromSeconds(2));
initialPage.Appearing += (sender, _) =>
{
Assert.True(appearingShouldFireOnInitialPage);
Expand All @@ -92,12 +92,12 @@ void OnInitialPageAppearing(object sender, EventArgs e)
pushedPage.Disappearing += (sender, _)
=> pageDisappeared = (ContentPage)sender;

await nav.PushAsync(pushedPage);
await nav.PushAsync(pushedPage).WaitAsync(TimeSpan.FromSeconds(2));
Assert.Null(rootPageFiresAppearingAfterPop);
appearingShouldFireOnInitialPage = true;
Assert.Null(pageDisappeared);

await nav.PopAsync();
await nav.PopAsync().WaitAsync(TimeSpan.FromSeconds(2));

Assert.Equal(initialPage, rootPageFiresAppearingAfterPop);
Assert.Equal(pushedPage, pageDisappeared);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ public static PropertyMapper<IStackNavigationView, TestNavigationHandler> Naviga

TaskCompletionSource _navigationSource;

public Task NavigatingTask => (_navigationSource?.Task ?? Task.CompletedTask);
public Task NavigatingTask => _navigationSource?.Task ?? Task.CompletedTask;

public async void CompleteCurrentNavigation()
{
Expand Down
21 changes: 21 additions & 0 deletions src/Controls/tests/TestCases.HostApp/Issues/Issue16910.xaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
<?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.Issue16910">
<ContentPage.Content>
<Grid RowDefinitions="Auto,100,*,50,50" x:Name="grid">
<Label Grid.Row="1" Text="Interact with the RefreshView and make sure the IsRefreshing Label correctly Represents current state." />
<RefreshView x:Name="refreshView" Grid.Row="2" IsRefreshing="{Binding IsRefreshing, Mode=TwoWay}">
<CollectionView ItemsSource="{Binding ItemSource}" AutomationId="CollectionView">
<CollectionView.ItemTemplate>
<DataTemplate>
<Label Text="{Binding Text}" AutomationId="{Binding AutomationId}" />
</DataTemplate>
</CollectionView.ItemTemplate>
</CollectionView>
</RefreshView>
<Button x:Name="StopRefreshing" AutomationId="StopRefreshing" Grid.Row="3" Text="Stop Refresh" Clicked="OnStopRefreshClicked" />
<Button x:Name="StartRefreshing" AutomationId="StartRefreshing" Grid.Row="4" Text="Refresh" Clicked="OnRefreshClicked" />
</Grid>
</ContentPage.Content>
</ContentPage>
72 changes: 72 additions & 0 deletions src/Controls/tests/TestCases.HostApp/Issues/Issue16910.xaml.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
using System;
using System.Collections;
using System.Linq;
using Microsoft.Maui.Controls;
using Microsoft.Maui.Controls.Xaml;
using Microsoft.Maui.Platform;

namespace Maui.Controls.Sample.Issues
{
[Issue(IssueTracker.Github, 16910, "IsRefreshing binding works", PlatformAffected.All)]
public partial class Issue16910 : ContentPage
{
Label _isRefreshingLabel = new Label(){Text = "Is Refreshing", AutomationId = "IsRefreshing"};
Label _isNotRefreshingLabel = new Label(){Text = "Is Not Refreshing", AutomationId = "IsNotRefreshing"};

bool _isRefreshing;

public IEnumerable ItemSource {get; set;}

public bool IsRefreshing
{
get => _isRefreshing;
set
{
_isRefreshing = value;
OnPropertyChanged(nameof(IsRefreshing));
UpdateRefreshingLabels();
}
}

void UpdateRefreshingLabels()
{
if (IsRefreshing)
{
grid.Remove(_isNotRefreshingLabel);
grid.Insert(0, _isRefreshingLabel);
StartRefreshing.IsVisible = false;
StopRefreshing.IsVisible = true;
}
else
{
grid.Remove(_isRefreshingLabel);
grid.Insert(0, _isNotRefreshingLabel);
StartRefreshing.IsVisible = true;
StopRefreshing.IsVisible = false;
}
}

public Issue16910()
{
InitializeComponent();
UpdateRefreshingLabels();
ItemSource =
Enumerable.Range(0,100)
.Select(x => new { Text = $"Item {x}", AutomationId = $"Item{x}" })
.ToList();

this.BindingContext = this;
}


void OnStopRefreshClicked(object sender, EventArgs e)
{
refreshView.IsRefreshing = false;
}

void OnRefreshClicked(object sender, EventArgs e)
{
refreshView.IsRefreshing = true;
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
using NUnit.Framework;
using UITest.Appium;
using UITest.Core;
using System.Threading.Tasks;

namespace Microsoft.Maui.TestCases.Tests.Issues;

public class Issue16910 : _IssuesUITest
{
public override string Issue => "IsRefreshing binding works";

protected override bool ResetAfterEachTest => true;
public Issue16910(TestDevice device)
: base(device)
{

}

[Test]
public void BindingUpdatesFromProgrammaticRefresh()
{
_ = App.WaitForElement("StartRefreshing");
App.Tap("StartRefreshing");
App.WaitForElement("IsRefreshing");
App.Click("StopRefreshing");
App.WaitForElement("IsNotRefreshing");
}

// Windows only works with touch inputs which we don't have running on the test server
#if !WINDOWS && !MACCATALYST
[Test]
[Category(UITestCategories.RefreshView)]
public void BindingUpdatesFromInteractiveRefresh()
{
_ = App.WaitForElement("CollectionView");
App.ScrollUp("CollectionView");
App.WaitForElement("IsRefreshing");
App.Tap("StopRefreshing");
App.WaitForElement("IsNotRefreshing");
}
#endif

}
24 changes: 22 additions & 2 deletions src/TestUtils/src/UITest.Appium/Actions/AppiumMouseActions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,9 @@
using OpenQA.Selenium;
using OpenQA.Selenium.Appium;
using OpenQA.Selenium.Appium.Interactions;
using OpenQA.Selenium.Appium.Mac;
using OpenQA.Selenium.Interactions;
using OpenQA.Selenium.Support.UI;
using UITest.Core;

namespace UITest.Appium
Expand Down Expand Up @@ -93,22 +95,40 @@ CommandResponse ClickCoordinates(IDictionary<string, object> parameters)

CommandResponse ClickElement(AppiumElement element)
{
string tagName = string.Empty;

// If the click fails on catalyst we need to retrieve the element again
if (_appiumApp.Driver is MacDriver)
tagName = element.TagName;

try
{
element.Click();
return CommandResponse.SuccessEmptyResponse;
}
catch (InvalidOperationException)
catch (InvalidOperationException ioe)
{
Console.WriteLine($"WebDriverException: {ioe}");
return ProcessException();
}
catch (WebDriverException)
catch (WebDriverException we)
{
Console.WriteLine($"WebDriverException: {we}");
return ProcessException();
}

CommandResponse ProcessException()
{
// Appium elements will sometimes become stale
// Which appears to happen if click fails, so, we retrieve it here
if(!String.IsNullOrWhiteSpace(tagName))
element = (AppiumElement)_appiumApp.FindElement(tagName);

if (element is null)
{
return CommandResponse.FailedEmptyResponse;
}

// Some elements aren't "clickable" from an automation perspective (e.g., Frame renders as a Border
// with content in it; if the content is just a TextBlock, we'll end up here)

Expand Down
Loading