Files
ClaudeDo/tests/ClaudeDo.Ui.Tests/ViewModels/WorktreesOverviewModalErrorTests.cs
T
Mika Kuns a0d5db0db0 feat(ui): separate OperationStatus per worktree action (refresh/cleanup/reset/force-remove/batch-merge)
Replaces the shared IsBusy/IsMerging flags in WorktreesOverviewModalViewModel and the
reset flow in WorktreesSettingsTabViewModel with dedicated OperationStatus instances
shown via OperationIndicator, so a running Refresh no longer blocks the Cleanup
indicator. ForceRemove gains a CanExecute guard against re-entrancy while it's running,
and the reconcile tick's busy guard now checks all four action statuses instead of the
old IsBusy||IsMerging pair.
2026-08-12 09:39:10 +02:00

80 lines
2.8 KiB
C#

using System.IO;
using ClaudeDo.Localization;
using ClaudeDo.Ui.Localization;
using ClaudeDo.Ui.Services;
using ClaudeDo.Ui.ViewModels.Modals;
namespace ClaudeDo.Ui.Tests.ViewModels;
public class WorktreesOverviewModalErrorTests
{
public WorktreesOverviewModalErrorTests()
{
var dir = AppContext.BaseDirectory;
while (dir is not null && !Directory.Exists(Path.Combine(dir, "src", "ClaudeDo.Localization", "locales")))
dir = Path.GetDirectoryName(dir);
Loc.Current = new Localizer(
LocaleStore.Load(Path.Combine(dir!, "src", "ClaudeDo.Localization", "locales")), "en");
}
private sealed class ThrowingWorker : StubWorkerClient
{
public string ExceptionMessage { get; init; } = "worktree is locked by another process";
public override Task<List<WorktreeOverviewDto>> GetWorktreesOverviewAsync(string? listId) =>
throw new Exception(ExceptionMessage);
public override Task<WorktreeCleanupDto?> CleanupFinishedWorktreesAsync(string? listId = null) =>
throw new Exception(ExceptionMessage);
public override Task<ForceRemoveResultDto?> ForceRemoveWorktreeAsync(string taskId) =>
throw new Exception(ExceptionMessage);
}
private static WorktreesOverviewModalViewModel NewVm(ThrowingWorker worker) =>
new(worker, () => null!, new MergeCoordinator());
[Fact]
public async Task CleanupFinished_WhenWorkerThrows_ShowsExceptionMessage()
{
var worker = new ThrowingWorker();
var vm = NewVm(worker);
await vm.CleanupFinishedCommand.ExecuteAsync(null);
Assert.NotNull(vm.StatusMessage);
Assert.Contains(worker.ExceptionMessage, vm.StatusMessage);
Assert.False(vm.CleanupStatus.IsRunning);
}
[Fact]
public async Task ForceRemove_WhenWorkerThrows_ShowsExceptionMessage_AndKeepsRow()
{
var worker = new ThrowingWorker();
var vm = NewVm(worker);
var row = new WorktreeOverviewRowViewModel
{
TaskId = "task-1",
TaskTitle = "Task 1",
TaskStatus = ClaudeDo.Data.Models.TaskStatus.Idle,
State = ClaudeDo.Data.Models.WorktreeState.Active,
};
vm.AddRowForTest(row);
await vm.ForceRemoveCommand.ExecuteAsync(row);
Assert.NotNull(vm.StatusMessage);
Assert.Contains(worker.ExceptionMessage, vm.StatusMessage);
Assert.Contains(row, vm.Rows);
Assert.False(vm.ForceRemoveStatus.IsRunning);
}
[Fact]
public async Task Refresh_WhenWorkerThrows_ResetsRefreshStatus()
{
var worker = new ThrowingWorker();
var vm = NewVm(worker);
await Assert.ThrowsAsync<Exception>(() => vm.RefreshCommand.ExecuteAsync(null));
Assert.False(vm.RefreshStatus.IsRunning);
}
}