Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion .github/workflows/buildDev.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ name: "Build Text Grab"
on:
push:
branches: [dev]
pull_request:
branches: [dev]

env:
PROJECT_PATH: "Text-Grab/Text-Grab.csproj"
Expand All @@ -15,7 +17,7 @@ jobs:
- name: Setup .NET
uses: actions/setup-dotnet@v4
with:
dotnet-version: "8.0.x"
dotnet-version: "9.0.x"
- name: Install dependencies
run: dotnet restore ${{ env.PROJECT_PATH }}
- name: Build
Expand Down
90 changes: 90 additions & 0 deletions Tests/DiagnosticsTests.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@
using System;
using System.IO;
using System.Threading.Tasks;
using Xunit;
using Text_Grab.Utilities;

namespace Tests;

public class DiagnosticsTests
{
[Fact]
public async Task GenerateBugReport_ReturnsValidJson()
{
// This test may fail on non-Windows platforms but should at least generate JSON
string bugReport = await DiagnosticsUtilities.GenerateBugReportAsync();

// Assert - Should not be empty
Assert.NotEmpty(bugReport);

// Assert - Should be valid JSON (basic check)
Assert.StartsWith("{", bugReport.Trim());
Assert.EndsWith("}", bugReport.Trim());

// Assert - Should contain expected sections
Assert.Contains("generatedAt", bugReport);
Assert.Contains("appVersion", bugReport);
Assert.Contains("installationType", bugReport);
Assert.Contains("startupDetails", bugReport);
}

[Fact]
public async Task SaveBugReportToFile_CreatesFileInDocuments()
{
// Act
string filePath = await DiagnosticsUtilities.SaveBugReportToFileAsync();

// Assert - File should exist
Assert.True(File.Exists(filePath));

// Assert - File should be in Documents folder
string documentsPath = Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments);
Assert.StartsWith(documentsPath, filePath);

// Assert - File should have correct naming pattern
Assert.Contains("TextGrab_BugReport_", Path.GetFileName(filePath));
Assert.EndsWith(".json", filePath);

// Cleanup
try
{
File.Delete(filePath);
}
catch
{
// Ignore cleanup failures in tests
}
}

[Fact]
public async Task BugReport_ContainsStartupPathDiagnostics()
{
// Act
string bugReport = await DiagnosticsUtilities.GenerateBugReportAsync();

// Assert - Should contain startup diagnostics to verify the fix
Assert.Contains("startupDetails", bugReport);
Assert.Contains("calculatedRegistryValue", bugReport);
Assert.Contains("actualRegistryValue", bugReport);
Assert.Contains("baseDirectory", bugReport);

// The bug report should help verify that startup path fix is working
Assert.Contains("Text-Grab.exe", bugReport);
}

[Fact]
public async Task BugReport_IncludesAllRequestedInformation()
{
// Act
string bugReport = await DiagnosticsUtilities.GenerateBugReportAsync();

// Assert - Should contain all requested information from issue #553
Assert.Contains("settingsInfo", bugReport); // Settings
Assert.Contains("installationType", bugReport); // Type of install
Assert.Contains("startupDetails", bugReport); // Startup location details
Assert.Contains("windowsVersion", bugReport); // Windows version
Assert.Contains("historyInfo", bugReport); // Amount of history
Assert.Contains("languageInfo", bugReport); // Installed languages
Assert.Contains("tesseractInfo", bugReport); // Tesseract details
}
}
122 changes: 122 additions & 0 deletions Tests/StartupTests.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,122 @@
using System;
using System.IO;
using Xunit;

namespace Tests;

