2024-03-22 13:10:10 +01:00
|
|
|
|
// 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;
|
2025-03-14 17:04:23 +08:00
|
|
|
|
using FancyZonesEditor.Models;
|
2024-03-22 13:10:10 +01:00
|
|
|
|
using FancyZonesEditorCommon.Data;
|
|
|
|
|
|
using Microsoft.FancyZonesEditor.UITests;
|
|
|
|
|
|
using Microsoft.FancyZonesEditor.UnitTests.Utils;
|
2025-03-14 17:04:23 +08:00
|
|
|
|
using Microsoft.PowerToys.UITest;
|
2024-03-22 13:10:10 +01:00
|
|
|
|
using Microsoft.VisualStudio.TestTools.UnitTesting;
|
2025-03-14 17:04:23 +08:00
|
|
|
|
using OpenQA.Selenium.Appium.Windows;
|
|
|
|
|
|
using static Microsoft.FancyZonesEditor.UnitTests.Utils.FancyZonesEditorHelper;
|
2024-03-22 13:10:10 +01:00
|
|
|
|
|
2025-03-14 17:04:23 +08:00
|
|
|
|
namespace Microsoft.FancyZonesEditor.UITests
|
2024-03-22 13:10:10 +01:00
|
|
|
|
{
|
|
|
|
|
|
[TestClass]
|
2025-03-14 17:04:23 +08:00
|
|
|
|
public class RunFancyZonesEditorTest : UITestBase
|
2024-03-22 13:10:10 +01:00
|
|
|
|
{
|
2025-03-14 17:04:23 +08:00
|
|
|
|
public RunFancyZonesEditorTest()
|
2025-06-17 17:56:48 +08:00
|
|
|
|
: base(PowerToysModule.FancyZone, WindowSize.UnSpecified)
|
2025-03-14 17:04:23 +08:00
|
|
|
|
{
|
|
|
|
|
|
}
|
2024-03-22 13:10:10 +01:00
|
|
|
|
|
2025-06-17 17:56:48 +08:00
|
|
|
|
[TestInitialize]
|
|
|
|
|
|
public void TestInitialize()
|
2024-03-22 13:10:10 +01:00
|
|
|
|
{
|
2025-03-14 17:04:23 +08:00
|
|
|
|
FancyZonesEditorHelper.Files.Restore();
|
2024-03-22 13:10:10 +01:00
|
|
|
|
|
2025-03-14 17:04:23 +08:00
|
|
|
|
// prepare test editor parameters with 2 monitors before launching the editor
|
2024-03-22 13:10:10 +01:00
|
|
|
|
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,
|
|
|
|
|
|
},
|
2025-03-14 17:04:23 +08:00
|
|
|
|
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,
|
|
|
|
|
|
},
|
2024-03-22 13:10:10 +01:00
|
|
|
|
},
|
|
|
|
|
|
};
|
2025-03-14 17:04:23 +08:00
|
|
|
|
FancyZonesEditorHelper.Files.ParamsIOHelper.WriteData(editorParameters.Serialize(parameters));
|
2024-03-22 13:10:10 +01:00
|
|
|
|
|
|
|
|
|
|
LayoutTemplates layoutTemplates = new LayoutTemplates();
|
|
|
|
|
|
LayoutTemplates.TemplateLayoutsListWrapper templateLayoutsListWrapper = new LayoutTemplates.TemplateLayoutsListWrapper
|
|
|
|
|
|
{
|
|
|
|
|
|
LayoutTemplates = new List<LayoutTemplates.TemplateLayoutWrapper>
|
|
|
|
|
|
{
|
|
|
|
|
|
new LayoutTemplates.TemplateLayoutWrapper
|
|
|
|
|
|
{
|
2025-03-14 17:04:23 +08:00
|
|
|
|
Type = LayoutType.Blank.TypeToString(),
|
2024-03-22 13:10:10 +01:00
|
|
|
|
},
|
|
|
|
|
|
new LayoutTemplates.TemplateLayoutWrapper
|
|
|
|
|
|
{
|
2025-03-14 17:04:23 +08:00
|
|
|
|
Type = LayoutType.Focus.TypeToString(),
|
2024-03-22 13:10:10 +01:00
|
|
|
|
ZoneCount = 10,
|
|
|
|
|
|
},
|
|
|
|
|
|
new LayoutTemplates.TemplateLayoutWrapper
|
|
|
|
|
|
{
|
2025-03-14 17:04:23 +08:00
|
|
|
|
Type = LayoutType.Rows.TypeToString(),
|
2024-03-22 13:10:10 +01:00
|
|
|
|
ZoneCount = 2,
|
|
|
|
|
|
ShowSpacing = true,
|
|
|
|
|
|
Spacing = 10,
|
|
|
|
|
|
SensitivityRadius = 10,
|
|
|
|
|
|
},
|
|
|
|
|
|
new LayoutTemplates.TemplateLayoutWrapper
|
|
|
|
|
|
{
|
2025-03-14 17:04:23 +08:00
|
|
|
|
Type = LayoutType.Columns.TypeToString(),
|
2024-03-22 13:10:10 +01:00
|
|
|
|
ZoneCount = 2,
|
|
|
|
|
|
ShowSpacing = true,
|
|
|
|
|
|
Spacing = 20,
|
|
|
|
|
|
SensitivityRadius = 20,
|
|
|
|
|
|
},
|
|
|
|
|
|
new LayoutTemplates.TemplateLayoutWrapper
|
|
|
|
|
|
{
|
2025-03-14 17:04:23 +08:00
|
|
|
|
Type = LayoutType.Grid.TypeToString(),
|
2024-03-22 13:10:10 +01:00
|
|
|
|
ZoneCount = 4,
|
|
|
|
|
|
ShowSpacing = false,
|
|
|
|
|
|
Spacing = 10,
|
|
|
|
|
|
SensitivityRadius = 30,
|
|
|
|
|
|
},
|
|
|
|
|
|
new LayoutTemplates.TemplateLayoutWrapper
|
|
|
|
|
|
{
|
2025-03-14 17:04:23 +08:00
|
|
|
|
Type = LayoutType.PriorityGrid.TypeToString(),
|
2024-03-22 13:10:10 +01:00
|
|
|
|
ZoneCount = 3,
|
|
|
|
|
|
ShowSpacing = true,
|
|
|
|
|
|
Spacing = 1,
|
|
|
|
|
|
SensitivityRadius = 40,
|
|
|
|
|
|
},
|
|
|
|
|
|
},
|
|
|
|
|
|
};
|
2025-03-14 17:04:23 +08:00
|
|
|
|
FancyZonesEditorHelper.Files.LayoutTemplatesIOHelper.WriteData(layoutTemplates.Serialize(templateLayoutsListWrapper));
|
2024-03-22 13:10:10 +01:00
|
|
|
|
|
|
|
|
|
|
CustomLayouts customLayouts = new CustomLayouts();
|
|
|
|
|
|
CustomLayouts.CustomLayoutListWrapper customLayoutListWrapper = new CustomLayouts.CustomLayoutListWrapper
|
|
|
|
|
|
{
|
2025-03-14 17:04:23 +08:00
|
|
|
|
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> { },
|
|
|
|
|
|
}),
|
|
|
|
|
|
},
|
|
|
|
|
|
},
|
2024-03-22 13:10:10 +01:00
|
|
|
|
};
|
2025-03-14 17:04:23 +08:00
|
|
|
|
FancyZonesEditorHelper.Files.CustomLayoutsIOHelper.WriteData(customLayouts.Serialize(customLayoutListWrapper));
|
2024-03-22 13:10:10 +01:00
|
|
|
|
|
|
|
|
|
|
DefaultLayouts defaultLayouts = new DefaultLayouts();
|
|
|
|
|
|
DefaultLayouts.DefaultLayoutsListWrapper defaultLayoutsListWrapper = new DefaultLayouts.DefaultLayoutsListWrapper
|
|
|
|
|
|
{
|
|
|
|
|
|
DefaultLayouts = new List<DefaultLayouts.DefaultLayoutWrapper> { },
|
|
|
|
|
|
};
|
2025-03-14 17:04:23 +08:00
|
|
|
|
FancyZonesEditorHelper.Files.DefaultLayoutsIOHelper.WriteData(defaultLayouts.Serialize(defaultLayoutsListWrapper));
|
2024-03-22 13:10:10 +01:00
|
|
|
|
|
|
|
|
|
|
LayoutHotkeys layoutHotkeys = new LayoutHotkeys();
|
|
|
|
|
|
LayoutHotkeys.LayoutHotkeysWrapper layoutHotkeysWrapper = new LayoutHotkeys.LayoutHotkeysWrapper
|
|
|
|
|
|
{
|
|
|
|
|
|
LayoutHotkeys = new List<LayoutHotkeys.LayoutHotkeyWrapper> { },
|
|
|
|
|
|
};
|
2025-03-14 17:04:23 +08:00
|
|
|
|
FancyZonesEditorHelper.Files.LayoutHotkeysIOHelper.WriteData(layoutHotkeys.Serialize(layoutHotkeysWrapper));
|
2024-03-22 13:10:10 +01:00
|
|
|
|
|
|
|
|
|
|
AppliedLayouts appliedLayouts = new AppliedLayouts();
|
|
|
|
|
|
AppliedLayouts.AppliedLayoutsListWrapper appliedLayoutsWrapper = new AppliedLayouts.AppliedLayoutsListWrapper
|
|
|
|
|
|
{
|
|
|
|
|
|
AppliedLayouts = new List<AppliedLayouts.AppliedLayoutWrapper> { },
|
|
|
|
|
|
};
|
2025-03-14 17:04:23 +08:00
|
|
|
|
FancyZonesEditorHelper.Files.AppliedLayoutsIOHelper.WriteData(appliedLayouts.Serialize(appliedLayoutsWrapper));
|
2024-03-22 13:10:10 +01:00
|
|
|
|
|
2025-06-17 17:56:48 +08:00
|
|
|
|
this.RestartScopeExe();
|
2024-03-22 13:10:10 +01:00
|
|
|
|
}
|
|
|
|
|
|
|
2025-03-14 17:04:23 +08:00
|
|
|
|
[TestMethod]
|
|
|
|
|
|
public void OpenNewLayoutDialog() // verify the new layout dialog is opened
|
2024-03-22 13:10:10 +01:00
|
|
|
|
{
|
2025-03-14 17:04:23 +08:00
|
|
|
|
Session.Find<Button>(By.AccessibilityId(AccessibilityId.NewLayoutButton)).Click();
|
|
|
|
|
|
Assert.IsNotNull(Session.Find<Element>("Choose layout type")); // check the pane header
|
2024-03-22 13:10:10 +01:00
|
|
|
|
}
|
|
|
|
|
|
|
2025-03-14 17:04:23 +08:00
|
|
|
|
[TestMethod]
|
|
|
|
|
|
public void OpenEditLayoutDialog() // verify the edit layout dialog is opened
|
2024-03-22 13:10:10 +01:00
|
|
|
|
{
|
2025-03-14 17:04:23 +08:00
|
|
|
|
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
|
2024-03-22 13:10:10 +01:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
[TestMethod]
|
2025-03-14 17:04:23 +08:00
|
|
|
|
public void OpenEditLayoutDialog_ByContextMenu_TemplateLayout() // verify the edit layout dialog is opened
|
2024-03-22 13:10:10 +01:00
|
|
|
|
{
|
2025-03-14 17:04:23 +08:00
|
|
|
|
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
|
2024-03-22 13:10:10 +01:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
[TestMethod]
|
2025-03-14 17:04:23 +08:00
|
|
|
|
public void OpenEditLayoutDialog_ByContextMenu_CustomLayout() // verify the edit layout dialog is opened
|
2024-03-22 13:10:10 +01:00
|
|
|
|
{
|
2025-03-14 17:04:23 +08:00
|
|
|
|
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
|
2024-03-22 13:10:10 +01:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
[TestMethod]
|
2025-03-14 17:04:23 +08:00
|
|
|
|
public void OpenContextMenu() // verify the context menu is opened
|
2024-03-22 13:10:10 +01:00
|
|
|
|
{
|
2025-03-14 17:04:23 +08:00
|
|
|
|
Session.Find<Button>(TestConstants.TemplateLayoutNames[LayoutType.Columns]).Click(true);
|
|
|
|
|
|
Assert.IsNotNull(Session.Find<Element>(By.ClassName(ClassName.ContextMenu)));
|
2024-03-22 13:10:10 +01:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
[TestMethod]
|
2025-03-14 17:04:23 +08:00
|
|
|
|
public void ClickMonitor()
|
2024-03-22 13:10:10 +01:00
|
|
|
|
{
|
2025-03-14 17:04:23 +08:00
|
|
|
|
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);
|
2024-03-22 13:10:10 +01:00
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|