feat(ui): add MissionControlViewModel
This commit is contained in:
@@ -0,0 +1,117 @@
|
||||
using ClaudeDo.Data;
|
||||
using ClaudeDo.Ui.Services;
|
||||
using ClaudeDo.Ui.ViewModels;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using Xunit;
|
||||
|
||||
namespace ClaudeDo.Ui.Tests.ViewModels;
|
||||
|
||||
public class MissionControlViewModelTests : IDisposable
|
||||
{
|
||||
private readonly string _dbPath;
|
||||
|
||||
public MissionControlViewModelTests()
|
||||
{
|
||||
_dbPath = Path.Combine(Path.GetTempPath(), $"claudedo_mc_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 FakeWorker : StubWorkerClient { }
|
||||
|
||||
private MissionControlViewModel BuildVm(StubWorkerClient worker)
|
||||
=> new MissionControlViewModel(new TestDbFactory(NewContext), worker);
|
||||
|
||||
[Fact]
|
||||
public void TwoStarts_CreateTwoMonitors_ColumnCountTwo()
|
||||
{
|
||||
var worker = new FakeWorker();
|
||||
using var vm = BuildVm(worker);
|
||||
|
||||
worker.RaiseTaskStarted("slot-1", "t1", DateTime.UtcNow);
|
||||
worker.RaiseTaskStarted("slot-2", "t2", DateTime.UtcNow);
|
||||
|
||||
Assert.Equal(2, vm.Monitors.Count);
|
||||
Assert.Equal(2, vm.ColumnCount);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void DuplicateStart_DoesNotAddSecondMonitor()
|
||||
{
|
||||
var worker = new FakeWorker();
|
||||
using var vm = BuildVm(worker);
|
||||
|
||||
worker.RaiseTaskStarted("slot-1", "t1", DateTime.UtcNow);
|
||||
worker.RaiseTaskStarted("slot-1", "t1", DateTime.UtcNow);
|
||||
|
||||
Assert.Equal(1, vm.Monitors.Count);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Finish_KeepsPane_AndFlipsState()
|
||||
{
|
||||
var worker = new FakeWorker();
|
||||
using var vm = BuildVm(worker);
|
||||
|
||||
worker.RaiseTaskStarted("slot-1", "t1", DateTime.UtcNow);
|
||||
worker.RaiseTaskFinished("slot-1", "t1", "done", DateTime.UtcNow);
|
||||
|
||||
Assert.Equal(1, vm.Monitors.Count);
|
||||
Assert.True(vm.Monitors[0].IsDone);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void ClearFinished_RemovesTerminalMonitors()
|
||||
{
|
||||
var worker = new FakeWorker();
|
||||
using var vm = BuildVm(worker);
|
||||
|
||||
worker.RaiseTaskStarted("slot-1", "t1", DateTime.UtcNow);
|
||||
worker.RaiseTaskStarted("slot-2", "t2", DateTime.UtcNow);
|
||||
worker.RaiseTaskFinished("slot-1", "t1", "done", DateTime.UtcNow);
|
||||
|
||||
vm.ClearFinishedCommand.Execute(null);
|
||||
|
||||
Assert.Equal(1, vm.Monitors.Count);
|
||||
Assert.Equal("t2", vm.Monitors[0].SubscribedTaskId);
|
||||
Assert.Equal(1, vm.ColumnCount);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void SeedsFromActiveTasksOnConstruction()
|
||||
{
|
||||
var worker = new SeededFakeWorker();
|
||||
using var vm = BuildVm(worker);
|
||||
|
||||
Assert.Equal(1, vm.Monitors.Count);
|
||||
Assert.Equal("seed1", vm.Monitors[0].SubscribedTaskId);
|
||||
}
|
||||
|
||||
private sealed class SeededFakeWorker : StubWorkerClient
|
||||
{
|
||||
public override IReadOnlyList<ActiveTask> GetActiveTasks()
|
||||
=> new[] { new ActiveTask("slot-1", "seed1", DateTime.UtcNow) };
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user