From 2e144c1fefef88f91e5fa75d283a88b5b93095da Mon Sep 17 00:00:00 2001
From: Brandon Minnick <13558917+brminnick@users.noreply.github.com>
Date: Wed, 5 Aug 2020 11:06:42 -0700
Subject: [PATCH] Add InformationLabel & InformationButton Tests
---
GitTrends.Android/GitTrends.Android.csproj | 2 +-
.../RepositoryPageAutomationIds.cs | 16 +++++
.../Enums/FloatingActionButtonType.cs | 4 ++
.../Services/StatisticsService.cs | 41 ++++++++++++-
GitTrends.UITests/Pages/BaseCollectionPage.cs | 2 +-
GitTrends.UITests/Pages/RepositoryPage.cs | 27 ++++++++-
.../Tests/ReferringSitesTests.cs | 2 +-
GitTrends.UITests/Tests/RepositoriesTests.cs | 39 +++++++++++-
GitTrends.iOS/GitTrends.iOS.csproj | 2 +-
GitTrends/GitTrends.csproj | 2 +-
GitTrends/Pages/RepositoryPage.cs | 28 +++------
.../Views/Repository/InformationButton.cs | 59 ++++++++++---------
12 files changed, 166 insertions(+), 58 deletions(-)
create mode 100644 GitTrends.Mobile.Common/Enums/FloatingActionButtonType.cs
diff --git a/GitTrends.Android/GitTrends.Android.csproj b/GitTrends.Android/GitTrends.Android.csproj
index 094e7c2a1..1eaf76231 100644
--- a/GitTrends.Android/GitTrends.Android.csproj
+++ b/GitTrends.Android/GitTrends.Android.csproj
@@ -101,7 +101,7 @@
-
+
diff --git a/GitTrends.Mobile.Common/Constants/AutomationIds/RepositoryPageAutomationIds.cs b/GitTrends.Mobile.Common/Constants/AutomationIds/RepositoryPageAutomationIds.cs
index f6cc2eed5..316725558 100644
--- a/GitTrends.Mobile.Common/Constants/AutomationIds/RepositoryPageAutomationIds.cs
+++ b/GitTrends.Mobile.Common/Constants/AutomationIds/RepositoryPageAutomationIds.cs
@@ -10,5 +10,21 @@ public static class RepositoryPageAutomationIds
public const string EmptyDataView = nameof(RepositoryPageAutomationIds) + nameof(EmptyDataView);
public const string LargeScreenTrendingImage = nameof(RepositoryPageAutomationIds) + nameof(LargeScreenTrendingImage);
public const string SmallScreenTrendingImage = nameof(RepositoryPageAutomationIds) + nameof(SmallScreenTrendingImage);
+ public const string InformationButton = nameof(RepositoryPageAutomationIds) + nameof(InformationButton);
+ public const string InformationLabel = nameof(RepositoryPageAutomationIds) + nameof(InformationLabel);
+
+ public static string GetFloatingActionTextButtonLabelAutomationId(in FloatingActionButtonType floatingActionButtonType)
+ {
+ const string label = "Label";
+
+ return floatingActionButtonType switch
+ {
+ FloatingActionButtonType.Information => nameof(RepositoryPageAutomationIds) + nameof(FloatingActionButtonType.Information) + label,
+ FloatingActionButtonType.Statistic1 => nameof(RepositoryPageAutomationIds) + nameof(FloatingActionButtonType.Statistic1) + label,
+ FloatingActionButtonType.Statistic2 => nameof(RepositoryPageAutomationIds) + nameof(FloatingActionButtonType.Statistic2) + label,
+ FloatingActionButtonType.Statistic3 => nameof(RepositoryPageAutomationIds) + nameof(FloatingActionButtonType.Statistic3) + label,
+ _ => throw new System.NotImplementedException(),
+ };
+ }
}
}
diff --git a/GitTrends.Mobile.Common/Enums/FloatingActionButtonType.cs b/GitTrends.Mobile.Common/Enums/FloatingActionButtonType.cs
new file mode 100644
index 000000000..0cbed4f47
--- /dev/null
+++ b/GitTrends.Mobile.Common/Enums/FloatingActionButtonType.cs
@@ -0,0 +1,4 @@
+namespace GitTrends.Mobile.Common
+{
+ public enum FloatingActionButtonType { Information, Statistic1, Statistic2, Statistic3 }
+}
diff --git a/GitTrends.Mobile.Common/Services/StatisticsService.cs b/GitTrends.Mobile.Common/Services/StatisticsService.cs
index 9f8798622..2071a197c 100644
--- a/GitTrends.Mobile.Common/Services/StatisticsService.cs
+++ b/GitTrends.Mobile.Common/Services/StatisticsService.cs
@@ -1,4 +1,10 @@
-namespace GitTrends.Mobile.Common
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using GitTrends.Mobile.Common.Constants;
+using GitTrends.Shared;
+
+namespace GitTrends.Mobile.Common
{
public static class StatisticsService
{
@@ -17,5 +23,38 @@ public static string ToAbbreviatedText(this long number)
return "0";
}
+
+ public static string GetInformationLabelText(in IReadOnlyList repositories, in MobileSortingService mobileSortingService) where TRepository : IRepository =>
+ GetInformationLabelText(repositories, MobileSortingService.GetSortingCategory(mobileSortingService.CurrentOption));
+
+ public static string GetInformationLabelText(in IReadOnlyList repositories, in SortingCategory sortingCategory) where TRepository : IRepository => (repositories.Any(), sortingCategory) switch
+ {
+ (false, _) => string.Empty,
+ (true, SortingCategory.Views) => $"{SortingConstants.Views} {repositories.Sum(x => x.TotalViews).ToAbbreviatedText()}, {SortingConstants.UniqueViews} {repositories.Sum(x => x.TotalUniqueViews).ToAbbreviatedText()}, {SortingConstants.Stars} {repositories.Sum(x => x.StarCount).ToAbbreviatedText()}",
+ (true, SortingCategory.Clones) => $"{SortingConstants.Clones} {repositories.Sum(x => x.TotalClones).ToAbbreviatedText()}, {SortingConstants.UniqueClones} {repositories.Sum(x => x.TotalUniqueClones).ToAbbreviatedText()}, {SortingConstants.Stars} {repositories.Sum(x => x.StarCount).ToAbbreviatedText()}",
+ (true, SortingCategory.IssuesForks) => $"{SortingConstants.Stars} {repositories.Sum(x => x.StarCount).ToAbbreviatedText()}, {SortingConstants.Forks} {repositories.Sum(x => x.ForkCount).ToAbbreviatedText()}, {SortingConstants.Issues} {repositories.Sum(x => x.IssuesCount).ToAbbreviatedText()}",
+ (_, _) => throw new NotSupportedException()
+ };
+
+ public static string GetFloatingActionTextButtonText(in MobileSortingService mobileSortingService, in IReadOnlyList repositories, in FloatingActionButtonType floatingActionButtonType) where TRepository : IRepository =>
+ GetFloatingActionTextButtonText(MobileSortingService.GetSortingCategory(mobileSortingService.CurrentOption), repositories.ToList(), floatingActionButtonType);
+
+ public static string GetFloatingActionTextButtonText(in SortingCategory sortingCategory, in IReadOnlyList repositories, in FloatingActionButtonType floatingActionButtonType) where TRepository : IRepository
+ {
+ return (sortingCategory, floatingActionButtonType) switch
+ {
+ (SortingCategory.Clones, FloatingActionButtonType.Statistic1) => repositories.Sum(x => x.TotalClones).ToAbbreviatedText(),
+ (SortingCategory.Clones, FloatingActionButtonType.Statistic2) => repositories.Sum(x => x.TotalUniqueClones).ToAbbreviatedText(),
+ (SortingCategory.Clones, FloatingActionButtonType.Statistic3) => repositories.Sum(x => x.StarCount).ToAbbreviatedText(),
+ (SortingCategory.Views, FloatingActionButtonType.Statistic1) => repositories.Sum(x => x.TotalViews).ToAbbreviatedText(),
+ (SortingCategory.Views, FloatingActionButtonType.Statistic2) => repositories.Sum(x => x.TotalUniqueViews).ToAbbreviatedText(),
+ (SortingCategory.Views, FloatingActionButtonType.Statistic3) => repositories.Sum(x => x.StarCount).ToAbbreviatedText(),
+ (SortingCategory.IssuesForks, FloatingActionButtonType.Statistic1) => repositories.Sum(x => x.StarCount).ToAbbreviatedText(),
+ (SortingCategory.IssuesForks, FloatingActionButtonType.Statistic2) => repositories.Sum(x => x.ForkCount).ToAbbreviatedText(),
+ (SortingCategory.IssuesForks, FloatingActionButtonType.Statistic3) => repositories.Sum(x => x.IssuesCount).ToAbbreviatedText(),
+ (_, FloatingActionButtonType.Information) => throw new NotSupportedException(),
+ (_, _) => throw new NotImplementedException()
+ };
+ }
}
}
diff --git a/GitTrends.UITests/Pages/BaseCollectionPage.cs b/GitTrends.UITests/Pages/BaseCollectionPage.cs
index c812021e5..6d48cd517 100644
--- a/GitTrends.UITests/Pages/BaseCollectionPage.cs
+++ b/GitTrends.UITests/Pages/BaseCollectionPage.cs
@@ -15,7 +15,7 @@ protected BaseCollectionPage(IApp app, Func? getPageTitle) : base(app, g
}
- public List VisibleCollection => App.InvokeBackdoorMethod>(BackdoorMethodConstants.GetVisibleCollection);
+ public IReadOnlyList VisibleCollection => App.InvokeBackdoorMethod>(BackdoorMethodConstants.GetVisibleCollection);
bool IsRefreshViewRefreshIndicatorDisplayed => App switch
{
diff --git a/GitTrends.UITests/Pages/RepositoryPage.cs b/GitTrends.UITests/Pages/RepositoryPage.cs
index f670e4ae9..745e37547 100644
--- a/GitTrends.UITests/Pages/RepositoryPage.cs
+++ b/GitTrends.UITests/Pages/RepositoryPage.cs
@@ -14,7 +14,8 @@ class RepositoryPage : BaseCollectionPage
{
readonly Query _searchBar, _settingsButton, _collectionView, _refreshView,
_androidContextMenuOverflowButton, _androidSearchBarButton, _sortButton, _emptyDataView,
- _smallScreenTrendingImage, _largeScreenTrendingImage;
+ _smallScreenTrendingImage, _largeScreenTrendingImage, _informationLabel, _informationButton,
+ _statistic1FloatingActionButton, _statistic2FloatingActionButton, _statistic3FloatingActionButton;
public RepositoryPage(IApp app) : base(app, () => PageTitles.RepositoryPage)
{
@@ -28,6 +29,11 @@ public RepositoryPage(IApp app) : base(app, () => PageTitles.RepositoryPage)
_emptyDataView = GenerateMarkedQuery(RepositoryPageAutomationIds.EmptyDataView);
_smallScreenTrendingImage = GenerateMarkedQuery(RepositoryPageAutomationIds.SmallScreenTrendingImage);
_largeScreenTrendingImage = GenerateMarkedQuery(RepositoryPageAutomationIds.LargeScreenTrendingImage);
+ _informationButton = GenerateMarkedQuery(RepositoryPageAutomationIds.InformationButton);
+ _informationLabel = GenerateMarkedQuery(RepositoryPageAutomationIds.InformationLabel);
+ _statistic1FloatingActionButton = GenerateMarkedQuery(RepositoryPageAutomationIds.GetFloatingActionTextButtonLabelAutomationId(FloatingActionButtonType.Statistic1));
+ _statistic2FloatingActionButton = GenerateMarkedQuery(RepositoryPageAutomationIds.GetFloatingActionTextButtonLabelAutomationId(FloatingActionButtonType.Statistic2));
+ _statistic3FloatingActionButton = GenerateMarkedQuery(RepositoryPageAutomationIds.GetFloatingActionTextButtonLabelAutomationId(FloatingActionButtonType.Statistic3));
}
public bool IsEmptyDataViewVisible => App.Query(_emptyDataView).Any();
@@ -35,6 +41,25 @@ public RepositoryPage(IApp app) : base(app, () => PageTitles.RepositoryPage)
public int SmallScreenTrendingImageCount => App.Query(_smallScreenTrendingImage).Count();
public int LargeScreenTrendingImageCount => App.Query(_largeScreenTrendingImage).Count();
+ public string InformationLabelText => App is iOSApp ? GetText(_informationLabel) : throw new NotSupportedException("Information Label Only Available on iOS");
+
+ public string InformationButtonStatistic1Text => App is AndroidApp ? GetText(_statistic1FloatingActionButton) : throw new NotSupportedException("Information Button Only Available on Android");
+ public string InformationButtonStatistic2Text => App is AndroidApp ? GetText(_statistic2FloatingActionButton) : throw new NotSupportedException("Information Button Only Available on Android");
+ public string InformationButtonStatistic3Text => App is AndroidApp ? GetText(_statistic3FloatingActionButton) : throw new NotSupportedException("Information Button Only Available on Android");
+
+ public void TapInformationButton()
+ {
+ if (App is AndroidApp)
+ {
+ App.Tap(_informationButton);
+ App.Screenshot("Information Button Tapped");
+ }
+ else
+ {
+ throw new NotSupportedException("Information Button Only Available on Android");
+ }
+ }
+
public void WaitForEmptyDataView()
{
App.WaitForElement(_emptyDataView);
diff --git a/GitTrends.UITests/Tests/ReferringSitesTests.cs b/GitTrends.UITests/Tests/ReferringSitesTests.cs
index 8d0454386..9fb58bc31 100644
--- a/GitTrends.UITests/Tests/ReferringSitesTests.cs
+++ b/GitTrends.UITests/Tests/ReferringSitesTests.cs
@@ -24,7 +24,7 @@ public override async Task BeforeEachTest()
{
await base.BeforeEachTest().ConfigureAwait(false);
- var referringSites = new List();
+ IReadOnlyList referringSites = Enumerable.Empty().ToList();
var repositories = RepositoryPage.VisibleCollection;
var repositoriesEnumerator = repositories.GetEnumerator();
diff --git a/GitTrends.UITests/Tests/RepositoriesTests.cs b/GitTrends.UITests/Tests/RepositoriesTests.cs
index 5d21ef559..04a3ac70b 100644
--- a/GitTrends.UITests/Tests/RepositoriesTests.cs
+++ b/GitTrends.UITests/Tests/RepositoriesTests.cs
@@ -6,6 +6,8 @@
using GitTrends.Mobile.Common.Constants;
using NUnit.Framework;
using Xamarin.UITest;
+using Xamarin.UITest.Android;
+using Xamarin.UITest.iOS;
namespace GitTrends.UITests
{
@@ -105,16 +107,27 @@ public async Task VerifySortingOptions(SortingOption sortingOption)
Assert.AreEqual(MobileSortingService.DefaultSortingOption, SortingOption.Views);
//Arrange
- Repository finalFirstRepository;
- Repository finalSecondTopRepository;
- Repository finalLastRepository;
+ Repository finalFirstRepository, finalSecondTopRepository, finalLastRepository;
Repository initialFirstRepository = RepositoryPage.VisibleCollection.First();
Repository initialSecondTopRepository = RepositoryPage.VisibleCollection.Skip(1).First();
Repository initialLastRepository = RepositoryPage.VisibleCollection.Last();
+ string floatingActionTextButtonStatistic1Text = string.Empty,
+ floatingActionTextButtonStatistic2Text = string.Empty,
+ floatingActionTextButtonStatistic3Text = string.Empty;
+
//Act
await RepositoryPage.SetSortingOption(sortingOption).ConfigureAwait(false);
+ if (App is AndroidApp)
+ {
+ floatingActionTextButtonStatistic1Text = RepositoryPage.InformationButtonStatistic1Text;
+ floatingActionTextButtonStatistic2Text = RepositoryPage.InformationButtonStatistic2Text;
+ floatingActionTextButtonStatistic3Text = RepositoryPage.InformationButtonStatistic3Text;
+
+ RepositoryPage.TapInformationButton();
+ }
+
//Assert
finalFirstRepository = RepositoryPage.VisibleCollection.First();
finalSecondTopRepository = RepositoryPage.VisibleCollection.Skip(1).First();
@@ -125,6 +138,26 @@ public async Task VerifySortingOptions(SortingOption sortingOption)
Assert.GreaterOrEqual(initialFirstRepository.TotalViews, initialLastRepository.TotalViews);
+ if (App is AndroidApp)
+ {
+ var floatingActionTextButtonStatistic1Text_Expected = StatisticsService.GetFloatingActionTextButtonText(MobileSortingService.GetSortingCategory(sortingOption), RepositoryPage.VisibleCollection, FloatingActionButtonType.Statistic1);
+ var floatingActionTextButtonStatistic2Text_Expected = StatisticsService.GetFloatingActionTextButtonText(MobileSortingService.GetSortingCategory(sortingOption), RepositoryPage.VisibleCollection, FloatingActionButtonType.Statistic2);
+ var floatingActionTextButtonStatistic3Text_Expected = StatisticsService.GetFloatingActionTextButtonText(MobileSortingService.GetSortingCategory(sortingOption), RepositoryPage.VisibleCollection, FloatingActionButtonType.Statistic3);
+
+ Assert.AreEqual(floatingActionTextButtonStatistic1Text_Expected, floatingActionTextButtonStatistic1Text);
+ Assert.AreEqual(floatingActionTextButtonStatistic2Text_Expected, floatingActionTextButtonStatistic2Text);
+ Assert.AreEqual(floatingActionTextButtonStatistic3Text_Expected, floatingActionTextButtonStatistic3Text);
+ }
+ else if (App is iOSApp)
+ {
+ var informationLabelText_Expected = StatisticsService.GetInformationLabelText(RepositoryPage.VisibleCollection, MobileSortingService.GetSortingCategory(sortingOption));
+ Assert.AreEqual(informationLabelText_Expected, RepositoryPage.InformationLabelText);
+ }
+ else
+ {
+ throw new NotSupportedException();
+ }
+
switch (sortingOption)
{
case SortingOption.Views when finalFirstRepository.IsTrending == finalSecondTopRepository.IsTrending:
diff --git a/GitTrends.iOS/GitTrends.iOS.csproj b/GitTrends.iOS/GitTrends.iOS.csproj
index 4efc8b527..de23dc0bd 100644
--- a/GitTrends.iOS/GitTrends.iOS.csproj
+++ b/GitTrends.iOS/GitTrends.iOS.csproj
@@ -438,7 +438,7 @@
-
+
diff --git a/GitTrends/GitTrends.csproj b/GitTrends/GitTrends.csproj
index c286b6247..6a99cbf76 100644
--- a/GitTrends/GitTrends.csproj
+++ b/GitTrends/GitTrends.csproj
@@ -42,7 +42,7 @@
-
+
diff --git a/GitTrends/Pages/RepositoryPage.cs b/GitTrends/Pages/RepositoryPage.cs
index 32f8fe1a9..f2dd493a0 100644
--- a/GitTrends/Pages/RepositoryPage.cs
+++ b/GitTrends/Pages/RepositoryPage.cs
@@ -76,9 +76,9 @@ public RepositoryPage(IMainThread mainThread,
Children =
{
- new TotalsLabel().Row(Row.Totals).ColumnSpan(All())
+ new InformationLabel().Row(Row.Totals).ColumnSpan(All())
.Bind