mirror of
https://github.com/microsoft/PowerToys.git
synced 2025-12-16 11:48:06 +01:00
Tests: Editor settings tests (#1682)
* Added tests for padding checkbox, padding values
This commit is contained in:
committed by
GitHub
parent
d95e49b535
commit
91223a8431
@@ -1,5 +1,6 @@
|
||||
using System;
|
||||
using System.IO;
|
||||
using System.Collections.Generic;
|
||||
using Microsoft.VisualStudio.TestTools.UnitTesting;
|
||||
using Newtonsoft.Json.Linq;
|
||||
using OpenQA.Selenium;
|
||||
@@ -8,71 +9,177 @@ using OpenQA.Selenium.Appium.Windows;
|
||||
namespace PowerToysTests
|
||||
{
|
||||
[TestClass]
|
||||
public class FancyZonesEditorSettingsTests : PowerToysSession
|
||||
public class FancyZonesEditorSettingsTests : FancyZonesEditor
|
||||
{
|
||||
private const string editorZoneCount = "editor-zone-count";
|
||||
private const string editorShowSpacing = "editor-show-spacing";
|
||||
private const string editorSpacing = "editor-spacing";
|
||||
|
||||
[TestMethod]
|
||||
public void ZoneCount()
|
||||
{
|
||||
ShortWait();
|
||||
OpenFancyZonesSettings();
|
||||
OpenEditor();
|
||||
|
||||
WindowsElement editorButton = WaitElementByXPath("//Button[@Name=\"Edit zones\"]");
|
||||
editorButton.Click();
|
||||
WindowsElement minusButton = session.FindElementByAccessibilityId("decrementZones");
|
||||
WindowsElement zoneCount = session.FindElementByAccessibilityId("zoneCount");
|
||||
|
||||
WindowsElement minusButton = WaitElementByAccessibilityId("decrementZones");
|
||||
WindowsElement zoneCount = WaitElementByAccessibilityId("zoneCount");
|
||||
WindowsElement applyButton;
|
||||
int editorZoneCountValue;
|
||||
Assert.IsTrue(Int32.TryParse(zoneCount.Text, out editorZoneCountValue));
|
||||
|
||||
int zoneCountQty;
|
||||
Assert.IsTrue(Int32.TryParse(zoneCount.Text, out zoneCountQty));
|
||||
|
||||
for (int i = zoneCountQty - 1, j = 0; i > -5; --i, ++j)
|
||||
for (int i = editorZoneCountValue - 1, j = 0; i > -5; --i, ++j)
|
||||
{
|
||||
minusButton.Click();
|
||||
|
||||
Assert.IsTrue(Int32.TryParse(zoneCount.Text, out zoneCountQty));
|
||||
Assert.AreEqual(Math.Max(i, 1), zoneCountQty);
|
||||
Assert.IsTrue(Int32.TryParse(zoneCount.Text, out editorZoneCountValue));
|
||||
Assert.AreEqual(Math.Max(i, 1), editorZoneCountValue);
|
||||
|
||||
if (j == 0 || i == -4)
|
||||
{
|
||||
applyButton = WaitElementByAccessibilityId("ApplyTemplateButton");
|
||||
applyButton.Click();
|
||||
session.FindElementByAccessibilityId("ApplyTemplateButton").Click();
|
||||
|
||||
ShortWait();
|
||||
Assert.AreEqual(zoneCountQty, getSavedZoneCount());
|
||||
editorButton.Click();
|
||||
minusButton = WaitElementByAccessibilityId("decrementZones");
|
||||
zoneCount = WaitElementByAccessibilityId("zoneCount");
|
||||
Assert.AreEqual(editorZoneCountValue, GetEditZonesSetting<int>(editorZoneCount));
|
||||
OpenEditor();
|
||||
|
||||
minusButton = session.FindElementByAccessibilityId("decrementZones");
|
||||
zoneCount = session.FindElementByAccessibilityId("zoneCount");
|
||||
}
|
||||
}
|
||||
|
||||
WindowsElement plusButton = WaitElementByAccessibilityId("incrementZones");
|
||||
WindowsElement plusButton = session.FindElementByAccessibilityId("incrementZones");
|
||||
|
||||
for (int i = 2; i < 45; ++i)
|
||||
{
|
||||
plusButton.Click();
|
||||
|
||||
Assert.IsTrue(Int32.TryParse(zoneCount.Text, out zoneCountQty));
|
||||
Assert.AreEqual(Math.Min(i, 40), zoneCountQty);
|
||||
Assert.IsTrue(Int32.TryParse(zoneCount.Text, out editorZoneCountValue));
|
||||
Assert.AreEqual(Math.Min(i, 40), editorZoneCountValue);
|
||||
}
|
||||
|
||||
applyButton = WaitElementByAccessibilityId("ApplyTemplateButton");
|
||||
applyButton.Click();
|
||||
session.FindElementByAccessibilityId("ApplyTemplateButton").Click();
|
||||
ShortWait();
|
||||
Assert.AreEqual(zoneCountQty, getSavedZoneCount());
|
||||
Assert.AreEqual(editorZoneCountValue, GetEditZonesSetting<int>(editorZoneCount));
|
||||
}
|
||||
|
||||
private int getSavedZoneCount()
|
||||
[TestMethod]
|
||||
public void ShowSpacingTest()
|
||||
{
|
||||
for (int i = 0; i < 2; ++i)
|
||||
{
|
||||
OpenEditor();
|
||||
|
||||
WindowsElement spaceAroundSetting = session.FindElementByAccessibilityId("spaceAroundSetting");
|
||||
bool spaceAroundSettingValue = spaceAroundSetting.Selected;
|
||||
spaceAroundSetting.Click();
|
||||
|
||||
session.FindElementByAccessibilityId("ApplyTemplateButton").Click();
|
||||
|
||||
ShortWait();
|
||||
|
||||
Assert.AreNotEqual(spaceAroundSettingValue, GetEditZonesSetting<bool>(editorShowSpacing));
|
||||
}
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
public void SpacingTestsValid()
|
||||
{
|
||||
OpenEditor();
|
||||
|
||||
WindowsElement spaceAroundSetting = session.FindElementByAccessibilityId("spaceAroundSetting");
|
||||
bool editorShowSpacingValue = spaceAroundSetting.Selected;
|
||||
|
||||
session.FindElementByAccessibilityId("ApplyTemplateButton").Click();
|
||||
ShortWait();
|
||||
|
||||
string[] validValues = { "0", "1", "2", "3", "4", "5", "6", "7", "8", "9" };
|
||||
|
||||
foreach (string editorSpacingValue in validValues)
|
||||
{
|
||||
OpenEditor();
|
||||
|
||||
WindowsElement paddingValue = WaitElementByAccessibilityId("paddingValue");
|
||||
ClearText(paddingValue);
|
||||
paddingValue.SendKeys(editorSpacingValue);
|
||||
|
||||
session.FindElementByAccessibilityId("ApplyTemplateButton").Click();
|
||||
ShortWait();
|
||||
|
||||
Assert.AreEqual(editorShowSpacingValue, GetEditZonesSetting<bool>(editorShowSpacing));
|
||||
Assert.AreEqual(editorSpacingValue, GetEditZonesSetting<string>(editorSpacing));
|
||||
}
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
public void SpacingTestsInvalid()
|
||||
{
|
||||
OpenEditor();
|
||||
|
||||
WindowsElement spaceAroundSetting = session.FindElementByAccessibilityId("spaceAroundSetting");
|
||||
bool editorShowSpacingValue = spaceAroundSetting.Selected;
|
||||
|
||||
session.FindElementByAccessibilityId("ApplyTemplateButton").Click();
|
||||
ShortWait();
|
||||
|
||||
string[] invalidValues = { "!", "/", "<", "?", "D", "Z", "]", "m", "}", "1.5", "2,5" };
|
||||
|
||||
string editorSpacingValue = GetEditZonesSetting<string>(editorSpacing);
|
||||
|
||||
foreach (string value in invalidValues)
|
||||
{
|
||||
OpenEditor();
|
||||
|
||||
WindowsElement paddingValue = WaitElementByAccessibilityId("paddingValue");
|
||||
ClearText(paddingValue);
|
||||
paddingValue.SendKeys(value);
|
||||
|
||||
session.FindElementByAccessibilityId("ApplyTemplateButton").Click();
|
||||
ShortWait();
|
||||
|
||||
Assert.AreEqual(editorShowSpacingValue, GetEditZonesSetting<bool>(editorShowSpacing));
|
||||
Assert.AreEqual(editorSpacingValue, GetEditZonesSetting<string>(editorSpacing));
|
||||
}
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
public void SpacingTestLargeValue()
|
||||
{
|
||||
OpenEditor();
|
||||
session.FindElementByXPath("//Text[@Name=\"Grid\"]").Click();
|
||||
|
||||
WindowsElement paddingValue = session.FindElementByAccessibilityId("paddingValue");
|
||||
ClearText(paddingValue);
|
||||
paddingValue.SendKeys("1000");
|
||||
|
||||
session.FindElementByAccessibilityId("ApplyTemplateButton").Click();
|
||||
|
||||
editorWindow = null;
|
||||
try
|
||||
{
|
||||
OpenEditor();
|
||||
}
|
||||
catch { }
|
||||
|
||||
Assert.AreNotEqual(editorWindow, null, "Editor Zones Window is not starting after setting large padding value");
|
||||
}
|
||||
|
||||
private T GetEditZonesSetting<T>(string value)
|
||||
{
|
||||
JObject zoneSettings = JObject.Parse(File.ReadAllText(_zoneSettingsPath));
|
||||
int editorZoneCount = (int)zoneSettings["devices"][0]["editor-zone-count"];
|
||||
return editorZoneCount;
|
||||
T result = zoneSettings["devices"][0][value].ToObject<T>();
|
||||
return result;
|
||||
}
|
||||
|
||||
private void ClearText(WindowsElement windowsElement)
|
||||
{
|
||||
windowsElement.SendKeys(Keys.Home);
|
||||
windowsElement.SendKeys(Keys.Control + Keys.Delete);
|
||||
}
|
||||
|
||||
[ClassInitialize]
|
||||
public static void ClassInitialize(TestContext context)
|
||||
{
|
||||
Setup(context);
|
||||
OpenSettings();
|
||||
Setup(context, false);
|
||||
ResetSettings();
|
||||
}
|
||||
|
||||
[ClassCleanup]
|
||||
@@ -91,7 +198,7 @@ namespace PowerToysTests
|
||||
[TestCleanup]
|
||||
public void TestCleanup()
|
||||
{
|
||||
|
||||
ResetSettings();
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user