acdream/tests/AcDream.UI.Abstractions.Tests/Panels/Settings/DisplaySettingsTests.cs
Erik 382f0ad3fa feat(ui): Display tab + settings.json persistence — first non-keybind tab lands
Phase L.0 (cont.) — first concrete tab on the new Settings shell, in
the Easy-wins build order agreed in the brainstorm
(Display → Audio → Gameplay → Chat → Character).

DisplaySettings (immutable record): Resolution / Fullscreen / VSync /
FieldOfView (30-120°) / Gamma (0.5-2.0) / ShowFps. Six common 16:9
resolutions in the dropdown. Defaults: 1920×1080, windowed, vsync on,
75° FOV, gamma 1.0, FPS off — matches the brainstorm UX agreement.

SettingsStore: JSON persistence at %LOCALAPPDATA%\acdream\settings.json
(coexists with keybinds.json — own load/save path stays put, no
migration needed). LoadDisplay falls back per-field when keys are
missing (partial-file tolerant) and falls back to defaults when the
file is corrupt or the JSON is unparseable. SaveDisplay round-trips
preserved — unknown top-level keys (e.g. an `audio` section written
by a future client) are kept on save so older builds don't silently
drop newer-tab data.

SettingsVM gains a parallel display-state machine: persistedDisplay +
draftDisplay, SetDisplay mutator, HasUnsavedChanges checks both
keybinds and display deltas, Save/Cancel/ResetAll cover both
atomically from the user's POV (one Save commits everything, one
Cancel reverts everything). Constructor signature extends with two
new params; existing keybinds-only callers updated.

SettingsPanel.RenderDisplayTab replaces the L.0-shell placeholder —
Combo for resolution, Checkboxes for fullscreen/vsync/show-fps,
SliderFloat for FOV + gamma. Live-preview note in the panel body
matches the agreed UX: FOV + gamma update visibly while the user
drags; resolution / fullscreen / vsync apply on Save (live preview
would be too jarring).

GameWindow wires SettingsStore into the existing SettingsVM construct
site — load on startup, save on each tab Save. Errors print to
console and don't crash the panel.

19 new tests:
 · DisplaySettings record (4) — defaults pinned, value equality, with-
   expressions, AvailableResolutions sorted ascending
 · SettingsStore (6) — round trip, missing-file → defaults, corrupt-
   file → defaults, partial-file → per-field fallback, unknown-key
   preservation, DefaultPath shape
 · SettingsVM display (6) — initial draft tracks persisted, SetDisplay
   marks dirty, Save invokes display callback, Cancel reverts,
   ResetAllToDefaults covers display, Save-then-Cancel is no-op
 · SettingsPanel display tab (3) — widgets render only when active,
   resolution combo uses AvailableResolutions, no Combo emitted on
   inactive tabs

dotnet build green (0 warnings); dotnet test 1,246 / 1,246 green
(243 Core.Net + 330 UI.Abstractions + 673 Core).

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
2026-04-26 17:46:31 +02:00

67 lines
2.1 KiB
C#

using AcDream.UI.Abstractions.Panels.Settings;
namespace AcDream.UI.Abstractions.Tests.Panels.Settings;
/// <summary>
/// L.0: <see cref="DisplaySettings"/> is the immutable record of
/// display-tab preferences. Defaults are pinned here so a regression
/// (e.g. someone changing the default FOV out from under users)
/// surfaces immediately.
/// </summary>
public sealed class DisplaySettingsTests
{
[Fact]
public void Default_values_match_brainstorm_agreement()
{
var d = DisplaySettings.Default;
Assert.Equal("1920x1080", d.Resolution);
Assert.False(d.Fullscreen);
Assert.True(d.VSync);
Assert.Equal(75f, d.FieldOfView);
Assert.Equal(1.0f, d.Gamma);
Assert.False(d.ShowFps);
}
[Fact]
public void AvailableResolutions_includes_common_16_9_options()
{
var list = DisplaySettings.AvailableResolutions;
Assert.Contains("1280x720", list);
Assert.Contains("1920x1080", list);
Assert.Contains("2560x1440", list);
Assert.Contains("3840x2160", list);
// List should be ascending so the dropdown reads naturally.
for (int i = 1; i < list.Count; i++)
{
int prevW = ParseWidth(list[i - 1]);
int curW = ParseWidth(list[i]);
Assert.True(curW >= prevW, $"Resolutions not sorted: {list[i - 1]} >= {list[i]}");
}
}
[Fact]
public void Equality_is_value_based()
{
var a = DisplaySettings.Default;
var b = DisplaySettings.Default with { ShowFps = true };
var c = DisplaySettings.Default with { ShowFps = true };
Assert.NotEqual(a, b);
Assert.Equal(b, c);
}
[Fact]
public void With_expression_clones_one_field()
{
var d = DisplaySettings.Default with { FieldOfView = 90f };
Assert.Equal(90f, d.FieldOfView);
// Other fields untouched.
Assert.Equal("1920x1080", d.Resolution);
Assert.True(d.VSync);
}
private static int ParseWidth(string res)
{
int x = res.IndexOf('x');
return int.Parse(res.AsSpan(0, x));
}
}