Tests: Editor settings tests (#1682)

* Added tests for padding checkbox, padding values
This commit is contained in:
Yevhenii Holovachov
2020-04-08 16:33:05 +03:00
committed by GitHub
parent d95e49b535
commit 91223a8431

View File

@@ -1,5 +1,6 @@
using System; using System;
using System.IO; using System.IO;
using System.Collections.Generic;
using Microsoft.VisualStudio.TestTools.UnitTesting; using Microsoft.VisualStudio.TestTools.UnitTesting;
using Newtonsoft.Json.Linq; using Newtonsoft.Json.Linq;
using OpenQA.Selenium; using OpenQA.Selenium;
@@ -8,71 +9,177 @@ using OpenQA.Selenium.Appium.Windows;
namespace PowerToysTests namespace PowerToysTests
{ {
[TestClass] [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] [TestMethod]
public void ZoneCount() public void ZoneCount()
{ {
ShortWait(); OpenEditor();
OpenFancyZonesSettings();
WindowsElement editorButton = WaitElementByXPath("//Button[@Name=\"Edit zones\"]"); WindowsElement minusButton = session.FindElementByAccessibilityId("decrementZones");
editorButton.Click(); WindowsElement zoneCount = session.FindElementByAccessibilityId("zoneCount");
WindowsElement minusButton = WaitElementByAccessibilityId("decrementZones"); int editorZoneCountValue;
WindowsElement zoneCount = WaitElementByAccessibilityId("zoneCount"); Assert.IsTrue(Int32.TryParse(zoneCount.Text, out editorZoneCountValue));
WindowsElement applyButton;
int zoneCountQty; for (int i = editorZoneCountValue - 1, j = 0; i > -5; --i, ++j)
Assert.IsTrue(Int32.TryParse(zoneCount.Text, out zoneCountQty));
for (int i = zoneCountQty - 1, j = 0; i > -5; --i, ++j)
{ {
minusButton.Click(); minusButton.Click();
Assert.IsTrue(Int32.TryParse(zoneCount.Text, out zoneCountQty)); Assert.IsTrue(Int32.TryParse(zoneCount.Text, out editorZoneCountValue));
Assert.AreEqual(Math.Max(i, 1), zoneCountQty); Assert.AreEqual(Math.Max(i, 1), editorZoneCountValue);
if (j == 0 || i == -4) if (j == 0 || i == -4)
{ {
applyButton = WaitElementByAccessibilityId("ApplyTemplateButton"); session.FindElementByAccessibilityId("ApplyTemplateButton").Click();
applyButton.Click();
ShortWait(); ShortWait();
Assert.AreEqual(zoneCountQty, getSavedZoneCount()); Assert.AreEqual(editorZoneCountValue, GetEditZonesSetting<int>(editorZoneCount));
editorButton.Click(); OpenEditor();
minusButton = WaitElementByAccessibilityId("decrementZones");
zoneCount = WaitElementByAccessibilityId("zoneCount"); minusButton = session.FindElementByAccessibilityId("decrementZones");
zoneCount = session.FindElementByAccessibilityId("zoneCount");
} }
} }
WindowsElement plusButton = WaitElementByAccessibilityId("incrementZones"); WindowsElement plusButton = session.FindElementByAccessibilityId("incrementZones");
for (int i = 2; i < 45; ++i) for (int i = 2; i < 45; ++i)
{ {
plusButton.Click(); plusButton.Click();
Assert.IsTrue(Int32.TryParse(zoneCount.Text, out zoneCountQty)); Assert.IsTrue(Int32.TryParse(zoneCount.Text, out editorZoneCountValue));
Assert.AreEqual(Math.Min(i, 40), zoneCountQty); Assert.AreEqual(Math.Min(i, 40), editorZoneCountValue);
} }
applyButton = WaitElementByAccessibilityId("ApplyTemplateButton"); session.FindElementByAccessibilityId("ApplyTemplateButton").Click();
applyButton.Click();
ShortWait(); 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)); JObject zoneSettings = JObject.Parse(File.ReadAllText(_zoneSettingsPath));
int editorZoneCount = (int)zoneSettings["devices"][0]["editor-zone-count"]; T result = zoneSettings["devices"][0][value].ToObject<T>();
return editorZoneCount; return result;
}
private void ClearText(WindowsElement windowsElement)
{
windowsElement.SendKeys(Keys.Home);
windowsElement.SendKeys(Keys.Control + Keys.Delete);
} }
[ClassInitialize] [ClassInitialize]
public static void ClassInitialize(TestContext context) public static void ClassInitialize(TestContext context)
{ {
Setup(context); Setup(context, false);
OpenSettings(); ResetSettings();
} }
[ClassCleanup] [ClassCleanup]
@@ -91,7 +198,7 @@ namespace PowerToysTests
[TestCleanup] [TestCleanup]
public void TestCleanup() public void TestCleanup()
{ {
ResetSettings();
} }
} }
} }