using Avalonia.Controls; using Avalonia.Input; using DodoSSH.Client.App.Views; using DodoSSH.Client.Session; using DodoSSH.Client.Session.Tests; using DodoSSH.Client.Shell.ViewModels; using DodoSSH.Client.Storage; namespace DodoSSH.Client.App.Layout.Tests; /// /// The keyboard on the cards a closed vault shows: where it is when the card appears, and what Enter does. /// /// /// /// Launch used to leave the keyboard nowhere. Focus only moved on the way out of an unlocked vault, so the /// passphrase somebody started typing the moment the window appeared went nowhere until they clicked the box, /// and Enter in the server address did nothing at all. /// /// /// The whole window, shown the way describes. /// /// public sealed class ClosedVaultFocusTests { private static CancellationToken Token => TestContext.Current.CancellationToken; [Fact] public async Task AFreshMachine_PutsTheKeyboardInTheServerAddressAndEnterSignsIn() { using var caches = ClientCacheFactory.ForMemory($"focus-{Guid.CreateVersion7():N}"); await caches.MigrateAsync(Token); await using var workspace = WholeWindow.Workspace(); await using var shell = WholeWindow.Shell(caches, workspace); await shell.StartAsync(Token); shell.State.ShouldBe(ShellState.NeedsServer); await LayoutHarness.OnTheUiThreadAsync( () => WholeWindow.Show(shell, window => { var box = window.FindControl("ServerUrlBox").ShouldNotBeNull(); window.FocusManager!.GetFocusedElement().ShouldBeSameAs(box); box.KeyBindings.ShouldContain(binding => binding.Gesture == new KeyGesture(Key.Enter) && binding.Command == shell.SignInCommand); }), Token); } [Fact] public async Task AnEnrolledMachine_PutsTheKeyboardInThePassphraseBox() { using var caches = ClientCacheFactory.ForMemory($"focus-{Guid.CreateVersion7():N}"); await caches.MigrateAsync(Token); await new AccountProvisioner(new FakeAccountServer(), new StubKeyBinding(), caches, TimeProvider.System, WholeWindow.CheapProfile) .EnrollAsync("https://dodossh.example", WholeWindow.Passphrase, "laptop", "Personal", Token); await using var workspace = WholeWindow.Workspace(); await using var shell = WholeWindow.Shell(caches, workspace); await shell.StartAsync(Token); shell.State.ShouldBe(ShellState.Locked); await LayoutHarness.OnTheUiThreadAsync( () => WholeWindow.Show(shell, window => window.FocusManager!.GetFocusedElement() .ShouldBeSameAs(window.FindControl("UnlockPane").ShouldNotBeNull().PassphraseBox)), Token); } }