| | |
| | | using Moli.Desktop.Configuration; |
| | | using Moli.Desktop.Diagnostics; |
| | | using Moli.Desktop.Host; |
| | | using Moli.Desktop.Hotkeys; |
| | | using Moli.Desktop.Layout; |
| | | using Moli.Desktop.Plugins; |
| | | |
| | |
| | | Assert.Equal(1, snapshot.AppSettings.SchemaVersion); |
| | | Assert.Equal(1, snapshot.Plugins.SchemaVersion); |
| | | Assert.Equal(1, snapshot.Layout.SchemaVersion); |
| | | Assert.Equal(1, snapshot.Hotkeys.SchemaVersion); |
| | | Assert.True(File.Exists(Path.Combine(paths.ConfigDirectory, "appsettings.json"))); |
| | | Assert.True(File.Exists(Path.Combine(paths.ConfigDirectory, "plugins.json"))); |
| | | Assert.True(File.Exists(Path.Combine(paths.ConfigDirectory, "layout.json"))); |
| | | Assert.True(File.Exists(Path.Combine(paths.ConfigDirectory, "hotkeys.json"))); |
| | | Assert.Contains(snapshot.Hotkeys.Bindings, binding => binding.Id == "llm-palette-toggle-interactable"); |
| | | } |
| | | |
| | | [Fact] |
| | |
| | | Assert.Equal(DisplayLayer.AppTop, Assert.Single(loaded.Instances).DisplayLayer); |
| | | } |
| | | |
| | | [Fact] |
| | | public async Task LoadHotkeysAsync_CreatesDefaultBuiltinBinding() |
| | | { |
| | | var (service, paths, _) = CreateService(); |
| | | |
| | | var document = await service.LoadHotkeysAsync(); |
| | | |
| | | var binding = Assert.Single(document.Bindings); |
| | | Assert.Equal("llm-palette-toggle-interactable", binding.Id); |
| | | Assert.Equal("Ctrl+Shift+K", binding.Keys); |
| | | Assert.Equal("widget.toggleInteractable", binding.Action); |
| | | Assert.Equal("sample.llm-command-palette", binding.Target?.PluginId); |
| | | Assert.Equal(HotkeySource.Builtin, binding.Source); |
| | | Assert.True(File.Exists(Path.Combine(paths.ConfigDirectory, "hotkeys.json"))); |
| | | } |
| | | |
| | | [Fact] |
| | | public async Task LoadHotkeysAsync_BacksUpInvalidJsonAndRecoversDefault() |
| | | { |
| | | var (service, paths, diagnostics) = CreateService(); |
| | | Directory.CreateDirectory(paths.ConfigDirectory); |
| | | await File.WriteAllTextAsync(Path.Combine(paths.ConfigDirectory, "hotkeys.json"), "{ broken json"); |
| | | |
| | | var document = await service.LoadHotkeysAsync(); |
| | | |
| | | Assert.Equal(1, document.SchemaVersion); |
| | | Assert.Contains(document.Bindings, binding => binding.Id == "llm-palette-toggle-interactable"); |
| | | Assert.NotEmpty(Directory.GetFiles(paths.ConfigDirectory, "hotkeys.invalid.*.json")); |
| | | Assert.Contains(diagnostics.Snapshot(), entry => entry.Code == DiagnosticCodes.ConfigurationRecovered); |
| | | } |
| | | |
| | | [Fact] |
| | | public async Task SaveAndLoadHotkeysAsync_RoundTripsUserBinding() |
| | | { |
| | | var (service, _, _) = CreateService(); |
| | | var document = HotkeysDocument.CreateDefault(); |
| | | document.Bindings.Add(new HotkeyBinding |
| | | { |
| | | Id = "user-edit-mode", |
| | | Keys = "Ctrl+Alt+E", |
| | | Action = HotkeyActions.RuntimeToggleEditMode, |
| | | Enabled = true, |
| | | Source = HotkeySource.User |
| | | }); |
| | | |
| | | await service.SaveHotkeysAsync(document); |
| | | var loaded = await service.LoadHotkeysAsync(); |
| | | |
| | | Assert.Equal(2, loaded.Bindings.Count); |
| | | Assert.Contains(loaded.Bindings, binding => binding.Id == "user-edit-mode" && binding.Keys == "Ctrl+Alt+E"); |
| | | } |
| | | |
| | | private static (JsonConfigurationService Service, DesktopPaths Paths, DiagnosticsService Diagnostics) CreateService() |
| | | { |
| | | var root = Path.Combine(Path.GetTempPath(), "Moli.Desktop.Tests", Guid.NewGuid().ToString("N")); |