naps2/NAPS2.App.Tests/Appium/LanguageSelectionTests.cs

77 lines
2.5 KiB
C#
Raw Permalink Normal View History

using System.Collections.ObjectModel;
2022-12-19 02:27:57 +03:00
using System.Threading;
2022-12-19 00:52:33 +03:00
using NAPS2.App.Tests.Targets;
using NAPS2.App.Tests.Verification;
using OpenQA.Selenium.Appium.Windows;
using Xunit;
2022-07-31 00:57:21 +03:00
// ReSharper disable StringLiteralTypo
namespace NAPS2.App.Tests.Appium;
2022-07-31 00:57:21 +03:00
[Collection("appium")]
public class LanguageSelectionTests : AppiumTests
{
2023-12-17 08:46:21 +03:00
private static readonly HashSet<string> ExpectedMissingLanguages = ["bn", "ur"];
[VerifyTheory(AllowDebug = true, WindowsAppium = true)]
2022-12-19 00:52:33 +03:00
[ClassData(typeof(AppiumTestData))]
public void OpenLanguageDropdown(IAppTestTarget target)
{
2022-12-19 00:52:33 +03:00
Init(target);
// Open the Language dropdown
2022-07-31 00:57:21 +03:00
ClickAtName("Language");
var menuItems = GetMenuItems();
2022-11-13 22:09:22 +03:00
2022-11-28 09:15:27 +03:00
VerifyMissingLanguages(menuItems);
2022-11-13 22:09:22 +03:00
// Verify French (fr) translation as a standard language example
2022-11-13 22:09:22 +03:00
ClickAndResetWindow("Français");
ClickAndResetWindow("Langue");
// Verify Portuguese (pt-BR) translation as a country-specific language example
2022-11-13 22:09:22 +03:00
ClickAndResetWindow("Português (Brasil)");
ClickAndResetWindow("Idioma");
// Verify Hebrew translation as a RTL language example
2022-11-13 22:09:22 +03:00
ClickAndResetWindow("עברית");
ClickAndResetWindow("שפה");
2022-07-31 00:57:21 +03:00
// And back to English
2022-11-13 22:09:22 +03:00
ClickAndResetWindow("English");
2022-07-31 00:57:21 +03:00
ClickAtName("Language");
AppTestHelper.AssertNoErrorLog(FolderPath);
}
2022-11-28 09:15:27 +03:00
private void VerifyMissingLanguages(ReadOnlyCollection<WindowsElement> menuItems)
{
#if !DEBUG_LANG
// In Debug mode (without DEBUG_LANG) we don't expect to have all languages
if (Debugger.IsAttached) return;
#endif
// Verify all expected languages have menu items
var menuItemTexts = menuItems.Select(x => x.Text).ToHashSet();
var allLanguages = GetAllLanguages();
var missingLanguages = allLanguages
.Where(x => !menuItemTexts.Contains(x.langName) && !ExpectedMissingLanguages.Contains(x.langCode))
.ToList();
Assert.True(missingLanguages.Count == 0, $"Missing languages: {string.Join(",", missingLanguages)}");
}
2022-11-13 22:09:22 +03:00
private void ClickAndResetWindow(string name)
{
ClickAtName(name);
2022-12-19 02:27:57 +03:00
Thread.Sleep(100);
2022-11-13 22:09:22 +03:00
ResetMainWindow();
}
private List<(string langCode, string langName)> GetAllLanguages()
{
return new CultureHelper(Naps2Config.Stub()).GetAllCultures().ToList();
}
private ReadOnlyCollection<WindowsElement> GetMenuItems()
{
return _session.FindElementsByTagName("MenuItem");
}
}