using System; using System.IO; using System.Threading.Tasks; using Paca.App.Utils; using Paca.Core.QuickActions; using Xunit; namespace Paca.Tests.App; public class DownloadFolderOpenE2ERedScenarioTests { private static readonly string SolutionRoot = Path.GetFullPath(Path.Combine(AppContext.BaseDirectory, "..", "..", "..", "..", "..")); [Fact] public void Test01_ExplorerLauncher_CreatesMissingFolder_And_LaunchesExplorerWithFolderPath() { string uniqueFolder = Path.Combine(Path.GetTempPath(), $"paca_e2e_folder_{Guid.NewGuid():N}"); try { Assert.False(Directory.Exists(uniqueFolder), "Test directory should not exist prior to test"); // Build start info for folder opening var psi = ExplorerLauncher.BuildProcessStartInfo(null, uniqueFolder); // 1. Directory must be created automatically on disk! Assert.True(Directory.Exists(uniqueFolder), "ExplorerLauncher should auto-create destination folder if missing"); // 2. Must launch explorer.exe directly with quoted path argument Assert.Equal("explorer.exe", psi.FileName); Assert.Contains(uniqueFolder, psi.Arguments); Assert.True(psi.UseShellExecute); } finally { if (Directory.Exists(uniqueFolder)) Directory.Delete(uniqueFolder); } } [Fact] public void Test02_ExplorerLauncher_SelectedFile_LaunchesSelectArgument() { string uniqueFolder = Path.Combine(Path.GetTempPath(), $"paca_e2e_select_{Guid.NewGuid():N}"); Directory.CreateDirectory(uniqueFolder); string testFile = Path.Combine(uniqueFolder, "test_video.mp4"); File.WriteAllText(testFile, "dummy"); try { var psi = ExplorerLauncher.BuildProcessStartInfo(testFile, uniqueFolder); Assert.Equal("explorer.exe", psi.FileName); Assert.Contains("/select,", psi.Arguments); Assert.Contains(testFile, psi.Arguments); Assert.True(psi.UseShellExecute); } finally { if (Directory.Exists(uniqueFolder)) Directory.Delete(uniqueFolder, true); } } [Fact] public async Task Test03_QuickAction_MediaOpenOutputFolder_ActuallyInvokesFolderOpener() { var catalog = new QuickActionCatalog(); var action = catalog.GetAction("media.open_output_folder"); Assert.NotNull(action); string? openedFolder = "NOT_CALLED"; var ctx = new QuickActionContext( OutputFolder: @"C:\Downloads\Paca", FolderOpener: path => openedFolder = path ); Assert.NotNull(action.Handler); var result = await action.Handler.Invoke(ctx); Assert.True(result.Success); // It must NOT just display a toast, it must invoke FolderOpener! Assert.Null(openedFolder); // FolderOpener(null) opens the output folder } [Fact] public void Test04_NewTabPage_OpenDownloadsMessage_CallsOpenInExplorer() { string mainCs = File.ReadAllText(Path.Combine(SolutionRoot, "src", "Paca.App", "MainWindow.xaml.cs")); Assert.Contains("case \"ntp:opendownloads\":", mainCs); // ntp:opendownloads must call OpenInExplorer(null) to open the real Windows Explorer folder int idx = mainCs.IndexOf("case \"ntp:opendownloads\":", StringComparison.OrdinalIgnoreCase); Assert.True(idx >= 0); string block = mainCs.Substring(idx, 200); Assert.Contains("OpenInExplorer(null)", block); } }