Skip to content

Commit

Permalink
wip
Browse files Browse the repository at this point in the history
  • Loading branch information
coenm committed Oct 26, 2024
1 parent a58d8b0 commit d77a43e
Show file tree
Hide file tree
Showing 16 changed files with 1,218 additions and 8 deletions.
22 changes: 22 additions & 0 deletions RepoM.sln
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,8 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "RepoM.ActionMenu.Core.TestL
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "RepoM.ActionMenu.CodeGenDummyLibrary", "tests\RepoM.ActionMenu.CodeGenDummyLibrary\RepoM.ActionMenu.CodeGenDummyLibrary.csproj", "{998B5CA0-158D-4B01-A343-07ED534D02B0}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "UiTests", "tests\UiTests\UiTests.csproj", "{B537DF84-37BC-411F-ABBD-9CBBCE66F0E1}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Expand Down Expand Up @@ -681,6 +683,26 @@ Global
{998B5CA0-158D-4B01-A343-07ED534D02B0}.Release|x64.Build.0 = Release|Any CPU
{998B5CA0-158D-4B01-A343-07ED534D02B0}.Release|x86.ActiveCfg = Release|Any CPU
{998B5CA0-158D-4B01-A343-07ED534D02B0}.Release|x86.Build.0 = Release|Any CPU
{B537DF84-37BC-411F-ABBD-9CBBCE66F0E1}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{B537DF84-37BC-411F-ABBD-9CBBCE66F0E1}.Debug|Any CPU.Build.0 = Debug|Any CPU
{B537DF84-37BC-411F-ABBD-9CBBCE66F0E1}.Debug|ARM.ActiveCfg = Debug|Any CPU
{B537DF84-37BC-411F-ABBD-9CBBCE66F0E1}.Debug|ARM.Build.0 = Debug|Any CPU
{B537DF84-37BC-411F-ABBD-9CBBCE66F0E1}.Debug|ARM64.ActiveCfg = Debug|Any CPU
{B537DF84-37BC-411F-ABBD-9CBBCE66F0E1}.Debug|ARM64.Build.0 = Debug|Any CPU
{B537DF84-37BC-411F-ABBD-9CBBCE66F0E1}.Debug|x64.ActiveCfg = Debug|Any CPU
{B537DF84-37BC-411F-ABBD-9CBBCE66F0E1}.Debug|x64.Build.0 = Debug|Any CPU
{B537DF84-37BC-411F-ABBD-9CBBCE66F0E1}.Debug|x86.ActiveCfg = Debug|Any CPU
{B537DF84-37BC-411F-ABBD-9CBBCE66F0E1}.Debug|x86.Build.0 = Debug|Any CPU
{B537DF84-37BC-411F-ABBD-9CBBCE66F0E1}.Release|Any CPU.ActiveCfg = Release|Any CPU
{B537DF84-37BC-411F-ABBD-9CBBCE66F0E1}.Release|Any CPU.Build.0 = Release|Any CPU
{B537DF84-37BC-411F-ABBD-9CBBCE66F0E1}.Release|ARM.ActiveCfg = Release|Any CPU
{B537DF84-37BC-411F-ABBD-9CBBCE66F0E1}.Release|ARM.Build.0 = Release|Any CPU
{B537DF84-37BC-411F-ABBD-9CBBCE66F0E1}.Release|ARM64.ActiveCfg = Release|Any CPU
{B537DF84-37BC-411F-ABBD-9CBBCE66F0E1}.Release|ARM64.Build.0 = Release|Any CPU
{B537DF84-37BC-411F-ABBD-9CBBCE66F0E1}.Release|x64.ActiveCfg = Release|Any CPU
{B537DF84-37BC-411F-ABBD-9CBBCE66F0E1}.Release|x64.Build.0 = Release|Any CPU
{B537DF84-37BC-411F-ABBD-9CBBCE66F0E1}.Release|x86.ActiveCfg = Release|Any CPU
{B537DF84-37BC-411F-ABBD-9CBBCE66F0E1}.Release|x86.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
Expand Down
2 changes: 2 additions & 0 deletions src/RepoM.App/App.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -176,6 +176,7 @@ private static bool IsAlreadyRunning()
return false;
}

#pragma warning disable CS0162 // Unreachable code detected
try
{
_mutex = new Mutex(true, "Local\\github.com/coenm/RepoM", out var createdNew);
Expand All @@ -193,6 +194,7 @@ private static bool IsAlreadyRunning()
_mutex.Dispose();
_mutex = null;
return true;
#pragma warning restore CS0162 // Unreachable code detected
}

private static void ReleaseAndDisposeMutex()
Expand Down
9 changes: 5 additions & 4 deletions src/RepoM.App/MainWindow.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@
Focusable="False">

