Files
Chronos/tests/Chronos.App.Tests/Jobs/JobsScreenSmokeTests.cs
T
Alby96andClaude Opus 5.5 a89ec10ebf
CI / Build and test (pull_request) Successful in 11m47s
CI / Windows tests and installer (pull_request) Skipped
CI / YAML check (pull_request) Successful in 12s
CI / PostgreSQL 16 integration (pull_request) Successful in 10m37s
CI / PostgreSQL 17 integration (pull_request) Successful in 9m56s
CI / Docker image (pull_request) Successful in 1m48s
fix(jobs): show job log times in local time and give the Type column room; 1.1.1
The Windows hands-on test of 1.1.0 found two things in Jobs. The log under a job showed UTC times (12:35) next to rows
in local time (13:35): the stored log keeps UTC, so a server's jobs read right anywhere, and the desktop now dates the
lines backwards from the job's end and shows them in local time. The Type column cut "Analisi approfondita" at a
0.7* share; a 1* share (90-170 px) fits it in a 1440 px window and still gives way at the 1200 px minimum.

Builds without a release tag say 1.1.1; CHANGELOG [1.1.1], STATUS and DECISIONS updated.

Refs #70

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-16 14:26:21 +01:00

197 lines
9.9 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.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>
/// In a 1440 px window (a 1920 px screen at 100 %), the Type column shows the Italian kinds whole, the longest
/// "Analisi approfondita" included: it was cut at a 0.7* share (#70).
/// </summary>
[Test]
public Task KindsFitTheTypeColumnInItalianAt1440() => 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 = 1440;
UiLanguage.Apply("it");
try
{
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, "several rows are on screen");
foreach (var item in items)
{
var row = (JobRowViewModel)item.DataContext;
var kind = Descendants<TextBlock>(item).First(t => t.Text == row.Kind);
Assert.True(Needed(kind, kind.Text) <= kind.ActualWidth + 0.5, $"'{row.Kind}' needs {Needed(kind, kind.Text):0.0} px, has {kind.ActualWidth:0.0}");
var deep = JobText.Kind(Core.Model.JobKind.DeepAnalyse);
Assert.True(Needed(kind, deep) <= kind.ActualWidth + 0.5, $"'{deep}' needs {Needed(kind, deep):0.0} px, has {kind.ActualWidth:0.0}");
}
}
finally
{
UiLanguage.Apply("en");
}
});
/// <summary>The width <paramref name="text"/> takes in <paramref name="cell"/>'s font.</summary>
private static double Needed(TextBlock cell, string text) => new FormattedText(text, System.Globalization.CultureInfo.CurrentUICulture, cell.FlowDirection,
new Typeface(cell.FontFamily, cell.FontStyle, cell.FontWeight, cell.FontStretch), cell.FontSize, Brushes.Black,
VisualTreeHelper.GetDpi(cell).PixelsPerDip).WidthIncludingTrailingWhitespace;
/// <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;
}
}
}