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
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:
1 parent
c99842cc86
commit
5f27a86406
1799 files changed
+11728
-10668
No files matched your search
@@ -0,0 +1,93 @@
|
||||
using Chronos.App.Settings;
|
||||
using Chronos.Testing;
|
||||
|
||||
namespace Chronos.App.Tests.Settings;
|
||||
|
||||
/// <summary>
|
||||
/// Settings › Archive never shows a read of the archive's settings that overlapped an edit being written: on a slow share
|
||||
/// that read can hold archive.json as it was before the edit, and would undo the edit on the rows and in this PC's
|
||||
/// defaults while the archive keeps it. Its reader waits for the edits instead and reads again, so the read is done only
|
||||
/// once the rows show what the archive holds.
|
||||
/// </summary>
|
||||
public sealed class ArchiveReadGateTests
|
||||
{
|
||||
[Test]
|
||||
public void AReadWithNoEditMeanwhileIsShown()
|
||||
{
|
||||
var gate = new ArchiveReadGate();
|
||||
Assert.True(gate.IsCurrent(gate.BeginRead()));
|
||||
Assert.True(gate.WrittenAsync().IsCompleted, "no edit is being written");
|
||||
|
||||
// An edit written and ended before the read began is in the file it reads.
|
||||
gate.BeginWrite();
|
||||
gate.EndWrite();
|
||||
Assert.True(gate.IsCurrent(gate.BeginRead()));
|
||||
Assert.True(gate.WrittenAsync().IsCompleted);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void AReadThatAnEditOverlapsWaitsForTheEditAndReadsAgain()
|
||||
{
|
||||
// Settings is shown and reads archive.json; the user commits a template before the read answers.
|
||||
var gate = new ArchiveReadGate();
|
||||
var read = gate.BeginRead();
|
||||
gate.BeginWrite();
|
||||
Assert.False(gate.IsCurrent(read), "the read may hold the file before the edit");
|
||||
var written = gate.WrittenAsync();
|
||||
Assert.False(written.IsCompleted, "the edit is still being written");
|
||||
gate.EndWrite();
|
||||
Assert.True(written.IsCompleted, "the reader reads again once the edit is written");
|
||||
Assert.True(gate.IsCurrent(gate.BeginRead()));
|
||||
|
||||
// The edit began and ended while the read was out: the reader reads again at once.
|
||||
read = gate.BeginRead();
|
||||
gate.BeginWrite();
|
||||
gate.EndWrite();
|
||||
Assert.False(gate.IsCurrent(read));
|
||||
Assert.True(gate.WrittenAsync().IsCompleted);
|
||||
Assert.True(gate.IsCurrent(gate.BeginRead()));
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void AReadBegunWhileAnEditIsWrittenIsNeverShown()
|
||||
{
|
||||
// The rows are read again (a folder change, the screen shown) while an edit is still being written.
|
||||
var gate = new ArchiveReadGate();
|
||||
gate.BeginWrite();
|
||||
var read = gate.BeginRead();
|
||||
Assert.False(gate.IsCurrent(read));
|
||||
var written = gate.WrittenAsync();
|
||||
gate.EndWrite();
|
||||
Assert.False(gate.IsCurrent(read), "it began before the edit was written");
|
||||
Assert.True(written.IsCompleted);
|
||||
Assert.True(gate.IsCurrent(gate.BeginRead()));
|
||||
}
|
||||
|
||||
[Test]
|
||||
public async Task AReaderGoesOnOnlyOnceTheLastOfSeveralEditsIsWrittenAndNeverInsideIt()
|
||||
{
|
||||
// A proxy size and a thumbnail size picked one after the other, both overlapping a read.
|
||||
var gate = new ArchiveReadGate();
|
||||
var read = gate.BeginRead();
|
||||
gate.BeginWrite();
|
||||
gate.BeginWrite();
|
||||
Assert.False(gate.IsCurrent(read));
|
||||
var written = gate.WrittenAsync();
|
||||
Assert.Same(written, gate.WrittenAsync());
|
||||
gate.EndWrite();
|
||||
Assert.False(written.IsCompleted, "another edit is still being written");
|
||||
|
||||
// The reader goes on once the last edit ends, never inside its EndWrite: the writer finishes first.
|
||||
var thread = Environment.CurrentManagedThreadId;
|
||||
var ending = false;
|
||||
var inside = written.ContinueWith(_ => ending && Environment.CurrentManagedThreadId == thread, CancellationToken.None,
|
||||
TaskContinuationOptions.ExecuteSynchronously, TaskScheduler.Default);
|
||||
ending = true;
|
||||
gate.EndWrite();
|
||||
ending = false;
|
||||
Assert.True(written.IsCompleted);
|
||||
Assert.False(await inside, "the reader did not go on inside EndWrite");
|
||||
Assert.True(gate.IsCurrent(gate.BeginRead()));
|
||||
Assert.Throws<InvalidOperationException>(() => gate.EndWrite());
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,332 @@
|
||||
using System.ComponentModel;
|
||||
using System.Globalization;
|
||||
using System.IO;
|
||||
using Chronos.App.Settings;
|
||||
using Chronos.Core.Localization;
|
||||
using Chronos.Core.Naming;
|
||||
using Chronos.Core.Video;
|
||||
using Chronos.Testing;
|
||||
|
||||
namespace Chronos.App.Tests.Settings;
|
||||
|
||||
public sealed class SettingsLogicTests
|
||||
{
|
||||
public SettingsLogicTests() => Loc.SetCulture(CultureInfo.GetCultureInfo("en"));
|
||||
|
||||
[Test]
|
||||
public void DefaultTemplatesPreviewThreeNames()
|
||||
{
|
||||
var names = NamingPreview.FirstNames(TemplateDefaults.Folder, TemplateDefaults.File);
|
||||
Assert.SequenceEqual(
|
||||
[
|
||||
"2026/2026-09-28 Canon EOS R5/2026-09-28_18-02-11_0001.CR2",
|
||||
"2026/2026-09-28 Canon EOS R5/2026-09-28_18-02-13_0002.CR2",
|
||||
"2026/2026-09-28 Canon EOS R5/2026-09-28_18-02-15_0003.CR2",
|
||||
],
|
||||
names);
|
||||
Assert.Null(NamingPreview.Validate(TemplateDefaults.Folder, isFolder: true));
|
||||
Assert.Null(NamingPreview.Validate(TemplateDefaults.File, isFolder: false));
|
||||
}
|
||||
|
||||
[Theory]
|
||||
[Case("{date}_{time}_{n:0000", "Errors.Template.UnclosedBrace", "", 15)]
|
||||
[Case("{date}_{nope}", "Errors.Template.UnknownToken", "nope", 8)]
|
||||
[Case("{}_{n}", "Errors.Template.EmptyToken", "", 1)]
|
||||
[Case("{n}}x", "Errors.Template.UnopenedBrace", "", 4)]
|
||||
[Case(" ", "Errors.Template.Empty", "", 1)]
|
||||
[Case("{date}", "Errors.Template.NotUnique", "", 0)]
|
||||
[Case("{year}/{n}", "Errors.Template.FileSeparator", "", 0)]
|
||||
[Case("{date:%}_{n}", "Errors.Template.Format", "", 0)]
|
||||
public void InvalidFileTemplatesExplainTheProblem(string template, string key, string token, int position)
|
||||
{
|
||||
var expected = position > 0 ? Loc.L(key, token, position) : Loc.L(key);
|
||||
Assert.Equal(expected, NamingPreview.Validate(template, isFolder: false), template);
|
||||
Assert.Empty(NamingPreview.FirstNames(TemplateDefaults.Folder, template));
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void TemplateErrorsNameThePosition()
|
||||
{
|
||||
Assert.Equal("The brace opened at position 8 is never closed.", NamingPreview.Validate("{date}_{time", isFolder: false));
|
||||
Assert.Equal("Unknown token “nope” at position 8.", NamingPreview.Validate("{date}_{nope}", isFolder: false));
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void FolderTemplatesMayNestAndRepeat()
|
||||
{
|
||||
Assert.Null(NamingPreview.Validate("{year}/{month}/{camera}", isFolder: true));
|
||||
Assert.Equal("2026/09/Canon EOS R5/IMG_4211.CR2", NamingPreview.FirstNames("{year}/{month}/{camera}", "{name}")[0]);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void EnterCommitsAndEscReverts()
|
||||
{
|
||||
string? stored = null;
|
||||
var field = new EditableField("8", v => int.TryParse(v, out var n) && n is >= 1 and <= 32 ? null : "1 to 32", v => stored = v, () => "Worker threads");
|
||||
var changes = new List<string?>();
|
||||
field.PropertyChanged += (_, e) => changes.Add(e.PropertyName);
|
||||
var errors = 0;
|
||||
field.ErrorsChanged += (_, _) => errors++;
|
||||
|
||||
field.Text = "12";
|
||||
Assert.True(field.IsDirty);
|
||||
Assert.False(field.HasErrors);
|
||||
Assert.Equal("Worker threads", field.ToolTip);
|
||||
Assert.True(field.Commit());
|
||||
Assert.Equal("12", stored);
|
||||
Assert.Equal("12", field.Value);
|
||||
Assert.False(field.IsDirty);
|
||||
|
||||
field.Text = "99";
|
||||
Assert.True(field.HasErrors);
|
||||
Assert.Equal("1 to 32", field.ToolTip);
|
||||
Assert.Equal("1 to 32", ((IEnumerable<string>)field.GetErrors(nameof(EditableField.Text))).Single());
|
||||
Assert.False(field.Commit());
|
||||
Assert.Equal("12", stored);
|
||||
|
||||
field.Revert();
|
||||
Assert.Equal("12", field.Text);
|
||||
Assert.False(field.HasErrors);
|
||||
Assert.False(field.IsDirty);
|
||||
Assert.Equal(2, errors);
|
||||
Assert.Contains(nameof(EditableField.ToolTip), changes);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void LoadReplacesTheValueWithoutCommitting()
|
||||
{
|
||||
var commits = 0;
|
||||
var field = new EditableField("a", v => v.Length == 0 ? "empty" : null, _ => commits++, () => "tip");
|
||||
field.Load("b");
|
||||
Assert.Equal("b", field.Value);
|
||||
Assert.Equal("b", field.Text);
|
||||
Assert.False(field.IsDirty);
|
||||
Assert.Equal(0, commits);
|
||||
Assert.True(field.Commit());
|
||||
Assert.Equal(0, commits); // nothing changed, nothing stored
|
||||
field.Load(string.Empty);
|
||||
Assert.True(field.HasErrors);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void TheLanguageListHasEveryShippedCatalog()
|
||||
{
|
||||
var available = LanguageCatalog.Available;
|
||||
Assert.Equal("en", available[0].Code);
|
||||
Assert.Equal(available.Count, available.Select(l => l.Code).Distinct(StringComparer.OrdinalIgnoreCase).Count());
|
||||
foreach (var option in available)
|
||||
{
|
||||
Assert.Contains(option.Code, Languages.Shipped);
|
||||
Assert.True(LanguageCatalog.HasResources(option.Code), option.Code);
|
||||
Assert.False(string.IsNullOrWhiteSpace(option.Name));
|
||||
}
|
||||
|
||||
// Every culture folder of the catalog is offered, and nothing else.
|
||||
var folders = Directory.EnumerateDirectories(Path.Combine(TestContext.RepositoryRoot, "i18n"))
|
||||
.Select(Path.GetFileName)
|
||||
.Where(n => n is not null && Directory.EnumerateFiles(Path.Combine(TestContext.RepositoryRoot, "i18n", n), "*.resx").Any())
|
||||
.ToHashSet(StringComparer.OrdinalIgnoreCase);
|
||||
Assert.Contains("it", folders);
|
||||
Assert.SequenceEqual(folders.Order(StringComparer.OrdinalIgnoreCase), available.Select(o => o.Code).Order(StringComparer.OrdinalIgnoreCase));
|
||||
Assert.Equal("Italiano", available.Single(o => o.Code == "it").Name);
|
||||
Assert.Equal("it", LanguageCatalog.Match(CultureInfo.GetCultureInfo("it-CH")).Code);
|
||||
Assert.Equal("en", LanguageCatalog.Match(CultureInfo.GetCultureInfo("sw")).Code);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void EachEncoderNamesThePresetsItServes()
|
||||
{
|
||||
var hevc = new EncoderRow("HEVC", "NVIDIA HEVC Encoder MFT", "NVIDIA", EncoderSource.MediaFoundation, true, true, 8192, 8192, VideoCodec.Hevc);
|
||||
var av1 = hevc with { Codec = "AV1", Name = "NVIDIA AV1 Encoder MFT", VideoCodec = VideoCodec.Av1 };
|
||||
var h264 = new EncoderRow("H.264", "H264 Encoder MFT", "Microsoft", EncoderSource.MediaFoundation, false, false, 4096, 2304, VideoCodec.H264);
|
||||
var animation = new EncoderRow("GIF · APNG", "Chronos", null, EncoderSource.BuiltInAnimation, false, false, 0, 0, null);
|
||||
|
||||
Assert.SequenceEqual(["8K archive", "4K archive", "4K HEVC", "DCI 4K", "Cinema 21:9", "4K 60 fps"], EncoderUse.Presets(hevc));
|
||||
Assert.Equal("Animated GIF · Animated PNG", EncoderUse.Text(animation));
|
||||
Assert.Contains("Share 1080p", EncoderUse.Presets(h264));
|
||||
Assert.Equal("4K AV1", EncoderUse.Text(av1));
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void ARenderNodeOffersHardwareEncodersOnlyWhenRendersMayUseThem()
|
||||
{
|
||||
EncoderRow[] rows =
|
||||
[
|
||||
new("HEVC", "NVIDIA HEVC Encoder MFT", "NVIDIA", EncoderSource.MediaFoundation, true, true, 8192, 8192, VideoCodec.Hevc),
|
||||
new("H.264", "NVIDIA H.264 Encoder MFT", "NVIDIA", EncoderSource.MediaFoundation, true, false, 4096, 4096, VideoCodec.H264),
|
||||
new("H.264", "H264 Encoder MFT", "Microsoft", EncoderSource.MediaFoundation, false, false, 4096, 2304, VideoCodec.H264),
|
||||
new("MJPEG · AVI", "Chronos", null, EncoderSource.BuiltInMjpeg, false, false, 0, 0, VideoCodec.Mjpeg),
|
||||
];
|
||||
|
||||
Assert.Equal("HEVC · H.264", EncoderUse.Codecs(EncoderUse.Node(rows, allowsHardware: true)));
|
||||
Assert.Equal(3, EncoderUse.Node(rows, allowsHardware: true).Count);
|
||||
Assert.Equal("H.264", EncoderUse.Codecs(EncoderUse.Node(rows, allowsHardware: false)));
|
||||
Assert.Null(EncoderUse.Codecs([]));
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void ThePreviewTitleSpeaksTheInterfaceLanguage()
|
||||
{
|
||||
// The sample's title is a catalog string read on every preview (so a language switch shows at once), not English text.
|
||||
Assert.Equal("Harbour sunset", NamingPreview.FirstNames("{title}", "{n:0000}")[0].Split('/')[0]);
|
||||
Assert.Equal("Harbour sunset", NamingPreview.SampleFrames[0].Title);
|
||||
Assert.False(ReferenceEquals(NamingPreview.SampleFrames, NamingPreview.SampleFrames), "built on each call");
|
||||
var italian = Loc.Get("Settings.Naming.SampleTitle", CultureInfo.GetCultureInfo("it"));
|
||||
Assert.True(italian is { Length: > 0 } && italian != "Harbour sunset", italian);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void TheQualityProfileTunesTheJobs()
|
||||
{
|
||||
var settings = new Chronos.App.Infrastructure.AppSettings { Quality = Chronos.App.Infrastructure.QualityProfile.Best, Parallelism = 3, MemoryBudgetGb = 6 };
|
||||
var basis = new Chronos.Data.Processing.ProcessingOptions();
|
||||
|
||||
// One job runs at a time (owner review 1): it has the whole 6 GB, and decodes and measures 3 photos at once.
|
||||
var best = ProcessingTuning.Apply(basis, settings, 64L << 30, 16, @"C:\cache");
|
||||
Assert.Equal((6L << 30, @"C:\cache", 8, 3), (best.FrameWindow.MemoryBudget, best.FrameWindow.SpillDirectory, best.FrameWindow.Ahead, best.FrameWindow.MaxConcurrentLoads));
|
||||
Assert.Equal((1024, Chronos.Core.Project.FlowQualitySetting.Best), (best.Render.AnalysisLongEdge, best.Render.DefaultFlowQuality));
|
||||
Assert.Equal(3, best.DeepAnalysis.MaxDegreeOfParallelism);
|
||||
settings.Parallelism = 1;
|
||||
var single = ProcessingTuning.Apply(basis, settings, 64L << 30, 16, @"C:\cache");
|
||||
Assert.Equal((6L << 30, 1, 1), (single.FrameWindow.MemoryBudget, single.FrameWindow.MaxConcurrentLoads, single.DeepAnalysis.MaxDegreeOfParallelism));
|
||||
// A parallelism beyond the read-ahead widens the window, so the decodes have frames to work on.
|
||||
settings.Parallelism = 12;
|
||||
var wide = ProcessingTuning.Apply(basis, settings, 64L << 30, 16, @"C:\cache");
|
||||
Assert.Equal((12, 12, 12), (wide.FrameWindow.Ahead, wide.FrameWindow.MaxConcurrentLoads, wide.DeepAnalysis.MaxDegreeOfParallelism));
|
||||
|
||||
// Auto: a quarter of 32 GB, and half the 16 cores at once, with no cap of the analysis threads.
|
||||
settings.Quality = Chronos.App.Infrastructure.QualityProfile.Fast;
|
||||
settings.MemoryBudgetGb = null;
|
||||
settings.Parallelism = null;
|
||||
var fast = ProcessingTuning.Apply(basis, settings, 32L << 30, 16, @"C:\cache");
|
||||
Assert.Equal((8L << 30, 8), (fast.FrameWindow.MemoryBudget, fast.FrameWindow.Ahead));
|
||||
Assert.Equal((8, 8), (fast.FrameWindow.MaxConcurrentLoads, fast.DeepAnalysis.MaxDegreeOfParallelism));
|
||||
Assert.Equal((256, Chronos.Core.Project.FlowQualitySetting.Draft), (fast.Render.AnalysisLongEdge, fast.Render.DefaultFlowQuality));
|
||||
Assert.Equal(512, ProcessingTuning.PreparationLongEdge(Chronos.App.Infrastructure.QualityProfile.Balanced));
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void ParallelismAutoIsHalfTheCores()
|
||||
{
|
||||
// Photos the running job processes at once (owner review 1): half the cores, the archive engine's own default.
|
||||
Assert.Equal(8, ProcessingTuning.ParallelismAuto(16));
|
||||
Assert.Equal(2, ProcessingTuning.ParallelismAuto(4));
|
||||
Assert.Equal(1, ProcessingTuning.ParallelismAuto(1));
|
||||
Assert.Equal(Chronos.Data.Archiving.ArchiveServiceOptions.DefaultParallelism, ProcessingTuning.ParallelismAuto(Environment.ProcessorCount));
|
||||
Assert.Equal(1, new Chronos.Data.Jobs.JobEngineOptions().Workers);
|
||||
Assert.Equal(8, ProcessingTuning.Parallelism(new Chronos.App.Infrastructure.AppSettings(), 16));
|
||||
Assert.Equal(5, ProcessingTuning.Parallelism(new Chronos.App.Infrastructure.AppSettings { Parallelism = 5 }, 16));
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void TheAnalysisSettingsBecomeTheDeepAnalysisParameters()
|
||||
{
|
||||
var defaults = new Chronos.App.Infrastructure.AppSettings().DeepAnalysis(Chronos.Core.Analysis.Deep.DeepAnalysisOptions.Default);
|
||||
// The defaults of Settings › Analysis are the engine's own: nothing changes until the user does.
|
||||
Assert.Equal(Chronos.Core.Analysis.Deep.DeepAnalysisOptions.Default.Fingerprint(), defaults.Fingerprint());
|
||||
Assert.Equal(Chronos.Core.Analysis.Deep.DeepAnalysisOptions.Default.StarFieldDensity, defaults.StarFieldDensity);
|
||||
|
||||
var tuned = new Chronos.App.Infrastructure.AppSettings { AnalysisLongEdge = 1024, NightBrightnessPercent = 12.5, StarFieldDensity = 60 }
|
||||
.DeepAnalysis(Chronos.Core.Analysis.Deep.DeepAnalysisOptions.Default);
|
||||
Assert.Equal((1024, -3.0, 60.0), (tuned.MaxAnalysisLongEdge, tuned.DarkLogLuminance, tuned.StarFieldDensity));
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void NewCardsStartFromSettingsImport()
|
||||
{
|
||||
var settings = new Chronos.App.Infrastructure.AppSettings
|
||||
{
|
||||
ImportSessionGapMinutes = 90,
|
||||
ImportMinimumFrames = 20,
|
||||
ImportSubfolders = false,
|
||||
ImportVerify = false,
|
||||
ImportDuplicates = Chronos.Core.Import.DuplicatePolicy.ImportAgain,
|
||||
ImportAfter = Chronos.Data.Archiving.AfterImport.DeleteImported,
|
||||
ImportEject = false,
|
||||
DeepAnalysisAfterImport = false,
|
||||
};
|
||||
var profile = settings.ImportProfile("{year}", "{name}");
|
||||
Assert.Equal(("{year}", "{name}", 90, 20), (profile.FolderTemplate, profile.FileTemplate, profile.SessionGapMinutes, profile.MinimumSessionFrames));
|
||||
Assert.Equal((false, false, false, false), (profile.IncludeSubfolders, profile.VerifyCopies, profile.Eject, profile.DeepAnalysis));
|
||||
Assert.Equal((Chronos.Core.Import.DuplicatePolicy.ImportAgain, Chronos.Data.Archiving.AfterImport.DeleteImported), (profile.Duplicates, profile.AfterImport));
|
||||
// Untouched settings give the brief's card defaults.
|
||||
Assert.Equal(new Chronos.Data.Archiving.CardProfile(), new Chronos.App.Infrastructure.AppSettings().ImportProfile(TemplateDefaults.Folder, TemplateDefaults.File));
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void NewArchivesTakeSettingsArchive()
|
||||
{
|
||||
var settings = new Chronos.App.Infrastructure.AppSettings { FolderTemplate = "{year}", FileTemplate = "{name}", ProxyLongEdge = 2560, ThumbnailLongEdge = 480 };
|
||||
var archive = settings.ArchiveDefaults();
|
||||
Assert.Equal(("{year}", "{name}", 2560, 480), (archive.Templates.Folder, archive.Templates.File, archive.Proxies.LongEdge, archive.Thumbnails.LongEdge));
|
||||
Assert.Null((new Chronos.App.Infrastructure.AppSettings().ArchiveDefaults() with { Name = "Archive" }).Problem());
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void TheArchiveRowsEditOnlyTheArchiveAtTheArchiveFolder()
|
||||
{
|
||||
var main = new Chronos.Core.Model.Archive { Id = Guid.CreateVersion7(), Name = "Main", RootPath = "/archive", Created = DateTimeOffset.UtcNow };
|
||||
var travel = new Chronos.Core.Model.Archive { Id = Guid.CreateVersion7(), Name = "Travel", RootPath = "/media/travel", Created = DateTimeOffset.UtcNow };
|
||||
|
||||
Assert.Equal(travel.Id, Chronos.App.Archiving.CurrentArchive.At([main, travel], "/media/travel/")!.Id);
|
||||
// A folder no archive of the index is at: no archive at all, never the first one (its archive.json is someone else's).
|
||||
Assert.Null(Chronos.App.Archiving.CurrentArchive.At([main, travel], "/media/new"));
|
||||
Assert.Equal(main.Id, Chronos.App.Archiving.CurrentArchive.Pick([main, travel], "/media/new")!.Id);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void SettingsSurviveARoundTripWithTheNewSections()
|
||||
{
|
||||
var settings = new Chronos.App.Infrastructure.AppSettings { ThumbnailLongEdge = 640, ScanIntervalMinutes = 30, NightBrightnessPercent = 3.5, DeepAnalysisAfterScan = true };
|
||||
var copy = Chronos.App.Infrastructure.AppSettings.Parse(settings.ToJson())!;
|
||||
Assert.Equal((640, 30, 3.5, true), (copy.ThumbnailLongEdge, copy.ScanIntervalMinutes, copy.NightBrightnessPercent, copy.DeepAnalysisAfterScan));
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void BackgroundPriorityRaisesTheInterfaceOnlyInFront()
|
||||
{
|
||||
Assert.Equal(ThreadPriority.AboveNormal, InterfacePriority.For(enabled: true, active: true));
|
||||
Assert.Equal(ThreadPriority.Normal, InterfacePriority.For(enabled: true, active: false));
|
||||
Assert.Equal(ThreadPriority.Normal, InterfacePriority.For(enabled: false, active: true));
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void FormatsShowTheirTierAndWhatToInstall()
|
||||
{
|
||||
Assert.Equal(("JPEG XL", "CR3", "3FR"), (FormatNames.Of(Chronos.Core.Imaging.ImageFileFormat.JpegXl), FormatNames.Of(Chronos.Core.Imaging.ImageFileFormat.Cr3),
|
||||
FormatNames.Of(Chronos.Core.Imaging.ImageFileFormat.ThreeFr)));
|
||||
var heif = Chronos.Core.Windows.Codecs.StoreExtension.Get(Chronos.Core.Windows.Codecs.StoreExtensionKind.HeifImage);
|
||||
var format = Chronos.Core.Imaging.Decoders.DecoderFactory.DescribeFormats(Chronos.Core.Imaging.Decoders.DecoderFactory.CreateClient(null))
|
||||
.First(f => f.Format.Format == Chronos.Core.Imaging.ImageFileFormat.Heif).Format;
|
||||
var row = new FormatRowViewModel(new FormatRow(format, Chronos.Core.Imaging.DecodeTier.EmbeddedPreview, "managed", [heif]));
|
||||
Assert.Equal(("Preview only", "Chronos", heif.ProductName), (row.TierText, row.DecoderText, row.NeedsText));
|
||||
Assert.Equal(Chronos.Ui.Controls.StatusKind.Warning, row.TierKind);
|
||||
Assert.Equal("HEIF: Preview only", row.Announcement);
|
||||
var missing = new MissingExtensionViewModel(heif, new Chronos.Ui.Mvvm.RelayCommand(() => { }));
|
||||
Assert.Equal(heif.ProductName + " missing", missing.Text);
|
||||
var none = new FormatRowViewModel(new FormatRow(format, Chronos.Core.Imaging.DecodeTier.Unavailable, null, []));
|
||||
Assert.Equal(("Not supported", "—", "—", false), (none.TierText, none.DecoderText, none.NeedsText, none.HasNeeds));
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void EnumDrivenKeysExistInEveryRequiredLanguage()
|
||||
{
|
||||
var keys = new List<string>();
|
||||
keys.AddRange(Enum.GetNames<Chronos.Core.Model.JobKind>().Select(k => "Jobs.Kind." + k));
|
||||
keys.AddRange(Enum.GetNames<Chronos.Core.Model.JobState>().Select(k => "Jobs.State." + k));
|
||||
keys.AddRange(Enum.GetNames<Chronos.Core.Model.JobState>().Select(k => "Tooltips.Jobs.State." + k));
|
||||
keys.AddRange(Enum.GetNames<Chronos.App.Jobs.JobFilter>().SelectMany(k => new[] { "Jobs.Filter." + k, "Tooltips.Jobs.Filter." + k }));
|
||||
keys.AddRange(Enum.GetNames<Chronos.App.Library.StatusFilter>().Where(k => k != "Any").Select(k => "Library.Filter.Status." + k));
|
||||
keys.AddRange(Enum.GetNames<Chronos.Data.Repositories.SequenceSort>().Select(k => "Library.Sort." + k));
|
||||
keys.AddRange(Enum.GetNames<Chronos.App.Server.ConnectError>().Where(k => k != "None").Select(k => "Server.Error." + k));
|
||||
keys.AddRange(Enum.GetNames<Chronos.Core.Model.UserRole>().SelectMany(k => new[] { "Server.Role." + k, "Tooltips.Server.Role." + k }));
|
||||
keys.AddRange(Enum.GetNames<SettingsPage>().SelectMany(k => new[] { "Settings.Page." + k, "Tooltips.Settings.Page." + k }));
|
||||
keys.AddRange(Enum.GetNames<Chronos.App.Infrastructure.QualityProfile>().Select(k => "Settings.Rendering.Quality." + k));
|
||||
keys.AddRange(new[] { "UnclosedBrace", "EmptyToken", "UnknownToken", "UnopenedBrace", "Empty" }.Select(k => "Errors.Template." + k));
|
||||
// Italian completeness is checked by `Chronos.Tools i18n check`; here every enum value must have its key.
|
||||
var english = Loc.GetArea("Jobs", CultureInfo.InvariantCulture).Keys
|
||||
.Concat(new[] { "Library", "Server", "Settings", "Tooltips", "Errors" }.SelectMany(a => Loc.GetArea(a, CultureInfo.InvariantCulture).Keys))
|
||||
.ToHashSet(StringComparer.Ordinal);
|
||||
foreach (var key in keys) Assert.True(english.Contains(key), key);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,453 @@
|
||||
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.Sections;
|
||||
using Chronos.App.Server;
|
||||
using Chronos.App.Settings;
|
||||
using Chronos.App.Shell;
|
||||
using Chronos.App.Tests.Windows;
|
||||
using Chronos.Core.Localization;
|
||||
using Chronos.Testing;
|
||||
|
||||
namespace Chronos.App.Tests.Settings;
|
||||
|
||||
/// <summary>
|
||||
/// Settings, the first-run dialog and the reading direction on the capture sample: values other screens set, labels and
|
||||
/// paths that survive long translations and right-to-left text, keyboard focus and the questions before forgetting.
|
||||
/// </summary>
|
||||
[WindowsOnly]
|
||||
[Serial]
|
||||
[Timeout(300_000)]
|
||||
public sealed class SettingsScreenSmokeTests
|
||||
{
|
||||
[Test]
|
||||
public Task SettingsShowCurrentValuesAndNeverCutLabelsOrRows() => ScreenHost.RunAsync(async () =>
|
||||
{
|
||||
await using var app = await ScreenSmokeTests.SampleApp.StartAsync();
|
||||
var shell = app.Shell;
|
||||
await app.Sample.FillAsync();
|
||||
await shell.Services.Server.RestoreAsync();
|
||||
var settings = shell.Settings;
|
||||
|
||||
// The open archive and the server connected to were set after Settings was built: it shows them when opened.
|
||||
shell.Navigate(SectionKey.Settings);
|
||||
Assert.Equal(@"D:\ChronosArchive", settings.ArchiveRoot.Text);
|
||||
Assert.Equal("https://nas.local:8443", settings.DefaultServer.Text);
|
||||
Assert.False(settings.ArchiveRoot.IsDirty || settings.DefaultServer.IsDirty, "values loaded, not edits");
|
||||
|
||||
// The section list shows where keyboard focus is.
|
||||
await app.ExpectAsync<SettingsView>("settings-general");
|
||||
Assert.True(app.FindAll<ListBoxItem>().Where(i => i.DataContext is SettingsPageItem).All(i => i.FocusVisualStyle is not null), "sections have a focus ring");
|
||||
|
||||
// At the minimum window width the cache folder row stays one line: Clear beside the path, not under it.
|
||||
settings.Page = SettingsPage.Storage;
|
||||
await app.ExpectAsync<SettingsView>("settings-storage");
|
||||
var window = Window.GetWindow(app.FindAll<SettingsView>().First(v => v.IsVisible));
|
||||
var width = window.Width;
|
||||
window.Width = 1200;
|
||||
window.UpdateLayout();
|
||||
var cache = Field(app, Loc.L("Settings.Storage.Folder"));
|
||||
var clear = app.FindAll<Button>().First(b => b.Content as string == Loc.L("Settings.Storage.Clear") && b.IsVisible);
|
||||
Assert.Approximately(Middle(cache), Middle(clear), 2, "Clear is on the path's line");
|
||||
Assert.Equal(FlowDirection.LeftToRight, cache.FlowDirection);
|
||||
// Beside the 200 px rail, Clear stays inside the page in every language (owner review 1, R1).
|
||||
await InsidePageInEveryLanguageAsync(window, () => app.FindAll<Button>().First(b => ReferenceEquals(b.Command, settings.ClearCacheCommand) && b.IsVisible));
|
||||
window.Width = width;
|
||||
|
||||
// Long translations are never cut: German labels show whole (or wrap) in the shared label column.
|
||||
UiLanguage.Apply("de");
|
||||
try
|
||||
{
|
||||
await app.ExpectAsync<SettingsView>("settings-storage-de");
|
||||
foreach (var label in Labels(app)) Assert.True(IsWhole(label), $"\"{label.Text}\" is shown whole");
|
||||
}
|
||||
finally
|
||||
{
|
||||
UiLanguage.Apply("en");
|
||||
}
|
||||
|
||||
// Auto values are text with their reason in the tooltip, not buttons that do nothing.
|
||||
settings.Page = SettingsPage.Rendering;
|
||||
await app.ExpectAsync<SettingsView>("settings-rendering");
|
||||
Assert.False(app.FindAll<Button>().Any(b => b.Content is string text && (text == settings.MemoryAutoText || text == settings.ParallelismAutoText)), "no dead Auto buttons");
|
||||
|
||||
// Paths, addresses and fingerprints read left to right; read-only paths show whole in their tooltip.
|
||||
settings.Page = SettingsPage.Advanced;
|
||||
await app.ExpectAsync<SettingsView>("settings-advanced");
|
||||
var data = Field(app, Loc.L("Settings.Advanced.DataFolder"));
|
||||
Assert.Equal(FlowDirection.LeftToRight, data.FlowDirection);
|
||||
Assert.Equal(settings.DataFolder, data.ToolTip);
|
||||
// Advanced has nothing to reset: no Reset section there.
|
||||
Assert.False(settings.CanResetSection);
|
||||
Assert.False(settings.ResetSectionCommand.CanExecute(null));
|
||||
Assert.False(app.FindAll<Button>().Any(b => b.Content as string == Loc.L("Settings.ResetSection") && b.IsVisible), "no Reset section on Advanced");
|
||||
|
||||
// Forgetting a trusted certificate asks first, as on the Server screen; a "no" keeps it and the session.
|
||||
settings.Page = SettingsPage.Server;
|
||||
await app.ExpectAsync<SettingsView>("settings-server");
|
||||
Assert.True(settings.CanResetSection);
|
||||
Assert.Equal(FlowDirection.LeftToRight, Field(app, Loc.L("Settings.Server.Default")).FlowDirection);
|
||||
var certificate = Assert.Contains(settings.Certificates, _ => true);
|
||||
Assert.Contains(certificate.Server, certificate.ForgetName);
|
||||
// Beside the 200 px rail at the minimum width, Forget stays whole inside the page in every language (owner review 1, R1).
|
||||
window.Width = 1200;
|
||||
// (A language switch makes the certificate rows again: each round finds Forget in the row it shows.)
|
||||
await InsidePageInEveryLanguageAsync(window, () => app.FindAll<Button>().First(b => b is { DataContext: TrustedCertificateRow, IsVisible: true }));
|
||||
window.Width = width;
|
||||
certificate.ForgetCommand.Execute(null);
|
||||
Assert.Count(1, settings.Certificates);
|
||||
Assert.True(shell.Server.IsConnected, "the session on the certificate stays");
|
||||
Assert.True(ServerSession.ForgetRequest(certificate.FullFingerprint).IsDestructive);
|
||||
});
|
||||
|
||||
[Test]
|
||||
public Task ImportAnalysisAndFormatsAreRealSettings() => ScreenHost.RunAsync(async () =>
|
||||
{
|
||||
await using var app = await ScreenSmokeTests.SampleApp.StartAsync();
|
||||
var shell = app.Shell;
|
||||
await app.Sample.FillAsync();
|
||||
var settings = shell.Settings;
|
||||
// The open archive's own thumbnail size (archive.json) is what Settings › Archive shows.
|
||||
var archive = Assert.NotNull(await Chronos.App.Archiving.CurrentArchive.FindAsync(shell.Services.Database!, shell.Services.Settings.LastArchivePath));
|
||||
// The sample shows a display path as its archive folder; the rows edit only the archive at the archive folder.
|
||||
shell.Services.Settings.LastArchivePath = archive.RootPath;
|
||||
var manifestPath = new Chronos.Core.Archiving.ArchivePaths(archive.RootPath).ManifestPath;
|
||||
var manifest = Chronos.Core.Archiving.ManifestStore.ReadArchive(manifestPath);
|
||||
Chronos.Core.Archiving.ManifestStore.WriteArchive(manifestPath, manifest with { ThumbnailPolicy = new Chronos.Core.Archiving.ThumbnailPolicy { LongEdge = 240 } });
|
||||
|
||||
shell.Navigate(SectionKey.Settings);
|
||||
settings.Page = SettingsPage.Archive;
|
||||
await WaitAsync(() => settings.SelectedThumbnailSize.Value == 240, "the archive's thumbnail size is shown");
|
||||
await app.ExpectAsync<SettingsView>("settings-archive");
|
||||
settings.SelectedThumbnailSize = settings.ThumbnailSizes.Single(s => s.Value == 480);
|
||||
await WaitAsync(() => Chronos.Core.Archiving.ManifestStore.ReadArchive(manifestPath).ThumbnailPolicy.LongEdge == 480, "written into archive.json");
|
||||
Assert.Equal(480, shell.Services.Settings.ThumbnailLongEdge);
|
||||
|
||||
// A proxy size the admin panel set (3840 is none of the presets) is shown as it is, not as 1920.
|
||||
manifest = Chronos.Core.Archiving.ManifestStore.ReadArchive(manifestPath);
|
||||
Chronos.Core.Archiving.ManifestStore.WriteArchive(manifestPath, manifest with { ProxyPolicy = manifest.ProxyPolicy with { LongEdge = 3840 } });
|
||||
shell.Navigate(SectionKey.Library);
|
||||
shell.Navigate(SectionKey.Settings);
|
||||
await WaitAsync(() => settings.SelectedProxySize.Value == 3840, "the archive's own proxy size is shown");
|
||||
Assert.Equal("3840", settings.SelectedProxySize.Label);
|
||||
Assert.SequenceEqual([1280, 1920, 2560, 3840, Chronos.Core.Archiving.ProxyPolicy.FullSize, Chronos.Core.Archiving.ProxyPolicy.Disabled],
|
||||
settings.ProxySizes.Select(s => s.Value));
|
||||
|
||||
// Reset section on Archive changes the archive everyone shares: it asks first, and a "no" leaves archive.json alone.
|
||||
settings.ResetSectionCommand.Execute(null);
|
||||
Assert.Equal((480, 3840), (Chronos.Core.Archiving.ManifestStore.ReadArchive(manifestPath).ThumbnailPolicy.LongEdge,
|
||||
Chronos.Core.Archiving.ManifestStore.ReadArchive(manifestPath).ProxyPolicy.LongEdge));
|
||||
Assert.Equal(480, settings.SelectedThumbnailSize.Value);
|
||||
|
||||
// Import: the defaults of new cards.
|
||||
settings.Page = SettingsPage.Import;
|
||||
await app.ExpectAsync<SettingsView>("settings-import");
|
||||
settings.SessionGap.Text = "90";
|
||||
Assert.True(settings.SessionGap.Commit());
|
||||
settings.IsFormatCard = true;
|
||||
Assert.Equal((90, Chronos.Data.Archiving.AfterImport.FormatCard), (shell.Services.Settings.ImportSessionGapMinutes, shell.Services.Settings.ImportAfter));
|
||||
Assert.True(settings.CanResetSection);
|
||||
settings.ResetSectionCommand.Execute(null);
|
||||
Assert.Equal(("45", true), (settings.SessionGap.Text, settings.IsKeepCard));
|
||||
|
||||
// Analysis: thresholds in the language's own decimals, checked against their range.
|
||||
settings.Page = SettingsPage.Analysis;
|
||||
await app.ExpectAsync<SettingsView>("settings-analysis");
|
||||
Assert.Equal(6.25.ToString("0.##", System.Globalization.CultureInfo.CurrentCulture), settings.NightBrightness.Text);
|
||||
settings.NightBrightness.Text = "80";
|
||||
Assert.True(settings.NightBrightness.HasErrors, "beyond 50 %");
|
||||
settings.NightBrightness.Revert();
|
||||
settings.DeepAnalysisAfterScan = true;
|
||||
Assert.True(shell.Services.Settings.DeepAnalysisAfterScan);
|
||||
|
||||
// Formats: the tier of every format and a notice with Install per missing extension.
|
||||
settings.Page = SettingsPage.Formats;
|
||||
await WaitAsync(() => settings.Formats.Count > 0 && !settings.IsDetectingFormats, "formats listed");
|
||||
await app.ExpectAsync<SettingsView>("settings-formats");
|
||||
Assert.Count(3, settings.MissingExtensions);
|
||||
var installs = app.FindAll<Button>().Where(b => b.IsVisible && b.Content as string == Loc.L("Settings.Formats.Install")).ToList();
|
||||
Assert.Count(3, installs);
|
||||
Assert.True(installs.All(b => AutomationProperties.GetName(b).StartsWith(Loc.L("Settings.Formats.InstallName", string.Empty), StringComparison.Ordinal)), "named after the extension");
|
||||
Assert.Contains(settings.Formats, f => f.Row.Tier == Chronos.Core.Imaging.DecodeTier.Native);
|
||||
Assert.False(settings.CanResetSection, "Formats only shows this PC");
|
||||
installs[0].Command.Execute(null);
|
||||
});
|
||||
|
||||
[Test]
|
||||
public Task ArchiveRowsEditOnlyTheArchiveAtTheFolderAndKeepEditsMadeWhileItOpens() => ScreenHost.RunAsync(async () =>
|
||||
{
|
||||
await using var app = await ScreenSmokeTests.SampleApp.StartAsync();
|
||||
var shell = app.Shell;
|
||||
await app.Sample.FillAsync();
|
||||
var settings = shell.Settings;
|
||||
var db = shell.Services.Database!;
|
||||
var archive = Assert.NotNull(await Chronos.App.Archiving.CurrentArchive.FindAsync(db, null));
|
||||
var manifestPath = new Chronos.Core.Archiving.ArchivePaths(archive.RootPath).ManifestPath;
|
||||
static Chronos.Core.Archiving.ArchiveManifest Read(string path) => Chronos.Core.Archiving.ManifestStore.ReadArchive(path);
|
||||
shell.Navigate(SectionKey.Settings);
|
||||
settings.Page = SettingsPage.Archive;
|
||||
|
||||
// No archive folder: a template edit is this PC's default only, never the first archive of the index. The edit is
|
||||
// made once the rows follow the empty folder, so it cannot wait for anything that would hide a write.
|
||||
settings.ArchiveRoot.Text = string.Empty;
|
||||
Assert.True(settings.ArchiveRoot.Commit());
|
||||
await settings.ArchiveRetarget;
|
||||
settings.FolderTemplate.Text = "{camera}/{date}";
|
||||
Assert.True(settings.FolderTemplate.Commit());
|
||||
Assert.Equal("{camera}/{date}", shell.Services.Settings.FolderTemplate);
|
||||
|
||||
// The archive's folder is chosen and a template edited at once, while that archive is still opening: the edit
|
||||
// reaches its archive.json instead of being undone when it opens, and the row shows it.
|
||||
settings.ArchiveRoot.Text = archive.RootPath;
|
||||
Assert.True(settings.ArchiveRoot.Commit());
|
||||
settings.FileTemplate.Text = "{date}_{n:0000}";
|
||||
Assert.True(settings.FileTemplate.Commit());
|
||||
await WaitAsync(() => Read(manifestPath).LayoutTemplates.File == "{date}_{n:0000}", "the edit reached the archive that was opening");
|
||||
await WaitAsync(() => settings.FileTemplate.Text == "{date}_{n:0000}" && shell.Services.Settings.FileTemplate == "{date}_{n:0000}", "the row shows it");
|
||||
Assert.NotEqual("{camera}/{date}", Read(manifestPath).LayoutTemplates.Folder);
|
||||
|
||||
// An edit made before a second folder change, while the first folder's archive is still opening, goes to that
|
||||
// archive: never to the archive at the folder chosen after it.
|
||||
var otherRoot = System.IO.Path.Combine(shell.Services.Environment.DataDirectory, "other-archive");
|
||||
await shell.Services.Archives!.CreateAsync(otherRoot, "Other");
|
||||
var otherManifestPath = new Chronos.Core.Archiving.ArchivePaths(otherRoot).ManifestPath;
|
||||
settings.ArchiveRoot.Text = otherRoot;
|
||||
Assert.True(settings.ArchiveRoot.Commit());
|
||||
await settings.ArchiveRetarget;
|
||||
settings.ArchiveRoot.Text = archive.RootPath;
|
||||
Assert.True(settings.ArchiveRoot.Commit());
|
||||
settings.FileTemplate.Text = "{date}-{n:0000}";
|
||||
Assert.True(settings.FileTemplate.Commit());
|
||||
settings.ArchiveRoot.Text = otherRoot;
|
||||
Assert.True(settings.ArchiveRoot.Commit());
|
||||
await WaitAsync(() => Read(manifestPath).LayoutTemplates.File == "{date}-{n:0000}", "the edit reached the archive of the folder it was made for");
|
||||
// The folder change is done only once the rows show that folder's archive, also when its read overlapped the
|
||||
// edit written into the first archive: that read waits for the edit and reads again instead of leaving the rows.
|
||||
await settings.ArchiveRetarget;
|
||||
Assert.NotEqual("{date}-{n:0000}", Read(otherManifestPath).LayoutTemplates.File);
|
||||
Assert.Equal(Read(otherManifestPath).LayoutTemplates.File, settings.FileTemplate.Text);
|
||||
Assert.Equal(Read(otherManifestPath).LayoutTemplates.File, shell.Services.Settings.FileTemplate);
|
||||
settings.ArchiveRoot.Text = archive.RootPath;
|
||||
Assert.True(settings.ArchiveRoot.Commit());
|
||||
await settings.ArchiveRetarget;
|
||||
|
||||
// Offline, only archive.json knows the thumbnail size: this PC's stays instead of becoming the default.
|
||||
Chronos.Core.Archiving.ManifestStore.WriteArchive(manifestPath, Read(manifestPath) with { ThumbnailPolicy = new Chronos.Core.Archiving.ThumbnailPolicy { LongEdge = 480 } });
|
||||
shell.Navigate(SectionKey.Library);
|
||||
shell.Navigate(SectionKey.Settings);
|
||||
await WaitAsync(() => shell.Services.Settings.ThumbnailLongEdge == 480, "the archive's thumbnail size is shown");
|
||||
var row = Assert.NotNull(await db.Archives.GetAsync(archive.Id));
|
||||
await db.Archives.UpsertAsync(row with { ProxyLongEdge = 2560 });
|
||||
System.IO.File.Move(manifestPath, manifestPath + ".away");
|
||||
shell.Navigate(SectionKey.Library);
|
||||
shell.Navigate(SectionKey.Settings);
|
||||
await WaitAsync(() => shell.Services.Settings.ProxyLongEdge == 2560, "the index's proxy size is shown while offline");
|
||||
Assert.Equal(480, shell.Services.Settings.ThumbnailLongEdge);
|
||||
Assert.Equal(480, settings.SelectedThumbnailSize.Value);
|
||||
});
|
||||
|
||||
[Test]
|
||||
public Task AnArchiveRowEditedWhileSettingsReadsTheArchiveIsNotUndoneByThatRead() => ScreenHost.RunAsync(async () =>
|
||||
{
|
||||
await using var app = await ScreenSmokeTests.SampleApp.StartAsync();
|
||||
var shell = app.Shell;
|
||||
await app.Sample.FillAsync();
|
||||
var settings = shell.Settings;
|
||||
var archive = Assert.NotNull(await Chronos.App.Archiving.CurrentArchive.FindAsync(shell.Services.Database!, null));
|
||||
var paths = new Chronos.Core.Archiving.ArchivePaths(archive.RootPath);
|
||||
static Chronos.Core.Archiving.ArchiveManifest Read(string path) => Chronos.Core.Archiving.ManifestStore.ReadArchive(path);
|
||||
shell.Navigate(SectionKey.Settings);
|
||||
settings.Page = SettingsPage.Archive;
|
||||
settings.ArchiveRoot.Text = archive.RootPath;
|
||||
Assert.True(settings.ArchiveRoot.Commit());
|
||||
await settings.ArchiveRetarget;
|
||||
var before = Read(paths.ManifestPath).LayoutTemplates.File;
|
||||
const string edited = "{camera}_{n:00000}";
|
||||
Assert.NotEqual(edited, before);
|
||||
Assert.Equal(before, settings.FileTemplate.Text);
|
||||
|
||||
// Another PC holds the archive's settings, so the edit waits to be written. Settings is shown again just before
|
||||
// the edit is committed: its read of archive.json answers meanwhile, with the file from before the edit.
|
||||
var lease = Assert.NotNull(Chronos.Core.Archiving.LeaseFile.TryAcquire(paths.LocksDirectory, "archive-settings", "other-pc"));
|
||||
Task reload;
|
||||
try
|
||||
{
|
||||
shell.Navigate(SectionKey.Library);
|
||||
shell.Navigate(SectionKey.Settings);
|
||||
reload = settings.ArchiveReload;
|
||||
Assert.False(reload.IsCompleted, "the read is in flight");
|
||||
settings.FileTemplate.Text = edited;
|
||||
Assert.True(settings.FileTemplate.Commit());
|
||||
await Task.WhenAny(reload, Task.Delay(1500));
|
||||
Assert.False(reload.IsCompleted, "the read waits for the edit it overlapped");
|
||||
Assert.Equal(edited, settings.FileTemplate.Text);
|
||||
Assert.Equal(edited, shell.Services.Settings.FileTemplate);
|
||||
Assert.Equal(before, Read(paths.ManifestPath).LayoutTemplates.File);
|
||||
}
|
||||
finally
|
||||
{
|
||||
lease.Dispose();
|
||||
}
|
||||
|
||||
// Once the edit is written, the read is made again and shows it.
|
||||
await reload.WaitAsync(TimeSpan.FromSeconds(20));
|
||||
Assert.Equal(edited, Read(paths.ManifestPath).LayoutTemplates.File);
|
||||
Assert.Equal(edited, settings.FileTemplate.Text);
|
||||
Assert.Equal(edited, shell.Services.Settings.FileTemplate);
|
||||
});
|
||||
|
||||
[Test]
|
||||
public Task TheFirstRunDialogKeepsTheKeyboardInside() => ScreenHost.RunAsync(async () =>
|
||||
{
|
||||
await using var app = await ScreenSmokeTests.SampleApp.StartAsync();
|
||||
app.Shell.ShowWelcome();
|
||||
await app.ExpectAsync<WelcomeView>("welcome");
|
||||
|
||||
var welcome = app.FindAll<WelcomeView>().First(v => v.IsVisible);
|
||||
var dialog = (FrameworkElement)welcome.Content;
|
||||
Assert.Equal(KeyboardNavigationMode.Cycle, KeyboardNavigation.GetTabNavigation(dialog));
|
||||
Assert.Equal(KeyboardNavigationMode.Cycle, KeyboardNavigation.GetControlTabNavigation(dialog));
|
||||
Assert.Equal(KeyboardNavigationMode.Contained, KeyboardNavigation.GetDirectionalNavigation(dialog));
|
||||
// It opens with focus on the chosen card (a local archive by default).
|
||||
var focused = FocusManager.GetFocusedElement(Window.GetWindow(welcome)) as RadioButton;
|
||||
Assert.NotNull(focused, "a card has focus");
|
||||
Assert.True(focused.IsChecked == true && welcome.IsAncestorOf(focused), "the chosen card of the dialog has focus");
|
||||
// The logo is not mirrored in right-to-left languages.
|
||||
Assert.True(app.FindAll<Chronos.Ui.Controls.BrandMarkIcon>().Where(b => b.IsVisible).All(b => b.FlowDirection == FlowDirection.LeftToRight));
|
||||
app.Shell.CompleteWelcome();
|
||||
});
|
||||
|
||||
[Test]
|
||||
public Task ARightToLeftLanguageMirrorsEveryWindowAlsoThoseOpenedLater() => ScreenHost.RunAsync(async () =>
|
||||
{
|
||||
await using var app = await ScreenSmokeTests.SampleApp.StartAsync();
|
||||
app.Shell.About.SetResult(null);
|
||||
app.Shell.Navigate(SectionKey.About);
|
||||
await app.ExpectAsync<AboutView>("about");
|
||||
var main = Window.GetWindow(app.FindAll<AboutView>().First(v => v.IsVisible));
|
||||
Assert.Equal(FlowDirection.LeftToRight, main.FlowDirection);
|
||||
|
||||
UiLanguage.Apply("ar");
|
||||
var dialog = new Window
|
||||
{
|
||||
WindowStartupLocation = WindowStartupLocation.Manual,
|
||||
Left = -20000,
|
||||
Top = -20000,
|
||||
Width = 320,
|
||||
Height = 200,
|
||||
ShowActivated = false,
|
||||
ShowInTaskbar = false,
|
||||
};
|
||||
try
|
||||
{
|
||||
Assert.Equal(FlowDirection.RightToLeft, main.FlowDirection);
|
||||
// Loaded comes with the first render, which can follow an idle tick; class handlers run before this one.
|
||||
var loaded = new TaskCompletionSource();
|
||||
dialog.Loaded += (_, _) => loaded.TrySetResult();
|
||||
dialog.Show();
|
||||
await loaded.Task.WaitAsync(TimeSpan.FromSeconds(10));
|
||||
Assert.Equal(FlowDirection.RightToLeft, dialog.FlowDirection, "a window opened after the switch (a dialog) is mirrored too");
|
||||
await app.ExpectAsync<AboutView>("about-ar");
|
||||
|
||||
// Inside the mirrored window, paths and the logo keep their left-to-right order.
|
||||
var path = app.FindAll<TextBlock>().First(t => t.IsVisible && t.Text == app.Shell.About.DataFolder);
|
||||
Assert.Equal(FlowDirection.LeftToRight, path.FlowDirection);
|
||||
Assert.Equal(app.Shell.About.DataFolder, path.ToolTip);
|
||||
// The update result is a live region: screen readers hear each new state.
|
||||
var update = app.FindAll<Chronos.Ui.Controls.StatusGlyph>().First(g => g.IsVisible && g.Text == app.Shell.About.UpdateText);
|
||||
Assert.Equal(AutomationLiveSetting.Polite, AutomationProperties.GetLiveSetting(update));
|
||||
Assert.Equal(app.Shell.About.UpdateAnnouncement, AutomationProperties.GetName(update));
|
||||
}
|
||||
finally
|
||||
{
|
||||
dialog.Close();
|
||||
UiLanguage.Apply("en");
|
||||
}
|
||||
Assert.Equal(FlowDirection.LeftToRight, main.FlowDirection);
|
||||
});
|
||||
|
||||
/// <summary>Waits (on the UI thread, letting it run) until <paramref name="condition"/> holds.</summary>
|
||||
private static async Task WaitAsync(Func<bool> condition, string what)
|
||||
{
|
||||
var until = DateTime.UtcNow.AddSeconds(20);
|
||||
while (!condition())
|
||||
{
|
||||
Assert.True(DateTime.UtcNow < until, what);
|
||||
await Task.Delay(50);
|
||||
}
|
||||
}
|
||||
|
||||
private static TextBox Field(ScreenSmokeTests.SampleApp app, string name) =>
|
||||
app.FindAll<TextBox>().First(t => t.IsVisible && AutomationProperties.GetName(t) == name);
|
||||
|
||||
private static double Middle(FrameworkElement element) =>
|
||||
element.TranslatePoint(new Point(0, element.ActualHeight / 2), Window.GetWindow(element)).Y;
|
||||
|
||||
/// <summary>In every shipped language, the button <paramref name="find"/> returns lies inside its page's viewport (either reading direction).</summary>
|
||||
private static async Task InsidePageInEveryLanguageAsync(Window window, Func<Button> find)
|
||||
{
|
||||
try
|
||||
{
|
||||
foreach (var language in Languages.Shipped)
|
||||
{
|
||||
UiLanguage.Apply(language);
|
||||
window.UpdateLayout();
|
||||
await window.Dispatcher.InvokeAsync(() => { }, System.Windows.Threading.DispatcherPriority.ApplicationIdle);
|
||||
var button = find();
|
||||
var page = Ancestor<ScrollViewer>(button);
|
||||
var (left, right) = Span(page, page.ViewportWidth, window);
|
||||
var (start, end) = Span(button, button.ActualWidth, window);
|
||||
Assert.True(start >= left - 0.5 && end <= right + 0.5, $"{language}: '{button.Content}' spans {start:0}–{end:0} px, the page {left:0}–{right:0} px");
|
||||
}
|
||||
}
|
||||
finally
|
||||
{
|
||||
UiLanguage.Apply("en");
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>The left and right edges of the first <paramref name="width"/> pixels of an element in window coordinates.</summary>
|
||||
private static (double Left, double Right) Span(FrameworkElement element, double width, Window window)
|
||||
{
|
||||
var a = element.TranslatePoint(new Point(0, 0), window).X;
|
||||
var b = element.TranslatePoint(new Point(width, 0), window).X;
|
||||
return (Math.Min(a, b), Math.Max(a, b));
|
||||
}
|
||||
|
||||
/// <summary>The nearest <typeparamref name="T"/> above <paramref name="node"/>.</summary>
|
||||
private static T Ancestor<T>(DependencyObject node)
|
||||
where T : DependencyObject
|
||||
{
|
||||
for (var parent = VisualTreeHelper.GetParent(node); parent is not null; parent = VisualTreeHelper.GetParent(parent))
|
||||
{
|
||||
if (parent is T match) return match;
|
||||
}
|
||||
throw new InvalidOperationException($"No {typeof(T).Name} above {node}");
|
||||
}
|
||||
|
||||
/// <summary>The label of every visible Settings row (the first text of the row template).</summary>
|
||||
private static IEnumerable<TextBlock> Labels(ScreenSmokeTests.SampleApp app) =>
|
||||
app.FindAll<HeaderedContentControl>().Where(h => h.IsVisible).Select(h => Descendants<TextBlock>(h).First());
|
||||
|
||||
/// <summary>The label's text fits its width on one line, or wraps onto more lines; never trimmed.</summary>
|
||||
private static bool IsWhole(TextBlock label)
|
||||
{
|
||||
var probe = new TextBlock { Text = label.Text, FontFamily = label.FontFamily, FontSize = label.FontSize, FontWeight = label.FontWeight };
|
||||
probe.Measure(new Size(double.PositiveInfinity, double.PositiveInfinity));
|
||||
return label.TextTrimming == TextTrimming.None || probe.DesiredSize.Width <= label.ActualWidth + 0.5;
|
||||
}
|
||||
|
||||
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;
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user