[Tests] More consistent naming (#40754)

- [x] **Tests:** Added/updated and all pass
- [x] **Dev docs:** Added/updated

<img width="460" height="1017" alt="image"
src="https://github.com/user-attachments/assets/e72bf221-0875-48c3-b790-4ab1182c7d3a"
/>

I haven't touched the Run module, since we may deprecate it.

Closes: #40788
This commit is contained in:
Gleb Khmyznikov
2025-07-24 17:53:22 +02:00
committed by GitHub
parent 25fc5a26ff
commit 474756036e
70 changed files with 294 additions and 351 deletions

View File

@@ -0,0 +1,305 @@
// Copyright (c) Microsoft Corporation
// The Microsoft Corporation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information.
using System.Collections.Generic;
using System.Globalization;
using FancyZonesEditor.Models;
using FancyZonesEditorCommon.Data;
using Microsoft.FancyZonesEditor.UnitTests.Utils;
using Microsoft.PowerToys.UITest;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using ModernWpf.Controls;
using OpenQA.Selenium;
using static Microsoft.FancyZonesEditor.UnitTests.Utils.FancyZonesEditorHelper;
namespace Microsoft.FancyZonesEditor.UITests
{
[TestClass]
public class ApplyLayoutTests : UITestBase
{
public ApplyLayoutTests()
: base(PowerToysModule.FancyZone, WindowSize.UnSpecified)
{
}
private static readonly EditorParameters.ParamsWrapper Parameters = new EditorParameters.ParamsWrapper
{
ProcessId = 1,
SpanZonesAcrossMonitors = false,
Monitors = new List<EditorParameters.NativeMonitorDataWrapper>
{
new EditorParameters.NativeMonitorDataWrapper
{
Monitor = "monitor-1",
MonitorInstanceId = "instance-id-1",
MonitorSerialNumber = "serial-number-1",
MonitorNumber = 1,
VirtualDesktop = "{FF34D993-73F3-4B8C-AA03-73730A01D6A8}",
Dpi = 96,
LeftCoordinate = 0,
TopCoordinate = 0,
WorkAreaHeight = 1040,
WorkAreaWidth = 1920,
MonitorHeight = 1080,
MonitorWidth = 1920,
IsSelected = true,
},
new EditorParameters.NativeMonitorDataWrapper
{
Monitor = "monitor-2",
MonitorInstanceId = "instance-id-2",
MonitorSerialNumber = "serial-number-2",
MonitorNumber = 2,
VirtualDesktop = "{FF34D993-73F3-4B8C-AA03-73730A01D6A8}",
Dpi = 96,
LeftCoordinate = 1920,
TopCoordinate = 0,
WorkAreaHeight = 1040,
WorkAreaWidth = 1920,
MonitorHeight = 1080,
MonitorWidth = 1920,
IsSelected = false,
},
},
};
private static readonly CustomLayouts.CustomLayoutListWrapper CustomLayoutsList = new CustomLayouts.CustomLayoutListWrapper
{
CustomLayouts = new List<CustomLayouts.CustomLayoutWrapper>
{
new CustomLayouts.CustomLayoutWrapper
{
Uuid = "{E7807D0D-6223-4883-B15B-1F3883944C09}",
Type = CustomLayout.Canvas.TypeToString(),
Name = "Custom layout",
Info = new CustomLayouts().ToJsonElement(new CustomLayouts.CanvasInfoWrapper
{
RefHeight = 952,
RefWidth = 1500,
SensitivityRadius = 10,
Zones = new List<CustomLayouts.CanvasInfoWrapper.CanvasZoneWrapper> { },
}),
},
},
};
private static readonly LayoutTemplates.TemplateLayoutsListWrapper TemplateLayoutsList = new LayoutTemplates.TemplateLayoutsListWrapper
{
LayoutTemplates = new List<LayoutTemplates.TemplateLayoutWrapper>
{
new LayoutTemplates.TemplateLayoutWrapper
{
Type = LayoutType.Blank.TypeToString(),
},
new LayoutTemplates.TemplateLayoutWrapper
{
Type = LayoutType.Focus.TypeToString(),
ZoneCount = 10,
},
new LayoutTemplates.TemplateLayoutWrapper
{
Type = LayoutType.Rows.TypeToString(),
ZoneCount = 2,
ShowSpacing = true,
Spacing = 10,
SensitivityRadius = 10,
},
new LayoutTemplates.TemplateLayoutWrapper
{
Type = LayoutType.Columns.TypeToString(),
ZoneCount = 2,
ShowSpacing = true,
Spacing = 20,
SensitivityRadius = 20,
},
new LayoutTemplates.TemplateLayoutWrapper
{
Type = LayoutType.Grid.TypeToString(),
ZoneCount = 4,
ShowSpacing = false,
Spacing = 10,
SensitivityRadius = 30,
},
new LayoutTemplates.TemplateLayoutWrapper
{
Type = LayoutType.PriorityGrid.TypeToString(),
ZoneCount = 3,
ShowSpacing = true,
Spacing = 1,
SensitivityRadius = 40,
},
},
};
[TestInitialize]
public void TestInitialize()
{
FancyZonesEditorHelper.Files.Restore();
EditorParameters editorParameters = new EditorParameters();
FancyZonesEditorHelper.Files.ParamsIOHelper.WriteData(editorParameters.Serialize(Parameters));
LayoutTemplates layoutTemplates = new LayoutTemplates();
FancyZonesEditorHelper.Files.LayoutTemplatesIOHelper.WriteData(layoutTemplates.Serialize(TemplateLayoutsList));
CustomLayouts customLayouts = new CustomLayouts();
FancyZonesEditorHelper.Files.CustomLayoutsIOHelper.WriteData(customLayouts.Serialize(CustomLayoutsList));
DefaultLayouts defaultLayouts = new DefaultLayouts();
DefaultLayouts.DefaultLayoutsListWrapper defaultLayoutsListWrapper = new DefaultLayouts.DefaultLayoutsListWrapper
{
DefaultLayouts = new List<DefaultLayouts.DefaultLayoutWrapper>
{
new DefaultLayouts.DefaultLayoutWrapper
{
MonitorConfiguration = MonitorConfigurationType.Horizontal.TypeToString(),
Layout = new DefaultLayouts.DefaultLayoutWrapper.LayoutWrapper
{
Type = LayoutType.Focus.TypeToString(),
ZoneCount = 4,
ShowSpacing = true,
Spacing = 5,
SensitivityRadius = 20,
},
},
new DefaultLayouts.DefaultLayoutWrapper
{
MonitorConfiguration = MonitorConfigurationType.Vertical.TypeToString(),
Layout = new DefaultLayouts.DefaultLayoutWrapper.LayoutWrapper
{
Type = LayoutType.Custom.TypeToString(),
Uuid = "{0D6D2F58-9184-4804-81E4-4E4CC3476DC1}",
ZoneCount = 0,
ShowSpacing = false,
Spacing = 0,
SensitivityRadius = 0,
},
},
},
};
FancyZonesEditorHelper.Files.DefaultLayoutsIOHelper.WriteData(defaultLayouts.Serialize(defaultLayoutsListWrapper));
LayoutHotkeys layoutHotkeys = new LayoutHotkeys();
LayoutHotkeys.LayoutHotkeysWrapper layoutHotkeysWrapper = new LayoutHotkeys.LayoutHotkeysWrapper
{
LayoutHotkeys = new List<LayoutHotkeys.LayoutHotkeyWrapper> { },
};
FancyZonesEditorHelper.Files.LayoutHotkeysIOHelper.WriteData(layoutHotkeys.Serialize(layoutHotkeysWrapper));
AppliedLayouts appliedLayouts = new AppliedLayouts();
AppliedLayouts.AppliedLayoutsListWrapper appliedLayoutsWrapper = new AppliedLayouts.AppliedLayoutsListWrapper
{
AppliedLayouts = new List<AppliedLayouts.AppliedLayoutWrapper> { },
};
FancyZonesEditorHelper.Files.AppliedLayoutsIOHelper.WriteData(appliedLayouts.Serialize(appliedLayoutsWrapper));
this.RestartScopeExe();
}
[TestMethod]
public void ApplyCustomLayout()
{
var layout = CustomLayoutsList.CustomLayouts[0];
Assert.IsFalse(Session.Find<Element>(layout.Name).Selected);
Session.Find<Element>(layout.Name).Click();
Assert.IsTrue(Session.Find<Element>(layout.Name).Selected);
AppliedLayouts appliedLayouts = new AppliedLayouts();
var data = appliedLayouts.Read(appliedLayouts.File);
Assert.AreEqual(Parameters.Monitors.Count, data.AppliedLayouts.Count);
Assert.AreEqual(layout.Uuid, data.AppliedLayouts[0].AppliedLayout.Uuid);
Assert.AreEqual(Parameters.Monitors[0].MonitorNumber, data.AppliedLayouts[0].Device.MonitorNumber);
}
[TestMethod]
public void ApplyTemplateLayout()
{
var layoutType = LayoutType.Columns;
var layout = TestConstants.TemplateLayoutNames[layoutType];
Assert.IsFalse(Session.Find<Element>(layout).Selected);
Session.Find<Element>(layout).Click();
Assert.IsTrue(Session.Find<Element>(layout).Selected);
AppliedLayouts appliedLayouts = new AppliedLayouts();
var data = appliedLayouts.Read(appliedLayouts.File);
Assert.AreEqual(Parameters.Monitors.Count, data.AppliedLayouts.Count);
Assert.AreEqual(layoutType.TypeToString(), data.AppliedLayouts[0].AppliedLayout.Type);
Assert.AreEqual(Parameters.Monitors[0].MonitorNumber, data.AppliedLayouts[0].Device.MonitorNumber);
}
[TestMethod("FancyZonesEditor.Basic.ApplyLayoutsOnEachMonitor")]
[TestCategory("FancyZones Editor #10")]
public void ApplyLayoutsOnEachMonitor()
{
// apply the layout on the first monitor
var firstLayoutType = LayoutType.Columns;
var firstLayoutName = TestConstants.TemplateLayoutNames[firstLayoutType];
Session.Find<Element>(firstLayoutName).Click();
Assert.IsTrue(Session.Find<Element>(firstLayoutName)!.Selected);
// apply the layout on the second monitor
Session.Find<Element>(PowerToys.UITest.By.AccessibilityId("Monitors")).Find<Element>("Monitor 2").Click();
var secondLayout = CustomLayoutsList.CustomLayouts[0];
Session.Find<Element>(secondLayout.Name).Click();
Assert.IsTrue(Session.Find<Element>(secondLayout.Name)!.Selected);
// verify the layout on the first monitor wasn't changed
Session.Find<Element>(PowerToys.UITest.By.AccessibilityId("Monitors")).Find<Element>("Monitor 1").Click();
Assert.IsTrue(Session.Find<Element>(firstLayoutName)!.Selected);
// verify the file
var appliedLayouts = new AppliedLayouts();
var data = appliedLayouts.Read(appliedLayouts.File);
Assert.AreEqual(Parameters.Monitors.Count, data.AppliedLayouts.Count);
Assert.AreEqual(firstLayoutType.TypeToString(), data.AppliedLayouts.Find(x => x.Device.MonitorNumber == 1).AppliedLayout.Type);
Assert.AreEqual(secondLayout.Uuid, data.AppliedLayouts.Find(x => x.Device.MonitorNumber == 2).AppliedLayout.Uuid);
}
[TestMethod("FancyZonesEditor.Basic.ApplyTemplateWithDifferentParametersOnEachMonitor")]
[TestCategory("FancyZones Editor #10")]
public void ApplyTemplateWithDifferentParametersOnEachMonitor()
{
var layoutType = LayoutType.Columns;
var layoutName = TestConstants.TemplateLayoutNames[layoutType];
// apply the layout on the first monitor, set parameters
Session.Find<Element>(layoutName).Click();
Session.Find<Element>(layoutName).Find<Button>(PowerToys.UITest.By.AccessibilityId(AccessibilityId.EditLayoutButton)).Click();
var slider = Session.Find<Custom>(PowerToys.UITest.By.AccessibilityId(AccessibilityId.TemplateZoneSlider));
Assert.IsNotNull(slider);
slider.SendKeys(Key.Right);
slider.SendKeys(Key.Right);
var expectedFirstLayoutZoneCount = int.Parse(slider.Text!, CultureInfo.InvariantCulture);
Session.Find<Button>(ElementName.Save).Click();
// apply the layout on the second monitor, set different parameters
Session.Find<Element>(PowerToys.UITest.By.AccessibilityId("Monitors")).Find<Element>("Monitor 2").Click();
Session.Find<Element>(layoutName).Click();
Session.Find<Element>(layoutName).Find<Button>(PowerToys.UITest.By.AccessibilityId(AccessibilityId.EditLayoutButton)).Click();
slider = Session.Find<Custom>(PowerToys.UITest.By.AccessibilityId(AccessibilityId.TemplateZoneSlider));
Assert.IsNotNull(slider);
slider.SendKeys(Key.Left);
var expectedSecondLayoutZoneCount = int.Parse(slider.Text!, CultureInfo.InvariantCulture);
Session.Find<Button>(ElementName.Save).Click();
// verify the layout on the first monitor wasn't changed
Session.Find<Element>(PowerToys.UITest.By.AccessibilityId("Monitors")).Find<Element>("Monitor 1").Click();
Session.Find<Element>(layoutName).Find<Button>(PowerToys.UITest.By.AccessibilityId(AccessibilityId.EditLayoutButton)).Click();
slider = Session.Find<Custom>(PowerToys.UITest.By.AccessibilityId(AccessibilityId.TemplateZoneSlider));
Assert.IsNotNull(slider);
Assert.AreEqual(expectedFirstLayoutZoneCount, int.Parse(slider.Text!, CultureInfo.InvariantCulture));
Session.Find<Button>(ElementName.Cancel).Click();
// check the file
var appliedLayouts = new AppliedLayouts();
var data = appliedLayouts.Read(appliedLayouts.File);
Assert.AreEqual(Parameters.Monitors.Count, data.AppliedLayouts.Count);
Assert.AreEqual(layoutType.TypeToString(), data.AppliedLayouts.Find(x => x.Device.MonitorNumber == 1).AppliedLayout.Type);
Assert.AreEqual(expectedFirstLayoutZoneCount, data.AppliedLayouts.Find(x => x.Device.MonitorNumber == 1).AppliedLayout.ZoneCount);
Assert.AreEqual(layoutType.TypeToString(), data.AppliedLayouts.Find(x => x.Device.MonitorNumber == 2).AppliedLayout.Type);
Assert.AreEqual(expectedSecondLayoutZoneCount, data.AppliedLayouts.Find(x => x.Device.MonitorNumber == 2).AppliedLayout.ZoneCount);
}
}
}

View File

@@ -0,0 +1,359 @@
// Copyright (c) Microsoft Corporation
// The Microsoft Corporation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information.
using System.Collections.Generic;
using FancyZonesEditor.Models;
using FancyZonesEditorCommon.Data;
using Microsoft.FancyZonesEditor.UnitTests.Utils;
using Microsoft.PowerToys.UITest;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using static FancyZonesEditorCommon.Data.EditorParameters;
using static Microsoft.FancyZonesEditor.UnitTests.Utils.FancyZonesEditorHelper;
namespace Microsoft.FancyZonesEditor.UITests
{
[TestClass]
public class CopyLayoutTests : UITestBase
{
public CopyLayoutTests()
: base(PowerToysModule.FancyZone, WindowSize.UnSpecified)
{
}
private static readonly CustomLayouts.CustomLayoutListWrapper CustomLayouts = new CustomLayouts.CustomLayoutListWrapper
{
CustomLayouts = new List<CustomLayouts.CustomLayoutWrapper>
{
new CustomLayouts.CustomLayoutWrapper
{
Uuid = "{0D6D2F58-9184-4804-81E4-4E4CC3476DC1}",
Type = CustomLayout.Grid.TypeToString(),
Name = "Grid custom layout",
Info = new CustomLayouts().ToJsonElement(new CustomLayouts.GridInfoWrapper
{
Rows = 2,
Columns = 3,
RowsPercentage = new List<int> { 2967, 7033 },
ColumnsPercentage = new List<int> { 2410, 6040, 1550 },
CellChildMap = new int[][] { [0, 1, 1], [0, 2, 3] },
SensitivityRadius = 30,
Spacing = 26,
ShowSpacing = false,
}),
},
},
};
private static readonly LayoutHotkeys.LayoutHotkeysWrapper Hotkeys = new LayoutHotkeys.LayoutHotkeysWrapper
{
LayoutHotkeys = new List<LayoutHotkeys.LayoutHotkeyWrapper>
{
new LayoutHotkeys.LayoutHotkeyWrapper
{
LayoutId = CustomLayouts.CustomLayouts[0].Uuid,
Key = 0,
},
},
};
private static readonly DefaultLayouts.DefaultLayoutsListWrapper DefaultLayouts = new DefaultLayouts.DefaultLayoutsListWrapper
{
DefaultLayouts = new List<DefaultLayouts.DefaultLayoutWrapper>
{
new DefaultLayouts.DefaultLayoutWrapper
{
MonitorConfiguration = MonitorConfigurationType.Vertical.TypeToString(),
Layout = new DefaultLayouts.DefaultLayoutWrapper.LayoutWrapper
{
Type = "custom",
Uuid = CustomLayouts.CustomLayouts[0].Uuid,
},
},
},
};
[TestInitialize]
public void TestInitialize()
{
FancyZonesEditorHelper.Files.Restore();
EditorParameters editorParameters = new EditorParameters();
ParamsWrapper parameters = new ParamsWrapper
{
ProcessId = 1,
SpanZonesAcrossMonitors = false,
Monitors = new List<NativeMonitorDataWrapper>
{
new NativeMonitorDataWrapper
{
Monitor = "monitor-1",
MonitorInstanceId = "instance-id-1",
MonitorSerialNumber = "serial-number-1",
MonitorNumber = 1,
VirtualDesktop = "{FF34D993-73F3-4B8C-AA03-73730A01D6A8}",
Dpi = 192,
LeftCoordinate = 0,
TopCoordinate = 0,
WorkAreaHeight = 1040,
WorkAreaWidth = 1920,
MonitorHeight = 1080,
MonitorWidth = 1920,
IsSelected = true,
},
},
};
FancyZonesEditorHelper.Files.ParamsIOHelper.WriteData(editorParameters.Serialize(parameters));
CustomLayouts customLayouts = new CustomLayouts();
FancyZonesEditorHelper.Files.CustomLayoutsIOHelper.WriteData(customLayouts.Serialize(CustomLayouts));
LayoutTemplates layoutTemplates = new LayoutTemplates();
LayoutTemplates.TemplateLayoutsListWrapper templateLayoutsListWrapper = new LayoutTemplates.TemplateLayoutsListWrapper
{
LayoutTemplates = new List<LayoutTemplates.TemplateLayoutWrapper>
{
new LayoutTemplates.TemplateLayoutWrapper
{
Type = LayoutType.Blank.TypeToString(),
},
new LayoutTemplates.TemplateLayoutWrapper
{
Type = LayoutType.Focus.TypeToString(),
ZoneCount = 10,
},
new LayoutTemplates.TemplateLayoutWrapper
{
Type = LayoutType.Rows.TypeToString(),
ZoneCount = 2,
ShowSpacing = true,
Spacing = 10,
SensitivityRadius = 10,
},
new LayoutTemplates.TemplateLayoutWrapper
{
Type = LayoutType.Columns.TypeToString(),
ZoneCount = 2,
ShowSpacing = true,
Spacing = 20,
SensitivityRadius = 20,
},
new LayoutTemplates.TemplateLayoutWrapper
{
Type = LayoutType.Grid.TypeToString(),
ZoneCount = 4,
ShowSpacing = false,
Spacing = 10,
SensitivityRadius = 30,
},
new LayoutTemplates.TemplateLayoutWrapper
{
Type = LayoutType.PriorityGrid.TypeToString(),
ZoneCount = 3,
ShowSpacing = true,
Spacing = 1,
SensitivityRadius = 40,
},
},
};
FancyZonesEditorHelper.Files.LayoutTemplatesIOHelper.WriteData(layoutTemplates.Serialize(templateLayoutsListWrapper));
DefaultLayouts defaultLayouts = new DefaultLayouts();
FancyZonesEditorHelper.Files.DefaultLayoutsIOHelper.WriteData(defaultLayouts.Serialize(DefaultLayouts));
LayoutHotkeys layoutHotkeys = new LayoutHotkeys();
FancyZonesEditorHelper.Files.LayoutHotkeysIOHelper.WriteData(layoutHotkeys.Serialize(Hotkeys));
AppliedLayouts appliedLayouts = new AppliedLayouts();
AppliedLayouts.AppliedLayoutsListWrapper appliedLayoutsWrapper = new AppliedLayouts.AppliedLayoutsListWrapper
{
AppliedLayouts = new List<AppliedLayouts.AppliedLayoutWrapper> { },
};
FancyZonesEditorHelper.Files.AppliedLayoutsIOHelper.WriteData(appliedLayouts.Serialize(appliedLayoutsWrapper));
this.RestartScopeExe();
}
[TestMethod("FancyZonesEditor.Basic.CopyTemplate_FromEditLayoutWindow")]
[TestCategory("FancyZones Editor #4")]
public void CopyTemplate_FromEditLayoutWindow()
{
string copiedLayoutName = TestConstants.TemplateLayoutNames[LayoutType.Focus] + " (1)";
Session.Find<Element>(TestConstants.TemplateLayoutNames[LayoutType.Focus]).Find<Button>(By.AccessibilityId(AccessibilityId.EditLayoutButton)).Click();
ClickCopyLayout();
// verify the layout is copied
Assert.IsNotNull(Session.Find<Element>(copiedLayoutName)); // new name is presented
// verify the file
var customLayouts = new CustomLayouts();
var data = customLayouts.Read(customLayouts.File);
Assert.AreEqual(CustomLayouts.CustomLayouts.Count + 1, data.CustomLayouts.Count);
Assert.IsTrue(data.CustomLayouts.Exists(x => x.Name == copiedLayoutName));
}
[TestMethod("FancyZonesEditor.Basic.CopyTemplate_FromEditLayoutWindow")]
[TestCategory("FancyZones Editor #4")]
public void CopyTemplate_FromContextMenu()
{
string copiedLayoutName = TestConstants.TemplateLayoutNames[LayoutType.Rows] + " (1)";
FancyZonesEditorHelper.ClickContextMenuItem(Session, TestConstants.TemplateLayoutNames[LayoutType.Rows], ElementName.CreateCustomLayout);
// verify the layout is copied
Assert.IsNotNull(Session.Find<Element>(copiedLayoutName)); // new name is presented
// verify the file
var customLayouts = new CustomLayouts();
var data = customLayouts.Read(customLayouts.File);
Assert.AreEqual(CustomLayouts.CustomLayouts.Count + 1, data.CustomLayouts.Count);
Assert.IsTrue(data.CustomLayouts.Exists(x => x.Name == copiedLayoutName));
}
[TestMethod("FancyZonesEditor.Basic.CopyTemplate_DefaultLayout")]
[TestCategory("FancyZones Editor #13")]
public void CopyTemplate_DefaultLayout()
{
string copiedLayoutName = TestConstants.TemplateLayoutNames[LayoutType.PriorityGrid] + " (1)";
Session.Find<Element>(TestConstants.TemplateLayoutNames[LayoutType.PriorityGrid]).Find<Button>(By.AccessibilityId(AccessibilityId.EditLayoutButton)).Click();
ClickCopyLayout();
// verify the layout is copied
Assert.IsNotNull(Session.Find<Element>(copiedLayoutName)); // new name is presented
// verify the file
var customLayouts = new CustomLayouts();
var data = customLayouts.Read(customLayouts.File);
Assert.AreEqual(CustomLayouts.CustomLayouts.Count + 1, data.CustomLayouts.Count);
// verify the default layout wasn't changed
Session.Find<Element>(TestConstants.TemplateLayoutNames[LayoutType.PriorityGrid]).Find<Button>(By.AccessibilityId(AccessibilityId.EditLayoutButton)).Click();
var horizontalDefaultButton = Session.Find<Button>(By.AccessibilityId(AccessibilityId.HorizontalDefaultButtonChecked));
Assert.IsNotNull(horizontalDefaultButton);
Session.Find<Button>(ElementName.Cancel).Click();
Session.Find<Element>(copiedLayoutName).Find<Button>(By.AccessibilityId(AccessibilityId.EditLayoutButton)).Click();
horizontalDefaultButton = Session.Find<Button>(By.AccessibilityId(AccessibilityId.HorizontalDefaultButtonUnchecked));
Assert.IsNotNull(horizontalDefaultButton);
Session.Find<Button>(ElementName.Cancel).Click();
// verify the default layouts file wasn't changed
var defaultLayouts = new DefaultLayouts();
var defaultLayoutData = defaultLayouts.Read(defaultLayouts.File);
Assert.AreEqual(defaultLayouts.Serialize(DefaultLayouts), defaultLayouts.Serialize(defaultLayoutData));
}
[TestMethod("FancyZonesEditor.Basic.CopyCustomLayout_FromEditLayoutWindow")]
[TestCategory("FancyZones Editor #4")]
public void CopyCustomLayout_FromEditLayoutWindow()
{
string copiedLayoutName = CustomLayouts.CustomLayouts[0].Name + " (1)";
Session.Find<Element>(CustomLayouts.CustomLayouts[0].Name).Find<Button>(By.AccessibilityId(AccessibilityId.EditLayoutButton)).Click();
ClickCopyLayout();
// verify the layout is copied
Assert.IsNotNull(Session.Find<Element>(copiedLayoutName)); // new name is presented
// verify the file
var customLayouts = new CustomLayouts();
var data = customLayouts.Read(customLayouts.File);
Assert.AreEqual(CustomLayouts.CustomLayouts.Count + 1, data.CustomLayouts.Count);
Assert.IsTrue(data.CustomLayouts.Exists(x => x.Name == copiedLayoutName));
}
[TestMethod("FancyZonesEditor.Basic.CopyCustomLayout_FromContextMenu")]
[TestCategory("FancyZones Editor #4")]
public void CopyCustomLayout_FromContextMenu()
{
string copiedLayoutName = CustomLayouts.CustomLayouts[0].Name + " (1)";
FancyZonesEditorHelper.ClickContextMenuItem(Session, CustomLayouts.CustomLayouts[0].Name, ElementName.Duplicate);
// verify the layout is copied
Assert.IsNotNull(Session.Find<Element>(copiedLayoutName)); // new name is presented
// verify the file
var customLayouts = new CustomLayouts();
var data = customLayouts.Read(customLayouts.File);
Assert.AreEqual(CustomLayouts.CustomLayouts.Count + 1, data.CustomLayouts.Count);
Assert.IsTrue(data.CustomLayouts.Exists(x => x.Name == copiedLayoutName));
}
[TestMethod("FancyZonesEditor.Basic.CopyCustomLayout_DefaultLayout")]
[TestCategory("FancyZones Editor #13")]
public void CopyCustomLayout_DefaultLayout()
{
string copiedLayoutName = CustomLayouts.CustomLayouts[0].Name + " (1)";
Session.Find<Element>(CustomLayouts.CustomLayouts[0].Name).Find<Button>(By.AccessibilityId(AccessibilityId.EditLayoutButton)).Click();
ClickCopyLayout();
// verify the layout is copied
Assert.IsNotNull(Session.Find<Element>(copiedLayoutName)); // new name is presented
// verify the file
var customLayouts = new CustomLayouts();
var data = customLayouts.Read(customLayouts.File);
Assert.AreEqual(CustomLayouts.CustomLayouts.Count + 1, data.CustomLayouts.Count);
// verify the default layout wasn't changed
Session.Find<Element>(CustomLayouts.CustomLayouts[0].Name).Find<Button>(By.AccessibilityId(AccessibilityId.EditLayoutButton)).Click();
var verticalDefaultButton = Session.Find<Button>(By.AccessibilityId(AccessibilityId.VerticalDefaultButtonChecked));
Assert.IsNotNull(verticalDefaultButton);
Session.Find<Button>(ElementName.Cancel).Click();
Session.Find<Element>(copiedLayoutName).Find<Button>(By.AccessibilityId(AccessibilityId.EditLayoutButton)).Click();
verticalDefaultButton = Session.Find<Button>(By.AccessibilityId(AccessibilityId.VerticalDefaultButtonUnchecked));
Assert.IsNotNull(verticalDefaultButton);
Session.Find<Button>(ElementName.Cancel).Click();
// verify the default layouts file wasn't changed
var defaultLayouts = new DefaultLayouts();
var defaultLayoutData = defaultLayouts.Read(defaultLayouts.File);
Assert.AreEqual(defaultLayouts.Serialize(DefaultLayouts), defaultLayouts.Serialize(defaultLayoutData));
}
[TestMethod("FancyZonesEditor.Basic.CopyCustomLayout_Hotkey")]
[TestCategory("FancyZones Editor #4")]
public void CopyCustomLayout_Hotkey()
{
string copiedLayoutName = CustomLayouts.CustomLayouts[0].Name + " (1)";
Session.Find<Element>(CustomLayouts.CustomLayouts[0].Name).Find<Button>(By.AccessibilityId(AccessibilityId.EditLayoutButton)).Click();
ClickCopyLayout();
// verify the layout is copied
Assert.IsNotNull(Session.Find<Element>(copiedLayoutName)); // new name is presented
// verify the file
var customLayouts = new CustomLayouts();
var data = customLayouts.Read(customLayouts.File);
Assert.AreEqual(CustomLayouts.CustomLayouts.Count + 1, data.CustomLayouts.Count);
// verify the hotkey wasn't changed
Session.Find<Element>(CustomLayouts.CustomLayouts[0].Name).Find<Button>(By.AccessibilityId(AccessibilityId.EditLayoutButton)).Click();
var hotkeyComboBox = Session.Find<Element>(By.AccessibilityId(AccessibilityId.HotkeyComboBox));
Assert.IsNotNull(hotkeyComboBox);
Assert.AreEqual("0", hotkeyComboBox.Text);
Session.Find<Button>(ElementName.Cancel).Click();
Session.Find<Element>(copiedLayoutName).Find<Button>(By.AccessibilityId(AccessibilityId.EditLayoutButton)).Click();
hotkeyComboBox = Session.Find<Element>(By.AccessibilityId(AccessibilityId.HotkeyComboBox));
Assert.IsNotNull(hotkeyComboBox);
Assert.AreEqual("None", hotkeyComboBox.Text);
Session.Find<Button>(ElementName.Cancel).Click();
// verify the hotkey file wasn't changed
var hotkeys = new LayoutHotkeys();
var hotkeyData = hotkeys.Read(hotkeys.File);
Assert.AreEqual(hotkeys.Serialize(Hotkeys), hotkeys.Serialize(hotkeyData));
}
public void ClickCopyLayout()
{
if (Session.FindAll<Element>(By.AccessibilityId(AccessibilityId.CopyTemplate)).Count != 0)
{
Session.Find<Element>(By.AccessibilityId(AccessibilityId.CopyTemplate)).Click();
}
else
{
Session.Find<Element>(By.AccessibilityId(AccessibilityId.DuplicateLayoutButton)).Click();
}
}
}
}

View File

@@ -0,0 +1,241 @@
// Copyright (c) Microsoft Corporation
// The Microsoft Corporation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information.
using System.Collections.Generic;
using FancyZonesEditor.Models;
using FancyZonesEditorCommon.Data;
using Microsoft.FancyZonesEditor.UnitTests.Utils;
using Microsoft.PowerToys.UITest;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using static Microsoft.FancyZonesEditor.UnitTests.Utils.FancyZonesEditorHelper;
namespace Microsoft.FancyZonesEditor.UITests
{
[TestClass]
public class CreateLayoutTests : UITestBase
{
public CreateLayoutTests()
: base(PowerToysModule.FancyZone, WindowSize.UnSpecified)
{
}
[TestInitialize]
public void TestInitialize()
{
FancyZonesEditorHelper.Files.Restore();
// prepare test editor parameters with 2 monitors before launching the editor
EditorParameters editorParameters = new EditorParameters();
EditorParameters.ParamsWrapper parameters = new EditorParameters.ParamsWrapper
{
ProcessId = 1,
SpanZonesAcrossMonitors = false,
Monitors = new List<EditorParameters.NativeMonitorDataWrapper>
{
new EditorParameters.NativeMonitorDataWrapper
{
Monitor = "monitor-1",
MonitorInstanceId = "instance-id-1",
MonitorSerialNumber = "serial-number-1",
MonitorNumber = 1,
VirtualDesktop = "{FF34D993-73F3-4B8C-AA03-73730A01D6A8}",
Dpi = 96,
LeftCoordinate = 0,
TopCoordinate = 0,
WorkAreaHeight = 1040,
WorkAreaWidth = 1920,
MonitorHeight = 1080,
MonitorWidth = 1920,
IsSelected = true,
},
},
};
FancyZonesEditorHelper.Files.ParamsIOHelper.WriteData(editorParameters.Serialize(parameters));
LayoutTemplates layoutTemplates = new LayoutTemplates();
LayoutTemplates.TemplateLayoutsListWrapper templateLayoutsListWrapper = new LayoutTemplates.TemplateLayoutsListWrapper
{
LayoutTemplates = new List<LayoutTemplates.TemplateLayoutWrapper>
{
new LayoutTemplates.TemplateLayoutWrapper
{
Type = LayoutType.Blank.TypeToString(),
},
new LayoutTemplates.TemplateLayoutWrapper
{
Type = LayoutType.Focus.TypeToString(),
ZoneCount = 10,
},
new LayoutTemplates.TemplateLayoutWrapper
{
Type = LayoutType.Rows.TypeToString(),
ZoneCount = 2,
ShowSpacing = true,
Spacing = 10,
SensitivityRadius = 10,
},
new LayoutTemplates.TemplateLayoutWrapper
{
Type = LayoutType.Columns.TypeToString(),
ZoneCount = 2,
ShowSpacing = true,
Spacing = 20,
SensitivityRadius = 20,
},
new LayoutTemplates.TemplateLayoutWrapper
{
Type = LayoutType.Grid.TypeToString(),
ZoneCount = 4,
ShowSpacing = false,
Spacing = 10,
SensitivityRadius = 30,
},
new LayoutTemplates.TemplateLayoutWrapper
{
Type = LayoutType.PriorityGrid.TypeToString(),
ZoneCount = 3,
ShowSpacing = true,
Spacing = 1,
SensitivityRadius = 40,
},
},
};
FancyZonesEditorHelper.Files.LayoutTemplatesIOHelper.WriteData(layoutTemplates.Serialize(templateLayoutsListWrapper));
CustomLayouts customLayouts = new CustomLayouts();
CustomLayouts.CustomLayoutListWrapper customLayoutListWrapper = new CustomLayouts.CustomLayoutListWrapper
{
CustomLayouts = new List<CustomLayouts.CustomLayoutWrapper> { },
};
FancyZonesEditorHelper.Files.CustomLayoutsIOHelper.WriteData(customLayouts.Serialize(customLayoutListWrapper));
DefaultLayouts defaultLayouts = new DefaultLayouts();
DefaultLayouts.DefaultLayoutsListWrapper defaultLayoutsListWrapper = new DefaultLayouts.DefaultLayoutsListWrapper
{
DefaultLayouts = new List<DefaultLayouts.DefaultLayoutWrapper> { },
};
FancyZonesEditorHelper.Files.DefaultLayoutsIOHelper.WriteData(defaultLayouts.Serialize(defaultLayoutsListWrapper));
LayoutHotkeys layoutHotkeys = new LayoutHotkeys();
LayoutHotkeys.LayoutHotkeysWrapper layoutHotkeysWrapper = new LayoutHotkeys.LayoutHotkeysWrapper
{
LayoutHotkeys = new List<LayoutHotkeys.LayoutHotkeyWrapper> { },
};
FancyZonesEditorHelper.Files.LayoutHotkeysIOHelper.WriteData(layoutHotkeys.Serialize(layoutHotkeysWrapper));
AppliedLayouts appliedLayouts = new AppliedLayouts();
AppliedLayouts.AppliedLayoutsListWrapper appliedLayoutsWrapper = new AppliedLayouts.AppliedLayoutsListWrapper
{
AppliedLayouts = new List<AppliedLayouts.AppliedLayoutWrapper> { },
};
FancyZonesEditorHelper.Files.AppliedLayoutsIOHelper.WriteData(appliedLayouts.Serialize(appliedLayoutsWrapper));
this.RestartScopeExe();
}
[TestMethod]
public void CreateWithDefaultName()
{
string name = "Custom layout 1";
Session.Find<Element>(By.AccessibilityId(AccessibilityId.NewLayoutButton)).Click();
Session.Find<Element>(By.AccessibilityId(AccessibilityId.PrimaryButton)).Click();
Session.Find<Button>(ElementName.Save).Click();
// verify new layout presented
Assert.IsNotNull(Session.Find<Element>(name));
// check the file
var customLayouts = new CustomLayouts();
var data = customLayouts.Read(customLayouts.File);
Assert.AreEqual(1, data.CustomLayouts.Count);
Assert.IsTrue(data.CustomLayouts.Exists(x => x.Name == name));
}
[TestMethod("FancyZonesEditor.Basic.CreateWithCustomName")]
[TestCategory("FancyZones Editor #3")]
public void CreateWithCustomName()
{
string name = "Layout Name";
Session.Find<Element>(By.AccessibilityId(AccessibilityId.NewLayoutButton)).Click();
var input = Session.Find<TextBox>(By.ClassName(ClassName.TextBox));
Assert.IsNotNull(input);
input.SetText(name, true);
Session.Find<Element>(By.AccessibilityId(AccessibilityId.PrimaryButton)).Click();
Session.Find<Button>(ElementName.Save).Click();
// verify new layout presented
Assert.IsNotNull(Session.Find<Element>(name));
// check the file
var customLayouts = new CustomLayouts();
var data = customLayouts.Read(customLayouts.File);
Assert.AreEqual(1, data.CustomLayouts.Count);
Assert.IsTrue(data.CustomLayouts.Exists(x => x.Name == name));
}
[TestMethod("FancyZonesEditor.Basic.CreateGrid")]
[TestCategory("FancyZones Editor #3")]
public void CreateGrid()
{
CustomLayout type = CustomLayout.Grid;
Session.Find<Element>(By.AccessibilityId(AccessibilityId.NewLayoutButton)).Click();
Session.Find<Element>(By.AccessibilityId(AccessibilityId.GridRadioButton)).Click();
Session.Find<Element>(By.AccessibilityId(AccessibilityId.PrimaryButton)).Click();
Session.Find<Button>(ElementName.Save).Click();
// check the file
var customLayouts = new CustomLayouts();
var data = customLayouts.Read(customLayouts.File);
Assert.AreEqual(1, data.CustomLayouts.Count);
Assert.IsTrue(data.CustomLayouts.Exists(x => x.Type == type.TypeToString()));
}
[TestMethod("FancyZonesEditor.Basic.CreateCanvas")]
[TestCategory("FancyZones Editor #3")]
public void CreateCanvas()
{
CustomLayout type = CustomLayout.Canvas;
Session.Find<Element>(By.AccessibilityId(AccessibilityId.NewLayoutButton)).Click();
Session.Find<Element>(By.AccessibilityId(AccessibilityId.CanvasRadioButton)).Click();
Session.Find<Element>(By.AccessibilityId(AccessibilityId.PrimaryButton)).Click();
Session.Find<Button>(ElementName.Save).Click();
// check the file
var customLayouts = new CustomLayouts();
var data = customLayouts.Read(customLayouts.File);
Assert.AreEqual(1, data.CustomLayouts.Count);
Assert.IsTrue(data.CustomLayouts.Exists(x => x.Type == type.TypeToString()));
}
[TestMethod("FancyZonesEditor.Basic.CancelGridCreation")]
[TestCategory("FancyZones Editor #3")]
public void CancelGridCreation()
{
Session.Find<Element>(By.AccessibilityId(AccessibilityId.NewLayoutButton)).Click();
Session.Find<Element>(By.AccessibilityId(AccessibilityId.GridRadioButton)).Click();
Session.Find<Element>(By.AccessibilityId(AccessibilityId.PrimaryButton)).Click();
Session.Find<Button>(ElementName.Cancel).Click();
// check the file
var customLayouts = new CustomLayouts();
var data = customLayouts.Read(customLayouts.File);
Assert.AreEqual(0, data.CustomLayouts.Count);
}
[TestMethod("FancyZonesEditor.Basic.CancelCanvasCreation")]
[TestCategory("FancyZones Editor #3")]
public void CancelCanvasCreation()
{
Session.Find<Element>(By.AccessibilityId(AccessibilityId.NewLayoutButton)).Click();
Session.Find<Element>(By.AccessibilityId(AccessibilityId.CanvasRadioButton)).Click();
Session.Find<Element>(By.AccessibilityId(AccessibilityId.PrimaryButton)).Click();
Session.Find<Button>(ElementName.Cancel).Click();
// check the file
var customLayouts = new CustomLayouts();
var data = customLayouts.Read(customLayouts.File);
Assert.AreEqual(0, data.CustomLayouts.Count);
}
}
}

View File

@@ -0,0 +1,452 @@
// Copyright (c) Microsoft Corporation
// The Microsoft Corporation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information.
using System;
using System.Collections.Generic;
using FancyZonesEditor.Models;
using FancyZonesEditorCommon.Data;
using Microsoft.FancyZonesEditor.UnitTests.Utils;
using Microsoft.PowerToys.UITest;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using OpenQA.Selenium;
using static FancyZonesEditorCommon.Data.CustomLayouts;
using static FancyZonesEditorCommon.Data.EditorParameters;
using static Microsoft.FancyZonesEditor.UnitTests.Utils.FancyZonesEditorHelper;
namespace Microsoft.FancyZonesEditor.UITests
{
[TestClass]
public class CustomLayoutsTests : UITestBase
{
public CustomLayoutsTests()
: base(PowerToysModule.FancyZone, WindowSize.UnSpecified)
{
}
private static readonly CustomLayoutListWrapper Layouts = new CustomLayoutListWrapper
{
CustomLayouts = new List<CustomLayoutWrapper>
{
new CustomLayoutWrapper
{
Uuid = "{0D6D2F58-9184-4804-81E4-4E4CC3476DC1}",
Type = CustomLayout.Grid.TypeToString(),
Name = "Grid custom layout",
Info = new CustomLayouts().ToJsonElement(new GridInfoWrapper
{
Rows = 2,
Columns = 3,
RowsPercentage = new List<int> { 2967, 7033 },
ColumnsPercentage = new List<int> { 2410, 6040, 1550 },
CellChildMap = new int[][] { [0, 1, 1], [0, 2, 3] },
SensitivityRadius = 30,
Spacing = 26,
ShowSpacing = false,
}),
},
new CustomLayoutWrapper
{
Uuid = "{E7807D0D-6223-4883-B15B-1F3883944C09}",
Type = CustomLayout.Canvas.TypeToString(),
Name = "Canvas custom layout",
Info = new CustomLayouts().ToJsonElement(new CanvasInfoWrapper
{
RefHeight = 952,
RefWidth = 1500,
SensitivityRadius = 10,
Zones = new List<CanvasInfoWrapper.CanvasZoneWrapper>
{
new CanvasInfoWrapper.CanvasZoneWrapper
{
X = 0,
Y = 0,
Width = 900,
Height = 522,
},
new CanvasInfoWrapper.CanvasZoneWrapper
{
X = 900,
Y = 0,
Width = 600,
Height = 750,
},
new CanvasInfoWrapper.CanvasZoneWrapper
{
X = 0,
Y = 522,
Width = 1500,
Height = 430,
},
},
}),
},
new CustomLayoutWrapper
{
Uuid = "{F1A94F38-82B6-4876-A653-70D0E882DE2A}",
Type = CustomLayout.Grid.TypeToString(),
Name = "Grid custom layout spacing enabled",
Info = new CustomLayouts().ToJsonElement(new GridInfoWrapper
{
Rows = 2,
Columns = 3,
RowsPercentage = new List<int> { 2967, 7033 },
ColumnsPercentage = new List<int> { 2410, 6040, 1550 },
CellChildMap = new int[][] { [0, 1, 1], [0, 2, 3] },
SensitivityRadius = 30,
Spacing = 10,
ShowSpacing = true,
}),
},
},
};
[TestInitialize]
public void TestInitialize()
{
FancyZonesEditorHelper.Files.Restore();
CustomLayouts customLayouts = new CustomLayouts();
FancyZonesEditorHelper.Files.CustomLayoutsIOHelper.WriteData(customLayouts.Serialize(Layouts));
EditorParameters editorParameters = new EditorParameters();
ParamsWrapper parameters = new ParamsWrapper
{
ProcessId = 1,
SpanZonesAcrossMonitors = false,
Monitors = new List<NativeMonitorDataWrapper>
{
new NativeMonitorDataWrapper
{
Monitor = "monitor-1",
MonitorInstanceId = "instance-id-1",
MonitorSerialNumber = "serial-number-1",
MonitorNumber = 1,
VirtualDesktop = "{FF34D993-73F3-4B8C-AA03-73730A01D6A8}",
Dpi = 192,
LeftCoordinate = 0,
TopCoordinate = 0,
WorkAreaHeight = 1040,
WorkAreaWidth = 1920,
MonitorHeight = 1080,
MonitorWidth = 1920,
IsSelected = true,
},
},
};
FancyZonesEditorHelper.Files.ParamsIOHelper.WriteData(editorParameters.Serialize(parameters));
LayoutTemplates layoutTemplates = new LayoutTemplates();
LayoutTemplates.TemplateLayoutsListWrapper templateLayoutsListWrapper = new LayoutTemplates.TemplateLayoutsListWrapper
{
LayoutTemplates = new List<LayoutTemplates.TemplateLayoutWrapper>
{
new LayoutTemplates.TemplateLayoutWrapper
{
Type = LayoutType.Blank.TypeToString(),
},
new LayoutTemplates.TemplateLayoutWrapper
{
Type = LayoutType.Focus.TypeToString(),
ZoneCount = 10,
},
new LayoutTemplates.TemplateLayoutWrapper
{
Type = LayoutType.Rows.TypeToString(),
ZoneCount = 2,
ShowSpacing = true,
Spacing = 10,
SensitivityRadius = 10,
},
new LayoutTemplates.TemplateLayoutWrapper
{
Type = LayoutType.Columns.TypeToString(),
ZoneCount = 2,
ShowSpacing = true,
Spacing = 20,
SensitivityRadius = 20,
},
new LayoutTemplates.TemplateLayoutWrapper
{
Type = LayoutType.Grid.TypeToString(),
ZoneCount = 4,
ShowSpacing = false,
Spacing = 10,
SensitivityRadius = 30,
},
new LayoutTemplates.TemplateLayoutWrapper
{
Type = LayoutType.PriorityGrid.TypeToString(),
ZoneCount = 3,
ShowSpacing = true,
Spacing = 1,
SensitivityRadius = 40,
},
},
};
FancyZonesEditorHelper.Files.LayoutTemplatesIOHelper.WriteData(layoutTemplates.Serialize(templateLayoutsListWrapper));
DefaultLayouts defaultLayouts = new DefaultLayouts();
DefaultLayouts.DefaultLayoutsListWrapper defaultLayoutsListWrapper = new DefaultLayouts.DefaultLayoutsListWrapper
{
DefaultLayouts = new List<DefaultLayouts.DefaultLayoutWrapper> { },
};
FancyZonesEditorHelper.Files.DefaultLayoutsIOHelper.WriteData(defaultLayouts.Serialize(defaultLayoutsListWrapper));
LayoutHotkeys layoutHotkeys = new LayoutHotkeys();
LayoutHotkeys.LayoutHotkeysWrapper layoutHotkeysWrapper = new LayoutHotkeys.LayoutHotkeysWrapper
{
LayoutHotkeys = new List<LayoutHotkeys.LayoutHotkeyWrapper> { },
};
FancyZonesEditorHelper.Files.LayoutHotkeysIOHelper.WriteData(layoutHotkeys.Serialize(layoutHotkeysWrapper));
AppliedLayouts appliedLayouts = new AppliedLayouts();
AppliedLayouts.AppliedLayoutsListWrapper appliedLayoutsWrapper = new AppliedLayouts.AppliedLayoutsListWrapper
{
AppliedLayouts = new List<AppliedLayouts.AppliedLayoutWrapper> { },
};
FancyZonesEditorHelper.Files.AppliedLayoutsIOHelper.WriteData(appliedLayouts.Serialize(appliedLayoutsWrapper));
this.RestartScopeExe();
}
[TestMethod]
public void Name_Initialize()
{
// verify all custom layouts are presented
foreach (var layout in Layouts.CustomLayouts)
{
Assert.IsNotNull(Session.Find<Element>(layout.Name));
}
}
[TestMethod]
public void Rename_Save()
{
string newName = "New layout name";
var oldName = Layouts.CustomLayouts[0].Name;
// rename the layout
Session.Find<Element>(oldName).Find<Button>(PowerToys.UITest.By.AccessibilityId(AccessibilityId.EditLayoutButton)).Click();
var input = Session.Find<TextBox>(PowerToys.UITest.By.ClassName(ClassName.TextBox));
Assert.IsNotNull(input);
input.SetText(newName, true);
// verify new name
Session.Find<Button>(ElementName.Save).Click();
if (Session.FindAll<Element>(oldName).Count != 0)
{
Assert.Fail("Error : previous name isn't presented"); // previous name isn't presented
}
if (Session.FindAll<Element>(newName).Count == 0)
{
Assert.Fail("Error : new name is presented"); // new name is presented
}
}
[TestMethod]
public void Rename_Cancel()
{
string newName = "New layout name";
var oldName = Layouts.CustomLayouts[0].Name;
// rename the layout
Session.Find<Element>(oldName).Find<Button>(PowerToys.UITest.By.AccessibilityId(AccessibilityId.EditLayoutButton)).Click();
var input = Session.Find<TextBox>(PowerToys.UITest.By.ClassName(ClassName.TextBox));
Assert.IsNotNull(input);
input.SetText(newName, true);
// verify new name
Session.Find<Button>(ElementName.Cancel).Click();
Assert.IsTrue(Session.FindAll<Element>(oldName).Count == 0);
Assert.IsTrue(Session.FindAll<Element>(newName).Count != 0);
}
[TestMethod]
public void HighlightDistance_Initialize()
{
foreach (var layout in Layouts.CustomLayouts)
{
Session.Find<Element>(layout.Name).Find<Button>(PowerToys.UITest.By.AccessibilityId(AccessibilityId.EditLayoutButton)).Click();
var slider = Session.Find<Element>(PowerToys.UITest.By.AccessibilityId(AccessibilityId.SensitivitySlider));
Assert.IsNotNull(slider);
var expected = layout.Type == CustomLayout.Canvas.TypeToString() ?
new CustomLayouts().CanvasFromJsonElement(layout.Info.GetRawText()).SensitivityRadius :
new CustomLayouts().GridFromJsonElement(layout.Info.GetRawText()).SensitivityRadius;
Assert.AreEqual($"{expected}", slider.Text);
Session.Find<Button>(ElementName.Cancel).Click();
}
}
[TestMethod]
public void HighlightDistance_Save()
{
var layout = Layouts.CustomLayouts[0];
var type = layout.Type;
Session.Find<Element>(layout.Name).Find<Button>(PowerToys.UITest.By.AccessibilityId(AccessibilityId.EditLayoutButton)).Click();
var slider = Session.Find<Custom>(PowerToys.UITest.By.AccessibilityId(AccessibilityId.SensitivitySlider));
Assert.IsNotNull(slider);
slider.SendKeys(Key.Right);
var value = type == CustomLayout.Canvas.TypeToString() ?
new CustomLayouts().CanvasFromJsonElement(layout.Info.GetRawText()).SensitivityRadius :
new CustomLayouts().GridFromJsonElement(layout.Info.GetRawText()).SensitivityRadius;
var expected = value; // if have one step right please + 1
Assert.AreEqual($"{expected}", slider.Text);
Session.Find<Button>(ElementName.Save).Click();
// verify the file
var customLayouts = new CustomLayouts();
var data = customLayouts.Read(customLayouts.File);
var actual = type == CustomLayout.Canvas.TypeToString() ?
new CustomLayouts().CanvasFromJsonElement(data.CustomLayouts.Find(x => x.Uuid == layout.Uuid).Info.GetRawText()).SensitivityRadius :
new CustomLayouts().GridFromJsonElement(data.CustomLayouts.Find(x => x.Uuid == layout.Uuid).Info.GetRawText()).SensitivityRadius;
Assert.AreEqual(expected, actual);
}
[TestMethod]
public void HighlightDistance_Cancel()
{
var layout = Layouts.CustomLayouts[0];
var type = layout.Type;
Session.Find<Element>(layout.Name).Find<Button>(PowerToys.UITest.By.AccessibilityId(AccessibilityId.EditLayoutButton)).Click();
var slider = Session.Find<Custom>(PowerToys.UITest.By.AccessibilityId(AccessibilityId.SensitivitySlider));
Assert.IsNotNull(slider);
slider.SendKeys(Key.Right);
var expected = type == CustomLayout.Canvas.TypeToString() ?
new CustomLayouts().CanvasFromJsonElement(layout.Info.GetRawText()).SensitivityRadius :
new CustomLayouts().GridFromJsonElement(layout.Info.GetRawText()).SensitivityRadius;
Session.Find<Button>(ElementName.Cancel).Click();
// verify the file
var customLayouts = new CustomLayouts();
var data = customLayouts.Read(customLayouts.File);
var actual = type == CustomLayout.Canvas.TypeToString() ?
new CustomLayouts().CanvasFromJsonElement(data.CustomLayouts.Find(x => x.Uuid == layout.Uuid).Info.GetRawText()).SensitivityRadius :
new CustomLayouts().GridFromJsonElement(data.CustomLayouts.Find(x => x.Uuid == layout.Uuid).Info.GetRawText()).SensitivityRadius;
Assert.AreEqual(expected, actual);
}
[TestMethod]
public void SpaceAroundZones_Initialize()
{
foreach (var layout in Layouts.CustomLayouts)
{
if (layout.Type != CustomLayout.Grid.TypeToString())
{
// only for grid layouts
continue;
}
Session.Find<Element>(layout.Name).Find<Button>(PowerToys.UITest.By.AccessibilityId(AccessibilityId.EditLayoutButton)).Click();
var toggle = Session.Find<Element>(PowerToys.UITest.By.AccessibilityId(AccessibilityId.SpacingToggle));
Assert.IsNotNull(toggle);
var slider = Session.Find<Element>(PowerToys.UITest.By.AccessibilityId(AccessibilityId.SpacingSlider));
Assert.IsNotNull(slider);
var spacingEnabled = new CustomLayouts().GridFromJsonElement(layout.Info.GetRawText()).ShowSpacing;
Assert.AreEqual(spacingEnabled, slider.Enabled);
Assert.AreEqual(spacingEnabled, toggle.Selected);
var expected = new CustomLayouts().GridFromJsonElement(layout.Info.GetRawText()).Spacing;
Assert.AreEqual($"{expected}", slider.Text);
Session.Find<Button>(ElementName.Cancel).Click();
}
}
[TestMethod]
public void SpaceAroundZones_Slider_Save()
{
var layout = Layouts.CustomLayouts.Find(x => x.Type == CustomLayout.Grid.TypeToString() && new CustomLayouts().GridFromJsonElement(x.Info.GetRawText()).ShowSpacing);
var expected = new CustomLayouts().GridFromJsonElement(layout.Info.GetRawText()).Spacing; // one step right
Session.Find<Element>(layout.Name).Find<Button>(PowerToys.UITest.By.AccessibilityId(AccessibilityId.EditLayoutButton)).Click();
var slider = Session.Find<Custom>(PowerToys.UITest.By.AccessibilityId(AccessibilityId.SpacingSlider));
Assert.IsNotNull(slider);
slider.SendKeys(Key.Right);
Assert.AreEqual($"{expected}", slider.Text);
Session.Find<Button>(PowerToys.UITest.By.AccessibilityId(AccessibilityId.PrimaryButton)).Click();
// verify the file
var customLayouts = new CustomLayouts();
var data = customLayouts.Read(customLayouts.File);
var actual = new CustomLayouts().GridFromJsonElement(data.CustomLayouts.Find(x => x.Uuid == layout.Uuid).Info.GetRawText()).Spacing;
Assert.AreEqual(expected, actual);
}
[TestMethod]
public void SpaceAroundZones_Slider_Cancel()
{
var layout = Layouts.CustomLayouts.Find(x => x.Type == CustomLayout.Grid.TypeToString() && new CustomLayouts().GridFromJsonElement(x.Info.GetRawText()).ShowSpacing);
Session.Find<Element>(layout.Name).Find<Button>(PowerToys.UITest.By.AccessibilityId(AccessibilityId.EditLayoutButton)).Click();
var expected = new CustomLayouts().GridFromJsonElement(layout.Info.GetRawText()).Spacing;
var slider = Session.Find<Custom>(PowerToys.UITest.By.AccessibilityId(AccessibilityId.SpacingSlider));
Assert.IsNotNull(slider);
slider.SendKeys(Key.Right);
Session.Find<Button>(ElementName.Cancel).Click();
// verify the file
var customLayouts = new CustomLayouts();
var data = customLayouts.Read(customLayouts.File);
var actual = new CustomLayouts().GridFromJsonElement(data.CustomLayouts.Find(x => x.Uuid == layout.Uuid).Info.GetRawText()).Spacing;
Assert.AreEqual(expected, actual);
}
[TestMethod]
public void SpaceAroundZones_Toggle_Save()
{
var layout = Layouts.CustomLayouts.Find(x => x.Type == CustomLayout.Grid.TypeToString());
var value = new CustomLayouts().GridFromJsonElement(layout.Info.GetRawText()).ShowSpacing;
var expected = !value;
Session.Find<Element>(layout.Name).Find<Button>(PowerToys.UITest.By.AccessibilityId(AccessibilityId.EditLayoutButton)).Click();
var toggle = Session.Find<Element>(PowerToys.UITest.By.AccessibilityId(AccessibilityId.SpacingToggle));
Assert.IsNotNull(toggle);
toggle.Click();
Assert.AreEqual(expected, toggle.Selected, "Toggle value not changed");
Assert.AreEqual(expected, Session.Find<Element>(PowerToys.UITest.By.AccessibilityId(AccessibilityId.SpacingSlider))?.Enabled);
Session.Find<Button>(ElementName.Save).Click();
// verify the file
var customLayouts = new CustomLayouts();
var data = customLayouts.Read(customLayouts.File);
var actual = new CustomLayouts().GridFromJsonElement(data.CustomLayouts.Find(x => x.Uuid == layout.Uuid).Info.GetRawText()).ShowSpacing;
Assert.AreEqual(expected, actual);
}
[TestMethod]
public void SpaceAroundZones_Toggle_Cancel()
{
var layout = Layouts.CustomLayouts.Find(x => x.Type == CustomLayout.Grid.TypeToString());
var expected = new CustomLayouts().GridFromJsonElement(layout.Info.GetRawText()).ShowSpacing;
Session.Find<Element>(layout.Name).Find<Button>(PowerToys.UITest.By.AccessibilityId(AccessibilityId.EditLayoutButton)).Click();
var toggle = Session.Find<Element>(PowerToys.UITest.By.AccessibilityId(AccessibilityId.SpacingToggle));
Assert.IsNotNull(toggle);
toggle.Click();
Assert.AreNotEqual(expected, toggle.Selected, "Toggle value not changed");
Assert.AreNotEqual(expected, Session.Find<Element>(PowerToys.UITest.By.AccessibilityId(AccessibilityId.SpacingSlider))?.Enabled);
Session.Find<Button>(ElementName.Cancel).Click();
// verify the file
var customLayouts = new CustomLayouts();
var data = customLayouts.Read(customLayouts.File);
var actual = new CustomLayouts().GridFromJsonElement(data.CustomLayouts.Find(x => x.Uuid == layout.Uuid).Info.GetRawText()).ShowSpacing;
Assert.AreEqual(expected, actual);
}
}
}

View File

@@ -0,0 +1,361 @@
// Copyright (c) Microsoft Corporation
// The Microsoft Corporation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information.
using System.Collections.Generic;
using System.Xml.Linq;
using FancyZonesEditor.Models;
using FancyZonesEditorCommon.Data;
using Microsoft.FancyZonesEditor.UnitTests.Utils;
using Microsoft.PowerToys.UITest;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using static FancyZonesEditorCommon.Data.CustomLayouts;
using static FancyZonesEditorCommon.Data.DefaultLayouts;
using static FancyZonesEditorCommon.Data.EditorParameters;
using static Microsoft.FancyZonesEditor.UnitTests.Utils.FancyZonesEditorHelper;
namespace Microsoft.FancyZonesEditor.UITests
{
[TestClass]
public class DefaultLayoutsTest : UITestBase
{
public DefaultLayoutsTest()
: base(PowerToysModule.FancyZone, WindowSize.UnSpecified)
{
}
private static readonly string Vertical = MonitorConfigurationType.Vertical.TypeToString();
private static readonly string Horizontal = MonitorConfigurationType.Horizontal.TypeToString();
private static readonly CustomLayoutListWrapper CustomLayouts = new CustomLayoutListWrapper
{
CustomLayouts = new List<CustomLayoutWrapper>
{
new CustomLayoutWrapper
{
Uuid = "{0D6D2F58-9184-4804-81E4-4E4CC3476DC1}",
Type = CustomLayout.Canvas.TypeToString(),
Name = "Layout 0",
Info = new CustomLayouts().ToJsonElement(new CanvasInfoWrapper
{
RefHeight = 1080,
RefWidth = 1920,
SensitivityRadius = 10,
Zones = new List<CanvasInfoWrapper.CanvasZoneWrapper> { },
}),
},
new CustomLayoutWrapper
{
Uuid = "{E7807D0D-6223-4883-B15B-1F3883944C09}",
Type = CustomLayout.Canvas.TypeToString(),
Name = "Layout 1",
Info = new CustomLayouts().ToJsonElement(new CanvasInfoWrapper
{
RefHeight = 1080,
RefWidth = 1920,
SensitivityRadius = 10,
Zones = new List<CanvasInfoWrapper.CanvasZoneWrapper> { },
}),
},
new CustomLayoutWrapper
{
Uuid = "{F1A94F38-82B6-4876-A653-70D0E882DE2A}",
Type = CustomLayout.Canvas.TypeToString(),
Name = "Layout 2",
Info = new CustomLayouts().ToJsonElement(new CanvasInfoWrapper
{
RefHeight = 1080,
RefWidth = 1920,
SensitivityRadius = 10,
Zones = new List<CanvasInfoWrapper.CanvasZoneWrapper> { },
}),
},
new CustomLayoutWrapper
{
Uuid = "{F5FDBC04-0760-4776-9F05-96AAC4AE613F}",
Type = CustomLayout.Canvas.TypeToString(),
Name = "Layout 3",
Info = new CustomLayouts().ToJsonElement(new CanvasInfoWrapper
{
RefHeight = 1080,
RefWidth = 1920,
SensitivityRadius = 10,
Zones = new List<CanvasInfoWrapper.CanvasZoneWrapper> { },
}),
},
},
};
private static readonly DefaultLayoutsListWrapper Layouts = new DefaultLayoutsListWrapper
{
DefaultLayouts = new List<DefaultLayoutWrapper>
{
new DefaultLayoutWrapper
{
MonitorConfiguration = Horizontal,
Layout = new DefaultLayoutWrapper.LayoutWrapper
{
Type = LayoutType.Grid.TypeToString(),
ZoneCount = 4,
ShowSpacing = true,
Spacing = 5,
SensitivityRadius = 20,
},
},
new DefaultLayoutWrapper
{
MonitorConfiguration = Vertical,
Layout = new DefaultLayoutWrapper.LayoutWrapper
{
Type = "custom",
Uuid = "{0D6D2F58-9184-4804-81E4-4E4CC3476DC1}",
ZoneCount = 0,
ShowSpacing = false,
Spacing = 0,
SensitivityRadius = 0,
},
},
},
};
[TestInitialize]
public void TestInitialize()
{
FancyZonesEditorHelper.Files.Restore();
var defaultLayouts = new DefaultLayouts();
FancyZonesEditorHelper.Files.DefaultLayoutsIOHelper.WriteData(defaultLayouts.Serialize(Layouts));
EditorParameters editorParameters = new EditorParameters();
ParamsWrapper parameters = new ParamsWrapper
{
ProcessId = 1,
SpanZonesAcrossMonitors = false,
Monitors = new List<NativeMonitorDataWrapper>
{
new NativeMonitorDataWrapper
{
Monitor = "monitor-1",
MonitorInstanceId = "instance-id-1",
MonitorSerialNumber = "serial-number-1",
MonitorNumber = 1,
VirtualDesktop = "{FF34D993-73F3-4B8C-AA03-73730A01D6A8}",
Dpi = 192,
LeftCoordinate = 0,
TopCoordinate = 0,
WorkAreaHeight = 1040,
WorkAreaWidth = 1920,
MonitorHeight = 1080,
MonitorWidth = 1920,
IsSelected = true,
},
new NativeMonitorDataWrapper
{
Monitor = "monitor-2",
MonitorInstanceId = "instance-id-2",
MonitorSerialNumber = "serial-number-2",
MonitorNumber = 2,
VirtualDesktop = "{FF34D993-73F3-4B8C-AA03-73730A01D6A8}",
Dpi = 96,
LeftCoordinate = 1920,
TopCoordinate = 0,
WorkAreaHeight = 1040,
WorkAreaWidth = 1920,
MonitorHeight = 1080,
MonitorWidth = 1920,
IsSelected = false,
},
},
};
FancyZonesEditorHelper.Files.ParamsIOHelper.WriteData(editorParameters.Serialize(parameters));
CustomLayouts customLayouts = new CustomLayouts();
FancyZonesEditorHelper.Files.CustomLayoutsIOHelper.WriteData(customLayouts.Serialize(CustomLayouts));
LayoutTemplates layoutTemplates = new LayoutTemplates();
LayoutTemplates.TemplateLayoutsListWrapper templateLayoutsListWrapper = new LayoutTemplates.TemplateLayoutsListWrapper
{
LayoutTemplates = new List<LayoutTemplates.TemplateLayoutWrapper>
{
new LayoutTemplates.TemplateLayoutWrapper
{
Type = LayoutType.Blank.TypeToString(),
},
new LayoutTemplates.TemplateLayoutWrapper
{
Type = LayoutType.Focus.TypeToString(),
ZoneCount = 10,
},
new LayoutTemplates.TemplateLayoutWrapper
{
Type = LayoutType.Rows.TypeToString(),
ZoneCount = 2,
ShowSpacing = true,
Spacing = 10,
SensitivityRadius = 10,
},
new LayoutTemplates.TemplateLayoutWrapper
{
Type = LayoutType.Columns.TypeToString(),
ZoneCount = 2,
ShowSpacing = true,
Spacing = 20,
SensitivityRadius = 20,
},
new LayoutTemplates.TemplateLayoutWrapper
{
Type = LayoutType.Grid.TypeToString(),
ZoneCount = 4,
ShowSpacing = false,
Spacing = 10,
SensitivityRadius = 30,
},
new LayoutTemplates.TemplateLayoutWrapper
{
Type = LayoutType.PriorityGrid.TypeToString(),
ZoneCount = 3,
ShowSpacing = true,
Spacing = 1,
SensitivityRadius = 40,
},
},
};
FancyZonesEditorHelper.Files.LayoutTemplatesIOHelper.WriteData(layoutTemplates.Serialize(templateLayoutsListWrapper));
LayoutHotkeys layoutHotkeys = new LayoutHotkeys();
LayoutHotkeys.LayoutHotkeysWrapper layoutHotkeysWrapper = new LayoutHotkeys.LayoutHotkeysWrapper
{
LayoutHotkeys = new List<LayoutHotkeys.LayoutHotkeyWrapper> { },
};
FancyZonesEditorHelper.Files.LayoutHotkeysIOHelper.WriteData(layoutHotkeys.Serialize(layoutHotkeysWrapper));
AppliedLayouts appliedLayouts = new AppliedLayouts();
AppliedLayouts.AppliedLayoutsListWrapper appliedLayoutsWrapper = new AppliedLayouts.AppliedLayoutsListWrapper
{
AppliedLayouts = new List<AppliedLayouts.AppliedLayoutWrapper> { },
};
FancyZonesEditorHelper.Files.AppliedLayoutsIOHelper.WriteData(appliedLayouts.Serialize(appliedLayoutsWrapper));
this.RestartScopeExe();
}
[TestMethod("FancyZonesEditor.Basic.Default_Initialize")]
[TestCategory("FancyZones Editor #12")]
public void Initialize()
{
CheckTemplateLayouts(LayoutType.Grid, null);
CheckCustomLayouts(string.Empty, CustomLayouts.CustomLayouts[0].Uuid);
}
[TestMethod("FancyZonesEditor.Basic.Default_Assign_Cancel")]
[TestCategory("FancyZones Editor #12")]
public void Assign_Cancel()
{
// assign Focus as a default horizontal and vertical layout
Session.Find<Element>(TestConstants.TemplateLayoutNames[LayoutType.Focus]).Find<Button>(By.AccessibilityId(AccessibilityId.EditLayoutButton)).Click();
Session.Find<Button>(By.AccessibilityId(AccessibilityId.HorizontalDefaultButtonUnchecked)).Click();
Session.Find<Button>(By.AccessibilityId(AccessibilityId.VerticalDefaultButtonUnchecked)).Click();
// cancel
Session.Find<Button>(ElementName.Cancel).Click();
// check that default layouts weren't changed
CheckTemplateLayouts(LayoutType.Grid, null);
CheckCustomLayouts(string.Empty, CustomLayouts.CustomLayouts[0].Uuid);
}
[TestMethod("FancyZonesEditor.Basic.Default_Assign_Save")]
[TestCategory("FancyZones Editor #12")]
public void Assign_Save()
{
// assign Focus as a default horizontal and vertical layout
Session.Find<Element>(TestConstants.TemplateLayoutNames[LayoutType.Focus]).Find<Button>(By.AccessibilityId(AccessibilityId.EditLayoutButton)).Click();
Session.Find<Button>(By.AccessibilityId(AccessibilityId.HorizontalDefaultButtonUnchecked)).Click();
Session.Find<Button>(By.AccessibilityId(AccessibilityId.VerticalDefaultButtonUnchecked)).Click();
// save
Session.Find<Button>(ElementName.Save).Click();
// check that default layout was changed
CheckTemplateLayouts(LayoutType.Focus, LayoutType.Focus);
CheckCustomLayouts(string.Empty, string.Empty);
}
private void CheckTemplateLayouts(LayoutType? horizontalDefault, LayoutType? verticalDefault)
{
foreach (var (key, name) in TestConstants.TemplateLayoutNames)
{
if (key == LayoutType.Blank)
{
continue;
}
Session.Find<Element>(name).Find<Button>(By.AccessibilityId(AccessibilityId.EditLayoutButton)).Click();
bool isCheckedHorizontal = key == horizontalDefault;
bool isCheckedVertical = key == verticalDefault;
Button? horizontalDefaultButton;
Button? verticalDefaultButton;
if (isCheckedHorizontal)
{
horizontalDefaultButton = Session.Find<Button>(By.AccessibilityId(AccessibilityId.HorizontalDefaultButtonChecked));
}
else
{
horizontalDefaultButton = Session.Find<Button>(By.AccessibilityId(AccessibilityId.HorizontalDefaultButtonUnchecked));
}
if (isCheckedVertical)
{
verticalDefaultButton = Session.Find<Button>(By.AccessibilityId(AccessibilityId.VerticalDefaultButtonChecked));
}
else
{
verticalDefaultButton = Session.Find<Button>(By.AccessibilityId(AccessibilityId.VerticalDefaultButtonUnchecked));
}
Assert.IsNotNull(horizontalDefaultButton, "Incorrect horizontal default layout set at " + name);
Assert.IsNotNull(verticalDefaultButton, "Incorrect vertical default layout set at " + name);
Session.Find<Button>(ElementName.Cancel).Click();
}
}
private void CheckCustomLayouts(string horizontalDefaultLayoutUuid, string verticalDefaultLayoutUuid)
{
foreach (var layout in CustomLayouts.CustomLayouts)
{
Session.Find<Element>(layout.Name).Find<Button>(By.AccessibilityId(AccessibilityId.EditLayoutButton)).Click();
bool isCheckedHorizontal = layout.Uuid == horizontalDefaultLayoutUuid;
bool isCheckedVertical = layout.Uuid == verticalDefaultLayoutUuid;
Button? horizontalDefaultButton;
Button? verticalDefaultButton;
if (isCheckedHorizontal)
{
horizontalDefaultButton = Session.Find<Button>(By.AccessibilityId(AccessibilityId.HorizontalDefaultButtonChecked));
}
else
{
horizontalDefaultButton = Session.Find<Button>(By.AccessibilityId(AccessibilityId.HorizontalDefaultButtonUnchecked));
}
if (isCheckedVertical)
{
verticalDefaultButton = Session.Find<Button>(By.AccessibilityId(AccessibilityId.VerticalDefaultButtonChecked));
}
else
{
verticalDefaultButton = Session.Find<Button>(By.AccessibilityId(AccessibilityId.VerticalDefaultButtonUnchecked));
}
Assert.IsNotNull(horizontalDefaultButton, "Incorrect horizontal custom layout set at " + layout.Name);
Assert.IsNotNull(verticalDefaultButton, "Incorrect vertical custom layout set at " + layout.Name);
Session.Find<Button>(ElementName.Cancel).Click();
}
}
}
}

View File

@@ -0,0 +1,367 @@
// Copyright (c) Microsoft Corporation
// The Microsoft Corporation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information.
using System.Collections.Generic;
using FancyZonesEditor.Models;
using FancyZonesEditorCommon.Data;
using Microsoft.FancyZonesEditor.UnitTests.Utils;
using Microsoft.PowerToys.UITest;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using ModernWpf.Controls;
using OpenQA.Selenium;
using static FancyZonesEditorCommon.Data.CustomLayouts;
using static FancyZonesEditorCommon.Data.DefaultLayouts;
using static FancyZonesEditorCommon.Data.EditorParameters;
using static FancyZonesEditorCommon.Data.LayoutHotkeys;
using static Microsoft.FancyZonesEditor.UnitTests.Utils.FancyZonesEditorHelper;
namespace Microsoft.FancyZonesEditor.UITests
{
[TestClass]
public class DeleteLayoutTests : UITestBase
{
public DeleteLayoutTests()
: base(PowerToysModule.FancyZone, WindowSize.UnSpecified)
{
}
private static readonly CustomLayoutListWrapper CustomLayouts = new CustomLayoutListWrapper
{
CustomLayouts = new List<CustomLayoutWrapper>
{
new CustomLayoutWrapper
{
Uuid = "{0D6D2F58-9184-4804-81E4-4E4CC3476DC1}",
Type = CustomLayout.Grid.TypeToString(),
Name = "Custom layout 1",
Info = new CustomLayouts().ToJsonElement(new CustomLayouts.GridInfoWrapper
{
Rows = 2,
Columns = 3,
RowsPercentage = new List<int> { 2967, 7033 },
ColumnsPercentage = new List<int> { 2410, 6040, 1550 },
CellChildMap = new int[][] { [0, 1, 1], [0, 2, 3] },
SensitivityRadius = 30,
Spacing = 26,
ShowSpacing = false,
}),
},
new CustomLayoutWrapper
{
Uuid = "{E7807D0D-6223-4883-B15B-1F3883944C09}",
Type = CustomLayout.Canvas.TypeToString(),
Name = "Custom layout 2",
Info = new CustomLayouts().ToJsonElement(new CanvasInfoWrapper
{
RefHeight = 952,
RefWidth = 1500,
SensitivityRadius = 10,
Zones = new List<CanvasInfoWrapper.CanvasZoneWrapper>
{
new CanvasInfoWrapper.CanvasZoneWrapper
{
X = 0,
Y = 0,
Width = 900,
Height = 522,
},
new CanvasInfoWrapper.CanvasZoneWrapper
{
X = 900,
Y = 0,
Width = 600,
Height = 750,
},
new CanvasInfoWrapper.CanvasZoneWrapper
{
X = 0,
Y = 522,
Width = 1500,
Height = 430,
},
},
}),
},
},
};
private static readonly DefaultLayouts.DefaultLayoutsListWrapper DefaultLayoutsList = new DefaultLayouts.DefaultLayoutsListWrapper
{
DefaultLayouts = new List<DefaultLayouts.DefaultLayoutWrapper>
{
new DefaultLayoutWrapper
{
MonitorConfiguration = MonitorConfigurationType.Horizontal.TypeToString(),
Layout = new DefaultLayoutWrapper.LayoutWrapper
{
Type = LayoutType.Custom.TypeToString(),
Uuid = CustomLayouts.CustomLayouts[1].Uuid,
},
},
},
};
private static readonly LayoutHotkeys.LayoutHotkeysWrapper Hotkeys = new LayoutHotkeys.LayoutHotkeysWrapper
{
LayoutHotkeys = new List<LayoutHotkeys.LayoutHotkeyWrapper>
{
new LayoutHotkeyWrapper
{
LayoutId = CustomLayouts.CustomLayouts[1].Uuid,
Key = 0,
},
},
};
private static readonly ParamsWrapper Parameters = new ParamsWrapper
{
ProcessId = 1,
SpanZonesAcrossMonitors = false,
Monitors = new List<NativeMonitorDataWrapper>
{
new NativeMonitorDataWrapper
{
Monitor = "monitor-1",
MonitorInstanceId = "instance-id-1",
MonitorSerialNumber = "serial-number-1",
MonitorNumber = 1,
VirtualDesktop = "{FF34D993-73F3-4B8C-AA03-73730A01D6A8}",
Dpi = 192,
LeftCoordinate = 0,
TopCoordinate = 0,
WorkAreaHeight = 1040,
WorkAreaWidth = 1920,
MonitorHeight = 1080,
MonitorWidth = 1920,
IsSelected = true,
},
},
};
[TestInitialize]
public void TestInitialize()
{
FancyZonesEditorHelper.Files.Restore();
EditorParameters editorParameters = new EditorParameters();
FancyZonesEditorHelper.Files.ParamsIOHelper.WriteData(editorParameters.Serialize(Parameters));
CustomLayouts customLayouts = new CustomLayouts();
FancyZonesEditorHelper.Files.CustomLayoutsIOHelper.WriteData(customLayouts.Serialize(CustomLayouts));
LayoutTemplates layoutTemplates = new LayoutTemplates();
LayoutTemplates.TemplateLayoutsListWrapper templateLayoutsListWrapper = new LayoutTemplates.TemplateLayoutsListWrapper
{
LayoutTemplates = new List<LayoutTemplates.TemplateLayoutWrapper>
{
new LayoutTemplates.TemplateLayoutWrapper
{
Type = LayoutType.Blank.TypeToString(),
},
new LayoutTemplates.TemplateLayoutWrapper
{
Type = LayoutType.Focus.TypeToString(),
ZoneCount = 10,
},
new LayoutTemplates.TemplateLayoutWrapper
{
Type = LayoutType.Rows.TypeToString(),
ZoneCount = 2,
ShowSpacing = true,
Spacing = 10,
SensitivityRadius = 10,
},
new LayoutTemplates.TemplateLayoutWrapper
{
Type = LayoutType.Columns.TypeToString(),
ZoneCount = 2,
ShowSpacing = true,
Spacing = 20,
SensitivityRadius = 20,
},
new LayoutTemplates.TemplateLayoutWrapper
{
Type = LayoutType.Grid.TypeToString(),
ZoneCount = 4,
ShowSpacing = false,
Spacing = 10,
SensitivityRadius = 30,
},
new LayoutTemplates.TemplateLayoutWrapper
{
Type = LayoutType.PriorityGrid.TypeToString(),
ZoneCount = 3,
ShowSpacing = true,
Spacing = 1,
SensitivityRadius = 40,
},
},
};
FancyZonesEditorHelper.Files.LayoutTemplatesIOHelper.WriteData(layoutTemplates.Serialize(templateLayoutsListWrapper));
DefaultLayouts defaultLayouts = new DefaultLayouts();
FancyZonesEditorHelper.Files.DefaultLayoutsIOHelper.WriteData(defaultLayouts.Serialize(DefaultLayoutsList));
LayoutHotkeys layoutHotkeys = new LayoutHotkeys();
FancyZonesEditorHelper.Files.LayoutHotkeysIOHelper.WriteData(layoutHotkeys.Serialize(Hotkeys));
AppliedLayouts appliedLayouts = new AppliedLayouts();
AppliedLayouts.AppliedLayoutsListWrapper appliedLayoutsWrapper = new AppliedLayouts.AppliedLayoutsListWrapper
{
AppliedLayouts = new List<AppliedLayouts.AppliedLayoutWrapper> { },
};
FancyZonesEditorHelper.Files.AppliedLayoutsIOHelper.WriteData(appliedLayouts.Serialize(appliedLayoutsWrapper));
this.RestartScopeExe();
Session.Find<Element>(CustomLayouts.CustomLayouts[0].Name).Click();
}
[TestMethod("FancyZonesEditor.Basic.DeleteNotAppliedLayout")]
[TestCategory("FancyZones Editor #5")]
public void DeleteNotAppliedLayout()
{
var deletedLayout = CustomLayouts.CustomLayouts[1].Name;
Session.Find<Element>(deletedLayout).Find<Button>(PowerToys.UITest.By.AccessibilityId(AccessibilityId.EditLayoutButton)).Click();
Session.Find<Button>(PowerToys.UITest.By.AccessibilityId(AccessibilityId.DeleteLayoutButton)).Click();
Session.SendKeySequence(Key.Tab, Key.Enter);
// verify the layout is removed
Assert.IsTrue(Session.FindAll<Element>(deletedLayout).Count == 0);
// check the file
var customLayouts = new CustomLayouts();
var data = customLayouts.Read(customLayouts.File);
Assert.AreEqual(CustomLayouts.CustomLayouts.Count - 1, data.CustomLayouts.Count);
Assert.IsFalse(data.CustomLayouts.Exists(x => x.Name == deletedLayout));
}
[TestMethod("FancyZonesEditor.Basic.DeleteAppliedLayout")]
[TestCategory("FancyZones Editor #5")]
public void DeleteAppliedLayout()
{
var deletedLayout = CustomLayouts.CustomLayouts[0].Name;
Session.Find<Element>(deletedLayout).Find<Button>(PowerToys.UITest.By.AccessibilityId(AccessibilityId.EditLayoutButton)).Click();
Session.Find<Button>(PowerToys.UITest.By.AccessibilityId(AccessibilityId.DeleteLayoutButton)).Click();
Session.SendKeySequence(Key.Tab, Key.Enter);
// verify the layout is removed
Assert.IsTrue(Session.FindAll<Element>(deletedLayout).Count == 0);
// verify the empty layout is selected
Assert.IsTrue(Session.Find<Element>(TestConstants.TemplateLayoutNames[LayoutType.Blank])!.Selected);
// check the file
var customLayouts = new CustomLayouts();
var data = customLayouts.Read(customLayouts.File);
Assert.AreEqual(CustomLayouts.CustomLayouts.Count - 1, data.CustomLayouts.Count);
Assert.IsFalse(data.CustomLayouts.Exists(x => x.Name == deletedLayout));
var appliedLayouts = new AppliedLayouts();
var appliedLayoutsData = appliedLayouts.Read(appliedLayouts.File);
Assert.AreEqual(LayoutType.Blank.TypeToString(), appliedLayoutsData.AppliedLayouts.Find(x => x.Device.Monitor == Parameters.Monitors[0].Monitor).AppliedLayout.Type);
}
[TestMethod("FancyZonesEditor.Basic.CancelDeletion")]
[TestCategory("FancyZones Editor #5")]
public void CancelDeletion()
{
var deletedLayout = CustomLayouts.CustomLayouts[1].Name;
Session.Find<Element>(deletedLayout).Find<Button>(PowerToys.UITest.By.AccessibilityId(AccessibilityId.EditLayoutButton)).Click();
Session.Find<Button>(PowerToys.UITest.By.AccessibilityId(AccessibilityId.DeleteLayoutButton)).Click();
Session.SendKeySequence(Key.Tab, Key.Tab, Key.Enter);
// verify the layout is not removed
Assert.IsNotNull(Session.Find<Element>(deletedLayout));
// check the file
var customLayouts = new CustomLayouts();
var data = customLayouts.Read(customLayouts.File);
Assert.AreEqual(CustomLayouts.CustomLayouts.Count, data.CustomLayouts.Count);
Assert.IsTrue(data.CustomLayouts.Exists(x => x.Name == deletedLayout));
}
[TestMethod("FancyZonesEditor.Basic.DeleteFromContextMenu")]
[TestCategory("FancyZones Editor #5")]
public void DeleteFromContextMenu()
{
var deletedLayout = CustomLayouts.CustomLayouts[1].Name;
FancyZonesEditorHelper.ClickContextMenuItem(Session, deletedLayout, FancyZonesEditorHelper.ElementName.Delete);
Session.SendKeySequence(Key.Tab, Key.Enter);
// verify the layout is removed
Assert.IsTrue(Session.FindAll<Element>(deletedLayout).Count == 0);
// check the file
var customLayouts = new CustomLayouts();
var data = customLayouts.Read(customLayouts.File);
Assert.AreEqual(CustomLayouts.CustomLayouts.Count - 1, data.CustomLayouts.Count);
Assert.IsFalse(data.CustomLayouts.Exists(x => x.Name == deletedLayout));
}
[TestMethod("FancyZonesEditor.Basic.DeleteDefaultLayout")]
[TestCategory("FancyZones Editor #5")]
public void DeleteDefaultLayout()
{
var deletedLayout = CustomLayouts.CustomLayouts[1].Name;
FancyZonesEditorHelper.ClickContextMenuItem(Session, deletedLayout, FancyZonesEditorHelper.ElementName.Delete);
Session.SendKeySequence(Key.Tab, Key.Enter);
// verify the default layout is reset to the "default" default
Session.Find<Element>(TestConstants.TemplateLayoutNames[LayoutType.PriorityGrid]).Find<Button>(PowerToys.UITest.By.AccessibilityId(AccessibilityId.EditLayoutButton)).Click();
Assert.IsNotNull(Session.Find<Element>(PowerToys.UITest.By.AccessibilityId(AccessibilityId.HorizontalDefaultButtonChecked)));
Session.Find<Button>(ElementName.Cancel).Click();
// check the file
var defaultLayouts = new DefaultLayouts();
var data = defaultLayouts.Read(defaultLayouts.File);
string configuration = MonitorConfigurationType.Horizontal.TypeToString();
Assert.AreEqual(LayoutType.PriorityGrid.TypeToString(), data.DefaultLayouts.Find(x => x.MonitorConfiguration == configuration).Layout.Type);
}
[TestMethod("FancyZonesEditor.Basic.DeleteLayoutWithHotkey")]
[TestCategory("FancyZones Editor #5")]
public void DeleteLayoutWithHotkey()
{
var deletedLayout = CustomLayouts.CustomLayouts[1].Name;
FancyZonesEditorHelper.ClickContextMenuItem(Session, deletedLayout, FancyZonesEditorHelper.ElementName.Delete);
Session.SendKeySequence(Key.Tab, Key.Enter);
// verify the hotkey is available
Session.Find<Element>(CustomLayouts.CustomLayouts[0].Name).Find<Button>(PowerToys.UITest.By.AccessibilityId(AccessibilityId.EditLayoutButton)).Click();
var hotkeyComboBox = Session.Find<Element>(PowerToys.UITest.By.AccessibilityId(AccessibilityId.HotkeyComboBox));
Assert.IsNotNull(hotkeyComboBox);
hotkeyComboBox.Click();
var popup = Session.Find<Element>(PowerToys.UITest.By.ClassName(ClassName.Popup));
Assert.IsNotNull(popup);
try
{
for (int i = 0; i < 10; i++)
{
popup.Find<Element>($"{i}");
}
}
catch
{
Assert.Fail("Hotkey not found");
}
Session.Find<Button>(ElementName.Cancel).DoubleClick();
// check the file
var hotkeys = new LayoutHotkeys();
var data = hotkeys.Read(hotkeys.File);
int layoutHotkeyCount = 0;
foreach (var layout in data.LayoutHotkeys)
{
if (layout.Key != -1)
{
layoutHotkeyCount++;
}
}
Assert.AreEqual(0, layoutHotkeyCount);
}
}
}

View File

@@ -0,0 +1,664 @@
// Copyright (c) Microsoft Corporation
// The Microsoft Corporation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information.
using System.Collections.Generic;
using System.Linq;
using FancyZonesEditor.Models;
using FancyZonesEditorCommon.Data;
using Microsoft.FancyZonesEditor.UnitTests.Utils;
using Microsoft.PowerToys.UITest;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using ModernWpf.Controls;
using OpenQA.Selenium.Appium.Windows;
using static FancyZonesEditorCommon.Data.CustomLayouts;
using static FancyZonesEditorCommon.Data.EditorParameters;
using static Microsoft.FancyZonesEditor.UnitTests.Utils.FancyZonesEditorHelper;
namespace Microsoft.FancyZonesEditor.UITests
{
[TestClass]
public class EditLayoutTests : UITestBase
{
public EditLayoutTests()
: base(PowerToysModule.FancyZone, WindowSize.UnSpecified)
{
}
private static readonly CustomLayouts.CustomLayoutListWrapper Layouts = new CustomLayouts.CustomLayoutListWrapper
{
CustomLayouts = new List<CustomLayouts.CustomLayoutWrapper>
{
new CustomLayoutWrapper
{
Uuid = "{0D6D2F58-9184-4804-81E4-4E4CC3476DC1}",
Type = CustomLayout.Grid.TypeToString(),
Name = "Grid custom layout",
Info = new CustomLayouts().ToJsonElement(new GridInfoWrapper
{
Rows = 2,
Columns = 2,
RowsPercentage = new List<int> { 5000, 5000 },
ColumnsPercentage = new List<int> { 5000, 5000 },
CellChildMap = new int[][] { [0, 1], [2, 3] },
SensitivityRadius = 30,
Spacing = 26,
ShowSpacing = false,
}),
},
new CustomLayoutWrapper
{
Uuid = "{0EB9BF3E-010E-46D7-8681-1879D1E111E1}",
Type = CustomLayout.Grid.TypeToString(),
Name = "Grid-9",
Info = new CustomLayouts().ToJsonElement(new GridInfoWrapper
{
Rows = 3,
Columns = 3,
RowsPercentage = new List<int> { 2333, 3333, 4334 },
ColumnsPercentage = new List<int> { 2333, 3333, 4334 },
CellChildMap = new int[][] { [0, 1, 2], [3, 4, 5], [6, 7, 8] },
SensitivityRadius = 20,
Spacing = 3,
ShowSpacing = false,
}),
},
new CustomLayoutWrapper
{
Uuid = "{E7807D0D-6223-4883-B15B-1F3883944C09}",
Type = CustomLayout.Canvas.TypeToString(),
Name = "Canvas custom layout",
Info = new CustomLayouts().ToJsonElement(new CanvasInfoWrapper
{
RefHeight = 1040,
RefWidth = 1920,
SensitivityRadius = 10,
Zones = new List<CanvasInfoWrapper.CanvasZoneWrapper>
{
new CanvasInfoWrapper.CanvasZoneWrapper
{
X = 0,
Y = 0,
Width = 500,
Height = 250,
},
new CanvasInfoWrapper.CanvasZoneWrapper
{
X = 500,
Y = 0,
Width = 1420,
Height = 500,
},
new CanvasInfoWrapper.CanvasZoneWrapper
{
X = 0,
Y = 250,
Width = 1920,
Height = 500,
},
},
}),
},
},
};
[TestInitialize]
public void TestInitialize()
{
FancyZonesEditorHelper.Files.Restore();
EditorParameters editorParameters = new EditorParameters();
ParamsWrapper parameters = new ParamsWrapper
{
ProcessId = 1,
SpanZonesAcrossMonitors = false,
Monitors = new List<NativeMonitorDataWrapper>
{
new NativeMonitorDataWrapper
{
Monitor = "monitor-1",
MonitorInstanceId = "instance-id-1",
MonitorSerialNumber = "serial-number-1",
MonitorNumber = 1,
VirtualDesktop = "{FF34D993-73F3-4B8C-AA03-73730A01D6A8}",
Dpi = 192,
LeftCoordinate = 0,
TopCoordinate = 0,
WorkAreaHeight = 1040,
WorkAreaWidth = 1920,
MonitorHeight = 1080,
MonitorWidth = 1920,
IsSelected = true,
},
},
};
FancyZonesEditorHelper.Files.ParamsIOHelper.WriteData(editorParameters.Serialize(parameters));
LayoutTemplates layoutTemplates = new LayoutTemplates();
LayoutTemplates.TemplateLayoutsListWrapper templateLayoutsListWrapper = new LayoutTemplates.TemplateLayoutsListWrapper
{
LayoutTemplates = new List<LayoutTemplates.TemplateLayoutWrapper>
{
new LayoutTemplates.TemplateLayoutWrapper
{
Type = LayoutType.Blank.TypeToString(),
},
new LayoutTemplates.TemplateLayoutWrapper
{
Type = LayoutType.Focus.TypeToString(),
ZoneCount = 10,
},
new LayoutTemplates.TemplateLayoutWrapper
{
Type = LayoutType.Rows.TypeToString(),
ZoneCount = 2,
ShowSpacing = true,
Spacing = 10,
SensitivityRadius = 10,
},
new LayoutTemplates.TemplateLayoutWrapper
{
Type = LayoutType.Columns.TypeToString(),
ZoneCount = 2,
ShowSpacing = true,
Spacing = 20,
SensitivityRadius = 20,
},
new LayoutTemplates.TemplateLayoutWrapper
{
Type = LayoutType.Grid.TypeToString(),
ZoneCount = 4,
ShowSpacing = false,
Spacing = 10,
SensitivityRadius = 30,
},
new LayoutTemplates.TemplateLayoutWrapper
{
Type = LayoutType.PriorityGrid.TypeToString(),
ZoneCount = 3,
ShowSpacing = true,
Spacing = 1,
SensitivityRadius = 40,
},
},
};
FancyZonesEditorHelper.Files.LayoutTemplatesIOHelper.WriteData(layoutTemplates.Serialize(templateLayoutsListWrapper));
CustomLayouts customLayouts = new CustomLayouts();
FancyZonesEditorHelper.Files.CustomLayoutsIOHelper.WriteData(customLayouts.Serialize(Layouts));
DefaultLayouts defaultLayouts = new DefaultLayouts();
DefaultLayouts.DefaultLayoutsListWrapper defaultLayoutsListWrapper = new DefaultLayouts.DefaultLayoutsListWrapper
{
DefaultLayouts = new List<DefaultLayouts.DefaultLayoutWrapper> { },
};
FancyZonesEditorHelper.Files.DefaultLayoutsIOHelper.WriteData(defaultLayouts.Serialize(defaultLayoutsListWrapper));
LayoutHotkeys layoutHotkeys = new LayoutHotkeys();
LayoutHotkeys.LayoutHotkeysWrapper layoutHotkeysWrapper = new LayoutHotkeys.LayoutHotkeysWrapper
{
LayoutHotkeys = new List<LayoutHotkeys.LayoutHotkeyWrapper> { },
};
FancyZonesEditorHelper.Files.LayoutHotkeysIOHelper.WriteData(layoutHotkeys.Serialize(layoutHotkeysWrapper));
AppliedLayouts appliedLayouts = new AppliedLayouts();
AppliedLayouts.AppliedLayoutsListWrapper appliedLayoutsWrapper = new AppliedLayouts.AppliedLayoutsListWrapper
{
AppliedLayouts = new List<AppliedLayouts.AppliedLayoutWrapper> { },
};
FancyZonesEditorHelper.Files.AppliedLayoutsIOHelper.WriteData(appliedLayouts.Serialize(appliedLayoutsWrapper));
this.RestartScopeExe();
}
[TestMethod("FancyZonesEditor.Basic.OpenEditMode")]
[TestCategory("FancyZones Editor #7")]
public void OpenEditMode()
{
Session.Find<Element>(Layouts.CustomLayouts[0].Name).Find<Button>(By.AccessibilityId(AccessibilityId.EditLayoutButton)).Click();
Session.Find<Button>(By.AccessibilityId(AccessibilityId.EditZonesButton)).Click();
Assert.IsNotNull(Session.Find<Element>(ElementName.GridLayoutEditor));
Session.Find<Button>(ElementName.Cancel).Click();
}
[TestMethod("FancyZonesEditor.Basic.OpenEditModeFromContextMenu")]
[TestCategory("FancyZones Editor #7")]
public void OpenEditModeFromContextMenu()
{
FancyZonesEditorHelper.ClickContextMenuItem(Session, Layouts.CustomLayouts[0].Name, FancyZonesEditorHelper.ElementName.EditZones);
Assert.IsNotNull(Session.Find<Element>(ElementName.GridLayoutEditor));
Session.Find<Button>(ElementName.Cancel).Click();
}
[TestMethod("FancyZonesEditor.Basic.Canvas_AddZone_Save")]
[TestCategory("FancyZones Editor #7")]
public void Canvas_AddZone_Save()
{
var canvas = Layouts.CustomLayouts.Find(x => x.Type == CustomLayout.Canvas.TypeToString());
FancyZonesEditorHelper.ClickContextMenuItem(Session, canvas.Name, FancyZonesEditorHelper.ElementName.EditZones);
Session.Find<Button>(By.AccessibilityId(AccessibilityId.NewZoneButton)).Click();
Session.Find<Button>(ElementName.Save).Click();
// check the file
var customLayouts = new CustomLayouts();
var data = customLayouts.Read(customLayouts.File);
var expected = customLayouts.CanvasFromJsonElement(canvas.Info.ToString());
var actual = customLayouts.CanvasFromJsonElement(data.CustomLayouts.Find(x => x.Uuid == canvas.Uuid).Info.GetRawText());
Assert.AreEqual(expected.Zones.Count + 1, actual.Zones.Count);
}
[TestMethod("FancyZonesEditor.Basic.Canvas_AddZone_Cancel")]
[TestCategory("FancyZones Editor #7")]
public void Canvas_AddZone_Cancel()
{
var canvas = Layouts.CustomLayouts.Find(x => x.Type == CustomLayout.Canvas.TypeToString());
FancyZonesEditorHelper.ClickContextMenuItem(Session, canvas.Name, FancyZonesEditorHelper.ElementName.EditZones);
Session.Find<Button>(By.AccessibilityId(AccessibilityId.NewZoneButton)).Click();
Session.Find<Button>(ElementName.Cancel).Click();
// check the file
var customLayouts = new CustomLayouts();
var data = customLayouts.Read(customLayouts.File);
var expected = customLayouts.CanvasFromJsonElement(canvas.Info.ToString());
var actual = customLayouts.CanvasFromJsonElement(data.CustomLayouts.Find(x => x.Uuid == canvas.Uuid).Info.GetRawText());
Assert.AreEqual(expected.Zones.Count, actual.Zones.Count);
}
[TestMethod("FancyZonesEditor.Basic.Canvas_DeleteZone_Save")]
[TestCategory("FancyZones Editor #7")]
public void Canvas_DeleteZone_Save()
{
var canvas = Layouts.CustomLayouts.Find(x => x.Type == CustomLayout.Canvas.TypeToString());
FancyZonesEditorHelper.ClickContextMenuItem(Session, canvas.Name, FancyZonesEditorHelper.ElementName.EditZones);
FancyZonesEditorHelper.ClickDeleteZone(Session, 1);
Session.Find<Button>(ElementName.Save).Click();
// check the file
var customLayouts = new CustomLayouts();
var data = customLayouts.Read(customLayouts.File);
var expected = customLayouts.CanvasFromJsonElement(canvas.Info.ToString());
var actual = customLayouts.CanvasFromJsonElement(data.CustomLayouts.Find(x => x.Uuid == canvas.Uuid).Info.GetRawText());
Assert.AreEqual(expected.Zones.Count - 1, actual.Zones.Count);
}
[TestMethod("FancyZonesEditor.Basic.Canvas_DeleteZone_Cancel")]
[TestCategory("FancyZones Editor #7")]
public void Canvas_DeleteZone_Cancel()
{
var canvas = Layouts.CustomLayouts.Find(x => x.Type == CustomLayout.Canvas.TypeToString());
FancyZonesEditorHelper.ClickContextMenuItem(Session, canvas.Name, FancyZonesEditorHelper.ElementName.EditZones);
FancyZonesEditorHelper.ClickDeleteZone(Session, 1);
Session.Find<Button>(ElementName.Cancel).Click();
// check the file
var customLayouts = new CustomLayouts();
var data = customLayouts.Read(customLayouts.File);
var expected = customLayouts.CanvasFromJsonElement(canvas.Info.ToString());
var actual = customLayouts.CanvasFromJsonElement(data.CustomLayouts.Find(x => x.Uuid == canvas.Uuid).Info.GetRawText());
Assert.AreEqual(expected.Zones.Count, actual.Zones.Count);
}
[TestMethod("FancyZonesEditor.Basic.Canvas_MoveZone_Save")]
[TestCategory("FancyZones Editor #7")]
public void Canvas_MoveZone_Save()
{
int zoneNumber = 1;
int xOffset = 100;
int yOffset = 100;
var canvas = Layouts.CustomLayouts.Find(x => x.Type == CustomLayout.Canvas.TypeToString());
FancyZonesEditorHelper.ClickContextMenuItem(Session, canvas.Name, FancyZonesEditorHelper.ElementName.EditZones);
FancyZonesEditorHelper.GetZone(Session, zoneNumber, FancyZonesEditorHelper.ClassName.CanvasZone)?.Drag(xOffset, yOffset);
Session.Find<Button>(ElementName.Save).Click();
// check the file
var customLayouts = new CustomLayouts();
var data = customLayouts.Read(customLayouts.File);
var expected = customLayouts.CanvasFromJsonElement(canvas.Info.ToString());
var actual = customLayouts.CanvasFromJsonElement(data.CustomLayouts.Find(x => x.Uuid == canvas.Uuid).Info.GetRawText());
// changed zone, exact offset may vary depending on screen resolution
Assert.IsTrue(expected.Zones[zoneNumber - 1].X < actual.Zones[zoneNumber - 1].X, $"X: {expected.Zones[zoneNumber - 1].X} > {actual.Zones[zoneNumber - 1].X}");
Assert.IsTrue(expected.Zones[zoneNumber - 1].Y < actual.Zones[zoneNumber - 1].Y, $"Y: {expected.Zones[zoneNumber - 1].Y} > {actual.Zones[zoneNumber - 1].Y}");
Assert.AreEqual(expected.Zones[zoneNumber - 1].Width, actual.Zones[zoneNumber - 1].Width);
Assert.AreEqual(expected.Zones[zoneNumber - 1].Height, actual.Zones[zoneNumber - 1].Height);
// other zones
for (int i = 0; i < expected.Zones.Count; i++)
{
if (i != zoneNumber - 1)
{
Assert.AreEqual(expected.Zones[i].X, actual.Zones[i].X);
Assert.AreEqual(expected.Zones[i].Y, actual.Zones[i].Y);
Assert.AreEqual(expected.Zones[i].Width, actual.Zones[i].Width);
Assert.AreEqual(expected.Zones[i].Height, actual.Zones[i].Height);
}
}
}
[TestMethod("FancyZonesEditor.Basic.Canvas_MoveZone_Cancel")]
[TestCategory("FancyZones Editor #7")]
public void Canvas_MoveZone_Cancel()
{
int zoneNumber = 1;
var canvas = Layouts.CustomLayouts.Find(x => x.Type == CustomLayout.Canvas.TypeToString());
FancyZonesEditorHelper.ClickContextMenuItem(Session, canvas.Name, FancyZonesEditorHelper.ElementName.EditZones);
FancyZonesEditorHelper.GetZone(Session, zoneNumber, FancyZonesEditorHelper.ClassName.CanvasZone)?.Drag(100, 100);
Session.Find<Button>(ElementName.Cancel).Click();
// check the file
var customLayouts = new CustomLayouts();
var data = customLayouts.Read(customLayouts.File);
var expected = customLayouts.CanvasFromJsonElement(canvas.Info.ToString());
var actual = customLayouts.CanvasFromJsonElement(data.CustomLayouts.Find(x => x.Uuid == canvas.Uuid).Info.GetRawText());
for (int i = 0; i < expected.Zones.Count; i++)
{
Assert.AreEqual(expected.Zones[i].X, actual.Zones[i].X);
Assert.AreEqual(expected.Zones[i].Y, actual.Zones[i].Y);
Assert.AreEqual(expected.Zones[i].Width, actual.Zones[i].Width);
Assert.AreEqual(expected.Zones[i].Height, actual.Zones[i].Height);
}
}
[TestMethod("FancyZonesEditor.Basic.Canvas_ResizeZone_Save")]
[TestCategory("FancyZones Editor #7")]
public void Canvas_ResizeZone_Save()
{
int zoneNumber = 1;
int xOffset = 100;
int yOffset = 100;
var canvas = Layouts.CustomLayouts.Find(x => x.Type == CustomLayout.Canvas.TypeToString());
FancyZonesEditorHelper.ClickContextMenuItem(Session, canvas.Name, FancyZonesEditorHelper.ElementName.EditZones);
FancyZonesEditorHelper.GetZone(Session, zoneNumber, FancyZonesEditorHelper.ClassName.CanvasZone)?.Find<Thumb>(By.AccessibilityId(FancyZonesEditorHelper.AccessibilityId.TopRightCorner)).Drag(xOffset, yOffset);
Session.Find<Button>(ElementName.Save).Click();
// check the file
var customLayouts = new CustomLayouts();
var data = customLayouts.Read(customLayouts.File);
var expected = customLayouts.CanvasFromJsonElement(canvas.Info.ToString());
var actual = customLayouts.CanvasFromJsonElement(data.CustomLayouts.Find(x => x.Uuid == canvas.Uuid).Info.GetRawText());
// changed zone, exact offset may vary depending on screen resolution
Assert.AreEqual(expected.Zones[zoneNumber - 1].X, actual.Zones[zoneNumber - 1].X);
Assert.IsTrue(expected.Zones[zoneNumber - 1].Y < actual.Zones[zoneNumber - 1].Y, $"Y: {expected.Zones[zoneNumber - 1].Y} > {actual.Zones[zoneNumber - 1].Y}");
Assert.IsTrue(expected.Zones[zoneNumber - 1].Width < actual.Zones[zoneNumber - 1].Width, $"Width: {expected.Zones[zoneNumber - 1].Width} < {actual.Zones[zoneNumber - 1].Width}");
Assert.IsTrue(expected.Zones[zoneNumber - 1].Height > actual.Zones[zoneNumber - 1].Height, $"Height: {expected.Zones[zoneNumber - 1].Height} < {actual.Zones[zoneNumber - 1].Height}");
// other zones
for (int i = 0; i < expected.Zones.Count; i++)
{
if (i != zoneNumber - 1)
{
Assert.AreEqual(expected.Zones[i].X, actual.Zones[i].X);
Assert.AreEqual(expected.Zones[i].Y, actual.Zones[i].Y);
Assert.AreEqual(expected.Zones[i].Width, actual.Zones[i].Width);
Assert.AreEqual(expected.Zones[i].Height, actual.Zones[i].Height);
}
}
}
[TestMethod("FancyZonesEditor.Basic.Canvas_ResizeZone_Cancel")]
[TestCategory("FancyZones Editor #7")]
public void Canvas_ResizeZone_Cancel()
{
int zoneNumber = 1;
int xOffset = 100;
int yOffset = 100;
var canvas = Layouts.CustomLayouts.Find(x => x.Type == CustomLayout.Canvas.TypeToString());
FancyZonesEditorHelper.ClickContextMenuItem(Session, canvas.Name, FancyZonesEditorHelper.ElementName.EditZones);
FancyZonesEditorHelper.GetZone(Session, zoneNumber, FancyZonesEditorHelper.ClassName.CanvasZone)?.Find<Thumb>(By.AccessibilityId(FancyZonesEditorHelper.AccessibilityId.TopRightCorner)).Drag(xOffset, yOffset);
Session.Find<Button>(ElementName.Cancel).Click();
// check the file
var customLayouts = new CustomLayouts();
var data = customLayouts.Read(customLayouts.File);
var expected = customLayouts.CanvasFromJsonElement(canvas.Info.ToString());
var actual = customLayouts.CanvasFromJsonElement(data.CustomLayouts.Find(x => x.Uuid == canvas.Uuid).Info.GetRawText());
for (int i = 0; i < expected.Zones.Count; i++)
{
Assert.AreEqual(expected.Zones[i].X, actual.Zones[i].X);
Assert.AreEqual(expected.Zones[i].Y, actual.Zones[i].Y);
Assert.AreEqual(expected.Zones[i].Width, actual.Zones[i].Width);
Assert.AreEqual(expected.Zones[i].Height, actual.Zones[i].Height);
}
}
[TestMethod("FancyZonesEditor.Basic.Grid_SplitZone_Save")]
[TestCategory("FancyZones Editor #8")]
public void Grid_SplitZone_Save()
{
int zoneNumber = 1;
var grid = Layouts.CustomLayouts.Find(x => x.Type == CustomLayout.Grid.TypeToString());
FancyZonesEditorHelper.ClickContextMenuItem(Session, grid.Name, FancyZonesEditorHelper.ElementName.EditZones);
FancyZonesEditorHelper.GetZone(Session, zoneNumber, FancyZonesEditorHelper.ClassName.GridZone)?.Click(); // horizontal split in the middle of the zone
Session.Find<Button>(ElementName.Save).Click();
// check the file
var customLayouts = new CustomLayouts();
var data = customLayouts.Read(customLayouts.File);
var expected = customLayouts.GridFromJsonElement(grid.Info.ToString());
var actual = customLayouts.GridFromJsonElement(data.CustomLayouts.Find(x => x.Uuid == grid.Uuid).Info.GetRawText());
// new column added
Assert.AreEqual(expected.Columns + 1, actual.Columns);
Assert.AreEqual(expected.ColumnsPercentage[0], actual.ColumnsPercentage[0] + actual.ColumnsPercentage[1]);
Assert.AreEqual(expected.ColumnsPercentage[1], actual.ColumnsPercentage[2]);
// rows are not changed
Assert.AreEqual(expected.Rows, actual.Rows);
for (int i = 0; i < expected.Rows; i++)
{
Assert.AreEqual(expected.RowsPercentage[i], actual.RowsPercentage[i]);
}
}
[TestMethod("FancyZonesEditor.Basic.Grid_SplitZone_Cancel")]
[TestCategory("FancyZones Editor #8")]
public void Grid_SplitZone_Cancel()
{
int zoneNumber = 1;
var grid = Layouts.CustomLayouts.Find(x => x.Type == CustomLayout.Grid.TypeToString());
FancyZonesEditorHelper.ClickContextMenuItem(Session, grid.Name, FancyZonesEditorHelper.ElementName.EditZones);
FancyZonesEditorHelper.GetZone(Session, zoneNumber, FancyZonesEditorHelper.ClassName.GridZone)?.Click(); // horizontal split in the middle of the zone
Session.Find<Button>(ElementName.Cancel).Click();
// check the file
var customLayouts = new CustomLayouts();
var data = customLayouts.Read(customLayouts.File);
var expected = customLayouts.GridFromJsonElement(grid.Info.ToString());
var actual = customLayouts.GridFromJsonElement(data.CustomLayouts.Find(x => x.Uuid == grid.Uuid).Info.GetRawText());
// columns are not changed
Assert.AreEqual(expected.Columns, actual.Columns);
for (int i = 0; i < expected.Columns; i++)
{
Assert.AreEqual(expected.ColumnsPercentage[i], actual.ColumnsPercentage[i]);
}
// rows are not changed
Assert.AreEqual(expected.Rows, actual.Rows);
for (int i = 0; i < expected.Rows; i++)
{
Assert.AreEqual(expected.RowsPercentage[i], actual.RowsPercentage[i]);
}
}
[TestMethod("FancyZonesEditor.Basic.Grid_MergeZones_Save")]
[TestCategory("FancyZones Editor #8")]
public void Grid_MergeZones_Save()
{
var grid = Layouts.CustomLayouts.Find(x => x.Type == CustomLayout.Grid.TypeToString());
FancyZonesEditorHelper.ClickContextMenuItem(Session, grid.Name, FancyZonesEditorHelper.ElementName.EditZones);
FancyZonesEditorHelper.MergeGridZones(Session, 1, 2);
Session.Find<Button>(ElementName.Save).Click();
// check the file
var customLayouts = new CustomLayouts();
var data = customLayouts.Read(customLayouts.File);
var expected = customLayouts.GridFromJsonElement(grid.Info.ToString());
var actual = customLayouts.GridFromJsonElement(data.CustomLayouts.Find(x => x.Uuid == grid.Uuid).Info.GetRawText());
// columns are not changed
Assert.AreEqual(expected.Columns, actual.Columns);
for (int i = 0; i < expected.Columns; i++)
{
Assert.AreEqual(expected.ColumnsPercentage[i], actual.ColumnsPercentage[i]);
}
// rows are not changed
Assert.AreEqual(expected.Rows, actual.Rows);
for (int i = 0; i < expected.Rows; i++)
{
Assert.AreEqual(expected.RowsPercentage[i], actual.RowsPercentage[i]);
}
// cells are updated to [0,0][1,2]
Assert.IsTrue(actual.CellChildMap[0].SequenceEqual([0, 0]));
Assert.IsTrue(actual.CellChildMap[1].SequenceEqual([1, 2]));
}
[TestMethod("FancyZonesEditor.Basic.Grid_MergeZones_Cancel")]
[TestCategory("FancyZones Editor #8")]
public void Grid_MergeZones_Cancel()
{
var grid = Layouts.CustomLayouts.Find(x => x.Type == CustomLayout.Grid.TypeToString());
FancyZonesEditorHelper.ClickContextMenuItem(Session, grid.Name, FancyZonesEditorHelper.ElementName.EditZones);
FancyZonesEditorHelper.MergeGridZones(Session, 1, 2);
Session.Find<Button>(ElementName.Cancel).Click();
// check the file
var customLayouts = new CustomLayouts();
var data = customLayouts.Read(customLayouts.File);
var expected = customLayouts.GridFromJsonElement(grid.Info.ToString());
var actual = customLayouts.GridFromJsonElement(data.CustomLayouts.Find(x => x.Uuid == grid.Uuid).Info.GetRawText());
// columns are not changed
Assert.AreEqual(expected.Columns, actual.Columns);
for (int i = 0; i < expected.Columns; i++)
{
Assert.AreEqual(expected.ColumnsPercentage[i], actual.ColumnsPercentage[i]);
}
// rows are not changed
Assert.AreEqual(expected.Rows, actual.Rows);
for (int i = 0; i < expected.Rows; i++)
{
Assert.AreEqual(expected.RowsPercentage[i], actual.RowsPercentage[i]);
}
// cells are not changed
for (int i = 0; i < expected.CellChildMap.Length; i++)
{
Assert.IsTrue(actual.CellChildMap[i].SequenceEqual(expected.CellChildMap[i]));
}
}
[TestMethod("FancyZonesEditor.Basic.Grid_MoveSplitter_Save")]
[TestCategory("FancyZones Editor #8")]
public void Grid_MoveSplitter_Save()
{
EditorParameters editorParameters = new EditorParameters();
ParamsWrapper parameters = new ParamsWrapper
{
ProcessId = 1,
SpanZonesAcrossMonitors = false,
Monitors = new List<NativeMonitorDataWrapper>
{
new NativeMonitorDataWrapper
{
Monitor = "monitor-1",
MonitorInstanceId = "instance-id-1",
MonitorSerialNumber = "serial-number-1",
MonitorNumber = 1,
VirtualDesktop = "{FF34D993-73F3-4B8C-AA03-73730A01D6A8}",
Dpi = 192,
LeftCoordinate = 0,
TopCoordinate = 0,
WorkAreaHeight = 780,
WorkAreaWidth = 1240,
MonitorHeight = 780,
MonitorWidth = 1240,
IsSelected = true,
},
},
};
FancyZonesEditorHelper.Files.ParamsIOHelper.WriteData(editorParameters.Serialize(parameters));
this.RestartScopeExe();
var grid = Layouts.CustomLayouts.Find(x => x.Type == CustomLayout.Grid.TypeToString() && x.Name == "Grid-9");
FancyZonesEditorHelper.ClickContextMenuItem(Session, grid.Name, FancyZonesEditorHelper.ElementName.EditZones);
FancyZonesEditorHelper.MoveSplitter(Session, 2, -50, 0);
Session.Find<Button>(ElementName.Save).Click();
// check the file
var customLayouts = new CustomLayouts();
var data = customLayouts.Read(customLayouts.File);
var expected = customLayouts.GridFromJsonElement(grid.Info.ToString());
var actual = customLayouts.GridFromJsonElement(data.CustomLayouts.Find(x => x.Uuid == grid.Uuid).Info.GetRawText());
// rows are not changed
Assert.AreEqual(expected.Rows, actual.Rows);
for (int i = 0; i < expected.Rows; i++)
{
Assert.AreEqual(expected.RowsPercentage[i], actual.RowsPercentage[i]);
}
// Columns are changed
Assert.AreEqual(expected.Columns, actual.Columns);
Assert.IsTrue(expected.ColumnsPercentage[0] > actual.ColumnsPercentage[0], $"{expected.ColumnsPercentage[0]} > {actual.ColumnsPercentage[0]}");
Assert.IsTrue(expected.ColumnsPercentage[1] < actual.ColumnsPercentage[1], $"{expected.ColumnsPercentage[1]} < {actual.ColumnsPercentage[1]}");
Assert.AreEqual(expected.ColumnsPercentage[2], actual.ColumnsPercentage[2], $"{expected.ColumnsPercentage[2]} == {actual.ColumnsPercentage[2]}");
// cells are not changed
for (int i = 0; i < expected.CellChildMap.Length; i++)
{
Assert.IsTrue(actual.CellChildMap[i].SequenceEqual(expected.CellChildMap[i]));
}
}
[TestMethod("FancyZonesEditor.Basic.Grid_MoveSplitter_Cancel")]
[TestCategory("FancyZones Editor #8")]
public void Grid_MoveSplitter_Cancel()
{
var grid = Layouts.CustomLayouts.Find(x => x.Type == CustomLayout.Grid.TypeToString() && x.Name == "Grid-9");
FancyZonesEditorHelper.ClickContextMenuItem(Session, grid.Name, FancyZonesEditorHelper.ElementName.EditZones);
FancyZonesEditorHelper.MoveSplitter(Session, 2, -100, 0);
Session.Find<Button>(ElementName.Cancel).Click();
// check the file
var customLayouts = new CustomLayouts();
var data = customLayouts.Read(customLayouts.File);
var expected = customLayouts.GridFromJsonElement(grid.Info.ToString());
var actual = customLayouts.GridFromJsonElement(data.CustomLayouts.Find(x => x.Uuid == grid.Uuid).Info.GetRawText());
// columns are not changed
Assert.AreEqual(expected.Columns, actual.Columns);
for (int i = 0; i < expected.Columns; i++)
{
Assert.AreEqual(expected.ColumnsPercentage[i], actual.ColumnsPercentage[i]);
}
// rows are not changed
Assert.AreEqual(expected.Rows, actual.Rows);
for (int i = 0; i < expected.Rows; i++)
{
Assert.AreEqual(expected.RowsPercentage[i], actual.RowsPercentage[i]);
}
// cells are not changed
for (int i = 0; i < expected.CellChildMap.Length; i++)
{
Assert.IsTrue(actual.CellChildMap[i].SequenceEqual(expected.CellChildMap[i]));
}
}
}
}

View File

@@ -0,0 +1,37 @@
<Project Sdk="Microsoft.NET.Sdk">
<!-- Look at Directory.Build.props in root for common stuff as well -->
<Import Project="..\..\..\Common.Dotnet.CsWinRT.props" />
<PropertyGroup>
<ProjectGuid>{9BAFFC28-E1EF-4C14-A101-EEBFC0A50D83}</ProjectGuid>
<RootNamespace>Microsoft.FancyZonesEditor.UITests</RootNamespace>
<IsPackable>false</IsPackable>
<Nullable>enable</Nullable>
<OutputType>Library</OutputType>
<!-- This is a UI test, so don't run as part of MSBuild -->
<RunVSTest>false</RunVSTest>
</PropertyGroup>
<PropertyGroup>
<OutputPath>..\..\..\..\$(Platform)\$(Configuration)\tests\UITests-FancyZonesEditor\</OutputPath>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Appium.WebDriver" />
<PackageReference Include="MSTest" />
<PackageReference Include="System.IO.Abstractions" />
<PackageReference Include="System.Net.Http" />
<PackageReference Include="System.Private.Uri" />
<PackageReference Include="System.Text.RegularExpressions" />
</ItemGroup>
<ItemGroup>
<Folder Include="Properties\" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\editor\FancyZonesEditor\FancyZonesEditor.csproj" />
<ProjectReference Include="..\..\..\common\UITestAutomation\UITestAutomation.csproj" />
</ItemGroup>
</Project>

View File

@@ -0,0 +1,152 @@
// Copyright (c) Microsoft Corporation
// The Microsoft Corporation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information.
using System.Collections.Generic;
using System.Globalization;
using System.Windows.Forms;
using System.Xml.Linq;
using FancyZonesEditor.Models;
using FancyZonesEditorCommon.Data;
using Microsoft.FancyZonesEditor.UITests;
using Microsoft.FancyZonesEditor.UITests.Utils;
using Microsoft.FancyZonesEditor.UnitTests.Utils;
using Microsoft.PowerToys.UITest;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using ModernWpf.Controls;
using Windows.UI;
using static FancyZonesEditorCommon.Data.EditorParameters;
using static Microsoft.ApplicationInsights.MetricDimensionNames.TelemetryContext;
using static Microsoft.FancyZonesEditor.UnitTests.Utils.FancyZonesEditorHelper;
namespace Microsoft.FancyZonesEditor.UITests
{
[TestClass]
public class FirstLunchTest : UITestBase
{
public FirstLunchTest()
: base(PowerToysModule.FancyZone, WindowSize.UnSpecified)
{
}
[TestInitialize]
public void TestInitialize()
{
FancyZonesEditorHelper.Files.Restore();
EditorParameters editorParameters = new EditorParameters();
ParamsWrapper parameters = new ParamsWrapper
{
ProcessId = 1,
SpanZonesAcrossMonitors = false,
Monitors = new List<NativeMonitorDataWrapper>
{
new NativeMonitorDataWrapper
{
Monitor = "monitor-1",
MonitorInstanceId = "instance-id-1",
MonitorSerialNumber = "serial-number-1",
MonitorNumber = 1,
VirtualDesktop = "{FF34D993-73F3-4B8C-AA03-73730A01D6A8}",
Dpi = 192, // 200% scaling
LeftCoordinate = 0,
TopCoordinate = 0,
WorkAreaHeight = 1040,
WorkAreaWidth = 1920,
MonitorHeight = 1080,
MonitorWidth = 1920,
IsSelected = true,
},
},
};
FancyZonesEditorHelper.Files.ParamsIOHelper.WriteData(editorParameters.Serialize(parameters));
DefaultLayouts defaultLayouts = new DefaultLayouts();
DefaultLayouts.DefaultLayoutsListWrapper defaultLayoutsListWrapper = new DefaultLayouts.DefaultLayoutsListWrapper
{
DefaultLayouts = new List<DefaultLayouts.DefaultLayoutWrapper> { },
};
FancyZonesEditorHelper.Files.DefaultLayoutsIOHelper.WriteData(defaultLayouts.Serialize(defaultLayoutsListWrapper));
LayoutHotkeys layoutHotkeys = new LayoutHotkeys();
LayoutHotkeys.LayoutHotkeysWrapper layoutHotkeysWrapper = new LayoutHotkeys.LayoutHotkeysWrapper
{
LayoutHotkeys = new List<LayoutHotkeys.LayoutHotkeyWrapper> { },
};
FancyZonesEditorHelper.Files.LayoutHotkeysIOHelper.WriteData(layoutHotkeys.Serialize(layoutHotkeysWrapper));
AppliedLayouts appliedLayouts = new AppliedLayouts();
AppliedLayouts.AppliedLayoutsListWrapper appliedLayoutsWrapper = new AppliedLayouts.AppliedLayoutsListWrapper
{
AppliedLayouts = new List<AppliedLayouts.AppliedLayoutWrapper> { },
};
FancyZonesEditorHelper.Files.AppliedLayoutsIOHelper.WriteData(appliedLayouts.Serialize(appliedLayoutsWrapper));
CustomLayouts customLayouts = new CustomLayouts();
CustomLayouts.CustomLayoutListWrapper customLayoutListWrapper = new CustomLayouts.CustomLayoutListWrapper
{
CustomLayouts = new List<CustomLayouts.CustomLayoutWrapper> { },
};
FancyZonesEditorHelper.Files.CustomLayoutsIOHelper.WriteData(customLayouts.Serialize(customLayoutListWrapper));
LayoutTemplates layoutTemplates = new LayoutTemplates();
LayoutTemplates.TemplateLayoutsListWrapper templateLayoutsListWrapper = new LayoutTemplates.TemplateLayoutsListWrapper
{
LayoutTemplates = new List<LayoutTemplates.TemplateLayoutWrapper>
{
new LayoutTemplates.TemplateLayoutWrapper
{
Type = LayoutType.Blank.TypeToString(),
},
new LayoutTemplates.TemplateLayoutWrapper
{
Type = LayoutType.Focus.TypeToString(),
ZoneCount = 10,
},
new LayoutTemplates.TemplateLayoutWrapper
{
Type = LayoutType.Rows.TypeToString(),
ZoneCount = 2,
ShowSpacing = true,
Spacing = 10,
SensitivityRadius = 10,
},
new LayoutTemplates.TemplateLayoutWrapper
{
Type = LayoutType.Columns.TypeToString(),
ZoneCount = 2,
ShowSpacing = true,
Spacing = 20,
SensitivityRadius = 20,
},
new LayoutTemplates.TemplateLayoutWrapper
{
Type = LayoutType.Grid.TypeToString(),
ZoneCount = 4,
ShowSpacing = false,
Spacing = 10,
SensitivityRadius = 30,
},
new LayoutTemplates.TemplateLayoutWrapper
{
Type = LayoutType.PriorityGrid.TypeToString(),
ZoneCount = 3,
ShowSpacing = true,
Spacing = 1,
SensitivityRadius = 40,
},
},
};
FancyZonesEditorHelper.Files.LayoutTemplatesIOHelper.WriteData(layoutTemplates.Serialize(templateLayoutsListWrapper));
// verify editor opens without errors
this.RestartScopeExe();
}
[TestMethod]
public void FirstLaunch()
{
Session.Find<Element>(By.AccessibilityId(FancyZonesEditorHelper.AccessibilityId.MainWindow)).Click();
Assert.IsNotNull(Session.Find<Element>(By.AccessibilityId(FancyZonesEditorHelper.AccessibilityId.MainWindow)));
}
}
}

View File

@@ -0,0 +1,36 @@
// Copyright (c) Microsoft Corporation
// The Microsoft Corporation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information.
using System.Diagnostics;
using Microsoft.VisualStudio.TestTools.UnitTesting;
namespace Microsoft.FancyZonesEditor.UITests
{
[TestClass]
public class Init
{
private static Process? appDriver;
[AssemblyInitialize]
public static void SetupAll(TestContext context)
{
string winAppDriverPath = "C:\\Program Files (x86)\\Windows Application Driver\\WinAppDriver.exe";
context.WriteLine($"Attempting to launch WinAppDriver at: {winAppDriverPath}");
appDriver = Process.Start(winAppDriverPath);
}
[AssemblyCleanup]
public static void CleanupAll()
{
try
{
appDriver?.Kill();
}
catch
{
}
}
}
}

View File

@@ -0,0 +1,469 @@
// Copyright (c) Microsoft Corporation
// The Microsoft Corporation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information.
using System;
using System.Collections.Generic;
using System.Globalization;
using System.Linq;
using FancyZonesEditor.Models;
using FancyZonesEditorCommon.Data;
using Microsoft.FancyZonesEditor.UnitTests.Utils;
using Microsoft.PowerToys.UITest;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using ModernWpf.Controls;
using static FancyZonesEditorCommon.Data.CustomLayouts;
using static FancyZonesEditorCommon.Data.EditorParameters;
using static FancyZonesEditorCommon.Data.LayoutHotkeys;
using static Microsoft.FancyZonesEditor.UnitTests.Utils.FancyZonesEditorHelper;
namespace Microsoft.FancyZonesEditor.UITests
{
[TestClass]
public class LayoutHotkeysTests : UITestBase
{
public LayoutHotkeysTests()
: base(PowerToysModule.FancyZone, WindowSize.UnSpecified)
{
}
private static readonly CustomLayoutListWrapper CustomLayouts = new CustomLayoutListWrapper
{
CustomLayouts = new List<CustomLayoutWrapper>
{
new CustomLayoutWrapper
{
Uuid = "{0D6D2F58-9184-4804-81E4-4E4CC3476DC1}",
Type = CustomLayout.Canvas.TypeToString(),
Name = "Layout 0",
Info = new CustomLayouts().ToJsonElement(new CanvasInfoWrapper
{
RefHeight = 1080,
RefWidth = 1920,
SensitivityRadius = 10,
Zones = new List<CanvasInfoWrapper.CanvasZoneWrapper> { },
}),
},
new CustomLayoutWrapper
{
Uuid = "{E7807D0D-6223-4883-B15B-1F3883944C09}",
Type = CustomLayout.Canvas.TypeToString(),
Name = "Layout 1",
Info = new CustomLayouts().ToJsonElement(new CanvasInfoWrapper
{
RefHeight = 1080,
RefWidth = 1920,
SensitivityRadius = 10,
Zones = new List<CanvasInfoWrapper.CanvasZoneWrapper> { },
}),
},
new CustomLayoutWrapper
{
Uuid = "{F1A94F38-82B6-4876-A653-70D0E882DE2A}",
Type = CustomLayout.Canvas.TypeToString(),
Name = "Layout 2",
Info = new CustomLayouts().ToJsonElement(new CanvasInfoWrapper
{
RefHeight = 1080,
RefWidth = 1920,
SensitivityRadius = 10,
Zones = new List<CanvasInfoWrapper.CanvasZoneWrapper> { },
}),
},
new CustomLayoutWrapper
{
Uuid = "{F5FDBC04-0760-4776-9F05-96AAC4AE613F}",
Type = CustomLayout.Canvas.TypeToString(),
Name = "Layout 3",
Info = new CustomLayouts().ToJsonElement(new CanvasInfoWrapper
{
RefHeight = 1080,
RefWidth = 1920,
SensitivityRadius = 10,
Zones = new List<CanvasInfoWrapper.CanvasZoneWrapper> { },
}),
},
},
};
private static readonly LayoutHotkeysWrapper Hotkeys = new LayoutHotkeysWrapper
{
LayoutHotkeys = new List<LayoutHotkeyWrapper>
{
new LayoutHotkeyWrapper
{
LayoutId = "{0D6D2F58-9184-4804-81E4-4E4CC3476DC1}",
Key = 0,
},
new LayoutHotkeyWrapper
{
LayoutId = "{E7807D0D-6223-4883-B15B-1F3883944C09}",
Key = 1,
},
},
};
[TestInitialize]
public void TestInitialize()
{
FancyZonesEditorHelper.Files.Restore();
EditorParameters editorParameters = new EditorParameters();
ParamsWrapper parameters = new ParamsWrapper
{
ProcessId = 1,
SpanZonesAcrossMonitors = false,
Monitors = new List<NativeMonitorDataWrapper>
{
new NativeMonitorDataWrapper
{
Monitor = "monitor-1",
MonitorInstanceId = "instance-id-1",
MonitorSerialNumber = "serial-number-1",
MonitorNumber = 1,
VirtualDesktop = "{FF34D993-73F3-4B8C-AA03-73730A01D6A8}",
Dpi = 192,
LeftCoordinate = 0,
TopCoordinate = 0,
WorkAreaHeight = 1040,
WorkAreaWidth = 1920,
MonitorHeight = 1080,
MonitorWidth = 1920,
IsSelected = true,
},
},
};
FancyZonesEditorHelper.Files.ParamsIOHelper.WriteData(editorParameters.Serialize(parameters));
CustomLayouts customLayouts = new CustomLayouts();
FancyZonesEditorHelper.Files.CustomLayoutsIOHelper.WriteData(customLayouts.Serialize(CustomLayouts));
var layoutHotkeys = new LayoutHotkeys();
FancyZonesEditorHelper.Files.LayoutHotkeysIOHelper.WriteData(layoutHotkeys.Serialize(Hotkeys));
LayoutTemplates layoutTemplates = new LayoutTemplates();
LayoutTemplates.TemplateLayoutsListWrapper templateLayoutsListWrapper = new LayoutTemplates.TemplateLayoutsListWrapper
{
LayoutTemplates = new List<LayoutTemplates.TemplateLayoutWrapper>
{
new LayoutTemplates.TemplateLayoutWrapper
{
Type = LayoutType.Blank.TypeToString(),
},
new LayoutTemplates.TemplateLayoutWrapper
{
Type = LayoutType.Focus.TypeToString(),
ZoneCount = 10,
},
new LayoutTemplates.TemplateLayoutWrapper
{
Type = LayoutType.Rows.TypeToString(),
ZoneCount = 2,
ShowSpacing = true,
Spacing = 10,
SensitivityRadius = 10,
},
new LayoutTemplates.TemplateLayoutWrapper
{
Type = LayoutType.Columns.TypeToString(),
ZoneCount = 2,
ShowSpacing = true,
Spacing = 20,
SensitivityRadius = 20,
},
new LayoutTemplates.TemplateLayoutWrapper
{
Type = LayoutType.Grid.TypeToString(),
ZoneCount = 4,
ShowSpacing = false,
Spacing = 10,
SensitivityRadius = 30,
},
new LayoutTemplates.TemplateLayoutWrapper
{
Type = LayoutType.PriorityGrid.TypeToString(),
ZoneCount = 3,
ShowSpacing = true,
Spacing = 1,
SensitivityRadius = 40,
},
},
};
FancyZonesEditorHelper.Files.LayoutTemplatesIOHelper.WriteData(layoutTemplates.Serialize(templateLayoutsListWrapper));
DefaultLayouts defaultLayouts = new DefaultLayouts();
DefaultLayouts.DefaultLayoutsListWrapper defaultLayoutsListWrapper = new DefaultLayouts.DefaultLayoutsListWrapper
{
DefaultLayouts = new List<DefaultLayouts.DefaultLayoutWrapper> { },
};
FancyZonesEditorHelper.Files.DefaultLayoutsIOHelper.WriteData(defaultLayouts.Serialize(defaultLayoutsListWrapper));
AppliedLayouts appliedLayouts = new AppliedLayouts();
AppliedLayouts.AppliedLayoutsListWrapper appliedLayoutsWrapper = new AppliedLayouts.AppliedLayoutsListWrapper
{
AppliedLayouts = new List<AppliedLayouts.AppliedLayoutWrapper> { },
};
FancyZonesEditorHelper.Files.AppliedLayoutsIOHelper.WriteData(appliedLayouts.Serialize(appliedLayoutsWrapper));
this.RestartScopeExe();
}
[TestMethod("FancyZonesEditor.Basic.HotKey_Initialize")]
[TestCategory("FancyZones Editor #11")]
public void Initialize()
{
foreach (var layout in CustomLayouts.CustomLayouts)
{
Session.Find<Element>(layout.Name).Find<Button>(By.AccessibilityId(AccessibilityId.EditLayoutButton)).Click();
var hotkeyComboBox = Session.Find<Element>(By.AccessibilityId(AccessibilityId.HotkeyComboBox));
Assert.IsNotNull(hotkeyComboBox);
// verify the selected key
string expected = "None";
if (Hotkeys.LayoutHotkeys.Any(x => x.LayoutId == layout.Uuid))
{
expected = $"{Hotkeys.LayoutHotkeys.Find(x => x.LayoutId == layout.Uuid).Key}";
}
Assert.AreEqual($"{expected}", hotkeyComboBox.Text);
// verify the available values
hotkeyComboBox.Click();
var popup = Session.Find<Element>(By.ClassName(ClassName.Popup));
Assert.IsNotNull(popup, "Hotkey combo box wasn't opened");
try
{
popup.Find<Element>(expected); // the current value should be available
// 0 and 1 are assigned, all others should be available
for (int i = 2; i < 10; i++)
{
popup.Find<Element>($"{i}");
}
}
catch
{
Assert.Fail("Hotkey is missed");
}
Session.Find<Button>(ElementName.Cancel).DoubleClick();
}
}
[TestMethod("FancyZonesEditor.Basic.HotKey_Assign_Save")]
[TestCategory("FancyZones Editor #11")]
public void Assign_Save()
{
var layout = CustomLayouts.CustomLayouts[2]; // a layout without assigned hotkey
Session.Find<Element>(layout.Name).Find<Button>(By.AccessibilityId(AccessibilityId.EditLayoutButton)).Click();
// assign hotkey
const string key = "3";
var hotkeyComboBox = Session.Find<Element>(By.AccessibilityId(AccessibilityId.HotkeyComboBox));
Assert.IsNotNull(hotkeyComboBox);
hotkeyComboBox.Click();
var popup = Session.Find<Element>(By.ClassName(ClassName.Popup));
Assert.IsNotNull(popup);
popup.Find<Element>($"{key}").Click(); // assign a free hotkey
Assert.AreEqual(key, hotkeyComboBox.Text);
// verify the file
Session.Find<Button>(ElementName.Save).Click();
var hotkeys = new LayoutHotkeys();
var actualData = hotkeys.Read(hotkeys.File);
Assert.IsTrue(actualData.LayoutHotkeys.Contains(new LayoutHotkeyWrapper { Key = int.Parse(key, CultureInfo.InvariantCulture), LayoutId = layout.Uuid }));
// verify the availability
Session.Find<Element>(CustomLayouts.CustomLayouts[3].Name).Find<Button>(By.AccessibilityId(AccessibilityId.EditLayoutButton)).Click();
hotkeyComboBox = Session.Find<Element>(By.AccessibilityId(AccessibilityId.HotkeyComboBox));
Assert.IsNotNull(hotkeyComboBox);
hotkeyComboBox.Click();
popup = Session.Find<Element>(By.ClassName(ClassName.Popup));
Assert.IsNotNull(popup);
try
{
popup.Find<Element>($"{key}"); // verify the key is not available
Assert.Fail($"{key} The assigned key is still available for other layouts.");
}
catch
{
// key not found as expected
}
}
[TestMethod("FancyZonesEditor.Basic.HotKey_Assign_Cancel")]
[TestCategory("FancyZones Editor #11")]
public void Assign_Cancel()
{
var layout = CustomLayouts.CustomLayouts[2]; // a layout without assigned hotkey
Session.Find<Element>(layout.Name).Find<Button>(By.AccessibilityId(AccessibilityId.EditLayoutButton)).Click();
// assign a hotkey
const string key = "3";
var hotkeyComboBox = Session.Find<Element>(By.AccessibilityId(AccessibilityId.HotkeyComboBox));
Assert.IsNotNull(hotkeyComboBox);
hotkeyComboBox.Click();
var popup = Session.Find<Element>(By.ClassName(ClassName.Popup));
Assert.IsNotNull(popup);
popup.Find<Element>($"{key}").Click();
Assert.AreEqual(key, hotkeyComboBox.Text);
// verify the file
Session.Find<Button>(ElementName.Cancel).Click();
var hotkeys = new LayoutHotkeys();
var actualData = hotkeys.Read(hotkeys.File);
Assert.AreEqual(Hotkeys.ToString(), actualData.ToString());
// verify the availability
Session.Find<Element>(CustomLayouts.CustomLayouts[3].Name).Find<Button>(By.AccessibilityId(AccessibilityId.EditLayoutButton)).Click();
hotkeyComboBox = Session.Find<Element>(By.AccessibilityId(AccessibilityId.HotkeyComboBox));
Assert.IsNotNull(hotkeyComboBox);
hotkeyComboBox.Click();
popup = Session.Find<Element>(By.ClassName(ClassName.Popup));
Assert.IsNotNull(popup);
try
{
popup.Find<Element>($"{key}"); // verify the key is available
}
catch
{
Assert.Fail("The key is not available for other layouts.");
}
}
[TestMethod("FancyZonesEditor.Basic.HotKey_Assign_AllPossibleValues")]
[TestCategory("FancyZones Editor #11")]
public void Assign_AllPossibleValues()
{
for (int i = 0; i < 4; i++)
{
string layoutName = $"Layout {i}";
Session.Find<Element>(layoutName).Find<Button>(By.AccessibilityId(AccessibilityId.EditLayoutButton)).Click();
var hotkeyComboBox = Session.Find<Element>(By.AccessibilityId(AccessibilityId.HotkeyComboBox));
Assert.IsNotNull(hotkeyComboBox);
hotkeyComboBox.Click();
var popup = Session.Find<Element>(By.ClassName(ClassName.Popup));
Assert.IsNotNull(popup);
popup.Find<Element>($"{i}").Click();
Session.Find<Button>(ElementName.Save).Click();
}
// check there nothing except None
{
int layout = 3;
string layoutName = $"Layout {layout}";
Session.Find<Element>(layoutName).Find<Button>(By.AccessibilityId(AccessibilityId.EditLayoutButton)).Click();
var hotkeyComboBox = Session.Find<Element>(By.AccessibilityId(AccessibilityId.HotkeyComboBox));
Assert.IsNotNull(hotkeyComboBox);
hotkeyComboBox.Click();
var popup = Session.Find<Element>(By.ClassName(ClassName.Popup));
Assert.IsNotNull(popup);
for (int i = 0; i < 10; i++)
{
try
{
popup.Find<Element>($"{i}");
Assert.Fail("The assigned key is still available for other layouts.");
}
catch
{
}
}
popup.Find<Element>($"None").Click();
Session.Find<Button>(ElementName.Save).Click();
}
}
[TestMethod("FancyZonesEditor.Basic.HotKey_Reset_Save")]
[TestCategory("FancyZones Editor #11")]
public void Reset_Save()
{
var layout = CustomLayouts.CustomLayouts[0]; // a layout with assigned hotkey
int assignedKey = Hotkeys.LayoutHotkeys.Find(x => x.LayoutId == layout.Uuid).Key;
Session.Find<Element>(layout.Name).Find<Button>(By.AccessibilityId(AccessibilityId.EditLayoutButton)).Click();
const string None = "None";
// reset the hotkey
var hotkeyComboBox = Session.Find<Element>(By.AccessibilityId(AccessibilityId.HotkeyComboBox));
Assert.IsNotNull(hotkeyComboBox);
hotkeyComboBox.Click();
var popup = Session.Find<Element>(By.ClassName(ClassName.Popup));
Assert.IsNotNull(popup);
popup.Find<Element>(None).Click();
Assert.AreEqual(None, hotkeyComboBox.Text);
// verify the file
Session.Find<Button>(ElementName.Save).Click();
var hotkeys = new LayoutHotkeys();
var actualData = hotkeys.Read(hotkeys.File);
Assert.IsFalse(actualData.LayoutHotkeys.Contains(new LayoutHotkeyWrapper { Key = assignedKey, LayoutId = layout.Uuid }));
// verify the previously assigned key is available
Session.Find<Element>(CustomLayouts.CustomLayouts[3].Name).Find<Button>(By.AccessibilityId(AccessibilityId.EditLayoutButton)).Click();
hotkeyComboBox = Session.Find<Element>(By.AccessibilityId(AccessibilityId.HotkeyComboBox));
Assert.IsNotNull(hotkeyComboBox);
hotkeyComboBox.Click();
popup = Session.Find<Element>(By.ClassName(ClassName.Popup));
Assert.IsNotNull(popup);
try
{
popup.Find<Element>($"{assignedKey}"); // verify the key is available
}
catch
{
Assert.Fail("The key is not available for other layouts.");
}
}
[TestMethod("FancyZonesEditor.Basic.HotKey_Reset_Cancel")]
[TestCategory("FancyZones Editor #11")]
public void Reset_Cancel()
{
var layout = CustomLayouts.CustomLayouts[0]; // a layout with assigned hotkey
int assignedKey = Hotkeys.LayoutHotkeys.Find(x => x.LayoutId == layout.Uuid).Key;
Session.Find<Element>(layout.Name).Find<Button>(By.AccessibilityId(AccessibilityId.EditLayoutButton)).Click();
const string None = "None";
// assign hotkey
var hotkeyComboBox = Session.Find<Element>(By.AccessibilityId(AccessibilityId.HotkeyComboBox));
Assert.IsNotNull(hotkeyComboBox);
hotkeyComboBox.Click();
var popup = Session.Find<Element>(By.ClassName(ClassName.Popup));
Assert.IsNotNull(popup);
popup.Find<Element>(None).Click(); // reset the hotkey
Assert.AreEqual(None, hotkeyComboBox.Text);
// verify the file
Session.Find<Button>(ElementName.Cancel).Click();
var hotkeys = new LayoutHotkeys();
var actualData = hotkeys.Read(hotkeys.File);
Assert.IsTrue(actualData.LayoutHotkeys.Contains(new LayoutHotkeyWrapper { Key = assignedKey, LayoutId = layout.Uuid }));
// verify the previously assigned key is not available
Session.Find<Element>(CustomLayouts.CustomLayouts[3].Name).Find<Button>(By.AccessibilityId(AccessibilityId.EditLayoutButton)).Click();
hotkeyComboBox = Session.Find<Element>(By.AccessibilityId(AccessibilityId.HotkeyComboBox));
Assert.IsNotNull(hotkeyComboBox);
hotkeyComboBox.Click();
popup = Session.Find<Element>(By.ClassName(ClassName.Popup));
Assert.IsNotNull(popup);
try
{
popup.Find<Element>($"{assignedKey}"); // verify the key is not available
Assert.Fail("The key is still available for other layouts.");
}
catch
{
// the key is not available as expected
}
}
}
}

View File

@@ -0,0 +1,153 @@
// Copyright (c) Microsoft Corporation
// The Microsoft Corporation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information.
using System.Collections.Generic;
using FancyZonesEditor.Models;
using FancyZonesEditorCommon.Data;
using Microsoft.FancyZonesEditor.UITests;
using Microsoft.FancyZonesEditor.UnitTests.Utils;
using Microsoft.PowerToys.UITest;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using Windows.UI;
using static FancyZonesEditorCommon.Data.EditorParameters;
namespace Microsoft.FancyZonesEditor.UITests
{
[TestClass]
public class NewFancyZonesEditorTest
{
public NewFancyZonesEditorTest()
{
// FancyZonesEditorHelper.InitFancyZonesLayout();
}
[TestClass]
public class TestCaseFirstLaunch : UITestBase
{
public TestCaseFirstLaunch()
: base(PowerToysModule.FancyZone, WindowSize.UnSpecified)
{
}
[TestInitialize]
public void TestInitialize()
{
EditorParameters editorParameters = new EditorParameters();
ParamsWrapper parameters = new ParamsWrapper
{
ProcessId = 1,
SpanZonesAcrossMonitors = false,
Monitors = new List<NativeMonitorDataWrapper>
{
new NativeMonitorDataWrapper
{
Monitor = "monitor-1",
MonitorInstanceId = "instance-id-1",
MonitorSerialNumber = "serial-number-1",
MonitorNumber = 1,
VirtualDesktop = "{FF34D993-73F3-4B8C-AA03-73730A01D6A8}",
Dpi = 192, // 200% scaling
LeftCoordinate = 0,
TopCoordinate = 0,
WorkAreaHeight = 1040,
WorkAreaWidth = 1920,
MonitorHeight = 1080,
MonitorWidth = 1920,
IsSelected = true,
},
},
};
FancyZonesEditorHelper.Files.ParamsIOHelper.WriteData(editorParameters.Serialize(parameters));
// files not yet exist
DefaultLayouts defaultLayouts = new DefaultLayouts();
DefaultLayouts.DefaultLayoutsListWrapper defaultLayoutsListWrapper = new DefaultLayouts.DefaultLayoutsListWrapper
{
DefaultLayouts = new List<DefaultLayouts.DefaultLayoutWrapper> { },
};
FancyZonesEditorHelper.Files.DefaultLayoutsIOHelper.WriteData(defaultLayouts.Serialize(defaultLayoutsListWrapper));
LayoutHotkeys layoutHotkeys = new LayoutHotkeys();
LayoutHotkeys.LayoutHotkeysWrapper layoutHotkeysWrapper = new LayoutHotkeys.LayoutHotkeysWrapper
{
LayoutHotkeys = new List<LayoutHotkeys.LayoutHotkeyWrapper> { },
};
FancyZonesEditorHelper.Files.LayoutHotkeysIOHelper.WriteData(layoutHotkeys.Serialize(layoutHotkeysWrapper));
AppliedLayouts appliedLayouts = new AppliedLayouts();
AppliedLayouts.AppliedLayoutsListWrapper appliedLayoutsWrapper = new AppliedLayouts.AppliedLayoutsListWrapper
{
AppliedLayouts = new List<AppliedLayouts.AppliedLayoutWrapper> { },
};
FancyZonesEditorHelper.Files.AppliedLayoutsIOHelper.WriteData(appliedLayouts.Serialize(appliedLayoutsWrapper));
CustomLayouts customLayouts = new CustomLayouts();
CustomLayouts.CustomLayoutListWrapper customLayoutListWrapper = new CustomLayouts.CustomLayoutListWrapper
{
CustomLayouts = new List<CustomLayouts.CustomLayoutWrapper> { },
};
FancyZonesEditorHelper.Files.CustomLayoutsIOHelper.WriteData(customLayouts.Serialize(customLayoutListWrapper));
LayoutTemplates layoutTemplates = new LayoutTemplates();
LayoutTemplates.TemplateLayoutsListWrapper templateLayoutsListWrapper = new LayoutTemplates.TemplateLayoutsListWrapper
{
LayoutTemplates = new List<LayoutTemplates.TemplateLayoutWrapper>
{
new LayoutTemplates.TemplateLayoutWrapper
{
Type = LayoutType.Blank.TypeToString(),
},
new LayoutTemplates.TemplateLayoutWrapper
{
Type = LayoutType.Focus.TypeToString(),
ZoneCount = 10,
},
new LayoutTemplates.TemplateLayoutWrapper
{
Type = LayoutType.Rows.TypeToString(),
ZoneCount = 2,
ShowSpacing = true,
Spacing = 10,
SensitivityRadius = 10,
},
new LayoutTemplates.TemplateLayoutWrapper
{
Type = LayoutType.Columns.TypeToString(),
ZoneCount = 2,
ShowSpacing = true,
Spacing = 20,
SensitivityRadius = 20,
},
new LayoutTemplates.TemplateLayoutWrapper
{
Type = LayoutType.Grid.TypeToString(),
ZoneCount = 4,
ShowSpacing = false,
Spacing = 10,
SensitivityRadius = 30,
},
new LayoutTemplates.TemplateLayoutWrapper
{
Type = LayoutType.PriorityGrid.TypeToString(),
ZoneCount = 3,
ShowSpacing = true,
Spacing = 1,
SensitivityRadius = 40,
},
},
};
FancyZonesEditorHelper.Files.LayoutTemplatesIOHelper.WriteData(layoutTemplates.Serialize(templateLayoutsListWrapper));
// verify editor opens without errors
this.RestartScopeExe();
}
[TestMethod]
public void FirstLaunch() // verify the session is initialized
{
Assert.IsNotNull(Session.Find<Element>("FancyZones Layout"));
}
}
}
}

View File

@@ -0,0 +1,232 @@
// Copyright (c) Microsoft Corporation
// The Microsoft Corporation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information.
using System.Collections.Generic;
using FancyZonesEditor.Models;
using FancyZonesEditorCommon.Data;
using Microsoft.FancyZonesEditor.UITests;
using Microsoft.FancyZonesEditor.UnitTests.Utils;
using Microsoft.PowerToys.UITest;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using OpenQA.Selenium.Appium.Windows;
using static Microsoft.FancyZonesEditor.UnitTests.Utils.FancyZonesEditorHelper;
namespace Microsoft.FancyZonesEditor.UITests
{
[TestClass]
public class RunFancyZonesEditorTest : UITestBase
{
public RunFancyZonesEditorTest()
: base(PowerToysModule.FancyZone, WindowSize.UnSpecified)
{
}
[TestInitialize]
public void TestInitialize()
{
FancyZonesEditorHelper.Files.Restore();
// prepare test editor parameters with 2 monitors before launching the editor
EditorParameters editorParameters = new EditorParameters();
EditorParameters.ParamsWrapper parameters = new EditorParameters.ParamsWrapper
{
ProcessId = 1,
SpanZonesAcrossMonitors = false,
Monitors = new List<EditorParameters.NativeMonitorDataWrapper>
{
new EditorParameters.NativeMonitorDataWrapper
{
Monitor = "monitor-1",
MonitorInstanceId = "instance-id-1",
MonitorSerialNumber = "serial-number-1",
MonitorNumber = 1,
VirtualDesktop = "{FF34D993-73F3-4B8C-AA03-73730A01D6A8}",
Dpi = 96,
LeftCoordinate = 0,
TopCoordinate = 0,
WorkAreaHeight = 1040,
WorkAreaWidth = 1920,
MonitorHeight = 1080,
MonitorWidth = 1920,
IsSelected = true,
},
new EditorParameters.NativeMonitorDataWrapper
{
Monitor = "monitor-2",
MonitorInstanceId = "instance-id-2",
MonitorSerialNumber = "serial-number-2",
MonitorNumber = 2,
VirtualDesktop = "{FF34D993-73F3-4B8C-AA03-73730A01D6A8}",
Dpi = 96,
LeftCoordinate = 1920,
TopCoordinate = 0,
WorkAreaHeight = 1040,
WorkAreaWidth = 1920,
MonitorHeight = 1080,
MonitorWidth = 1920,
IsSelected = false,
},
},
};
FancyZonesEditorHelper.Files.ParamsIOHelper.WriteData(editorParameters.Serialize(parameters));
LayoutTemplates layoutTemplates = new LayoutTemplates();
LayoutTemplates.TemplateLayoutsListWrapper templateLayoutsListWrapper = new LayoutTemplates.TemplateLayoutsListWrapper
{
LayoutTemplates = new List<LayoutTemplates.TemplateLayoutWrapper>
{
new LayoutTemplates.TemplateLayoutWrapper
{
Type = LayoutType.Blank.TypeToString(),
},
new LayoutTemplates.TemplateLayoutWrapper
{
Type = LayoutType.Focus.TypeToString(),
ZoneCount = 10,
},
new LayoutTemplates.TemplateLayoutWrapper
{
Type = LayoutType.Rows.TypeToString(),
ZoneCount = 2,
ShowSpacing = true,
Spacing = 10,
SensitivityRadius = 10,
},
new LayoutTemplates.TemplateLayoutWrapper
{
Type = LayoutType.Columns.TypeToString(),
ZoneCount = 2,
ShowSpacing = true,
Spacing = 20,
SensitivityRadius = 20,
},
new LayoutTemplates.TemplateLayoutWrapper
{
Type = LayoutType.Grid.TypeToString(),
ZoneCount = 4,
ShowSpacing = false,
Spacing = 10,
SensitivityRadius = 30,
},
new LayoutTemplates.TemplateLayoutWrapper
{
Type = LayoutType.PriorityGrid.TypeToString(),
ZoneCount = 3,
ShowSpacing = true,
Spacing = 1,
SensitivityRadius = 40,
},
},
};
FancyZonesEditorHelper.Files.LayoutTemplatesIOHelper.WriteData(layoutTemplates.Serialize(templateLayoutsListWrapper));
CustomLayouts customLayouts = new CustomLayouts();
CustomLayouts.CustomLayoutListWrapper customLayoutListWrapper = new CustomLayouts.CustomLayoutListWrapper
{
CustomLayouts = new List<CustomLayouts.CustomLayoutWrapper>
{
new CustomLayouts.CustomLayoutWrapper
{
Uuid = "{E7807D0D-6223-4883-B15B-1F3883944C09}",
Type = CustomLayout.Canvas.TypeToString(),
Name = "Custom layout",
Info = new CustomLayouts().ToJsonElement(new CustomLayouts.CanvasInfoWrapper
{
RefHeight = 952,
RefWidth = 1500,
SensitivityRadius = 10,
Zones = new List<CustomLayouts.CanvasInfoWrapper.CanvasZoneWrapper> { },
}),
},
},
};
FancyZonesEditorHelper.Files.CustomLayoutsIOHelper.WriteData(customLayouts.Serialize(customLayoutListWrapper));
DefaultLayouts defaultLayouts = new DefaultLayouts();
DefaultLayouts.DefaultLayoutsListWrapper defaultLayoutsListWrapper = new DefaultLayouts.DefaultLayoutsListWrapper
{
DefaultLayouts = new List<DefaultLayouts.DefaultLayoutWrapper> { },
};
FancyZonesEditorHelper.Files.DefaultLayoutsIOHelper.WriteData(defaultLayouts.Serialize(defaultLayoutsListWrapper));
LayoutHotkeys layoutHotkeys = new LayoutHotkeys();
LayoutHotkeys.LayoutHotkeysWrapper layoutHotkeysWrapper = new LayoutHotkeys.LayoutHotkeysWrapper
{
LayoutHotkeys = new List<LayoutHotkeys.LayoutHotkeyWrapper> { },
};
FancyZonesEditorHelper.Files.LayoutHotkeysIOHelper.WriteData(layoutHotkeys.Serialize(layoutHotkeysWrapper));
AppliedLayouts appliedLayouts = new AppliedLayouts();
AppliedLayouts.AppliedLayoutsListWrapper appliedLayoutsWrapper = new AppliedLayouts.AppliedLayoutsListWrapper
{
AppliedLayouts = new List<AppliedLayouts.AppliedLayoutWrapper> { },
};
FancyZonesEditorHelper.Files.AppliedLayoutsIOHelper.WriteData(appliedLayouts.Serialize(appliedLayoutsWrapper));
this.RestartScopeExe();
}
[TestMethod]
public void OpenNewLayoutDialog() // verify the new layout dialog is opened
{
Session.Find<Button>(By.AccessibilityId(AccessibilityId.NewLayoutButton)).Click();
Assert.IsNotNull(Session.Find<Element>("Choose layout type")); // check the pane header
}
[TestMethod]
public void OpenEditLayoutDialog() // verify the edit layout dialog is opened
{
Session.Find<Button>(TestConstants.TemplateLayoutNames[LayoutType.Grid]).Click();
Assert.IsNotNull(Session.Find<Element>(By.AccessibilityId(FancyZonesEditorHelper.AccessibilityId.DialogTitle))); // check the pane header
Assert.IsNotNull(Session.Find<Element>($"Edit '{TestConstants.TemplateLayoutNames[LayoutType.Grid]}'")); // verify it's opened for the correct layout
}
[TestMethod]
public void OpenEditLayoutDialog_ByContextMenu_TemplateLayout() // verify the edit layout dialog is opened
{
Session.Find<Button>(TestConstants.TemplateLayoutNames[LayoutType.Grid]).Click(true);
var menu = Session.Find<Element>(By.ClassName(ClassName.ContextMenu));
menu.Find<Element>(FancyZonesEditorHelper.ElementName.Edit).Click();
Assert.IsNotNull(Session.Find<Element>(By.AccessibilityId(FancyZonesEditorHelper.AccessibilityId.DialogTitle))); // check the pane header
Assert.IsNotNull(Session.Find<Element>($"Edit '{TestConstants.TemplateLayoutNames[LayoutType.Grid]}'")); // verify it's opened for the correct layout
}
[TestMethod]
public void OpenEditLayoutDialog_ByContextMenu_CustomLayout() // verify the edit layout dialog is opened
{
string layoutName = "Custom layout";
Session.Find<Button>(layoutName).Click(true);
var menu = Session.Find<Element>(By.ClassName(ClassName.ContextMenu));
menu.Find<Element>(FancyZonesEditorHelper.ElementName.Edit).Click();
Assert.IsNotNull(Session.Find<Element>(By.AccessibilityId(FancyZonesEditorHelper.AccessibilityId.DialogTitle))); // check the pane header
Assert.IsNotNull(Session.Find<Element>($"Edit '{layoutName}'")); // verify it's opened for the correct layout
}
[TestMethod]
public void OpenContextMenu() // verify the context menu is opened
{
Session.Find<Button>(TestConstants.TemplateLayoutNames[LayoutType.Columns]).Click(true);
Assert.IsNotNull(Session.Find<Element>(By.ClassName(ClassName.ContextMenu)));
}
[TestMethod]
public void ClickMonitor()
{
Assert.IsNotNull(Session.Find<Element>("Monitor 1"));
Assert.IsNotNull(Session.Find<Element>("Monitor 2"));
// verify that the monitor 1 is selected initially
Assert.IsTrue(Session.Find<Element>("Monitor 1").Selected);
Assert.IsFalse(Session.Find<Element>("Monitor 2").Selected);
Session.Find<Element>("Monitor 2").Click();
// verify that the monitor 2 is selected after click
Assert.IsFalse(Session.Find<Element>("Monitor 1").Selected);
Assert.IsTrue(Session.Find<Element>("Monitor 2").Selected);
}
}
}

View File

@@ -0,0 +1,406 @@
// Copyright (c) Microsoft Corporation
// The Microsoft Corporation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information.
using System.Collections.Generic;
using FancyZonesEditor.Models;
using FancyZonesEditorCommon.Data;
using Microsoft.FancyZonesEditor.UITests;
using Microsoft.FancyZonesEditor.UITests.Utils;
using Microsoft.FancyZonesEditor.UnitTests.Utils;
using Microsoft.PowerToys.UITest;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using OpenQA.Selenium;
using Windows.UI;
using static FancyZonesEditorCommon.Data.AppliedLayouts;
using static FancyZonesEditorCommon.Data.DefaultLayouts;
using static FancyZonesEditorCommon.Data.EditorParameters;
using static FancyZonesEditorCommon.Data.LayoutTemplates;
using static Microsoft.ApplicationInsights.MetricDimensionNames.TelemetryContext;
using static Microsoft.FancyZonesEditor.UnitTests.Utils.FancyZonesEditorHelper;
namespace Microsoft.FancyZonesEditor.UITests
{
[TestClass]
public class TemplateLayoutsTests : UITestBase
{
private static readonly TemplateLayoutsListWrapper Layouts = new TemplateLayoutsListWrapper
{
LayoutTemplates = new List<TemplateLayoutWrapper>
{
new TemplateLayoutWrapper
{
Type = LayoutType.Blank.TypeToString(),
},
new TemplateLayoutWrapper
{
Type = LayoutType.Focus.TypeToString(),
ZoneCount = 10,
},
new TemplateLayoutWrapper
{
Type = LayoutType.Rows.TypeToString(),
ZoneCount = 2,
ShowSpacing = true,
Spacing = 10,
SensitivityRadius = 10,
},
new TemplateLayoutWrapper
{
Type = LayoutType.Columns.TypeToString(),
ZoneCount = 2,
ShowSpacing = true,
Spacing = 20,
SensitivityRadius = 20,
},
new TemplateLayoutWrapper
{
Type = LayoutType.Grid.TypeToString(),
ZoneCount = 4,
ShowSpacing = false,
Spacing = 10,
SensitivityRadius = 30,
},
new TemplateLayoutWrapper
{
Type = LayoutType.PriorityGrid.TypeToString(),
ZoneCount = 3,
ShowSpacing = true,
Spacing = 1,
SensitivityRadius = 40,
},
},
};
public TemplateLayoutsTests()
: base(PowerToysModule.FancyZone, WindowSize.UnSpecified)
{
}
[TestInitialize]
public void TestInitialize()
{
FancyZonesEditorHelper.Files.Restore();
EditorParameters editorParameters = new EditorParameters();
ParamsWrapper parameters = new ParamsWrapper
{
ProcessId = 1,
SpanZonesAcrossMonitors = false,
Monitors = new List<NativeMonitorDataWrapper>
{
new NativeMonitorDataWrapper
{
Monitor = "monitor-1",
MonitorInstanceId = "instance-id-1",
MonitorSerialNumber = "serial-number-1",
MonitorNumber = 1,
VirtualDesktop = "{FF34D993-73F3-4B8C-AA03-73730A01D6A8}",
Dpi = 192,
LeftCoordinate = 0,
TopCoordinate = 0,
WorkAreaHeight = 1040,
WorkAreaWidth = 1920,
MonitorHeight = 1080,
MonitorWidth = 1920,
IsSelected = true,
},
},
};
FancyZonesEditorHelper.Files.ParamsIOHelper.WriteData(editorParameters.Serialize(parameters));
LayoutTemplates layoutTemplates = new LayoutTemplates();
FancyZonesEditorHelper.Files.LayoutTemplatesIOHelper.WriteData(layoutTemplates.Serialize(Layouts));
// Default layouts should match templates
DefaultLayouts defaultLayouts = new DefaultLayouts();
DefaultLayoutsListWrapper defaultLayoutsList = new DefaultLayoutsListWrapper
{
DefaultLayouts = new List<DefaultLayoutWrapper>
{
new DefaultLayoutWrapper
{
MonitorConfiguration = MonitorConfigurationType.Vertical.ToString(),
Layout = new DefaultLayoutWrapper.LayoutWrapper
{
Type = LayoutType.Rows.TypeToString(),
ZoneCount = 2,
ShowSpacing = true,
Spacing = 10,
SensitivityRadius = 10,
},
},
new DefaultLayoutWrapper
{
MonitorConfiguration = MonitorConfigurationType.Horizontal.ToString(),
Layout = new DefaultLayoutWrapper.LayoutWrapper
{
Type = LayoutType.PriorityGrid.TypeToString(),
ZoneCount = 3,
ShowSpacing = true,
Spacing = 1,
SensitivityRadius = 40,
},
},
},
};
FancyZonesEditorHelper.Files.DefaultLayoutsIOHelper.WriteData(defaultLayouts.Serialize(defaultLayoutsList));
// Make sure applied layouts don't replate template settings
AppliedLayouts appliedLayouts = new AppliedLayouts();
AppliedLayoutsListWrapper appliedLayoutsList = new AppliedLayoutsListWrapper
{
AppliedLayouts = new List<AppliedLayoutWrapper>
{
new AppliedLayoutWrapper
{
Device = new AppliedLayoutWrapper.DeviceIdWrapper
{
Monitor = "monitor-1",
MonitorInstance = "instance-id-1",
MonitorNumber = 1,
SerialNumber = "serial-number-1",
VirtualDesktop = "{FF34D993-73F3-4B8C-AA03-73730A01D6A8}",
},
AppliedLayout = new AppliedLayoutWrapper.LayoutWrapper
{
Uuid = "{72409DFC-2B87-469B-AAC4-557273791C26}",
Type = LayoutType.PriorityGrid.TypeToString(),
ZoneCount = 3,
ShowSpacing = true,
Spacing = 1,
SensitivityRadius = 40,
},
},
},
};
FancyZonesEditorHelper.Files.AppliedLayoutsIOHelper.WriteData(appliedLayouts.Serialize(appliedLayoutsList));
CustomLayouts customLayouts = new CustomLayouts();
CustomLayouts.CustomLayoutListWrapper customLayoutListWrapper = new CustomLayouts.CustomLayoutListWrapper
{
CustomLayouts = new List<CustomLayouts.CustomLayoutWrapper> { },
};
FancyZonesEditorHelper.Files.CustomLayoutsIOHelper.WriteData(customLayouts.Serialize(customLayoutListWrapper));
LayoutHotkeys layoutHotkeys = new LayoutHotkeys();
LayoutHotkeys.LayoutHotkeysWrapper layoutHotkeysWrapper = new LayoutHotkeys.LayoutHotkeysWrapper
{
LayoutHotkeys = new List<LayoutHotkeys.LayoutHotkeyWrapper> { },
};
FancyZonesEditorHelper.Files.LayoutHotkeysIOHelper.WriteData(layoutHotkeys.Serialize(layoutHotkeysWrapper));
this.RestartScopeExe();
}
[TestMethod("FancyZonesEditor.Basic.ZoneNumber_Cancel")]
[TestCategory("FancyZones Editor #6")]
public void ZoneNumber_Cancel()
{
var type = LayoutType.Rows;
var layout = Layouts.LayoutTemplates.Find(x => x.Type == type.TypeToString());
var expected = layout.ZoneCount;
Session.Find<Button>(TestConstants.TemplateLayoutNames[type]).Click();
var slider = Session.Find<Custom>(PowerToys.UITest.By.AccessibilityId(AccessibilityId.TemplateZoneSlider));
Assert.IsNotNull(slider);
slider.SendKeys(Key.Left);
Session.Find<Button>(ElementName.Cancel).Click();
// verify the file
var templateLayouts = new LayoutTemplates();
var data = templateLayouts.Read(templateLayouts.File);
var actual = data.LayoutTemplates.Find(x => x.Type == type.TypeToString()).ZoneCount;
Assert.AreEqual(expected, actual);
}
[TestMethod("FancyZonesEditor.Basic.HighlightDistance_Initialize")]
[TestCategory("FancyZones Editor #6")]
public void HighlightDistance_Initialize()
{
foreach (var (type, name) in TestConstants.TemplateLayoutNames)
{
if (type == LayoutType.Blank)
{
continue;
}
Session.Find<Button>(name).Click();
var slider = Session.Find<Element>(PowerToys.UITest.By.AccessibilityId(AccessibilityId.SensitivitySlider));
Assert.IsNotNull(slider);
var expected = Layouts.LayoutTemplates.Find(x => x.Type == type.TypeToString()).SensitivityRadius;
Assert.AreEqual($"{expected}", slider.Text);
Session.Find<Button>(ElementName.Cancel).Click();
}
}
[TestMethod("FancyZonesEditor.Basic.HighlightDistance_Save")]
[TestCategory("FancyZones Editor #6")]
public void HighlightDistance_Save()
{
var type = LayoutType.Focus;
var layout = Layouts.LayoutTemplates.Find(x => x.Type == type.TypeToString());
var value = layout.SensitivityRadius;
Session.Find<Button>(TestConstants.TemplateLayoutNames[type]).Click();
var slider = Session.Find<Custom>(PowerToys.UITest.By.AccessibilityId(AccessibilityId.SensitivitySlider));
Assert.IsNotNull(slider);
slider.SendKeys(Key.Right);
var expected = value; // one step right
Assert.AreEqual($"{expected}", slider.Text);
Session.Find<Button>(ElementName.Save).Click();
// verify the file
var templateLayouts = new LayoutTemplates();
var data = templateLayouts.Read(templateLayouts.File);
var actual = data.LayoutTemplates.Find(x => x.Type == type.TypeToString()).SensitivityRadius;
Assert.AreEqual(expected, actual);
}
[TestMethod("FancyZonesEditor.Basic.HighlightDistance_Cancel")]
[TestCategory("FancyZones Editor #6")]
public void HighlightDistance_Cancel()
{
var type = LayoutType.Focus;
var layout = Layouts.LayoutTemplates.Find(x => x.Type == type.TypeToString());
var expected = layout.SensitivityRadius;
Session.Find<Button>(TestConstants.TemplateLayoutNames[type]).Click();
var slider = Session.Find<Custom>(PowerToys.UITest.By.AccessibilityId(AccessibilityId.SensitivitySlider));
Assert.IsNotNull(slider);
slider.SendKeys(Key.Right);
Session.Find<Button>(ElementName.Cancel).Click();
// verify the file
var templateLayouts = new LayoutTemplates();
var data = templateLayouts.Read(templateLayouts.File);
var actual = data.LayoutTemplates.Find(x => x.Type == type.TypeToString()).SensitivityRadius;
Assert.AreEqual(expected, actual);
}
[TestMethod("FancyZonesEditor.Basic.SpaceAroundZones_Initialize")]
[TestCategory("FancyZones Editor #6")]
public void SpaceAroundZones_Initialize()
{
foreach (var (type, name) in TestConstants.TemplateLayoutNames)
{
if (type == LayoutType.Blank || type == LayoutType.Focus)
{
// only for grid layouts
continue;
}
Session.Find<Button>(name).Click();
var slider = Session.Find<Element>(PowerToys.UITest.By.AccessibilityId(AccessibilityId.SpacingSlider));
Assert.IsNotNull(slider);
var spacingEnabled = Layouts.LayoutTemplates.Find(x => x.Type == type.TypeToString()).ShowSpacing;
Assert.AreEqual(spacingEnabled, slider.Enabled);
var expected = Layouts.LayoutTemplates.Find(x => x.Type == type.TypeToString()).Spacing;
Assert.AreEqual($"{expected}", slider.Text);
Session.Find<Button>(ElementName.Cancel).Click();
}
}
[TestMethod("FancyZonesEditor.Basic.SpaceAroundZones_Slider_Save")]
[TestCategory("FancyZones Editor #6")]
public void SpaceAroundZones_Slider_Save()
{
var type = LayoutType.PriorityGrid;
var layout = Layouts.LayoutTemplates.Find(x => x.Type == type.TypeToString());
var expected = layout.Spacing;
Session.Find<Button>(TestConstants.TemplateLayoutNames[type]).Click();
var slider = Session.Find<Custom>(PowerToys.UITest.By.AccessibilityId(AccessibilityId.SpacingSlider));
Assert.IsNotNull(slider);
slider.SendKeys(Key.Right);
Assert.AreEqual($"{expected}", slider.Text);
Session.Find<Button>(ElementName.Save).Click();
// verify the file
var templateLayouts = new LayoutTemplates();
var data = templateLayouts.Read(templateLayouts.File);
var actual = data.LayoutTemplates.Find(x => x.Type == type.TypeToString()).Spacing;
Assert.AreEqual(expected, actual);
}
[TestMethod("FancyZonesEditor.Basic.SpaceAroundZones_Slider_Cancel")]
[TestCategory("FancyZones Editor #6")]
public void SpaceAroundZones_Slider_Cancel()
{
var type = LayoutType.PriorityGrid;
var layout = Layouts.LayoutTemplates.Find(x => x.Type == type.TypeToString());
var expected = layout.Spacing;
Session.Find<Button>(TestConstants.TemplateLayoutNames[type]).Click();
var slider = Session.Find<Custom>(PowerToys.UITest.By.AccessibilityId(AccessibilityId.SpacingSlider));
Assert.IsNotNull(slider);
slider.SendKeys(Key.Right);
Assert.AreEqual($"{expected}", slider.Text);
Session.Find<Button>(ElementName.Cancel).Click();
// verify the file
var templateLayouts = new LayoutTemplates();
var data = templateLayouts.Read(templateLayouts.File);
var actual = data.LayoutTemplates.Find(x => x.Type == type.TypeToString()).Spacing;
Assert.AreEqual(expected, actual);
}
[TestMethod("FancyZonesEditor.Basic.SpaceAroundZones_Toggle_Save")]
[TestCategory("FancyZones Editor #6")]
public void SpaceAroundZones_Toggle_Save()
{
var type = LayoutType.PriorityGrid;
var layout = Layouts.LayoutTemplates.Find(x => x.Type == type.TypeToString());
var expected = !layout.ShowSpacing;
Session.Find<Button>(TestConstants.TemplateLayoutNames[type]).Click();
var toggle = Session.Find<Element>(PowerToys.UITest.By.AccessibilityId(AccessibilityId.SpacingToggle));
Assert.IsNotNull(toggle);
toggle.Click();
Assert.AreEqual(expected, toggle.Selected);
Assert.AreEqual(expected, Session.Find<Element>(PowerToys.UITest.By.AccessibilityId(AccessibilityId.SpacingSlider))?.Enabled);
Session.Find<Button>(ElementName.Save).Click();
// verify the file
var templateLayouts = new LayoutTemplates();
var data = templateLayouts.Read(templateLayouts.File);
var actual = data.LayoutTemplates.Find(x => x.Type == type.TypeToString()).ShowSpacing;
Assert.AreEqual(expected, actual);
}
[TestMethod("FancyZonesEditor.Basic.SpaceAroundZones_Toggle_Cancel")]
[TestCategory("FancyZones Editor #6")]
public void SpaceAroundZones_Toggle_Cancel()
{
var type = LayoutType.PriorityGrid;
var layout = Layouts.LayoutTemplates.Find(x => x.Type == type.TypeToString());
var expected = layout.ShowSpacing;
Session.Find<Button>(TestConstants.TemplateLayoutNames[type]).Click();
var toggle = Session.Find<Element>(PowerToys.UITest.By.AccessibilityId(AccessibilityId.SpacingToggle));
Assert.IsNotNull(toggle);
toggle.Click();
Assert.AreNotEqual(expected, toggle.Selected);
Assert.AreNotEqual(expected, Session.Find<Element>(PowerToys.UITest.By.AccessibilityId(AccessibilityId.SpacingSlider))?.Enabled);
Session.Find<Button>(ElementName.Cancel).Click();
// verify the file
var templateLayouts = new LayoutTemplates();
var data = templateLayouts.Read(templateLayouts.File);
var actual = data.LayoutTemplates.Find(x => x.Type == type.TypeToString()).ShowSpacing;
Assert.AreEqual(expected, actual);
}
}
}

View File

@@ -0,0 +1,24 @@
// Copyright (c) Microsoft Corporation
// The Microsoft Corporation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information.
using System.Collections.Generic;
using FancyZonesEditor.Models;
using static FancyZonesEditorCommon.Data.Constants;
namespace Microsoft.FancyZonesEditor.UITests
{
public static class TestConstants
{
public static readonly Dictionary<LayoutType, string> TemplateLayoutNames = new Dictionary<LayoutType, string>()
{
{ LayoutType.Blank, "No layout" },
{ LayoutType.Focus, "Focus" },
{ LayoutType.Rows, "Rows" },
{ LayoutType.Columns, "Columns" },
{ LayoutType.Grid, "Grid" },
{ LayoutType.PriorityGrid, "Priority Grid" },
};
}
}

View File

@@ -0,0 +1,842 @@
// Copyright (c) Microsoft Corporation
// The Microsoft Corporation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information.
using System.Collections.Generic;
using System.Globalization;
using System.Xml.Linq;
using FancyZonesEditor.Models;
using FancyZonesEditorCommon.Data;
using Microsoft.FancyZonesEditor.UITests;
using Microsoft.FancyZonesEditor.UITests.Utils;
using Microsoft.FancyZonesEditor.UnitTests.Utils;
using Microsoft.PowerToys.UITest;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using Windows.UI;
using static FancyZonesEditorCommon.Data.EditorParameters;
using static Microsoft.ApplicationInsights.MetricDimensionNames.TelemetryContext;
using static Microsoft.FancyZonesEditor.UnitTests.Utils.FancyZonesEditorHelper;
namespace Microsoft.FancyZonesEditor.UITests
{
[TestClass]
public class UIInitializeTest : UITestBase
{
public UIInitializeTest()
: base(PowerToysModule.FancyZone, WindowSize.UnSpecified)
{
}
[TestMethod("FancyZonesEditor.Basic.EditorParams_VerifySelectedMonitor")]
[TestCategory("FancyZones Editor #10")]
public void EditorParams_VerifySelectedMonitor()
{
InitFileData();
EditorParameters editorParameters = new EditorParameters();
ParamsWrapper parameters = new ParamsWrapper
{
ProcessId = 1,
SpanZonesAcrossMonitors = false,
Monitors = new List<NativeMonitorDataWrapper>
{
new NativeMonitorDataWrapper
{
Monitor = "monitor-1",
MonitorInstanceId = "instance-id-1",
MonitorSerialNumber = "serial-number-1",
MonitorNumber = 1,
VirtualDesktop = "{FF34D993-73F3-4B8C-AA03-73730A01D6A8}",
Dpi = 96,
LeftCoordinate = 0,
TopCoordinate = 0,
WorkAreaHeight = 1040,
WorkAreaWidth = 1920,
MonitorHeight = 1080,
MonitorWidth = 1920,
IsSelected = false,
},
new NativeMonitorDataWrapper
{
Monitor = "monitor-2",
MonitorInstanceId = "instance-id-2",
MonitorSerialNumber = "serial-number-2",
MonitorNumber = 2,
VirtualDesktop = "{FF34D993-73F3-4B8C-AA03-73730A01D6A8}",
Dpi = 96,
LeftCoordinate = 1920,
TopCoordinate = 0,
WorkAreaHeight = 1040,
WorkAreaWidth = 1920,
MonitorHeight = 1080,
MonitorWidth = 1920,
IsSelected = true,
},
},
};
FancyZonesEditorHelper.Files.ParamsIOHelper.WriteData(editorParameters.Serialize(parameters));
this.RestartScopeExe();
Session.Find<Element>("Monitor 1").Click();
Session.Find<Element>("Monitor 2").Click();
Assert.IsFalse(Session.Find<Element>("Monitor 1").Selected);
Assert.IsTrue(Session.Find<Element>("Monitor 2").Selected);
}
[TestMethod]
public void EditorParams_VerifyMonitorScaling()
{
InitFileData();
EditorParameters editorParameters = new EditorParameters();
ParamsWrapper parameters = new ParamsWrapper
{
ProcessId = 1,
SpanZonesAcrossMonitors = false,
Monitors = new List<NativeMonitorDataWrapper>
{
new NativeMonitorDataWrapper
{
Monitor = "monitor-1",
MonitorInstanceId = "instance-id-1",
MonitorSerialNumber = "serial-number-1",
MonitorNumber = 1,
VirtualDesktop = "{FF34D993-73F3-4B8C-AA03-73730A01D6A8}",
Dpi = 192, // 200% scaling
LeftCoordinate = 0,
TopCoordinate = 0,
WorkAreaHeight = 1040,
WorkAreaWidth = 1920,
MonitorHeight = 1080,
MonitorWidth = 1920,
IsSelected = true,
},
},
};
FancyZonesEditorHelper.Files.ParamsIOHelper.WriteData(editorParameters.Serialize(parameters));
this.RestartScopeExe();
Session.Find<Element>("Monitor 1").Click();
var monitor = Session.Find<Element>("Monitor 1");
var scaling = monitor.Find<Element>(By.AccessibilityId("ScalingText"));
Assert.AreEqual("200%", scaling.Text);
}
[TestMethod]
public void EditorParams_VerifyMonitorResolution()
{
InitFileData();
EditorParameters editorParameters = new EditorParameters();
ParamsWrapper parameters = new ParamsWrapper
{
ProcessId = 1,
SpanZonesAcrossMonitors = false,
Monitors = new List<NativeMonitorDataWrapper>
{
new NativeMonitorDataWrapper
{
Monitor = "monitor-1",
MonitorInstanceId = "instance-id-1",
MonitorSerialNumber = "serial-number-1",
MonitorNumber = 1,
VirtualDesktop = "{FF34D993-73F3-4B8C-AA03-73730A01D6A8}",
Dpi = 192,
LeftCoordinate = 0,
TopCoordinate = 0,
WorkAreaHeight = 1040,
WorkAreaWidth = 1920,
MonitorHeight = 1080,
MonitorWidth = 1920,
IsSelected = true,
},
},
};
FancyZonesEditorHelper.Files.ParamsIOHelper.WriteData(editorParameters.Serialize(parameters));
this.RestartScopeExe();
Session.Find<Element>("Monitor 1").Click();
var monitor = Session.Find<Element>("Monitor 1");
var resolution = monitor.Find<Element>(By.AccessibilityId("ResolutionText"));
Assert.AreEqual("1920 × 1080", resolution.Text);
}
[TestMethod]
public void EditorParams_SpanAcrossMonitors()
{
InitFileData();
EditorParameters editorParameters = new EditorParameters();
ParamsWrapper parameters = new ParamsWrapper
{
ProcessId = 1,
SpanZonesAcrossMonitors = true,
Monitors = new List<NativeMonitorDataWrapper>
{
new NativeMonitorDataWrapper
{
Monitor = "monitor-1",
MonitorInstanceId = "instance-id-1",
MonitorSerialNumber = "serial-number-1",
MonitorNumber = 1,
VirtualDesktop = "{FF34D993-73F3-4B8C-AA03-73730A01D6A8}",
Dpi = 192,
LeftCoordinate = 0,
TopCoordinate = 0,
WorkAreaHeight = 1040,
WorkAreaWidth = 1920,
MonitorHeight = 1080,
MonitorWidth = 1920,
IsSelected = true,
},
},
};
FancyZonesEditorHelper.Files.ParamsIOHelper.WriteData(editorParameters.Serialize(parameters));
this.RestartScopeExe();
Session.Find<Element>("Monitor 1").Click();
var monitor = Session.Find<Element>("Monitor 1");
Assert.IsNotNull(monitor);
Assert.IsTrue(monitor.Selected);
}
[TestMethod]
public void AppliedLayouts_LayoutsApplied()
{
InitFileData();
EditorParameters editorParameters = new EditorParameters();
ParamsWrapper parameters = new ParamsWrapper
{
ProcessId = 1,
SpanZonesAcrossMonitors = false,
Monitors = new List<NativeMonitorDataWrapper>
{
new NativeMonitorDataWrapper
{
Monitor = "monitor-1",
MonitorInstanceId = "instance-id-1",
MonitorSerialNumber = "serial-number-1",
MonitorNumber = 1,
VirtualDesktop = "{FF34D993-73F3-4B8C-AA03-73730A01D6A8}",
Dpi = 96,
LeftCoordinate = 0,
TopCoordinate = 0,
WorkAreaHeight = 1040,
WorkAreaWidth = 1920,
MonitorHeight = 1080,
MonitorWidth = 1920,
IsSelected = true,
},
new NativeMonitorDataWrapper
{
Monitor = "monitor-2",
MonitorInstanceId = "instance-id-2",
MonitorSerialNumber = "serial-number-2",
MonitorNumber = 2,
VirtualDesktop = "{FF34D993-73F3-4B8C-AA03-73730A01D6A8}",
Dpi = 96,
LeftCoordinate = 1920,
TopCoordinate = 0,
WorkAreaHeight = 1040,
WorkAreaWidth = 1920,
MonitorHeight = 1080,
MonitorWidth = 1920,
IsSelected = false,
},
},
};
FancyZonesEditorHelper.Files.ParamsIOHelper.WriteData(editorParameters.Serialize(parameters));
CustomLayouts customLayouts = new CustomLayouts();
CustomLayouts.CustomLayoutListWrapper customLayoutListWrapper = new CustomLayouts.CustomLayoutListWrapper
{
CustomLayouts = new List<CustomLayouts.CustomLayoutWrapper>
{
new CustomLayouts.CustomLayoutWrapper
{
Uuid = "{0D6D2F58-9184-4804-81E4-4E4CC3476DC1}",
Type = CustomLayout.Canvas.TypeToString(),
Name = "Custom layout 1",
Info = new CustomLayouts().ToJsonElement(new CustomLayouts.CanvasInfoWrapper
{
RefHeight = 1080,
RefWidth = 1920,
SensitivityRadius = 10,
Zones = new List<CustomLayouts.CanvasInfoWrapper.CanvasZoneWrapper> { },
}),
},
},
};
FancyZonesEditorHelper.Files.CustomLayoutsIOHelper.WriteData(customLayouts.Serialize(customLayoutListWrapper));
AppliedLayouts appliedLayouts = new AppliedLayouts();
AppliedLayouts.AppliedLayoutsListWrapper appliedLayoutsWrapper = new AppliedLayouts.AppliedLayoutsListWrapper
{
AppliedLayouts = new List<AppliedLayouts.AppliedLayoutWrapper>
{
new AppliedLayouts.AppliedLayoutWrapper
{
Device = new AppliedLayouts.AppliedLayoutWrapper.DeviceIdWrapper
{
Monitor = "monitor-1",
MonitorInstance = "instance-id-1",
SerialNumber = "serial-number-1",
MonitorNumber = 1,
VirtualDesktop = "{FF34D993-73F3-4B8C-AA03-73730A01D6A8}",
},
AppliedLayout = new AppliedLayouts.AppliedLayoutWrapper.LayoutWrapper
{
Uuid = "{00000000-0000-0000-0000-000000000000}",
Type = LayoutType.Columns.TypeToString(),
ShowSpacing = true,
Spacing = 10,
ZoneCount = 1,
SensitivityRadius = 20,
},
},
new AppliedLayouts.AppliedLayoutWrapper
{
Device = new AppliedLayouts.AppliedLayoutWrapper.DeviceIdWrapper
{
Monitor = "monitor-2",
MonitorInstance = "instance-id-2",
SerialNumber = "serial-number-2",
MonitorNumber = 2,
VirtualDesktop = "{FF34D993-73F3-4B8C-AA03-73730A01D6A8}",
},
AppliedLayout = new AppliedLayouts.AppliedLayoutWrapper.LayoutWrapper
{
Uuid = customLayoutListWrapper.CustomLayouts[0].Uuid,
Type = LayoutType.Custom.TypeToString(),
},
},
},
};
FancyZonesEditorHelper.Files.AppliedLayoutsIOHelper.WriteData(appliedLayouts.Serialize(appliedLayoutsWrapper));
this.RestartScopeExe();
// check layout on monitor 1
var layoutOnMonitor1 = Session.Find<Element>(TestConstants.TemplateLayoutNames[LayoutType.Columns]);
Assert.IsNotNull(layoutOnMonitor1);
Assert.IsTrue(layoutOnMonitor1.Selected);
// check layout on monitor 2
Session.Find<Element>(By.AccessibilityId("Monitors")).Find<Element>("Monitor 2").Click();
var layoutOnMonitor2 = Session.Find<Element>(customLayoutListWrapper.CustomLayouts[0].Name);
Assert.IsNotNull(layoutOnMonitor2);
Assert.IsTrue(layoutOnMonitor2.Selected);
}
[TestMethod]
public void AppliedLayouts_CustomLayoutsApplied_LayoutIdNotFound()
{
InitFileData();
EditorParameters editorParameters = new EditorParameters();
ParamsWrapper parameters = new ParamsWrapper
{
ProcessId = 1,
SpanZonesAcrossMonitors = false,
Monitors = new List<NativeMonitorDataWrapper>
{
new NativeMonitorDataWrapper
{
Monitor = "monitor-1",
MonitorInstanceId = "instance-id-1",
MonitorSerialNumber = "serial-number-1",
MonitorNumber = 1,
VirtualDesktop = "{FF34D993-73F3-4B8C-AA03-73730A01D6A8}",
Dpi = 96,
LeftCoordinate = 0,
TopCoordinate = 0,
WorkAreaHeight = 1040,
WorkAreaWidth = 1920,
MonitorHeight = 1080,
MonitorWidth = 1920,
IsSelected = true,
},
},
};
FancyZonesEditorHelper.Files.ParamsIOHelper.WriteData(editorParameters.Serialize(parameters));
CustomLayouts customLayouts = new CustomLayouts();
CustomLayouts.CustomLayoutListWrapper customLayoutListWrapper = new CustomLayouts.CustomLayoutListWrapper
{
CustomLayouts = new List<CustomLayouts.CustomLayoutWrapper>
{
new CustomLayouts.CustomLayoutWrapper
{
Uuid = "{0D6D2F58-9184-4804-81E4-4E4CC3476DC1}",
Type = CustomLayout.Canvas.TypeToString(),
Name = "Custom layout 1",
Info = new CustomLayouts().ToJsonElement(new CustomLayouts.CanvasInfoWrapper
{
RefHeight = 1080,
RefWidth = 1920,
SensitivityRadius = 10,
Zones = new List<CustomLayouts.CanvasInfoWrapper.CanvasZoneWrapper> { },
}),
},
},
};
FancyZonesEditorHelper.Files.CustomLayoutsIOHelper.WriteData(customLayouts.Serialize(customLayoutListWrapper));
AppliedLayouts appliedLayouts = new AppliedLayouts();
AppliedLayouts.AppliedLayoutsListWrapper appliedLayoutsWrapper = new AppliedLayouts.AppliedLayoutsListWrapper
{
AppliedLayouts = new List<AppliedLayouts.AppliedLayoutWrapper>
{
new AppliedLayouts.AppliedLayoutWrapper
{
Device = new AppliedLayouts.AppliedLayoutWrapper.DeviceIdWrapper
{
Monitor = "monitor-1",
MonitorInstance = "instance-id-1",
SerialNumber = "serial-number-1",
MonitorNumber = 1,
VirtualDesktop = "{FF34D993-73F3-4B8C-AA03-73730A01D6A8}",
},
AppliedLayout = new AppliedLayouts.AppliedLayoutWrapper.LayoutWrapper
{
Uuid = "{00000000-0000-0000-0000-000000000000}",
Type = LayoutType.Custom.TypeToString(),
},
},
},
};
FancyZonesEditorHelper.Files.AppliedLayoutsIOHelper.WriteData(appliedLayouts.Serialize(appliedLayoutsWrapper));
this.RestartScopeExe();
var emptyLayout = Session.Find<Element>(TestConstants.TemplateLayoutNames[LayoutType.Blank]);
Assert.IsNotNull(emptyLayout);
Assert.IsTrue(emptyLayout.Selected);
}
[TestMethod]
public void AppliedLayouts_NoLayoutsApplied_CustomDefaultLayout()
{
InitFileData();
EditorParameters editorParameters = new EditorParameters();
ParamsWrapper parameters = new ParamsWrapper
{
ProcessId = 1,
SpanZonesAcrossMonitors = false,
Monitors = new List<NativeMonitorDataWrapper>
{
new NativeMonitorDataWrapper
{
Monitor = "monitor-1",
MonitorInstanceId = "instance-id-1",
MonitorSerialNumber = "serial-number-1",
MonitorNumber = 1,
VirtualDesktop = "{FF34D993-73F3-4B8C-AA03-73730A01D6A8}",
Dpi = 96,
LeftCoordinate = 0,
TopCoordinate = 0,
WorkAreaHeight = 1040,
WorkAreaWidth = 1920,
MonitorHeight = 1080,
MonitorWidth = 1920,
IsSelected = true,
},
},
};
FancyZonesEditorHelper.Files.ParamsIOHelper.WriteData(editorParameters.Serialize(parameters));
CustomLayouts customLayouts = new CustomLayouts();
CustomLayouts.CustomLayoutListWrapper customLayoutListWrapper = new CustomLayouts.CustomLayoutListWrapper
{
CustomLayouts = new List<CustomLayouts.CustomLayoutWrapper>
{
new CustomLayouts.CustomLayoutWrapper
{
Uuid = "{0D6D2F58-9184-4804-81E4-4E4CC3476DC1}",
Type = CustomLayout.Canvas.TypeToString(),
Name = "Custom layout 1",
Info = new CustomLayouts().ToJsonElement(new CustomLayouts.CanvasInfoWrapper
{
RefHeight = 1080,
RefWidth = 1920,
SensitivityRadius = 10,
Zones = new List<CustomLayouts.CanvasInfoWrapper.CanvasZoneWrapper> { },
}),
},
},
};
FancyZonesEditorHelper.Files.CustomLayoutsIOHelper.WriteData(customLayouts.Serialize(customLayoutListWrapper));
FancyZonesEditorHelper.Files.DefaultLayoutsIOHelper.RestoreData();
DefaultLayouts defaultLayouts = new DefaultLayouts();
DefaultLayouts.DefaultLayoutsListWrapper defaultLayoutsListWrapper = new DefaultLayouts.DefaultLayoutsListWrapper
{
DefaultLayouts = new List<DefaultLayouts.DefaultLayoutWrapper>
{
new DefaultLayouts.DefaultLayoutWrapper
{
MonitorConfiguration = MonitorConfigurationType.Horizontal.TypeToString(),
Layout = new DefaultLayouts.DefaultLayoutWrapper.LayoutWrapper
{
Type = LayoutType.Custom.TypeToString(),
Uuid = customLayoutListWrapper.CustomLayouts[0].Uuid,
},
},
},
};
FancyZonesEditorHelper.Files.DefaultLayoutsIOHelper.WriteData(defaultLayouts.Serialize(defaultLayoutsListWrapper));
this.RestartScopeExe();
Session.Find<Element>(customLayoutListWrapper.CustomLayouts[0].Name).Click();
var defaultLayout = Session.Find<Element>(customLayoutListWrapper.CustomLayouts[0].Name);
Assert.IsNotNull(defaultLayout);
Assert.IsTrue(defaultLayout.Selected);
}
[TestMethod]
public void AppliedLayouts_NoLayoutsApplied_TemplateDefaultLayout()
{
InitFileData();
EditorParameters editorParameters = new EditorParameters();
ParamsWrapper parameters = new ParamsWrapper
{
ProcessId = 1,
SpanZonesAcrossMonitors = false,
Monitors = new List<NativeMonitorDataWrapper>
{
new NativeMonitorDataWrapper
{
Monitor = "monitor-1",
MonitorInstanceId = "instance-id-1",
MonitorSerialNumber = "serial-number-1",
MonitorNumber = 1,
VirtualDesktop = "{FF34D993-73F3-4B8C-AA03-73730A01D6A8}",
Dpi = 96,
LeftCoordinate = 0,
TopCoordinate = 0,
WorkAreaHeight = 1040,
WorkAreaWidth = 1920,
MonitorHeight = 1080,
MonitorWidth = 1920,
IsSelected = true,
},
},
};
FancyZonesEditorHelper.Files.ParamsIOHelper.WriteData(editorParameters.Serialize(parameters));
FancyZonesEditorHelper.Files.DefaultLayoutsIOHelper.RestoreData();
DefaultLayouts defaultLayouts = new DefaultLayouts();
DefaultLayouts.DefaultLayoutsListWrapper defaultLayoutsListWrapper = new DefaultLayouts.DefaultLayoutsListWrapper
{
DefaultLayouts = new List<DefaultLayouts.DefaultLayoutWrapper>
{
new DefaultLayouts.DefaultLayoutWrapper
{
MonitorConfiguration = MonitorConfigurationType.Horizontal.TypeToString(),
Layout = new DefaultLayouts.DefaultLayoutWrapper.LayoutWrapper
{
Type = LayoutType.Grid.TypeToString(),
ZoneCount = 6,
ShowSpacing = true,
Spacing = 5,
SensitivityRadius = 20,
},
},
},
};
FancyZonesEditorHelper.Files.DefaultLayoutsIOHelper.WriteData(defaultLayouts.Serialize(defaultLayoutsListWrapper));
this.RestartScopeExe();
Session.Find<Element>(TestConstants.TemplateLayoutNames[LayoutType.Grid]).Click();
var defaultLayout = Session.Find<Element>(TestConstants.TemplateLayoutNames[LayoutType.Grid]);
Assert.IsNotNull(defaultLayout);
Assert.IsTrue(defaultLayout.Selected);
// check the number of zones and spacing
Session.Find<Element>(TestConstants.TemplateLayoutNames[LayoutType.Grid]).Find<Button>(By.AccessibilityId(AccessibilityId.EditLayoutButton)).Click();
Assert.AreEqual(defaultLayoutsListWrapper.DefaultLayouts[0].Layout.ZoneCount, int.Parse(Session.Find<Element>(By.AccessibilityId(AccessibilityId.TemplateZoneSlider))?.Text!, CultureInfo.InvariantCulture));
Assert.AreEqual(defaultLayoutsListWrapper.DefaultLayouts[0].Layout.Spacing, int.Parse(Session.Find<Element>(By.AccessibilityId(AccessibilityId.SpacingSlider))?.Text!, CultureInfo.InvariantCulture));
Assert.AreEqual(defaultLayoutsListWrapper.DefaultLayouts[0].Layout.ShowSpacing, Session.Find<Element>(By.AccessibilityId(AccessibilityId.SpacingSlider))?.Enabled);
Assert.AreEqual(defaultLayoutsListWrapper.DefaultLayouts[0].Layout.ShowSpacing, Session.Find<Element>(By.AccessibilityId(AccessibilityId.SpacingToggle))?.Selected);
Assert.AreEqual(defaultLayoutsListWrapper.DefaultLayouts[0].Layout.SensitivityRadius, int.Parse(Session.Find<Element>(By.AccessibilityId(AccessibilityId.SensitivitySlider))?.Text!, CultureInfo.InvariantCulture));
Assert.IsNotNull(Session.Find<Element>(By.AccessibilityId(AccessibilityId.HorizontalDefaultButtonChecked)));
}
[TestMethod]
public void AppliedLayouts_VerifyDisconnectedMonitorsLayoutsAreNotChanged()
{
InitFileData();
EditorParameters editorParameters = new EditorParameters();
ParamsWrapper parameters = new ParamsWrapper
{
ProcessId = 1,
SpanZonesAcrossMonitors = false,
Monitors = new List<NativeMonitorDataWrapper>
{
new NativeMonitorDataWrapper
{
Monitor = "monitor-1",
MonitorInstanceId = "instance-id-1",
MonitorSerialNumber = "serial-number-1",
MonitorNumber = 1,
VirtualDesktop = "{FF34D993-73F3-4B8C-AA03-73730A01D6A8}",
Dpi = 96,
LeftCoordinate = 0,
TopCoordinate = 0,
WorkAreaHeight = 1040,
WorkAreaWidth = 1920,
MonitorHeight = 1080,
MonitorWidth = 1920,
IsSelected = true,
},
},
};
FancyZonesEditorHelper.Files.ParamsIOHelper.WriteData(editorParameters.Serialize(parameters));
AppliedLayouts appliedLayouts = new AppliedLayouts();
AppliedLayouts.AppliedLayoutsListWrapper appliedLayoutsWrapper = new AppliedLayouts.AppliedLayoutsListWrapper
{
AppliedLayouts = new List<AppliedLayouts.AppliedLayoutWrapper>
{
new AppliedLayouts.AppliedLayoutWrapper
{
Device = new AppliedLayouts.AppliedLayoutWrapper.DeviceIdWrapper
{
Monitor = "monitor-2",
MonitorInstance = "instance-id-2",
SerialNumber = "serial-number-2",
MonitorNumber = 2,
VirtualDesktop = "{FF34D993-73F3-4B8C-AA03-73730A01D6A8}",
},
AppliedLayout = new AppliedLayouts.AppliedLayoutWrapper.LayoutWrapper
{
Uuid = "{00000000-0000-0000-0000-000000000000}",
Type = LayoutType.Focus.TypeToString(),
ShowSpacing = true,
Spacing = 10,
ZoneCount = 4,
SensitivityRadius = 30,
},
},
new AppliedLayouts.AppliedLayoutWrapper
{
Device = new AppliedLayouts.AppliedLayoutWrapper.DeviceIdWrapper
{
Monitor = "monitor-3",
MonitorInstance = "instance-id-3",
SerialNumber = "serial-number-3",
MonitorNumber = 1,
VirtualDesktop = "{FF34D993-73F3-4B8C-AA03-73730A01D6A8}",
},
AppliedLayout = new AppliedLayouts.AppliedLayoutWrapper.LayoutWrapper
{
Uuid = "{00000000-0000-0000-0000-000000000000}",
Type = LayoutType.Columns.TypeToString(),
ShowSpacing = true,
Spacing = 10,
ZoneCount = 1,
SensitivityRadius = 20,
},
},
},
};
FancyZonesEditorHelper.Files.AppliedLayoutsIOHelper.WriteData(appliedLayouts.Serialize(appliedLayoutsWrapper));
this.RestartScopeExe();
Session.Find<Element>(TestConstants.TemplateLayoutNames[LayoutType.Rows]).Click();
// check the file
var data = appliedLayouts.Read(appliedLayouts.File);
Assert.AreEqual(parameters.Monitors.Count + appliedLayoutsWrapper.AppliedLayouts.Count, data.AppliedLayouts.Count);
foreach (var monitor in parameters.Monitors)
{
Assert.IsNotNull(data.AppliedLayouts.Find(x => x.Device.Monitor == monitor.Monitor));
}
foreach (var layout in appliedLayoutsWrapper.AppliedLayouts)
{
Assert.IsNotNull(data.AppliedLayouts.Find(x => x.Device.Monitor == layout.Device.Monitor));
}
}
[TestMethod]
public void AppliedLayouts_VerifyOtherVirtualDesktopsAreNotChanged()
{
InitFileData();
string virtualDesktop1 = "{11111111-1111-1111-1111-111111111111}";
string virtualDesktop2 = "{22222222-2222-2222-2222-222222222222}";
EditorParameters editorParameters = new EditorParameters();
ParamsWrapper parameters = new ParamsWrapper
{
ProcessId = 1,
SpanZonesAcrossMonitors = false,
Monitors = new List<NativeMonitorDataWrapper>
{
new NativeMonitorDataWrapper
{
Monitor = "monitor-1",
MonitorInstanceId = "instance-id-1",
MonitorSerialNumber = "serial-number-1",
MonitorNumber = 1,
VirtualDesktop = virtualDesktop1,
Dpi = 96,
LeftCoordinate = 0,
TopCoordinate = 0,
WorkAreaHeight = 1040,
WorkAreaWidth = 1920,
MonitorHeight = 1080,
MonitorWidth = 1920,
IsSelected = true,
},
},
};
FancyZonesEditorHelper.Files.ParamsIOHelper.WriteData(editorParameters.Serialize(parameters));
AppliedLayouts appliedLayouts = new AppliedLayouts();
AppliedLayouts.AppliedLayoutsListWrapper appliedLayoutsWrapper = new AppliedLayouts.AppliedLayoutsListWrapper
{
AppliedLayouts = new List<AppliedLayouts.AppliedLayoutWrapper>
{
new AppliedLayouts.AppliedLayoutWrapper
{
Device = new AppliedLayouts.AppliedLayoutWrapper.DeviceIdWrapper
{
Monitor = "monitor-1",
MonitorInstance = "instance-id-1",
SerialNumber = "serial-number-1",
MonitorNumber = 1,
VirtualDesktop = virtualDesktop2,
},
AppliedLayout = new AppliedLayouts.AppliedLayoutWrapper.LayoutWrapper
{
Uuid = "{00000000-0000-0000-0000-000000000000}",
Type = LayoutType.Focus.TypeToString(),
ShowSpacing = true,
Spacing = 10,
ZoneCount = 4,
SensitivityRadius = 30,
},
},
},
};
FancyZonesEditorHelper.Files.AppliedLayoutsIOHelper.WriteData(appliedLayouts.Serialize(appliedLayoutsWrapper));
this.RestartScopeExe();
Session.Find<Element>(TestConstants.TemplateLayoutNames[LayoutType.Rows]).Click();
// check the file
var data = appliedLayouts.Read(appliedLayouts.File);
Assert.AreEqual(parameters.Monitors.Count + appliedLayoutsWrapper.AppliedLayouts.Count, data.AppliedLayouts.Count);
Assert.IsNotNull(data.AppliedLayouts.Find(x => x.Device.VirtualDesktop == virtualDesktop1));
Assert.IsNotNull(data.AppliedLayouts.Find(x => x.Device.VirtualDesktop == virtualDesktop2));
Assert.AreEqual(appliedLayoutsWrapper.AppliedLayouts[0].AppliedLayout.Type, data.AppliedLayouts.Find(x => x.Device.VirtualDesktop == virtualDesktop2).AppliedLayout.Type);
Assert.AreEqual(LayoutType.Rows.TypeToString(), data.AppliedLayouts.Find(x => x.Device.VirtualDesktop == virtualDesktop1).AppliedLayout.Type);
}
private void InitFileData()
{
FancyZonesEditorHelper.Files.Restore();
EditorParameters editorParameters = new EditorParameters();
ParamsWrapper parameters = new ParamsWrapper
{
ProcessId = 1,
SpanZonesAcrossMonitors = false,
Monitors = new List<NativeMonitorDataWrapper>
{
new NativeMonitorDataWrapper
{
Monitor = "monitor-1",
MonitorInstanceId = "instance-id-1",
MonitorSerialNumber = "serial-number-1",
MonitorNumber = 1,
VirtualDesktop = "{FF34D993-73F3-4B8C-AA03-73730A01D6A8}",
Dpi = 192, // 200% scaling
LeftCoordinate = 0,
TopCoordinate = 0,
WorkAreaHeight = 1040,
WorkAreaWidth = 1920,
MonitorHeight = 1080,
MonitorWidth = 1920,
IsSelected = true,
},
},
};
FancyZonesEditorHelper.Files.ParamsIOHelper.WriteData(editorParameters.Serialize(parameters));
DefaultLayouts defaultLayouts = new DefaultLayouts();
DefaultLayouts.DefaultLayoutsListWrapper defaultLayoutsListWrapper = new DefaultLayouts.DefaultLayoutsListWrapper
{
DefaultLayouts = new List<DefaultLayouts.DefaultLayoutWrapper> { },
};
FancyZonesEditorHelper.Files.DefaultLayoutsIOHelper.WriteData(defaultLayouts.Serialize(defaultLayoutsListWrapper));
LayoutHotkeys layoutHotkeys = new LayoutHotkeys();
LayoutHotkeys.LayoutHotkeysWrapper layoutHotkeysWrapper = new LayoutHotkeys.LayoutHotkeysWrapper
{
LayoutHotkeys = new List<LayoutHotkeys.LayoutHotkeyWrapper> { },
};
FancyZonesEditorHelper.Files.LayoutHotkeysIOHelper.WriteData(layoutHotkeys.Serialize(layoutHotkeysWrapper));
AppliedLayouts appliedLayouts = new AppliedLayouts();
AppliedLayouts.AppliedLayoutsListWrapper appliedLayoutsWrapper = new AppliedLayouts.AppliedLayoutsListWrapper
{
AppliedLayouts = new List<AppliedLayouts.AppliedLayoutWrapper> { },
};
FancyZonesEditorHelper.Files.AppliedLayoutsIOHelper.WriteData(appliedLayouts.Serialize(appliedLayoutsWrapper));
CustomLayouts customLayouts = new CustomLayouts();
CustomLayouts.CustomLayoutListWrapper customLayoutListWrapper = new CustomLayouts.CustomLayoutListWrapper
{
CustomLayouts = new List<CustomLayouts.CustomLayoutWrapper> { },
};
FancyZonesEditorHelper.Files.CustomLayoutsIOHelper.WriteData(customLayouts.Serialize(customLayoutListWrapper));
LayoutTemplates layoutTemplates = new LayoutTemplates();
LayoutTemplates.TemplateLayoutsListWrapper templateLayoutsListWrapper = new LayoutTemplates.TemplateLayoutsListWrapper
{
LayoutTemplates = new List<LayoutTemplates.TemplateLayoutWrapper>
{
new LayoutTemplates.TemplateLayoutWrapper
{
Type = LayoutType.Blank.TypeToString(),
},
new LayoutTemplates.TemplateLayoutWrapper
{
Type = LayoutType.Focus.TypeToString(),
ZoneCount = 10,
},
new LayoutTemplates.TemplateLayoutWrapper
{
Type = LayoutType.Rows.TypeToString(),
ZoneCount = 2,
ShowSpacing = true,
Spacing = 10,
SensitivityRadius = 10,
},
new LayoutTemplates.TemplateLayoutWrapper
{
Type = LayoutType.Columns.TypeToString(),
ZoneCount = 2,
ShowSpacing = true,
Spacing = 20,
SensitivityRadius = 20,
},
new LayoutTemplates.TemplateLayoutWrapper
{
Type = LayoutType.Grid.TypeToString(),
ZoneCount = 4,
ShowSpacing = false,
Spacing = 10,
SensitivityRadius = 30,
},
new LayoutTemplates.TemplateLayoutWrapper
{
Type = LayoutType.PriorityGrid.TypeToString(),
ZoneCount = 3,
ShowSpacing = true,
Spacing = 1,
SensitivityRadius = 40,
},
},
};
FancyZonesEditorHelper.Files.LayoutTemplatesIOHelper.WriteData(layoutTemplates.Serialize(templateLayoutsListWrapper));
}
}
}

View File

@@ -0,0 +1,78 @@
// Copyright (c) Microsoft Corporation
// The Microsoft Corporation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information.
using System.Collections.Generic;
using System.Text.Json;
using static FancyZonesEditorCommon.Data.AppZoneHistory.AppZoneHistoryWrapper;
using static FancyZonesEditorCommon.Data.CustomLayouts;
namespace FancyZonesEditorCommon.Data
{
public class AppZoneHistory : EditorData<AppZoneHistory.AppZoneHistoryListWrapper>
{
public string File
{
get
{
return GetDataFolder() + "\\Microsoft\\PowerToys\\FancyZones\\app-zone-history.json";
}
}
public struct AppZoneHistoryWrapper
{
public struct ZoneHistoryWrapper
{
public int[][] ZoneIndexSet { get; set; }
public DeviceIdWrapper Device { get; set; }
public string ZonesetUuid { get; set; }
}
public struct DeviceIdWrapper
{
public string Monitor { get; set; }
public string MonitorInstance { get; set; }
public int MonitorNumber { get; set; }
public string SerialNumber { get; set; }
public string VirtualDesktop { get; set; }
}
public string AppPath { get; set; }
public List<ZoneHistoryWrapper> History { get; set; }
}
public struct AppZoneHistoryListWrapper
{
public List<AppZoneHistoryWrapper> AppZoneHistory { get; set; }
}
public JsonElement ToJsonElement(ZoneHistoryWrapper info)
{
string json = JsonSerializer.Serialize(info, this.JsonOptions);
return JsonSerializer.Deserialize<JsonElement>(json);
}
public JsonElement ToJsonElement(DeviceIdWrapper info)
{
string json = JsonSerializer.Serialize(info, this.JsonOptions);
return JsonSerializer.Deserialize<JsonElement>(json);
}
public ZoneHistoryWrapper ZoneHistoryFromJsonElement(string json)
{
return JsonSerializer.Deserialize<ZoneHistoryWrapper>(json, this.JsonOptions);
}
public DeviceIdWrapper GridFromJsonElement(string json)
{
return JsonSerializer.Deserialize<DeviceIdWrapper>(json, this.JsonOptions);
}
}
}

View File

@@ -0,0 +1,47 @@
// Copyright (c) Microsoft Corporation
// The Microsoft Corporation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information.
using FancyZonesEditorCommon.Data;
namespace Microsoft.FancyZonesEditor.UITests.Utils
{
public class FancyZonesEditorFiles
{
public IOTestHelper ParamsIOHelper { get; }
public IOTestHelper AppliedLayoutsIOHelper { get; }
public IOTestHelper CustomLayoutsIOHelper { get; }
public IOTestHelper DefaultLayoutsIOHelper { get; }
public IOTestHelper LayoutHotkeysIOHelper { get; }
public IOTestHelper LayoutTemplatesIOHelper { get; }
public IOTestHelper AppZoneHistoryIOHelper { get; }
public FancyZonesEditorFiles()
{
ParamsIOHelper = new IOTestHelper(new EditorParameters().File);
AppliedLayoutsIOHelper = new IOTestHelper(new AppliedLayouts().File);
CustomLayoutsIOHelper = new IOTestHelper(new CustomLayouts().File);
DefaultLayoutsIOHelper = new IOTestHelper(new DefaultLayouts().File);
LayoutHotkeysIOHelper = new IOTestHelper(new LayoutHotkeys().File);
LayoutTemplatesIOHelper = new IOTestHelper(new LayoutTemplates().File);
AppZoneHistoryIOHelper = new IOTestHelper(new AppZoneHistory().File);
}
public void Restore()
{
ParamsIOHelper.RestoreData();
AppliedLayoutsIOHelper.RestoreData();
CustomLayoutsIOHelper.RestoreData();
DefaultLayoutsIOHelper.RestoreData();
LayoutHotkeysIOHelper.RestoreData();
LayoutTemplatesIOHelper.RestoreData();
AppZoneHistoryIOHelper.RestoreData();
}
}
}

View File

@@ -0,0 +1,288 @@
// Copyright (c) Microsoft Corporation
// The Microsoft Corporation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information.
using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Globalization;
using System.IO;
using System.Reflection;
using FancyZonesEditorCommon.Data;
using Microsoft.FancyZonesEditor.UITests.Utils;
using Microsoft.PowerToys.UITest;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using ModernWpf.Controls;
using OpenQA.Selenium.Appium.Windows;
using OpenQA.Selenium.Interactions;
namespace Microsoft.FancyZonesEditor.UnitTests.Utils
{
public class FancyZonesEditorHelper
{
private static FancyZonesEditorFiles? _files;
public static FancyZonesEditorFiles Files
{
get
{
if (_files == null)
{
_files = new FancyZonesEditorFiles();
}
return _files;
}
}
public static class AccessibilityId
{
// main window
public const string MainWindow = "MainWindow1";
public const string Monitors = "Monitors";
public const string NewLayoutButton = "NewLayoutButton";
// layout card
public const string EditLayoutButton = "EditLayoutButton";
// edit layout window: common for template and custom layouts
public const string DialogTitle = "EditLayoutDialogTitle";
public const string SensitivitySlider = "SensitivityInput";
public const string SpacingSlider = "Spacing";
public const string SpacingToggle = "spaceAroundSetting";
public const string HorizontalDefaultButtonUnchecked = "SetLayoutAsHorizontalDefaultButton";
public const string VerticalDefaultButtonUnchecked = "SetLayoutAsVerticalDefaultButton";
public const string HorizontalDefaultButtonChecked = "HorizontalDefaultLayoutButton";
public const string VerticalDefaultButtonChecked = "VerticalDefaultLayoutButton";
// edit template layout window
public const string CopyTemplate = "createFromTemplateLayoutButton";
public const string TemplateZoneSlider = "TemplateZoneCount";
// edit custom layout window
public const string DuplicateLayoutButton = "duplicateLayoutButton";
public const string DeleteLayoutButton = "deleteLayoutButton";
public const string KeySelectionComboBox = "quickKeySelectionComboBox";
public const string EditZonesButton = "editZoneLayoutButton";
public const string DeleteTextButton = "DeleteButton";
public const string HotkeyComboBox = "quickKeySelectionComboBox";
public const string NewZoneButton = "newZoneButton";
public const string TopRightCorner = "NEResize";
// layout creation dialog
public const string GridRadioButton = "GridLayoutRadioButton";
public const string CanvasRadioButton = "CanvasLayoutRadioButton";
// confirmation dialog
public const string PrimaryButton = "PrimaryButton";
public const string SecondaryButton = "SecondaryButton";
}
public static class ElementName
{
public const string Save = "Save";
public const string Cancel = "Cancel";
// context menu
public const string Edit = "Edit";
public const string EditZones = "Edit zones";
public const string Delete = "Delete";
public const string Duplicate = "Duplicate";
public const string CreateCustomLayout = "Create custom layout";
// canvas layout editor
public const string CanvasEditorWindow = "Canvas layout editor";
// grid layout editor
public const string GridLayoutEditor = "Grid layout editor";
public const string MergeZonesButton = "Merge zones";
}
public static class ClassName
{
public const string ContextMenu = "ContextMenu";
public const string TextBox = "TextBox";
public const string Popup = "Popup";
// layout editor
public const string CanvasZone = "CanvasZone";
public const string GridZone = "GridZone";
public const string Button = "Button";
public const string Thumb = "Thumb";
}
public static void ClickContextMenuItem(Session session, string layoutName, string menuItem)
{
session.Find<Element>(layoutName).Click(true);
session.Find<Element>(By.ClassName(ClassName.ContextMenu)).Find<Element>(menuItem).Click();
}
public static Custom? GetZone(Session session, int zoneNumber, string zoneClassName)
{
var zones = session.FindAll<Custom>(By.ClassName(zoneClassName));
foreach (var zone in zones)
{
try
{
zone.Find<Element>(zoneNumber.ToString(CultureInfo.InvariantCulture));
Assert.IsNotNull(zone, "zone not found");
return zone;
}
catch
{
// required number not found in the zone
}
}
Assert.IsNotNull(zones, $"zoneClassName : {zoneClassName} not found");
return null;
}
public static void MergeGridZones(Session session, int zoneNumber1, int zoneNumber2)
{
var zone1 = GetZone(session, zoneNumber1, ClassName.GridZone);
var zone2 = GetZone(session, zoneNumber2, ClassName.GridZone);
Assert.IsNotNull(zone1, "first zone not found");
Assert.IsNotNull(zone2, "second zone not found");
if (zone1 == null || zone2 == null)
{
Assert.Fail("zone is null");
return;
}
zone1.Drag(zone2);
session.Find<Element>(ElementName.MergeZonesButton).Click();
}
public static void MoveSplitter(Session session, int index, int xOffset, int yOffset)
{
var thumbs = session.FindAll<Thumb>(By.ClassName(ClassName.Thumb));
if (thumbs.Count == 0 || index >= thumbs.Count)
{
return;
}
thumbs[index].Drag(xOffset, yOffset);
Console.WriteLine($"Moving splitter {index} by ({xOffset}, {yOffset})");
}
public static void ClickDeleteZone(Session session, int zoneNumber)
{
var zone = FancyZonesEditorHelper.GetZone(session, zoneNumber, ClassName.CanvasZone);
Assert.IsNotNull(zone);
var button = zone.Find<Button>(By.ClassName(ClassName.Button));
Assert.IsNotNull(button);
button.Click();
}
public static void InitFancyZonesLayout()
{
// prepare files to launch Editor without errors
EditorParameters editorParameters = new EditorParameters();
EditorParameters.ParamsWrapper parameters = new EditorParameters.ParamsWrapper
{
ProcessId = 1,
SpanZonesAcrossMonitors = false,
Monitors = new List<EditorParameters.NativeMonitorDataWrapper>
{
new EditorParameters.NativeMonitorDataWrapper
{
Monitor = "monitor-1",
MonitorInstanceId = "instance-id-1",
MonitorSerialNumber = "serial-number-1",
MonitorNumber = 1,
VirtualDesktop = "{FF34D993-73F3-4B8C-AA03-73730A01D6A8}",
Dpi = 96,
LeftCoordinate = 0,
TopCoordinate = 0,
WorkAreaHeight = 1040,
WorkAreaWidth = 1920,
MonitorHeight = 1080,
MonitorWidth = 1920,
IsSelected = true,
},
},
};
FancyZonesEditorHelper.Files.ParamsIOHelper.WriteData(editorParameters.Serialize(parameters));
LayoutTemplates layoutTemplates = new LayoutTemplates();
LayoutTemplates.TemplateLayoutsListWrapper templateLayoutsListWrapper = new LayoutTemplates.TemplateLayoutsListWrapper
{
LayoutTemplates = new List<LayoutTemplates.TemplateLayoutWrapper>
{
new LayoutTemplates.TemplateLayoutWrapper
{
Type = Constants.TemplateLayoutJsonTags[Constants.TemplateLayout.Empty],
},
new LayoutTemplates.TemplateLayoutWrapper
{
Type = Constants.TemplateLayoutJsonTags[Constants.TemplateLayout.Focus],
ZoneCount = 10,
},
new LayoutTemplates.TemplateLayoutWrapper
{
Type = Constants.TemplateLayoutJsonTags[Constants.TemplateLayout.Rows],
ZoneCount = 2,
ShowSpacing = true,
Spacing = 10,
SensitivityRadius = 10,
},
new LayoutTemplates.TemplateLayoutWrapper
{
Type = Constants.TemplateLayoutJsonTags[Constants.TemplateLayout.Columns],
ZoneCount = 2,
ShowSpacing = true,
Spacing = 20,
SensitivityRadius = 20,
},
new LayoutTemplates.TemplateLayoutWrapper
{
Type = Constants.TemplateLayoutJsonTags[Constants.TemplateLayout.Grid],
ZoneCount = 4,
ShowSpacing = false,
Spacing = 10,
SensitivityRadius = 30,
},
new LayoutTemplates.TemplateLayoutWrapper
{
Type = Constants.TemplateLayoutJsonTags[Constants.TemplateLayout.PriorityGrid],
ZoneCount = 3,
ShowSpacing = true,
Spacing = 1,
SensitivityRadius = 40,
},
},
};
FancyZonesEditorHelper.Files.LayoutTemplatesIOHelper.WriteData(layoutTemplates.Serialize(templateLayoutsListWrapper));
CustomLayouts customLayouts = new CustomLayouts();
CustomLayouts.CustomLayoutListWrapper customLayoutListWrapper = new CustomLayouts.CustomLayoutListWrapper
{
CustomLayouts = new List<CustomLayouts.CustomLayoutWrapper> { },
};
FancyZonesEditorHelper.Files.CustomLayoutsIOHelper.WriteData(customLayouts.Serialize(customLayoutListWrapper));
DefaultLayouts defaultLayouts = new DefaultLayouts();
DefaultLayouts.DefaultLayoutsListWrapper defaultLayoutsListWrapper = new DefaultLayouts.DefaultLayoutsListWrapper
{
DefaultLayouts = new List<DefaultLayouts.DefaultLayoutWrapper> { },
};
FancyZonesEditorHelper.Files.DefaultLayoutsIOHelper.WriteData(defaultLayouts.Serialize(defaultLayoutsListWrapper));
LayoutHotkeys layoutHotkeys = new LayoutHotkeys();
LayoutHotkeys.LayoutHotkeysWrapper layoutHotkeysWrapper = new LayoutHotkeys.LayoutHotkeysWrapper
{
LayoutHotkeys = new List<LayoutHotkeys.LayoutHotkeyWrapper> { },
};
FancyZonesEditorHelper.Files.LayoutHotkeysIOHelper.WriteData(layoutHotkeys.Serialize(layoutHotkeysWrapper));
AppliedLayouts appliedLayouts = new AppliedLayouts();
AppliedLayouts.AppliedLayoutsListWrapper appliedLayoutsWrapper = new AppliedLayouts.AppliedLayoutsListWrapper
{
AppliedLayouts = new List<AppliedLayouts.AppliedLayoutWrapper> { },
};
FancyZonesEditorHelper.Files.AppliedLayoutsIOHelper.WriteData(appliedLayouts.Serialize(appliedLayoutsWrapper));
}
}
}

View File

@@ -0,0 +1,123 @@
// Copyright (c) Microsoft Corporation
// The Microsoft Corporation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information.
using System;
using System.IO;
using System.IO.Abstractions;
using System.Threading.Tasks;
namespace Microsoft.FancyZonesEditor.UITests.Utils
{
public class IOTestHelper
{
private readonly IFileSystem _fileSystem = new FileSystem();
private string _file;
private string _data = string.Empty;
public IOTestHelper(string file)
{
_file = file;
if (_fileSystem.File.Exists(_file))
{
_data = ReadFile(_file);
}
else
{
var path = Path.GetDirectoryName(file);
if (path != null)
{
_fileSystem.Directory.CreateDirectory(path);
}
}
}
~IOTestHelper()
{
RestoreData();
}
public void RestoreData()
{
if (_data != string.Empty)
{
WriteData(_data);
}
else
{
DeleteFile();
}
}
public void WriteData(string data)
{
var attempts = 0;
while (attempts < 10)
{
try
{
_fileSystem.File.WriteAllText(_file, data);
}
catch (Exception)
{
Task.Delay(10).Wait();
}
attempts++;
}
}
// For get app zone history data
public string GetData()
{
return ReadFile(_file);
}
private string ReadFile(string fileName)
{
var attempts = 0;
while (attempts < 10)
{
try
{
using (Stream inputStream = _fileSystem.File.Open(fileName, FileMode.Open))
using (StreamReader reader = new StreamReader(inputStream))
{
string data = reader.ReadToEnd();
inputStream.Close();
return data;
}
}
catch (Exception)
{
Task.Delay(10).Wait();
}
attempts++;
}
return string.Empty;
}
public void DeleteFile()
{
var attempts = 0;
while (attempts < 10)
{
try
{
_fileSystem.File.Delete(_file);
}
catch (Exception)
{
Task.Delay(10).Wait();
}
attempts++;
}
}
}
}

View File

@@ -0,0 +1,108 @@
## This is for tracking UI-Tests migration progress for FancyZones Editor Module
Refer to [release check list] (https://github.com/microsoft/PowerToys/blob/releaseChecklist/doc/releases/tests-checklist-template.md) for all manual tests.
### Existing Manual Test-cases run by previous PowerToys owner
For existing manual test-cases, we will convert them to UI-Tests and run them in CI and Release pipeline
* Launch Host File Editor:
- [ ] Open editor from the settings
- [ ] Open editor with a shortcut
- [ ] Create a new layout (grid and canvas)
- [ ] Duplicate a template and a custom layout
- [ ] Delete layout
- [ ] Edit templates (number of zones, spacing, distance to highlight adjacent zones). Verify after reopening the editor that saved settings are kept the same.
- [ ] Edit canvas layout: zones size and position, create or delete zones.
- [ ] Edit grid layout: split, merge, resize zones.
- [ ] Check Save and apply and Cancel buttons behavior after editing.
- [ ] Assign a layout to each monitor.
- [ ] Assign keys to quickly switch layouts (custom layouts only), Win + Ctrl + Alt + number.
- [ ] Assign horizontal and vertical default layouts
- [ ] Test duplicate layout focus
- Select any layout X in 'Templates' or 'Custom' section by click left mouse button
- Mouse right button click on any layout Y in 'Templates' or 'Custom' sections
- Duplicate it by clicking 'Create custom layout' (Templates section) or 'Duplicate' in 'Custom' section
- Expect the layout Y is duplicated
### Additional UI-Tests cases
- [ ] Add test data and start → verify data is correct (custom layouts, template layouts, defaults, shortcut keys)
- [ ] Create a new canvas - verify layout exists
- [ ] Create a new canvas - cancel - doesnt exist
- [ ] Create a new grid - verify the layout exists
- [ ] Create a new grid - cancel - doesnt exist
- [ ] Duplicate template by button (+ check default)
- [ ] Duplicate template by menu (+ check default)
- [ ] Duplicate custom by button (+ check shortcut key and default)
- [ ] Duplicate custom by menu (+ check shortcut key and default)
- [ ] Delete non-applied layout
- [ ] Delete applied layout
- [ ] Delete-cancel
- [ ] Delete from context menu
- [ ] Delete: hotkey released
- [ ] Delete: default layout reset to default-default
- [ ] Edit template and save
- [ ] Edit template and cancel
- [ ] Edit custom and save
- [ ] Edit custom and cancel
- [ ] Edit canvas: add zone
- [ ] Edit canvas: delete zone
- [ ] Edit canvas: move zone
- [ ] Edit canvas: resize zone
- [ ] Edit grid: split zone
- [ ] Edit grid: merge zones
- [ ] Edit grid: move splitter
- [ ] UI Init: assigned layouts selected
- [ ] UI Init: applied default - check params
- [ ] UI Init: assigned custom layout, but id not found
- [ ] Assign the same template but with different params to monitors
- [ ] Assign layout on each monitor
- [ ] Assign custom
- [ ] Assign template
- [ ] Assign shortcut key and save
- [ ] Assign shortcut key and cancel
- [ ] Reset shortcut key and save
- [ ] Reset shortcut key and cancel
- [ ] Set default layout + verify both prev and current after reopening
- [ ] applied-layouts.json keeps info about not connected devices - verify theyre present after closing
- [ ] applied-layouts.json keeps info about other virtual desktops
- [ ] first launch without custom-layouts.json, default-layouts.json, layout-hotkeys.json and layout-templates.json