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"
VerticalScrollBarVisibility="Auto"
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>
<ItemsPanelTemplate>
<StackPanel
@ -235,7 +235,7 @@
Grid.Column="1"
Margin="12,12,12,12"
Orientation="Vertical">
<StackPanel HorizontalAlignment="Right" Orientation="Horizontal">
<StackPanel HorizontalAlignment="Right" Orientation="Horizontal" x:Name="WorkspaceActionGroup">
<Button
x:Name="MoreButton"
HorizontalAlignment="Right"
@ -248,7 +248,8 @@
</Button>
<Popup
AllowsTransparency="True"
IsOpen="{Binding IsPopupVisible, Mode=OneWay, UpdateSourceTrigger=PropertyChanged}"
IsOpen="{Binding IsPopupVisible, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}"
Closed="PopupClosed"
Placement="Left"
PlacementTarget="{Binding ElementName=MoreButton}"
StaysOpen="False">

View File

@ -4,7 +4,8 @@
using System.Windows;
using System.Windows.Controls;
using System.Windows.Controls.Primitives;
using ManagedCommon;
using WorkspacesEditor.Models;
using WorkspacesEditor.ViewModels;
@ -42,17 +43,28 @@ namespace WorkspacesEditor
e.Handled = true;
Button button = sender as Button;
Project selectedProject = button.DataContext as Project;
selectedProject.IsPopupVisible = false;
_mainViewModel.DeleteProject(selectedProject);
}
private void MoreButton_Click(object sender, RoutedEventArgs e)
{
_mainViewModel.CloseAllPopups();
e.Handled = true;
Button button = sender as Button;
Project project = button.DataContext as Project;
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)
{
e.Handled = true;

View File

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

View File

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

View File

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

View File

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

View File

@ -2,8 +2,6 @@
// 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.Diagnostics;
using System.Threading.Tasks;
using Microsoft.PowerToys.UITest;
using Microsoft.VisualStudio.TestTools.UnitTesting;
@ -35,8 +33,6 @@ public class WorkspacesSnapshotTests : WorkspacesUiAutomationBase
Assert.IsNotNull(cancelButton, "Capture button should exist");
cancelButton.Click();
AttachWorkspacesEditor();
}
[TestMethod("WorkspacesSnapshot.CapturePackagedApps")]
@ -61,36 +57,11 @@ public class WorkspacesSnapshotTests : WorkspacesUiAutomationBase
AttachWorkspacesEditor();
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;
bool foundSettings = false;
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");
var settingItem = appList.Find<Element>(By.AccessibilityId("Settings"));
Assert.IsNotNull(settingItem, "Calculator should be captured");
// Cancel to clean up
Find<Button>("Cancel").Click();
@ -101,6 +72,7 @@ public class WorkspacesSnapshotTests : WorkspacesUiAutomationBase
CloseWindowsSettings();
}
/* Not finished yet
[TestMethod("WorkspacesSnapshot.CaptureElevatedApps")]
[TestCategory("Workspaces Snapshot UI")]
public void TestCaptureElevatedApplications()
@ -323,20 +295,6 @@ public class WorkspacesSnapshotTests : WorkspacesUiAutomationBase
// 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()
{
var startInfo = new ProcessStartInfo
@ -376,4 +334,5 @@ public class WorkspacesSnapshotTests : WorkspacesUiAutomationBase
SendKeys(Key.Win, Key.Down);
Thread.Sleep(500);
}
*/
}

View File

@ -5,6 +5,8 @@
using System.Diagnostics;
using System.Threading;
using Microsoft.PowerToys.UITest;
using OpenQA.Selenium.Interactions;
using Windows.Media.Playback;
namespace WorkspacesEditorUITest
{
@ -19,32 +21,62 @@ namespace WorkspacesEditorUITest
{
// Open notepad for capture
OpenNotepad();
Thread.Sleep(2000);
Task.Delay(1000).Wait();
// Create workspace
AttachWorkspacesEditor();
var createButton = Find<Button>("Create Workspace");
createButton.Click();
Thread.Sleep(1000);
Task.Delay(500).Wait();
// Capture
AttachSnapshotWindow();
var captureButton = Find<Button>("Capture");
captureButton.Click();
Thread.Sleep(2000);
Task.Delay(5000).Wait();
// Set name
var nameTextBox = Find<TextBox>("WorkspaceName");
nameTextBox.SetText(string.Empty);
var nameTextBox = Find<TextBox>("EditNameTextBox");
nameTextBox.SetText(name);
Thread.Sleep(500);
// Save
Find<Button>("Save").Click();
Thread.Sleep(1000);
Find<Button>("Save Workspace").Click();
// Close notepad
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()
{
// Open multiple test applications
@ -146,7 +178,7 @@ namespace WorkspacesEditorUITest
protected void OpenNotepad()
{
var process = System.Diagnostics.Process.Start("notepad.exe");
Thread.Sleep(1000);
Task.Delay(1000).Wait();
}
protected void CloseNotepad()