refactor!: rename Titano to Chronos and move CI and releases to Gitea
CI / Build and test (pull_request) Failing after 2m3s
CI / PostgreSQL 16 integration (pull_request) Skipped
CI / PostgreSQL 17 integration (pull_request) Skipped
CI / Docker image (pull_request) Skipped
CI / Windows tests and installer (pull_request) Skipped
CI / YAML check (pull_request) Successful in 4s

The owner renamed the product and moved the repository to the self-hosted
Gitea (https://gitea.encke-hake.ts.net/BalboSoft/Chronos) for more control,
and asked for Actions and a first automatic release with the server package
and the Windows exe (docs/requests/2026-10-23-chronos-gitea.md).

- Chronos everywhere: a byte-exact rename of contents and paths, then a
  per-language review of the forms the old name's ending had dictated.
- Gitea instead of GitHub: the update check, licence, issue and support
  links read ChronosReleasesUrl; the update check takes the highest stable
  version, offers a pre-release build its final release and reports a
  repository it cannot see as a failed check. EULA, security policy and
  Gitea issue forms live at the repository root.
- Gitea Actions for the Linux act_runner (.gitea/workflows): CI, release,
  nightly image and performance gates in the .NET SDK container with git
  checkout. The release cross-compiles the Windows programs, checks their
  icon, version and DPI manifest, packs installers and zips, publishes the
  Gitea release and pushes the server image (REGISTRY_TOKEN). Windows-only
  tests run in an opt-in job on a Windows runner (WINDOWS_RUNNER).
- New Chronos.Tools commands: zip, gitea-release, postgres-ci (replaces the
  docker-exec script, which Gitea's service containers do not allow) and
  pe-check.

BREAKING CHANGE: programs, settings, data folders, file types, environment
variables and the Docker image use the new name; nothing is migrated from
Titano, which never had a release.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
Alby96andClaude Opus 5.5 committed 2026-10-23 11:34:48 +02:00
1 parent c99842cc86
commit 5f27a86406
1799 files changed
+11728 -10668

No files matched your search

@@ -0,0 +1,233 @@
using System.Globalization;
using Chronos.App.Infrastructure;
using Chronos.App.Jobs;
using Chronos.Core.Localization;
using Chronos.Core.Model;
using Chronos.Data.Jobs;
using Chronos.Testing;
namespace Chronos.App.Tests.Jobs;
public sealed class JobListModelTests
{
private static readonly DateTimeOffset T0 = new(2026, 9, 28, 10, 0, 0, TimeSpan.Zero);
[Test]
public void OrderIsRunningPausedQueueThenNewestHistory()
{
var model = new JobListModel();
var oldDone = Job(JobState.Done, created: -60, started: -60, finished: -50);
var newDone = Job(JobState.Done, created: -40, started: -40, finished: -10);
var failed = Job(JobState.Failed, created: -30, started: -30, finished: -20);
var queuedLow = Job(JobState.Queued, created: -50, priority: JobPriority.Background);
var queuedOld = Job(JobState.Queued, created: -45);
var queuedNew = Job(JobState.Queued, created: -5);
var queuedUrgent = Job(JobState.Queued, created: -1, priority: JobPriority.User);
var paused = Job(JobState.Paused, created: -35, started: -35);
var runningLate = Job(JobState.Running, created: -8, started: -3);
var runningEarly = Job(JobState.Running, created: -9, started: -7);
foreach (var j in new[] { oldDone, newDone, failed, queuedLow, queuedOld, queuedNew, queuedUrgent, paused, runningLate, runningEarly }) model.Apply(j);
var order = model.Ordered().Select(e => e.Id).ToList();
Assert.SequenceEqual(
new[] { runningEarly, runningLate, paused, queuedUrgent, queuedOld, queuedNew, queuedLow, newDone, failed, oldDone }.Select(j => j.Id),
order);
Assert.Equal(1, model.QueuePosition(queuedUrgent.Id));
Assert.Equal(2, model.QueuePosition(queuedOld.Id));
Assert.Equal(4, model.QueuePosition(queuedLow.Id));
Assert.Equal(0, model.QueuePosition(runningEarly.Id));
Assert.Equal(2, model.RunningCount);
Assert.Equal(4, model.QueuedCount);
}
[Test]
public void FiltersCountAndHideClearedHistory()
{
var model = new JobListModel();
model.Apply(Job(JobState.Running, started: -1));
model.Apply(Job(JobState.Paused, started: -2));
model.Apply(Job(JobState.Queued));
model.Apply(Job(JobState.Done, started: -30, finished: -20));
model.Apply(Job(JobState.Done, started: -5, finished: -2));
model.Apply(Job(JobState.Failed, started: -6, finished: -4));
model.Apply(Job(JobState.Cancelled, started: -7, finished: -6));
Assert.Equal(7, model.CountOf(JobFilter.All));
Assert.Equal(2, model.CountOf(JobFilter.Running));
Assert.Equal(1, model.CountOf(JobFilter.Queued));
Assert.Equal(2, model.CountOf(JobFilter.Done));
Assert.Equal(2, model.CountOf(JobFilter.Failed));
var cleared = T0.AddMinutes(-10);
Assert.Equal(1, model.CountOf(JobFilter.Done, cleared));
Assert.Equal(6, model.Ordered(JobFilter.All, null, cleared).Count);
Assert.Equal(3, model.Ordered(JobFilter.All, null, T0).Count); // only the active jobs remain
}
[Test]
public void SearchMatchesTargetAndKind()
{
Loc.SetCulture(CultureInfo.GetCultureInfo("en"));
var model = new JobListModel();
model.Apply(Job(JobState.Queued, kind: JobKind.Render, label: "Harbour sunset → 4K"));
model.Apply(Job(JobState.Queued, kind: JobKind.Verify, label: "Archive · 2024"));
Assert.Equal(1, model.Ordered(JobFilter.All, "harbour").Count);
Assert.Equal(1, model.Ordered(JobFilter.All, "verify").Count);
Assert.Equal(2, model.Ordered(JobFilter.All, " ").Count);
Assert.Empty(model.Ordered(JobFilter.All, "comet"));
}
[Test]
public void ProgressMergesIntoRunningJobsOnly()
{
var model = new JobListModel();
var running = Job(JobState.Running, started: -1, done: 10, total: 100);
var queued = Job(JobState.Queued);
model.Apply(running);
model.Apply(queued);
Assert.True(model.Apply(Progress(running.Id, 62, 100, 11.3, TimeSpan.FromMinutes(2))));
Assert.False(model.Apply(Progress(queued.Id, 5, 100)));
Assert.False(model.Apply(Progress(Guid.CreateVersion7(), 5, 100)));
var entry = model[running.Id]!;
Assert.Equal(62, entry.Done);
Assert.Approximately(0.62, entry.Fraction!.Value, 1e-9);
Assert.Equal(11.3, entry.ItemsPerSecond);
Assert.Same(entry, model.Current);
Assert.Equal(0, model[queued.Id]!.Done);
// Finishing drops the live progress and falls back to the stored snapshot.
model.Apply(running with { State = JobState.Done, ProgressDone = 100, Finished = T0 });
Assert.Null(model[running.Id]!.Live);
Assert.Equal(100, model[running.Id]!.Done);
Assert.Null(model.Current);
}
[Test]
public void ALoadedPageNeverOverwritesANewerEvent()
{
var model = new JobListModel();
var queued = Job(JobState.Queued);
var readAt = model.Stamp; // page requested
model.Apply(queued with { State = JobState.Running, Started = T0 }); // event arrives first
Assert.False(model.ApplyLoaded(queued, readAt)); // the stale page row is ignored
Assert.Equal(JobState.Running, model[queued.Id]!.State);
var other = Job(JobState.Done, started: -3, finished: -1);
Assert.True(model.ApplyLoaded(other, model.Stamp));
Assert.True(model.Apply(other with { State = JobState.Queued, Finished = null }));
Assert.Equal(JobState.Queued, model[other.Id]!.State);
}
[Test]
public void CurrentPrefersTheJobWithLiveProgress()
{
var model = new JobListModel();
var a = Job(JobState.Running, started: -10);
var b = Job(JobState.Running, started: -1);
model.Apply(a);
model.Apply(b);
Assert.Equal(a.Id, model.Current!.Id);
model.Apply(Progress(b.Id, 1, 2));
Assert.Equal(b.Id, model.Current!.Id);
}
[Test]
public void ClaimOrderMatchesTheRepository()
{
var older = Job(JobState.Queued, created: -10);
var newer = Job(JobState.Queued, created: -5);
var urgent = Job(JobState.Queued, created: -1, priority: JobPriority.User);
Assert.True(JobListModel.ClaimsBefore(older, newer));
Assert.True(JobListModel.ClaimsBefore(urgent, older));
Assert.False(JobListModel.ClaimsBefore(newer, older));
}
[Test]
public void ThePriorityQueueOrdersTheQueueAsTheEngineClaimsIt()
{
var model = new JobListModel();
var verify = Job(JobState.Queued, created: -30, priority: JobPriority.User, kind: JobKind.Verify);
var scan = Job(JobState.Queued, created: -20, kind: JobKind.Scan);
var render = Job(JobState.Queued, created: -1, kind: JobKind.Render);
foreach (var j in new[] { verify, scan, render }) model.Apply(j);
Assert.SequenceEqual(new[] { verify.Id, scan.Id, render.Id }, model.Ordered().Select(e => e.Id));
// Owner review 1: on, renders come first and verifies last, whatever their age and priority.
model.PriorityQueue = new JobPriorityQueue { Enabled = true };
Assert.SequenceEqual(new[] { render.Id, scan.Id, verify.Id }, model.Ordered().Select(e => e.Id));
Assert.Equal((1, 2, 3), (model.QueuePosition(render.Id), model.QueuePosition(scan.Id), model.QueuePosition(verify.Id)));
}
[Test]
public void TextsDescribeTheJob()
{
Loc.SetCulture(CultureInfo.GetCultureInfo("en"));
var running = new JobEntry(Job(JobState.Running, kind: JobKind.Render, label: "Harbour sunset", started: -3))
{
Live = Progress(Guid.Empty, 2232, 3600, 11.3, TimeSpan.FromMinutes(2)),
};
Assert.Equal("Render · Harbour sunset · 2,232 / 3,600 · 11.3 fps · 2 min left", JobText.Bar(running));
Assert.Equal("2 min", JobText.Left(running, 0));
// Imports and verifies count bytes; scans count folders; frame jobs read in fps (owner review 1).
Assert.Equal("118 B/s", JobText.Speed(JobKind.Import, 118));
Assert.Equal(JobText.Speed(JobKind.Verify, 57_000_000), Loc.L("Jobs.Speed.Bytes", Formatting.Bytes(57_000_000)));
Assert.Equal("4/s", JobText.Speed(JobKind.Scan, 4));
Assert.Equal("1.7 fps", JobText.Speed(JobKind.Proxies, 1.7));
Assert.Equal(string.Empty, JobText.Speed(JobKind.Render, null));
Assert.Equal("this PC", JobText.Where("STUDIO#2", "studio"));
Assert.Equal("render-box", JobText.Where("render-box", "studio"));
var queued = new JobEntry(Job(JobState.Queued));
Assert.Equal("next", JobText.Left(queued, 1));
Assert.Equal("after 2", JobText.Left(queued, 3));
var done = new JobEntry(Job(JobState.Done, started: -10, finished: -7));
Assert.Equal("done · 3:00", JobText.State(done));
}
[Test]
public void TheWorkersReadoutCountsOnlyJobsOfThisPc()
{
var model = new JobListModel();
model.Apply(Job(JobState.Running, started: -1) with { NodeId = "STUDIO#0" });
model.Apply(Job(JobState.Running, started: -2) with { NodeId = "studio#3" });
model.Apply(Job(JobState.Running, started: -3) with { NodeId = "render-box#0" });
model.Apply(Job(JobState.Running, started: -4));
model.Apply(Job(JobState.Done, started: -9, finished: -8) with { NodeId = "studio#1" });
Assert.Equal(4, model.RunningCount);
Assert.Equal(2, model.RunningOn("studio"));
Assert.True(JobText.IsLocal("studio#2", "STUDIO"));
Assert.False(JobText.IsLocal("studio-2", "studio"));
Assert.False(JobText.IsLocal(null, "studio"));
}
[Test]
public void RowsAreNamedByKindAndTarget()
{
Loc.SetCulture(CultureInfo.GetCultureInfo("en"));
Assert.Equal("Render · Harbour sunset", JobText.Name(Job(JobState.Running, kind: JobKind.Render, label: "Harbour sunset")));
Assert.Equal("Proxies", JobText.Name(Job(JobState.Queued)));
}
private static Job Job(JobState state, int created = 0, int? started = null, int? finished = null, JobPriority priority = JobPriority.Normal,
JobKind kind = JobKind.Proxies, string? label = null, long done = 0, long total = 0) => new()
{
Id = Guid.CreateVersion7(),
Kind = kind,
State = state,
Priority = priority,
TargetLabel = label,
ProgressDone = done,
ProgressTotal = total,
Created = T0.AddMinutes(created),
Started = started is { } s ? T0.AddMinutes(s) : null,
Finished = finished is { } f ? T0.AddMinutes(f) : null,
};
private static JobProgressInfo Progress(Guid id, long done, long total, double? rate = null, TimeSpan? eta = null) =>
new(id, JobKind.Render, null, done, total, rate, eta, null);
}
@@ -0,0 +1,152 @@
using Chronos.App.Jobs;
using Chronos.Core.Model;
using Chronos.Testing;
namespace Chronos.App.Tests.Jobs;
/// <summary>UI-08: which job endings raise the shell's toast, whichever screen started the job, and how a batch speaks once.</summary>
public sealed class JobNoticesTests
{
[Theory]
[Case(JobKind.Render)]
[Case(JobKind.DeepAnalyse)]
[Case(JobKind.Verify)]
[Case(JobKind.Rebuild)]
[Case(JobKind.Maintenance)]
[Case(JobKind.UploadCommit)]
[Case(JobKind.Move)]
[Case(JobKind.Adopt)]
public void ALongOperationThatEndsSaysSo(JobKind kind)
{
Assert.Equal(JobNotice.Done, JobNotices.For(JobState.Running, Job(kind, JobState.Done)));
Assert.Equal(JobNotice.Failed, JobNotices.For(JobState.Running, Job(kind, JobState.Failed)));
// Queued and finished between two flushes of the Jobs screen: still one notice.
Assert.Equal(JobNotice.Done, JobNotices.For(JobState.Queued, Job(kind, JobState.Done)));
Assert.Equal(JobNotice.Done, JobNotices.For(null, Job(kind, JobState.Done)));
}
[Theory]
[Case(JobKind.Scan)]
[Case(JobKind.LightAnalyse)]
[Case(JobKind.Thumbs)]
[Case(JobKind.Proxies)]
public void UpkeepAndScansEndSilently(JobKind kind)
{
Assert.Equal(JobNotice.None, JobNotices.For(JobState.Running, Job(kind, JobState.Done)));
Assert.Equal(JobNotice.None, JobNotices.For(JobState.Running, Job(kind, JobState.Failed)));
}
[Theory]
[Case(JobKind.Import)]
[Case(JobKind.Download)]
[Case(JobKind.Duplicates)]
[Case(JobKind.Orphans)]
public void EveryOtherFailureIsSaid(JobKind kind)
{
// An import announces its result on the Import screen, a download on its Library card and Server row.
Assert.Equal(JobNotice.None, JobNotices.For(JobState.Running, Job(kind, JobState.Done)));
Assert.Equal(JobNotice.Failed, JobNotices.For(JobState.Running, Job(kind, JobState.Failed)));
}
[Test]
public void BackgroundPriorityCancelledAndRepeatedEndingsSayNothing()
{
// The deep analysis queued after an import, and the proxies sync fetches, run in the background.
Assert.Equal(JobNotice.None, JobNotices.For(JobState.Running, Job(JobKind.DeepAnalyse, JobState.Done, JobPriority.Background)));
Assert.Equal(JobNotice.None, JobNotices.For(JobState.Running, Job(JobKind.Download, JobState.Failed, JobPriority.Background)));
Assert.Equal(JobNotice.None, JobNotices.For(JobState.Running, Job(JobKind.Render, JobState.Cancelled)));
Assert.Equal(JobNotice.None, JobNotices.For(JobState.Done, Job(JobKind.Render, JobState.Done)));
Assert.Equal(JobNotice.None, JobNotices.For(JobState.Failed, Job(JobKind.Render, JobState.Failed)));
Assert.Equal(JobNotice.None, JobNotices.For(JobState.Queued, Job(JobKind.Render, JobState.Running)));
// "Add to queue" renders have Normal priority: they are announced too.
Assert.Equal(JobNotice.Done, JobNotices.For(JobState.Running, Job(JobKind.Render, JobState.Done, JobPriority.Normal)));
}
[Test]
public void ABatchOfOneKindSpeaksOnceWhenItsLastJobEnds()
{
// Server › Upload all: 100 uploads queued; each one that ends waits for the rest.
var endings = new JobEndings();
var model = new JobListModel();
var uploads = Enumerable.Range(0, 100).Select(_ => Job(JobKind.UploadCommit, JobState.Queued)).ToList();
foreach (var upload in uploads) model.Apply(upload);
for (var i = 0; i < 99; i++)
{
var done = uploads[i] with { State = JobState.Done };
model.Apply(done);
endings.Add(JobNotices.For(JobState.Running, done), done);
Assert.Empty(endings.Take(model.IsBusy));
}
Assert.Equal(99, endings.Waiting);
// A render of the same flush is its own kind: it is said at once.
var render = Job(JobKind.Render, JobState.Done);
model.Apply(render);
endings.Add(JobNotice.Done, render);
var due = endings.Take(model.IsBusy);
Assert.Count(1, due);
Assert.Equal(JobNotice.Done, due[0].Notice);
Assert.SequenceEqual([render.Id], due[0].Jobs.Select(j => j.Id));
var last = uploads[99] with { State = JobState.Done };
model.Apply(last);
endings.Add(JobNotice.Done, last);
due = endings.Take(model.IsBusy);
Assert.Count(1, due);
Assert.SequenceEqual(uploads.Select(u => u.Id), due[0].Jobs.Select(j => j.Id));
Assert.Equal(0, endings.Waiting);
Assert.Empty(endings.Take(model.IsBusy));
}
[Test]
public void PausedAndBackgroundJobsDoNotHoldABatch()
{
var endings = new JobEndings();
var model = new JobListModel();
// An upload paused on a metered network, and the proxies sync fetches in the background, wait for something else.
model.Apply(Job(JobKind.UploadCommit, JobState.Paused));
model.Apply(Job(JobKind.Download, JobState.Running, JobPriority.Background));
var upload = Job(JobKind.UploadCommit, JobState.Done);
model.Apply(upload);
endings.Add(JobNotice.Done, upload);
Assert.Count(1, endings.Take(model.IsBusy));
Assert.False(model.IsBusy(JobKind.UploadCommit));
Assert.False(model.IsBusy(JobKind.Download));
}
[Test]
public void FailuresAreSaidAtTheEndOfTheirFlushTogether()
{
var endings = new JobEndings();
var model = new JobListModel();
// More uploads still run: failures do not wait for them.
model.Apply(Job(JobKind.UploadCommit, JobState.Running));
var first = Job(JobKind.UploadCommit, JobState.Failed);
var second = Job(JobKind.Verify, JobState.Failed);
endings.Add(JobNotice.Failed, first);
endings.Add(JobNotice.Failed, second);
endings.Add(JobNotice.None, Job(JobKind.Scan, JobState.Done));
var due = endings.Take(model.IsBusy);
Assert.Count(1, due);
Assert.Equal(JobNotice.Failed, due[0].Notice);
Assert.SequenceEqual([first.Id, second.Id], due[0].Jobs.Select(j => j.Id));
// The next flush starts again.
var third = Job(JobKind.UploadCommit, JobState.Failed);
endings.Add(JobNotice.Failed, third);
due = endings.Take(model.IsBusy);
Assert.Count(1, due);
Assert.SequenceEqual([third.Id], due[0].Jobs.Select(j => j.Id));
Assert.Empty(endings.Take(model.IsBusy));
}
private static Job Job(JobKind kind, JobState state, JobPriority priority = JobPriority.User) => new()
{
Id = Guid.CreateVersion7(),
Kind = kind,
State = state,
Priority = priority,
TargetLabel = "Harbour sunset",
Created = DateTimeOffset.UtcNow,
};
}
@@ -0,0 +1,106 @@
using System.Collections.Concurrent;
using Chronos.App.Jobs;
using Chronos.Core.Model;
using Chronos.Data.Jobs;
using Chronos.Testing;
namespace Chronos.App.Tests.Jobs;
public sealed class JobUpdateBufferTests
{
[Test]
public void ThousandsOfEventsCoalesceToTheLatestPerJob()
{
var buffer = new JobUpdateBuffer();
var ids = Enumerable.Range(0, 3).Select(_ => Guid.CreateVersion7()).ToArray();
Parallel.For(0, 3000, i =>
{
var id = ids[i % 3];
buffer.Post(new JobProgressInfo(id, JobKind.Render, null, i, 3000, null, null, null));
});
Assert.Equal(3000, buffer.Posted);
var (jobs, progress) = buffer.Drain();
Assert.Empty(jobs);
Assert.Equal(3, progress.Count);
Assert.True(buffer.IsEmpty);
Assert.Empty(buffer.Drain().Progress);
}
[Test]
public void AStateChangeSupersedesEarlierProgress()
{
var buffer = new JobUpdateBuffer();
var job = new Job { Id = Guid.CreateVersion7(), Kind = JobKind.Verify, State = JobState.Running };
Assert.True(buffer.Post(new JobProgressInfo(job.Id, job.Kind, null, 5, 10, null, null, null)));
Assert.False(buffer.Post(job with { State = JobState.Done }));
var (jobs, progress) = buffer.Drain();
Assert.Equal(JobState.Done, jobs.Single().State);
Assert.Empty(progress);
// Progress after the snapshot is kept: it is newer.
buffer.Post(job);
buffer.Post(new JobProgressInfo(job.Id, job.Kind, null, 7, 10, null, null, null));
(jobs, progress) = buffer.Drain();
Assert.Equal(1, jobs.Count);
Assert.Equal(7, progress.Single().Done);
}
[Test]
public async Task TheThrottleFlushesAtMostOncePerInterval()
{
var flushes = new ConcurrentQueue<long>();
var clock = System.Diagnostics.Stopwatch.StartNew();
using var throttle = new CoalescingThrottle(TimeSpan.FromMilliseconds(100), null, () => flushes.Enqueue(clock.ElapsedMilliseconds));
// A burst of signals from several threads for about 550 ms.
var stop = DateTime.UtcNow.AddMilliseconds(550);
await Task.WhenAll(Enumerable.Range(0, 4).Select(_ => Task.Run(async () =>
{
while (DateTime.UtcNow < stop)
{
throttle.Signal();
await Task.Delay(1);
}
})));
await Task.Delay(250);
var times = flushes.ToArray();
Assert.InRange(times.Length, 3, 8);
for (var i = 1; i < times.Length; i++) Assert.GreaterOrEqual(times[i] - times[i - 1], 80, $"flush {i} came too early");
Assert.Equal(times.Length, throttle.Flushes);
}
[Test]
public async Task TheFirstSignalFlushesWithoutWaiting()
{
var flushed = new TaskCompletionSource();
using var throttle = new CoalescingThrottle(TimeSpan.FromSeconds(30), null, () => flushed.TrySetResult());
throttle.Signal();
await flushed.Task.WaitAsync(TimeSpan.FromSeconds(5));
Assert.Equal(1, throttle.Flushes);
}
[Test]
public async Task FlushesRunOnTheGivenContext()
{
var context = new RecordingContext();
var flushed = new TaskCompletionSource();
using var throttle = new CoalescingThrottle(TimeSpan.FromMilliseconds(10), context, () => flushed.TrySetResult());
throttle.Signal();
await flushed.Task.WaitAsync(TimeSpan.FromSeconds(5));
Assert.Equal(1, context.Posts);
}
private sealed class RecordingContext : SynchronizationContext
{
private int _posts;
public int Posts => Volatile.Read(ref _posts);
public override void Post(SendOrPostCallback d, object? state)
{
Interlocked.Increment(ref _posts);
ThreadPool.QueueUserWorkItem(_ => d(state));
}
}
}
@@ -0,0 +1,155 @@
using System.Windows;
using System.Windows.Automation;
using System.Windows.Controls;
using System.Windows.Input;
using System.Windows.Media;
using Chronos.App.Infrastructure;
using Chronos.App.Jobs;
using Chronos.App.Sections;
using Chronos.App.Shell;
using Chronos.App.Tests.Windows;
using Chronos.Core.Localization;
using Chronos.Testing;
using Chronos.Ui.Controls;
namespace Chronos.App.Tests.Jobs;
/// <summary>The Jobs screen on the capture sample: keyboard reach, names for screen readers, counts and the table's columns.</summary>
[WindowsOnly]
[Serial]
[Timeout(300_000)]
public sealed class JobsScreenSmokeTests
{
[Test]
public Task RowsAreReachableNamedAndLinedUpWithTheHeader() => ScreenHost.RunAsync(async () =>
{
await using var app = await ScreenSmokeTests.SampleApp.StartAsync();
var shell = app.Shell;
await app.Sample.FillAsync();
await shell.Jobs.ReloadAsync();
shell.Navigate(SectionKey.Jobs);
await app.ExpectAsync<JobsView>("jobs");
var jobs = shell.Jobs;
// The rail badge, the status strip and the Running chip count the same jobs.
var running = jobs.Chips.Single(c => c.Filter == JobFilter.Running).Count;
Assert.Greater(running, 0);
Assert.Equal(running, jobs.Badge);
Assert.Equal(Loc.Plural("Shell.Status.Jobs", running), shell.JobsText);
// The capture engine runs no jobs: there is no "8 photos at once" to show.
Assert.False(jobs.HasEngine);
// Tab reaches every row button: the rows take no focus, the list passes Tab on to their content.
var list = app.FindAll<ListBox>().Single(l => l.Name == "JobList");
Assert.Equal(KeyboardNavigationMode.Continue, KeyboardNavigation.GetTabNavigation(list));
var items = app.FindAll<ListBoxItem>().Where(i => i.DataContext is JobRowViewModel && i.IsVisible).ToList();
Assert.True(items.Count > 3, "several rows are on screen");
foreach (var item in items)
{
var row = (JobRowViewModel)item.DataContext;
// A row reads as its job and state; its buttons and its log toggle name the job.
Assert.Equal(row.AccessibleName, AutomationProperties.GetName(item));
Assert.Equal(row.StateText, AutomationProperties.GetItemStatus(item));
var buttons = Descendants<Button>(item).Where(b => b.IsVisible).ToList();
Assert.True(buttons.All(b => b.Focusable && b.IsTabStop), "every row button is a tab stop");
Assert.True(buttons.All(b => AutomationProperties.GetName(b).Contains(row.AccessibleName, StringComparison.Ordinal)), $"buttons of {row.AccessibleName} name it");
var state = Descendants<StatusGlyph>(item).Single();
Assert.Equal(AutomationLiveSetting.Polite, AutomationProperties.GetLiveSetting(state));
// Right to left: numbers stay right-aligned in both reading directions.
var percent = Descendants<TextBlock>(item).First(t => t.Text == row.PercentText);
Assert.True(percent.FlowDirection == FlowDirection.LeftToRight && percent.TextAlignment == TextAlignment.Right, "the percentage stays right-aligned");
}
// Header and rows share their columns: same padding, one actions column for all, the scroll-bar gutter kept.
var rows = items.Select(i => (Row: (JobRowViewModel)i.DataContext, Item: i)).ToList();
var kindHeader = Text(app, Loc.L("Jobs.Column.Kind"));
var stateHeader = Text(app, Loc.L("Jobs.Column.State"));
foreach (var (row, item) in rows)
{
Assert.Approximately(Left(kindHeader), Left(Descendants<TextBlock>(item).First(t => t.Text == row.Kind)), 1.5, $"Kind of {row.AccessibleName}");
Assert.Approximately(Left(stateHeader), Left(Descendants<StatusGlyph>(item).Single()), 1.5, $"State of {row.AccessibleName}");
}
var actionColumns = rows.Select(r => Left(Descendants<ItemsControl>(r.Item).Last())).ToList();
Assert.True(actionColumns.Max() - actionColumns.Min() < 1, "the actions column starts at the same x in every row");
// A language switch reaches the job bar at once, not at the job's next progress report.
var bar = shell.JobText;
Assert.True(shell.IsJobActive, "the sample runs a job");
UiLanguage.Apply("it");
try
{
Assert.NotEqual(bar, shell.JobText, "the job bar follows the language");
}
finally
{
UiLanguage.Apply("en");
}
Assert.Equal(bar, shell.JobText);
});
/// <summary>
/// Beside the 200 px rail (owner review 1, R1), at the 1200 px minimum width, every row's buttons stay inside the row
/// in every shipped language. A row's content is clipped where the row's padding begins, so that is the edge checked.
/// </summary>
[Test]
public Task RowActionsStayInsideTheirRowAtTheMinimumWidthInEveryLanguage() => ScreenHost.RunAsync(async () =>
{
await using var app = await ScreenSmokeTests.SampleApp.StartAsync();
var shell = app.Shell;
await app.Sample.FillAsync();
await shell.Jobs.ReloadAsync();
shell.Navigate(SectionKey.Jobs);
await app.ExpectAsync<JobsView>("jobs");
app.Window.Width = 1200;
try
{
foreach (var language in Languages.Shipped)
{
UiLanguage.Apply(language);
app.Window.UpdateLayout();
await app.Window.Dispatcher.InvokeAsync(() => { }, System.Windows.Threading.DispatcherPriority.ApplicationIdle);
var items = app.FindAll<ListBoxItem>().Where(i => i.DataContext is JobRowViewModel && i.IsVisible).ToList();
Assert.True(items.Count > 3, $"{language}: several rows are on screen");
foreach (var item in items)
{
var row = Descendants<Border>(item).First(b => b.Name == "Row");
var (left, right) = Span(row, app.Window);
foreach (var button in Descendants<Button>(row).Where(b => b.IsVisible))
{
var (start, end) = Span(button, app.Window);
Assert.True(start >= left + row.Padding.Left - 0.5 && end <= right - row.Padding.Right + 0.5,
$"{language}: '{AutomationProperties.GetName(button)}' spans {start:0}–{end:0} px, its row's content {left + row.Padding.Left:0}–{right - row.Padding.Right:0} px");
}
}
}
}
finally
{
UiLanguage.Apply("en");
}
});
/// <summary>The left and right edges of an element in window coordinates, whichever way the window reads.</summary>
private static (double Left, double Right) Span(FrameworkElement element, Window window)
{
var a = element.TranslatePoint(new Point(0, 0), window).X;
var b = element.TranslatePoint(new Point(element.ActualWidth, 0), window).X;
return (Math.Min(a, b), Math.Max(a, b));
}
private static TextBlock Text(ScreenSmokeTests.SampleApp app, string text) => app.FindAll<TextBlock>().First(t => t.Text == text && t.IsVisible);
/// <summary>The left edge of an element in window coordinates.</summary>
private static double Left(FrameworkElement element) => element.TranslatePoint(new Point(0, 0), Window.GetWindow(element)).X;
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;
}
}
}