97 lines
3.4 KiB
C#
97 lines
3.4 KiB
C#
using System.Collections.ObjectModel;
|
|
using ClaudeDo.Data;
|
|
using ClaudeDo.Data.Models;
|
|
using ClaudeDo.Data.Repositories;
|
|
using ClaudeDo.Ui.Services;
|
|
using ClaudeDo.Ui.ViewModels.Islands;
|
|
using Microsoft.EntityFrameworkCore;
|
|
using TaskStatus = ClaudeDo.Data.Models.TaskStatus;
|
|
|
|
namespace ClaudeDo.Ui.Tests.ViewModels;
|
|
|
|
public class DetailsIslandConflictSeamTests : IDisposable
|
|
{
|
|
private readonly string _dbPath;
|
|
|
|
public DetailsIslandConflictSeamTests()
|
|
{
|
|
_dbPath = Path.Combine(Path.GetTempPath(), $"claudedo_conflict_seam_test_{Guid.NewGuid():N}.db");
|
|
using var ctx = NewContext();
|
|
ctx.Database.EnsureCreated();
|
|
}
|
|
|
|
public void Dispose()
|
|
{
|
|
try { File.Delete(_dbPath); } catch { }
|
|
try { File.Delete(_dbPath + "-wal"); } catch { }
|
|
try { File.Delete(_dbPath + "-shm"); } catch { }
|
|
}
|
|
|
|
private ClaudeDoDbContext NewContext()
|
|
{
|
|
var opts = new DbContextOptionsBuilder<ClaudeDoDbContext>()
|
|
.UseSqlite($"Data Source={_dbPath}")
|
|
.Options;
|
|
return new ClaudeDoDbContext(opts);
|
|
}
|
|
|
|
private sealed class TestDbFactory : IDbContextFactory<ClaudeDoDbContext>
|
|
{
|
|
private readonly Func<ClaudeDoDbContext> _create;
|
|
public TestDbFactory(Func<ClaudeDoDbContext> create) => _create = create;
|
|
public ClaudeDoDbContext CreateDbContext() => _create();
|
|
}
|
|
|
|
private sealed class NullServiceProvider : IServiceProvider
|
|
{
|
|
public object? GetService(Type serviceType) => null;
|
|
}
|
|
|
|
private sealed class StubNotesApi : ClaudeDo.Ui.Services.Interfaces.INotesApi
|
|
{
|
|
public Task<List<ClaudeDo.Ui.Services.DailyNoteDto>> ListAsync(DateOnly day) =>
|
|
Task.FromResult(new List<ClaudeDo.Ui.Services.DailyNoteDto>());
|
|
public Task<ClaudeDo.Ui.Services.DailyNoteDto?> AddAsync(DateOnly day, string text) =>
|
|
Task.FromResult<ClaudeDo.Ui.Services.DailyNoteDto?>(null);
|
|
public Task UpdateAsync(string id, string text) => Task.CompletedTask;
|
|
public Task DeleteAsync(string id) => Task.CompletedTask;
|
|
}
|
|
|
|
private sealed class ConflictApproveWorkerClient : StubWorkerClient
|
|
{
|
|
public override bool IsConnected => true;
|
|
public override Task<MergeResultDto?> ApproveReviewAsync(string taskId, string targetBranch) =>
|
|
Task.FromResult<MergeResultDto?>(new MergeResultDto("conflict", new[] { "a.cs" }, null));
|
|
}
|
|
|
|
private DetailsIslandViewModel BuildVm(StubWorkerClient worker)
|
|
{
|
|
var factory = new TestDbFactory(NewContext);
|
|
return new DetailsIslandViewModel(factory, worker, new NullServiceProvider(), new StubNotesApi());
|
|
}
|
|
|
|
[Fact]
|
|
public async Task ApproveReview_OnConflict_InvokesConflictResolutionSeam()
|
|
{
|
|
const string taskId = "task-conflict-1";
|
|
|
|
var vm = BuildVm(new ConflictApproveWorkerClient());
|
|
vm.Bind(new TaskRowViewModel { Id = taskId, Status = TaskStatus.WaitingForReview });
|
|
vm.SelectedMergeTarget = "main";
|
|
|
|
string? capturedTaskId = null;
|
|
string? capturedTarget = null;
|
|
vm.RequestConflictResolution = (tid, target) =>
|
|
{
|
|
capturedTaskId = tid;
|
|
capturedTarget = target;
|
|
return Task.CompletedTask;
|
|
};
|
|
|
|
await vm.ApproveReviewCommand.ExecuteAsync(null);
|
|
|
|
Assert.Equal(taskId, capturedTaskId);
|
|
Assert.Equal("main", capturedTarget);
|
|
}
|
|
}
|