Public Access
75 lines
2.8 KiB
C#
75 lines
2.8 KiB
C#
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;
|
|
|
|
/// <summary>
|
|
/// The keyboard on the cards a closed vault shows: where it is when the card appears, and what Enter does.
|
|
/// </summary>
|
|
/// <remarks>
|
|
/// <para>
|
|
/// 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.
|
|
/// </para>
|
|
/// <para>
|
|
/// The whole window, shown the way <see cref="WholeWindow"/> describes.
|
|
/// </para>
|
|
/// </remarks>
|
|
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<TextBox>("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<UnlockCard>("UnlockPane").ShouldNotBeNull().PassphraseBox)),
|
|
Token);
|
|
}
|
|
}
|