From 1d704e3114cf55bfcff323fe37e51c7a020137e1 Mon Sep 17 00:00:00 2001 From: Zhaopeng Wang Date: Wed, 5 Mar 2025 19:06:19 +0800 Subject: [PATCH] add DefaultLayoutsTest --- src/common/UITestAutomation/UITestBase.cs | 2 +- .../DefaultLayoutsTest.cs | 307 +++++++++++++++++- .../RunFancyZonesEditorTest.cs | 17 + 3 files changed, 311 insertions(+), 15 deletions(-) diff --git a/src/common/UITestAutomation/UITestBase.cs b/src/common/UITestAutomation/UITestBase.cs index 1fb37468ff2a..40de0dc99119 100644 --- a/src/common/UITestAutomation/UITestBase.cs +++ b/src/common/UITestAutomation/UITestBase.cs @@ -55,7 +55,7 @@ public void TestInit() [TestCleanup] public void TestClean() { - // this.sessionHelper.Cleanup(); + this.sessionHelper.Cleanup(); } /// diff --git a/src/modules/fancyzones/UITests-FancyZonesEditor/DefaultLayoutsTest.cs b/src/modules/fancyzones/UITests-FancyZonesEditor/DefaultLayoutsTest.cs index 06c06d53e289..398353b687f8 100644 --- a/src/modules/fancyzones/UITests-FancyZonesEditor/DefaultLayoutsTest.cs +++ b/src/modules/fancyzones/UITests-FancyZonesEditor/DefaultLayoutsTest.cs @@ -3,13 +3,16 @@ // 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.UITests; using Microsoft.FancyZonesEditor.UnitTests.Utils; using Microsoft.PowerToys.UITest; using Microsoft.VisualStudio.TestTools.UnitTesting; -using Windows.UI; +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 { @@ -19,7 +22,108 @@ public class DefaultLayoutsTest : UITestBase public DefaultLayoutsTest() : base(PowerToysModule.FancyZone) { - FancyZonesEditorHelper.Files.ParamsIOHelper.RestoreData(); + } + + 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 + { + 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 { }, + }), + }, + 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 { }, + }), + }, + 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 { }, + }), + }, + 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 { }, + }), + }, + }, + }; + + private static readonly DefaultLayoutsListWrapper Layouts = new DefaultLayoutsListWrapper + { + DefaultLayouts = new List + { + 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() + { + var defaultLayouts = new DefaultLayouts(); + FancyZonesEditorHelper.Files.DefaultLayoutsIOHelper.WriteData(defaultLayouts.Serialize(Layouts)); + EditorParameters editorParameters = new EditorParameters(); ParamsWrapper parameters = new ParamsWrapper { @@ -34,7 +138,7 @@ public DefaultLayoutsTest() MonitorSerialNumber = "serial-number-1", MonitorNumber = 1, VirtualDesktop = "{FF34D993-73F3-4B8C-AA03-73730A01D6A8}", - Dpi = 96, + Dpi = 192, LeftCoordinate = 0, TopCoordinate = 0, WorkAreaHeight = 1040, @@ -62,23 +166,198 @@ public DefaultLayoutsTest() }, }; 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 + { + 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 { }, + }; + 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(); } [TestMethod] - public void ClickMonitor() + public void Initialize() { - Assert.IsNotNull(Session.Find("Monitor 1")); - Assert.IsNotNull(Session.Find("Monitor 2")); + CheckTemplateLayouts(LayoutType.Grid, null); + CheckCustomLayouts(string.Empty, CustomLayouts.CustomLayouts[0].Uuid); + } - // verify that the monitor 1 is selected initially - Assert.IsTrue(Session.Find("Monitor 1").Selected); - Assert.IsFalse(Session.Find("Monitor 2").Selected); + [TestMethod] + public void Assign_Cancel() + { + // assign Focus as a default horizontal and vertical layout + Session.Find(TestConstants.TemplateLayoutNames[LayoutType.Focus]).Find