mirror of
https://github.com/microsoft/PowerToys.git
synced 2025-06-11 20:23:07 +08:00
Editor tests: apply templates (#1648)
* apply templates tests * moved settings reset methods
This commit is contained in:
parent
6f2801cea8
commit
e32d619677
@ -0,0 +1,126 @@
|
|||||||
|
using System.IO;
|
||||||
|
using Microsoft.VisualStudio.TestTools.UnitTesting;
|
||||||
|
using Newtonsoft.Json.Linq;
|
||||||
|
using OpenQA.Selenium.Appium.Windows;
|
||||||
|
using OpenQA.Selenium.Interactions;
|
||||||
|
|
||||||
|
namespace PowerToysTests
|
||||||
|
{
|
||||||
|
[TestClass]
|
||||||
|
public class FancyZonesEditorTemplatesApplyTests : PowerToysSession
|
||||||
|
{
|
||||||
|
WindowsElement editorWindow;
|
||||||
|
|
||||||
|
private void OpenEditor()
|
||||||
|
{
|
||||||
|
new Actions(session).KeyDown(OpenQA.Selenium.Keys.Command).SendKeys("`").KeyUp(OpenQA.Selenium.Keys.Command).Perform();
|
||||||
|
ShortWait();
|
||||||
|
|
||||||
|
editorWindow = session.FindElementByXPath("//Window[@Name=\"FancyZones Editor\"]");
|
||||||
|
}
|
||||||
|
|
||||||
|
private void OpenTemplates()
|
||||||
|
{
|
||||||
|
WindowsElement templatesTab = session.FindElementByName("Templates");
|
||||||
|
templatesTab.Click();
|
||||||
|
string isSelected = templatesTab.GetAttribute("SelectionItem.IsSelected");
|
||||||
|
Assert.AreEqual("True", isSelected, "Templates tab cannot be opened");
|
||||||
|
}
|
||||||
|
|
||||||
|
private void ApplyLayout(string tabName)
|
||||||
|
{
|
||||||
|
string elementXPath = "//Text[@Name=\"" + tabName + "\"]";
|
||||||
|
session.FindElementByXPath(elementXPath).Click();
|
||||||
|
session.FindElementByAccessibilityId("ApplyTemplateButton").Click();
|
||||||
|
|
||||||
|
try
|
||||||
|
{
|
||||||
|
Assert.IsNull(session.FindElementByXPath("//Window[@Name=\"FancyZones Editor\"]"));
|
||||||
|
}
|
||||||
|
catch (OpenQA.Selenium.WebDriverException)
|
||||||
|
{
|
||||||
|
//editor was closed as expected
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void CheckSettingsLayout(string expectedLayout)
|
||||||
|
{
|
||||||
|
JObject settings = JObject.Parse(File.ReadAllText(_zoneSettingsPath));
|
||||||
|
Assert.AreEqual(expectedLayout, settings["devices"][0]["active-zoneset"]["type"]);
|
||||||
|
}
|
||||||
|
|
||||||
|
[TestMethod]
|
||||||
|
public void ApplyFocus()
|
||||||
|
{
|
||||||
|
ApplyLayout("Focus");
|
||||||
|
CheckSettingsLayout("focus");
|
||||||
|
}
|
||||||
|
|
||||||
|
[TestMethod]
|
||||||
|
public void ApplyColumns()
|
||||||
|
{
|
||||||
|
ApplyLayout("Columns");
|
||||||
|
CheckSettingsLayout("columns");
|
||||||
|
}
|
||||||
|
|
||||||
|
[TestMethod]
|
||||||
|
public void ApplyRows()
|
||||||
|
{
|
||||||
|
ApplyLayout("Rows");
|
||||||
|
CheckSettingsLayout("rows");
|
||||||
|
}
|
||||||
|
|
||||||
|
[TestMethod]
|
||||||
|
public void ApplyGrid()
|
||||||
|
{
|
||||||
|
ApplyLayout("Grid");
|
||||||
|
CheckSettingsLayout("grid");
|
||||||
|
}
|
||||||
|
|
||||||
|
[TestMethod]
|
||||||
|
public void ApplyPriorityGrid()
|
||||||
|
{
|
||||||
|
ApplyLayout("Priority Grid");
|
||||||
|
CheckSettingsLayout("priority-grid");
|
||||||
|
}
|
||||||
|
|
||||||
|
[ClassInitialize]
|
||||||
|
public static void ClassInitialize(TestContext context)
|
||||||
|
{
|
||||||
|
Setup(context, false);
|
||||||
|
ResetDefaultFancyZonesSettings(true);
|
||||||
|
}
|
||||||
|
|
||||||
|
[ClassCleanup]
|
||||||
|
public static void ClassCleanup()
|
||||||
|
{
|
||||||
|
CloseSettings();
|
||||||
|
TearDown();
|
||||||
|
}
|
||||||
|
|
||||||
|
[TestInitialize]
|
||||||
|
public void TestInitialize()
|
||||||
|
{
|
||||||
|
OpenEditor();
|
||||||
|
OpenTemplates();
|
||||||
|
}
|
||||||
|
|
||||||
|
[TestCleanup]
|
||||||
|
public void TestCleanup()
|
||||||
|
{
|
||||||
|
//Close editor
|
||||||
|
try
|
||||||
|
{
|
||||||
|
if (editorWindow != null)
|
||||||
|
{
|
||||||
|
editorWindow.SendKeys(OpenQA.Selenium.Keys.Alt + OpenQA.Selenium.Keys.F4);
|
||||||
|
ShortWait();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
catch (OpenQA.Selenium.WebDriverException)
|
||||||
|
{
|
||||||
|
//editor has already closed
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -11,23 +11,6 @@ namespace PowerToysTests
|
|||||||
{
|
{
|
||||||
WindowsElement editorWindow;
|
WindowsElement editorWindow;
|
||||||
|
|
||||||
private static void ResetDefaultFancyZonesSettings()
|
|
||||||
{
|
|
||||||
if (!Directory.Exists(_settingsFolderPath))
|
|
||||||
{
|
|
||||||
Directory.CreateDirectory(_settingsFolderPath);
|
|
||||||
}
|
|
||||||
|
|
||||||
string settings = "{\"version\":\"1.0\",\"name\":\"FancyZones\",\"properties\":{\"fancyzones_shiftDrag\":{\"value\":true},\"fancyzones_overrideSnapHotkeys\":{\"value\":false},\"fancyzones_zoneSetChange_flashZones\":{\"value\":false},\"fancyzones_displayChange_moveWindows\":{\"value\":false},\"fancyzones_zoneSetChange_moveWindows\":{\"value\":false},\"fancyzones_virtualDesktopChange_moveWindows\":{\"value\":false},\"fancyzones_appLastZone_moveWindows\":{\"value\":false},\"use_cursorpos_editor_startupscreen\":{\"value\":true},\"fancyzones_zoneHighlightColor\":{\"value\":\"#0078D7\"},\"fancyzones_highlight_opacity\":{\"value\":90},\"fancyzones_editor_hotkey\":{\"value\":{\"win\":true,\"ctrl\":false,\"alt\":false,\"shift\":false,\"code\":192,\"key\":\"`\"}},\"fancyzones_excluded_apps\":{\"value\":\"\"}}}";
|
|
||||||
File.WriteAllText(_settingsPath, settings);
|
|
||||||
}
|
|
||||||
|
|
||||||
private void ResetDefautZoneSettings()
|
|
||||||
{
|
|
||||||
string zoneSettings = "{\"app-zone-history\":[],\"devices\":[],\"custom-zone-sets\":[]}";
|
|
||||||
File.WriteAllText(_zoneSettingsPath, zoneSettings);
|
|
||||||
}
|
|
||||||
|
|
||||||
private void OpenEditor()
|
private void OpenEditor()
|
||||||
{
|
{
|
||||||
new Actions(session).KeyDown(OpenQA.Selenium.Keys.Command).SendKeys("`").KeyUp(OpenQA.Selenium.Keys.Command).Perform();
|
new Actions(session).KeyDown(OpenQA.Selenium.Keys.Command).SendKeys("`").KeyUp(OpenQA.Selenium.Keys.Command).Perform();
|
||||||
@ -166,8 +149,7 @@ namespace PowerToysTests
|
|||||||
{
|
{
|
||||||
ExitPowerToys();
|
ExitPowerToys();
|
||||||
}
|
}
|
||||||
ResetDefaultFancyZonesSettings();
|
ResetDefaultFancyZonesSettings(true);
|
||||||
LaunchPowerToys();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
[ClassCleanup]
|
[ClassCleanup]
|
||||||
@ -205,8 +187,7 @@ namespace PowerToysTests
|
|||||||
//editor has already closed
|
//editor has already closed
|
||||||
}
|
}
|
||||||
|
|
||||||
ResetDefautZoneSettings();
|
ResetDefautZoneSettings(false);
|
||||||
ExitPowerToys();
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -227,5 +227,38 @@ namespace PowerToysTests
|
|||||||
trayButton.Click(); //close tray
|
trayButton.Click(); //close tray
|
||||||
isPowerToysLaunched = false;
|
isPowerToysLaunched = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static void ResetDefaultFancyZonesSettings(bool relaunch)
|
||||||
|
{
|
||||||
|
if (!Directory.Exists(_settingsFolderPath))
|
||||||
|
{
|
||||||
|
Directory.CreateDirectory(_settingsFolderPath);
|
||||||
|
}
|
||||||
|
|
||||||
|
string settings = "{\"version\":\"1.0\",\"name\":\"FancyZones\",\"properties\":{\"fancyzones_shiftDrag\":{\"value\":true},\"fancyzones_overrideSnapHotkeys\":{\"value\":false},\"fancyzones_zoneSetChange_flashZones\":{\"value\":false},\"fancyzones_displayChange_moveWindows\":{\"value\":false},\"fancyzones_zoneSetChange_moveWindows\":{\"value\":false},\"fancyzones_virtualDesktopChange_moveWindows\":{\"value\":false},\"fancyzones_appLastZone_moveWindows\":{\"value\":false},\"use_cursorpos_editor_startupscreen\":{\"value\":true},\"fancyzones_zoneHighlightColor\":{\"value\":\"#0078D7\"},\"fancyzones_highlight_opacity\":{\"value\":90},\"fancyzones_editor_hotkey\":{\"value\":{\"win\":true,\"ctrl\":false,\"alt\":false,\"shift\":false,\"code\":192,\"key\":\"`\"}},\"fancyzones_excluded_apps\":{\"value\":\"\"}}}";
|
||||||
|
File.WriteAllText(_settingsPath, settings);
|
||||||
|
|
||||||
|
if (isPowerToysLaunched)
|
||||||
|
{
|
||||||
|
ExitPowerToys();
|
||||||
|
}
|
||||||
|
|
||||||
|
if (relaunch)
|
||||||
|
{
|
||||||
|
LaunchPowerToys();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void ResetDefautZoneSettings(bool relaunch)
|
||||||
|
{
|
||||||
|
string zoneSettings = "{\"app-zone-history\":[],\"devices\":[],\"custom-zone-sets\":[]}";
|
||||||
|
File.WriteAllText(_zoneSettingsPath, zoneSettings);
|
||||||
|
|
||||||
|
ExitPowerToys();
|
||||||
|
if (relaunch)
|
||||||
|
{
|
||||||
|
LaunchPowerToys();
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
<?xml version="1.0" encoding="utf-8"?>
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
<Project ToolsVersion="15.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
|
<Project ToolsVersion="15.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
|
||||||
<Import Project="..\..\..\packages\MSTest.TestAdapter.2.1.0\build\net45\MSTest.TestAdapter.props" Condition="Exists('..\..\..\packages\MSTest.TestAdapter.2.1.0\build\net45\MSTest.TestAdapter.props')" />
|
<Import Project="..\..\..\packages\MSTest.TestAdapter.2.1.0\build\net45\MSTest.TestAdapter.props" Condition="Exists('..\..\..\packages\MSTest.TestAdapter.2.1.0\build\net45\MSTest.TestAdapter.props')" />
|
||||||
<Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')" />
|
<Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')" />
|
||||||
@ -88,6 +88,7 @@
|
|||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<Compile Include="FancyZonesTests\EditorOpeningTests.cs" />
|
<Compile Include="FancyZonesTests\EditorOpeningTests.cs" />
|
||||||
<Compile Include="FancyZonesTests\EditorSettingsTests.cs" />
|
<Compile Include="FancyZonesTests\EditorSettingsTests.cs" />
|
||||||
|
<Compile Include="FancyZonesTests\EditorTemplatesApplyTests.cs" />
|
||||||
<Compile Include="FancyZonesTests\EditorTemplatesEditTests.cs" />
|
<Compile Include="FancyZonesTests\EditorTemplatesEditTests.cs" />
|
||||||
<Compile Include="FancyZonesTests\FancyZonesSettingsTests.cs" />
|
<Compile Include="FancyZonesTests\FancyZonesSettingsTests.cs" />
|
||||||
<Compile Include="PowerToysSession.cs" />
|
<Compile Include="PowerToysSession.cs" />
|
||||||
|
Loading…
Reference in New Issue
Block a user