Files
poli0981andClaude Opus 4.8 6a198872d1 Phase 5c: Home dashboard, favorites, window-state, accessibility
Completes Phase 5 (Polish):
- Home dashboard (default screen): recent commands, pinned favorites,
  and a read-only system-status widget (Windows + build, RAM, system
  drive, uptime) via ISystemInfoService. Status is read locally with
  no process spawn, no elevation and no network (golden rules).
- Favorites: pin/unpin from the list + detail star, persisted by id in
  config.json; a Favorites sidebar item filters the catalog to pins.
- Recent commands: last 10 run command ids tracked for Home.
- Window placement: persist + restore size/position/maximized, clamped
  to the virtual screen so a stale multi-monitor position never lands
  off-screen.
- Accessibility: AutomationProperties.Name on new controls + palette
  and confirmation inputs; heading semantics on Home; Ctrl+H opens Home.

Implementation notes:
- ISystemInfoService uses Environment.OSVersion + CsWin32
  GlobalMemoryStatusEx + DriveInfo + TickCount64 (AllowUnsafeBlocks for
  the generated interop).
- Pure, unit-tested helpers RecentCommands.Add / Favorites.Toggle and
  WindowPlacement.IsOnScreen.
- 102 tests pass; 0-warning Release build.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
2026-06-18 14:33:48 +07:00

87 lines
2.5 KiB
C#

using CommandForge.Application;
using CommandForge.Application.Logging;
using CommandForge.Application.Ports;
using CommandForge.Application.Settings;
namespace CommandForge.Tests;
/// <summary>Tests for the first-run legal acceptance logic.</summary>
public sealed class LegalGateServiceTests
{
[Fact]
public void HasAcceptedCurrentTerms_IsFalse_WhenNothingAccepted()
{
var settings = new FakeSettings();
var sut = new LegalGateService(settings);
Assert.False(sut.HasAcceptedCurrentTerms());
}
[Fact]
public void AcceptCurrentTerms_RecordsAndPersistsCurrentVersion()
{
var settings = new FakeSettings();
var sut = new LegalGateService(settings);
sut.AcceptCurrentTerms();
Assert.Equal(LegalGateService.CurrentTermsVersion, settings.AcceptedTermsVersion);
Assert.True(sut.HasAcceptedCurrentTerms());
Assert.Equal(1, settings.SaveCount);
}
[Fact]
public void HasAcceptedCurrentTerms_IsFalse_WhenOlderVersionAccepted()
{
var settings = new FakeSettings { AcceptedTermsVersion = "0.0" };
var sut = new LegalGateService(settings);
Assert.False(sut.HasAcceptedCurrentTerms());
}
private sealed class FakeSettings : ISettingsService
{
public string? AcceptedTermsVersion { get; set; }
public bool AutoCheckForUpdates { get; set; } = true;
public AppTheme Theme { get; set; } = AppTheme.System;
public string Language { get; set; } = "";
public FontScale FontSize { get; set; } = FontScale.Medium;
public bool CollapseSidebarByDefault { get; set; }
public bool ShowAdminRestartBadges { get; set; } = true;
public bool ConfirmCaution { get; set; } = true;
public bool AutoCreateRestorePoint { get; set; } = true;
public bool AutoScrollConsole { get; set; } = true;
public bool WarnOnCancel { get; set; } = true;
public LogLevel LogLevel { get; set; } = LogLevel.Information;
public IReadOnlyList<string> FavoriteCommandIds { get; set; } = [];
public IReadOnlyList<string> RecentCommandIds { get; set; } = [];
public double? WindowWidth { get; set; }
public double? WindowHeight { get; set; }
public double? WindowLeft { get; set; }
public double? WindowTop { get; set; }
public bool WindowMaximized { get; set; }
public int SaveCount { get; private set; }
public void Save() => SaveCount++;
}
}