Files
Chronos/tests/Chronos.App.Tests/Jobs/ScheduledTabTests.cs
T
Alby96andClaude Opus 5.5 db389a54f2
CI / Build and test (push) Successful in 9m26s
CI / Windows tests and installer (push) Skipped
CI / YAML check (push) Successful in 8s
Release / Build, test and publish (push) Successful in 14m31s
CI / PostgreSQL 16 integration (push) Successful in 9m53s
CI / PostgreSQL 17 integration (push) Successful in 9m22s
CI / Docker image (push) Successful in 44s
Release / Server image (push) Successful in 1m36s
feat: owner review 2 phase 5c: originals, local render, clean-up and the workspace settings (#18)
Originals in the workspace, local render and send home with provenance, the workspace clean-up, size limit and trash, moving the workspace folder, and the complete Settings › Workspace page (owner review 2, R8, phase 5c). One adversarial review round (35 findings, 32 fixed), a copy-cancel race fixed, 184 strings in all 38 languages.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-authored-by: Alberto Balbo <alberto.balbo.96@gmail.com>
2026-11-04 20:03:52 +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", "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;
}
}
}