70 lines
1.8 KiB
C#
70 lines
1.8 KiB
C#
using FluentAssertions;
|
|
using FreeCode.State;
|
|
using Xunit;
|
|
|
|
namespace FreeCode.Tests.Unit.State;
|
|
|
|
public sealed class AppStateStoreTests
|
|
{
|
|
[Fact]
|
|
public void InitialState_HasDefaults()
|
|
{
|
|
var sut = new AppStateStore();
|
|
|
|
var state = sut.GetTypedState();
|
|
|
|
state.Verbose.Should().BeFalse();
|
|
state.PermissionMode.Should().Be(FreeCode.Core.Enums.PermissionMode.Default);
|
|
state.Tasks.Should().BeEmpty();
|
|
}
|
|
|
|
[Fact]
|
|
public void Update_ChangesState()
|
|
{
|
|
var sut = new AppStateStore();
|
|
|
|
sut.Update(state => state with { Verbose = true, MainLoopModel = "claude" });
|
|
|
|
sut.GetTypedState().Verbose.Should().BeTrue();
|
|
sut.GetTypedState().MainLoopModel.Should().Be("claude");
|
|
}
|
|
|
|
[Fact]
|
|
public void Subscribe_ReceivesNotifications()
|
|
{
|
|
var sut = new AppStateStore();
|
|
object? observed = null;
|
|
|
|
using var subscription = sut.Subscribe(state => observed = state);
|
|
|
|
sut.Update(state => state with { StatusLineText = "updated" });
|
|
|
|
observed.Should().BeOfType<AppState>();
|
|
((AppState)observed!).StatusLineText.Should().Be("updated");
|
|
}
|
|
|
|
[Fact]
|
|
public void StateChanged_EventFires()
|
|
{
|
|
var sut = new AppStateStore();
|
|
FreeCode.Core.Models.StateChangedEventArgs? args = null;
|
|
sut.StateChanged += (_, eventArgs) => args = eventArgs;
|
|
|
|
sut.Update(state => state with { FastMode = true });
|
|
|
|
args.Should().NotBeNull();
|
|
((AppState)args!.OldState).FastMode.Should().BeFalse();
|
|
((AppState)args.NewState).FastMode.Should().BeTrue();
|
|
}
|
|
|
|
[Fact]
|
|
public void TypedUpdate_Works()
|
|
{
|
|
var sut = new AppStateStore();
|
|
|
|
sut.Update(state => state with { PromptSuggestionEnabled = true });
|
|
|
|
sut.GetTypedState().PromptSuggestionEnabled.Should().BeTrue();
|
|
}
|
|
}
|