CI / Build and test (push) Successful in 11m36s
CI / Windows tests and installer (push) Skipped
CI / YAML check (push) Successful in 12s
Release / Build, test and publish (push) Successful in 14m56s
CI / PostgreSQL 16 integration (push) Successful in 10m11s
CI / PostgreSQL 17 integration (push) Successful in 10m15s
CI / Docker image (push) Successful in 45s
Release / Server image (push) Successful in 4m55s
Co-authored-by: Alberto Balbo <alberto.balbo.96@gmail.com>
187 lines
9.5 KiB
C#
187 lines
9.5 KiB
C#
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;
|
||
|
||
/// <summary>The status line of a running job (owner review 5, #65): what it does now, in the job bar, the Jobs table and the tooltips.</summary>
|
||
public sealed class JobTextTests
|
||
{
|
||
private static readonly DateTimeOffset T0 = new(2026, 9, 28, 10, 0, 0, TimeSpan.Zero);
|
||
|
||
[Test]
|
||
public void TheStatusLineSaysStepItemAndPart()
|
||
{
|
||
Loc.SetCulture(CultureInfo.GetCultureInfo("en"));
|
||
var verify = new JobDetail(JobStep.Verify, "Harbour sunset", 812, 2_400, 3, 41, JobPartUnit.Sequence);
|
||
Assert.Equal("Verifying photo 812 of 2,400 · Harbour sunset · sequence 3 of 41", JobText.Status(verify));
|
||
// Not counted: the step word alone; a single part is not said.
|
||
Assert.Equal("Listing folders", JobText.Status(new JobDetail(JobStep.List)));
|
||
Assert.Equal("Encoding frame 10 of 300", JobText.Status(new JobDetail(JobStep.Encode, null, 10, 300, 1, 1, JobPartUnit.Render)));
|
||
// A part without a unit is counted plainly.
|
||
Assert.Equal("Analysing · Lake · 120 of 4,812", JobText.Status(new JobDetail(JobStep.Analyse, "Lake", Part: 120, Parts: 4_812)));
|
||
Assert.Equal(string.Empty, JobText.Status(null));
|
||
}
|
||
|
||
[Test]
|
||
public void EveryStepAndPartHasItsWordsInEnglishAndItalian()
|
||
{
|
||
foreach (var culture in new[] { "en", "it" })
|
||
{
|
||
var c = CultureInfo.GetCultureInfo(culture);
|
||
foreach (var step in Enum.GetValues<JobStep>().Where(s => s != JobStep.None))
|
||
Assert.True(Loc.Get("Jobs.Step." + step, c) is not null, $"{culture} {step}");
|
||
foreach (var unit in Enum.GetValues<JobPartUnit>().Where(u => u != JobPartUnit.None))
|
||
Assert.True(Loc.Get("Jobs.Part." + unit, c) is not null, $"{culture} {unit}");
|
||
foreach (var sub in new[] { "Leases", "Temp", "Packs", "Duplicates", "Vacuum" })
|
||
Assert.True(Loc.Get("Jobs.Maintenance.Step." + sub, c) is not null, $"{culture} {sub}");
|
||
}
|
||
}
|
||
|
||
|
||
[Test]
|
||
public void SubStepsNameThemselvesAndUnknownOnesShowCountsOnly()
|
||
{
|
||
Loc.SetCulture(CultureInfo.GetCultureInfo("en"));
|
||
Assert.Equal("Compacting thumbnails · step 3 of 5", JobText.Status(new JobDetail(JobStep.Maintenance, "packs", Part: 3, Parts: 5, PartUnit: JobPartUnit.Step)));
|
||
Assert.Equal("Job history", JobText.Status(new JobDetail(JobStep.Cleanup, "job-history")));
|
||
// A sub-step key of a newer server is never shown as text.
|
||
Assert.Equal("Maintenance · step 6 of 6", JobText.Status(new JobDetail(JobStep.Maintenance, "re-index", Part: 6, Parts: 6, PartUnit: JobPartUnit.Step)));
|
||
// A step this build does not know (JobStep.None from the wire) shows its counts and item only.
|
||
Assert.Equal("4 of 10 · Lake", JobText.Status(new JobDetail(JobStep.None, "Lake", 4, 10)));
|
||
Assert.Equal(JobStep.None, JobWire.FromDto(new Chronos.Protocol.JobDetailDto("teleport", "Lake", 4, 10))!.Step);
|
||
}
|
||
|
||
[Test]
|
||
public void FoldersStayLeftToRight()
|
||
{
|
||
Loc.SetCulture(CultureInfo.GetCultureInfo("en"));
|
||
var status = JobText.Status(new JobDetail(JobStep.Index, "2024/2024-09-27 Harbour", 1, 2));
|
||
Assert.Contains(Formatting.LeftToRight("2024/2024-09-27 Harbour"), status);
|
||
}
|
||
|
||
[Test]
|
||
public void ALongLineDropsTheItemFirstThenIsCut()
|
||
{
|
||
Loc.SetCulture(CultureInfo.GetCultureInfo("en"));
|
||
var detail = new JobDetail(JobStep.Verify, new string('x', 120), 812, 2_400, 3, 41, JobPartUnit.Sequence);
|
||
Assert.Equal("Verifying photo 812 of 2,400 · sequence 3 of 41", JobText.Status(detail, JobText.BarStatusLength));
|
||
var cut = JobText.Status(detail, 20);
|
||
Assert.Equal(20, cut.Length);
|
||
Assert.True(cut.EndsWith('…'));
|
||
// A cut folder island is closed again.
|
||
var folder = JobText.Status(new JobDetail(JobStep.Index, "2024/" + new string('y', 80)), 30);
|
||
Assert.Equal(folder.Count(c => c == ''), folder.Count(c => c == ''));
|
||
}
|
||
|
||
[Test]
|
||
public void TheBarSaysWhatTheJobDoesNow()
|
||
{
|
||
Loc.SetCulture(CultureInfo.GetCultureInfo("en"));
|
||
var job = Job(JobKind.Verify, JobState.Running, "Harbour sunset") with
|
||
{
|
||
Detail = new JobDetail(JobStep.Verify, "Harbour sunset", 812, 2_400, 3, 41, JobPartUnit.Sequence),
|
||
};
|
||
// The bar keeps 60 characters of the line: the item (already the target here) goes first.
|
||
var entry = new JobEntry(job);
|
||
Assert.Equal("Verify · Harbour sunset · Verifying photo 812 of 2,400 · sequence 3 of 41", JobText.Bar(entry));
|
||
|
||
// Without a detail the counter stays, in bytes for a byte job.
|
||
var bytes = new JobEntry(Job(JobKind.Import, JobState.Running, "Card") with { ProgressDone = 2_000_000, ProgressTotal = 8_000_000 });
|
||
Assert.Equal($"Import · Card · {Formatting.Bytes(2_000_000)} / {Formatting.Bytes(8_000_000)}", JobText.Bar(bytes));
|
||
Assert.Equal("3 / 9", JobText.Counter(JobKind.Scan, 3, 9));
|
||
}
|
||
|
||
[Test]
|
||
public void TheBarsTooltipHasTheLineWholeWithItsItem()
|
||
{
|
||
Loc.SetCulture(CultureInfo.GetCultureInfo("en"));
|
||
var job = Job(JobKind.Verify, JobState.Running, "Archive") with
|
||
{
|
||
Detail = new JobDetail(JobStep.Verify, "2024/2024-09-27 Harbour sunset at the old lighthouse", 812, 2_400, 3, 41, JobPartUnit.Sequence),
|
||
};
|
||
var entry = new JobEntry(job);
|
||
// The bar cuts the line at 60 characters, dropping the sequence first; the tooltip names it.
|
||
Assert.False(JobText.Bar(entry).Contains("Harbour sunset", StringComparison.Ordinal), JobText.Bar(entry));
|
||
Assert.Equal("Verify · Archive · " + JobText.Status(job.Detail), JobText.BarToolTip(entry));
|
||
Assert.Contains("Harbour sunset at the old lighthouse", JobText.BarToolTip(entry));
|
||
}
|
||
|
||
[Test]
|
||
public void LiveDetailWinsAndStoppedJobsSayWhere()
|
||
{
|
||
Loc.SetCulture(CultureInfo.GetCultureInfo("en"));
|
||
var job = Job(JobKind.Thumbs, JobState.Running, "Lake") with { Detail = new JobDetail(JobStep.Thumbs, "Lake", 1, 10) };
|
||
var entry = new JobEntry(job)
|
||
{
|
||
Live = new JobProgressInfo(job.Id, job.Kind, "Lake", 5, 10, 2.5, TimeSpan.FromMinutes(2), null, new JobDetail(JobStep.Thumbs, "Lake", 5, 10)),
|
||
};
|
||
Assert.Equal("Thumbnail 5 of 10 · Lake", JobText.RowStatus(entry));
|
||
Assert.Equal("Thumbnail 5 of 10 · Lake · 2.5 fps · 2 min left", JobText.RowStatusToolTip(entry));
|
||
|
||
var paused = new JobEntry(job with { State = JobState.Paused });
|
||
Assert.Equal("Stopped at Thumbnail 1 of 10 · Lake", JobText.RowStatus(paused));
|
||
Assert.Equal(string.Empty, JobText.RowStatus(new JobEntry(job with { State = JobState.Queued })));
|
||
Assert.Equal(string.Empty, JobText.RowStatus(new JobEntry(job with { State = JobState.Done })));
|
||
}
|
||
|
||
[Test]
|
||
public void RecentMaintenanceFollowsLiveProgress()
|
||
{
|
||
Loc.SetCulture(CultureInfo.GetCultureInfo("en"));
|
||
var verify = Job(JobKind.Verify, JobState.Running, "ChronosArchive") with { ProgressDone = 10, ProgressTotal = 100 };
|
||
var scan = Job(JobKind.Scan, JobState.Paused, "Archive") with { Detail = new JobDetail(JobStep.Index, null, 4, 9) };
|
||
var live = new Dictionary<Guid, JobProgressInfo>
|
||
{
|
||
[verify.Id] = new(verify.Id, verify.Kind, null, 71, 100, null, null, null, new JobDetail(JobStep.Verify, "Harbour sunset", 3, 9)),
|
||
// Progress of a job that is not running is not shown.
|
||
[scan.Id] = new(scan.Id, scan.Kind, null, 99, 100, null, null, null, new JobDetail(JobStep.Index, null, 8, 9)),
|
||
};
|
||
var recent = Chronos.App.Archiving.MaintenanceReports.Recent([verify, scan], 5, live);
|
||
var running = recent.Single(r => r.JobId == verify.Id);
|
||
Assert.Equal("71 %", running.StateText);
|
||
Assert.Equal("Verifying photo 3 of 9 · Harbour sunset", running.Detail);
|
||
Assert.True(running.HasDetail);
|
||
var paused = recent.Single(r => r.JobId == scan.Id);
|
||
Assert.Equal("Stopped at Indexing photo 4 of 9", paused.Detail);
|
||
// Without live progress the stored snapshot speaks.
|
||
Assert.Equal("10 %", Chronos.App.Archiving.MaintenanceReports.Recent([verify], 5).Single().StateText);
|
||
}
|
||
|
||
private static Job Job(JobKind kind, JobState state, string label) => new()
|
||
{
|
||
Id = Guid.CreateVersion7(),
|
||
Kind = kind,
|
||
State = state,
|
||
TargetLabel = label,
|
||
Created = T0,
|
||
Started = state == JobState.Queued ? null : T0,
|
||
};
|
||
}
|
||
|
||
/// <summary>The status line in Italian. It switches the process-wide UI language, so the class is serial.</summary>
|
||
[Serial]
|
||
public sealed class JobTextLanguageTests
|
||
{
|
||
[Test]
|
||
public void ItalianWordsTheSameLine()
|
||
{
|
||
Loc.SetCulture(CultureInfo.GetCultureInfo("it"));
|
||
try
|
||
{
|
||
var verify = new JobDetail(JobStep.Verify, "Tramonto", 812, 2_400, 3, 41, JobPartUnit.Sequence);
|
||
Assert.Equal($"Verifica foto 812 di {Formatting.Count(2_400)} · Tramonto · sequenza 3 di 41", JobText.Status(verify));
|
||
Assert.Equal("Elaborazione foto 5 di 9", JobText.Status(new JobDetail(JobStep.Process, null, 5, 9)));
|
||
Assert.Equal("Fermo a Miniatura 1 di 10", Loc.L("Jobs.Detail.StoppedAt", JobText.Status(new JobDetail(JobStep.Thumbs, null, 1, 10))));
|
||
}
|
||
finally
|
||
{
|
||
Loc.SetCulture(CultureInfo.GetCultureInfo("en"));
|
||
}
|
||
}
|
||
}
|