Phase 5c P4. The workspace no longer grows without bound: a daily workspace-cleanup system schedule (04:30, catch-up) removes the media of projects in step with their home that were not opened for Clean after, and the size limit removes the least recently used after each copy. Each project kept is logged with its reason (open in Edit, not in step, home offline, jobs pending, renders not sent, unreadable, just copied). - WorkspaceCleaner: cleans under the project's lease, re-checking every condition; the originals the home no longer holds go to the workspace trash, never away. The media index is marked Cleaned, so the project reads as MediaRemoved and opening it copies the media again. - WorkspaceTrash: lists entries with a fingerprint, and empties only the plan the user confirmed (refused when the trash changed since). - Trash dialog view model and view: Erase is enabled only after the user types the number of entries. - Removing a copy counts the unsent renders and the last originals. Send first queues the renders' sending and refuses the removal until they are sent. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
118 lines
6.0 KiB
C#
118 lines
6.0 KiB
C#
using System.Windows;
|
||
using System.Windows.Automation;
|
||
using System.Windows.Controls;
|
||
using System.Windows.Controls.Primitives;
|
||
using System.Windows.Media;
|
||
using Chronos.App.Jobs;
|
||
using Chronos.App.Sections;
|
||
using Chronos.App.Shell;
|
||
using Chronos.App.Tests.Windows;
|
||
using Chronos.Core.Localization;
|
||
using Chronos.Testing;
|
||
|
||
namespace Chronos.App.Tests.Jobs;
|
||
|
||
/// <summary>
|
||
/// Jobs › Scheduled on the capture sample (owner review 2, R10): the tab draws in both themes, every row and control is
|
||
/// named and has a tooltip, system rows reset and the user's delete, a schedule's run opens in the Queue tab with its
|
||
/// "Scheduled" pill, and the editor opens over the screen.
|
||
/// </summary>
|
||
[WindowsOnly]
|
||
[Serial]
|
||
[Timeout(300_000)]
|
||
public sealed class ScheduledTabTests
|
||
{
|
||
[Test]
|
||
public Task TheScheduledTabListsTheSchedulesAndLeadsToTheirJobs() => ScreenHost.RunAsync(async () =>
|
||
{
|
||
await using var app = await ScreenSmokeTests.SampleApp.StartAsync();
|
||
var shell = app.Shell;
|
||
await app.Sample.FillAsync();
|
||
await shell.Jobs.ReloadAsync();
|
||
var schedules = shell.Jobs.Schedules;
|
||
await schedules.Attached;
|
||
await schedules.ReloadAsync();
|
||
shell.Navigate(SectionKey.Jobs);
|
||
shell.Jobs.TabIndex = 1;
|
||
await app.ExpectAsync<SchedulesView>("jobs-scheduled");
|
||
|
||
Assert.SequenceEqual(["Archive scan", "Index backup", "Housekeeping", "Workspace clean-up", "Weekly integrity check", "Monthly orphans report"], schedules.Rows.Select(r => r.Name));
|
||
var items = app.FindAll<ListBoxItem>().Where(i => i.DataContext is ScheduleRowViewModel && i.IsVisible).ToList();
|
||
Assert.Count(6, items);
|
||
foreach (var item in items)
|
||
{
|
||
var row = (ScheduleRowViewModel)item.DataContext;
|
||
Assert.Equal(row.AccessibleName, AutomationProperties.GetName(item));
|
||
var controls = Descendants<ButtonBase>(item).Where(b => b.IsVisible).ToList();
|
||
// The switch, Run now, Edit, and Reset or Delete.
|
||
Assert.Count(4, controls);
|
||
Assert.True(controls.All(c => c.ToolTip is not null && AutomationProperties.GetName(c).Contains(row.Name, StringComparison.Ordinal)),
|
||
$"every control of {row.Name} has a tooltip and names its row");
|
||
var last = Descendants<Button>(item).Last(b => b.IsVisible);
|
||
Assert.Equal(Loc.L(row.IsSystem ? "Jobs.Schedule.Reset" : "Jobs.Schedule.Delete"), last.Content);
|
||
}
|
||
// The queue's toolbar gives way to New schedule.
|
||
Assert.True(app.FindAll<Button>().Any(b => b.IsVisible && Equals(b.Content, Loc.L("Jobs.Schedule.New"))), "New schedule is on the toolbar");
|
||
Assert.False(app.FindAll<TextBox>().Any(t => t.IsVisible && AutomationProperties.GetName(t) == Loc.L("Jobs.Search")), "the queue's search is hidden");
|
||
|
||
// The weekly check's run waits in the queue: Show in queue opens it there, expanded.
|
||
var weekly = schedules.Rows.Single(r => r.Name == "Weekly integrity check");
|
||
schedules.Selected = weekly;
|
||
await schedules.RunsLoading;
|
||
var run = Assert.NotNull(schedules.Runs.SingleOrDefault());
|
||
Assert.Equal(weekly.Schedule.LastJobId, run.Id);
|
||
await shell.Jobs.ShowJobAsync(run.Id);
|
||
Assert.True(shell.Jobs.IsQueue, "the Queue tab is shown");
|
||
var shown = shell.Jobs.Rows.Single(r => r.Id == run.Id);
|
||
Assert.True(shown.IsExpanded && shown.IsScheduled, "the job is expanded and marked as scheduled");
|
||
await app.ExpectAsync<JobsView>("jobs-from-schedule");
|
||
var pills = app.FindAll<Border>().Where(b => b.IsVisible && Equals(b.ToolTip, Loc.L("Tooltips.Jobs.Scheduled"))).ToList();
|
||
Assert.True(pills.Count >= 1, "a scheduled job carries the pill");
|
||
});
|
||
|
||
[Test]
|
||
public Task TheEditorOpensOverTheScreenAndCloses() => ScreenHost.RunAsync(async () =>
|
||
{
|
||
await using var app = await ScreenSmokeTests.SampleApp.StartAsync();
|
||
var shell = app.Shell;
|
||
await app.Sample.FillAsync();
|
||
var schedules = shell.Jobs.Schedules;
|
||
await schedules.Attached;
|
||
await schedules.ReloadAsync();
|
||
shell.Navigate(SectionKey.Jobs);
|
||
shell.Jobs.TabIndex = 1;
|
||
var weekly = schedules.Rows.Single(r => r.Name == "Weekly integrity check");
|
||
weekly.EditCommand.Execute(null);
|
||
var editor = Assert.NotNull(schedules.Editor);
|
||
Assert.False(shell.Jobs.IsContentEnabled);
|
||
await app.ExpectAsync<SchedulesView>("jobs-schedule-editor");
|
||
|
||
// Weekly, on Sunday at 02:00, verifying 25 % of the sequences unverified for 30 days.
|
||
Assert.Equal(2, editor.KindIndex);
|
||
Assert.SequenceEqual([DayOfWeek.Sunday], editor.Days.Where(d => d.IsChecked).Select(d => d.Value));
|
||
Assert.Equal(("02:00", "30", "25"), (editor.Time.Text, editor.OlderThan.Text, editor.Percent.Text));
|
||
var fields = app.FindAll<TextBox>().Where(t => t.IsVisible && t.DataContext is ScheduleEditorViewModel).ToList();
|
||
Assert.True(fields.Count >= 4, "name, time, age and share are on screen");
|
||
Assert.True(fields.All(t => t.ToolTip is not null && !string.IsNullOrWhiteSpace(AutomationProperties.GetName(t))), "every field is named and has a tooltip");
|
||
var toggles = app.FindAll<ToggleButton>().Where(t => t.IsVisible && t.DataContext is ScheduleChoice<DayOfWeek>).ToList();
|
||
Assert.Count(7, toggles);
|
||
// Unavailable actions are listed disabled: the scheduler answers for this PC.
|
||
Assert.True(editor.ActionOptions.Any(a => a.IsAvailable), "actions are available");
|
||
|
||
editor.CloseCommand.Execute(null);
|
||
Assert.Null(schedules.Editor);
|
||
Assert.True(shell.Jobs.IsContentEnabled);
|
||
});
|
||
|
||
private static IEnumerable<T> Descendants<T>(DependencyObject node)
|
||
where T : DependencyObject
|
||
{
|
||
for (var i = 0; i < VisualTreeHelper.GetChildrenCount(node); i++)
|
||
{
|
||
var child = VisualTreeHelper.GetChild(node, i);
|
||
if (child is T match) yield return match;
|
||
foreach (var nested in Descendants<T>(child)) yield return nested;
|
||
}
|
||
}
|
||
}
|