Files
PowerToys/src/tests/win-app-driver/FancyZonesTests/EditorTemplatesEditTests.cs

207 lines
5.5 KiB
C#
Raw Normal View History

using System.IO.Abstractions;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using Newtonsoft.Json.Linq;
using OpenQA.Selenium.Appium;
using OpenQA.Selenium.Interactions;
namespace PowerToysTests
{
[TestClass]
2020-03-31 15:15:51 +03:00
public class FancyZonesEditorTemplatesEditTests : FancyZonesEditor
{
private static readonly IFileSystem FileSystem = new FileSystem();
private static readonly IFile File = FileSystem.File;
2020-08-14 15:10:06 -07:00
private void ChangeLayout()
{
new Actions(session).MoveToElement(creatorWindow.FindElementByAccessibilityId("PART_TitleBar")).MoveByOffset(0, -50).Click().Perform();
}
private void Cancel(AppiumWebElement creatorWindow)
2020-08-14 15:10:06 -07:00
{
AppiumWebElement cancelButton = creatorWindow.FindElementByName("Cancel");
Assert.IsNotNull(cancelButton);
2020-08-14 15:10:06 -07:00
new Actions(session).MoveToElement(cancelButton).Click().Perform();
}
private void CancelTest(AppiumWebElement creatorWindow)
{
Cancel(creatorWindow);
2020-08-14 15:10:06 -07:00
WaitSeconds(1);
Assert.AreEqual(_defaultZoneSettings, File.ReadAllText(_zoneSettingsPath), "Settings were changed");
}
2020-08-14 15:10:06 -07:00
private void SaveTest()
{
new Actions(session).MoveToElement(creatorWindow.FindElementByName("Save and apply")).Click().Perform();
2020-08-14 15:10:06 -07:00
WaitSeconds(1);
JObject settings = JObject.Parse(File.ReadAllText(_zoneSettingsPath));
Assert.AreEqual("Custom Layout 1", settings["custom-zone-sets"][0]["name"]);
Assert.AreEqual(settings["custom-zone-sets"][0]["uuid"], settings["devices"][0]["active-zoneset"]["uuid"]);
}
[TestMethod]
2020-08-14 15:10:06 -07:00
public void EditFocusCancel()
{
OpenCreatorWindow("Focus", "EditTemplateButton");
2020-08-14 15:10:06 -07:00
ZoneCountTest(3, 0);
creatorWindow.FindElementByAccessibilityId("newZoneButton").Click();
2020-08-14 15:10:06 -07:00
ZoneCountTest(4, 0);
CancelTest(creatorWindow);
2020-08-14 15:10:06 -07:00
}
[TestMethod]
2020-08-14 15:10:06 -07:00
public void EditColumnsCancel()
{
OpenCreatorWindow("Columns", "EditTemplateButton");
2020-08-14 15:10:06 -07:00
ZoneCountTest(0, 3);
ChangeLayout();
ZoneCountTest(0, 4);
CancelTest(creatorWindow);
2020-08-14 15:10:06 -07:00
}
[TestMethod]
2020-08-14 15:10:06 -07:00
public void EditRowsCancel()
{
OpenCreatorWindow("Rows", "EditTemplateButton");
2020-08-14 15:10:06 -07:00
ZoneCountTest(0, 3);
ChangeLayout();
ZoneCountTest(0, 4);
CancelTest(creatorWindow);
2020-08-14 15:10:06 -07:00
}
[TestMethod]
2020-08-14 15:10:06 -07:00
public void EditGridCancel()
{
OpenCreatorWindow("Grid", "EditTemplateButton");
2020-08-14 15:10:06 -07:00
ZoneCountTest(0, 3);
ChangeLayout();
ZoneCountTest(0, 4);
CancelTest(creatorWindow);
2020-08-14 15:10:06 -07:00
}
[TestMethod]
2020-08-14 15:10:06 -07:00
public void EditPriorityGridCancel()
{
OpenCreatorWindow("Priority Grid", "EditTemplateButton");
2020-08-14 15:10:06 -07:00
ZoneCountTest(0, 3);
ChangeLayout();
ZoneCountTest(0, 4);
CancelTest(creatorWindow);
}
[TestMethod]
2020-08-14 15:10:06 -07:00
public void EditFocusSave()
{
OpenCreatorWindow("Focus", "EditTemplateButton");
2020-08-14 15:10:06 -07:00
ZoneCountTest(3, 0);
creatorWindow.FindElementByAccessibilityId("newZoneButton").Click();
2020-08-14 15:10:06 -07:00
ZoneCountTest(4, 0);
SaveTest();
}
[TestMethod]
2020-08-14 15:10:06 -07:00
public void EditColumnsSave()
{
OpenCreatorWindow("Columns", "EditTemplateButton");
2020-08-14 15:10:06 -07:00
ZoneCountTest(0, 3);
ChangeLayout();
ZoneCountTest(0, 4);
SaveTest();
}
[TestMethod]
2020-08-14 15:10:06 -07:00
public void EditRowsSave()
{
OpenCreatorWindow("Rows", "EditTemplateButton");
2020-08-14 15:10:06 -07:00
ZoneCountTest(0, 3);
ChangeLayout();
ZoneCountTest(0, 4);
SaveTest();
}
[TestMethod]
2020-08-14 15:10:06 -07:00
public void EditGridSave()
{
OpenCreatorWindow("Grid", "EditTemplateButton");
2020-08-14 15:10:06 -07:00
ZoneCountTest(0, 3);
ChangeLayout();
ZoneCountTest(0, 4);
SaveTest();
}
[TestMethod]
2020-08-14 15:10:06 -07:00
public void EditPriorityGridSave()
{
OpenCreatorWindow("Priority Grid", "EditTemplateButton");
2020-08-14 15:10:06 -07:00
ZoneCountTest(0, 3);
ChangeLayout();
ZoneCountTest(0, 4);
SaveTest();
}
[ClassInitialize]
public static void ClassInitialize(TestContext context)
{
Setup(context);
Assert.IsNotNull(session);
EnableModules(false, true, false, false, false, false, false, false);
2020-03-31 15:15:51 +03:00
ResetDefaultFancyZonesSettings(false);
}
[ClassCleanup]
public static void ClassCleanup()
{
2020-08-14 15:10:06 -07:00
CloseSettings();
ExitPowerToys();
TearDown();
}
[TestInitialize]
public void TestInitialize()
2020-08-14 15:10:06 -07:00
{
ResetDefaultZoneSettings(true);
Assert.IsTrue(OpenEditor());
2020-08-14 15:10:06 -07:00
OpenTemplates();
}
[TestCleanup]
public void TestCleanup()
{
//Close editor
2020-08-14 15:10:06 -07:00
try
{
if (editorWindow != null)
{
editorWindow.SendKeys(OpenQA.Selenium.Keys.Alt + OpenQA.Selenium.Keys.F4);
}
}
catch (OpenQA.Selenium.WebDriverException)
2020-08-14 15:10:06 -07:00
{
//editor was already closed
}
}
}
}