using Avalonia.Controls; using Avalonia.Threading; using DodoSSH.Client.App.Views; using DodoSSH.Client.Session; using DodoSSH.Client.Shell.ViewModels; using DodoSSH.Client.Ssh; using DodoSSH.Client.Storage; using DodoSSH.Client.Terminal; using DodoSSH.Client.Transfer; using DodoSSH.Crypto; using NSubstitute; namespace DodoSSH.Client.App.Layout.Tests; /// /// The real main window over a real shell, for the tests that are about where the keyboard goes. /// /// /// says this window cannot be shown here: the /// terminal's WebView refuses this thread's apartment when it is attached. It is taken out of the tree before /// the window is shown, which is everything that test is about and nothing these are. /// internal static class WholeWindow { internal const string Passphrase = "a sufficiently long passphrase"; internal static readonly Argon2Profile CheapProfile = Argon2Profile.FromStoredParameters(memoryKibibytes: 8 * 1024, passes: 1, parallelism: 1); internal static TerminalWorkspace Workspace() => new( new InMemoryTerminalAssetProvider(new Dictionary(StringComparer.Ordinal)), Substitute.For(), TimeProvider.System); internal static MainWindowViewModel Shell(ClientCacheFactory caches, TerminalWorkspace workspace) => new( new ClientPaths(Path.Combine(Path.GetTempPath(), $"dodossh-focus-{Guid.CreateVersion7():N}")), caches, workspace, new VaultKnownHostStore(), new UnavailableDeviceKeyStore(), static (_, _) => throw new InvalidOperationException("A layout test has no network."), TimeProvider.System, Substitute.For(), CheapProfile); internal static void Show(MainWindowViewModel shell, Action assert) { var window = new MainWindow { DataContext = shell }; if (window.FindControl("Terminal") is { Parent: Panel panel } web) { panel.Children.Remove(web); } try { LayoutHarness.Settle(window, LayoutHarness.MinimumWidth, LayoutHarness.MinimumHeight); Dispatcher.UIThread.RunJobs(); assert(window); } finally { window.Close(); } } }