Files
Chronos/tests/Chronos.App.Tests/Jobs/ScheduledTabTests.cs
T
Alby96 bc786c12c4 feat(app): Jobs › Scheduled and the desktop scheduler
Owner review 2, R10 on the desktop: every timer that queued work out of
sight is now a visible, editable schedule of this PC.

- DesktopScheduleHost implements IScheduleHost: the PC's time zone, the
  archive at Settings › Archive's folder (refreshed from archive.json,
  none while it is offline), and three system schedules: archive-scan
  (every:<ScanIntervalMinutes>m, seeded once from the old setting, no
  catch-up), index-backup (every day with catch-up, replacing
  DatabaseBackups.RunDailyAsync) and housekeeping (daily 04:00 with
  catch-up: job history 90 days and the new cache-trim step).
- AppServices starts the Scheduler after the engine, once the archive was
  reopened; an unplugged archive is looked for every minute and the
  scheduler woken when it is back. The rescan loop and the daily backup
  loop are gone; ApplyJobSettings wakes the scheduler.
- CacheStore.Trim brings the cache to Settings › Storage › Cache limit,
  oldest files first, skipping files in use and the proxies, render-node
  and server-import folders; CacheTrimStep runs it as a clean-up step.
- Jobs gets a Queue | Scheduled segmented control. Scheduled lists the
  schedules (switch, name, action, when, next run, last result) with Run
  now, Edit, Reset (system) or Delete (user's, confirmed), the selected
  schedule's last runs with Show in queue, and an in-window editor that
  checks every field with the scheduler's limits. Jobs a schedule queued
  carry a "Scheduled" pill; the history line follows the housekeeping's
  job-history days.
- JobNotices: a scheduled background run raises a toast only when it
  fails (upkeep stays silent).
- Settings › Archive › Rescan every is removed; ScanIntervalMinutes stays
  only as the seed. Strings in en and it; the others are retranslated.
- The capture shows jobs-scheduled and jobs-schedule-editor on a stopped
  scheduler clock with sample schedules.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
(cherry picked from commit e25d812feb3f417cb9251c748c29e8035fd9b03c)
2026-10-27 02:26:07 +01:00

118 lines
6.0 KiB
C#
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
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", "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(5, 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;
}
}
}