public class StartupTests
{
[Fact]
public void StartupPathCalculation_OldVsNewLogic()
{
// Arrange - Simulate a typical Windows executable path structure
string simulatedBaseDirectory = @"C:\Apps\Text-Grab\";

// Act - Old buggy logic (what's currently in the code)
string? parentDir = Path.GetDirectoryName(simulatedBaseDirectory.TrimEnd('\\'));
string oldLogicPath = parentDir is not null ?
$"\"{parentDir}\\Text-Grab.exe\"" : "";

// Act - New correct logic (what it should be)
string newLogicPath = $"\"{Path.Combine(simulatedBaseDirectory, "Text-Grab.exe")}\"";

// Assert - The paths should be different (proving the bug exists)
Assert.NotEqual(oldLogicPath, newLogicPath);

// Assert - Old logic should point to parent directory (wrong)
Assert.Contains(@"C:\Apps\Text-Grab.exe", oldLogicPath);

// Assert - New logic should point to base directory (correct)
Assert.Contains(@"C:\Apps\Text-Grab\Text-Grab.exe", newLogicPath);
}

[Fact]
public void WindowsStartupPathCalculation_OldVsNewLogic()
{
// Arrange - Simulate a typical Windows executable path structure
string simulatedBaseDirectory = @"C:\Program Files\Text-Grab\";

// Act - Old buggy logic (what's currently in the code)
string? parentDir = Path.GetDirectoryName(simulatedBaseDirectory.TrimEnd('\\'));
string oldLogicPath = parentDir is not null ?
$"\"{parentDir}\\Text-Grab.exe\"" : "";

// Act - New correct logic (what it should be)
string newLogicPath = $"\"{Path.Combine(simulatedBaseDirectory, "Text-Grab.exe")}\"";

// Assert - The paths should be different (proving the bug exists)
Assert.NotEqual(oldLogicPath, newLogicPath);

// Assert - Old logic should point to parent directory (wrong)
Assert.Equal("\"C:\\Program Files\\Text-Grab.exe\"", oldLogicPath);

// Assert - New logic should point to correct directory
Assert.Equal("\"C:\\Program Files\\Text-Grab\\Text-Grab.exe\"", newLogicPath);
}

[Fact]
public void FixedStartupPathCalculation_UsesCorrectBaseDirectory()
{
// Arrange - Simulate the fixed logic that should be in the code now
string simulatedBaseDirectory = @"C:\MyApps\Text-Grab\";

// Act - Fixed logic using Path.Combine with BaseDirectory directly
string fixedLogicPath = $"\"{Path.Combine(simulatedBaseDirectory, "Text-Grab.exe")}\"";

// Assert - Fixed logic should create correct path
Assert.Equal("\"C:\\MyApps\\Text-Grab\\Text-Grab.exe\"", fixedLogicPath);

// Assert - Path should point to the executable in the base directory
Assert.Contains(simulatedBaseDirectory.TrimEnd('\\'), fixedLogicPath);
Assert.EndsWith("Text-Grab.exe\"", fixedLogicPath);
}

[Fact]
public void FileUtilitiesPathCalculation_OldVsNewLogic()
{
// Arrange - Simulate a typical Windows executable path structure
string simulatedBaseDirectory = @"C:\Apps\Text-Grab\";

// Act - Old buggy logic (what was previously in FileUtilities)
string? parentDir = Path.GetDirectoryName(simulatedBaseDirectory.TrimEnd('\\'));
string oldLogicHistoryPath = parentDir is not null ?
$"{parentDir}\\history" : "";

// Act - New correct logic (what should be in FileUtilities now)
string newLogicHistoryPath = Path.Combine(simulatedBaseDirectory, "history");

// Assert - The paths should be different (proving the bug exists)
Assert.NotEqual(oldLogicHistoryPath, newLogicHistoryPath);

// Assert - Old logic should point to parent directory (wrong)
Assert.Equal(@"C:\Apps\history", oldLogicHistoryPath);

// Assert - New logic should point to base directory (correct)
Assert.Equal(@"C:\Apps\Text-Grab\history", newLogicHistoryPath);
}

[Fact]
public void FileUtilitiesLocalFilePathCalculation_OldVsNewLogic()
{
// Arrange - Simulate a typical Windows executable path structure and relative file
string simulatedBaseDirectory = @"C:\Program Files\Text-Grab\";
string relativeFile = @"images\logo.png";

// Act - Old buggy logic (what was previously in GetPathToLocalFile)
string? parentDir = Path.GetDirectoryName(simulatedBaseDirectory.TrimEnd('\\'));
string oldLogicPath = parentDir is not null ?
Path.Combine(parentDir, relativeFile) : "";

// Act - New correct logic (what should be in GetPathToLocalFile now)
string newLogicPath = Path.Combine(simulatedBaseDirectory, relativeFile);

// Assert - The paths should be different (proving the bug exists)
Assert.NotEqual(oldLogicPath, newLogicPath);

// Assert - Old logic should point to parent directory (wrong)
Assert.Equal(@"C:\Program Files\images\logo.png", oldLogicPath);

// Assert - New logic should point to base directory (correct)
Assert.Equal(@"C:\Program Files\Text-Grab\images\logo.png", newLogicPath);
}
}
11 changes: 9 additions & 2 deletions Text-Grab/Controls/NotifyIconWindow.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@
Left="-50"
Opacity="0"
ShowInTaskbar="True"
ToolTip="Text Grab"
Top="-50"
WindowStyle="ToolWindow"
mc:Ignorable="d">
Expand All @@ -26,7 +25,7 @@
Icon="/Images/TealSelect40.png"
IsVisibleChanged="NotifyIcon_IsVisibleChanged"
LeftClick="NotifyIcon_LeftClick"
ToolTip="Text Grab">
TooltipText="Text Grab">
<WpfUiIcon:NotifyIcon.Menu>
<ContextMenu>
<MenuItem
Expand Down Expand Up @@ -79,6 +78,14 @@
<wpfui:SymbolIcon Symbol="PanelBottom20" />
</MenuItem.Icon>
</MenuItem>
<MenuItem
x:Name="LastEditWindow"
Click="LastEditWindow_Click"
Header="Last Edit Text Window">
<MenuItem.Icon>
<wpfui:SymbolIcon Symbol="History20" />
</MenuItem.Icon>
</MenuItem>
<MenuItem
x:Name="EditWindowMenuItem"
Click="EditWindowMenuItem_Click"
Expand Down
48 changes: 43 additions & 5 deletions Text-Grab/Controls/NotifyIconWindow.xaml.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
using System.Windows;
using System;
using System.Windows;
using Text_Grab.Properties;
using Text_Grab.Services;
using Text_Grab.Utilities;
using Text_Grab.Views;
Expand All @@ -10,6 +12,8 @@ namespace Text_Grab.Controls;
/// </summary>
public partial class NotifyIconWindow : Window
{
private readonly Settings DefaultSettings = AppUtilities.TextGrabSettings;

public NotifyIconWindow()
{
InitializeComponent();
Expand All @@ -30,16 +34,41 @@ private void Window_Activated(object sender, System.EventArgs e)
{
Hide();
NotifyIcon.Visibility = Visibility.Visible;

string toolTipText = "Text Grab";
TextGrabMode defaultLaunchSetting = Enum.Parse<TextGrabMode>(DefaultSettings.DefaultLaunch, true);

switch (defaultLaunchSetting)
{
case TextGrabMode.Fullscreen:
toolTipText += " - Fullscreen Grab";
break;
case TextGrabMode.GrabFrame:
toolTipText += " - Grab Frame";
break;
case TextGrabMode.EditText:
toolTipText += " - Edit Text";
break;
case TextGrabMode.QuickLookup:
toolTipText += " - Quick Lookup";
break;
default:
break;
}

NotifyIcon.TooltipText = toolTipText;
}

private void EditWindowMenuItem_Click(object sender, RoutedEventArgs e)
{
EditTextWindow etw = new(); etw.Show();
EditTextWindow etw = new();
etw.Show();
}

private void GrabFrameMenuItem_Click(object sender, RoutedEventArgs e)
{
GrabFrame gf = new(); gf.Show();
GrabFrame gf = new();
gf.Show();
}

private void FullscreenGrabMenuItem_Click(object sender, RoutedEventArgs e)
Expand All @@ -54,7 +83,8 @@ private async void PreviousRegionMenuItem_Click(object sender, RoutedEventArgs e

private void LookupMenuItem_Click(object sender, RoutedEventArgs e)
{
QuickSimpleLookup qsl = new(); qsl.Show();
QuickSimpleLookup qsl = new();
qsl.Show();
}

private void LastGrabMenuItem_Click(object sender, RoutedEventArgs e)
Expand All @@ -64,12 +94,20 @@ private void LastGrabMenuItem_Click(object sender, RoutedEventArgs e)

private void SettingsMenuItem_Click(object sender, RoutedEventArgs e)
{
SettingsWindow sw = new(); sw.Show();
SettingsWindow sw = new();
sw.Show();
}

private void NotifyIcon_IsVisibleChanged(object sender, DependencyPropertyChangedEventArgs e)
{
if (!NotifyIcon.IsVisible)
NotifyIcon.Visibility = Visibility.Visible;
}

private void LastEditWindow_Click(object sender, RoutedEventArgs e)
{
EditTextWindow etw = new();
etw.Show();
etw.OpenMostRecentTextHistoryItem();
}
}
10 changes: 10 additions & 0 deletions Text-Grab/Pages/DangerSettings.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,16 @@
<StackPanel Margin="20,12,40,40" Orientation="Vertical">
<TextBlock Style="{StaticResource TextHeader}" Text="Dangerous Options" />

<TextBlock Margin="0,12,0,0" Style="{StaticResource TextBodyNormal}">
Generate bug report with app diagnostic information.
</TextBlock>
<controls:CollapsibleButton
x:Name="ExportBugReportButton"
HorizontalAlignment="Left"
ButtonSymbol="DocumentSave24"
ButtonText="Export Bug Report"
Click="ExportBugReportButton_Click" />

<TextBlock Margin="0,12,0,0" Style="{StaticResource TextBodyNormal}">
Reset All settings to default settings.
</TextBlock>
Expand Down
Loading
Loading