Files
Chronos/tests/Titano.App.Tests/Library/LibraryScreenSmokeTests.cs
T
Claude 7f94c9a839 test(app): Library logic tests, capture scenes and smoke tests
Timeline bands and month mapping, saved views (validation and a round trip
through the settings table), the mass actions bar's targets and reasons, remote
cards and their place among the pages, the CSV list and the delete dry run's
confirmation. --capture writes library-timeline, library-mass, library-delete
and library-remote in both themes (LibraryScenes), the sample data saves two
views, and a Windows smoke test renders each scene and checks the bar, the
typed confirmation and the saved views.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_012iLMBNwBE2GnphAsu4cjaC
2026-10-03 16:44:10 +00:00

107 lines
5.3 KiB
C#

using System.Windows;
using System.Windows.Controls;
using System.Windows.Input;
using System.Windows.Media;
using Titano.App.Archiving;
using Titano.App.Library;
using Titano.App.Sections;
using Titano.App.Shell;
using Titano.App.Tests.Windows;
using Titano.Testing;
using Titano.Ui.Visuals;
namespace Titano.App.Tests.Library;
/// <summary>
/// The Library's new states of <c>--capture</c> (<see cref="LibraryScenes"/>) on the sample index while signed in to the
/// sample server, rendered in both themes in the real main window: the timeline, a selection with the whole mass actions
/// bar and its delete dry run, the server's sequences as remote cards, and saved views.
/// </summary>
[WindowsOnly]
[Serial]
[Timeout(300_000)]
public sealed class LibraryScreenSmokeTests
{
[Test]
public Task EveryLibrarySceneRendersInBothThemes() => ScreenHost.RunAsync(async () =>
{
await using var app = await ScreenSmokeTests.SampleApp.StartAsync();
await app.Sample.FillAsync();
await app.Shell.Services.Server.RestoreAsync();
await app.Shell.Services.Sync.RefreshAsync();
var library = app.Shell.Library;
await LibraryScenes.ShowAsync(app.Shell, "timeline");
Assert.True(library.IsTimeline, "the timeline shows its bands");
Assert.True(library.IsGrid, "the cards stay under the bands");
Assert.Equal(2, library.TimelineBands.Count, "one band per year, 2026 and 2025");
Assert.True(library.TimelineBand >= 0 && library.TimelineSlot >= 0, "the chosen month is outlined");
Assert.True(library.IsYearFiltered, "a month narrows the Library to its year");
await app.ExpectAsync<LibraryView>("library-timeline", waitForThumbnails: true);
Assert.True(app.FindAll<TimelineBands>().Any(t => t.IsVisible && t.ActualHeight > 0), "the bands are drawn");
await LibraryScenes.ShowAsync(app.Shell, "mass");
Assert.Equal(LibraryScenes.MassSelection, library.SelectionCount);
await app.ExpectAsync<LibraryView>("library-mass", waitForThumbnails: true);
foreach (var command in new[] { library.AnalyseCommand, library.ProxiesCommand, library.VerifyCommand, library.TagCommand, library.MoveCommand,
library.ExportListCommand, library.DeleteCommand })
Assert.True(ButtonFor(app, command).IsEnabled, "the bar's archive actions work on sequences of this PC");
Assert.True(library.CanRate);
var request = Assert.NotNull(await LibraryScenes.DeleteRequestAsync(app.Shell), "the dry run moves something");
Assert.True(request.IsDestructive);
Assert.NotNull(request.TypedConfirmation);
var dialog = new ConfirmDialog(request) { WindowStartupLocation = WindowStartupLocation.Manual, Left = -20000, Top = -20000, ShowActivated = false };
dialog.Show();
try
{
dialog.UpdateLayout();
var action = Find<Button>(dialog).Single(b => Equals(b.Content, request.ActionText));
Assert.False(action.IsEnabled, "Delete waits for the typed confirmation");
Find<TextBox>(dialog).Single(t => t.IsVisible).Text = request.TypedConfirmation;
Assert.True(action.IsEnabled, "typing the count enables Delete");
}
finally
{
dialog.Close();
}
// The sample dialogs cancel every confirmation: nothing moves.
var selected = library.SelectedItems().Select(i => i.Id).ToList();
Assert.False(await SequenceDeletion.RunAsync(app.Shell, selected));
foreach (var id in selected) Assert.NotNull(await app.Services.Database!.Sequences.GetAsync(id));
await LibraryScenes.ShowAsync(app.Shell, "remote");
Assert.True(library.ShowsOrigin, "signed in, the origin filter shows");
Assert.Equal(2, library.Items.Count, "the two sequences only on the sample server");
Assert.True(library.Items.All(i => i.IsRemote));
Assert.True(library.IsSingleSelection);
Assert.False(library.DeleteCommand.CanExecute(null), "a remote card has nothing here to delete");
Assert.True(library.DownloadCommand.CanExecute(null), "its originals can come here");
await app.ExpectAsync<LibraryView>("library-remote");
library.ClearFiltersCommand.Execute(null);
await library.RefreshAsync();
Assert.True(library.HasViews, "the sample saved two views");
library.ViewChoices.Single(v => v.Label == "Nikon Z 8").Command.Execute(null);
await library.RefreshAsync();
Assert.True(library.IsViewActive);
Assert.True(library.Items.Count > 0 && library.Items.All(i => i.Sequence.CameraModel == "NIKON Z 8"));
});
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");
private static List<T> Find<T>(DependencyObject root)
where T : DependencyObject
{
var found = new List<T>();
for (var i = 0; i < VisualTreeHelper.GetChildrenCount(root); i++)
{
var child = VisualTreeHelper.GetChild(root, i);
if (child is T match) found.Add(match);
found.AddRange(Find<T>(child));
}
return found;
}
}