Skip to content

Commit 4bfaa04

Browse files
Copilotniels9001
andcommitted
Add unit test for Copy Path button functionality
Co-authored-by: niels9001 <[email protected]>
1 parent 75c92e1 commit 4bfaa04

File tree

2 files changed

+59
-0
lines changed

2 files changed

+59
-0
lines changed

src/modules/peek/Peek.UI/PeekXAML/Views/TitleBar.xaml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,7 @@
9393
x:Name="CopyPathButton"
9494
Grid.Column="3"
9595
VerticalAlignment="Center"
96+
AutomationProperties.AutomationId="CopyPathButton"
9697
Command="{x:Bind CopyPathButtonCommand, Mode=OneWay}"
9798
Style="{StaticResource SubtleButtonStyle}"
9899
ToolTipService.ToolTip="{x:Bind CopyPathButtonToolTip, Mode=OneWay}">
@@ -104,6 +105,7 @@
104105
Glyph="&#xE8C8;" />
105106
<TextBlock
106107
x:Name="CopyPathButton_Text"
108+
AutomationProperties.AutomationId="CopyPathButton_Text"
107109
Style="{StaticResource CaptionTextBlockStyle}"
108110
Text="{x:Bind CopyPathButtonText, Mode=OneWay}" />
109111
</StackPanel>

src/modules/peek/Peek.UITests/PeekFilePreviewTests.cs

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -332,6 +332,35 @@ public void TestOpenWithDefaultProgramByButton()
332332
ClosePeekAndExplorer();
333333
}
334334

335+
/// <summary>
336+
/// Test copying file path to clipboard by clicking the copy path button
337+
/// </summary>
338+
[TestMethod("Peek.CopyPath.ClickButton")]
339+
[TestCategory("Copy Path")]
340+
public void TestCopyPathByButton()
341+
{
342+
string zipPath = Path.GetFullPath(@".\TestAssets\7.zip");
343+
344+
// Open zip file with Peek
345+
var peekWindow = OpenPeekWindow(zipPath);
346+
347+
// Find and click the "Copy path" button
348+
var copyPathButton = FindCopyPathButton();
349+
Assert.IsNotNull(copyPathButton, "Copy path button should be found");
350+
351+
// Click the button to copy path to clipboard
352+
copyPathButton.Click();
353+
354+
// Wait a moment for the clipboard operation to complete
355+
Thread.Sleep(500);
356+
357+
// Note: We can't directly test clipboard contents in UI tests due to security restrictions
358+
// The test verifies that the button exists and can be clicked without exceptions
359+
// The actual clipboard functionality is tested through the underlying ClipboardHelper
360+
361+
ClosePeekAndExplorer();
362+
}
363+
335364
/// <summary>
336365
/// Test opening file with default program by pressing Enter key
337366
/// </summary>
@@ -862,4 +891,32 @@ private Element FindPeekWindow(string filePath, int timeout = 5000)
862891

863892
return null;
864893
}
894+
895+
/// <summary>
896+
/// Helper method to find the copy path button with different AccessibilityIds depending on window size
897+
/// </summary>
898+
/// <returns>The copy path button element</returns>
899+
private Element? FindCopyPathButton()
900+
{
901+
try
902+
{
903+
// Try to find button with ID for larger window first
904+
var button = Find(By.AccessibilityId("CopyPathButton_Text"), 1000);
905+
if (button != null)
906+
{
907+
return button;
908+
}
909+
}
910+
catch
911+
{
912+
// Try to find button with ID for smaller window
913+
var button = Find(By.AccessibilityId("CopyPathButton"), 1000);
914+
if (button != null)
915+
{
916+
return button;
917+
}
918+
}
919+
920+
return null;
921+
}
865922
}

0 commit comments

Comments
 (0)