Skip to content

Commit

Permalink
add DefaultLayoutsTest
Browse files Browse the repository at this point in the history
  • Loading branch information
Zhaopeng Wang committed Mar 5, 2025
1 parent 7a511ac commit 1d704e3
Show file tree
Hide file tree
Showing 3 changed files with 311 additions and 15 deletions.
2 changes: 1 addition & 1 deletion src/common/UITestAutomation/UITestBase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ public void TestInit()
[TestCleanup]
public void TestClean()
{
// this.sessionHelper.Cleanup();
this.sessionHelper.Cleanup();
}

/// <summary>
Expand Down
307 changes: 293 additions & 14 deletions src/modules/fancyzones/UITests-FancyZonesEditor/DefaultLayoutsTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,16 @@
// See the LICENSE file in the project root for more information.

using System.Collections.Generic;
using System.Xml.Linq;
using FancyZonesEditor.Models;
using FancyZonesEditorCommon.Data;
using Microsoft.FancyZonesEditor.UITests;
using Microsoft.FancyZonesEditor.UnitTests.Utils;
using Microsoft.PowerToys.UITest;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using Windows.UI;
using static FancyZonesEditorCommon.Data.CustomLayouts;
using static FancyZonesEditorCommon.Data.DefaultLayouts;
using static FancyZonesEditorCommon.Data.EditorParameters;
using static Microsoft.FancyZonesEditor.UnitTests.Utils.FancyZonesEditorHelper;

namespace Microsoft.FancyZonesEditor.UITests
{
Expand All @@ -19,7 +22,108 @@ public class DefaultLayoutsTest : UITestBase
public DefaultLayoutsTest()
: base(PowerToysModule.FancyZone)
{
FancyZonesEditorHelper.Files.ParamsIOHelper.RestoreData();
}

private static readonly string Vertical = MonitorConfigurationType.Vertical.TypeToString();
private static readonly string Horizontal = MonitorConfigurationType.Horizontal.TypeToString();

private static readonly CustomLayoutListWrapper CustomLayouts = new CustomLayoutListWrapper
{
CustomLayouts = new List<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
{
Expand All @@ -34,7 +138,7 @@ public DefaultLayoutsTest()
MonitorSerialNumber = "serial-number-1",
MonitorNumber = 1,
VirtualDesktop = "{FF34D993-73F3-4B8C-AA03-73730A01D6A8}",
Dpi = 96,
Dpi = 192,
LeftCoordinate = 0,
TopCoordinate = 0,
WorkAreaHeight = 1040,
Expand Down Expand Up @@ -62,23 +166,198 @@ public DefaultLayoutsTest()
},
};
FancyZonesEditorHelper.Files.ParamsIOHelper.WriteData(editorParameters.Serialize(parameters));

CustomLayouts customLayouts = new CustomLayouts();
FancyZonesEditorHelper.Files.CustomLayoutsIOHelper.WriteData(customLayouts.Serialize(CustomLayouts));

LayoutTemplates layoutTemplates = new LayoutTemplates();
LayoutTemplates.TemplateLayoutsListWrapper templateLayoutsListWrapper = new LayoutTemplates.TemplateLayoutsListWrapper
{
LayoutTemplates = new List<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 ClickMonitor()
public void Initialize()
{
Assert.IsNotNull(Session.Find<Element>("Monitor 1"));
Assert.IsNotNull(Session.Find<Element>("Monitor 2"));
CheckTemplateLayouts(LayoutType.Grid, null);
CheckCustomLayouts(string.Empty, CustomLayouts.CustomLayouts[0].Uuid);
}

// verify that the monitor 1 is selected initially
Assert.IsTrue(Session.Find<Element>("Monitor 1").Selected);
Assert.IsFalse(Session.Find<Element>("Monitor 2").Selected);
[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));
}

Session.Find<Element>("Monitor 2").Click();
Assert.IsNotNull(horizontalDefaultButton, "Incorrect horizontal custom layout set at " + layout.Name);
Assert.IsNotNull(verticalDefaultButton, "Incorrect vertical custom layout set at " + layout.Name);

// 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);
Session.Find<Button>(ElementName.Cancel).Click();
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -215,5 +215,22 @@ public void OpenContextMenu() // verify the context menu is opened
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);
}
}
}

1 comment on commit 1d704e3

@github-actions
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@check-spelling-bot Report

🔴 Please review

See the 📜action log or 📝 job summary for details.

Unrecognized words (2)

Initializet
Tes

These words are not needed and should be removed ahk AMPROPERTY AMPROPSETID Breadcrumb CDEF comdef ddf devenum DEVMON DEVSOURCE DGR DIIRFLAG dshow DVH DVHD DVSD DVSL EData ERole fdw FILEINFOSIG Filtergraph Filterx HCERTSTORE IKs iljxck IYUV KSPROPERTY lcb ldx lld LONGLONG LTRB majortype makecab MEDIASUBTYPE mediatype mfplat mic mjpg Msimg msiquery ORAW outpin overlaywindow PAUDIO PINDIR Pnp ppmt previouscamera PROPBAG propvarutil reencoded REFGUID REGFILTER REGFILTERPINS REGPINTYPES regsvr shmem sizeread stl strsafe strutil subquery SYNCMFT TMPVAR vcdl vdi vid VIDCAP VIDEOINFOHEADER vih webcam wistd WVC

To accept these unrecognized words as correct and remove the previously acknowledged and now absent words, you could run the following commands

... in a clone of the [email protected]:microsoft/PowerToys.git repository
on the dev/zhaopengwang/test/37733-ui-test-fancyzones-editor branch (ℹ️ how do I use this?):

curl -s -S -L 'https://raw.githubusercontent.com/check-spelling/check-spelling/v0.0.24/apply.pl' |
perl - 'https://github.com/microsoft/PowerToys/actions/runs/13674552093/attempts/1'
If the flagged items are 🤯 false positives

If items relate to a ...

  • binary file (or some other file you wouldn't want to check at all).

    Please add a file path to the excludes.txt file matching the containing file.

    File paths are Perl 5 Regular Expressions - you can test yours before committing to verify it will match your files.

    ^ refers to the file's path from the root of the repository, so ^README\.md$ would exclude README.md (on whichever branch you're using).

  • well-formed pattern.

    If you can write a pattern that would match it,
    try adding it to the patterns.txt file.

    Patterns are Perl 5 Regular Expressions - you can test yours before committing to verify it will match your lines.

    Note that patterns can't match multiline strings.

Please sign in to comment.