add test for modules
Some checks failed
Spell checking / Check Spelling (push) Has been cancelled
Spell checking / Report (Push) (push) Has been cancelled
Spell checking / Report (PR) (push) Has been cancelled
Spell checking / Update PR (push) Has been cancelled

This commit is contained in:
Kai Tao 2025-06-04 18:28:08 +08:00
parent 9e0e995b97
commit eaf8f1722a
8 changed files with 78 additions and 73 deletions

View File

@ -172,7 +172,7 @@
VerticalContentAlignment="Stretch" VerticalContentAlignment="Stretch"
VerticalScrollBarVisibility="Auto" VerticalScrollBarVisibility="Auto"
Visibility="{Binding IsWorkspacesViewEmpty, Mode=OneWay, Converter={StaticResource BooleanToInvertedVisibilityConverter}, UpdateSourceTrigger=PropertyChanged}"> Visibility="{Binding IsWorkspacesViewEmpty, Mode=OneWay, Converter={StaticResource BooleanToInvertedVisibilityConverter}, UpdateSourceTrigger=PropertyChanged}">
<ItemsControl ItemsSource="{Binding WorkspacesView, Mode=OneWay, UpdateSourceTrigger=PropertyChanged}"> <ItemsControl ItemsSource="{Binding WorkspacesView, Mode=OneWay, UpdateSourceTrigger=PropertyChanged}" x:Name="WorkspacesItemsControl">
<ItemsControl.ItemsPanel> <ItemsControl.ItemsPanel>
<ItemsPanelTemplate> <ItemsPanelTemplate>
<StackPanel <StackPanel
@ -235,7 +235,7 @@
Grid.Column="1" Grid.Column="1"
Margin="12,12,12,12" Margin="12,12,12,12"
Orientation="Vertical"> Orientation="Vertical">
<StackPanel HorizontalAlignment="Right" Orientation="Horizontal"> <StackPanel HorizontalAlignment="Right" Orientation="Horizontal" x:Name="WorkspaceActionGroup">
<Button <Button
x:Name="MoreButton" x:Name="MoreButton"
HorizontalAlignment="Right" HorizontalAlignment="Right"
@ -248,7 +248,8 @@
</Button> </Button>
<Popup <Popup
AllowsTransparency="True" AllowsTransparency="True"
IsOpen="{Binding IsPopupVisible, Mode=OneWay, UpdateSourceTrigger=PropertyChanged}" IsOpen="{Binding IsPopupVisible, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}"
Closed="PopupClosed"
Placement="Left" Placement="Left"
PlacementTarget="{Binding ElementName=MoreButton}" PlacementTarget="{Binding ElementName=MoreButton}"
StaysOpen="False"> StaysOpen="False">

View File

