WorkspacesEditorTests.cs
1 // Copyright (c) Microsoft Corporation 2 // The Microsoft Corporation licenses this file to you under the MIT license. 3 // See the LICENSE file in the project root for more information. 4 5 using Microsoft.PowerToys.UITest; 6 using Microsoft.VisualStudio.TestTools.UnitTesting; 7 8 namespace WorkspacesEditorUITest; 9 10 [TestClass] 11 public class WorkspacesEditorTests : WorkspacesUiAutomationBase 12 { 13 public WorkspacesEditorTests() 14 : base() 15 { 16 } 17 18 [TestMethod("WorkspacesEditor.Items.Present")] 19 [TestCategory("Workspaces UI")] 20 public void TestItemsPresents() 21 { 22 Assert.IsTrue(this.Has<Button>("Create Workspace"), "Should have create workspace button"); 23 } 24 25 /* 26 [TestMethod("WorkspacesEditor.Editor.NewWorkspaceAppearsInList")] 27 [TestCategory("Workspaces UI")] 28 public void TestNewWorkspaceAppearsInListAfterCapture() 29 { 30 // Open test application 31 OpenNotepad(); 32 Thread.Sleep(2000); 33 34 // Create workspace 35 var createButton = Find<Button>("Create Workspace"); 36 createButton.Click(); 37 Thread.Sleep(1000); 38 39 // Capture 40 var captureButton = Find<Button>("Capture"); 41 captureButton.Click(); 42 Thread.Sleep(2000); 43 44 // Save workspace 45 var saveButton = Find<Button>("Save"); 46 saveButton.Click(); 47 Thread.Sleep(1000); 48 49 // Verify workspace appears in list 50 var workspacesList = Find<Custom>("WorkspacesList"); 51 var workspaceItems = workspacesList.FindAll<Custom>(By.ClassName("WorkspaceItem")); 52 Assert.IsTrue(workspaceItems.Count > 0, "New workspace should appear in the list"); 53 54 CloseNotepad(); 55 } 56 57 [TestMethod("WorkspacesEditor.Editor.CancelCaptureDoesNotAddWorkspace")] 58 [TestCategory("Workspaces UI")] 59 public void TestCancelCaptureDoesNotAddWorkspace() 60 { 61 // Count existing workspaces 62 var workspacesList = Find<Custom>("WorkspacesList"); 63 var initialCount = workspacesList.FindAll<Custom>(By.ClassName("WorkspaceItem")).Count; 64 65 // Create workspace 66 var createButton = Find<Button>("Create Workspace"); 67 createButton.Click(); 68 Thread.Sleep(1000); 69 70 // Cancel 71 var cancelButton = Find<Button>("Cancel"); 72 cancelButton.Click(); 73 Thread.Sleep(1000); 74 75 // Verify count hasn't changed 76 var finalCount = workspacesList.FindAll<Custom>(By.ClassName("WorkspaceItem")).Count; 77 Assert.AreEqual(initialCount, finalCount, "Workspace count should not change after canceling"); 78 } 79 80 [TestMethod("WorkspacesEditor.Editor.SearchFiltersWorkspaces")] 81 [TestCategory("Workspaces UI")] 82 public void TestSearchFiltersWorkspaces() 83 { 84 // Create test workspaces first 85 CreateTestWorkspace("TestWorkspace1"); 86 CreateTestWorkspace("TestWorkspace2"); 87 CreateTestWorkspace("DifferentName"); 88 89 // Find search box 90 var searchBox = Find<TextBox>("Search"); 91 searchBox.SetText("TestWorkspace"); 92 Thread.Sleep(1000); 93 94 // Verify filtered results 95 var workspacesList = Find<Custom>("WorkspacesList"); 96 var visibleItems = workspacesList.FindAll<Custom>(By.ClassName("WorkspaceItem")); 97 98 // Should only show items matching "TestWorkspace" 99 Assert.IsTrue(visibleItems.Count >= 2, "Should show at least 2 TestWorkspace items"); 100 101 // Clear search 102 searchBox.SetText(string.Empty); 103 Thread.Sleep(500); 104 } 105 106 [TestMethod("WorkspacesEditor.Editor.SortByWorks")] 107 [TestCategory("Workspaces UI")] 108 public void TestSortByFunctionality() 109 { 110 // Find sort dropdown 111 var sortDropdown = Find<ComboBox>("SortBy"); 112 sortDropdown.Click(); 113 Thread.Sleep(500); 114 115 // Select different sort options 116 var sortOptions = FindAll<Custom>(By.ClassName("ComboBoxItem")); 117 if (sortOptions.Count > 1) 118 { 119 sortOptions[1].Click(); // Select second option 120 Thread.Sleep(1000); 121 122 // Verify list is updated (we can't easily verify sort order in UI tests) 123 var workspacesList = Find<Custom>("WorkspacesList"); 124 Assert.IsNotNull(workspacesList, "Workspaces list should still be visible after sorting"); 125 } 126 } 127 128 [TestMethod("WorkspacesEditor.Editor.SortByPersists")] 129 [TestCategory("Workspaces UI")] 130 public void TestSortByPersistsAfterRestart() 131 { 132 // Set sort option 133 var sortDropdown = Find<ComboBox>("SortBy"); 134 sortDropdown.Click(); 135 Thread.Sleep(500); 136 137 var sortOptions = FindAll<Custom>(By.ClassName("ComboBoxItem")); 138 string selectedOption = string.Empty; 139 if (sortOptions.Count > 1) 140 { 141 sortOptions[1].Click(); // Select second option 142 selectedOption = sortDropdown.Text; 143 Thread.Sleep(1000); 144 } 145 146 // Restart editor 147 RestartScopeExe(); 148 Thread.Sleep(2000); 149 150 // Verify sort option persisted 151 sortDropdown = Find<ComboBox>("SortBy"); 152 Assert.AreEqual(selectedOption, sortDropdown.Text, "Sort option should persist after restart"); 153 } 154 155 [TestMethod("WorkspacesEditor.Editor.RemoveWorkspace")] 156 [TestCategory("Workspaces UI")] 157 public void TestRemoveWorkspace() 158 { 159 // Create a test workspace 160 CreateTestWorkspace("WorkspaceToRemove"); 161 162 // Find the workspace in the list 163 var workspacesList = Find<Custom>("WorkspacesList"); 164 var workspaceItem = workspacesList.Find<Custom>(By.Name("WorkspaceToRemove")); 165 166 // Click remove button 167 var removeButton = workspaceItem.Find<Button>("Remove"); 168 removeButton.Click(); 169 Thread.Sleep(1000); 170 171 // Confirm removal if dialog appears 172 if (Has<Button>("Yes")) 173 { 174 Find<Button>("Yes").Click(); 175 Thread.Sleep(1000); 176 } 177 178 // Verify workspace is removed 179 Assert.IsFalse(Has(By.Name("WorkspaceToRemove")), "Workspace should be removed from list"); 180 } 181 182 [TestMethod("WorkspacesEditor.Editor.EditOpensEditingPage")] 183 [TestCategory("Workspaces UI")] 184 public void TestEditOpensEditingPage() 185 { 186 // Create a test workspace if none exist 187 if (!Has<Custom>("WorkspacesList")) 188 { 189 CreateTestWorkspace("TestWorkspace"); 190 } 191 192 // Find first workspace 193 var workspacesList = Find<Custom>("WorkspacesList"); 194 var workspaceItem = workspacesList.FindAll<Custom>(By.ClassName("WorkspaceItem"))[0]; 195 196 // Click edit button 197 var editButton = workspaceItem.Find<Button>("Edit"); 198 editButton.Click(); 199 Thread.Sleep(1000); 200 201 // Verify editing page opened 202 Assert.IsTrue(Has<Button>("Save"), "Should have Save button on editing page"); 203 Assert.IsTrue(Has<Button>("Cancel"), "Should have Cancel button on editing page"); 204 205 // Go back 206 Find<Button>("Cancel").Click(); 207 Thread.Sleep(1000); 208 } 209 210 [TestMethod("WorkspacesEditor.Editor.ClickWorkspaceOpensEditingPage")] 211 [TestCategory("Workspaces UI")] 212 public void TestClickWorkspaceOpensEditingPage() 213 { 214 // Create a test workspace if none exist 215 if (!Has<Custom>("WorkspacesList")) 216 { 217 CreateTestWorkspace("TestWorkspace"); 218 } 219 220 // Find first workspace 221 var workspacesList = Find<Custom>("WorkspacesList"); 222 var workspaceItem = workspacesList.FindAll<Custom>(By.ClassName("WorkspaceItem"))[0]; 223 224 // Click on the workspace item itself 225 workspaceItem.Click(); 226 Thread.Sleep(1000); 227 228 // Verify editing page opened 229 Assert.IsTrue(Has<Button>("Save"), "Should have Save button on editing page"); 230 Assert.IsTrue(Has<Button>("Cancel"), "Should have Cancel button on editing page"); 231 232 // Go back 233 Find<Button>("Cancel").Click(); 234 Thread.Sleep(1000); 235 } 236 */ 237 }