From bb84eecf8c1ab1db635a9ad5f7047851457b6f5d Mon Sep 17 00:00:00 2001 From: Zhaopeng Wang Date: Wed, 5 Mar 2025 02:35:07 +0800 Subject: [PATCH] add UI Initialize Test --- .../Data/CustomLayoutEnumExtension.cs | 44 + .../UIInitializaionTest.cs | 198 ----- .../UIInitializeTest.cs | 768 ++++++++++++++++++ .../MonitorConfigurationTypeEnumExtensions.cs | 38 + 4 files changed, 850 insertions(+), 198 deletions(-) create mode 100644 src/modules/fancyzones/FancyZonesEditorCommon/Data/CustomLayoutEnumExtension.cs delete mode 100644 src/modules/fancyzones/UITests-FancyZonesEditor/UIInitializaionTest.cs create mode 100644 src/modules/fancyzones/UITests-FancyZonesEditor/UIInitializeTest.cs create mode 100644 src/modules/fancyzones/editor/FancyZonesEditor/Models/MonitorConfigurationTypeEnumExtensions.cs diff --git a/src/modules/fancyzones/FancyZonesEditorCommon/Data/CustomLayoutEnumExtension.cs b/src/modules/fancyzones/FancyZonesEditorCommon/Data/CustomLayoutEnumExtension.cs new file mode 100644 index 000000000000..4f158b3acaef --- /dev/null +++ b/src/modules/fancyzones/FancyZonesEditorCommon/Data/CustomLayoutEnumExtension.cs @@ -0,0 +1,44 @@ +// 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. + +namespace FancyZonesEditorCommon.Data +{ + public enum CustomLayout + { + Canvas, + Grid, + } + + public static class CustomLayoutEnumExtension + { + private const string CanvasJsonTag = "canvas"; + private const string GridJsonTag = "grid"; + + public static string TypeToString(this CustomLayout value) + { + switch (value) + { + case CustomLayout.Canvas: + return CanvasJsonTag; + case CustomLayout.Grid: + return GridJsonTag; + } + + return CanvasJsonTag; + } + + public static CustomLayout TypeFromString(string value) + { + switch (value) + { + case CanvasJsonTag: + return CustomLayout.Canvas; + case GridJsonTag: + return CustomLayout.Grid; + } + + return CustomLayout.Canvas; + } + } +} diff --git a/src/modules/fancyzones/UITests-FancyZonesEditor/UIInitializaionTest.cs b/src/modules/fancyzones/UITests-FancyZonesEditor/UIInitializaionTest.cs deleted file mode 100644 index 7eba8442fa6e..000000000000 --- a/src/modules/fancyzones/UITests-FancyZonesEditor/UIInitializaionTest.cs +++ /dev/null @@ -1,198 +0,0 @@ -// 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 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; - -namespace UITests_FancyZonesEditor -{ - [TestClass] - public class UIInitializaionTest : UITestBase - { - public UIInitializaionTest() - : base(PowerToysModule.FancyZone) - { - } - - [TestInitialize] - public void TestInitialize() - { - FancyZonesEditorHelper.Files.ParamsIOHelper.RestoreData(); - } - - [TestCleanup] - public void TestCleanup() - { - this.TestClean(); - } - - [TestMethod] - public void EditorParams_VerifySelectedMonitor() - { - 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 = 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(); - - Assert.IsFalse(Session.Find("Monitor 1").Selected); - Assert.IsTrue(Session.Find("Monitor 2").Selected); - } - - [TestMethod] - public void EditorParams_VerifyMonitorScaling() - { - 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, // 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(); - - var monitor = Session.Find("Monitor 1"); - var scaling = monitor.FindByAccessibilityId("ScalingText"); - Assert.AreEqual("200%", scaling.Text); - } - - [TestMethod] - public void EditorParams_VerifyMonitorResolution() - { - 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)); - this.RestartScopeExe(); - - var monitor = Session.Find("Monitor 1"); - var resolution = monitor.FindByAccessibilityId("ResolutionText"); - Assert.AreEqual("1920 × 1080", resolution.Text); - } - - [TestMethod] - public void EditorParams_SpanAcrossMonitors() - { - EditorParameters editorParameters = new EditorParameters(); - ParamsWrapper parameters = new ParamsWrapper - { - ProcessId = 1, - SpanZonesAcrossMonitors = true, - 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)); - this.RestartScopeExe(); - - var monitor = Session.Find("Monitor 1"); - Assert.IsNotNull(monitor); - Assert.IsTrue(monitor.Selected); - } - } -} diff --git a/src/modules/fancyzones/UITests-FancyZonesEditor/UIInitializeTest.cs b/src/modules/fancyzones/UITests-FancyZonesEditor/UIInitializeTest.cs new file mode 100644 index 000000000000..5fd38a63156e --- /dev/null +++ b/src/modules/fancyzones/UITests-FancyZonesEditor/UIInitializeTest.cs @@ -0,0 +1,768 @@ +// 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.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 UITests_FancyZonesEditor +{ + [TestClass] + public class UIInitializeTest : UITestBase + { + public UIInitializeTest() + : base(PowerToysModule.FancyZone) + { + } + + [TestInitialize] + public void TestInitialize() + { + FancyZonesEditorHelper.Files.Restore(); + } + + [TestCleanup] + public void TestCleanup() + { + this.TestClean(); + } + + [TestMethod] + public void EditorParams_VerifySelectedMonitor() + { + 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 = 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(); + + Assert.IsFalse(Session.Find("Monitor 1").Selected); + Assert.IsTrue(Session.Find("Monitor 2").Selected); + } + + [TestMethod] + public void EditorParams_VerifyMonitorScaling() + { + 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, // 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(); + + var monitor = Session.Find("Monitor 1"); + var scaling = monitor.FindByAccessibilityId("ScalingText"); + Assert.AreEqual("200%", scaling.Text); + } + + [TestMethod] + public void EditorParams_VerifyMonitorResolution() + { + 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)); + this.RestartScopeExe(); + + var monitor = Session.Find("Monitor 1"); + var resolution = monitor.FindByAccessibilityId("ResolutionText"); + Assert.AreEqual("1920 × 1080", resolution.Text); + } + + [TestMethod] + public void EditorParams_SpanAcrossMonitors() + { + EditorParameters editorParameters = new EditorParameters(); + ParamsWrapper parameters = new ParamsWrapper + { + ProcessId = 1, + SpanZonesAcrossMonitors = true, + 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)); + this.RestartScopeExe(); + + var monitor = Session.Find("Monitor 1"); + Assert.IsNotNull(monitor); + Assert.IsTrue(monitor.Selected); + } + + [TestMethod] + public void AppliedLayouts_LayoutsApplied() + { + 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 = 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, + }, + }, + }; + FancyZonesEditorSession.Files.ParamsIOHelper.WriteData(editorParameters.Serialize(parameters)); + + CustomLayouts customLayouts = new CustomLayouts(); + CustomLayouts.CustomLayoutListWrapper customLayoutListWrapper = new CustomLayouts.CustomLayoutListWrapper + { + CustomLayouts = new List + { + new CustomLayouts.CustomLayoutWrapper + { + Uuid = "{0D6D2F58-9184-4804-81E4-4E4CC3476DC1}", + Type = CustomLayout.Canvas.TypeToString(), + Name = "Layout 0", + Info = new CustomLayouts().ToJsonElement(new CustomLayouts.CanvasInfoWrapper + { + RefHeight = 1080, + RefWidth = 1920, + SensitivityRadius = 10, + Zones = new List { }, + }), + }, + }, + }; + FancyZonesEditorSession.Files.CustomLayoutsIOHelper.WriteData(customLayouts.Serialize(customLayoutListWrapper)); + + AppliedLayouts appliedLayouts = new AppliedLayouts(); + AppliedLayouts.AppliedLayoutsListWrapper appliedLayoutsWrapper = new AppliedLayouts.AppliedLayoutsListWrapper + { + AppliedLayouts = new List + { + 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(), + }, + }, + }, + }; + FancyZonesEditorSession.Files.AppliedLayoutsIOHelper.WriteData(appliedLayouts.Serialize(appliedLayoutsWrapper)); + this.RestartScopeExe(); + + // check layout on monitor 1 + var layoutOnMonitor1 = Session.Find(TestConstants.TemplateLayoutNames[LayoutType.Columns]); + Assert.IsNotNull(layoutOnMonitor1); + Assert.IsTrue(layoutOnMonitor1.Selected); + + // check layout on monitor 2 + Session.FindByAccessibilityId("Monitors").Find("Monitor 2").Click(); + var layoutOnMonitor2 = Session.Find(customLayoutListWrapper.CustomLayouts[0].Name); + Assert.IsNotNull(layoutOnMonitor2); + Assert.IsTrue(layoutOnMonitor2.Selected); + } + + [TestMethod] + public void AppliedLayouts_CustomLayoutsApplied_LayoutIdNotFound() + { + 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 = 96, + LeftCoordinate = 0, + TopCoordinate = 0, + WorkAreaHeight = 1040, + WorkAreaWidth = 1920, + MonitorHeight = 1080, + MonitorWidth = 1920, + IsSelected = true, + }, + }, + }; + FancyZonesEditorSession.Files.ParamsIOHelper.WriteData(editorParameters.Serialize(parameters)); + + CustomLayouts customLayouts = new CustomLayouts(); + CustomLayouts.CustomLayoutListWrapper customLayoutListWrapper = new CustomLayouts.CustomLayoutListWrapper + { + CustomLayouts = new List + { + new CustomLayouts.CustomLayoutWrapper + { + Uuid = "{0D6D2F58-9184-4804-81E4-4E4CC3476DC1}", + Type = CustomLayout.Canvas.TypeToString(), + Name = "Layout 0", + Info = new CustomLayouts().ToJsonElement(new CustomLayouts.CanvasInfoWrapper + { + RefHeight = 1080, + RefWidth = 1920, + SensitivityRadius = 10, + Zones = new List { }, + }), + }, + }, + }; + FancyZonesEditorSession.Files.CustomLayoutsIOHelper.WriteData(customLayouts.Serialize(customLayoutListWrapper)); + + AppliedLayouts appliedLayouts = new AppliedLayouts(); + AppliedLayouts.AppliedLayoutsListWrapper appliedLayoutsWrapper = new AppliedLayouts.AppliedLayoutsListWrapper + { + AppliedLayouts = new List + { + 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(), + }, + }, + }, + }; + FancyZonesEditorSession.Files.AppliedLayoutsIOHelper.WriteData(appliedLayouts.Serialize(appliedLayoutsWrapper)); + + this.RestartScopeExe(); + + var emptyLayout = Session.Find(TestConstants.TemplateLayoutNames[LayoutType.Blank]); + Assert.IsNotNull(emptyLayout); + Assert.IsTrue(emptyLayout.Selected); + } + + [TestMethod] + public void AppliedLayouts_NoLayoutsApplied_CustomDefaultLayout() + { + 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 = 96, + LeftCoordinate = 0, + TopCoordinate = 0, + WorkAreaHeight = 1040, + WorkAreaWidth = 1920, + MonitorHeight = 1080, + MonitorWidth = 1920, + IsSelected = true, + }, + }, + }; + FancyZonesEditorSession.Files.ParamsIOHelper.WriteData(editorParameters.Serialize(parameters)); + + CustomLayouts customLayouts = new CustomLayouts(); + CustomLayouts.CustomLayoutListWrapper customLayoutListWrapper = new CustomLayouts.CustomLayoutListWrapper + { + CustomLayouts = new List + { + new CustomLayouts.CustomLayoutWrapper + { + Uuid = "{0D6D2F58-9184-4804-81E4-4E4CC3476DC1}", + Type = CustomLayout.Canvas.TypeToString(), + Name = "Layout 0", + Info = new CustomLayouts().ToJsonElement(new CustomLayouts.CanvasInfoWrapper + { + RefHeight = 1080, + RefWidth = 1920, + SensitivityRadius = 10, + Zones = new List { }, + }), + }, + }, + }; + FancyZonesEditorSession.Files.CustomLayoutsIOHelper.WriteData(customLayouts.Serialize(customLayoutListWrapper)); + + FancyZonesEditorSession.Files.DefaultLayoutsIOHelper.RestoreData(); + DefaultLayouts defaultLayouts = new DefaultLayouts(); + DefaultLayouts.DefaultLayoutsListWrapper defaultLayoutsListWrapper = new DefaultLayouts.DefaultLayoutsListWrapper + { + DefaultLayouts = new List + { + new DefaultLayouts.DefaultLayoutWrapper + { + MonitorConfiguration = MonitorConfigurationType.Horizontal.TypeToString(), + Layout = new DefaultLayouts.DefaultLayoutWrapper.LayoutWrapper + { + Type = LayoutType.Custom.TypeToString(), + Uuid = customLayoutListWrapper.CustomLayouts[0].Uuid, + }, + }, + }, + }; + FancyZonesEditorSession.Files.DefaultLayoutsIOHelper.WriteData(defaultLayouts.Serialize(defaultLayoutsListWrapper)); + + this.RestartScopeExe(); + + var defaultLayout = Session.Find(customLayoutListWrapper.CustomLayouts[0].Name); + Assert.IsNotNull(defaultLayout); + Assert.IsTrue(defaultLayout.Selected); + } + + [TestMethod] + public void AppliedLayouts_NoLayoutsApplied_TemplateDefaultLayout() + { + 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 = 96, + LeftCoordinate = 0, + TopCoordinate = 0, + WorkAreaHeight = 1040, + WorkAreaWidth = 1920, + MonitorHeight = 1080, + MonitorWidth = 1920, + IsSelected = true, + }, + }, + }; + FancyZonesEditorSession.Files.ParamsIOHelper.WriteData(editorParameters.Serialize(parameters)); + + FancyZonesEditorSession.Files.DefaultLayoutsIOHelper.RestoreData(); + DefaultLayouts defaultLayouts = new DefaultLayouts(); + DefaultLayouts.DefaultLayoutsListWrapper defaultLayoutsListWrapper = new DefaultLayouts.DefaultLayoutsListWrapper + { + DefaultLayouts = new List + { + new DefaultLayouts.DefaultLayoutWrapper + { + MonitorConfiguration = MonitorConfigurationType.Horizontal.TypeToString(), + Layout = new DefaultLayouts.DefaultLayoutWrapper.LayoutWrapper + { + Type = LayoutType.Grid.TypeToString(), + ZoneCount = 6, + ShowSpacing = true, + Spacing = 5, + SensitivityRadius = 20, + }, + }, + }, + }; + FancyZonesEditorSession.Files.DefaultLayoutsIOHelper.WriteData(defaultLayouts.Serialize(defaultLayoutsListWrapper)); + + this.RestartScopeExe(); + + var defaultLayout = Session.Find(TestConstants.TemplateLayoutNames[LayoutType.Grid]); + Assert.IsNotNull(defaultLayout); + Assert.IsTrue(defaultLayout.Selected); + + // check the number of zones and spacing + Session.Find