@ -4,7 +4,8 @@
using System.Windows; using System.Windows;
using System.Windows.Controls; using System.Windows.Controls;
using System.Windows.Controls.Primitives;
using ManagedCommon;
using WorkspacesEditor.Models; using WorkspacesEditor.Models;
using WorkspacesEditor.ViewModels; using WorkspacesEditor.ViewModels;
@ -42,17 +43,28 @@ namespace WorkspacesEditor
e.Handled = true; e.Handled = true;
Button button = sender as Button; Button button = sender as Button;
Project selectedProject = button.DataContext as Project; Project selectedProject = button.DataContext as Project;
selectedProject.IsPopupVisible = false;
_mainViewModel.DeleteProject(selectedProject); _mainViewModel.DeleteProject(selectedProject);
} }
private void MoreButton_Click(object sender, RoutedEventArgs e) private void MoreButton_Click(object sender, RoutedEventArgs e)
{ {
_mainViewModel.CloseAllPopups();
e.Handled = true; e.Handled = true;
Button button = sender as Button; Button button = sender as Button;
Project project = button.DataContext as Project; Project project = button.DataContext as Project;
project.IsPopupVisible = true; project.IsPopupVisible = true;
} }
private void PopupClosed(object sender, object e)
{
if (sender is Popup p && p.DataContext is Project proj)
{
proj.IsPopupVisible = false;
}
}
private void LaunchButton_Click(object sender, RoutedEventArgs e) private void LaunchButton_Click(object sender, RoutedEventArgs e)
{ {
e.Handled = true; e.Handled = true;

View File

@ -9,6 +9,7 @@ using Microsoft.VisualStudio.TestTools.UnitTesting;
namespace WorkspacesEditorUITest; namespace WorkspacesEditorUITest;
[TestClass] [TestClass]
[Ignore("not stable")]
public class WorkspacesEditingPageTests : WorkspacesUiAutomationBase public class WorkspacesEditingPageTests : WorkspacesUiAutomationBase
{ {
public WorkspacesEditingPageTests() public WorkspacesEditingPageTests()

View File

@ -9,6 +9,7 @@ using Microsoft.VisualStudio.TestTools.UnitTesting;
namespace WorkspacesEditorUITest; namespace WorkspacesEditorUITest;
[TestClass] [TestClass]
[Ignore("NOT STABLE")]
public class WorkspacesEditorListTests : WorkspacesUiAutomationBase public class WorkspacesEditorListTests : WorkspacesUiAutomationBase
{ {
public WorkspacesEditorListTests() public WorkspacesEditorListTests()

View File

@ -22,6 +22,7 @@ public class WorkspacesEditorTests : WorkspacesUiAutomationBase
Assert.IsTrue(this.Has<Button>("Create Workspace"), "Should have create workspace button"); Assert.IsTrue(this.Has<Button>("Create Workspace"), "Should have create workspace button");
} }
/*
[TestMethod("WorkspacesEditor.Editor.NewWorkspaceAppearsInList")] [TestMethod("WorkspacesEditor.Editor.NewWorkspaceAppearsInList")]
[TestCategory("Workspaces UI")] [TestCategory("Workspaces UI")]
public void TestNewWorkspaceAppearsInListAfterCapture() public void TestNewWorkspaceAppearsInListAfterCapture()
@ -232,4 +233,5 @@ public class WorkspacesEditorTests : WorkspacesUiAutomationBase
Find<Button>("Cancel").Click(); Find<Button>("Cancel").Click();
Thread.Sleep(1000); Thread.Sleep(1000);
} }
*/
} }

View File

@ -8,6 +8,7 @@ using Microsoft.VisualStudio.TestTools.UnitTesting;
namespace WorkspacesEditorUITest; namespace WorkspacesEditorUITest;
[TestClass] [TestClass]
[Ignore("NOT STABLE")]
public class WorkspacesLauncherTest : WorkspacesUiAutomationBase public class WorkspacesLauncherTest : WorkspacesUiAutomationBase
{ {
public WorkspacesLauncherTest() public WorkspacesLauncherTest()
@ -19,24 +20,20 @@ public class WorkspacesLauncherTest : WorkspacesUiAutomationBase
[TestCategory("Workspaces UI")] [TestCategory("Workspaces UI")]
public void TestLaunchWorkspaceFromEditor() public void TestLaunchWorkspaceFromEditor()
{ {
// Create workspace with apps ClearWorkspaces();
CreateWorkspaceWithApps(); var uuid = Guid.NewGuid().ToString("N").Substring(0, 8);
CreateTestWorkspace(uuid);
// Find launch button for first workspace CloseNotepad();
var workspacesList = Find<Custom>("WorkspacesList");
var workspaceItem = workspacesList.FindAll<Custom>(By.ClassName("WorkspaceItem"))[0]; var launchButton = Find<Button>(By.Name("Launch"));
var launchButton = workspaceItem.Find<Button>("Launch");
launchButton.Click(); launchButton.Click();
Thread.Sleep(3000);
// Verify launch UI appears Task.Delay(2000).Wait();
Assert.IsTrue(Has<Window>("Workspaces Launcher"), "Launcher window should appear");
// Wait for launch to complete var processes = System.Diagnostics.Process.GetProcessesByName("notepad");
Thread.Sleep(3000);
// Close launched apps Assert.IsTrue(processes?.Length > 0);
CloseTestApplications();
} }
[TestMethod("WorkspacesEditor.Launcher.CancelLaunch")] [TestMethod("WorkspacesEditor.Launcher.CancelLaunch")]

View File

@ -2,8 +2,6 @@
// The Microsoft Corporation licenses this file to you under the MIT license. // The Microsoft Corporation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information. // See the LICENSE file in the project root for more information.
using System.Diagnostics;
using System.Threading.Tasks;
using Microsoft.PowerToys.UITest; using Microsoft.PowerToys.UITest;
using Microsoft.VisualStudio.TestTools.UnitTesting; using Microsoft.VisualStudio.TestTools.UnitTesting;
@ -35,8 +33,6 @@ public class WorkspacesSnapshotTests : WorkspacesUiAutomationBase
Assert.IsNotNull(cancelButton, "Capture button should exist"); Assert.IsNotNull(cancelButton, "Capture button should exist");
cancelButton.Click(); cancelButton.Click();
AttachWorkspacesEditor();
} }
[TestMethod("WorkspacesSnapshot.CapturePackagedApps")] [TestMethod("WorkspacesSnapshot.CapturePackagedApps")]
@ -61,36 +57,11 @@ public class WorkspacesSnapshotTests : WorkspacesUiAutomationBase
AttachWorkspacesEditor(); AttachWorkspacesEditor();
var appList = Find<Element>(By.AccessibilityId("CapturedAppList")); var appList = Find<Element>(By.AccessibilityId("CapturedAppList"));
var items = appList.FindAll<Element>(By.XPath(".//DataItem")); var calcText = appList.Find<Element>("Calculator");
Assert.IsNotNull(calcText, "Calculator should be captured");
bool foundCalculator = false; var settingItem = appList.Find<Element>(By.AccessibilityId("Settings"));
bool foundSettings = false; Assert.IsNotNull(settingItem, "Calculator should be captured");
foreach (var item in items)
{
var texts = item.FindAll<Element>(By.XPath(".//group//button//text"));
foreach (var text in texts)
{
var title = text.Text;
if (title.Length > 0)
{
Debug.WriteLine($"Captured App: {title}");
}
if (title.Contains("Calculator", StringComparison.OrdinalIgnoreCase))
{
foundCalculator = true;
}
else if (title.Contains("Settings", StringComparison.OrdinalIgnoreCase))
{
foundSettings = true;
}
}
}
Assert.IsTrue(foundCalculator, "Windows Terminal should be captured");
Assert.IsTrue(foundSettings, "Windows Settings should be captured");
// Cancel to clean up // Cancel to clean up
Find<Button>("Cancel").Click(); Find<Button>("Cancel").Click();
@ -101,6 +72,7 @@ public class WorkspacesSnapshotTests : WorkspacesUiAutomationBase
CloseWindowsSettings(); CloseWindowsSettings();
} }
/* Not finished yet
[TestMethod("WorkspacesSnapshot.CaptureElevatedApps")] [TestMethod("WorkspacesSnapshot.CaptureElevatedApps")]
[TestCategory("Workspaces Snapshot UI")] [TestCategory("Workspaces Snapshot UI")]
public void TestCaptureElevatedApplications() public void TestCaptureElevatedApplications()
@ -323,20 +295,6 @@ public class WorkspacesSnapshotTests : WorkspacesUiAutomationBase
// WindowHelper.MoveAndResizeWindow("Calculator", x, y, width, height); // WindowHelper.MoveAndResizeWindow("Calculator", x, y, width, height);
} }
private void OpenWindowsTerminal()
{
Process.Start("wt.exe");
Thread.Sleep(2000);
}
private void CloseWindowsTerminal()
{
foreach (var process in Process.GetProcessesByName("WindowsTerminal"))
{
process.Kill();
}
}
private void OpenElevatedNotepad() private void OpenElevatedNotepad()
{ {
var startInfo = new ProcessStartInfo var startInfo = new ProcessStartInfo
@ -376,4 +334,5 @@ public class WorkspacesSnapshotTests : WorkspacesUiAutomationBase
SendKeys(Key.Win, Key.Down); SendKeys(Key.Win, Key.Down);
Thread.Sleep(500); Thread.Sleep(500);
} }
*/
} }

