-
Notifications
You must be signed in to change notification settings - Fork 6.8k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Zhaopeng Wang
committed
Mar 5, 2025
1 parent
8007ff9
commit ad3cde7
Showing
1 changed file
with
242 additions
and
0 deletions.
There are no files selected for viewing
242 changes: 242 additions & 0 deletions
242
src/modules/fancyzones/UITests-FancyZonesEditor/CreateLayoutTests.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,242 @@ | ||
// 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; | ||
using static Microsoft.FancyZonesEditor.UnitTests.Utils.FancyZonesEditorSession; | ||
|
||
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, | ||
}, | ||
}, | ||
}; | ||
FancyZonesEditorSession.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, | ||
}, | ||
}, | ||
}; | ||
FancyZonesEditorSession.Files.LayoutTemplatesIOHelper.WriteData(layoutTemplates.Serialize(templateLayoutsListWrapper)); | ||
|
||
CustomLayouts customLayouts = new CustomLayouts(); | ||
CustomLayouts.CustomLayoutListWrapper customLayoutListWrapper = new CustomLayouts.CustomLayoutListWrapper | ||
{ | ||
CustomLayouts = new List<CustomLayouts.CustomLayoutWrapper> { }, | ||
}; | ||
FancyZonesEditorSession.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)); | ||
|
||
LayoutHotkeys layoutHotkeys = new LayoutHotkeys(); | ||
LayoutHotkeys.LayoutHotkeysWrapper layoutHotkeysWrapper = new LayoutHotkeys.LayoutHotkeysWrapper | ||
{ | ||
LayoutHotkeys = new List<LayoutHotkeys.LayoutHotkeyWrapper> { }, | ||
}; | ||
FancyZonesEditorSession.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)); | ||
|
||
this.RestartScopeExe(); | ||
} | ||
|
||
[TestCleanup] | ||
public void TestCleanup() | ||
{ | ||
FancyZonesEditorSession.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(); | ||
System.Threading.Thread.Sleep(1000); | ||
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); | ||
} | ||
} | ||
} |
ad3cde7
There was a problem hiding this comment.
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 WVCTo 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?):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.