diff --git a/src/common/UITestAutomation/Element/Element.cs b/src/common/UITestAutomation/Element/Element.cs
index 936b2734eea2..70bdc690c08e 100644
--- a/src/common/UITestAutomation/Element/Element.cs
+++ b/src/common/UITestAutomation/Element/Element.cs
@@ -3,7 +3,10 @@
// See the LICENSE file in the project root for more information.
using System.Collections.ObjectModel;
+using System.Drawing;
using System.Runtime.CompilerServices;
+using System.Xml.Linq;
+using ABI.Windows.Foundation;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using OpenQA.Selenium;
using OpenQA.Selenium.Appium;
@@ -64,6 +67,14 @@ public bool Selected
get { return this.windowsElement?.Selected ?? false; }
}
+ ///
+ /// Gets the Rect of the UI element.
+ ///
+ public Rectangle? Rect
+ {
+ get { return this.windowsElement?.Rect; }
+ }
+
///
/// Gets the AutomationID of the UI element.
///
@@ -139,6 +150,42 @@ public virtual void DoubleClick()
});
}
+ ///
+ /// Drag element move offset.
+ ///
+ /// The offsetX to move.
+ /// The offsetY to move.
+ public void Drag(int offsetX, int offsetY)
+ {
+ PerformAction((actions, windowElement) =>
+ {
+ actions.MoveToElement(windowElement).MoveByOffset(10, 10).ClickAndHold(windowElement).MoveByOffset(offsetX, offsetY).Release();
+ actions.Build().Perform();
+ });
+ }
+
+ ///
+ /// Drag element move to other element.
+ ///
+ /// Move to this element.
+ public void Drag(Element element)
+ {
+ PerformAction((actions, windowElement) =>
+ {
+ actions.MoveToElement(windowElement).ClickAndHold();
+ Assert.IsNotNull(element.windowsElement, "element is null");
+ int dx = (element.windowsElement.Rect.X - windowElement.Rect.X) / 10;
+ int dy = (element.windowsElement.Rect.Y - windowElement.Rect.Y) / 10;
+ for (int i = 0; i < 10; i++)
+ {
+ actions.MoveByOffset(dx, dy);
+ }
+
+ actions.Release();
+ actions.Build().Perform();
+ });
+ }
+
///
/// Send Key of the element.
///
diff --git a/src/modules/fancyzones/UITests-FancyZonesEditor/EditLayoutTests.cs b/src/modules/fancyzones/UITests-FancyZonesEditor/EditLayoutTests.cs
new file mode 100644
index 000000000000..ade84b7750d8
--- /dev/null
+++ b/src/modules/fancyzones/UITests-FancyZonesEditor/EditLayoutTests.cs
@@ -0,0 +1,626 @@
+// 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)
+ {
+ }
+
+ private static readonly CustomLayouts.CustomLayoutListWrapper Layouts = new CustomLayouts.CustomLayoutListWrapper
+ {
+ CustomLayouts = new List
+ {
+ 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 { 5000, 5000 },
+ ColumnsPercentage = new List { 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 { 3333, 3333, 3334 },
+ ColumnsPercentage = new List { 3333, 3333, 3334 },
+ 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
+ {
+ 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()
+ {
+ EditorParameters editorParameters = new EditorParameters();
+ ParamsWrapper parameters = new ParamsWrapper
+ {
+ ProcessId = 1,
+ SpanZonesAcrossMonitors = false,
+ Monitors = new List
+ {
+ 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
+ {
+ 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 { },
+ };
+ FancyZonesEditorHelper.Files.DefaultLayoutsIOHelper.WriteData(defaultLayouts.Serialize(defaultLayoutsListWrapper));
+
+ LayoutHotkeys layoutHotkeys = new LayoutHotkeys();
+ LayoutHotkeys.LayoutHotkeysWrapper layoutHotkeysWrapper = new LayoutHotkeys.LayoutHotkeysWrapper
+ {
+ LayoutHotkeys = new List { },
+ };
+ FancyZonesEditorHelper.Files.LayoutHotkeysIOHelper.WriteData(layoutHotkeys.Serialize(layoutHotkeysWrapper));
+
+ AppliedLayouts appliedLayouts = new AppliedLayouts();
+ AppliedLayouts.AppliedLayoutsListWrapper appliedLayoutsWrapper = new AppliedLayouts.AppliedLayoutsListWrapper
+ {
+ AppliedLayouts = new List { },
+ };
+ FancyZonesEditorHelper.Files.AppliedLayoutsIOHelper.WriteData(appliedLayouts.Serialize(appliedLayoutsWrapper));
+
+ this.RestartScopeExe();
+ }
+
+ [TestCleanup]
+ public void TestCleanup()
+ {
+ FancyZonesEditorHelper.Files.Restore();
+ this.TestClean();
+ }
+
+ [TestMethod]
+ public void OpenEditMode()
+ {
+ Session.Find(Layouts.CustomLayouts[0].Name).FindByAccessibilityId