<Grid>
<TextBlock x:Name="tbNoRepositories"
<TextBlock Name="tbNoRepositories"
Text="{DynamicResource EmptyHint}"
TextWrapping="Wrap"
FontSize="15"
Expand Down Expand Up @@ -272,8 +272,9 @@
Click="UpdateButton_Click" />
</Grid>

<ListBox Name="lstRepositories"
DockPanel.Dock="Top"
<ListBox x:Name="lstRepositories"
AutomationProperties.Name="lstRepositories"
DockPanel.Dock="Top"
HorizontalContentAlignment="Stretch"
MouseDoubleClick="LstRepositories_MouseDoubleClick"
KeyDown="LstRepositories_KeyDown"
Expand Down Expand Up @@ -373,7 +374,7 @@
</DataTemplate>
</ListBox.ItemTemplate>
<ListBox.ContextMenu>
<controls:AcrylicContextMenu x:Name="mnuRepositoryContext" >
<controls:AcrylicContextMenu x:Name="mnuRepositoryContext" >
<!--<controls:AcrylicContextMenu.ItemsPanel>
<ItemsPanelTemplate>
<VirtualizingStackPanel IsVirtualizing="True" VirtualizationMode="Recycling" />
Expand Down
9 changes: 5 additions & 4 deletions tests/SystemTests/SystemTests.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,11 @@
<PropertyGroup>
<TargetFramework>net8.0</TargetFramework>
</PropertyGroup>
<ItemGroup>
<Compile Remove="Helpers\**" />
<EmbeddedResource Remove="Helpers\**" />
<None Remove="Helpers\**" />
</ItemGroup>

<ItemGroup>
<ProjectReference Include="..\..\src\RepoM.ActionMenu.Core\RepoM.ActionMenu.Core.csproj" />
Expand All @@ -27,8 +32,4 @@
<PackageReference Include="System.Runtime.CompilerServices.Unsafe" Version="6.0.0" />
<PackageReference Include="TUnit" Version="0.1.1030" />
</ItemGroup>

<ItemGroup>
<Folder Include="Helpers\" />
</ItemGroup>
</Project>
22 changes: 22 additions & 0 deletions tests/UiTests/ApplicationStartMode.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
namespace UiTests;

/// <summary>
/// Defines how the application under test should be started by the test fixture.
/// </summary>
public enum ApplicationStartMode
{
/// <summary>
/// Do not start or stop the application as this is done outside.
/// </summary>
None,

/// <summary>
/// Start the application before each test and close it after each test.
/// </summary>
OncePerTest,

/// <summary>
/// Start the application once for the whole test fixture and close it when all tests are finished.
/// </summary>
OncePerFixture
}
116 changes: 116 additions & 0 deletions tests/UiTests/Class1.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,116 @@
namespace UiTests;

using System;
using System.Threading.Tasks;
using FlaUI.Core.AutomationElements;
using FlaUI.Core.Input;
using FlaUI.Core.WindowsAPI;
using FlaUI.UIA3;
using FluentAssertions;
using UiTests.Extensions;
using UiTests.Framework;
using UiTests.RepoM;
using UiTests.Utils;
using Xunit;
using Xunit.Abstractions;

