Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_012iLMBNwBE2GnphAsu4cjaC
99 lines
4.5 KiB
C#
99 lines
4.5 KiB
C#
using System.Windows.Controls;
|
|
using System.Windows.Input;
|
|
using Titano.App.Import;
|
|
using Titano.App.Sections;
|
|
using Titano.App.Tests.Windows;
|
|
using Titano.Testing;
|
|
using Titano.Ui.Controls;
|
|
|
|
namespace Titano.App.Tests.Import;
|
|
|
|
/// <summary>
|
|
/// Every Import state of <c>--capture</c> (<see cref="ImportScenes"/>) on the simulated cards, rendered in both themes
|
|
/// in the real main window, with the figures and gates each state must show — and the buttons really enabled, not
|
|
/// only their commands.
|
|
/// </summary>
|
|
[WindowsOnly]
|
|
[Serial]
|
|
[Timeout(300_000)]
|
|
public sealed class ImportScreenSmokeTests
|
|
{
|
|
[Test]
|
|
public Task EveryImportStateRendersInBothThemes() => ScreenHost.RunAsync(async () =>
|
|
{
|
|
await using var app = await ScreenSmokeTests.SampleApp.StartAsync();
|
|
await app.Sample.FillAsync();
|
|
var import = app.Shell.Import;
|
|
|
|
await ShowAsync(app, "inserted");
|
|
Assert.NotEmpty(app.FindAll<ToastHost>().SelectMany(host => host.Toasts), "the insertion toast");
|
|
await app.ExpectAsync<ImportView>("import-inserted");
|
|
|
|
await ShowAsync(app, "plan");
|
|
Assert.Equal(ImportPhase.Ready, import.Phase);
|
|
Assert.Equal("EOS R5 · card A", import.SourceTitle);
|
|
Assert.Equal(3, import.Sessions.Count, "night, dawn and sunset");
|
|
Assert.Equal(50, import.Plan!.CopyCount);
|
|
Assert.Equal("Harbour sunset", import.Plan.Sessions[^1].Title);
|
|
Assert.Null(import.StartBlocker);
|
|
Assert.Empty(app.FindAll<ToastHost>().SelectMany(host => host.Toasts));
|
|
await app.ExpectAsync<ImportView>("import-plan");
|
|
Assert.True(ButtonFor(app, import.StartCommand).IsEnabled, "the Import button is enabled once the plan is ready");
|
|
Assert.True(ButtonFor(app, import.Sessions[1].MergeCommand).IsEnabled, "a session can merge into the one before");
|
|
|
|
await ShowAsync(app, "showplan");
|
|
Assert.True(import.IsDetailsOpen);
|
|
Assert.Equal(50 + 3, import.Details!.Rows.Count);
|
|
await app.ExpectAsync<ImportView>("import-showplan");
|
|
|
|
await ShowAsync(app, "running");
|
|
Assert.True(import.IsRunning);
|
|
Assert.False(import.IsFormEnabled);
|
|
Assert.False(import.Sessions[0].IsEditable, "titles lock while copying");
|
|
await app.ExpectAsync<ImportView>("import-running");
|
|
Assert.True(ButtonFor(app, import.CancelCommand).IsEnabled, "Cancel is enabled while copying");
|
|
|
|
await ShowAsync(app, "failed");
|
|
Assert.True(import.IsFailed);
|
|
await app.ExpectAsync<ImportView>("import-failed");
|
|
Assert.True(ButtonFor(app, import.RetryCommand).IsEnabled, "Retry is enabled after a failure");
|
|
|
|
await ShowAsync(app, "done");
|
|
Assert.True(import.IsDone);
|
|
var result = import.Result!;
|
|
Assert.True(result.IsComplete);
|
|
Assert.True(result.OffersDelete);
|
|
Assert.True(result.Actions.CanDelete, "a verified import and its dry run allow deleting");
|
|
Assert.Equal(49, result.Actions.DeleteCount);
|
|
Assert.False(result.Actions.CanFormat, "a photo touched since the import keeps the card from being formatted");
|
|
Assert.Empty(app.FindAll<ToastHost>().SelectMany(host => host.Toasts));
|
|
await app.ExpectAsync<ImportView>("import-done");
|
|
Assert.True(ButtonFor(app, result.DeleteCommand).IsEnabled, "the Delete button follows the dry run");
|
|
|
|
await ShowAsync(app, "newcard");
|
|
Assert.True(import.IsNicknameOpen, "a new card asks for its nickname");
|
|
Assert.Equal("SONY", import.SourceTitle);
|
|
Assert.NotEmpty(app.FindAll<ToastHost>().SelectMany(host => host.Toasts));
|
|
await app.ExpectAsync<ImportView>("import-newcard");
|
|
});
|
|
|
|
/// <summary>As <c>--capture</c> does: toasts of the previous state go, those of an insertion state stay.</summary>
|
|
private static async Task ShowAsync(ScreenSmokeTests.SampleApp app, string state)
|
|
{
|
|
DismissToasts(app);
|
|
await ImportScenes.ShowAsync(app.Shell, state);
|
|
if (!ImportScenes.ShowsToast(state)) DismissToasts(app);
|
|
}
|
|
|
|
private static void DismissToasts(ScreenSmokeTests.SampleApp app)
|
|
{
|
|
foreach (var host in app.FindAll<ToastHost>())
|
|
{
|
|
foreach (var toast in host.Toasts.ToList()) host.Dismiss(toast);
|
|
}
|
|
}
|
|
|
|
private static Button ButtonFor(ScreenSmokeTests.SampleApp app, ICommand command) =>
|
|
Assert.NotNull(app.FindAll<Button>().FirstOrDefault(b => ReferenceEquals(b.Command, command) && b.IsVisible), "a visible button bound to the command");
|
|
}
|