mirror of
https://github.com/microsoft/PowerToys.git
synced 2026-04-04 18:26:39 +02:00
Dev/zhaopengwang/test/37733 UI test fancyzones editor (#37769)
* first launch test * add FancyZonesEditorHelper * click monitor test and add FindByAccessibilityId function * add ui initialization tests and add exit scope exe function * add cleanup test function and change file init * add TemplateLayoutsTest and add LayoutTypeEnumExtension.cs and Element class add sendkey function * add UI Initialize Test * add OpenEditLayoutDialog test case and add By type * add LayoutHotkeysTest * add EditLayoutTests and add element drag function * add DeleteLayouTest and change cleanup to base class and change FindByAccessibilityId to By.AccessibilityId * add DefaultLayoutsTest * add CustomLayoutsTest * add CreateLayoutTest * add CopyLayoutTest * add ApplyLayoutTest * add some cleanup code * fix spelling error * fix DeleteLayoutWithHotkey test code bug * change code * fix restart exe some bug * move first lunch text code to new file * test write file error * fix test code init fancyzone file error * test maxsize button * get current window size * change layout count * change test case work windows size * change fancyzone editor window size * change fancyzone editor window size and change element move rule * change window size --------- Co-authored-by: Zhaopeng Wang <zhaopengwang@microsoft.com>
This commit is contained in:
@@ -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;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,308 @@
|
||||
// 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.UnitTests.Utils;
|
||||
using Microsoft.PowerToys.UITest;
|
||||
using Microsoft.VisualStudio.TestTools.UnitTesting;
|
||||
using ModernWpf.Controls;
|
||||
using OpenQA.Selenium;
|
||||
using static Microsoft.FancyZonesEditor.UnitTests.Utils.FancyZonesEditorHelper;
|
||||
|
||||
namespace Microsoft.FancyZonesEditor.UITests
|
||||
{
|
||||
[TestClass]
|
||||
public class ApplyLayoutTests : UITestBase
|
||||
{
|
||||
public ApplyLayoutTests()
|
||||
: base(PowerToysModule.FancyZone)
|
||||
{
|
||||
}
|
||||
|
||||
private static readonly 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,
|
||||
},
|
||||
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,
|
||||
},
|
||||
},
|
||||
};
|
||||
|
||||
private static readonly CustomLayouts.CustomLayoutListWrapper CustomLayoutsList = new CustomLayouts.CustomLayoutListWrapper
|
||||
{
|
||||
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> { },
|
||||
}),
|
||||
},
|
||||
},
|
||||
};
|
||||
|
||||
private static readonly LayoutTemplates.TemplateLayoutsListWrapper TemplateLayoutsList = new LayoutTemplates.TemplateLayoutsListWrapper
|
||||
{
|
||||
LayoutTemplates = new List<LayoutTemplates.TemplateLayoutWrapper>
|
||||
{
|
||||
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,
|
||||
},
|
||||
},
|
||||
};
|
||||
|
||||
[TestInitialize]
|
||||
public void TestInitialize()
|
||||
{
|
||||
EditorParameters editorParameters = new EditorParameters();
|
||||
FancyZonesEditorHelper.Files.ParamsIOHelper.WriteData(editorParameters.Serialize(Parameters));
|
||||
|
||||
LayoutTemplates layoutTemplates = new LayoutTemplates();
|
||||
FancyZonesEditorHelper.Files.LayoutTemplatesIOHelper.WriteData(layoutTemplates.Serialize(TemplateLayoutsList));
|
||||
|
||||
CustomLayouts customLayouts = new CustomLayouts();
|
||||
FancyZonesEditorHelper.Files.CustomLayoutsIOHelper.WriteData(customLayouts.Serialize(CustomLayoutsList));
|
||||
|
||||
DefaultLayouts defaultLayouts = new DefaultLayouts();
|
||||
DefaultLayouts.DefaultLayoutsListWrapper defaultLayoutsListWrapper = new DefaultLayouts.DefaultLayoutsListWrapper
|
||||
{
|
||||
DefaultLayouts = new List<DefaultLayouts.DefaultLayoutWrapper>
|
||||
{
|
||||
new DefaultLayouts.DefaultLayoutWrapper
|
||||
{
|
||||
MonitorConfiguration = MonitorConfigurationType.Horizontal.TypeToString(),
|
||||
Layout = new DefaultLayouts.DefaultLayoutWrapper.LayoutWrapper
|
||||
{
|
||||
Type = LayoutType.Focus.TypeToString(),
|
||||
ZoneCount = 4,
|
||||
ShowSpacing = true,
|
||||
Spacing = 5,
|
||||
SensitivityRadius = 20,
|
||||
},
|
||||
},
|
||||
new DefaultLayouts.DefaultLayoutWrapper
|
||||
{
|
||||
MonitorConfiguration = MonitorConfigurationType.Vertical.TypeToString(),
|
||||
Layout = new DefaultLayouts.DefaultLayoutWrapper.LayoutWrapper
|
||||
{
|
||||
Type = LayoutType.Custom.TypeToString(),
|
||||
Uuid = "{0D6D2F58-9184-4804-81E4-4E4CC3476DC1}",
|
||||
ZoneCount = 0,
|
||||
ShowSpacing = false,
|
||||
Spacing = 0,
|
||||
SensitivityRadius = 0,
|
||||
},
|
||||
},
|
||||
},
|
||||
};
|
||||
FancyZonesEditorHelper.Files.DefaultLayoutsIOHelper.WriteData(defaultLayouts.Serialize(defaultLayoutsListWrapper));
|
||||
|
||||
LayoutHotkeys layoutHotkeys = new LayoutHotkeys();
|
||||
LayoutHotkeys.LayoutHotkeysWrapper layoutHotkeysWrapper = new LayoutHotkeys.LayoutHotkeysWrapper
|
||||
{
|
||||
LayoutHotkeys = new List<LayoutHotkeys.LayoutHotkeyWrapper> { },
|
||||
};
|
||||
FancyZonesEditorHelper.Files.LayoutHotkeysIOHelper.WriteData(layoutHotkeys.Serialize(layoutHotkeysWrapper));
|
||||
|
||||
AppliedLayouts appliedLayouts = new AppliedLayouts();
|
||||
AppliedLayouts.AppliedLayoutsListWrapper appliedLayoutsWrapper = new AppliedLayouts.AppliedLayoutsListWrapper
|
||||
{
|
||||
AppliedLayouts = new List<AppliedLayouts.AppliedLayoutWrapper> { },
|
||||
};
|
||||
FancyZonesEditorHelper.Files.AppliedLayoutsIOHelper.WriteData(appliedLayouts.Serialize(appliedLayoutsWrapper));
|
||||
|
||||
this.RestartScopeExe();
|
||||
}
|
||||
|
||||
[TestCleanup]
|
||||
public void TestCleanup()
|
||||
{
|
||||
FancyZonesEditorHelper.Files.Restore();
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
public void ApplyCustomLayout()
|
||||
{
|
||||
var layout = CustomLayoutsList.CustomLayouts[0];
|
||||
Assert.IsFalse(Session.Find<Element>(layout.Name).Selected);
|
||||
Session.Find<Element>(layout.Name).Click();
|
||||
|
||||
Assert.IsTrue(Session.Find<Element>(layout.Name).Selected);
|
||||
|
||||
AppliedLayouts appliedLayouts = new AppliedLayouts();
|
||||
var data = appliedLayouts.Read(appliedLayouts.File);
|
||||
Assert.AreEqual(Parameters.Monitors.Count, data.AppliedLayouts.Count);
|
||||
Assert.AreEqual(layout.Uuid, data.AppliedLayouts[0].AppliedLayout.Uuid);
|
||||
Assert.AreEqual(Parameters.Monitors[0].MonitorNumber, data.AppliedLayouts[0].Device.MonitorNumber);
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
public void ApplyTemplateLayout()
|
||||
{
|
||||
var layoutType = LayoutType.Columns;
|
||||
var layout = TestConstants.TemplateLayoutNames[layoutType];
|
||||
Assert.IsFalse(Session.Find<Element>(layout).Selected);
|
||||
Session.Find<Element>(layout).Click();
|
||||
|
||||
Assert.IsTrue(Session.Find<Element>(layout).Selected);
|
||||
|
||||
AppliedLayouts appliedLayouts = new AppliedLayouts();
|
||||
var data = appliedLayouts.Read(appliedLayouts.File);
|
||||
Assert.AreEqual(Parameters.Monitors.Count, data.AppliedLayouts.Count);
|
||||
Assert.AreEqual(layoutType.TypeToString(), data.AppliedLayouts[0].AppliedLayout.Type);
|
||||
Assert.AreEqual(Parameters.Monitors[0].MonitorNumber, data.AppliedLayouts[0].Device.MonitorNumber);
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
public void ApplyLayoutsOnEachMonitor()
|
||||
{
|
||||
// apply the layout on the first monitor
|
||||
var firstLayoutType = LayoutType.Columns;
|
||||
var firstLayoutName = TestConstants.TemplateLayoutNames[firstLayoutType];
|
||||
Session.Find<Element>(firstLayoutName).Click();
|
||||
Assert.IsTrue(Session.Find<Element>(firstLayoutName)!.Selected);
|
||||
|
||||
// apply the layout on the second monitor
|
||||
Session.Find<Element>(PowerToys.UITest.By.AccessibilityId("Monitors")).Find<Element>("Monitor 2").Click();
|
||||
var secondLayout = CustomLayoutsList.CustomLayouts[0];
|
||||
Session.Find<Element>(secondLayout.Name).Click();
|
||||
Assert.IsTrue(Session.Find<Element>(secondLayout.Name)!.Selected);
|
||||
|
||||
// verify the layout on the first monitor wasn't changed
|
||||
Session.Find<Element>(PowerToys.UITest.By.AccessibilityId("Monitors")).Find<Element>("Monitor 1").Click();
|
||||
Assert.IsTrue(Session.Find<Element>(firstLayoutName)!.Selected);
|
||||
|
||||
// verify the file
|
||||
var appliedLayouts = new AppliedLayouts();
|
||||
var data = appliedLayouts.Read(appliedLayouts.File);
|
||||
Assert.AreEqual(Parameters.Monitors.Count, data.AppliedLayouts.Count);
|
||||
Assert.AreEqual(firstLayoutType.TypeToString(), data.AppliedLayouts.Find(x => x.Device.MonitorNumber == 1).AppliedLayout.Type);
|
||||
Assert.AreEqual(secondLayout.Uuid, data.AppliedLayouts.Find(x => x.Device.MonitorNumber == 2).AppliedLayout.Uuid);
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
public void ApplyTemplateWithDifferentParametersOnEachMonitor()
|
||||
{
|
||||
var layoutType = LayoutType.Columns;
|
||||
var layoutName = TestConstants.TemplateLayoutNames[layoutType];
|
||||
|
||||
// apply the layout on the first monitor, set parameters
|
||||
Session.Find<Element>(layoutName).Click();
|
||||
Session.Find<Element>(layoutName).Find<Button>(PowerToys.UITest.By.AccessibilityId(AccessibilityId.EditLayoutButton)).Click();
|
||||
var slider = Session.Find<Element>(PowerToys.UITest.By.AccessibilityId(AccessibilityId.TemplateZoneSlider));
|
||||
Assert.IsNotNull(slider);
|
||||
slider.SendKeys(Keys.Right);
|
||||
slider.SendKeys(Keys.Right);
|
||||
var expectedFirstLayoutZoneCount = int.Parse(slider.Text!, CultureInfo.InvariantCulture);
|
||||
Session.Find<Button>(ElementName.Save).Click();
|
||||
|
||||
// apply the layout on the second monitor, set different parameters
|
||||
Session.Find<Element>(PowerToys.UITest.By.AccessibilityId("Monitors")).Find<Element>("Monitor 2").Click();
|
||||
Session.Find<Element>(layoutName).Click();
|
||||
Session.Find<Element>(layoutName).Find<Button>(PowerToys.UITest.By.AccessibilityId(AccessibilityId.EditLayoutButton)).Click();
|
||||
slider = Session.Find<Element>(PowerToys.UITest.By.AccessibilityId(AccessibilityId.TemplateZoneSlider));
|
||||
Assert.IsNotNull(slider);
|
||||
slider.SendKeys(Keys.Left);
|
||||
var expectedSecondLayoutZoneCount = int.Parse(slider.Text!, CultureInfo.InvariantCulture);
|
||||
Session.Find<Button>(ElementName.Save).Click();
|
||||
|
||||
// verify the layout on the first monitor wasn't changed
|
||||
Session.Find<Element>(PowerToys.UITest.By.AccessibilityId("Monitors")).Find<Element>("Monitor 1").Click();
|
||||
Session.Find<Element>(layoutName).Find<Button>(PowerToys.UITest.By.AccessibilityId(AccessibilityId.EditLayoutButton)).Click();
|
||||
slider = Session.Find<Element>(PowerToys.UITest.By.AccessibilityId(AccessibilityId.TemplateZoneSlider));
|
||||
Assert.IsNotNull(slider);
|
||||
Assert.AreEqual(expectedFirstLayoutZoneCount, int.Parse(slider.Text!, CultureInfo.InvariantCulture));
|
||||
Session.Find<Button>(ElementName.Cancel).Click();
|
||||
|
||||
// check the file
|
||||
var appliedLayouts = new AppliedLayouts();
|
||||
var data = appliedLayouts.Read(appliedLayouts.File);
|
||||
Assert.AreEqual(Parameters.Monitors.Count, data.AppliedLayouts.Count);
|
||||
Assert.AreEqual(layoutType.TypeToString(), data.AppliedLayouts.Find(x => x.Device.MonitorNumber == 1).AppliedLayout.Type);
|
||||
Assert.AreEqual(expectedFirstLayoutZoneCount, data.AppliedLayouts.Find(x => x.Device.MonitorNumber == 1).AppliedLayout.ZoneCount);
|
||||
Assert.AreEqual(layoutType.TypeToString(), data.AppliedLayouts.Find(x => x.Device.MonitorNumber == 2).AppliedLayout.Type);
|
||||
Assert.AreEqual(expectedSecondLayoutZoneCount, data.AppliedLayouts.Find(x => x.Device.MonitorNumber == 2).AppliedLayout.ZoneCount);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,357 @@
|
||||
// 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 FancyZonesEditor.Models;
|
||||
using FancyZonesEditorCommon.Data;
|
||||
using Microsoft.FancyZonesEditor.UnitTests.Utils;
|
||||
using Microsoft.PowerToys.UITest;
|
||||
using Microsoft.VisualStudio.TestTools.UnitTesting;
|
||||
using static FancyZonesEditorCommon.Data.EditorParameters;
|
||||
using static Microsoft.FancyZonesEditor.UnitTests.Utils.FancyZonesEditorHelper;
|
||||
|
||||
namespace Microsoft.FancyZonesEditor.UITests
|
||||
{
|
||||
[TestClass]
|
||||
public class CopyLayoutTests : UITestBase
|
||||
{
|
||||
public CopyLayoutTests()
|
||||
: base(PowerToysModule.FancyZone)
|
||||
{
|
||||
}
|
||||
|
||||
private static readonly CustomLayouts.CustomLayoutListWrapper CustomLayouts = new CustomLayouts.CustomLayoutListWrapper
|
||||
{
|
||||
CustomLayouts = new List<CustomLayouts.CustomLayoutWrapper>
|
||||
{
|
||||
new CustomLayouts.CustomLayoutWrapper
|
||||
{
|
||||
Uuid = "{0D6D2F58-9184-4804-81E4-4E4CC3476DC1}",
|
||||
Type = CustomLayout.Grid.TypeToString(),
|
||||
Name = "Grid custom layout",
|
||||
Info = new CustomLayouts().ToJsonElement(new CustomLayouts.GridInfoWrapper
|
||||
{
|
||||
Rows = 2,
|
||||
Columns = 3,
|
||||
RowsPercentage = new List<int> { 2967, 7033 },
|
||||
ColumnsPercentage = new List<int> { 2410, 6040, 1550 },
|
||||
CellChildMap = new int[][] { [0, 1, 1], [0, 2, 3] },
|
||||
SensitivityRadius = 30,
|
||||
Spacing = 26,
|
||||
ShowSpacing = false,
|
||||
}),
|
||||
},
|
||||
},
|
||||
};
|
||||
|
||||
private static readonly LayoutHotkeys.LayoutHotkeysWrapper Hotkeys = new LayoutHotkeys.LayoutHotkeysWrapper
|
||||
{
|
||||
LayoutHotkeys = new List<LayoutHotkeys.LayoutHotkeyWrapper>
|
||||
{
|
||||
new LayoutHotkeys.LayoutHotkeyWrapper
|
||||
{
|
||||
LayoutId = CustomLayouts.CustomLayouts[0].Uuid,
|
||||
Key = 0,
|
||||
},
|
||||
},
|
||||
};
|
||||
|
||||
private static readonly DefaultLayouts.DefaultLayoutsListWrapper DefaultLayouts = new DefaultLayouts.DefaultLayoutsListWrapper
|
||||
{
|
||||
DefaultLayouts = new List<DefaultLayouts.DefaultLayoutWrapper>
|
||||
{
|
||||
new DefaultLayouts.DefaultLayoutWrapper
|
||||
{
|
||||
MonitorConfiguration = MonitorConfigurationType.Vertical.TypeToString(),
|
||||
Layout = new DefaultLayouts.DefaultLayoutWrapper.LayoutWrapper
|
||||
{
|
||||
Type = "custom",
|
||||
Uuid = CustomLayouts.CustomLayouts[0].Uuid,
|
||||
},
|
||||
},
|
||||
},
|
||||
};
|
||||
|
||||
[TestInitialize]
|
||||
public void TestInitialize()
|
||||
{
|
||||
EditorParameters editorParameters = new EditorParameters();
|
||||
ParamsWrapper parameters = new ParamsWrapper
|
||||
{
|
||||
ProcessId = 1,
|
||||
SpanZonesAcrossMonitors = false,
|
||||
Monitors = new List<NativeMonitorDataWrapper>
|
||||
{
|
||||
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));
|
||||
|
||||
CustomLayouts customLayouts = new CustomLayouts();
|
||||
FancyZonesEditorHelper.Files.CustomLayoutsIOHelper.WriteData(customLayouts.Serialize(CustomLayouts));
|
||||
|
||||
LayoutTemplates layoutTemplates = new LayoutTemplates();
|
||||
LayoutTemplates.TemplateLayoutsListWrapper templateLayoutsListWrapper = new LayoutTemplates.TemplateLayoutsListWrapper
|
||||
{
|
||||
LayoutTemplates = new List<LayoutTemplates.TemplateLayoutWrapper>
|
||||
{
|
||||
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));
|
||||
|
||||
DefaultLayouts defaultLayouts = new DefaultLayouts();
|
||||
FancyZonesEditorHelper.Files.DefaultLayoutsIOHelper.WriteData(defaultLayouts.Serialize(DefaultLayouts));
|
||||
|
||||
LayoutHotkeys layoutHotkeys = new LayoutHotkeys();
|
||||
FancyZonesEditorHelper.Files.LayoutHotkeysIOHelper.WriteData(layoutHotkeys.Serialize(Hotkeys));
|
||||
|
||||
AppliedLayouts appliedLayouts = new AppliedLayouts();
|
||||
AppliedLayouts.AppliedLayoutsListWrapper appliedLayoutsWrapper = new AppliedLayouts.AppliedLayoutsListWrapper
|
||||
{
|
||||
AppliedLayouts = new List<AppliedLayouts.AppliedLayoutWrapper> { },
|
||||
};
|
||||
FancyZonesEditorHelper.Files.AppliedLayoutsIOHelper.WriteData(appliedLayouts.Serialize(appliedLayoutsWrapper));
|
||||
|
||||
this.RestartScopeExe();
|
||||
}
|
||||
|
||||
[TestCleanup]
|
||||
public void TestCleanup()
|
||||
{
|
||||
FancyZonesEditorHelper.Files.Restore();
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
public void CopyTemplate_FromEditLayoutWindow()
|
||||
{
|
||||
string copiedLayoutName = TestConstants.TemplateLayoutNames[LayoutType.Focus] + " (1)";
|
||||
Session.Find<Element>(TestConstants.TemplateLayoutNames[LayoutType.Focus]).Find<Button>(By.AccessibilityId(AccessibilityId.EditLayoutButton)).Click();
|
||||
ClickCopyLayout();
|
||||
|
||||
// verify the layout is copied
|
||||
Assert.IsNotNull(Session.Find<Element>(copiedLayoutName)); // new name is presented
|
||||
|
||||
// verify the file
|
||||
var customLayouts = new CustomLayouts();
|
||||
var data = customLayouts.Read(customLayouts.File);
|
||||
Assert.AreEqual(CustomLayouts.CustomLayouts.Count + 1, data.CustomLayouts.Count);
|
||||
Assert.IsTrue(data.CustomLayouts.Exists(x => x.Name == copiedLayoutName));
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
public void CopyTemplate_FromContextMenu()
|
||||
{
|
||||
string copiedLayoutName = TestConstants.TemplateLayoutNames[LayoutType.Rows] + " (1)";
|
||||
FancyZonesEditorHelper.ClickContextMenuItem(Session, TestConstants.TemplateLayoutNames[LayoutType.Rows], ElementName.CreateCustomLayout);
|
||||
|
||||
// verify the layout is copied
|
||||
Assert.IsNotNull(Session.Find<Element>(copiedLayoutName)); // new name is presented
|
||||
|
||||
// verify the file
|
||||
var customLayouts = new CustomLayouts();
|
||||
var data = customLayouts.Read(customLayouts.File);
|
||||
Assert.AreEqual(CustomLayouts.CustomLayouts.Count + 1, data.CustomLayouts.Count);
|
||||
Assert.IsTrue(data.CustomLayouts.Exists(x => x.Name == copiedLayoutName));
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
public void CopyTemplate_DefaultLayout()
|
||||
{
|
||||
string copiedLayoutName = TestConstants.TemplateLayoutNames[LayoutType.PriorityGrid] + " (1)";
|
||||
Session.Find<Element>(TestConstants.TemplateLayoutNames[LayoutType.PriorityGrid]).Find<Button>(By.AccessibilityId(AccessibilityId.EditLayoutButton)).Click();
|
||||
ClickCopyLayout();
|
||||
|
||||
// verify the layout is copied
|
||||
Assert.IsNotNull(Session.Find<Element>(copiedLayoutName)); // new name is presented
|
||||
|
||||
// verify the file
|
||||
var customLayouts = new CustomLayouts();
|
||||
var data = customLayouts.Read(customLayouts.File);
|
||||
Assert.AreEqual(CustomLayouts.CustomLayouts.Count + 1, data.CustomLayouts.Count);
|
||||
|
||||
// verify the default layout wasn't changed
|
||||
Session.Find<Element>(TestConstants.TemplateLayoutNames[LayoutType.PriorityGrid]).Find<Button>(By.AccessibilityId(AccessibilityId.EditLayoutButton)).Click();
|
||||
var horizontalDefaultButton = Session.Find<Button>(By.AccessibilityId(AccessibilityId.HorizontalDefaultButtonChecked));
|
||||
Assert.IsNotNull(horizontalDefaultButton);
|
||||
Session.Find<Button>(ElementName.Cancel).Click();
|
||||
|
||||
Session.Find<Element>(copiedLayoutName).Find<Button>(By.AccessibilityId(AccessibilityId.EditLayoutButton)).Click();
|
||||
horizontalDefaultButton = Session.Find<Button>(By.AccessibilityId(AccessibilityId.HorizontalDefaultButtonUnchecked));
|
||||
Assert.IsNotNull(horizontalDefaultButton);
|
||||
Session.Find<Button>(ElementName.Cancel).Click();
|
||||
|
||||
// verify the default layouts file wasn't changed
|
||||
var defaultLayouts = new DefaultLayouts();
|
||||
var defaultLayoutData = defaultLayouts.Read(defaultLayouts.File);
|
||||
Assert.AreEqual(defaultLayouts.Serialize(DefaultLayouts), defaultLayouts.Serialize(defaultLayoutData));
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
public void CopyCustomLayout_FromEditLayoutWindow()
|
||||
{
|
||||
string copiedLayoutName = CustomLayouts.CustomLayouts[0].Name + " (1)";
|
||||
Session.Find<Element>(CustomLayouts.CustomLayouts[0].Name).Find<Button>(By.AccessibilityId(AccessibilityId.EditLayoutButton)).Click();
|
||||
ClickCopyLayout();
|
||||
|
||||
// verify the layout is copied
|
||||
Assert.IsNotNull(Session.Find<Element>(copiedLayoutName)); // new name is presented
|
||||
|
||||
// verify the file
|
||||
var customLayouts = new CustomLayouts();
|
||||
var data = customLayouts.Read(customLayouts.File);
|
||||
Assert.AreEqual(CustomLayouts.CustomLayouts.Count + 1, data.CustomLayouts.Count);
|
||||
Assert.IsTrue(data.CustomLayouts.Exists(x => x.Name == copiedLayoutName));
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
public void CopyCustomLayout_FromContextMenu()
|
||||
{
|
||||
string copiedLayoutName = CustomLayouts.CustomLayouts[0].Name + " (1)";
|
||||
FancyZonesEditorHelper.ClickContextMenuItem(Session, CustomLayouts.CustomLayouts[0].Name, ElementName.Duplicate);
|
||||
|
||||
// verify the layout is copied
|
||||
Assert.IsNotNull(Session.Find<Element>(copiedLayoutName)); // new name is presented
|
||||
|
||||
// verify the file
|
||||
var customLayouts = new CustomLayouts();
|
||||
var data = customLayouts.Read(customLayouts.File);
|
||||
Assert.AreEqual(CustomLayouts.CustomLayouts.Count + 1, data.CustomLayouts.Count);
|
||||
Assert.IsTrue(data.CustomLayouts.Exists(x => x.Name == copiedLayoutName));
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
public void CopyCustomLayout_DefaultLayout()
|
||||
{
|
||||
string copiedLayoutName = CustomLayouts.CustomLayouts[0].Name + " (1)";
|
||||
Session.Find<Element>(CustomLayouts.CustomLayouts[0].Name).Find<Button>(By.AccessibilityId(AccessibilityId.EditLayoutButton)).Click();
|
||||
ClickCopyLayout();
|
||||
|
||||
// verify the layout is copied
|
||||
Assert.IsNotNull(Session.Find<Element>(copiedLayoutName)); // new name is presented
|
||||
|
||||
// verify the file
|
||||
var customLayouts = new CustomLayouts();
|
||||
var data = customLayouts.Read(customLayouts.File);
|
||||
Assert.AreEqual(CustomLayouts.CustomLayouts.Count + 1, data.CustomLayouts.Count);
|
||||
|
||||
// verify the default layout wasn't changed
|
||||
Session.Find<Element>(CustomLayouts.CustomLayouts[0].Name).Find<Button>(By.AccessibilityId(AccessibilityId.EditLayoutButton)).Click();
|
||||
var verticalDefaultButton = Session.Find<Button>(By.AccessibilityId(AccessibilityId.VerticalDefaultButtonChecked));
|
||||
Assert.IsNotNull(verticalDefaultButton);
|
||||
Session.Find<Button>(ElementName.Cancel).Click();
|
||||
|
||||
Session.Find<Element>(copiedLayoutName).Find<Button>(By.AccessibilityId(AccessibilityId.EditLayoutButton)).Click();
|
||||
verticalDefaultButton = Session.Find<Button>(By.AccessibilityId(AccessibilityId.VerticalDefaultButtonUnchecked));
|
||||
Assert.IsNotNull(verticalDefaultButton);
|
||||
Session.Find<Button>(ElementName.Cancel).Click();
|
||||
|
||||
// verify the default layouts file wasn't changed
|
||||
var defaultLayouts = new DefaultLayouts();
|
||||
var defaultLayoutData = defaultLayouts.Read(defaultLayouts.File);
|
||||
Assert.AreEqual(defaultLayouts.Serialize(DefaultLayouts), defaultLayouts.Serialize(defaultLayoutData));
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
public void CopyCustomLayout_Hotkey()
|
||||
{
|
||||
string copiedLayoutName = CustomLayouts.CustomLayouts[0].Name + " (1)";
|
||||
Session.Find<Element>(CustomLayouts.CustomLayouts[0].Name).Find<Button>(By.AccessibilityId(AccessibilityId.EditLayoutButton)).Click();
|
||||
ClickCopyLayout();
|
||||
|
||||
// verify the layout is copied
|
||||
Assert.IsNotNull(Session.Find<Element>(copiedLayoutName)); // new name is presented
|
||||
|
||||
// verify the file
|
||||
var customLayouts = new CustomLayouts();
|
||||
var data = customLayouts.Read(customLayouts.File);
|
||||
Assert.AreEqual(CustomLayouts.CustomLayouts.Count + 1, data.CustomLayouts.Count);
|
||||
|
||||
// verify the hotkey wasn't changed
|
||||
Session.Find<Element>(CustomLayouts.CustomLayouts[0].Name).Find<Button>(By.AccessibilityId(AccessibilityId.EditLayoutButton)).Click();
|
||||
var hotkeyComboBox = Session.Find<Element>(By.AccessibilityId(AccessibilityId.HotkeyComboBox));
|
||||
Assert.IsNotNull(hotkeyComboBox);
|
||||
Assert.AreEqual("0", hotkeyComboBox.Text);
|
||||
Session.Find<Button>(ElementName.Cancel).Click();
|
||||
|
||||
Session.Find<Element>(copiedLayoutName).Find<Button>(By.AccessibilityId(AccessibilityId.EditLayoutButton)).Click();
|
||||
hotkeyComboBox = Session.Find<Element>(By.AccessibilityId(AccessibilityId.HotkeyComboBox));
|
||||
Assert.IsNotNull(hotkeyComboBox);
|
||||
Assert.AreEqual("None", hotkeyComboBox.Text);
|
||||
Session.Find<Button>(ElementName.Cancel).Click();
|
||||
|
||||
// verify the hotkey file wasn't changed
|
||||
var hotkeys = new LayoutHotkeys();
|
||||
var hotkeyData = hotkeys.Read(hotkeys.File);
|
||||
Assert.AreEqual(hotkeys.Serialize(Hotkeys), hotkeys.Serialize(hotkeyData));
|
||||
}
|
||||
|
||||
public void ClickCopyLayout()
|
||||
{
|
||||
if (Session.FindAll<Element>(By.AccessibilityId(AccessibilityId.CopyTemplate)).Count != 0)
|
||||
{
|
||||
Session.Find<Element>(By.AccessibilityId(AccessibilityId.CopyTemplate)).Click();
|
||||
}
|
||||
else
|
||||
{
|
||||
Session.Find<Element>(By.AccessibilityId(AccessibilityId.DuplicateLayoutButton)).Click();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,240 @@
|
||||
// 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 FancyZonesEditor.Models;
|
||||
using FancyZonesEditorCommon.Data;
|
||||
using Microsoft.FancyZonesEditor.UnitTests.Utils;
|
||||
using Microsoft.PowerToys.UITest;
|
||||
using Microsoft.VisualStudio.TestTools.UnitTesting;
|
||||
using static Microsoft.FancyZonesEditor.UnitTests.Utils.FancyZonesEditorHelper;
|
||||
|
||||
namespace Microsoft.FancyZonesEditor.UITests
|
||||
{
|
||||
[TestClass]
|
||||
public class CreateLayoutTests : UITestBase
|
||||
{
|
||||
public CreateLayoutTests()
|
||||
: base(PowerToysModule.FancyZone)
|
||||
{
|
||||
}
|
||||
|
||||
[TestInitialize]
|
||||
public void TestInitialize()
|
||||
{
|
||||
// prepare test editor parameters with 2 monitors before launching the editor
|
||||
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,
|
||||
},
|
||||
},
|
||||
};
|
||||
FancyZonesEditorHelper.Files.ParamsIOHelper.WriteData(editorParameters.Serialize(parameters));
|
||||
|
||||
LayoutTemplates layoutTemplates = new LayoutTemplates();
|
||||
LayoutTemplates.TemplateLayoutsListWrapper templateLayoutsListWrapper = new LayoutTemplates.TemplateLayoutsListWrapper
|
||||
{
|
||||
LayoutTemplates = new List<LayoutTemplates.TemplateLayoutWrapper>
|
||||
{
|
||||
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();
|
||||
CustomLayouts.CustomLayoutListWrapper customLayoutListWrapper = new CustomLayouts.CustomLayoutListWrapper
|
||||
{
|
||||
CustomLayouts = new List<CustomLayouts.CustomLayoutWrapper> { },
|
||||
};
|
||||
FancyZonesEditorHelper.Files.CustomLayoutsIOHelper.WriteData(customLayouts.Serialize(customLayoutListWrapper));
|
||||
|
||||
DefaultLayouts defaultLayouts = new DefaultLayouts();
|
||||
DefaultLayouts.DefaultLayoutsListWrapper defaultLayoutsListWrapper = new DefaultLayouts.DefaultLayoutsListWrapper
|
||||
{
|
||||
DefaultLayouts = new List<DefaultLayouts.DefaultLayoutWrapper> { },
|
||||
};
|
||||
FancyZonesEditorHelper.Files.DefaultLayoutsIOHelper.WriteData(defaultLayouts.Serialize(defaultLayoutsListWrapper));
|
||||
|
||||
LayoutHotkeys layoutHotkeys = new LayoutHotkeys();
|
||||
LayoutHotkeys.LayoutHotkeysWrapper layoutHotkeysWrapper = new LayoutHotkeys.LayoutHotkeysWrapper
|
||||
{
|
||||
LayoutHotkeys = new List<LayoutHotkeys.LayoutHotkeyWrapper> { },
|
||||
};
|
||||
FancyZonesEditorHelper.Files.LayoutHotkeysIOHelper.WriteData(layoutHotkeys.Serialize(layoutHotkeysWrapper));
|
||||
|
||||
AppliedLayouts appliedLayouts = new AppliedLayouts();
|
||||
AppliedLayouts.AppliedLayoutsListWrapper appliedLayoutsWrapper = new AppliedLayouts.AppliedLayoutsListWrapper
|
||||
{
|
||||
AppliedLayouts = new List<AppliedLayouts.AppliedLayoutWrapper> { },
|
||||
};
|
||||
FancyZonesEditorHelper.Files.AppliedLayoutsIOHelper.WriteData(appliedLayouts.Serialize(appliedLayoutsWrapper));
|
||||
|
||||
this.RestartScopeExe();
|
||||
}
|
||||
|
||||
[TestCleanup]
|
||||
public void TestCleanup()
|
||||
{
|
||||
FancyZonesEditorHelper.Files.Restore();
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
public void CreateWithDefaultName()
|
||||
{
|
||||
string name = "Custom layout 1";
|
||||
Session.Find<Element>(By.AccessibilityId(AccessibilityId.NewLayoutButton)).Click();
|
||||
Session.Find<Element>(By.AccessibilityId(AccessibilityId.PrimaryButton)).Click();
|
||||
Session.Find<Button>(ElementName.Save).Click();
|
||||
|
||||
// verify new layout presented
|
||||
Assert.IsNotNull(Session.Find<Element>(name));
|
||||
|
||||
// check the file
|
||||
var customLayouts = new CustomLayouts();
|
||||
var data = customLayouts.Read(customLayouts.File);
|
||||
Assert.AreEqual(1, data.CustomLayouts.Count);
|
||||
Assert.IsTrue(data.CustomLayouts.Exists(x => x.Name == name));
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
public void CreateWithCustomName()
|
||||
{
|
||||
string name = "Layout Name";
|
||||
Session.Find<Element>(By.AccessibilityId(AccessibilityId.NewLayoutButton)).Click();
|
||||
var input = Session.Find<TextBox>(By.ClassName(ClassName.TextBox));
|
||||
Assert.IsNotNull(input);
|
||||
input.SetText(name, true);
|
||||
Session.Find<Element>(By.AccessibilityId(AccessibilityId.PrimaryButton)).Click();
|
||||
Session.Find<Button>(ElementName.Save).Click();
|
||||
|
||||
// verify new layout presented
|
||||
Assert.IsNotNull(Session.Find<Element>(name));
|
||||
|
||||
// check the file
|
||||
var customLayouts = new CustomLayouts();
|
||||
var data = customLayouts.Read(customLayouts.File);
|
||||
Assert.AreEqual(1, data.CustomLayouts.Count);
|
||||
Assert.IsTrue(data.CustomLayouts.Exists(x => x.Name == name));
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
public void CreateGrid()
|
||||
{
|
||||
CustomLayout type = CustomLayout.Grid;
|
||||
Session.Find<Element>(By.AccessibilityId(AccessibilityId.NewLayoutButton)).Click();
|
||||
Session.Find<Element>(By.AccessibilityId(AccessibilityId.GridRadioButton)).Click();
|
||||
Session.Find<Element>(By.AccessibilityId(AccessibilityId.PrimaryButton)).Click();
|
||||
Session.Find<Button>(ElementName.Save).Click();
|
||||
|
||||
// check the file
|
||||
var customLayouts = new CustomLayouts();
|
||||
var data = customLayouts.Read(customLayouts.File);
|
||||
Assert.AreEqual(1, data.CustomLayouts.Count);
|
||||
Assert.IsTrue(data.CustomLayouts.Exists(x => x.Type == type.TypeToString()));
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
public void CreateCanvas()
|
||||
{
|
||||
CustomLayout type = CustomLayout.Canvas;
|
||||
Session.Find<Element>(By.AccessibilityId(AccessibilityId.NewLayoutButton)).Click();
|
||||
Session.Find<Element>(By.AccessibilityId(AccessibilityId.CanvasRadioButton)).Click();
|
||||
Session.Find<Element>(By.AccessibilityId(AccessibilityId.PrimaryButton)).Click();
|
||||
Session.Find<Button>(ElementName.Save).Click();
|
||||
|
||||
// check the file
|
||||
var customLayouts = new CustomLayouts();
|
||||
var data = customLayouts.Read(customLayouts.File);
|
||||
Assert.AreEqual(1, data.CustomLayouts.Count);
|
||||
Assert.IsTrue(data.CustomLayouts.Exists(x => x.Type == type.TypeToString()));
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
public void CancelGridCreation()
|
||||
{
|
||||
Session.Find<Element>(By.AccessibilityId(AccessibilityId.NewLayoutButton)).Click();
|
||||
Session.Find<Element>(By.AccessibilityId(AccessibilityId.GridRadioButton)).Click();
|
||||
Session.Find<Element>(By.AccessibilityId(AccessibilityId.PrimaryButton)).Click();
|
||||
Session.Find<Button>(ElementName.Cancel).Click();
|
||||
|
||||
// check the file
|
||||
var customLayouts = new CustomLayouts();
|
||||
var data = customLayouts.Read(customLayouts.File);
|
||||
Assert.AreEqual(0, data.CustomLayouts.Count);
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
public void CancelCanvasCreation()
|
||||
{
|
||||
Session.Find<Element>(By.AccessibilityId(AccessibilityId.NewLayoutButton)).Click();
|
||||
Session.Find<Element>(By.AccessibilityId(AccessibilityId.CanvasRadioButton)).Click();
|
||||
Session.Find<Element>(By.AccessibilityId(AccessibilityId.PrimaryButton)).Click();
|
||||
Session.Find<Button>(ElementName.Cancel).Click();
|
||||
|
||||
// check the file
|
||||
var customLayouts = new CustomLayouts();
|
||||
var data = customLayouts.Read(customLayouts.File);
|
||||
Assert.AreEqual(0, data.CustomLayouts.Count);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,457 @@
|
||||
// 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;
|
||||
|
||||
namespace Microsoft.FancyZonesEditor.UITests
|
||||
{
|
||||
[TestClass]
|
||||
public class CustomLayoutsTests : UITestBase
|
||||
{
|
||||
public CustomLayoutsTests()
|
||||
: base(PowerToysModule.FancyZone)
|
||||
{
|
||||
}
|
||||
|
||||
private static readonly CustomLayoutListWrapper Layouts = new CustomLayoutListWrapper
|
||||
{
|
||||
CustomLayouts = new List<CustomLayoutWrapper>
|
||||
{
|
||||
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<int> { 2967, 7033 },
|
||||
ColumnsPercentage = new List<int> { 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<CanvasInfoWrapper.CanvasZoneWrapper>
|
||||
{
|
||||
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<int> { 2967, 7033 },
|
||||
ColumnsPercentage = new List<int> { 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();
|
||||
FancyZonesEditorHelper.Files.CustomLayoutsIOHelper.WriteData(customLayouts.Serialize(Layouts));
|
||||
|
||||
EditorParameters editorParameters = new EditorParameters();
|
||||
ParamsWrapper parameters = new ParamsWrapper
|
||||
{
|
||||
ProcessId = 1,
|
||||
SpanZonesAcrossMonitors = false,
|
||||
Monitors = new List<NativeMonitorDataWrapper>
|
||||
{
|
||||
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<LayoutTemplates.TemplateLayoutWrapper>
|
||||
{
|
||||
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));
|
||||
|
||||
DefaultLayouts defaultLayouts = new DefaultLayouts();
|
||||
DefaultLayouts.DefaultLayoutsListWrapper defaultLayoutsListWrapper = new DefaultLayouts.DefaultLayoutsListWrapper
|
||||
{
|
||||
DefaultLayouts = new List<DefaultLayouts.DefaultLayoutWrapper> { },
|
||||
};
|
||||
FancyZonesEditorHelper.Files.DefaultLayoutsIOHelper.WriteData(defaultLayouts.Serialize(defaultLayoutsListWrapper));
|
||||
|
||||
LayoutHotkeys layoutHotkeys = new LayoutHotkeys();
|
||||
LayoutHotkeys.LayoutHotkeysWrapper layoutHotkeysWrapper = new LayoutHotkeys.LayoutHotkeysWrapper
|
||||
{
|
||||
LayoutHotkeys = new List<LayoutHotkeys.LayoutHotkeyWrapper> { },
|
||||
};
|
||||
FancyZonesEditorHelper.Files.LayoutHotkeysIOHelper.WriteData(layoutHotkeys.Serialize(layoutHotkeysWrapper));
|
||||
|
||||
AppliedLayouts appliedLayouts = new AppliedLayouts();
|
||||
AppliedLayouts.AppliedLayoutsListWrapper appliedLayoutsWrapper = new AppliedLayouts.AppliedLayoutsListWrapper
|
||||
{
|
||||
AppliedLayouts = new List<AppliedLayouts.AppliedLayoutWrapper> { },
|
||||
};
|
||||
FancyZonesEditorHelper.Files.AppliedLayoutsIOHelper.WriteData(appliedLayouts.Serialize(appliedLayoutsWrapper));
|
||||
|
||||
this.RestartScopeExe();
|
||||
}
|
||||
|
||||
[TestCleanup]
|
||||
public void TestCleanup()
|
||||
{
|
||||
FancyZonesEditorHelper.Files.Restore();
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
public void Name_Initialize()
|
||||
{
|
||||
// verify all custom layouts are presented
|
||||
foreach (var layout in Layouts.CustomLayouts)
|
||||
{
|
||||
Assert.IsNotNull(Session.Find<Element>(layout.Name));
|
||||
}
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
public void Rename_Save()
|
||||
{
|
||||
string newName = "New layout name";
|
||||
var oldName = Layouts.CustomLayouts[0].Name;
|
||||
|
||||
// rename the layout
|
||||
Session.Find<Element>(oldName).Find<Button>(PowerToys.UITest.By.AccessibilityId(AccessibilityId.EditLayoutButton)).Click();
|
||||
var input = Session.Find<TextBox>(PowerToys.UITest.By.ClassName(ClassName.TextBox));
|
||||
Assert.IsNotNull(input);
|
||||
input.SetText(newName, true);
|
||||
|
||||
// verify new name
|
||||
Session.Find<Button>(ElementName.Save).Click();
|
||||
if (Session.FindAll<Element>(oldName).Count != 0)
|
||||
{
|
||||
Assert.Fail("Error : previous name isn't presented"); // previous name isn't presented
|
||||
}
|
||||
|
||||
if (Session.FindAll<Element>(newName).Count == 0)
|
||||
{
|
||||
Assert.Fail("Error : new name is presented"); // new name is presented
|
||||
}
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
public void Rename_Cancel()
|
||||
{
|
||||
string newName = "New layout name";
|
||||
var oldName = Layouts.CustomLayouts[0].Name;
|
||||
|
||||
// rename the layout
|
||||
Session.Find<Element>(oldName).Find<Button>(PowerToys.UITest.By.AccessibilityId(AccessibilityId.EditLayoutButton)).Click();
|
||||
var input = Session.Find<TextBox>(PowerToys.UITest.By.ClassName(ClassName.TextBox));
|
||||
Assert.IsNotNull(input);
|
||||
input.SetText(newName, true);
|
||||
|
||||
// verify new name
|
||||
Session.Find<Button>(ElementName.Cancel).Click();
|
||||
Assert.IsTrue(Session.FindAll<Element>(oldName).Count == 0);
|
||||
Assert.IsTrue(Session.FindAll<Element>(newName).Count != 0);
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
public void HighlightDistance_Initialize()
|
||||
{
|
||||
foreach (var layout in Layouts.CustomLayouts)
|
||||
{
|
||||
Session.Find<Element>(layout.Name).Find<Button>(PowerToys.UITest.By.AccessibilityId(AccessibilityId.EditLayoutButton)).Click();
|
||||
|
||||
var slider = Session.Find<Element>(PowerToys.UITest.By.AccessibilityId(AccessibilityId.SensitivitySlider));
|
||||
Assert.IsNotNull(slider);
|
||||
var expected = layout.Type == CustomLayout.Canvas.TypeToString() ?
|
||||
new CustomLayouts().CanvasFromJsonElement(layout.Info.GetRawText()).SensitivityRadius :
|
||||
new CustomLayouts().GridFromJsonElement(layout.Info.GetRawText()).SensitivityRadius;
|
||||
Assert.AreEqual($"{expected}", slider.Text);
|
||||
|
||||
Session.Find<Button>(ElementName.Cancel).Click();
|
||||
}
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
public void HighlightDistance_Save()
|
||||
{
|
||||
var layout = Layouts.CustomLayouts[0];
|
||||
var type = layout.Type;
|
||||
Session.Find<Element>(layout.Name).Find<Button>(PowerToys.UITest.By.AccessibilityId(AccessibilityId.EditLayoutButton)).Click();
|
||||
|
||||
var slider = Session.Find<Element>(PowerToys.UITest.By.AccessibilityId(AccessibilityId.SensitivitySlider));
|
||||
Assert.IsNotNull(slider);
|
||||
slider.SendKeys(Keys.Right);
|
||||
|
||||
var value = type == CustomLayout.Canvas.TypeToString() ?
|
||||
new CustomLayouts().CanvasFromJsonElement(layout.Info.GetRawText()).SensitivityRadius :
|
||||
new CustomLayouts().GridFromJsonElement(layout.Info.GetRawText()).SensitivityRadius;
|
||||
var expected = value + 1; // one step right
|
||||
|
||||
Assert.AreEqual($"{expected}", slider.Text);
|
||||
|
||||
Session.Find<Button>(ElementName.Save).Click();
|
||||
|
||||
// verify the file
|
||||
var customLayouts = new CustomLayouts();
|
||||
var data = customLayouts.Read(customLayouts.File);
|
||||
var actual = type == CustomLayout.Canvas.TypeToString() ?
|
||||
new CustomLayouts().CanvasFromJsonElement(data.CustomLayouts.Find(x => x.Uuid == layout.Uuid).Info.GetRawText()).SensitivityRadius :
|
||||
new CustomLayouts().GridFromJsonElement(data.CustomLayouts.Find(x => x.Uuid == layout.Uuid).Info.GetRawText()).SensitivityRadius;
|
||||
Assert.AreEqual(expected, actual);
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
public void HighlightDistance_Cancel()
|
||||
{
|
||||
var layout = Layouts.CustomLayouts[0];
|
||||
var type = layout.Type;
|
||||
Session.Find<Element>(layout.Name).Find<Button>(PowerToys.UITest.By.AccessibilityId(AccessibilityId.EditLayoutButton)).Click();
|
||||
|
||||
var slider = Session.Find<Element>(PowerToys.UITest.By.AccessibilityId(AccessibilityId.SensitivitySlider));
|
||||
Assert.IsNotNull(slider);
|
||||
slider.SendKeys(Keys.Right);
|
||||
|
||||
var expected = type == CustomLayout.Canvas.TypeToString() ?
|
||||
new CustomLayouts().CanvasFromJsonElement(layout.Info.GetRawText()).SensitivityRadius :
|
||||
new CustomLayouts().GridFromJsonElement(layout.Info.GetRawText()).SensitivityRadius;
|
||||
|
||||
Session.Find<Button>(ElementName.Cancel).Click();
|
||||
|
||||
// verify the file
|
||||
var customLayouts = new CustomLayouts();
|
||||
var data = customLayouts.Read(customLayouts.File);
|
||||
var actual = type == CustomLayout.Canvas.TypeToString() ?
|
||||
new CustomLayouts().CanvasFromJsonElement(data.CustomLayouts.Find(x => x.Uuid == layout.Uuid).Info.GetRawText()).SensitivityRadius :
|
||||
new CustomLayouts().GridFromJsonElement(data.CustomLayouts.Find(x => x.Uuid == layout.Uuid).Info.GetRawText()).SensitivityRadius;
|
||||
Assert.AreEqual(expected, actual);
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
public void SpaceAroundZones_Initialize()
|
||||
{
|
||||
foreach (var layout in Layouts.CustomLayouts)
|
||||
{
|
||||
if (layout.Type != CustomLayout.Grid.TypeToString())
|
||||
{
|
||||
// only for grid layouts
|
||||
continue;
|
||||
}
|
||||
|
||||
Session.Find<Element>(layout.Name).Find<Button>(PowerToys.UITest.By.AccessibilityId(AccessibilityId.EditLayoutButton)).Click();
|
||||
|
||||
var toggle = Session.Find<Element>(PowerToys.UITest.By.AccessibilityId(AccessibilityId.SpacingToggle));
|
||||
Assert.IsNotNull(toggle);
|
||||
var slider = Session.Find<Element>(PowerToys.UITest.By.AccessibilityId(AccessibilityId.SpacingSlider));
|
||||
Assert.IsNotNull(slider);
|
||||
|
||||
var spacingEnabled = new CustomLayouts().GridFromJsonElement(layout.Info.GetRawText()).ShowSpacing;
|
||||
Assert.AreEqual(spacingEnabled, slider.Enabled);
|
||||
Assert.AreEqual(spacingEnabled, toggle.Selected);
|
||||
|
||||
var expected = new CustomLayouts().GridFromJsonElement(layout.Info.GetRawText()).Spacing;
|
||||
Assert.AreEqual($"{expected}", slider.Text);
|
||||
|
||||
Session.Find<Button>(ElementName.Cancel).Click();
|
||||
}
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
public void SpaceAroundZones_Slider_Save()
|
||||
{
|
||||
var layout = Layouts.CustomLayouts.Find(x => x.Type == CustomLayout.Grid.TypeToString() && new CustomLayouts().GridFromJsonElement(x.Info.GetRawText()).ShowSpacing);
|
||||
var expected = new CustomLayouts().GridFromJsonElement(layout.Info.GetRawText()).Spacing + 1; // one step right
|
||||
Session.Find<Element>(layout.Name).Find<Button>(PowerToys.UITest.By.AccessibilityId(AccessibilityId.EditLayoutButton)).Click();
|
||||
|
||||
var slider = Session.Find<Element>(PowerToys.UITest.By.AccessibilityId(AccessibilityId.SpacingSlider));
|
||||
Assert.IsNotNull(slider);
|
||||
slider.SendKeys(Keys.Right);
|
||||
Assert.AreEqual($"{expected}", slider.Text);
|
||||
|
||||
Session.Find<Button>(ElementName.Save).Click();
|
||||
|
||||
// verify the file
|
||||
var customLayouts = new CustomLayouts();
|
||||
var data = customLayouts.Read(customLayouts.File);
|
||||
var actual = new CustomLayouts().GridFromJsonElement(data.CustomLayouts.Find(x => x.Uuid == layout.Uuid).Info.GetRawText()).Spacing;
|
||||
Assert.AreEqual(expected, actual);
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
public void SpaceAroundZones_Slider_Cancel()
|
||||
{
|
||||
var layout = Layouts.CustomLayouts.Find(x => x.Type == CustomLayout.Grid.TypeToString() && new CustomLayouts().GridFromJsonElement(x.Info.GetRawText()).ShowSpacing);
|
||||
Session.Find<Element>(layout.Name).Find<Button>(PowerToys.UITest.By.AccessibilityId(AccessibilityId.EditLayoutButton)).Click();
|
||||
var expected = new CustomLayouts().GridFromJsonElement(layout.Info.GetRawText()).Spacing;
|
||||
|
||||
var slider = Session.Find<Element>(PowerToys.UITest.By.AccessibilityId(AccessibilityId.SpacingSlider));
|
||||
Assert.IsNotNull(slider);
|
||||
slider.SendKeys(Keys.Right);
|
||||
Session.Find<Button>(ElementName.Cancel).Click();
|
||||
|
||||
// verify the file
|
||||
var customLayouts = new CustomLayouts();
|
||||
var data = customLayouts.Read(customLayouts.File);
|
||||
var actual = new CustomLayouts().GridFromJsonElement(data.CustomLayouts.Find(x => x.Uuid == layout.Uuid).Info.GetRawText()).Spacing;
|
||||
Assert.AreEqual(expected, actual);
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
public void SpaceAroundZones_Toggle_Save()
|
||||
{
|
||||
var layout = Layouts.CustomLayouts.Find(x => x.Type == CustomLayout.Grid.TypeToString());
|
||||
var value = new CustomLayouts().GridFromJsonElement(layout.Info.GetRawText()).ShowSpacing;
|
||||
var expected = !value;
|
||||
Session.Find<Element>(layout.Name).Find<Button>(PowerToys.UITest.By.AccessibilityId(AccessibilityId.EditLayoutButton)).Click();
|
||||
|
||||
var toggle = Session.Find<Element>(PowerToys.UITest.By.AccessibilityId(AccessibilityId.SpacingToggle));
|
||||
Assert.IsNotNull(toggle);
|
||||
toggle.Click();
|
||||
Assert.AreEqual(expected, toggle.Selected, "Toggle value not changed");
|
||||
Assert.AreEqual(expected, Session.Find<Element>(PowerToys.UITest.By.AccessibilityId(AccessibilityId.SpacingSlider))?.Enabled);
|
||||
|
||||
Session.Find<Button>(ElementName.Save).Click();
|
||||
|
||||
// verify the file
|
||||
var customLayouts = new CustomLayouts();
|
||||
var data = customLayouts.Read(customLayouts.File);
|
||||
var actual = new CustomLayouts().GridFromJsonElement(data.CustomLayouts.Find(x => x.Uuid == layout.Uuid).Info.GetRawText()).ShowSpacing;
|
||||
Assert.AreEqual(expected, actual);
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
public void SpaceAroundZones_Toggle_Cancel()
|
||||
{
|
||||
var layout = Layouts.CustomLayouts.Find(x => x.Type == CustomLayout.Grid.TypeToString());
|
||||
var expected = new CustomLayouts().GridFromJsonElement(layout.Info.GetRawText()).ShowSpacing;
|
||||
Session.Find<Element>(layout.Name).Find<Button>(PowerToys.UITest.By.AccessibilityId(AccessibilityId.EditLayoutButton)).Click();
|
||||
|
||||
var toggle = Session.Find<Element>(PowerToys.UITest.By.AccessibilityId(AccessibilityId.SpacingToggle));
|
||||
Assert.IsNotNull(toggle);
|
||||
toggle.Click();
|
||||
Assert.AreNotEqual(expected, toggle.Selected, "Toggle value not changed");
|
||||
Assert.AreNotEqual(expected, Session.Find<Element>(PowerToys.UITest.By.AccessibilityId(AccessibilityId.SpacingSlider))?.Enabled);
|
||||
|
||||
Session.Find<Button>(ElementName.Cancel).Click();
|
||||
|
||||
// verify the file
|
||||
var customLayouts = new CustomLayouts();
|
||||
var data = customLayouts.Read(customLayouts.File);
|
||||
var actual = new CustomLayouts().GridFromJsonElement(data.CustomLayouts.Find(x => x.Uuid == layout.Uuid).Info.GetRawText()).ShowSpacing;
|
||||
Assert.AreEqual(expected, actual);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,363 @@
|
||||
// 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.Xml.Linq;
|
||||
using FancyZonesEditor.Models;
|
||||
using FancyZonesEditorCommon.Data;
|
||||
using Microsoft.FancyZonesEditor.UnitTests.Utils;
|
||||
using Microsoft.PowerToys.UITest;
|
||||
using Microsoft.VisualStudio.TestTools.UnitTesting;
|
||||
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
|
||||
{
|
||||
[TestClass]
|
||||
public class DefaultLayoutsTest : UITestBase
|
||||
{
|
||||
public DefaultLayoutsTest()
|
||||
: base(PowerToysModule.FancyZone)
|
||||
{
|
||||
}
|
||||
|
||||
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<CustomLayoutWrapper>
|
||||
{
|
||||
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<CanvasInfoWrapper.CanvasZoneWrapper> { },
|
||||
}),
|
||||
},
|
||||
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<CanvasInfoWrapper.CanvasZoneWrapper> { },
|
||||
}),
|
||||
},
|
||||
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<CanvasInfoWrapper.CanvasZoneWrapper> { },
|
||||
}),
|
||||
},
|
||||
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<CanvasInfoWrapper.CanvasZoneWrapper> { },
|
||||
}),
|
||||
},
|
||||
},
|
||||
};
|
||||
|
||||
private static readonly DefaultLayoutsListWrapper Layouts = new DefaultLayoutsListWrapper
|
||||
{
|
||||
DefaultLayouts = new List<DefaultLayoutWrapper>
|
||||
{
|
||||
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
|
||||
{
|
||||
ProcessId = 1,
|
||||
SpanZonesAcrossMonitors = false,
|
||||
Monitors = new List<NativeMonitorDataWrapper>
|
||||
{
|
||||
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,
|
||||
},
|
||||
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,
|
||||
},
|
||||
},
|
||||
};
|
||||
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<LayoutTemplates.TemplateLayoutWrapper>
|
||||
{
|
||||
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<LayoutHotkeys.LayoutHotkeyWrapper> { },
|
||||
};
|
||||
FancyZonesEditorHelper.Files.LayoutHotkeysIOHelper.WriteData(layoutHotkeys.Serialize(layoutHotkeysWrapper));
|
||||
|
||||
AppliedLayouts appliedLayouts = new AppliedLayouts();
|
||||
AppliedLayouts.AppliedLayoutsListWrapper appliedLayoutsWrapper = new AppliedLayouts.AppliedLayoutsListWrapper
|
||||
{
|
||||
AppliedLayouts = new List<AppliedLayouts.AppliedLayoutWrapper> { },
|
||||
};
|
||||
FancyZonesEditorHelper.Files.AppliedLayoutsIOHelper.WriteData(appliedLayouts.Serialize(appliedLayoutsWrapper));
|
||||
|
||||
this.RestartScopeExe();
|
||||
}
|
||||
|
||||
[TestCleanup]
|
||||
public void TestCleanup()
|
||||
{
|
||||
FancyZonesEditorHelper.Files.Restore();
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
public void Initialize()
|
||||
{
|
||||
CheckTemplateLayouts(LayoutType.Grid, null);
|
||||
CheckCustomLayouts(string.Empty, CustomLayouts.CustomLayouts[0].Uuid);
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
public void Assign_Cancel()
|
||||
{
|
||||
// assign Focus as a default horizontal and vertical layout
|
||||
Session.Find<Element>(TestConstants.TemplateLayoutNames[LayoutType.Focus]).Find<Button>(By.AccessibilityId(AccessibilityId.EditLayoutButton)).Click();
|
||||
Session.Find<Button>(By.AccessibilityId(AccessibilityId.HorizontalDefaultButtonUnchecked)).Click();
|
||||
Session.Find<Button>(By.AccessibilityId(AccessibilityId.VerticalDefaultButtonUnchecked)).Click();
|
||||
|
||||
// cancel
|
||||
Session.Find<Button>(ElementName.Cancel).Click();
|
||||
|
||||
// check that default layouts weren't changed
|
||||
CheckTemplateLayouts(LayoutType.Grid, null);
|
||||
CheckCustomLayouts(string.Empty, CustomLayouts.CustomLayouts[0].Uuid);
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
public void Assign_Save()
|
||||
{
|
||||
// assign Focus as a default horizontal and vertical layout
|
||||
Session.Find<Element>(TestConstants.TemplateLayoutNames[LayoutType.Focus]).Find<Button>(By.AccessibilityId(AccessibilityId.EditLayoutButton)).Click();
|
||||
Session.Find<Button>(By.AccessibilityId(AccessibilityId.HorizontalDefaultButtonUnchecked)).Click();
|
||||
Session.Find<Button>(By.AccessibilityId(AccessibilityId.VerticalDefaultButtonUnchecked)).Click();
|
||||
|
||||
// save
|
||||
Session.Find<Button>(ElementName.Save).Click();
|
||||
|
||||
// check that default layout was changed
|
||||
CheckTemplateLayouts(LayoutType.Focus, LayoutType.Focus);
|
||||
CheckCustomLayouts(string.Empty, string.Empty);
|
||||
}
|
||||
|
||||
private void CheckTemplateLayouts(LayoutType? horizontalDefault, LayoutType? verticalDefault)
|
||||
{
|
||||
foreach (var (key, name) in TestConstants.TemplateLayoutNames)
|
||||
{
|
||||
if (key == LayoutType.Blank)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
Session.Find<Element>(name).Find<Button>(By.AccessibilityId(AccessibilityId.EditLayoutButton)).Click();
|
||||
|
||||
bool isCheckedHorizontal = key == horizontalDefault;
|
||||
bool isCheckedVertical = key == verticalDefault;
|
||||
|
||||
Button? horizontalDefaultButton;
|
||||
Button? verticalDefaultButton;
|
||||
|
||||
if (isCheckedHorizontal)
|
||||
{
|
||||
horizontalDefaultButton = Session.Find<Button>(By.AccessibilityId(AccessibilityId.HorizontalDefaultButtonChecked));
|
||||
}
|
||||
else
|
||||
{
|
||||
horizontalDefaultButton = Session.Find<Button>(By.AccessibilityId(AccessibilityId.HorizontalDefaultButtonUnchecked));
|
||||
}
|
||||
|
||||
if (isCheckedVertical)
|
||||
{
|
||||
verticalDefaultButton = Session.Find<Button>(By.AccessibilityId(AccessibilityId.VerticalDefaultButtonChecked));
|
||||
}
|
||||
else
|
||||
{
|
||||
verticalDefaultButton = Session.Find<Button>(By.AccessibilityId(AccessibilityId.VerticalDefaultButtonUnchecked));
|
||||
}
|
||||
|
||||
Assert.IsNotNull(horizontalDefaultButton, "Incorrect horizontal default layout set at " + name);
|
||||
Assert.IsNotNull(verticalDefaultButton, "Incorrect vertical default layout set at " + name);
|
||||
|
||||
Session.Find<Button>(ElementName.Cancel).Click();
|
||||
}
|
||||
}
|
||||
|
||||
private void CheckCustomLayouts(string horizontalDefaultLayoutUuid, string verticalDefaultLayoutUuid)
|
||||
{
|
||||
foreach (var layout in CustomLayouts.CustomLayouts)
|
||||
{
|
||||
Session.Find<Element>(layout.Name).Find<Button>(By.AccessibilityId(AccessibilityId.EditLayoutButton)).Click();
|
||||
|
||||
bool isCheckedHorizontal = layout.Uuid == horizontalDefaultLayoutUuid;
|
||||
bool isCheckedVertical = layout.Uuid == verticalDefaultLayoutUuid;
|
||||
Button? horizontalDefaultButton;
|
||||
Button? verticalDefaultButton;
|
||||
|
||||
if (isCheckedHorizontal)
|
||||
{
|
||||
horizontalDefaultButton = Session.Find<Button>(By.AccessibilityId(AccessibilityId.HorizontalDefaultButtonChecked));
|
||||
}
|
||||
else
|
||||
{
|
||||
horizontalDefaultButton = Session.Find<Button>(By.AccessibilityId(AccessibilityId.HorizontalDefaultButtonUnchecked));
|
||||
}
|
||||
|
||||
if (isCheckedVertical)
|
||||
{
|
||||
verticalDefaultButton = Session.Find<Button>(By.AccessibilityId(AccessibilityId.VerticalDefaultButtonChecked));
|
||||
}
|
||||
else
|
||||
{
|
||||
verticalDefaultButton = Session.Find<Button>(By.AccessibilityId(AccessibilityId.VerticalDefaultButtonUnchecked));
|
||||
}
|
||||
|
||||
Assert.IsNotNull(horizontalDefaultButton, "Incorrect horizontal custom layout set at " + layout.Name);
|
||||
Assert.IsNotNull(verticalDefaultButton, "Incorrect vertical custom layout set at " + layout.Name);
|
||||
|
||||
Session.Find<Button>(ElementName.Cancel).Click();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,365 @@
|
||||
// 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 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;
|
||||
using static FancyZonesEditorCommon.Data.CustomLayouts;
|
||||
using static FancyZonesEditorCommon.Data.DefaultLayouts;
|
||||
using static FancyZonesEditorCommon.Data.EditorParameters;
|
||||
using static FancyZonesEditorCommon.Data.LayoutHotkeys;
|
||||
using static Microsoft.FancyZonesEditor.UnitTests.Utils.FancyZonesEditorHelper;
|
||||
|
||||
namespace Microsoft.FancyZonesEditor.UITests
|
||||
{
|
||||
[TestClass]
|
||||
public class DeleteLayoutTests : UITestBase
|
||||
{
|
||||
public DeleteLayoutTests()
|
||||
: base(PowerToysModule.FancyZone)
|
||||
{
|
||||
}
|
||||
|
||||
private static readonly CustomLayoutListWrapper CustomLayouts = new CustomLayoutListWrapper
|
||||
{
|
||||
CustomLayouts = new List<CustomLayoutWrapper>
|
||||
{
|
||||
new CustomLayoutWrapper
|
||||
{
|
||||
Uuid = "{0D6D2F58-9184-4804-81E4-4E4CC3476DC1}",
|
||||
Type = CustomLayout.Grid.TypeToString(),
|
||||
Name = "Custom layout 1",
|
||||
Info = new CustomLayouts().ToJsonElement(new CustomLayouts.GridInfoWrapper
|
||||
{
|
||||
Rows = 2,
|
||||
Columns = 3,
|
||||
RowsPercentage = new List<int> { 2967, 7033 },
|
||||
ColumnsPercentage = new List<int> { 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 = "Custom layout 2",
|
||||
Info = new CustomLayouts().ToJsonElement(new CanvasInfoWrapper
|
||||
{
|
||||
RefHeight = 952,
|
||||
RefWidth = 1500,
|
||||
SensitivityRadius = 10,
|
||||
Zones = new List<CanvasInfoWrapper.CanvasZoneWrapper>
|
||||
{
|
||||
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,
|
||||
},
|
||||
},
|
||||
}),
|
||||
},
|
||||
},
|
||||
};
|
||||
|
||||
private static readonly DefaultLayouts.DefaultLayoutsListWrapper DefaultLayoutsList = new DefaultLayouts.DefaultLayoutsListWrapper
|
||||
{
|
||||
DefaultLayouts = new List<DefaultLayouts.DefaultLayoutWrapper>
|
||||
{
|
||||
new DefaultLayoutWrapper
|
||||
{
|
||||
MonitorConfiguration = MonitorConfigurationType.Horizontal.TypeToString(),
|
||||
Layout = new DefaultLayoutWrapper.LayoutWrapper
|
||||
{
|
||||
Type = LayoutType.Custom.TypeToString(),
|
||||
Uuid = CustomLayouts.CustomLayouts[1].Uuid,
|
||||
},
|
||||
},
|
||||
},
|
||||
};
|
||||
|
||||
private static readonly LayoutHotkeys.LayoutHotkeysWrapper Hotkeys = new LayoutHotkeys.LayoutHotkeysWrapper
|
||||
{
|
||||
LayoutHotkeys = new List<LayoutHotkeys.LayoutHotkeyWrapper>
|
||||
{
|
||||
new LayoutHotkeyWrapper
|
||||
{
|
||||
LayoutId = CustomLayouts.CustomLayouts[1].Uuid,
|
||||
Key = 0,
|
||||
},
|
||||
},
|
||||
};
|
||||
|
||||
private static readonly ParamsWrapper Parameters = new ParamsWrapper
|
||||
{
|
||||
ProcessId = 1,
|
||||
SpanZonesAcrossMonitors = false,
|
||||
Monitors = new List<NativeMonitorDataWrapper>
|
||||
{
|
||||
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,
|
||||
},
|
||||
},
|
||||
};
|
||||
|
||||
[TestInitialize]
|
||||
public void TestInitialize()
|
||||
{
|
||||
EditorParameters editorParameters = new EditorParameters();
|
||||
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<LayoutTemplates.TemplateLayoutWrapper>
|
||||
{
|
||||
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));
|
||||
|
||||
DefaultLayouts defaultLayouts = new DefaultLayouts();
|
||||
FancyZonesEditorHelper.Files.DefaultLayoutsIOHelper.WriteData(defaultLayouts.Serialize(DefaultLayoutsList));
|
||||
|
||||
LayoutHotkeys layoutHotkeys = new LayoutHotkeys();
|
||||
FancyZonesEditorHelper.Files.LayoutHotkeysIOHelper.WriteData(layoutHotkeys.Serialize(Hotkeys));
|
||||
|
||||
AppliedLayouts appliedLayouts = new AppliedLayouts();
|
||||
AppliedLayouts.AppliedLayoutsListWrapper appliedLayoutsWrapper = new AppliedLayouts.AppliedLayoutsListWrapper
|
||||
{
|
||||
AppliedLayouts = new List<AppliedLayouts.AppliedLayoutWrapper> { },
|
||||
};
|
||||
FancyZonesEditorHelper.Files.AppliedLayoutsIOHelper.WriteData(appliedLayouts.Serialize(appliedLayoutsWrapper));
|
||||
|
||||
this.RestartScopeExe();
|
||||
Session.Find<Element>(CustomLayouts.CustomLayouts[0].Name).Click();
|
||||
}
|
||||
|
||||
[TestCleanup]
|
||||
public void TestCleanup()
|
||||
{
|
||||
FancyZonesEditorHelper.Files.Restore();
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
public void DeleteNotAppliedLayout()
|
||||
{
|
||||
var deletedLayout = CustomLayouts.CustomLayouts[1].Name;
|
||||
Session.Find<Element>(deletedLayout).Find<Button>(PowerToys.UITest.By.AccessibilityId(AccessibilityId.EditLayoutButton)).Click();
|
||||
Session.Find<Button>(PowerToys.UITest.By.AccessibilityId(AccessibilityId.DeleteLayoutButton)).Click();
|
||||
Session.KeyboardAction(Keys.Tab, Keys.Enter);
|
||||
|
||||
// verify the layout is removed
|
||||
Assert.IsTrue(Session.FindAll<Element>(deletedLayout).Count == 0);
|
||||
|
||||
// check the file
|
||||
var customLayouts = new CustomLayouts();
|
||||
var data = customLayouts.Read(customLayouts.File);
|
||||
Assert.AreEqual(CustomLayouts.CustomLayouts.Count - 1, data.CustomLayouts.Count);
|
||||
Assert.IsFalse(data.CustomLayouts.Exists(x => x.Name == deletedLayout));
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
public void DeleteAppliedLayout()
|
||||
{
|
||||
var deletedLayout = CustomLayouts.CustomLayouts[0].Name;
|
||||
Session.Find<Element>(deletedLayout).Find<Button>(PowerToys.UITest.By.AccessibilityId(AccessibilityId.EditLayoutButton)).Click();
|
||||
Session.Find<Button>(PowerToys.UITest.By.AccessibilityId(AccessibilityId.DeleteLayoutButton)).Click();
|
||||
Session.KeyboardAction(Keys.Tab, Keys.Enter);
|
||||
|
||||
// verify the layout is removed
|
||||
Assert.IsTrue(Session.FindAll<Element>(deletedLayout).Count == 0);
|
||||
|
||||
// verify the empty layout is selected
|
||||
Assert.IsTrue(Session.Find<Element>(TestConstants.TemplateLayoutNames[LayoutType.Blank])!.Selected);
|
||||
|
||||
// check the file
|
||||
var customLayouts = new CustomLayouts();
|
||||
var data = customLayouts.Read(customLayouts.File);
|
||||
Assert.AreEqual(CustomLayouts.CustomLayouts.Count - 1, data.CustomLayouts.Count);
|
||||
Assert.IsFalse(data.CustomLayouts.Exists(x => x.Name == deletedLayout));
|
||||
|
||||
var appliedLayouts = new AppliedLayouts();
|
||||
var appliedLayoutsData = appliedLayouts.Read(appliedLayouts.File);
|
||||
Assert.AreEqual(LayoutType.Blank.TypeToString(), appliedLayoutsData.AppliedLayouts.Find(x => x.Device.Monitor == Parameters.Monitors[0].Monitor).AppliedLayout.Type);
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
public void CancelDeletion()
|
||||
{
|
||||
var deletedLayout = CustomLayouts.CustomLayouts[1].Name;
|
||||
Session.Find<Element>(deletedLayout).Find<Button>(PowerToys.UITest.By.AccessibilityId(AccessibilityId.EditLayoutButton)).Click();
|
||||
Session.Find<Button>(PowerToys.UITest.By.AccessibilityId(AccessibilityId.DeleteLayoutButton)).Click();
|
||||
Session.KeyboardAction(Keys.Tab, Keys.Tab, Keys.Enter);
|
||||
|
||||
// verify the layout is not removed
|
||||
Assert.IsNotNull(Session.Find<Element>(deletedLayout));
|
||||
|
||||
// check the file
|
||||
var customLayouts = new CustomLayouts();
|
||||
var data = customLayouts.Read(customLayouts.File);
|
||||
Assert.AreEqual(CustomLayouts.CustomLayouts.Count, data.CustomLayouts.Count);
|
||||
Assert.IsTrue(data.CustomLayouts.Exists(x => x.Name == deletedLayout));
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
public void DeleteFromContextMenu()
|
||||
{
|
||||
var deletedLayout = CustomLayouts.CustomLayouts[1].Name;
|
||||
FancyZonesEditorHelper.ClickContextMenuItem(Session, deletedLayout, FancyZonesEditorHelper.ElementName.Delete);
|
||||
Session.KeyboardAction(Keys.Tab, Keys.Enter);
|
||||
|
||||
// verify the layout is removed
|
||||
Assert.IsTrue(Session.FindAll<Element>(deletedLayout).Count == 0);
|
||||
|
||||
// check the file
|
||||
var customLayouts = new CustomLayouts();
|
||||
var data = customLayouts.Read(customLayouts.File);
|
||||
Assert.AreEqual(CustomLayouts.CustomLayouts.Count - 1, data.CustomLayouts.Count);
|
||||
Assert.IsFalse(data.CustomLayouts.Exists(x => x.Name == deletedLayout));
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
public void DeleteDefaultLayout()
|
||||
{
|
||||
var deletedLayout = CustomLayouts.CustomLayouts[1].Name;
|
||||
FancyZonesEditorHelper.ClickContextMenuItem(Session, deletedLayout, FancyZonesEditorHelper.ElementName.Delete);
|
||||
Session.KeyboardAction(Keys.Tab, Keys.Enter);
|
||||
|
||||
// verify the default layout is reset to the "default" default
|
||||
Session.Find<Element>(TestConstants.TemplateLayoutNames[LayoutType.PriorityGrid]).Find<Button>(PowerToys.UITest.By.AccessibilityId(AccessibilityId.EditLayoutButton)).Click();
|
||||
Assert.IsNotNull(Session.Find<Element>(PowerToys.UITest.By.AccessibilityId(AccessibilityId.HorizontalDefaultButtonChecked)));
|
||||
Session.Find<Button>(ElementName.Cancel).Click();
|
||||
|
||||
// check the file
|
||||
var defaultLayouts = new DefaultLayouts();
|
||||
var data = defaultLayouts.Read(defaultLayouts.File);
|
||||
string configuration = MonitorConfigurationType.Horizontal.TypeToString();
|
||||
Assert.AreEqual(LayoutType.PriorityGrid.TypeToString(), data.DefaultLayouts.Find(x => x.MonitorConfiguration == configuration).Layout.Type);
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
public void DeleteLayoutWithHotkey()
|
||||
{
|
||||
var deletedLayout = CustomLayouts.CustomLayouts[1].Name;
|
||||
FancyZonesEditorHelper.ClickContextMenuItem(Session, deletedLayout, FancyZonesEditorHelper.ElementName.Delete);
|
||||
Session.KeyboardAction(Keys.Tab, Keys.Enter);
|
||||
|
||||
// verify the hotkey is available
|
||||
Session.Find<Element>(CustomLayouts.CustomLayouts[0].Name).Find<Button>(PowerToys.UITest.By.AccessibilityId(AccessibilityId.EditLayoutButton)).Click();
|
||||
var hotkeyComboBox = Session.Find<Element>(PowerToys.UITest.By.AccessibilityId(AccessibilityId.HotkeyComboBox));
|
||||
Assert.IsNotNull(hotkeyComboBox);
|
||||
hotkeyComboBox.Click();
|
||||
|
||||
var popup = Session.Find<Element>(PowerToys.UITest.By.ClassName(ClassName.Popup));
|
||||
Assert.IsNotNull(popup);
|
||||
try
|
||||
{
|
||||
for (int i = 0; i < 10; i++)
|
||||
{
|
||||
popup.Find<Element>($"{i}");
|
||||
}
|
||||
}
|
||||
catch
|
||||
{
|
||||
Assert.Fail("Hotkey not found");
|
||||
}
|
||||
|
||||
Session.Find<Button>(ElementName.Cancel).DoubleClick();
|
||||
|
||||
// check the file
|
||||
var hotkeys = new LayoutHotkeys();
|
||||
var data = hotkeys.Read(hotkeys.File);
|
||||
int layoutHotkeyCount = 0;
|
||||
foreach (var layout in data.LayoutHotkeys)
|
||||
{
|
||||
if (layout.Key != -1)
|
||||
{
|
||||
layoutHotkeyCount++;
|
||||
}
|
||||
}
|
||||
|
||||
Assert.AreEqual(0, layoutHotkeyCount);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,653 @@
|
||||
// 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<CustomLayouts.CustomLayoutWrapper>
|
||||
{
|
||||
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<int> { 5000, 5000 },
|
||||
ColumnsPercentage = new List<int> { 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<int> { 2333, 3333, 4334 },
|
||||
ColumnsPercentage = new List<int> { 2333, 3333, 4334 },
|
||||
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<CanvasInfoWrapper.CanvasZoneWrapper>
|
||||
{
|
||||
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<NativeMonitorDataWrapper>
|
||||
{
|
||||
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<LayoutTemplates.TemplateLayoutWrapper>
|
||||
{
|
||||
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<DefaultLayouts.DefaultLayoutWrapper> { },
|
||||
};
|
||||
FancyZonesEditorHelper.Files.DefaultLayoutsIOHelper.WriteData(defaultLayouts.Serialize(defaultLayoutsListWrapper));
|
||||
|
||||
LayoutHotkeys layoutHotkeys = new LayoutHotkeys();
|
||||
LayoutHotkeys.LayoutHotkeysWrapper layoutHotkeysWrapper = new LayoutHotkeys.LayoutHotkeysWrapper
|
||||
{
|
||||
LayoutHotkeys = new List<LayoutHotkeys.LayoutHotkeyWrapper> { },
|
||||
};
|
||||
FancyZonesEditorHelper.Files.LayoutHotkeysIOHelper.WriteData(layoutHotkeys.Serialize(layoutHotkeysWrapper));
|
||||
|
||||
AppliedLayouts appliedLayouts = new AppliedLayouts();
|
||||
AppliedLayouts.AppliedLayoutsListWrapper appliedLayoutsWrapper = new AppliedLayouts.AppliedLayoutsListWrapper
|
||||
{
|
||||
AppliedLayouts = new List<AppliedLayouts.AppliedLayoutWrapper> { },
|
||||
};
|
||||
FancyZonesEditorHelper.Files.AppliedLayoutsIOHelper.WriteData(appliedLayouts.Serialize(appliedLayoutsWrapper));
|
||||
|
||||
this.RestartScopeExe();
|
||||
}
|
||||
|
||||
[TestCleanup]
|
||||
public void TestCleanup()
|
||||
{
|
||||
FancyZonesEditorHelper.Files.Restore();
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
public void OpenEditMode()
|
||||
{
|
||||
Session.Find<Element>(Layouts.CustomLayouts[0].Name).Find<Button>(By.AccessibilityId(AccessibilityId.EditLayoutButton)).Click();
|
||||
Session.Find<Button>(By.AccessibilityId(AccessibilityId.EditZonesButton)).Click();
|
||||
Assert.IsNotNull(Session.Find<Element>(ElementName.GridLayoutEditor));
|
||||
Session.Find<Button>(ElementName.Cancel).Click();
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
public void OpenEditModeFromContextMenu()
|
||||
{
|
||||
FancyZonesEditorHelper.ClickContextMenuItem(Session, Layouts.CustomLayouts[0].Name, FancyZonesEditorHelper.ElementName.EditZones);
|
||||
Assert.IsNotNull(Session.Find<Element>(ElementName.GridLayoutEditor));
|
||||
Session.Find<Button>(ElementName.Cancel).Click();
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
public void Canvas_AddZone_Save()
|
||||
{
|
||||
var canvas = Layouts.CustomLayouts.Find(x => x.Type == CustomLayout.Canvas.TypeToString());
|
||||
FancyZonesEditorHelper.ClickContextMenuItem(Session, canvas.Name, FancyZonesEditorHelper.ElementName.EditZones);
|
||||
Session.Find<Button>(By.AccessibilityId(AccessibilityId.NewZoneButton)).Click();
|
||||
Session.Find<Button>(ElementName.Save).Click();
|
||||
|
||||
// check the file
|
||||
var customLayouts = new CustomLayouts();
|
||||
var data = customLayouts.Read(customLayouts.File);
|
||||
var expected = customLayouts.CanvasFromJsonElement(canvas.Info.ToString());
|
||||
var actual = customLayouts.CanvasFromJsonElement(data.CustomLayouts.Find(x => x.Uuid == canvas.Uuid).Info.GetRawText());
|
||||
Assert.AreEqual(expected.Zones.Count + 1, actual.Zones.Count);
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
public void Canvas_AddZone_Cancel()
|
||||
{
|
||||
var canvas = Layouts.CustomLayouts.Find(x => x.Type == CustomLayout.Canvas.TypeToString());
|
||||
FancyZonesEditorHelper.ClickContextMenuItem(Session, canvas.Name, FancyZonesEditorHelper.ElementName.EditZones);
|
||||
Session.Find<Button>(By.AccessibilityId(AccessibilityId.NewZoneButton)).Click();
|
||||
Session.Find<Button>(ElementName.Cancel).Click();
|
||||
|
||||
// check the file
|
||||
var customLayouts = new CustomLayouts();
|
||||
var data = customLayouts.Read(customLayouts.File);
|
||||
var expected = customLayouts.CanvasFromJsonElement(canvas.Info.ToString());
|
||||
var actual = customLayouts.CanvasFromJsonElement(data.CustomLayouts.Find(x => x.Uuid == canvas.Uuid).Info.GetRawText());
|
||||
Assert.AreEqual(expected.Zones.Count, actual.Zones.Count);
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
public void Canvas_DeleteZone_Save()
|
||||
{
|
||||
var canvas = Layouts.CustomLayouts.Find(x => x.Type == CustomLayout.Canvas.TypeToString());
|
||||
FancyZonesEditorHelper.ClickContextMenuItem(Session, canvas.Name, FancyZonesEditorHelper.ElementName.EditZones);
|
||||
FancyZonesEditorHelper.ClickDeleteZone(Session, 1);
|
||||
Session.Find<Button>(ElementName.Save).Click();
|
||||
|
||||
// check the file
|
||||
var customLayouts = new CustomLayouts();
|
||||
var data = customLayouts.Read(customLayouts.File);
|
||||
var expected = customLayouts.CanvasFromJsonElement(canvas.Info.ToString());
|
||||
var actual = customLayouts.CanvasFromJsonElement(data.CustomLayouts.Find(x => x.Uuid == canvas.Uuid).Info.GetRawText());
|
||||
Assert.AreEqual(expected.Zones.Count - 1, actual.Zones.Count);
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
public void Canvas_DeleteZone_Cancel()
|
||||
{
|
||||
var canvas = Layouts.CustomLayouts.Find(x => x.Type == CustomLayout.Canvas.TypeToString());
|
||||
FancyZonesEditorHelper.ClickContextMenuItem(Session, canvas.Name, FancyZonesEditorHelper.ElementName.EditZones);
|
||||
FancyZonesEditorHelper.ClickDeleteZone(Session, 1);
|
||||
Session.Find<Button>(ElementName.Cancel).Click();
|
||||
|
||||
// check the file
|
||||
var customLayouts = new CustomLayouts();
|
||||
var data = customLayouts.Read(customLayouts.File);
|
||||
var expected = customLayouts.CanvasFromJsonElement(canvas.Info.ToString());
|
||||
var actual = customLayouts.CanvasFromJsonElement(data.CustomLayouts.Find(x => x.Uuid == canvas.Uuid).Info.GetRawText());
|
||||
Assert.AreEqual(expected.Zones.Count, actual.Zones.Count);
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
public void Canvas_MoveZone_Save()
|
||||
{
|
||||
int zoneNumber = 1;
|
||||
int xOffset = 100;
|
||||
int yOffset = 100;
|
||||
var canvas = Layouts.CustomLayouts.Find(x => x.Type == CustomLayout.Canvas.TypeToString());
|
||||
FancyZonesEditorHelper.ClickContextMenuItem(Session, canvas.Name, FancyZonesEditorHelper.ElementName.EditZones);
|
||||
|
||||
FancyZonesEditorHelper.GetZone(Session, zoneNumber, FancyZonesEditorHelper.ClassName.CanvasZone)?.Drag(xOffset, yOffset);
|
||||
Session.Find<Button>(ElementName.Save).Click();
|
||||
|
||||
// check the file
|
||||
var customLayouts = new CustomLayouts();
|
||||
var data = customLayouts.Read(customLayouts.File);
|
||||
var expected = customLayouts.CanvasFromJsonElement(canvas.Info.ToString());
|
||||
var actual = customLayouts.CanvasFromJsonElement(data.CustomLayouts.Find(x => x.Uuid == canvas.Uuid).Info.GetRawText());
|
||||
|
||||
// changed zone, exact offset may vary depending on screen resolution
|
||||
Assert.IsTrue(expected.Zones[zoneNumber - 1].X < actual.Zones[zoneNumber - 1].X, $"X: {expected.Zones[zoneNumber - 1].X} > {actual.Zones[zoneNumber - 1].X}");
|
||||
Assert.IsTrue(expected.Zones[zoneNumber - 1].Y < actual.Zones[zoneNumber - 1].Y, $"Y: {expected.Zones[zoneNumber - 1].Y} > {actual.Zones[zoneNumber - 1].Y}");
|
||||
Assert.AreEqual(expected.Zones[zoneNumber - 1].Width, actual.Zones[zoneNumber - 1].Width);
|
||||
Assert.AreEqual(expected.Zones[zoneNumber - 1].Height, actual.Zones[zoneNumber - 1].Height);
|
||||
|
||||
// other zones
|
||||
for (int i = 0; i < expected.Zones.Count; i++)
|
||||
{
|
||||
if (i != zoneNumber - 1)
|
||||
{
|
||||
Assert.AreEqual(expected.Zones[i].X, actual.Zones[i].X);
|
||||
Assert.AreEqual(expected.Zones[i].Y, actual.Zones[i].Y);
|
||||
Assert.AreEqual(expected.Zones[i].Width, actual.Zones[i].Width);
|
||||
Assert.AreEqual(expected.Zones[i].Height, actual.Zones[i].Height);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
public void Canvas_MoveZone_Cancel()
|
||||
{
|
||||
int zoneNumber = 1;
|
||||
var canvas = Layouts.CustomLayouts.Find(x => x.Type == CustomLayout.Canvas.TypeToString());
|
||||
FancyZonesEditorHelper.ClickContextMenuItem(Session, canvas.Name, FancyZonesEditorHelper.ElementName.EditZones);
|
||||
|
||||
FancyZonesEditorHelper.GetZone(Session, zoneNumber, FancyZonesEditorHelper.ClassName.CanvasZone)?.Drag(100, 100);
|
||||
Session.Find<Button>(ElementName.Cancel).Click();
|
||||
|
||||
// check the file
|
||||
var customLayouts = new CustomLayouts();
|
||||
var data = customLayouts.Read(customLayouts.File);
|
||||
var expected = customLayouts.CanvasFromJsonElement(canvas.Info.ToString());
|
||||
var actual = customLayouts.CanvasFromJsonElement(data.CustomLayouts.Find(x => x.Uuid == canvas.Uuid).Info.GetRawText());
|
||||
for (int i = 0; i < expected.Zones.Count; i++)
|
||||
{
|
||||
Assert.AreEqual(expected.Zones[i].X, actual.Zones[i].X);
|
||||
Assert.AreEqual(expected.Zones[i].Y, actual.Zones[i].Y);
|
||||
Assert.AreEqual(expected.Zones[i].Width, actual.Zones[i].Width);
|
||||
Assert.AreEqual(expected.Zones[i].Height, actual.Zones[i].Height);
|
||||
}
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
public void Canvas_ResizeZone_Save()
|
||||
{
|
||||
int zoneNumber = 1;
|
||||
int xOffset = 100;
|
||||
int yOffset = 100;
|
||||
var canvas = Layouts.CustomLayouts.Find(x => x.Type == CustomLayout.Canvas.TypeToString());
|
||||
FancyZonesEditorHelper.ClickContextMenuItem(Session, canvas.Name, FancyZonesEditorHelper.ElementName.EditZones);
|
||||
|
||||
FancyZonesEditorHelper.GetZone(Session, zoneNumber, FancyZonesEditorHelper.ClassName.CanvasZone)?.Find<Element>(By.AccessibilityId(FancyZonesEditorHelper.AccessibilityId.TopRightCorner)).Drag(xOffset, yOffset);
|
||||
Session.Find<Button>(ElementName.Save).Click();
|
||||
|
||||
// check the file
|
||||
var customLayouts = new CustomLayouts();
|
||||
var data = customLayouts.Read(customLayouts.File);
|
||||
var expected = customLayouts.CanvasFromJsonElement(canvas.Info.ToString());
|
||||
var actual = customLayouts.CanvasFromJsonElement(data.CustomLayouts.Find(x => x.Uuid == canvas.Uuid).Info.GetRawText());
|
||||
|
||||
// changed zone, exact offset may vary depending on screen resolution
|
||||
Assert.AreEqual(expected.Zones[zoneNumber - 1].X, actual.Zones[zoneNumber - 1].X);
|
||||
Assert.IsTrue(expected.Zones[zoneNumber - 1].Y < actual.Zones[zoneNumber - 1].Y, $"Y: {expected.Zones[zoneNumber - 1].Y} > {actual.Zones[zoneNumber - 1].Y}");
|
||||
Assert.IsTrue(expected.Zones[zoneNumber - 1].Width < actual.Zones[zoneNumber - 1].Width, $"Width: {expected.Zones[zoneNumber - 1].Width} < {actual.Zones[zoneNumber - 1].Width}");
|
||||
Assert.IsTrue(expected.Zones[zoneNumber - 1].Height > actual.Zones[zoneNumber - 1].Height, $"Height: {expected.Zones[zoneNumber - 1].Height} < {actual.Zones[zoneNumber - 1].Height}");
|
||||
|
||||
// other zones
|
||||
for (int i = 0; i < expected.Zones.Count; i++)
|
||||
{
|
||||
if (i != zoneNumber - 1)
|
||||
{
|
||||
Assert.AreEqual(expected.Zones[i].X, actual.Zones[i].X);
|
||||
Assert.AreEqual(expected.Zones[i].Y, actual.Zones[i].Y);
|
||||
Assert.AreEqual(expected.Zones[i].Width, actual.Zones[i].Width);
|
||||
Assert.AreEqual(expected.Zones[i].Height, actual.Zones[i].Height);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
public void Canvas_ResizeZone_Cancel()
|
||||
{
|
||||
int zoneNumber = 1;
|
||||
int xOffset = 100;
|
||||
int yOffset = 100;
|
||||
var canvas = Layouts.CustomLayouts.Find(x => x.Type == CustomLayout.Canvas.TypeToString());
|
||||
FancyZonesEditorHelper.ClickContextMenuItem(Session, canvas.Name, FancyZonesEditorHelper.ElementName.EditZones);
|
||||
|
||||
FancyZonesEditorHelper.GetZone(Session, zoneNumber, FancyZonesEditorHelper.ClassName.CanvasZone)?.Find<Element>(By.AccessibilityId(FancyZonesEditorHelper.AccessibilityId.TopRightCorner)).Drag(xOffset, yOffset);
|
||||
Session.Find<Button>(ElementName.Cancel).Click();
|
||||
|
||||
// check the file
|
||||
var customLayouts = new CustomLayouts();
|
||||
var data = customLayouts.Read(customLayouts.File);
|
||||
var expected = customLayouts.CanvasFromJsonElement(canvas.Info.ToString());
|
||||
var actual = customLayouts.CanvasFromJsonElement(data.CustomLayouts.Find(x => x.Uuid == canvas.Uuid).Info.GetRawText());
|
||||
|
||||
for (int i = 0; i < expected.Zones.Count; i++)
|
||||
{
|
||||
Assert.AreEqual(expected.Zones[i].X, actual.Zones[i].X);
|
||||
Assert.AreEqual(expected.Zones[i].Y, actual.Zones[i].Y);
|
||||
Assert.AreEqual(expected.Zones[i].Width, actual.Zones[i].Width);
|
||||
Assert.AreEqual(expected.Zones[i].Height, actual.Zones[i].Height);
|
||||
}
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
public void Grid_SplitZone_Save()
|
||||
{
|
||||
int zoneNumber = 1;
|
||||
var grid = Layouts.CustomLayouts.Find(x => x.Type == CustomLayout.Grid.TypeToString());
|
||||
FancyZonesEditorHelper.ClickContextMenuItem(Session, grid.Name, FancyZonesEditorHelper.ElementName.EditZones);
|
||||
|
||||
FancyZonesEditorHelper.GetZone(Session, zoneNumber, FancyZonesEditorHelper.ClassName.GridZone)?.Click(); // horizontal split in the middle of the zone
|
||||
Session.Find<Button>(ElementName.Save).Click();
|
||||
|
||||
// check the file
|
||||
var customLayouts = new CustomLayouts();
|
||||
var data = customLayouts.Read(customLayouts.File);
|
||||
var expected = customLayouts.GridFromJsonElement(grid.Info.ToString());
|
||||
var actual = customLayouts.GridFromJsonElement(data.CustomLayouts.Find(x => x.Uuid == grid.Uuid).Info.GetRawText());
|
||||
|
||||
// new column added
|
||||
Assert.AreEqual(expected.Columns + 1, actual.Columns);
|
||||
Assert.AreEqual(expected.ColumnsPercentage[0], actual.ColumnsPercentage[0] + actual.ColumnsPercentage[1]);
|
||||
Assert.AreEqual(expected.ColumnsPercentage[1], actual.ColumnsPercentage[2]);
|
||||
|
||||
// rows are not changed
|
||||
Assert.AreEqual(expected.Rows, actual.Rows);
|
||||
for (int i = 0; i < expected.Rows; i++)
|
||||
{
|
||||
Assert.AreEqual(expected.RowsPercentage[i], actual.RowsPercentage[i]);
|
||||
}
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
public void Grid_SplitZone_Cancel()
|
||||
{
|
||||
int zoneNumber = 1;
|
||||
var grid = Layouts.CustomLayouts.Find(x => x.Type == CustomLayout.Grid.TypeToString());
|
||||
FancyZonesEditorHelper.ClickContextMenuItem(Session, grid.Name, FancyZonesEditorHelper.ElementName.EditZones);
|
||||
|
||||
FancyZonesEditorHelper.GetZone(Session, zoneNumber, FancyZonesEditorHelper.ClassName.GridZone)?.Click(); // horizontal split in the middle of the zone
|
||||
Session.Find<Button>(ElementName.Cancel).Click();
|
||||
|
||||
// check the file
|
||||
var customLayouts = new CustomLayouts();
|
||||
var data = customLayouts.Read(customLayouts.File);
|
||||
var expected = customLayouts.GridFromJsonElement(grid.Info.ToString());
|
||||
var actual = customLayouts.GridFromJsonElement(data.CustomLayouts.Find(x => x.Uuid == grid.Uuid).Info.GetRawText());
|
||||
|
||||
// columns are not changed
|
||||
Assert.AreEqual(expected.Columns, actual.Columns);
|
||||
for (int i = 0; i < expected.Columns; i++)
|
||||
{
|
||||
Assert.AreEqual(expected.ColumnsPercentage[i], actual.ColumnsPercentage[i]);
|
||||
}
|
||||
|
||||
// rows are not changed
|
||||
Assert.AreEqual(expected.Rows, actual.Rows);
|
||||
for (int i = 0; i < expected.Rows; i++)
|
||||
{
|
||||
Assert.AreEqual(expected.RowsPercentage[i], actual.RowsPercentage[i]);
|
||||
}
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
public void Grid_MergeZones_Save()
|
||||
{
|
||||
var grid = Layouts.CustomLayouts.Find(x => x.Type == CustomLayout.Grid.TypeToString());
|
||||
FancyZonesEditorHelper.ClickContextMenuItem(Session, grid.Name, FancyZonesEditorHelper.ElementName.EditZones);
|
||||
|
||||
FancyZonesEditorHelper.MergeGridZones(Session, 1, 2);
|
||||
Session.Find<Button>(ElementName.Save).Click();
|
||||
|
||||
// check the file
|
||||
var customLayouts = new CustomLayouts();
|
||||
var data = customLayouts.Read(customLayouts.File);
|
||||
var expected = customLayouts.GridFromJsonElement(grid.Info.ToString());
|
||||
var actual = customLayouts.GridFromJsonElement(data.CustomLayouts.Find(x => x.Uuid == grid.Uuid).Info.GetRawText());
|
||||
|
||||
// columns are not changed
|
||||
Assert.AreEqual(expected.Columns, actual.Columns);
|
||||
for (int i = 0; i < expected.Columns; i++)
|
||||
{
|
||||
Assert.AreEqual(expected.ColumnsPercentage[i], actual.ColumnsPercentage[i]);
|
||||
}
|
||||
|
||||
// rows are not changed
|
||||
Assert.AreEqual(expected.Rows, actual.Rows);
|
||||
for (int i = 0; i < expected.Rows; i++)
|
||||
{
|
||||
Assert.AreEqual(expected.RowsPercentage[i], actual.RowsPercentage[i]);
|
||||
}
|
||||
|
||||
// cells are updated to [0,0][1,2]
|
||||
Assert.IsTrue(actual.CellChildMap[0].SequenceEqual([0, 0]));
|
||||
Assert.IsTrue(actual.CellChildMap[1].SequenceEqual([1, 2]));
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
public void Grid_MergeZones_Cancel()
|
||||
{
|
||||
var grid = Layouts.CustomLayouts.Find(x => x.Type == CustomLayout.Grid.TypeToString());
|
||||
FancyZonesEditorHelper.ClickContextMenuItem(Session, grid.Name, FancyZonesEditorHelper.ElementName.EditZones);
|
||||
|
||||
FancyZonesEditorHelper.MergeGridZones(Session, 1, 2);
|
||||
Session.Find<Button>(ElementName.Cancel).Click();
|
||||
|
||||
// check the file
|
||||
var customLayouts = new CustomLayouts();
|
||||
var data = customLayouts.Read(customLayouts.File);
|
||||
var expected = customLayouts.GridFromJsonElement(grid.Info.ToString());
|
||||
var actual = customLayouts.GridFromJsonElement(data.CustomLayouts.Find(x => x.Uuid == grid.Uuid).Info.GetRawText());
|
||||
|
||||
// columns are not changed
|
||||
Assert.AreEqual(expected.Columns, actual.Columns);
|
||||
for (int i = 0; i < expected.Columns; i++)
|
||||
{
|
||||
Assert.AreEqual(expected.ColumnsPercentage[i], actual.ColumnsPercentage[i]);
|
||||
}
|
||||
|
||||
// rows are not changed
|
||||
Assert.AreEqual(expected.Rows, actual.Rows);
|
||||
for (int i = 0; i < expected.Rows; i++)
|
||||
{
|
||||
Assert.AreEqual(expected.RowsPercentage[i], actual.RowsPercentage[i]);
|
||||
}
|
||||
|
||||
// cells are not changed
|
||||
for (int i = 0; i < expected.CellChildMap.Length; i++)
|
||||
{
|
||||
Assert.IsTrue(actual.CellChildMap[i].SequenceEqual(expected.CellChildMap[i]));
|
||||
}
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
public void Grid_MoveSplitter_Save()
|
||||
{
|
||||
EditorParameters editorParameters = new EditorParameters();
|
||||
ParamsWrapper parameters = new ParamsWrapper
|
||||
{
|
||||
ProcessId = 1,
|
||||
SpanZonesAcrossMonitors = false,
|
||||
Monitors = new List<NativeMonitorDataWrapper>
|
||||
{
|
||||
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 = 780,
|
||||
WorkAreaWidth = 1240,
|
||||
MonitorHeight = 780,
|
||||
MonitorWidth = 1240,
|
||||
IsSelected = true,
|
||||
},
|
||||
},
|
||||
};
|
||||
FancyZonesEditorHelper.Files.ParamsIOHelper.WriteData(editorParameters.Serialize(parameters));
|
||||
this.RestartScopeExe();
|
||||
|
||||
var grid = Layouts.CustomLayouts.Find(x => x.Type == CustomLayout.Grid.TypeToString() && x.Name == "Grid-9");
|
||||
FancyZonesEditorHelper.ClickContextMenuItem(Session, grid.Name, FancyZonesEditorHelper.ElementName.EditZones);
|
||||
|
||||
FancyZonesEditorHelper.MoveSplitter(Session, 2, -50, 0);
|
||||
Session.Find<Button>(ElementName.Save).Click();
|
||||
|
||||
// check the file
|
||||
var customLayouts = new CustomLayouts();
|
||||
var data = customLayouts.Read(customLayouts.File);
|
||||
var expected = customLayouts.GridFromJsonElement(grid.Info.ToString());
|
||||
var actual = customLayouts.GridFromJsonElement(data.CustomLayouts.Find(x => x.Uuid == grid.Uuid).Info.GetRawText());
|
||||
|
||||
// rows are not changed
|
||||
Assert.AreEqual(expected.Rows, actual.Rows);
|
||||
for (int i = 0; i < expected.Rows; i++)
|
||||
{
|
||||
Assert.AreEqual(expected.RowsPercentage[i], actual.RowsPercentage[i]);
|
||||
}
|
||||
|
||||
// Columns are changed
|
||||
Assert.AreEqual(expected.Columns, actual.Columns);
|
||||
Assert.IsTrue(expected.ColumnsPercentage[0] > actual.ColumnsPercentage[0], $"{expected.ColumnsPercentage[0]} > {actual.ColumnsPercentage[0]}");
|
||||
Assert.IsTrue(expected.ColumnsPercentage[1] < actual.ColumnsPercentage[1], $"{expected.ColumnsPercentage[1]} < {actual.ColumnsPercentage[1]}");
|
||||
Assert.AreEqual(expected.ColumnsPercentage[2], actual.ColumnsPercentage[2], $"{expected.ColumnsPercentage[2]} == {actual.ColumnsPercentage[2]}");
|
||||
|
||||
// cells are not changed
|
||||
for (int i = 0; i < expected.CellChildMap.Length; i++)
|
||||
{
|
||||
Assert.IsTrue(actual.CellChildMap[i].SequenceEqual(expected.CellChildMap[i]));
|
||||
}
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
public void Grid_MoveSplitter_Cancel()
|
||||
{
|
||||
var grid = Layouts.CustomLayouts.Find(x => x.Type == CustomLayout.Grid.TypeToString() && x.Name == "Grid-9");
|
||||
FancyZonesEditorHelper.ClickContextMenuItem(Session, grid.Name, FancyZonesEditorHelper.ElementName.EditZones);
|
||||
|
||||
FancyZonesEditorHelper.MoveSplitter(Session, 2, -100, 0);
|
||||
Session.Find<Button>(ElementName.Cancel).Click();
|
||||
|
||||
// check the file
|
||||
var customLayouts = new CustomLayouts();
|
||||
var data = customLayouts.Read(customLayouts.File);
|
||||
var expected = customLayouts.GridFromJsonElement(grid.Info.ToString());
|
||||
var actual = customLayouts.GridFromJsonElement(data.CustomLayouts.Find(x => x.Uuid == grid.Uuid).Info.GetRawText());
|
||||
|
||||
// columns are not changed
|
||||
Assert.AreEqual(expected.Columns, actual.Columns);
|
||||
for (int i = 0; i < expected.Columns; i++)
|
||||
{
|
||||
Assert.AreEqual(expected.ColumnsPercentage[i], actual.ColumnsPercentage[i]);
|
||||
}
|
||||
|
||||
// rows are not changed
|
||||
Assert.AreEqual(expected.Rows, actual.Rows);
|
||||
for (int i = 0; i < expected.Rows; i++)
|
||||
{
|
||||
Assert.AreEqual(expected.RowsPercentage[i], actual.RowsPercentage[i]);
|
||||
}
|
||||
|
||||
// cells are not changed
|
||||
for (int i = 0; i < expected.CellChildMap.Length; i++)
|
||||
{
|
||||
Assert.IsTrue(actual.CellChildMap[i].SequenceEqual(expected.CellChildMap[i]));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,157 @@
|
||||
// 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 System.Windows.Forms;
|
||||
using System.Xml.Linq;
|
||||
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 ModernWpf.Controls;
|
||||
using Windows.UI;
|
||||
using static FancyZonesEditorCommon.Data.EditorParameters;
|
||||
using static Microsoft.ApplicationInsights.MetricDimensionNames.TelemetryContext;
|
||||
using static Microsoft.FancyZonesEditor.UnitTests.Utils.FancyZonesEditorHelper;
|
||||
|
||||
namespace Microsoft.FancyZonesEditor.UITests
|
||||
{
|
||||
[TestClass]
|
||||
public class FirstLunchTest : UITestBase
|
||||
{
|
||||
public FirstLunchTest()
|
||||
: base(PowerToysModule.FancyZone)
|
||||
{
|
||||
}
|
||||
|
||||
[TestInitialize]
|
||||
public void TestInitialize()
|
||||
{
|
||||
EditorParameters editorParameters = new EditorParameters();
|
||||
ParamsWrapper parameters = new ParamsWrapper
|
||||
{
|
||||
ProcessId = 1,
|
||||
SpanZonesAcrossMonitors = false,
|
||||
Monitors = new List<NativeMonitorDataWrapper>
|
||||
{
|
||||
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));
|
||||
|
||||
DefaultLayouts defaultLayouts = new DefaultLayouts();
|
||||
DefaultLayouts.DefaultLayoutsListWrapper defaultLayoutsListWrapper = new DefaultLayouts.DefaultLayoutsListWrapper
|
||||
{
|
||||
DefaultLayouts = new List<DefaultLayouts.DefaultLayoutWrapper> { },
|
||||
};
|
||||
FancyZonesEditorHelper.Files.DefaultLayoutsIOHelper.WriteData(defaultLayouts.Serialize(defaultLayoutsListWrapper));
|
||||
|
||||
LayoutHotkeys layoutHotkeys = new LayoutHotkeys();
|
||||
LayoutHotkeys.LayoutHotkeysWrapper layoutHotkeysWrapper = new LayoutHotkeys.LayoutHotkeysWrapper
|
||||
{
|
||||
LayoutHotkeys = new List<LayoutHotkeys.LayoutHotkeyWrapper> { },
|
||||
};
|
||||
FancyZonesEditorHelper.Files.LayoutHotkeysIOHelper.WriteData(layoutHotkeys.Serialize(layoutHotkeysWrapper));
|
||||
|
||||
AppliedLayouts appliedLayouts = new AppliedLayouts();
|
||||
AppliedLayouts.AppliedLayoutsListWrapper appliedLayoutsWrapper = new AppliedLayouts.AppliedLayoutsListWrapper
|
||||
{
|
||||
AppliedLayouts = new List<AppliedLayouts.AppliedLayoutWrapper> { },
|
||||
};
|
||||
FancyZonesEditorHelper.Files.AppliedLayoutsIOHelper.WriteData(appliedLayouts.Serialize(appliedLayoutsWrapper));
|
||||
|
||||
CustomLayouts customLayouts = new CustomLayouts();
|
||||
CustomLayouts.CustomLayoutListWrapper customLayoutListWrapper = new CustomLayouts.CustomLayoutListWrapper
|
||||
{
|
||||
CustomLayouts = new List<CustomLayouts.CustomLayoutWrapper> { },
|
||||
};
|
||||
FancyZonesEditorHelper.Files.CustomLayoutsIOHelper.WriteData(customLayouts.Serialize(customLayoutListWrapper));
|
||||
|
||||
LayoutTemplates layoutTemplates = new LayoutTemplates();
|
||||
LayoutTemplates.TemplateLayoutsListWrapper templateLayoutsListWrapper = new LayoutTemplates.TemplateLayoutsListWrapper
|
||||
{
|
||||
LayoutTemplates = new List<LayoutTemplates.TemplateLayoutWrapper>
|
||||
{
|
||||
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));
|
||||
|
||||
// verify editor opens without errors
|
||||
this.RestartScopeExe();
|
||||
}
|
||||
|
||||
[TestCleanup]
|
||||
public void TestCleanup()
|
||||
{
|
||||
FancyZonesEditorHelper.Files.Restore();
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
public void FirstLaunch()
|
||||
{
|
||||
Session.Find<Element>(By.AccessibilityId(FancyZonesEditorHelper.AccessibilityId.MainWindow)).Click();
|
||||
Assert.IsNotNull(Session.Find<Element>(By.AccessibilityId(FancyZonesEditorHelper.AccessibilityId.MainWindow)));
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,468 @@
|
||||
// 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 System.Globalization;
|
||||
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 static FancyZonesEditorCommon.Data.CustomLayouts;
|
||||
using static FancyZonesEditorCommon.Data.EditorParameters;
|
||||
using static FancyZonesEditorCommon.Data.LayoutHotkeys;
|
||||
using static Microsoft.FancyZonesEditor.UnitTests.Utils.FancyZonesEditorHelper;
|
||||
|
||||
namespace Microsoft.FancyZonesEditor.UITests
|
||||
{
|
||||
[TestClass]
|
||||
public class LayoutHotkeysTests : UITestBase
|
||||
{
|
||||
public LayoutHotkeysTests()
|
||||
: base(PowerToysModule.FancyZone)
|
||||
{
|
||||
}
|
||||
|
||||
private static readonly CustomLayoutListWrapper CustomLayouts = new CustomLayoutListWrapper
|
||||
{
|
||||
CustomLayouts = new List<CustomLayoutWrapper>
|
||||
{
|
||||
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<CanvasInfoWrapper.CanvasZoneWrapper> { },
|
||||
}),
|
||||
},
|
||||
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<CanvasInfoWrapper.CanvasZoneWrapper> { },
|
||||
}),
|
||||
},
|
||||
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<CanvasInfoWrapper.CanvasZoneWrapper> { },
|
||||
}),
|
||||
},
|
||||
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<CanvasInfoWrapper.CanvasZoneWrapper> { },
|
||||
}),
|
||||
},
|
||||
},
|
||||
};
|
||||
|
||||
private static readonly LayoutHotkeysWrapper Hotkeys = new LayoutHotkeysWrapper
|
||||
{
|
||||
LayoutHotkeys = new List<LayoutHotkeyWrapper>
|
||||
{
|
||||
new LayoutHotkeyWrapper
|
||||
{
|
||||
LayoutId = "{0D6D2F58-9184-4804-81E4-4E4CC3476DC1}",
|
||||
Key = 0,
|
||||
},
|
||||
new LayoutHotkeyWrapper
|
||||
{
|
||||
LayoutId = "{E7807D0D-6223-4883-B15B-1F3883944C09}",
|
||||
Key = 1,
|
||||
},
|
||||
},
|
||||
};
|
||||
|
||||
[TestInitialize]
|
||||
public void TestInitialize()
|
||||
{
|
||||
EditorParameters editorParameters = new EditorParameters();
|
||||
ParamsWrapper parameters = new ParamsWrapper
|
||||
{
|
||||
ProcessId = 1,
|
||||
SpanZonesAcrossMonitors = false,
|
||||
Monitors = new List<NativeMonitorDataWrapper>
|
||||
{
|
||||
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));
|
||||
|
||||
CustomLayouts customLayouts = new CustomLayouts();
|
||||
FancyZonesEditorHelper.Files.CustomLayoutsIOHelper.WriteData(customLayouts.Serialize(CustomLayouts));
|
||||
|
||||
var layoutHotkeys = new LayoutHotkeys();
|
||||
FancyZonesEditorHelper.Files.LayoutHotkeysIOHelper.WriteData(layoutHotkeys.Serialize(Hotkeys));
|
||||
|
||||
LayoutTemplates layoutTemplates = new LayoutTemplates();
|
||||
LayoutTemplates.TemplateLayoutsListWrapper templateLayoutsListWrapper = new LayoutTemplates.TemplateLayoutsListWrapper
|
||||
{
|
||||
LayoutTemplates = new List<LayoutTemplates.TemplateLayoutWrapper>
|
||||
{
|
||||
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));
|
||||
|
||||
DefaultLayouts defaultLayouts = new DefaultLayouts();
|
||||
DefaultLayouts.DefaultLayoutsListWrapper defaultLayoutsListWrapper = new DefaultLayouts.DefaultLayoutsListWrapper
|
||||
{
|
||||
DefaultLayouts = new List<DefaultLayouts.DefaultLayoutWrapper> { },
|
||||
};
|
||||
FancyZonesEditorHelper.Files.DefaultLayoutsIOHelper.WriteData(defaultLayouts.Serialize(defaultLayoutsListWrapper));
|
||||
|
||||
AppliedLayouts appliedLayouts = new AppliedLayouts();
|
||||
AppliedLayouts.AppliedLayoutsListWrapper appliedLayoutsWrapper = new AppliedLayouts.AppliedLayoutsListWrapper
|
||||
{
|
||||
AppliedLayouts = new List<AppliedLayouts.AppliedLayoutWrapper> { },
|
||||
};
|
||||
FancyZonesEditorHelper.Files.AppliedLayoutsIOHelper.WriteData(appliedLayouts.Serialize(appliedLayoutsWrapper));
|
||||
|
||||
this.RestartScopeExe();
|
||||
}
|
||||
|
||||
[TestCleanup]
|
||||
public void TestCleanup()
|
||||
{
|
||||
FancyZonesEditorHelper.Files.Restore();
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
public void Initialize()
|
||||
{
|
||||
foreach (var layout in CustomLayouts.CustomLayouts)
|
||||
{
|
||||
Session.Find<Element>(layout.Name).Find<Button>(By.AccessibilityId(AccessibilityId.EditLayoutButton)).Click();
|
||||
|
||||
var hotkeyComboBox = Session.Find<Element>(By.AccessibilityId(AccessibilityId.HotkeyComboBox));
|
||||
Assert.IsNotNull(hotkeyComboBox);
|
||||
|
||||
// verify the selected key
|
||||
string expected = "None";
|
||||
if (Hotkeys.LayoutHotkeys.Any(x => x.LayoutId == layout.Uuid))
|
||||
{
|
||||
expected = $"{Hotkeys.LayoutHotkeys.Find(x => x.LayoutId == layout.Uuid).Key}";
|
||||
}
|
||||
|
||||
Assert.AreEqual($"{expected}", hotkeyComboBox.Text);
|
||||
|
||||
// verify the available values
|
||||
hotkeyComboBox.Click();
|
||||
|
||||
var popup = Session.Find<Element>(By.ClassName(ClassName.Popup));
|
||||
Assert.IsNotNull(popup, "Hotkey combo box wasn't opened");
|
||||
|
||||
try
|
||||
{
|
||||
popup.Find<Element>(expected); // the current value should be available
|
||||
|
||||
// 0 and 1 are assigned, all others should be available
|
||||
for (int i = 2; i < 10; i++)
|
||||
{
|
||||
popup.Find<Element>($"{i}");
|
||||
}
|
||||
}
|
||||
catch
|
||||
{
|
||||
Assert.Fail("Hotkey is missed");
|
||||
}
|
||||
|
||||
Session.Find<Button>(ElementName.Cancel).DoubleClick();
|
||||
}
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
public void Assign_Save()
|
||||
{
|
||||
var layout = CustomLayouts.CustomLayouts[2]; // a layout without assigned hotkey
|
||||
Session.Find<Element>(layout.Name).Find<Button>(By.AccessibilityId(AccessibilityId.EditLayoutButton)).Click();
|
||||
|
||||
// assign hotkey
|
||||
const string key = "3";
|
||||
var hotkeyComboBox = Session.Find<Element>(By.AccessibilityId(AccessibilityId.HotkeyComboBox));
|
||||
Assert.IsNotNull(hotkeyComboBox);
|
||||
hotkeyComboBox.Click();
|
||||
|
||||
var popup = Session.Find<Element>(By.ClassName(ClassName.Popup));
|
||||
Assert.IsNotNull(popup);
|
||||
|
||||
popup.Find<Element>($"{key}").Click(); // assign a free hotkey
|
||||
Assert.AreEqual(key, hotkeyComboBox.Text);
|
||||
|
||||
// verify the file
|
||||
Session.Find<Button>(ElementName.Save).Click();
|
||||
var hotkeys = new LayoutHotkeys();
|
||||
var actualData = hotkeys.Read(hotkeys.File);
|
||||
Assert.IsTrue(actualData.LayoutHotkeys.Contains(new LayoutHotkeyWrapper { Key = int.Parse(key, CultureInfo.InvariantCulture), LayoutId = layout.Uuid }));
|
||||
|
||||
// verify the availability
|
||||
Session.Find<Element>(CustomLayouts.CustomLayouts[3].Name).Find<Button>(By.AccessibilityId(AccessibilityId.EditLayoutButton)).Click();
|
||||
hotkeyComboBox = Session.Find<Element>(By.AccessibilityId(AccessibilityId.HotkeyComboBox));
|
||||
Assert.IsNotNull(hotkeyComboBox);
|
||||
hotkeyComboBox.Click();
|
||||
|
||||
popup = Session.Find<Element>(By.ClassName(ClassName.Popup));
|
||||
Assert.IsNotNull(popup);
|
||||
try
|
||||
{
|
||||
popup.Find<Element>($"{key}"); // verify the key is not available
|
||||
Assert.Fail($"{key} The assigned key is still available for other layouts.");
|
||||
}
|
||||
catch
|
||||
{
|
||||
// key not found as expected
|
||||
}
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
public void Assign_Cancel()
|
||||
{
|
||||
var layout = CustomLayouts.CustomLayouts[2]; // a layout without assigned hotkey
|
||||
Session.Find<Element>(layout.Name).Find<Button>(By.AccessibilityId(AccessibilityId.EditLayoutButton)).Click();
|
||||
|
||||
// assign a hotkey
|
||||
const string key = "3";
|
||||
var hotkeyComboBox = Session.Find<Element>(By.AccessibilityId(AccessibilityId.HotkeyComboBox));
|
||||
Assert.IsNotNull(hotkeyComboBox);
|
||||
hotkeyComboBox.Click();
|
||||
var popup = Session.Find<Element>(By.ClassName(ClassName.Popup));
|
||||
Assert.IsNotNull(popup);
|
||||
popup.Find<Element>($"{key}").Click();
|
||||
Assert.AreEqual(key, hotkeyComboBox.Text);
|
||||
|
||||
// verify the file
|
||||
Session.Find<Button>(ElementName.Cancel).Click();
|
||||
var hotkeys = new LayoutHotkeys();
|
||||
var actualData = hotkeys.Read(hotkeys.File);
|
||||
Assert.AreEqual(Hotkeys.ToString(), actualData.ToString());
|
||||
|
||||
// verify the availability
|
||||
Session.Find<Element>(CustomLayouts.CustomLayouts[3].Name).Find<Button>(By.AccessibilityId(AccessibilityId.EditLayoutButton)).Click();
|
||||
hotkeyComboBox = Session.Find<Element>(By.AccessibilityId(AccessibilityId.HotkeyComboBox));
|
||||
Assert.IsNotNull(hotkeyComboBox);
|
||||
hotkeyComboBox.Click();
|
||||
popup = Session.Find<Element>(By.ClassName(ClassName.Popup));
|
||||
Assert.IsNotNull(popup);
|
||||
try
|
||||
{
|
||||
popup.Find<Element>($"{key}"); // verify the key is available
|
||||
}
|
||||
catch
|
||||
{
|
||||
Assert.Fail("The key is not available for other layouts.");
|
||||
}
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
public void Assign_AllPossibleValues()
|
||||
{
|
||||
for (int i = 0; i < 4; i++)
|
||||
{
|
||||
string layoutName = $"Layout {i}";
|
||||
Session.Find<Element>(layoutName).Find<Button>(By.AccessibilityId(AccessibilityId.EditLayoutButton)).Click();
|
||||
|
||||
var hotkeyComboBox = Session.Find<Element>(By.AccessibilityId(AccessibilityId.HotkeyComboBox));
|
||||
Assert.IsNotNull(hotkeyComboBox);
|
||||
hotkeyComboBox.Click();
|
||||
var popup = Session.Find<Element>(By.ClassName(ClassName.Popup));
|
||||
Assert.IsNotNull(popup);
|
||||
popup.Find<Element>($"{i}").Click();
|
||||
|
||||
Session.Find<Button>(ElementName.Save).Click();
|
||||
}
|
||||
|
||||
// check there nothing except None
|
||||
{
|
||||
int layout = 3;
|
||||
string layoutName = $"Layout {layout}";
|
||||
Session.Find<Element>(layoutName).Find<Button>(By.AccessibilityId(AccessibilityId.EditLayoutButton)).Click();
|
||||
var hotkeyComboBox = Session.Find<Element>(By.AccessibilityId(AccessibilityId.HotkeyComboBox));
|
||||
Assert.IsNotNull(hotkeyComboBox);
|
||||
hotkeyComboBox.Click();
|
||||
var popup = Session.Find<Element>(By.ClassName(ClassName.Popup));
|
||||
Assert.IsNotNull(popup);
|
||||
|
||||
for (int i = 0; i < 10; i++)
|
||||
{
|
||||
try
|
||||
{
|
||||
popup.Find<Element>($"{i}");
|
||||
Assert.Fail("The assigned key is still available for other layouts.");
|
||||
}
|
||||
catch
|
||||
{
|
||||
}
|
||||
}
|
||||
|
||||
popup.Find<Element>($"None").Click();
|
||||
Session.Find<Button>(ElementName.Save).Click();
|
||||
}
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
public void Reset_Save()
|
||||
{
|
||||
var layout = CustomLayouts.CustomLayouts[0]; // a layout with assigned hotkey
|
||||
int assignedKey = Hotkeys.LayoutHotkeys.Find(x => x.LayoutId == layout.Uuid).Key;
|
||||
Session.Find<Element>(layout.Name).Find<Button>(By.AccessibilityId(AccessibilityId.EditLayoutButton)).Click();
|
||||
const string None = "None";
|
||||
|
||||
// reset the hotkey
|
||||
var hotkeyComboBox = Session.Find<Element>(By.AccessibilityId(AccessibilityId.HotkeyComboBox));
|
||||
Assert.IsNotNull(hotkeyComboBox);
|
||||
hotkeyComboBox.Click();
|
||||
var popup = Session.Find<Element>(By.ClassName(ClassName.Popup));
|
||||
Assert.IsNotNull(popup);
|
||||
popup.Find<Element>(None).Click();
|
||||
Assert.AreEqual(None, hotkeyComboBox.Text);
|
||||
|
||||
// verify the file
|
||||
Session.Find<Button>(ElementName.Save).Click();
|
||||
var hotkeys = new LayoutHotkeys();
|
||||
var actualData = hotkeys.Read(hotkeys.File);
|
||||
Assert.IsFalse(actualData.LayoutHotkeys.Contains(new LayoutHotkeyWrapper { Key = assignedKey, LayoutId = layout.Uuid }));
|
||||
|
||||
// verify the previously assigned key is available
|
||||
Session.Find<Element>(CustomLayouts.CustomLayouts[3].Name).Find<Button>(By.AccessibilityId(AccessibilityId.EditLayoutButton)).Click();
|
||||
hotkeyComboBox = Session.Find<Element>(By.AccessibilityId(AccessibilityId.HotkeyComboBox));
|
||||
Assert.IsNotNull(hotkeyComboBox);
|
||||
hotkeyComboBox.Click();
|
||||
popup = Session.Find<Element>(By.ClassName(ClassName.Popup));
|
||||
Assert.IsNotNull(popup);
|
||||
try
|
||||
{
|
||||
popup.Find<Element>($"{assignedKey}"); // verify the key is available
|
||||
}
|
||||
catch
|
||||
{
|
||||
Assert.Fail("The key is not available for other layouts.");
|
||||
}
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
public void Reset_Cancel()
|
||||
{
|
||||
var layout = CustomLayouts.CustomLayouts[0]; // a layout with assigned hotkey
|
||||
int assignedKey = Hotkeys.LayoutHotkeys.Find(x => x.LayoutId == layout.Uuid).Key;
|
||||
Session.Find<Element>(layout.Name).Find<Button>(By.AccessibilityId(AccessibilityId.EditLayoutButton)).Click();
|
||||
const string None = "None";
|
||||
|
||||
// assign hotkey
|
||||
var hotkeyComboBox = Session.Find<Element>(By.AccessibilityId(AccessibilityId.HotkeyComboBox));
|
||||
Assert.IsNotNull(hotkeyComboBox);
|
||||
hotkeyComboBox.Click();
|
||||
var popup = Session.Find<Element>(By.ClassName(ClassName.Popup));
|
||||
Assert.IsNotNull(popup);
|
||||
popup.Find<Element>(None).Click(); // reset the hotkey
|
||||
Assert.AreEqual(None, hotkeyComboBox.Text);
|
||||
|
||||
// verify the file
|
||||
Session.Find<Button>(ElementName.Cancel).Click();
|
||||
var hotkeys = new LayoutHotkeys();
|
||||
var actualData = hotkeys.Read(hotkeys.File);
|
||||
Assert.IsTrue(actualData.LayoutHotkeys.Contains(new LayoutHotkeyWrapper { Key = assignedKey, LayoutId = layout.Uuid }));
|
||||
|
||||
// verify the previously assigned key is not available
|
||||
Session.Find<Element>(CustomLayouts.CustomLayouts[3].Name).Find<Button>(By.AccessibilityId(AccessibilityId.EditLayoutButton)).Click();
|
||||
hotkeyComboBox = Session.Find<Element>(By.AccessibilityId(AccessibilityId.HotkeyComboBox));
|
||||
Assert.IsNotNull(hotkeyComboBox);
|
||||
hotkeyComboBox.Click();
|
||||
popup = Session.Find<Element>(By.ClassName(ClassName.Popup));
|
||||
Assert.IsNotNull(popup);
|
||||
try
|
||||
{
|
||||
popup.Find<Element>($"{assignedKey}"); // verify the key is not available
|
||||
Assert.Fail("The key is still available for other layouts.");
|
||||
}
|
||||
catch
|
||||
{
|
||||
// the key is not available as expected
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,153 @@
|
||||
// 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 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.EditorParameters;
|
||||
|
||||
namespace Microsoft.FancyZonesEditor.UITests
|
||||
{
|
||||
[TestClass]
|
||||
public class NewFancyZonesEditorTest
|
||||
{
|
||||
public NewFancyZonesEditorTest()
|
||||
{
|
||||
// FancyZonesEditorHelper.InitFancyZonesLayout();
|
||||
}
|
||||
|
||||
[TestClass]
|
||||
public class TestCaseFirstLaunch : UITestBase
|
||||
{
|
||||
public TestCaseFirstLaunch()
|
||||
: base(PowerToysModule.FancyZone)
|
||||
{
|
||||
}
|
||||
|
||||
[TestInitialize]
|
||||
public void TestInitialize()
|
||||
{
|
||||
EditorParameters editorParameters = new EditorParameters();
|
||||
ParamsWrapper parameters = new ParamsWrapper
|
||||
{
|
||||
ProcessId = 1,
|
||||
SpanZonesAcrossMonitors = false,
|
||||
Monitors = new List<NativeMonitorDataWrapper>
|
||||
{
|
||||
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));
|
||||
|
||||
// files not yet exist
|
||||
DefaultLayouts defaultLayouts = new DefaultLayouts();
|
||||
DefaultLayouts.DefaultLayoutsListWrapper defaultLayoutsListWrapper = new DefaultLayouts.DefaultLayoutsListWrapper
|
||||
{
|
||||
DefaultLayouts = new List<DefaultLayouts.DefaultLayoutWrapper> { },
|
||||
};
|
||||
FancyZonesEditorHelper.Files.DefaultLayoutsIOHelper.WriteData(defaultLayouts.Serialize(defaultLayoutsListWrapper));
|
||||
|
||||
LayoutHotkeys layoutHotkeys = new LayoutHotkeys();
|
||||
LayoutHotkeys.LayoutHotkeysWrapper layoutHotkeysWrapper = new LayoutHotkeys.LayoutHotkeysWrapper
|
||||
{
|
||||
LayoutHotkeys = new List<LayoutHotkeys.LayoutHotkeyWrapper> { },
|
||||
};
|
||||
FancyZonesEditorHelper.Files.LayoutHotkeysIOHelper.WriteData(layoutHotkeys.Serialize(layoutHotkeysWrapper));
|
||||
|
||||
AppliedLayouts appliedLayouts = new AppliedLayouts();
|
||||
AppliedLayouts.AppliedLayoutsListWrapper appliedLayoutsWrapper = new AppliedLayouts.AppliedLayoutsListWrapper
|
||||
{
|
||||
AppliedLayouts = new List<AppliedLayouts.AppliedLayoutWrapper> { },
|
||||
};
|
||||
FancyZonesEditorHelper.Files.AppliedLayoutsIOHelper.WriteData(appliedLayouts.Serialize(appliedLayoutsWrapper));
|
||||
|
||||
CustomLayouts customLayouts = new CustomLayouts();
|
||||
CustomLayouts.CustomLayoutListWrapper customLayoutListWrapper = new CustomLayouts.CustomLayoutListWrapper
|
||||
{
|
||||
CustomLayouts = new List<CustomLayouts.CustomLayoutWrapper> { },
|
||||
};
|
||||
FancyZonesEditorHelper.Files.CustomLayoutsIOHelper.WriteData(customLayouts.Serialize(customLayoutListWrapper));
|
||||
|
||||
LayoutTemplates layoutTemplates = new LayoutTemplates();
|
||||
LayoutTemplates.TemplateLayoutsListWrapper templateLayoutsListWrapper = new LayoutTemplates.TemplateLayoutsListWrapper
|
||||
{
|
||||
LayoutTemplates = new List<LayoutTemplates.TemplateLayoutWrapper>
|
||||
{
|
||||
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));
|
||||
|
||||
// verify editor opens without errors
|
||||
this.RestartScopeExe();
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
public void FirstLaunch() // verify the session is initialized
|
||||
{
|
||||
Assert.IsNotNull(Session.Find<Element>("FancyZones Layout"));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -3,26 +3,31 @@
|
||||
// See the LICENSE file in the project root for more information.
|
||||
|
||||
using System.Collections.Generic;
|
||||
|
||||
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 OpenQA.Selenium.Appium.Windows;
|
||||
using static Microsoft.FancyZonesEditor.UnitTests.Utils.FancyZonesEditorHelper;
|
||||
|
||||
namespace UITests_FancyZonesEditor
|
||||
namespace Microsoft.FancyZonesEditor.UITests
|
||||
{
|
||||
[TestClass]
|
||||
public class RunFancyZonesEditorTest
|
||||
public class RunFancyZonesEditorTest : UITestBase
|
||||
{
|
||||
private static FancyZonesEditorSession? _session;
|
||||
private static TestContext? _context;
|
||||
public RunFancyZonesEditorTest()
|
||||
: base(PowerToysModule.FancyZone)
|
||||
{
|
||||
}
|
||||
|
||||
[ClassInitialize]
|
||||
public static void ClassInitialize(TestContext testContext)
|
||||
{
|
||||
_context = testContext;
|
||||
FancyZonesEditorHelper.Files.Restore();
|
||||
|
||||
// prepare files to launch Editor without errors
|
||||
// prepare test editor parameters with 2 monitors before launching the editor
|
||||
EditorParameters editorParameters = new EditorParameters();
|
||||
EditorParameters.ParamsWrapper parameters = new EditorParameters.ParamsWrapper
|
||||
{
|
||||
@@ -46,9 +51,25 @@ namespace UITests_FancyZonesEditor
|
||||
MonitorWidth = 1920,
|
||||
IsSelected = true,
|
||||
},
|
||||
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,
|
||||
},
|
||||
},
|
||||
};
|
||||
FancyZonesEditorSession.Files.ParamsIOHelper.WriteData(editorParameters.Serialize(parameters));
|
||||
FancyZonesEditorHelper.Files.ParamsIOHelper.WriteData(editorParameters.Serialize(parameters));
|
||||
|
||||
LayoutTemplates layoutTemplates = new LayoutTemplates();
|
||||
LayoutTemplates.TemplateLayoutsListWrapper templateLayoutsListWrapper = new LayoutTemplates.TemplateLayoutsListWrapper
|
||||
@@ -57,16 +78,16 @@ namespace UITests_FancyZonesEditor
|
||||
{
|
||||
new LayoutTemplates.TemplateLayoutWrapper
|
||||
{
|
||||
Type = Constants.TemplateLayoutJsonTags[Constants.TemplateLayout.Empty],
|
||||
Type = LayoutType.Blank.TypeToString(),
|
||||
},
|
||||
new LayoutTemplates.TemplateLayoutWrapper
|
||||
{
|
||||
Type = Constants.TemplateLayoutJsonTags[Constants.TemplateLayout.Focus],
|
||||
Type = LayoutType.Focus.TypeToString(),
|
||||
ZoneCount = 10,
|
||||
},
|
||||
new LayoutTemplates.TemplateLayoutWrapper
|
||||
{
|
||||
Type = Constants.TemplateLayoutJsonTags[Constants.TemplateLayout.Rows],
|
||||
Type = LayoutType.Rows.TypeToString(),
|
||||
ZoneCount = 2,
|
||||
ShowSpacing = true,
|
||||
Spacing = 10,
|
||||
@@ -74,7 +95,7 @@ namespace UITests_FancyZonesEditor
|
||||
},
|
||||
new LayoutTemplates.TemplateLayoutWrapper
|
||||
{
|
||||
Type = Constants.TemplateLayoutJsonTags[Constants.TemplateLayout.Columns],
|
||||
Type = LayoutType.Columns.TypeToString(),
|
||||
ZoneCount = 2,
|
||||
ShowSpacing = true,
|
||||
Spacing = 20,
|
||||
@@ -82,7 +103,7 @@ namespace UITests_FancyZonesEditor
|
||||
},
|
||||
new LayoutTemplates.TemplateLayoutWrapper
|
||||
{
|
||||
Type = Constants.TemplateLayoutJsonTags[Constants.TemplateLayout.Grid],
|
||||
Type = LayoutType.Grid.TypeToString(),
|
||||
ZoneCount = 4,
|
||||
ShowSpacing = false,
|
||||
Spacing = 10,
|
||||
@@ -90,7 +111,7 @@ namespace UITests_FancyZonesEditor
|
||||
},
|
||||
new LayoutTemplates.TemplateLayoutWrapper
|
||||
{
|
||||
Type = Constants.TemplateLayoutJsonTags[Constants.TemplateLayout.PriorityGrid],
|
||||
Type = LayoutType.PriorityGrid.TypeToString(),
|
||||
ZoneCount = 3,
|
||||
ShowSpacing = true,
|
||||
Spacing = 1,
|
||||
@@ -98,81 +119,118 @@ namespace UITests_FancyZonesEditor
|
||||
},
|
||||
},
|
||||
};
|
||||
FancyZonesEditorSession.Files.LayoutTemplatesIOHelper.WriteData(layoutTemplates.Serialize(templateLayoutsListWrapper));
|
||||
FancyZonesEditorHelper.Files.LayoutTemplatesIOHelper.WriteData(layoutTemplates.Serialize(templateLayoutsListWrapper));
|
||||
|
||||
CustomLayouts customLayouts = new CustomLayouts();
|
||||
CustomLayouts.CustomLayoutListWrapper customLayoutListWrapper = new CustomLayouts.CustomLayoutListWrapper
|
||||
{
|
||||
CustomLayouts = new List<CustomLayouts.CustomLayoutWrapper> { },
|
||||
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> { },
|
||||
}),
|
||||
},
|
||||
},
|
||||
};
|
||||
FancyZonesEditorSession.Files.CustomLayoutsIOHelper.WriteData(customLayouts.Serialize(customLayoutListWrapper));
|
||||
FancyZonesEditorHelper.Files.CustomLayoutsIOHelper.WriteData(customLayouts.Serialize(customLayoutListWrapper));
|
||||
|
||||
DefaultLayouts defaultLayouts = new DefaultLayouts();
|
||||
DefaultLayouts.DefaultLayoutsListWrapper defaultLayoutsListWrapper = new DefaultLayouts.DefaultLayoutsListWrapper
|
||||
{
|
||||
DefaultLayouts = new List<DefaultLayouts.DefaultLayoutWrapper> { },
|
||||
};
|
||||
FancyZonesEditorSession.Files.DefaultLayoutsIOHelper.WriteData(defaultLayouts.Serialize(defaultLayoutsListWrapper));
|
||||
FancyZonesEditorHelper.Files.DefaultLayoutsIOHelper.WriteData(defaultLayouts.Serialize(defaultLayoutsListWrapper));
|
||||
|
||||
LayoutHotkeys layoutHotkeys = new LayoutHotkeys();
|
||||
LayoutHotkeys.LayoutHotkeysWrapper layoutHotkeysWrapper = new LayoutHotkeys.LayoutHotkeysWrapper
|
||||
{
|
||||
LayoutHotkeys = new List<LayoutHotkeys.LayoutHotkeyWrapper> { },
|
||||
};
|
||||
FancyZonesEditorSession.Files.LayoutHotkeysIOHelper.WriteData(layoutHotkeys.Serialize(layoutHotkeysWrapper));
|
||||
FancyZonesEditorHelper.Files.LayoutHotkeysIOHelper.WriteData(layoutHotkeys.Serialize(layoutHotkeysWrapper));
|
||||
|
||||
AppliedLayouts appliedLayouts = new AppliedLayouts();
|
||||
AppliedLayouts.AppliedLayoutsListWrapper appliedLayoutsWrapper = new AppliedLayouts.AppliedLayoutsListWrapper
|
||||
{
|
||||
AppliedLayouts = new List<AppliedLayouts.AppliedLayoutWrapper> { },
|
||||
};
|
||||
FancyZonesEditorSession.Files.AppliedLayoutsIOHelper.WriteData(appliedLayouts.Serialize(appliedLayoutsWrapper));
|
||||
FancyZonesEditorHelper.Files.AppliedLayoutsIOHelper.WriteData(appliedLayouts.Serialize(appliedLayoutsWrapper));
|
||||
}
|
||||
|
||||
[ClassCleanup]
|
||||
public static void ClassCleanup()
|
||||
{
|
||||
FancyZonesEditorSession.Files.Restore();
|
||||
_context = null;
|
||||
}
|
||||
|
||||
[TestInitialize]
|
||||
public void TestInitialize()
|
||||
{
|
||||
_session = new FancyZonesEditorSession(_context!);
|
||||
}
|
||||
|
||||
[TestCleanup]
|
||||
public void TestCleanup()
|
||||
{
|
||||
_session?.Close(_context!);
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
public void OpenEditorWindow() // verify the session is initialized
|
||||
{
|
||||
Assert.IsNotNull(_session?.Session);
|
||||
FancyZonesEditorHelper.Files.Restore();
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
public void OpenNewLayoutDialog() // verify the new layout dialog is opened
|
||||
{
|
||||
_session?.Click_CreateNewLayout();
|
||||
Assert.IsNotNull(_session?.Session?.FindElementsByName("Choose layout type")); // check the pane header
|
||||
Session.Find<Button>(By.AccessibilityId(AccessibilityId.NewLayoutButton)).Click();
|
||||
Assert.IsNotNull(Session.Find<Element>("Choose layout type")); // check the pane header
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
public void OpenEditLayoutDialog() // verify the edit layout dialog is opened
|
||||
{
|
||||
_session?.Click_EditLayout(TestConstants.TemplateLayoutNames[Constants.TemplateLayout.Grid]);
|
||||
Assert.IsNotNull(_session?.Session?.FindElementByAccessibilityId("EditLayoutDialogTitle")); // check the pane header
|
||||
Assert.IsNotNull(_session?.Session?.FindElementsByName("Edit 'Grid'")); // verify it's opened for the correct layout
|
||||
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
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
public void OpenEditLayoutDialog_ByContextMenu_TemplateLayout() // verify the edit layout dialog is opened
|
||||
{
|
||||
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
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
public void OpenEditLayoutDialog_ByContextMenu_CustomLayout() // verify the edit layout dialog is opened
|
||||
{
|
||||
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
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
public void OpenContextMenu() // verify the context menu is opened
|
||||
{
|
||||
Assert.IsNotNull(_session?.OpenContextMenu(TestConstants.TemplateLayoutNames[Constants.TemplateLayout.Columns]));
|
||||
Session.Find<Button>(TestConstants.TemplateLayoutNames[LayoutType.Columns]).Click(true);
|
||||
Assert.IsNotNull(Session.Find<Element>(By.ClassName(ClassName.ContextMenu)));
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
public void ClickMonitor()
|
||||
{
|
||||
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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,402 @@
|
||||
// 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 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 OpenQA.Selenium;
|
||||
using Windows.UI;
|
||||
using static FancyZonesEditorCommon.Data.AppliedLayouts;
|
||||
using static FancyZonesEditorCommon.Data.DefaultLayouts;
|
||||
using static FancyZonesEditorCommon.Data.EditorParameters;
|
||||
using static FancyZonesEditorCommon.Data.LayoutTemplates;
|
||||
using static Microsoft.ApplicationInsights.MetricDimensionNames.TelemetryContext;
|
||||
using static Microsoft.FancyZonesEditor.UnitTests.Utils.FancyZonesEditorHelper;
|
||||
|
||||
namespace Microsoft.FancyZonesEditor.UITests
|
||||
{
|
||||
[TestClass]
|
||||
public class TemplateLayoutsTests : UITestBase
|
||||
{
|
||||
private static readonly TemplateLayoutsListWrapper Layouts = new TemplateLayoutsListWrapper
|
||||
{
|
||||
LayoutTemplates = new List<TemplateLayoutWrapper>
|
||||
{
|
||||
new TemplateLayoutWrapper
|
||||
{
|
||||
Type = LayoutType.Blank.TypeToString(),
|
||||
},
|
||||
new TemplateLayoutWrapper
|
||||
{
|
||||
Type = LayoutType.Focus.TypeToString(),
|
||||
ZoneCount = 10,
|
||||
},
|
||||
new TemplateLayoutWrapper
|
||||
{
|
||||
Type = LayoutType.Rows.TypeToString(),
|
||||
ZoneCount = 2,
|
||||
ShowSpacing = true,
|
||||
Spacing = 10,
|
||||
SensitivityRadius = 10,
|
||||
},
|
||||
new TemplateLayoutWrapper
|
||||
{
|
||||
Type = LayoutType.Columns.TypeToString(),
|
||||
ZoneCount = 2,
|
||||
ShowSpacing = true,
|
||||
Spacing = 20,
|
||||
SensitivityRadius = 20,
|
||||
},
|
||||
new TemplateLayoutWrapper
|
||||
{
|
||||
Type = LayoutType.Grid.TypeToString(),
|
||||
ZoneCount = 4,
|
||||
ShowSpacing = false,
|
||||
Spacing = 10,
|
||||
SensitivityRadius = 30,
|
||||
},
|
||||
new TemplateLayoutWrapper
|
||||
{
|
||||
Type = LayoutType.PriorityGrid.TypeToString(),
|
||||
ZoneCount = 3,
|
||||
ShowSpacing = true,
|
||||
Spacing = 1,
|
||||
SensitivityRadius = 40,
|
||||
},
|
||||
},
|
||||
};
|
||||
|
||||
public TemplateLayoutsTests()
|
||||
: base(PowerToysModule.FancyZone)
|
||||
{
|
||||
}
|
||||
|
||||
[TestInitialize]
|
||||
public void TestInitialize()
|
||||
{
|
||||
EditorParameters editorParameters = new EditorParameters();
|
||||
ParamsWrapper parameters = new ParamsWrapper
|
||||
{
|
||||
ProcessId = 1,
|
||||
SpanZonesAcrossMonitors = false,
|
||||
Monitors = new List<NativeMonitorDataWrapper>
|
||||
{
|
||||
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();
|
||||
FancyZonesEditorHelper.Files.LayoutTemplatesIOHelper.WriteData(layoutTemplates.Serialize(Layouts));
|
||||
|
||||
// Default layouts should match templates
|
||||
DefaultLayouts defaultLayouts = new DefaultLayouts();
|
||||
DefaultLayoutsListWrapper defaultLayoutsList = new DefaultLayoutsListWrapper
|
||||
{
|
||||
DefaultLayouts = new List<DefaultLayoutWrapper>
|
||||
{
|
||||
new DefaultLayoutWrapper
|
||||
{
|
||||
MonitorConfiguration = MonitorConfigurationType.Vertical.ToString(),
|
||||
Layout = new DefaultLayoutWrapper.LayoutWrapper
|
||||
{
|
||||
Type = LayoutType.Rows.TypeToString(),
|
||||
ZoneCount = 2,
|
||||
ShowSpacing = true,
|
||||
Spacing = 10,
|
||||
SensitivityRadius = 10,
|
||||
},
|
||||
},
|
||||
new DefaultLayoutWrapper
|
||||
{
|
||||
MonitorConfiguration = MonitorConfigurationType.Horizontal.ToString(),
|
||||
Layout = new DefaultLayoutWrapper.LayoutWrapper
|
||||
{
|
||||
Type = LayoutType.PriorityGrid.TypeToString(),
|
||||
ZoneCount = 3,
|
||||
ShowSpacing = true,
|
||||
Spacing = 1,
|
||||
SensitivityRadius = 40,
|
||||
},
|
||||
},
|
||||
},
|
||||
};
|
||||
FancyZonesEditorHelper.Files.DefaultLayoutsIOHelper.WriteData(defaultLayouts.Serialize(defaultLayoutsList));
|
||||
|
||||
// Make sure applied layouts don't replate template settings
|
||||
AppliedLayouts appliedLayouts = new AppliedLayouts();
|
||||
AppliedLayoutsListWrapper appliedLayoutsList = new AppliedLayoutsListWrapper
|
||||
{
|
||||
AppliedLayouts = new List<AppliedLayoutWrapper>
|
||||
{
|
||||
new AppliedLayoutWrapper
|
||||
{
|
||||
Device = new AppliedLayoutWrapper.DeviceIdWrapper
|
||||
{
|
||||
Monitor = "monitor-1",
|
||||
MonitorInstance = "instance-id-1",
|
||||
MonitorNumber = 1,
|
||||
SerialNumber = "serial-number-1",
|
||||
VirtualDesktop = "{FF34D993-73F3-4B8C-AA03-73730A01D6A8}",
|
||||
},
|
||||
AppliedLayout = new AppliedLayoutWrapper.LayoutWrapper
|
||||
{
|
||||
Uuid = "{72409DFC-2B87-469B-AAC4-557273791C26}",
|
||||
Type = LayoutType.PriorityGrid.TypeToString(),
|
||||
ZoneCount = 3,
|
||||
ShowSpacing = true,
|
||||
Spacing = 1,
|
||||
SensitivityRadius = 40,
|
||||
},
|
||||
},
|
||||
},
|
||||
};
|
||||
FancyZonesEditorHelper.Files.AppliedLayoutsIOHelper.WriteData(appliedLayouts.Serialize(appliedLayoutsList));
|
||||
|
||||
CustomLayouts customLayouts = new CustomLayouts();
|
||||
CustomLayouts.CustomLayoutListWrapper customLayoutListWrapper = new CustomLayouts.CustomLayoutListWrapper
|
||||
{
|
||||
CustomLayouts = new List<CustomLayouts.CustomLayoutWrapper> { },
|
||||
};
|
||||
FancyZonesEditorHelper.Files.CustomLayoutsIOHelper.WriteData(customLayouts.Serialize(customLayoutListWrapper));
|
||||
|
||||
LayoutHotkeys layoutHotkeys = new LayoutHotkeys();
|
||||
LayoutHotkeys.LayoutHotkeysWrapper layoutHotkeysWrapper = new LayoutHotkeys.LayoutHotkeysWrapper
|
||||
{
|
||||
LayoutHotkeys = new List<LayoutHotkeys.LayoutHotkeyWrapper> { },
|
||||
};
|
||||
FancyZonesEditorHelper.Files.LayoutHotkeysIOHelper.WriteData(layoutHotkeys.Serialize(layoutHotkeysWrapper));
|
||||
|
||||
this.RestartScopeExe();
|
||||
}
|
||||
|
||||
[TestCleanup]
|
||||
public void TestCleanup()
|
||||
{
|
||||
FancyZonesEditorHelper.Files.Restore();
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
public void ZoneNumber_Cancel()
|
||||
{
|
||||
var type = LayoutType.Rows;
|
||||
var layout = Layouts.LayoutTemplates.Find(x => x.Type == type.TypeToString());
|
||||
var expected = layout.ZoneCount;
|
||||
Session.Find<Button>(TestConstants.TemplateLayoutNames[type]).Click();
|
||||
|
||||
var slider = Session.Find<Element>(PowerToys.UITest.By.AccessibilityId(AccessibilityId.TemplateZoneSlider));
|
||||
Assert.IsNotNull(slider);
|
||||
slider.SendKeys(Keys.Left);
|
||||
|
||||
Session.Find<Button>(ElementName.Cancel).Click();
|
||||
|
||||
// verify the file
|
||||
var templateLayouts = new LayoutTemplates();
|
||||
var data = templateLayouts.Read(templateLayouts.File);
|
||||
var actual = data.LayoutTemplates.Find(x => x.Type == type.TypeToString()).ZoneCount;
|
||||
Assert.AreEqual(expected, actual);
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
public void HighlightDistance_Initialize()
|
||||
{
|
||||
foreach (var (type, name) in TestConstants.TemplateLayoutNames)
|
||||
{
|
||||
if (type == LayoutType.Blank)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
Session.Find<Button>(name).Click();
|
||||
|
||||
var slider = Session.Find<Element>(PowerToys.UITest.By.AccessibilityId(AccessibilityId.SensitivitySlider));
|
||||
Assert.IsNotNull(slider);
|
||||
var expected = Layouts.LayoutTemplates.Find(x => x.Type == type.TypeToString()).SensitivityRadius;
|
||||
Assert.AreEqual($"{expected}", slider.Text);
|
||||
|
||||
Session.Find<Button>(ElementName.Cancel).Click();
|
||||
}
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
public void HighlightDistance_Save()
|
||||
{
|
||||
var type = LayoutType.Focus;
|
||||
var layout = Layouts.LayoutTemplates.Find(x => x.Type == type.TypeToString());
|
||||
var value = layout.SensitivityRadius;
|
||||
Session.Find<Button>(TestConstants.TemplateLayoutNames[type]).Click();
|
||||
|
||||
var slider = Session.Find<Element>(PowerToys.UITest.By.AccessibilityId(AccessibilityId.SensitivitySlider));
|
||||
Assert.IsNotNull(slider);
|
||||
slider.SendKeys(Keys.Right);
|
||||
|
||||
var expected = value + 1; // one step right
|
||||
Assert.AreEqual($"{expected}", slider.Text);
|
||||
|
||||
Session.Find<Button>(ElementName.Save).Click();
|
||||
|
||||
// verify the file
|
||||
var templateLayouts = new LayoutTemplates();
|
||||
var data = templateLayouts.Read(templateLayouts.File);
|
||||
var actual = data.LayoutTemplates.Find(x => x.Type == type.TypeToString()).SensitivityRadius;
|
||||
Assert.AreEqual(expected, actual);
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
public void HighlightDistance_Cancel()
|
||||
{
|
||||
var type = LayoutType.Focus;
|
||||
var layout = Layouts.LayoutTemplates.Find(x => x.Type == type.TypeToString());
|
||||
var expected = layout.SensitivityRadius;
|
||||
Session.Find<Button>(TestConstants.TemplateLayoutNames[type]).Click();
|
||||
|
||||
var slider = Session.Find<Element>(PowerToys.UITest.By.AccessibilityId(AccessibilityId.SensitivitySlider));
|
||||
Assert.IsNotNull(slider);
|
||||
slider.SendKeys(Keys.Right);
|
||||
Session.Find<Button>(ElementName.Cancel).Click();
|
||||
|
||||
// verify the file
|
||||
var templateLayouts = new LayoutTemplates();
|
||||
var data = templateLayouts.Read(templateLayouts.File);
|
||||
var actual = data.LayoutTemplates.Find(x => x.Type == type.TypeToString()).SensitivityRadius;
|
||||
Assert.AreEqual(expected, actual);
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
public void SpaceAroundZones_Initialize()
|
||||
{
|
||||
foreach (var (type, name) in TestConstants.TemplateLayoutNames)
|
||||
{
|
||||
if (type == LayoutType.Blank || type == LayoutType.Focus)
|
||||
{
|
||||
// only for grid layouts
|
||||
continue;
|
||||
}
|
||||
|
||||
Session.Find<Button>(name).Click();
|
||||
|
||||
var slider = Session.Find<Element>(PowerToys.UITest.By.AccessibilityId(AccessibilityId.SpacingSlider));
|
||||
Assert.IsNotNull(slider);
|
||||
|
||||
var spacingEnabled = Layouts.LayoutTemplates.Find(x => x.Type == type.TypeToString()).ShowSpacing;
|
||||
Assert.AreEqual(spacingEnabled, slider.Enabled);
|
||||
|
||||
var expected = Layouts.LayoutTemplates.Find(x => x.Type == type.TypeToString()).Spacing;
|
||||
Assert.AreEqual($"{expected}", slider.Text);
|
||||
|
||||
Session.Find<Button>(ElementName.Cancel).Click();
|
||||
}
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
public void SpaceAroundZones_Slider_Save()
|
||||
{
|
||||
var type = LayoutType.PriorityGrid;
|
||||
var layout = Layouts.LayoutTemplates.Find(x => x.Type == type.TypeToString());
|
||||
var expected = layout.Spacing + 1;
|
||||
Session.Find<Button>(TestConstants.TemplateLayoutNames[type]).Click();
|
||||
|
||||
var slider = Session.Find<Element>(PowerToys.UITest.By.AccessibilityId(AccessibilityId.SpacingSlider));
|
||||
Assert.IsNotNull(slider);
|
||||
slider.SendKeys(Keys.Right);
|
||||
Assert.AreEqual($"{expected}", slider.Text);
|
||||
|
||||
Session.Find<Button>(ElementName.Save).Click();
|
||||
|
||||
// verify the file
|
||||
var templateLayouts = new LayoutTemplates();
|
||||
var data = templateLayouts.Read(templateLayouts.File);
|
||||
var actual = data.LayoutTemplates.Find(x => x.Type == type.TypeToString()).Spacing;
|
||||
Assert.AreEqual(expected, actual);
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
public void SpaceAroundZones_Slider_Cancel()
|
||||
{
|
||||
var type = LayoutType.PriorityGrid;
|
||||
var layout = Layouts.LayoutTemplates.Find(x => x.Type == type.TypeToString());
|
||||
var expected = layout.Spacing;
|
||||
Session.Find<Button>(TestConstants.TemplateLayoutNames[type]).Click();
|
||||
|
||||
var slider = Session.Find<Element>(PowerToys.UITest.By.AccessibilityId(AccessibilityId.SpacingSlider));
|
||||
Assert.IsNotNull(slider);
|
||||
slider.SendKeys(Keys.Right);
|
||||
Assert.AreEqual($"{expected + 1}", slider.Text);
|
||||
|
||||
Session.Find<Button>(ElementName.Cancel).Click();
|
||||
|
||||
// verify the file
|
||||
var templateLayouts = new LayoutTemplates();
|
||||
var data = templateLayouts.Read(templateLayouts.File);
|
||||
var actual = data.LayoutTemplates.Find(x => x.Type == type.TypeToString()).Spacing;
|
||||
Assert.AreEqual(expected, actual);
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
public void SpaceAroundZones_Toggle_Save()
|
||||
{
|
||||
var type = LayoutType.PriorityGrid;
|
||||
var layout = Layouts.LayoutTemplates.Find(x => x.Type == type.TypeToString());
|
||||
var expected = !layout.ShowSpacing;
|
||||
Session.Find<Button>(TestConstants.TemplateLayoutNames[type]).Click();
|
||||
|
||||
var toggle = Session.Find<Element>(PowerToys.UITest.By.AccessibilityId(AccessibilityId.SpacingToggle));
|
||||
Assert.IsNotNull(toggle);
|
||||
toggle.Click();
|
||||
Assert.AreEqual(expected, toggle.Selected);
|
||||
Assert.AreEqual(expected, Session.Find<Element>(PowerToys.UITest.By.AccessibilityId(AccessibilityId.SpacingSlider))?.Enabled);
|
||||
|
||||
Session.Find<Button>(ElementName.Save).Click();
|
||||
|
||||
// verify the file
|
||||
var templateLayouts = new LayoutTemplates();
|
||||
var data = templateLayouts.Read(templateLayouts.File);
|
||||
var actual = data.LayoutTemplates.Find(x => x.Type == type.TypeToString()).ShowSpacing;
|
||||
Assert.AreEqual(expected, actual);
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
public void SpaceAroundZones_Toggle_Cancel()
|
||||
{
|
||||
var type = LayoutType.PriorityGrid;
|
||||
var layout = Layouts.LayoutTemplates.Find(x => x.Type == type.TypeToString());
|
||||
var expected = layout.ShowSpacing;
|
||||
Session.Find<Button>(TestConstants.TemplateLayoutNames[type]).Click();
|
||||
|
||||
var toggle = Session.Find<Element>(PowerToys.UITest.By.AccessibilityId(AccessibilityId.SpacingToggle));
|
||||
Assert.IsNotNull(toggle);
|
||||
toggle.Click();
|
||||
Assert.AreNotEqual(expected, toggle.Selected);
|
||||
Assert.AreNotEqual(expected, Session.Find<Element>(PowerToys.UITest.By.AccessibilityId(AccessibilityId.SpacingSlider))?.Enabled);
|
||||
|
||||
Session.Find<Button>(ElementName.Cancel).Click();
|
||||
|
||||
// verify the file
|
||||
var templateLayouts = new LayoutTemplates();
|
||||
var data = templateLayouts.Read(templateLayouts.File);
|
||||
var actual = data.LayoutTemplates.Find(x => x.Type == type.TypeToString()).ShowSpacing;
|
||||
Assert.AreEqual(expected, actual);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -3,6 +3,7 @@
|
||||
// See the LICENSE file in the project root for more information.
|
||||
|
||||
using System.Collections.Generic;
|
||||
using FancyZonesEditor.Models;
|
||||
|
||||
using static FancyZonesEditorCommon.Data.Constants;
|
||||
|
||||
@@ -10,14 +11,14 @@ namespace Microsoft.FancyZonesEditor.UITests
|
||||
{
|
||||
public static class TestConstants
|
||||
{
|
||||
public static readonly Dictionary<TemplateLayout, string> TemplateLayoutNames = new Dictionary<TemplateLayout, string>()
|
||||
public static readonly Dictionary<LayoutType, string> TemplateLayoutNames = new Dictionary<LayoutType, string>()
|
||||
{
|
||||
{ TemplateLayout.Empty, "No layout" },
|
||||
{ TemplateLayout.Focus, "Focus" },
|
||||
{ TemplateLayout.Rows, "Rows" },
|
||||
{ TemplateLayout.Columns, "Columns" },
|
||||
{ TemplateLayout.Grid, "Grid" },
|
||||
{ TemplateLayout.PriorityGrid, "PriorityGrid" },
|
||||
{ LayoutType.Blank, "No layout" },
|
||||
{ LayoutType.Focus, "Focus" },
|
||||
{ LayoutType.Rows, "Rows" },
|
||||
{ LayoutType.Columns, "Columns" },
|
||||
{ LayoutType.Grid, "Grid" },
|
||||
{ LayoutType.PriorityGrid, "Priority Grid" },
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,846 @@
|
||||
// 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 System.Xml.Linq;
|
||||
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 Microsoft.FancyZonesEditor.UITests
|
||||
{
|
||||
[TestClass]
|
||||
public class UIInitializeTest : UITestBase
|
||||
{
|
||||
public UIInitializeTest()
|
||||
: base(PowerToysModule.FancyZone)
|
||||
{
|
||||
}
|
||||
|
||||
[TestCleanup]
|
||||
public void TestCleanup()
|
||||
{
|
||||
FancyZonesEditorHelper.Files.Restore();
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
public void EditorParams_VerifySelectedMonitor()
|
||||
{
|
||||
InitFileData();
|
||||
EditorParameters editorParameters = new EditorParameters();
|
||||
ParamsWrapper parameters = new ParamsWrapper
|
||||
{
|
||||
ProcessId = 1,
|
||||
SpanZonesAcrossMonitors = false,
|
||||
Monitors = new List<NativeMonitorDataWrapper>
|
||||
{
|
||||
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();
|
||||
|
||||
Session.Find<Element>("Monitor 1").Click();
|
||||
Session.Find<Element>("Monitor 2").Click();
|
||||
Assert.IsFalse(Session.Find<Element>("Monitor 1").Selected);
|
||||
Assert.IsTrue(Session.Find<Element>("Monitor 2").Selected);
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
public void EditorParams_VerifyMonitorScaling()
|
||||
{
|
||||
InitFileData();
|
||||
EditorParameters editorParameters = new EditorParameters();
|
||||
ParamsWrapper parameters = new ParamsWrapper
|
||||
{
|
||||
ProcessId = 1,
|
||||
SpanZonesAcrossMonitors = false,
|
||||
Monitors = new List<NativeMonitorDataWrapper>
|
||||
{
|
||||
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();
|
||||
|
||||
Session.Find<Element>("Monitor 1").Click();
|
||||
var monitor = Session.Find<Element>("Monitor 1");
|
||||
var scaling = monitor.Find<Element>(By.AccessibilityId("ScalingText"));
|
||||
Assert.AreEqual("200%", scaling.Text);
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
public void EditorParams_VerifyMonitorResolution()
|
||||
{
|
||||
InitFileData();
|
||||
EditorParameters editorParameters = new EditorParameters();
|
||||
ParamsWrapper parameters = new ParamsWrapper
|
||||
{
|
||||
ProcessId = 1,
|
||||
SpanZonesAcrossMonitors = false,
|
||||
Monitors = new List<NativeMonitorDataWrapper>
|
||||
{
|
||||
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();
|
||||
|
||||
Session.Find<Element>("Monitor 1").Click();
|
||||
var monitor = Session.Find<Element>("Monitor 1");
|
||||
var resolution = monitor.Find<Element>(By.AccessibilityId("ResolutionText"));
|
||||
Assert.AreEqual("1920 × 1080", resolution.Text);
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
public void EditorParams_SpanAcrossMonitors()
|
||||
{
|
||||
InitFileData();
|
||||
EditorParameters editorParameters = new EditorParameters();
|
||||
ParamsWrapper parameters = new ParamsWrapper
|
||||
{
|
||||
ProcessId = 1,
|
||||
SpanZonesAcrossMonitors = true,
|
||||
Monitors = new List<NativeMonitorDataWrapper>
|
||||
{
|
||||
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();
|
||||
|
||||
Session.Find<Element>("Monitor 1").Click();
|
||||
var monitor = Session.Find<Element>("Monitor 1");
|
||||
Assert.IsNotNull(monitor);
|
||||
Assert.IsTrue(monitor.Selected);
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
public void AppliedLayouts_LayoutsApplied()
|
||||
{
|
||||
InitFileData();
|
||||
EditorParameters editorParameters = new EditorParameters();
|
||||
ParamsWrapper parameters = new ParamsWrapper
|
||||
{
|
||||
ProcessId = 1,
|
||||
SpanZonesAcrossMonitors = false,
|
||||
Monitors = new List<NativeMonitorDataWrapper>
|
||||
{
|
||||
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,
|
||||
},
|
||||
},
|
||||
};
|
||||
FancyZonesEditorHelper.Files.ParamsIOHelper.WriteData(editorParameters.Serialize(parameters));
|
||||
|
||||
CustomLayouts customLayouts = new CustomLayouts();
|
||||
CustomLayouts.CustomLayoutListWrapper customLayoutListWrapper = new CustomLayouts.CustomLayoutListWrapper
|
||||
{
|
||||
CustomLayouts = new List<CustomLayouts.CustomLayoutWrapper>
|
||||
{
|
||||
new CustomLayouts.CustomLayoutWrapper
|
||||
{
|
||||
Uuid = "{0D6D2F58-9184-4804-81E4-4E4CC3476DC1}",
|
||||
Type = CustomLayout.Canvas.TypeToString(),
|
||||
Name = "Custom layout 1",
|
||||
Info = new CustomLayouts().ToJsonElement(new CustomLayouts.CanvasInfoWrapper
|
||||
{
|
||||
RefHeight = 1080,
|
||||
RefWidth = 1920,
|
||||
SensitivityRadius = 10,
|
||||
Zones = new List<CustomLayouts.CanvasInfoWrapper.CanvasZoneWrapper> { },
|
||||
}),
|
||||
},
|
||||
},
|
||||
};
|
||||
FancyZonesEditorHelper.Files.CustomLayoutsIOHelper.WriteData(customLayouts.Serialize(customLayoutListWrapper));
|
||||
|
||||
AppliedLayouts appliedLayouts = new AppliedLayouts();
|
||||
AppliedLayouts.AppliedLayoutsListWrapper appliedLayoutsWrapper = new AppliedLayouts.AppliedLayoutsListWrapper
|
||||
{
|
||||
AppliedLayouts = new List<AppliedLayouts.AppliedLayoutWrapper>
|
||||
{
|
||||
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(),
|
||||
},
|
||||
},
|
||||
},
|
||||
};
|
||||
FancyZonesEditorHelper.Files.AppliedLayoutsIOHelper.WriteData(appliedLayouts.Serialize(appliedLayoutsWrapper));
|
||||
this.RestartScopeExe();
|
||||
|
||||
// check layout on monitor 1
|
||||
var layoutOnMonitor1 = Session.Find<Element>(TestConstants.TemplateLayoutNames[LayoutType.Columns]);
|
||||
Assert.IsNotNull(layoutOnMonitor1);
|
||||
Assert.IsTrue(layoutOnMonitor1.Selected);
|
||||
|
||||
// check layout on monitor 2
|
||||
Session.Find<Element>(By.AccessibilityId("Monitors")).Find<Element>("Monitor 2").Click();
|
||||
var layoutOnMonitor2 = Session.Find<Element>(customLayoutListWrapper.CustomLayouts[0].Name);
|
||||
Assert.IsNotNull(layoutOnMonitor2);
|
||||
Assert.IsTrue(layoutOnMonitor2.Selected);
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
public void AppliedLayouts_CustomLayoutsApplied_LayoutIdNotFound()
|
||||
{
|
||||
InitFileData();
|
||||
EditorParameters editorParameters = new EditorParameters();
|
||||
ParamsWrapper parameters = new ParamsWrapper
|
||||
{
|
||||
ProcessId = 1,
|
||||
SpanZonesAcrossMonitors = false,
|
||||
Monitors = new List<NativeMonitorDataWrapper>
|
||||
{
|
||||
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,
|
||||
},
|
||||
},
|
||||
};
|
||||
FancyZonesEditorHelper.Files.ParamsIOHelper.WriteData(editorParameters.Serialize(parameters));
|
||||
|
||||
CustomLayouts customLayouts = new CustomLayouts();
|
||||
CustomLayouts.CustomLayoutListWrapper customLayoutListWrapper = new CustomLayouts.CustomLayoutListWrapper
|
||||
{
|
||||
CustomLayouts = new List<CustomLayouts.CustomLayoutWrapper>
|
||||
{
|
||||
new CustomLayouts.CustomLayoutWrapper
|
||||
{
|
||||
Uuid = "{0D6D2F58-9184-4804-81E4-4E4CC3476DC1}",
|
||||
Type = CustomLayout.Canvas.TypeToString(),
|
||||
Name = "Custom layout 1",
|
||||
Info = new CustomLayouts().ToJsonElement(new CustomLayouts.CanvasInfoWrapper
|
||||
{
|
||||
RefHeight = 1080,
|
||||
RefWidth = 1920,
|
||||
SensitivityRadius = 10,
|
||||
Zones = new List<CustomLayouts.CanvasInfoWrapper.CanvasZoneWrapper> { },
|
||||
}),
|
||||
},
|
||||
},
|
||||
};
|
||||
FancyZonesEditorHelper.Files.CustomLayoutsIOHelper.WriteData(customLayouts.Serialize(customLayoutListWrapper));
|
||||
|
||||
AppliedLayouts appliedLayouts = new AppliedLayouts();
|
||||
AppliedLayouts.AppliedLayoutsListWrapper appliedLayoutsWrapper = new AppliedLayouts.AppliedLayoutsListWrapper
|
||||
{
|
||||
AppliedLayouts = new List<AppliedLayouts.AppliedLayoutWrapper>
|
||||
{
|
||||
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(),
|
||||
},
|
||||
},
|
||||
},
|
||||
};
|
||||
FancyZonesEditorHelper.Files.AppliedLayoutsIOHelper.WriteData(appliedLayouts.Serialize(appliedLayoutsWrapper));
|
||||
|
||||
this.RestartScopeExe();
|
||||
|
||||
var emptyLayout = Session.Find<Element>(TestConstants.TemplateLayoutNames[LayoutType.Blank]);
|
||||
Assert.IsNotNull(emptyLayout);
|
||||
Assert.IsTrue(emptyLayout.Selected);
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
public void AppliedLayouts_NoLayoutsApplied_CustomDefaultLayout()
|
||||
{
|
||||
InitFileData();
|
||||
EditorParameters editorParameters = new EditorParameters();
|
||||
ParamsWrapper parameters = new ParamsWrapper
|
||||
{
|
||||
ProcessId = 1,
|
||||
SpanZonesAcrossMonitors = false,
|
||||
Monitors = new List<NativeMonitorDataWrapper>
|
||||
{
|
||||
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,
|
||||
},
|
||||
},
|
||||
};
|
||||
FancyZonesEditorHelper.Files.ParamsIOHelper.WriteData(editorParameters.Serialize(parameters));
|
||||
|
||||
CustomLayouts customLayouts = new CustomLayouts();
|
||||
CustomLayouts.CustomLayoutListWrapper customLayoutListWrapper = new CustomLayouts.CustomLayoutListWrapper
|
||||
{
|
||||
CustomLayouts = new List<CustomLayouts.CustomLayoutWrapper>
|
||||
{
|
||||
new CustomLayouts.CustomLayoutWrapper
|
||||
{
|
||||
Uuid = "{0D6D2F58-9184-4804-81E4-4E4CC3476DC1}",
|
||||
Type = CustomLayout.Canvas.TypeToString(),
|
||||
Name = "Custom layout 1",
|
||||
Info = new CustomLayouts().ToJsonElement(new CustomLayouts.CanvasInfoWrapper
|
||||
{
|
||||
RefHeight = 1080,
|
||||
RefWidth = 1920,
|
||||
SensitivityRadius = 10,
|
||||
Zones = new List<CustomLayouts.CanvasInfoWrapper.CanvasZoneWrapper> { },
|
||||
}),
|
||||
},
|
||||
},
|
||||
};
|
||||
FancyZonesEditorHelper.Files.CustomLayoutsIOHelper.WriteData(customLayouts.Serialize(customLayoutListWrapper));
|
||||
|
||||
FancyZonesEditorHelper.Files.DefaultLayoutsIOHelper.RestoreData();
|
||||
DefaultLayouts defaultLayouts = new DefaultLayouts();
|
||||
DefaultLayouts.DefaultLayoutsListWrapper defaultLayoutsListWrapper = new DefaultLayouts.DefaultLayoutsListWrapper
|
||||
{
|
||||
DefaultLayouts = new List<DefaultLayouts.DefaultLayoutWrapper>
|
||||
{
|
||||
new DefaultLayouts.DefaultLayoutWrapper
|
||||
{
|
||||
MonitorConfiguration = MonitorConfigurationType.Horizontal.TypeToString(),
|
||||
Layout = new DefaultLayouts.DefaultLayoutWrapper.LayoutWrapper
|
||||
{
|
||||
Type = LayoutType.Custom.TypeToString(),
|
||||
Uuid = customLayoutListWrapper.CustomLayouts[0].Uuid,
|
||||
},
|
||||
},
|
||||
},
|
||||
};
|
||||
FancyZonesEditorHelper.Files.DefaultLayoutsIOHelper.WriteData(defaultLayouts.Serialize(defaultLayoutsListWrapper));
|
||||
|
||||
this.RestartScopeExe();
|
||||
Session.Find<Element>(customLayoutListWrapper.CustomLayouts[0].Name).Click();
|
||||
var defaultLayout = Session.Find<Element>(customLayoutListWrapper.CustomLayouts[0].Name);
|
||||
Assert.IsNotNull(defaultLayout);
|
||||
Assert.IsTrue(defaultLayout.Selected);
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
public void AppliedLayouts_NoLayoutsApplied_TemplateDefaultLayout()
|
||||
{
|
||||
InitFileData();
|
||||
EditorParameters editorParameters = new EditorParameters();
|
||||
ParamsWrapper parameters = new ParamsWrapper
|
||||
{
|
||||
ProcessId = 1,
|
||||
SpanZonesAcrossMonitors = false,
|
||||
Monitors = new List<NativeMonitorDataWrapper>
|
||||
{
|
||||
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,
|
||||
},
|
||||
},
|
||||
};
|
||||
FancyZonesEditorHelper.Files.ParamsIOHelper.WriteData(editorParameters.Serialize(parameters));
|
||||
|
||||
FancyZonesEditorHelper.Files.DefaultLayoutsIOHelper.RestoreData();
|
||||
DefaultLayouts defaultLayouts = new DefaultLayouts();
|
||||
DefaultLayouts.DefaultLayoutsListWrapper defaultLayoutsListWrapper = new DefaultLayouts.DefaultLayoutsListWrapper
|
||||
{
|
||||
DefaultLayouts = new List<DefaultLayouts.DefaultLayoutWrapper>
|
||||
{
|
||||
new DefaultLayouts.DefaultLayoutWrapper
|
||||
{
|
||||
MonitorConfiguration = MonitorConfigurationType.Horizontal.TypeToString(),
|
||||
Layout = new DefaultLayouts.DefaultLayoutWrapper.LayoutWrapper
|
||||
{
|
||||
Type = LayoutType.Grid.TypeToString(),
|
||||
ZoneCount = 6,
|
||||
ShowSpacing = true,
|
||||
Spacing = 5,
|
||||
SensitivityRadius = 20,
|
||||
},
|
||||
},
|
||||
},
|
||||
};
|
||||
FancyZonesEditorHelper.Files.DefaultLayoutsIOHelper.WriteData(defaultLayouts.Serialize(defaultLayoutsListWrapper));
|
||||
|
||||
this.RestartScopeExe();
|
||||
|
||||
Session.Find<Element>(TestConstants.TemplateLayoutNames[LayoutType.Grid]).Click();
|
||||
var defaultLayout = Session.Find<Element>(TestConstants.TemplateLayoutNames[LayoutType.Grid]);
|
||||
Assert.IsNotNull(defaultLayout);
|
||||
Assert.IsTrue(defaultLayout.Selected);
|
||||
|
||||
// check the number of zones and spacing
|
||||
Session.Find<Element>(TestConstants.TemplateLayoutNames[LayoutType.Grid]).Find<Button>(By.AccessibilityId(AccessibilityId.EditLayoutButton)).Click();
|
||||
Assert.AreEqual(defaultLayoutsListWrapper.DefaultLayouts[0].Layout.ZoneCount, int.Parse(Session.Find<Element>(By.AccessibilityId(AccessibilityId.TemplateZoneSlider))?.Text!, CultureInfo.InvariantCulture));
|
||||
Assert.AreEqual(defaultLayoutsListWrapper.DefaultLayouts[0].Layout.Spacing, int.Parse(Session.Find<Element>(By.AccessibilityId(AccessibilityId.SpacingSlider))?.Text!, CultureInfo.InvariantCulture));
|
||||
Assert.AreEqual(defaultLayoutsListWrapper.DefaultLayouts[0].Layout.ShowSpacing, Session.Find<Element>(By.AccessibilityId(AccessibilityId.SpacingSlider))?.Enabled);
|
||||
Assert.AreEqual(defaultLayoutsListWrapper.DefaultLayouts[0].Layout.ShowSpacing, Session.Find<Element>(By.AccessibilityId(AccessibilityId.SpacingToggle))?.Selected);
|
||||
Assert.AreEqual(defaultLayoutsListWrapper.DefaultLayouts[0].Layout.SensitivityRadius, int.Parse(Session.Find<Element>(By.AccessibilityId(AccessibilityId.SensitivitySlider))?.Text!, CultureInfo.InvariantCulture));
|
||||
Assert.IsNotNull(Session.Find<Element>(By.AccessibilityId(AccessibilityId.HorizontalDefaultButtonChecked)));
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
public void AppliedLayouts_VerifyDisconnectedMonitorsLayoutsAreNotChanged()
|
||||
{
|
||||
InitFileData();
|
||||
EditorParameters editorParameters = new EditorParameters();
|
||||
ParamsWrapper parameters = new ParamsWrapper
|
||||
{
|
||||
ProcessId = 1,
|
||||
SpanZonesAcrossMonitors = false,
|
||||
Monitors = new List<NativeMonitorDataWrapper>
|
||||
{
|
||||
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,
|
||||
},
|
||||
},
|
||||
};
|
||||
FancyZonesEditorHelper.Files.ParamsIOHelper.WriteData(editorParameters.Serialize(parameters));
|
||||
|
||||
AppliedLayouts appliedLayouts = new AppliedLayouts();
|
||||
AppliedLayouts.AppliedLayoutsListWrapper appliedLayoutsWrapper = new AppliedLayouts.AppliedLayoutsListWrapper
|
||||
{
|
||||
AppliedLayouts = new List<AppliedLayouts.AppliedLayoutWrapper>
|
||||
{
|
||||
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 = "{00000000-0000-0000-0000-000000000000}",
|
||||
Type = LayoutType.Focus.TypeToString(),
|
||||
ShowSpacing = true,
|
||||
Spacing = 10,
|
||||
ZoneCount = 4,
|
||||
SensitivityRadius = 30,
|
||||
},
|
||||
},
|
||||
new AppliedLayouts.AppliedLayoutWrapper
|
||||
{
|
||||
Device = new AppliedLayouts.AppliedLayoutWrapper.DeviceIdWrapper
|
||||
{
|
||||
Monitor = "monitor-3",
|
||||
MonitorInstance = "instance-id-3",
|
||||
SerialNumber = "serial-number-3",
|
||||
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,
|
||||
},
|
||||
},
|
||||
},
|
||||
};
|
||||
FancyZonesEditorHelper.Files.AppliedLayoutsIOHelper.WriteData(appliedLayouts.Serialize(appliedLayoutsWrapper));
|
||||
|
||||
this.RestartScopeExe();
|
||||
Session.Find<Element>(TestConstants.TemplateLayoutNames[LayoutType.Rows]).Click();
|
||||
|
||||
// check the file
|
||||
var data = appliedLayouts.Read(appliedLayouts.File);
|
||||
Assert.AreEqual(parameters.Monitors.Count + appliedLayoutsWrapper.AppliedLayouts.Count, data.AppliedLayouts.Count);
|
||||
|
||||
foreach (var monitor in parameters.Monitors)
|
||||
{
|
||||
Assert.IsNotNull(data.AppliedLayouts.Find(x => x.Device.Monitor == monitor.Monitor));
|
||||
}
|
||||
|
||||
foreach (var layout in appliedLayoutsWrapper.AppliedLayouts)
|
||||
{
|
||||
Assert.IsNotNull(data.AppliedLayouts.Find(x => x.Device.Monitor == layout.Device.Monitor));
|
||||
}
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
public void AppliedLayouts_VerifyOtherVirtualDesktopsAreNotChanged()
|
||||
{
|
||||
InitFileData();
|
||||
string virtualDesktop1 = "{11111111-1111-1111-1111-111111111111}";
|
||||
string virtualDesktop2 = "{22222222-2222-2222-2222-222222222222}";
|
||||
|
||||
EditorParameters editorParameters = new EditorParameters();
|
||||
ParamsWrapper parameters = new ParamsWrapper
|
||||
{
|
||||
ProcessId = 1,
|
||||
SpanZonesAcrossMonitors = false,
|
||||
Monitors = new List<NativeMonitorDataWrapper>
|
||||
{
|
||||
new NativeMonitorDataWrapper
|
||||
{
|
||||
Monitor = "monitor-1",
|
||||
MonitorInstanceId = "instance-id-1",
|
||||
MonitorSerialNumber = "serial-number-1",
|
||||
MonitorNumber = 1,
|
||||
VirtualDesktop = virtualDesktop1,
|
||||
Dpi = 96,
|
||||
LeftCoordinate = 0,
|
||||
TopCoordinate = 0,
|
||||
WorkAreaHeight = 1040,
|
||||
WorkAreaWidth = 1920,
|
||||
MonitorHeight = 1080,
|
||||
MonitorWidth = 1920,
|
||||
IsSelected = true,
|
||||
},
|
||||
},
|
||||
};
|
||||
FancyZonesEditorHelper.Files.ParamsIOHelper.WriteData(editorParameters.Serialize(parameters));
|
||||
|
||||
AppliedLayouts appliedLayouts = new AppliedLayouts();
|
||||
AppliedLayouts.AppliedLayoutsListWrapper appliedLayoutsWrapper = new AppliedLayouts.AppliedLayoutsListWrapper
|
||||
{
|
||||
AppliedLayouts = new List<AppliedLayouts.AppliedLayoutWrapper>
|
||||
{
|
||||
new AppliedLayouts.AppliedLayoutWrapper
|
||||
{
|
||||
Device = new AppliedLayouts.AppliedLayoutWrapper.DeviceIdWrapper
|
||||
{
|
||||
Monitor = "monitor-1",
|
||||
MonitorInstance = "instance-id-1",
|
||||
SerialNumber = "serial-number-1",
|
||||
MonitorNumber = 1,
|
||||
VirtualDesktop = virtualDesktop2,
|
||||
},
|
||||
AppliedLayout = new AppliedLayouts.AppliedLayoutWrapper.LayoutWrapper
|
||||
{
|
||||
Uuid = "{00000000-0000-0000-0000-000000000000}",
|
||||
Type = LayoutType.Focus.TypeToString(),
|
||||
ShowSpacing = true,
|
||||
Spacing = 10,
|
||||
ZoneCount = 4,
|
||||
SensitivityRadius = 30,
|
||||
},
|
||||
},
|
||||
},
|
||||
};
|
||||
FancyZonesEditorHelper.Files.AppliedLayoutsIOHelper.WriteData(appliedLayouts.Serialize(appliedLayoutsWrapper));
|
||||
|
||||
this.RestartScopeExe();
|
||||
Session.Find<Element>(TestConstants.TemplateLayoutNames[LayoutType.Rows]).Click();
|
||||
|
||||
// check the file
|
||||
var data = appliedLayouts.Read(appliedLayouts.File);
|
||||
Assert.AreEqual(parameters.Monitors.Count + appliedLayoutsWrapper.AppliedLayouts.Count, data.AppliedLayouts.Count);
|
||||
Assert.IsNotNull(data.AppliedLayouts.Find(x => x.Device.VirtualDesktop == virtualDesktop1));
|
||||
Assert.IsNotNull(data.AppliedLayouts.Find(x => x.Device.VirtualDesktop == virtualDesktop2));
|
||||
Assert.AreEqual(appliedLayoutsWrapper.AppliedLayouts[0].AppliedLayout.Type, data.AppliedLayouts.Find(x => x.Device.VirtualDesktop == virtualDesktop2).AppliedLayout.Type);
|
||||
Assert.AreEqual(LayoutType.Rows.TypeToString(), data.AppliedLayouts.Find(x => x.Device.VirtualDesktop == virtualDesktop1).AppliedLayout.Type);
|
||||
}
|
||||
|
||||
private void InitFileData()
|
||||
{
|
||||
EditorParameters editorParameters = new EditorParameters();
|
||||
ParamsWrapper parameters = new ParamsWrapper
|
||||
{
|
||||
ProcessId = 1,
|
||||
SpanZonesAcrossMonitors = false,
|
||||
Monitors = new List<NativeMonitorDataWrapper>
|
||||
{
|
||||
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));
|
||||
|
||||
DefaultLayouts defaultLayouts = new DefaultLayouts();
|
||||
DefaultLayouts.DefaultLayoutsListWrapper defaultLayoutsListWrapper = new DefaultLayouts.DefaultLayoutsListWrapper
|
||||
{
|
||||
DefaultLayouts = new List<DefaultLayouts.DefaultLayoutWrapper> { },
|
||||
};
|
||||
FancyZonesEditorHelper.Files.DefaultLayoutsIOHelper.WriteData(defaultLayouts.Serialize(defaultLayoutsListWrapper));
|
||||
|
||||
LayoutHotkeys layoutHotkeys = new LayoutHotkeys();
|
||||
LayoutHotkeys.LayoutHotkeysWrapper layoutHotkeysWrapper = new LayoutHotkeys.LayoutHotkeysWrapper
|
||||
{
|
||||
LayoutHotkeys = new List<LayoutHotkeys.LayoutHotkeyWrapper> { },
|
||||
};
|
||||
FancyZonesEditorHelper.Files.LayoutHotkeysIOHelper.WriteData(layoutHotkeys.Serialize(layoutHotkeysWrapper));
|
||||
|
||||
AppliedLayouts appliedLayouts = new AppliedLayouts();
|
||||
AppliedLayouts.AppliedLayoutsListWrapper appliedLayoutsWrapper = new AppliedLayouts.AppliedLayoutsListWrapper
|
||||
{
|
||||
AppliedLayouts = new List<AppliedLayouts.AppliedLayoutWrapper> { },
|
||||
};
|
||||
FancyZonesEditorHelper.Files.AppliedLayoutsIOHelper.WriteData(appliedLayouts.Serialize(appliedLayoutsWrapper));
|
||||
|
||||
CustomLayouts customLayouts = new CustomLayouts();
|
||||
CustomLayouts.CustomLayoutListWrapper customLayoutListWrapper = new CustomLayouts.CustomLayoutListWrapper
|
||||
{
|
||||
CustomLayouts = new List<CustomLayouts.CustomLayoutWrapper> { },
|
||||
};
|
||||
FancyZonesEditorHelper.Files.CustomLayoutsIOHelper.WriteData(customLayouts.Serialize(customLayoutListWrapper));
|
||||
|
||||
LayoutTemplates layoutTemplates = new LayoutTemplates();
|
||||
LayoutTemplates.TemplateLayoutsListWrapper templateLayoutsListWrapper = new LayoutTemplates.TemplateLayoutsListWrapper
|
||||
{
|
||||
LayoutTemplates = new List<LayoutTemplates.TemplateLayoutWrapper>
|
||||
{
|
||||
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));
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -28,6 +28,7 @@
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\FancyZonesEditorCommon\FancyZonesEditorCommon.csproj" />
|
||||
<ProjectReference Include="..\editor\FancyZonesEditor\FancyZonesEditor.csproj" />
|
||||
<ProjectReference Include="..\..\..\common\UITestAutomation\UITestAutomation.csproj" />
|
||||
</ItemGroup>
|
||||
</Project>
|
||||
@@ -0,0 +1,288 @@
|
||||
// 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 System.Collections.ObjectModel;
|
||||
using System.Globalization;
|
||||
using System.IO;
|
||||
using System.Reflection;
|
||||
using FancyZonesEditorCommon.Data;
|
||||
using Microsoft.FancyZonesEditor.UITests.Utils;
|
||||
using Microsoft.PowerToys.UITest;
|
||||
using Microsoft.VisualStudio.TestTools.UnitTesting;
|
||||
using ModernWpf.Controls;
|
||||
using OpenQA.Selenium.Appium.Windows;
|
||||
using OpenQA.Selenium.Interactions;
|
||||
|
||||
namespace Microsoft.FancyZonesEditor.UnitTests.Utils
|
||||
{
|
||||
public class FancyZonesEditorHelper
|
||||
{
|
||||
private static FancyZonesEditorFiles? _files;
|
||||
|
||||
public static FancyZonesEditorFiles Files
|
||||
{
|
||||
get
|
||||
{
|
||||
if (_files == null)
|
||||
{
|
||||
_files = new FancyZonesEditorFiles();
|
||||
}
|
||||
|
||||
return _files;
|
||||
}
|
||||
}
|
||||
|
||||
public static class AccessibilityId
|
||||
{
|
||||
// main window
|
||||
public const string MainWindow = "MainWindow1";
|
||||
public const string Monitors = "Monitors";
|
||||
public const string NewLayoutButton = "NewLayoutButton";
|
||||
|
||||
// layout card
|
||||
public const string EditLayoutButton = "EditLayoutButton";
|
||||
|
||||
// edit layout window: common for template and custom layouts
|
||||
public const string DialogTitle = "EditLayoutDialogTitle";
|
||||
public const string SensitivitySlider = "SensitivityInput";
|
||||
public const string SpacingSlider = "Spacing";
|
||||
public const string SpacingToggle = "spaceAroundSetting";
|
||||
public const string HorizontalDefaultButtonUnchecked = "SetLayoutAsHorizontalDefaultButton";
|
||||
public const string VerticalDefaultButtonUnchecked = "SetLayoutAsVerticalDefaultButton";
|
||||
public const string HorizontalDefaultButtonChecked = "HorizontalDefaultLayoutButton";
|
||||
public const string VerticalDefaultButtonChecked = "VerticalDefaultLayoutButton";
|
||||
|
||||
// edit template layout window
|
||||
public const string CopyTemplate = "createFromTemplateLayoutButton";
|
||||
public const string TemplateZoneSlider = "TemplateZoneCount";
|
||||
|
||||
// edit custom layout window
|
||||
public const string DuplicateLayoutButton = "duplicateLayoutButton";
|
||||
public const string DeleteLayoutButton = "deleteLayoutButton";
|
||||
public const string KeySelectionComboBox = "quickKeySelectionComboBox";
|
||||
public const string EditZonesButton = "editZoneLayoutButton";
|
||||
public const string DeleteTextButton = "DeleteButton";
|
||||
public const string HotkeyComboBox = "quickKeySelectionComboBox";
|
||||
public const string NewZoneButton = "newZoneButton";
|
||||
public const string TopRightCorner = "NEResize";
|
||||
|
||||
// layout creation dialog
|
||||
public const string GridRadioButton = "GridLayoutRadioButton";
|
||||
public const string CanvasRadioButton = "CanvasLayoutRadioButton";
|
||||
|
||||
// confirmation dialog
|
||||
public const string PrimaryButton = "PrimaryButton";
|
||||
public const string SecondaryButton = "SecondaryButton";
|
||||
}
|
||||
|
||||
public static class ElementName
|
||||
{
|
||||
public const string Save = "Save";
|
||||
public const string Cancel = "Cancel";
|
||||
|
||||
// context menu
|
||||
public const string Edit = "Edit";
|
||||
public const string EditZones = "Edit zones";
|
||||
public const string Delete = "Delete";
|
||||
public const string Duplicate = "Duplicate";
|
||||
public const string CreateCustomLayout = "Create custom layout";
|
||||
|
||||
// canvas layout editor
|
||||
public const string CanvasEditorWindow = "Canvas layout editor";
|
||||
|
||||
// grid layout editor
|
||||
public const string GridLayoutEditor = "Grid layout editor";
|
||||
public const string MergeZonesButton = "Merge zones";
|
||||
}
|
||||
|
||||
public static class ClassName
|
||||
{
|
||||
public const string ContextMenu = "ContextMenu";
|
||||
public const string TextBox = "TextBox";
|
||||
public const string Popup = "Popup";
|
||||
|
||||
// layout editor
|
||||
public const string CanvasZone = "CanvasZone";
|
||||
public const string GridZone = "GridZone";
|
||||
public const string Button = "Button";
|
||||
public const string Thumb = "Thumb";
|
||||
}
|
||||
|
||||
public static void ClickContextMenuItem(Session session, string layoutName, string menuItem)
|
||||
{
|
||||
session.Find<Element>(layoutName).Click(true);
|
||||
session.Find<Element>(By.ClassName(ClassName.ContextMenu)).Find<Element>(menuItem).Click();
|
||||
}
|
||||
|
||||
public static Element? GetZone(Session session, int zoneNumber, string zoneClassName)
|
||||
{
|
||||
var zones = session.FindAll<Element>(By.ClassName(zoneClassName));
|
||||
foreach (var zone in zones)
|
||||
{
|
||||
try
|
||||
{
|
||||
zone.Find<Element>(zoneNumber.ToString(CultureInfo.InvariantCulture));
|
||||
Assert.IsNotNull(zone, "zone not found");
|
||||
return zone;
|
||||
}
|
||||
catch
|
||||
{
|
||||
// required number not found in the zone
|
||||
}
|
||||
}
|
||||
|
||||
Assert.IsNotNull(zones, $"zoneClassName : {zoneClassName} not found");
|
||||
return null;
|
||||
}
|
||||
|
||||
public static void MergeGridZones(Session session, int zoneNumber1, int zoneNumber2)
|
||||
{
|
||||
var zone1 = GetZone(session, zoneNumber1, ClassName.GridZone);
|
||||
var zone2 = GetZone(session, zoneNumber2, ClassName.GridZone);
|
||||
Assert.IsNotNull(zone1, "first zone not found");
|
||||
Assert.IsNotNull(zone2, "second zone not found");
|
||||
if (zone1 == null || zone2 == null)
|
||||
{
|
||||
Assert.Fail("zone is null");
|
||||
return;
|
||||
}
|
||||
|
||||
zone1.Drag(zone2);
|
||||
|
||||
session.Find<Element>(ElementName.MergeZonesButton).Click();
|
||||
}
|
||||
|
||||
public static void MoveSplitter(Session session, int index, int xOffset, int yOffset)
|
||||
{
|
||||
var thumbs = session.FindAll<Element>(By.ClassName(ClassName.Thumb));
|
||||
if (thumbs.Count == 0 || index >= thumbs.Count)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
thumbs[index].Drag(xOffset, yOffset);
|
||||
Console.WriteLine($"Moving splitter {index} by ({xOffset}, {yOffset})");
|
||||
}
|
||||
|
||||
public static void ClickDeleteZone(Session session, int zoneNumber)
|
||||
{
|
||||
var zone = FancyZonesEditorHelper.GetZone(session, zoneNumber, ClassName.CanvasZone);
|
||||
Assert.IsNotNull(zone);
|
||||
var button = zone.Find<Button>(By.ClassName(ClassName.Button));
|
||||
Assert.IsNotNull(button);
|
||||
button.Click();
|
||||
}
|
||||
|
||||
public static void InitFancyZonesLayout()
|
||||
{
|
||||
// prepare files to launch Editor without errors
|
||||
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,
|
||||
},
|
||||
},
|
||||
};
|
||||
FancyZonesEditorHelper.Files.ParamsIOHelper.WriteData(editorParameters.Serialize(parameters));
|
||||
|
||||
LayoutTemplates layoutTemplates = new LayoutTemplates();
|
||||
LayoutTemplates.TemplateLayoutsListWrapper templateLayoutsListWrapper = new LayoutTemplates.TemplateLayoutsListWrapper
|
||||
{
|
||||
LayoutTemplates = new List<LayoutTemplates.TemplateLayoutWrapper>
|
||||
{
|
||||
new LayoutTemplates.TemplateLayoutWrapper
|
||||
{
|
||||
Type = Constants.TemplateLayoutJsonTags[Constants.TemplateLayout.Empty],
|
||||
},
|
||||
new LayoutTemplates.TemplateLayoutWrapper
|
||||
{
|
||||
Type = Constants.TemplateLayoutJsonTags[Constants.TemplateLayout.Focus],
|
||||
ZoneCount = 10,
|
||||
},
|
||||
new LayoutTemplates.TemplateLayoutWrapper
|
||||
{
|
||||
Type = Constants.TemplateLayoutJsonTags[Constants.TemplateLayout.Rows],
|
||||
ZoneCount = 2,
|
||||
ShowSpacing = true,
|
||||
Spacing = 10,
|
||||
SensitivityRadius = 10,
|
||||
},
|
||||
new LayoutTemplates.TemplateLayoutWrapper
|
||||
{
|
||||
Type = Constants.TemplateLayoutJsonTags[Constants.TemplateLayout.Columns],
|
||||
ZoneCount = 2,
|
||||
ShowSpacing = true,
|
||||
Spacing = 20,
|
||||
SensitivityRadius = 20,
|
||||
},
|
||||
new LayoutTemplates.TemplateLayoutWrapper
|
||||
{
|
||||
Type = Constants.TemplateLayoutJsonTags[Constants.TemplateLayout.Grid],
|
||||
ZoneCount = 4,
|
||||
ShowSpacing = false,
|
||||
Spacing = 10,
|
||||
SensitivityRadius = 30,
|
||||
},
|
||||
new LayoutTemplates.TemplateLayoutWrapper
|
||||
{
|
||||
Type = Constants.TemplateLayoutJsonTags[Constants.TemplateLayout.PriorityGrid],
|
||||
ZoneCount = 3,
|
||||
ShowSpacing = true,
|
||||
Spacing = 1,
|
||||
SensitivityRadius = 40,
|
||||
},
|
||||
},
|
||||
};
|
||||
FancyZonesEditorHelper.Files.LayoutTemplatesIOHelper.WriteData(layoutTemplates.Serialize(templateLayoutsListWrapper));
|
||||
|
||||
CustomLayouts customLayouts = new CustomLayouts();
|
||||
CustomLayouts.CustomLayoutListWrapper customLayoutListWrapper = new CustomLayouts.CustomLayoutListWrapper
|
||||
{
|
||||
CustomLayouts = new List<CustomLayouts.CustomLayoutWrapper> { },
|
||||
};
|
||||
FancyZonesEditorHelper.Files.CustomLayoutsIOHelper.WriteData(customLayouts.Serialize(customLayoutListWrapper));
|
||||
|
||||
DefaultLayouts defaultLayouts = new DefaultLayouts();
|
||||
DefaultLayouts.DefaultLayoutsListWrapper defaultLayoutsListWrapper = new DefaultLayouts.DefaultLayoutsListWrapper
|
||||
{
|
||||
DefaultLayouts = new List<DefaultLayouts.DefaultLayoutWrapper> { },
|
||||
};
|
||||
FancyZonesEditorHelper.Files.DefaultLayoutsIOHelper.WriteData(defaultLayouts.Serialize(defaultLayoutsListWrapper));
|
||||
|
||||
LayoutHotkeys layoutHotkeys = new LayoutHotkeys();
|
||||
LayoutHotkeys.LayoutHotkeysWrapper layoutHotkeysWrapper = new LayoutHotkeys.LayoutHotkeysWrapper
|
||||
{
|
||||
LayoutHotkeys = new List<LayoutHotkeys.LayoutHotkeyWrapper> { },
|
||||
};
|
||||
FancyZonesEditorHelper.Files.LayoutHotkeysIOHelper.WriteData(layoutHotkeys.Serialize(layoutHotkeysWrapper));
|
||||
|
||||
AppliedLayouts appliedLayouts = new AppliedLayouts();
|
||||
AppliedLayouts.AppliedLayoutsListWrapper appliedLayoutsWrapper = new AppliedLayouts.AppliedLayoutsListWrapper
|
||||
{
|
||||
AppliedLayouts = new List<AppliedLayouts.AppliedLayoutWrapper> { },
|
||||
};
|
||||
FancyZonesEditorHelper.Files.AppliedLayoutsIOHelper.WriteData(appliedLayouts.Serialize(appliedLayoutsWrapper));
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,108 @@
|
||||
## This is for tracking UI-Tests migration progress for FancyZones Editor Module
|
||||
Refer to [release check list] (https://github.com/microsoft/PowerToys/blob/releaseChecklist/doc/releases/tests-checklist-template.md) for all manual tests.
|
||||
|
||||
### Existing Manual Test-cases run by previous PowerToys owner
|
||||
For existing manual test-cases, we will convert them to UI-Tests and run them in CI and Release pipeline
|
||||
|
||||
* Launch Host File Editor:
|
||||
- [ ] Open editor from the settings
|
||||
- [ ] Open editor with a shortcut
|
||||
- [ ] Create a new layout (grid and canvas)
|
||||
- [ ] Duplicate a template and a custom layout
|
||||
- [ ] Delete layout
|
||||
- [ ] Edit templates (number of zones, spacing, distance to highlight adjacent zones). Verify after reopening the editor that saved settings are kept the same.
|
||||
- [ ] Edit canvas layout: zones size and position, create or delete zones.
|
||||
- [ ] Edit grid layout: split, merge, resize zones.
|
||||
- [ ] Check Save and apply and Cancel buttons behavior after editing.
|
||||
- [ ] Assign a layout to each monitor.
|
||||
- [ ] Assign keys to quickly switch layouts (custom layouts only), Win + Ctrl + Alt + number.
|
||||
- [ ] Assign horizontal and vertical default layouts
|
||||
- [ ] Test duplicate layout focus
|
||||
- Select any layout X in 'Templates' or 'Custom' section by click left mouse button
|
||||
- Mouse right button click on any layout Y in 'Templates' or 'Custom' sections
|
||||
- Duplicate it by clicking 'Create custom layout' (Templates section) or 'Duplicate' in 'Custom' section
|
||||
- Expect the layout Y is duplicated
|
||||
|
||||
### Additional UI-Tests cases
|
||||
|
||||
- [ ] Add test data and start → verify data is correct (custom layouts, template layouts, defaults, shortcut keys)
|
||||
|
||||
- [ ] Create a new canvas - verify layout exists
|
||||
|
||||
- [ ] Create a new canvas - cancel - doesn’t exist
|
||||
|
||||
- [ ] Create a new grid - verify the layout exists
|
||||
|
||||
- [ ] Create a new grid - cancel - doesn’t exist
|
||||
|
||||
- [ ] Duplicate template by button (+ check default)
|
||||
|
||||
- [ ] Duplicate template by menu (+ check default)
|
||||
|
||||
- [ ] Duplicate custom by button (+ check shortcut key and default)
|
||||
|
||||
- [ ] Duplicate custom by menu (+ check shortcut key and default)
|
||||
|
||||
- [ ] Delete non-applied layout
|
||||
|
||||
- [ ] Delete applied layout
|
||||
|
||||
- [ ] Delete-cancel
|
||||
|
||||
- [ ] Delete from context menu
|
||||
|
||||
- [ ] Delete: hotkey released
|
||||
|
||||
- [ ] Delete: default layout reset to default-default
|
||||
|
||||
- [ ] Edit template and save
|
||||
|
||||
- [ ] Edit template and cancel
|
||||
|
||||
- [ ] Edit custom and save
|
||||
|
||||
- [ ] Edit custom and cancel
|
||||
|
||||
- [ ] Edit canvas: add zone
|
||||
|
||||
- [ ] Edit canvas: delete zone
|
||||
|
||||
- [ ] Edit canvas: move zone
|
||||
|
||||
- [ ] Edit canvas: resize zone
|
||||
|
||||
- [ ] Edit grid: split zone
|
||||
|
||||
- [ ] Edit grid: merge zones
|
||||
|
||||
- [ ] Edit grid: move splitter
|
||||
|
||||
- [ ] UI Init: assigned layouts selected
|
||||
|
||||
- [ ] UI Init: applied default - check params
|
||||
|
||||
- [ ] UI Init: assigned custom layout, but id not found
|
||||
|
||||
- [ ] Assign the same template but with different params to monitors
|
||||
|
||||
- [ ] Assign layout on each monitor
|
||||
|
||||
- [ ] Assign custom
|
||||
|
||||
- [ ] Assign template
|
||||
|
||||
- [ ] Assign shortcut key and save
|
||||
|
||||
- [ ] Assign shortcut key and cancel
|
||||
|
||||
- [ ] Reset shortcut key and save
|
||||
|
||||
- [ ] Reset shortcut key and cancel
|
||||
|
||||
- [ ] Set default layout + verify both prev and current after reopening
|
||||
|
||||
- [ ] applied-layouts.json keeps info about not connected devices - verify they’re present after closing
|
||||
|
||||
- [ ] applied-layouts.json keeps info about other virtual desktops
|
||||
|
||||
- [ ] first launch without custom-layouts.json, default-layouts.json, layout-hotkeys.json and layout-templates.json
|
||||
@@ -335,6 +335,7 @@
|
||||
</ScrollViewer.DataContext>
|
||||
<Grid>
|
||||
<ui:GridView
|
||||
x:Name="Monitors"
|
||||
HorizontalAlignment="Center"
|
||||
IsItemClickEnabled="True"
|
||||
IsSelectionEnabled="True"
|
||||
|
||||
@@ -0,0 +1,59 @@
|
||||
// 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 FancyZonesEditor.Models
|
||||
{
|
||||
public static class LayoutTypeEnumExtension
|
||||
{
|
||||
private const string BlankJsonTag = "blank";
|
||||
private const string FocusJsonTag = "focus";
|
||||
private const string RowsJsonTag = "rows";
|
||||
private const string ColumnsJsonTag = "columns";
|
||||
private const string GridJsonTag = "grid";
|
||||
private const string PriorityGridJsonTag = "priority-grid";
|
||||
private const string CustomLayoutJsonTag = "custom";
|
||||
|
||||
public static string TypeToString(this LayoutType value)
|
||||
{
|
||||
switch (value)
|
||||
{
|
||||
case LayoutType.Blank:
|
||||
return BlankJsonTag;
|
||||
case LayoutType.Focus:
|
||||
return FocusJsonTag;
|
||||
case LayoutType.Rows:
|
||||
return RowsJsonTag;
|
||||
case LayoutType.Columns:
|
||||
return ColumnsJsonTag;
|
||||
case LayoutType.Grid:
|
||||
return GridJsonTag;
|
||||
case LayoutType.PriorityGrid:
|
||||
return PriorityGridJsonTag;
|
||||
}
|
||||
|
||||
return CustomLayoutJsonTag;
|
||||
}
|
||||
|
||||
public static LayoutType TypeFromString(string value)
|
||||
{
|
||||
switch (value)
|
||||
{
|
||||
case BlankJsonTag:
|
||||
return LayoutType.Blank;
|
||||
case FocusJsonTag:
|
||||
return LayoutType.Focus;
|
||||
case RowsJsonTag:
|
||||
return LayoutType.Rows;
|
||||
case ColumnsJsonTag:
|
||||
return LayoutType.Columns;
|
||||
case GridJsonTag:
|
||||
return LayoutType.Grid;
|
||||
case PriorityGridJsonTag:
|
||||
return LayoutType.PriorityGrid;
|
||||
}
|
||||
|
||||
return LayoutType.Custom;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,38 @@
|
||||
// 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 FancyZonesEditor.Models
|
||||
{
|
||||
public static class MonitorConfigurationTypeEnumExtensions
|
||||
{
|
||||
private const string HorizontalJsonTag = "horizontal";
|
||||
private const string VerticalJsonTag = "vertical";
|
||||
|
||||
public static string TypeToString(this MonitorConfigurationType value)
|
||||
{
|
||||
switch (value)
|
||||
{
|
||||
case MonitorConfigurationType.Horizontal:
|
||||
return HorizontalJsonTag;
|
||||
case MonitorConfigurationType.Vertical:
|
||||
return VerticalJsonTag;
|
||||
}
|
||||
|
||||
return HorizontalJsonTag;
|
||||
}
|
||||
|
||||
public static MonitorConfigurationType TypeFromString(string value)
|
||||
{
|
||||
switch (value)
|
||||
{
|
||||
case HorizontalJsonTag:
|
||||
return MonitorConfigurationType.Horizontal;
|
||||
case VerticalJsonTag:
|
||||
return MonitorConfigurationType.Vertical;
|
||||
}
|
||||
|
||||
return MonitorConfigurationType.Horizontal;
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user