[SetTestName]
public class NotePadTest
{
private readonly ITestOutputHelper _outputHelper;

public NotePadTest(ITestOutputHelper outputHelper)
{
_outputHelper = outputHelper ?? throw new ArgumentNullException(nameof(outputHelper));
}

// make sure no vs code instance is running.

[Fact]
public async Task NotepadLaunchTest()
{
using var appVsCode = ApplicationFactory.LaunchVsCode(@"C:\Users\Munckhof CJJ\AppData\Roaming\RepoM\RepositoryActionsV2.yaml");
using var appRepoM = ApplicationFactory.LaunchRepoM();

using (var automationRepoM = new UIA3Automation())
// using (var automationVsCode = new UIA3Automation())
{
var automationVsCode = automationRepoM;

await Task.Delay(20_000);
appRepoM.WaitWhileMainHandleIsMissing(TimeSpan.FromSeconds(5));
appRepoM.WaitWhileBusy(TimeSpan.FromSeconds(5));
appVsCode.WaitWhileMainHandleIsMissing(TimeSpan.FromSeconds(20));
appVsCode.WaitWhileBusy(TimeSpan.FromSeconds(20));

VsCodeWindow vsCodeWindow = appVsCode.GetMainWindow(automationVsCode).As<VsCodeWindow>(_outputHelper);
vsCodeWindow.Should().NotBeNull();

await RepoMWindow.ShowRepoM();
await Task.Delay(100);

await RepoMWindow.KeepRepoMOpenAsync();
await Task.Delay(100);

RepoMWindow repoM = await RepoMWindow.GetRepoMWindowAsync(appRepoM, automationRepoM, _outputHelper);

// undo keep open
await RepoMWindow.KeepRepoMOpenAsync();

_ = repoM.Hide();

await Task.Delay(100);

await vsCodeWindow.FocusUsingMouseAsync();

vsCodeWindow.NotificationButton.Click();
await Task.Delay(100);
vsCodeWindow.NotificationButton.Click();

await vsCodeWindow.FocusActiveEditorGroupAsync();
await vsCodeWindow.GoToLineAsync(6);

Position pos = await vsCodeWindow.GetCurrentCursorPositionAsync(p => p.Line == 6);
_outputHelper.WriteLine($"L{pos.Line} C{pos.Column}");
pos.Line.Should().Be(6);


await vsCodeWindow.SelectLineAsync();
await Task.Delay(1000);
Keyboard.Type(VirtualKeyShort.DELETE);
await Task.Delay(1000);
Keyboard.Type("end");
await Task.Delay(1000);
await vsCodeWindow.GoToStartOfLineAsync();
await Task.Delay(1000);
// await vsCodeWindow.GoToEndOfLineAsync();
// Keyboard.Type("Hello World");

await repoM.ShowAsync();
await repoM.SearchTextBox.FocusByMouseAsync();
await repoM.SearchTextBox.TypeTextAsync("RepoM", Delays.DefaultKeyPressDelay);

await Delays.DelayMediumAsync();


repoM.RepositoryList.Items.Should().NotBeEmpty();
ListBoxItem firstItem = repoM.RepositoryList.Items[0];

await firstItem.MoveMouseAndClick(MouseButton.Right, Delays.DefaultWaitUntilClick);
await Delays.DelayMediumAsync();

var ctxMenuItem = repoM.ContextMenu.Items[1].AsMenuItem();
_outputHelper.WriteLine($"ctxMenuItem item text {ctxMenuItem.Text}");
await ctxMenuItem.MoveMouseAndClick(MouseButton.Left, Delays.DefaultWaitUntilClick);

var txt = firstItem.Text;
_outputHelper.WriteLine($"Selected item text {txt}");

repoM.Title.Should().Be("RepoM");
}

await Task.Delay(1000);
appRepoM.Close();
appVsCode.Close();
}
}
89 changes: 89 additions & 0 deletions tests/UiTests/Extensions/AutomationElementExtensionsExtensions.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@
namespace UiTests.Extensions;

using System;
using System.Collections.Generic;
using System.Drawing;
using System.Threading.Tasks;
using FlaUI.Core.AutomationElements;
using FlaUI.Core.Input;
using UiTests;
using UiTests.Utils;

public static class AutomationElementExtensionsExtensions
{
public static T As<T>(this AutomationElement self, params object[] args) where T : AutomationElement
{
if (self == null)
{
return default!;
}

var args2 = new List<object>
{
self.FrameworkAutomationElement,
};
args2.AddRange(args);

return (T)Activator.CreateInstance(typeof(T), args2.ToArray())!;
}

public static async Task MoveMouseAsync(this AutomationElement element)
{
Point point = element.GetClickablePoint();
await Delays.DelaySmallAsync();
Mouse.MoveTo(point);
await Delays.DelaySmallAsync();
}

public static async Task MoveMouseAndClick(this AutomationElement element, MouseButton btn = MouseButton.Left, TimeSpan? delayBeforeClick = null)
{
await element.MoveMouseAsync();

if (delayBeforeClick.HasValue)
{
await Task.Delay(delayBeforeClick.Value);
}

Mouse.Click(btn);
await Delays.DelaySmallAsync();
}

public static Task FocusByMouseAsync(this AutomationElement element, TimeSpan? delayBeforeClick = null)
{
return MoveMouseAndClick(element, MouseButton.Left, delayBeforeClick);
}

public static Task TypeTextAsync(this TextBox textBox, string text)
{
return textBox.TypeTextAsync(text, TimeSpan.Zero);
}

public static async Task TypeTextAsync(this TextBox textBox, string text, TimeSpan delayBetweenChars)
{
if (!textBox.IsEnabled)
{
throw new Exception("TextBox is not enabled");
}

if (text == string.Empty)
{
await Delays.DelaySmallAsync();
return;
}

if (delayBetweenChars > TimeSpan.Zero)
{
foreach (var character in text)
{
Keyboard.Type(character);
await Task.Delay(delayBetweenChars);
}
}
else
{
Keyboard.Type(text);
}

await Delays.DelaySmallAsync();
}
}
Loading

0 comments on commit d77a43e

Please sign in to comment.