Files
LanMountainDesktop/LanMountainDesktop.Tests/HostAppSettingsOobeMergerTests.cs
lincube 60e7f31ba7 Add OOBE startup presentation and settings merge
Introduce a new OOBE step for "Startup & Presentation" that exposes startup and UI preferences in OobeWindow (toggles for taskbar, slide/fade transitions, fused popup, and autostart). Add HostAppSettingsOobeMerger to read/write Host settings.json (PascalCase fields) and MergeStartupPresentation behavior, plus LauncherWindowsStartupService to sync the current Launcher into the Windows Run key on Windows. Wire UI handlers, persist choices on Next, and load defaults when entering the step. Include unit tests for the merger, adjust SettingsWindow navigation pane/toggle handling, and update docs/LAUNCHER.md to describe the new OOBE step and implementation files.
2026-05-04 11:22:21 +08:00

92 lines
3.0 KiB
C#

using LanMountainDesktop.Launcher.Services;
using Xunit;
namespace LanMountainDesktop.Tests;
public sealed class HostAppSettingsOobeMergerTests
{
[Fact]
public void MergeStartupPresentation_PreservesUnrelatedJsonKeys()
{
var dir = Path.Combine(Path.GetTempPath(), "LMD.OobeMerge", Guid.NewGuid().ToString("N"));
Directory.CreateDirectory(dir);
var path = Path.Combine(dir, "settings.json");
File.WriteAllText(path, """
{
"LanguageCode": "ja-JP",
"ShowInTaskbar": false,
"EnableFadeTransition": true,
"EnableSlideTransition": false
}
""");
try
{
HostAppSettingsOobeMerger.MergeStartupPresentation(
path,
new HostAppSettingsStartupChoices(
ShowInTaskbar: true,
EnableFadeTransition: false,
EnableSlideTransition: true,
FusedPopupExperience: true,
AutoStartWithWindows: true));
var json = File.ReadAllText(path);
using var doc = System.Text.Json.JsonDocument.Parse(json);
var root = doc.RootElement;
Assert.Equal("ja-JP", root.GetProperty("LanguageCode").GetString());
Assert.True(root.GetProperty("ShowInTaskbar").GetBoolean());
Assert.False(root.GetProperty("EnableFadeTransition").GetBoolean());
Assert.True(root.GetProperty("EnableSlideTransition").GetBoolean());
Assert.True(root.GetProperty("EnableFusedDesktop").GetBoolean());
Assert.True(root.GetProperty("EnableThreeFingerSwipe").GetBoolean());
Assert.True(root.GetProperty("AutoStartWithWindows").GetBoolean());
}
finally
{
Directory.Delete(dir, recursive: true);
}
}
[Fact]
public void GetSettingsFilePath_NormalizesDataRoot()
{
var root = Path.Combine(Path.GetTempPath(), "LMD.OobePath", Guid.NewGuid().ToString("N"));
Directory.CreateDirectory(root);
try
{
var path = HostAppSettingsOobeMerger.GetSettingsFilePath(root + Path.DirectorySeparatorChar);
Assert.Equal(Path.Combine(Path.GetFullPath(root), "settings.json"), path);
}
finally
{
Directory.Delete(root);
}
}
[Fact]
public void LoadStartupDefaults_WhenFusedAndSwipeDiffer_TreatsPopupExperienceAsBothTrue()
{
var dir = Path.Combine(Path.GetTempPath(), "LMD.OobeDefaults", Guid.NewGuid().ToString("N"));
Directory.CreateDirectory(dir);
var path = Path.Combine(dir, "settings.json");
File.WriteAllText(path, """
{
"EnableFusedDesktop": true,
"EnableThreeFingerSwipe": false
}
""");
try
{
var d = HostAppSettingsOobeMerger.LoadStartupDefaults(path);
Assert.False(d.FusedPopupExperience);
}
finally
{
Directory.Delete(dir, recursive: true);
}
}
}