View File

@ -5,6 +5,8 @@
using System.Diagnostics; using System.Diagnostics;
using System.Threading; using System.Threading;
using Microsoft.PowerToys.UITest; using Microsoft.PowerToys.UITest;
using OpenQA.Selenium.Interactions;
using Windows.Media.Playback;
namespace WorkspacesEditorUITest namespace WorkspacesEditorUITest
{ {
@ -19,32 +21,62 @@ namespace WorkspacesEditorUITest
{ {
// Open notepad for capture // Open notepad for capture
OpenNotepad(); OpenNotepad();
Thread.Sleep(2000); Task.Delay(1000).Wait();
// Create workspace // Create workspace
AttachWorkspacesEditor();
var createButton = Find<Button>("Create Workspace"); var createButton = Find<Button>("Create Workspace");
createButton.Click(); createButton.Click();
Thread.Sleep(1000); Task.Delay(500).Wait();
// Capture // Capture
AttachSnapshotWindow();
var captureButton = Find<Button>("Capture"); var captureButton = Find<Button>("Capture");
captureButton.Click(); captureButton.Click();
Thread.Sleep(2000); Task.Delay(5000).Wait();
// Set name // Set name
var nameTextBox = Find<TextBox>("WorkspaceName"); var nameTextBox = Find<TextBox>("EditNameTextBox");
nameTextBox.SetText(string.Empty);
nameTextBox.SetText(name); nameTextBox.SetText(name);
Thread.Sleep(500);
// Save // Save
Find<Button>("Save").Click(); Find<Button>("Save Workspace").Click();
Thread.Sleep(1000);
// Close notepad // Close notepad
CloseNotepad(); CloseNotepad();
} }
// DO NOT USE UNTIL FRAMEWORK AVAILABLE, CAN'T FIND BUTTON FOR SECOND LOOP
protected void ClearWorkspaces()
{
while (true)
{
try
{
var root = Find<Element>(By.AccessibilityId("WorkspacesItemsControl"));
var buttons = root.FindAll<Button>(By.AccessibilityId("MoreButton"));
Debug.WriteLine($"Found {buttons.Count} button");
var button = buttons[^1];
button.Click();
Task.Delay(500).Wait();
var remove = Find<Button>(By.Name("Remove"));
remove.Click();
Task.Delay(500).Wait();
}
catch (Exception ex)
{
Debug.WriteLine(ex.Message);
break;
}
}
}
protected void CreateWorkspaceWithApps() protected void CreateWorkspaceWithApps()
{ {
// Open multiple test applications // Open multiple test applications
@ -146,7 +178,7 @@ namespace WorkspacesEditorUITest
protected void OpenNotepad() protected void OpenNotepad()
{ {
var process = System.Diagnostics.Process.Start("notepad.exe"); var process = System.Diagnostics.Process.Start("notepad.exe");
Thread.Sleep(1000); Task.Delay(1000).Wait();
} }
protected void CloseNotepad() protected void CloseNotepad()