diff --git a/src/modules/fancyzones/UITests-FancyZonesEditor/CustomLayoutsTests.cs b/src/modules/fancyzones/UITests-FancyZonesEditor/CustomLayoutsTests.cs new file mode 100644 index 000000000000..1726afd0dc7f --- /dev/null +++ b/src/modules/fancyzones/UITests-FancyZonesEditor/CustomLayoutsTests.cs @@ -0,0 +1,458 @@ +// 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; +using static Microsoft.FancyZonesEditor.UnitTests.Utils.FancyZonesEditorSession; + +namespace Microsoft.FancyZonesEditor.UITests +{ + [TestClass] + public class CustomLayoutsTests : UITestBase + { + public CustomLayoutsTests() + : base(PowerToysModule.FancyZone) + { + } + + private static readonly CustomLayoutListWrapper Layouts = new 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 = 3, + RowsPercentage = new List { 2967, 7033 }, + ColumnsPercentage = new List { 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 + { + 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 { 2967, 7033 }, + ColumnsPercentage = new List { 2410, 6040, 1550 }, + CellChildMap = new int[][] { [0, 1, 1], [0, 2, 3] }, + SensitivityRadius = 30, + Spacing = 10, + ShowSpacing = true, + }), + }, + }, + }; + + [TestInitialize] + public void TestInitialize() + { + CustomLayouts customLayouts = new CustomLayouts(); + FancyZonesEditorSession.Files.CustomLayoutsIOHelper.WriteData(customLayouts.Serialize(Layouts)); + + 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, + }, + }, + }; + FancyZonesEditorSession.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, + }, + }, + }; + FancyZonesEditorSession.Files.LayoutTemplatesIOHelper.WriteData(layoutTemplates.Serialize(templateLayoutsListWrapper)); + + DefaultLayouts defaultLayouts = new DefaultLayouts(); + DefaultLayouts.DefaultLayoutsListWrapper defaultLayoutsListWrapper = new DefaultLayouts.DefaultLayoutsListWrapper + { + DefaultLayouts = new List { }, + }; + FancyZonesEditorSession.Files.DefaultLayoutsIOHelper.WriteData(defaultLayouts.Serialize(defaultLayoutsListWrapper)); + + LayoutHotkeys layoutHotkeys = new LayoutHotkeys(); + LayoutHotkeys.LayoutHotkeysWrapper layoutHotkeysWrapper = new LayoutHotkeys.LayoutHotkeysWrapper + { + LayoutHotkeys = new List { }, + }; + FancyZonesEditorSession.Files.LayoutHotkeysIOHelper.WriteData(layoutHotkeys.Serialize(layoutHotkeysWrapper)); + + AppliedLayouts appliedLayouts = new AppliedLayouts(); + AppliedLayouts.AppliedLayoutsListWrapper appliedLayoutsWrapper = new AppliedLayouts.AppliedLayoutsListWrapper + { + AppliedLayouts = new List { }, + }; + FancyZonesEditorSession.Files.AppliedLayoutsIOHelper.WriteData(appliedLayouts.Serialize(appliedLayoutsWrapper)); + + this.RestartScopeExe(); + } + + [TestCleanup] + public void TestCleanup() + { + FancyZonesEditorSession.Files.Restore(); + } + + [TestMethod] + public void Name_Initialize() + { + // verify all custom layouts are presented + foreach (var layout in Layouts.CustomLayouts) + { + Assert.IsNotNull(Session.Find(layout.Name)); + } + } + + [TestMethod] + public void Rename_Save() + { + string newName = "New layout name"; + var oldName = Layouts.CustomLayouts[0].Name; + + // rename the layout + Session.Find(oldName).Find