Uploader: - Mirror the main window, the confirmation dialog and the tray menu for ar/he/fa/ur; keep paths, addresses, file names, the fingerprint, the brand mark and media glyphs left to right. - Queue rows take keyboard focus, are named "file · state" for screen readers, and Enter retries a failed file; a "✕ n failed" link jumps to the first failure; the list follows the upload near its top. - Focus moves into the settings panel (Tab cycles inside) and back to the gear, to Browse after sign-in and to the refused field after a failed one; activity changes and sign-in errors are announced. - A wrong address or password marks its field (error border, message in the tooltip); Retry only where it can help; session-ended toasts offer Sign in; the form stays visible while its own sign-in runs. - Watch chips and the add button wrap and shorten long paths; target choices wrap with their fields; the settings panel uses the side-panel width with wrapping labels; disabled controls say why. - The window opens at 760x700 (min 630 high) so the per-file list shows five rows; --capture adds an Arabic pass. Setup: - Every stage has a default and a cancel button (safe action first), the keyboard moves to the new default and outcomes are announced; the title-bar Close is disabled while files are written. - "Remove my data" measures the user data folder and shows the plan (largest entries, total) before Uninstall can run; the tooltip names backups and the uploader queue. - Folder field before Browse in Tab order; paths and file names left to right; disabled tooltips say why. Both: byte units come from the language (Common.Size.*). Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_012iLMBNwBE2GnphAsu4cjaC
141 lines
5.6 KiB
C#
141 lines
5.6 KiB
C#
using System.Globalization;
|
|
using Titano.Testing;
|
|
using Titano.Uploader.Text;
|
|
using Titano.Uploader.Uploads;
|
|
|
|
namespace Titano.App.Tests.Uploader;
|
|
|
|
public sealed class UploaderTextTests
|
|
{
|
|
private static readonly CultureInfo En = CultureInfo.GetCultureInfo("en");
|
|
private static readonly CultureInfo It = CultureInfo.GetCultureInfo("it");
|
|
|
|
private static readonly QueueSummary Mockup = new(4_812, 96_200_000_000, 2_214, 2_201, 0, 0, 44_000_000_000, "2026-09-28_18-02-11_0413.CR2")
|
|
{
|
|
RemainingBytes = 93_480_000_000,
|
|
};
|
|
|
|
[Test]
|
|
public void QueueLineMatchesTheMockup()
|
|
{
|
|
var left = RateMeter.TimeLeft(Mockup.RemainingBytes, 38_000_000);
|
|
Assert.Equal("4,812 files · 96.2 GB · 38 MB/s · 41 min left", UploaderText.QueueLine(Mockup, QueueActivity.Running, 38_000_000, left, En));
|
|
}
|
|
|
|
[Test]
|
|
public void QueueLineFollowsTheCulture()
|
|
{
|
|
Assert.Equal("4.812 file · 96,2 GB · 38 MB/s · mancano 41 min", UploaderText.QueueLine(Mockup, QueueActivity.Running, 38_000_000, TimeSpan.FromMinutes(41), It));
|
|
}
|
|
|
|
[Test]
|
|
public void QueueLineNamesTheActivityWhenNotRunning()
|
|
{
|
|
Assert.Equal("4,812 files · 96.2 GB · Paused", UploaderText.QueueLine(Mockup, QueueActivity.Paused, 0, null, En));
|
|
Assert.Equal("4,812 files · 96.2 GB · Waiting for server", UploaderText.QueueLine(Mockup, QueueActivity.WaitingForServer, 0, null, En));
|
|
Assert.Equal("1 file · 25 MB · Done", UploaderText.QueueLine(Mockup with { Files = 1, Bytes = 25_000_000 }, QueueActivity.Done, 0, null, En));
|
|
Assert.Equal("Nothing queued", UploaderText.QueueLine(default, QueueActivity.Idle, 0, null, En));
|
|
}
|
|
|
|
[Test]
|
|
public void RunningLineOmitsRateAndTimeUntilKnown()
|
|
{
|
|
Assert.Equal("4,812 files · 96.2 GB", UploaderText.QueueLine(Mockup, QueueActivity.Running, 0, null, En));
|
|
}
|
|
|
|
[Test]
|
|
public void ProgressLineMatchesTheMockup()
|
|
{
|
|
Assert.Equal("2,214 of 4,812 sent · 2,201 verified by the server · 0 retries", UploaderText.ProgressLine(Mockup, En));
|
|
Assert.Equal("2,214 of 4,812 sent · 2,201 verified by the server · 1 retry", UploaderText.ProgressLine(Mockup with { Retries = 1, Failed = 3 }, En));
|
|
}
|
|
|
|
[Test]
|
|
public void FailuresHaveTheirOwnTextOnlyWhenThereAreAny()
|
|
{
|
|
Assert.Null(UploaderText.Failed(Mockup, En));
|
|
Assert.Equal("1,203 failed", UploaderText.Failed(Mockup with { Failed = 1_203 }, En));
|
|
Assert.Equal("3 non riusciti", UploaderText.Failed(Mockup with { Failed = 3 }, It));
|
|
}
|
|
|
|
[Test]
|
|
public void SizeUnitsFollowTheLanguage()
|
|
{
|
|
Assert.Equal("999 byte", UploaderText.Bytes(999, It));
|
|
Assert.Equal("1,5 KB", UploaderText.Bytes(1_536, It));
|
|
Assert.Equal("4,2 MB/s", UploaderText.Rate(4_240_000, It));
|
|
}
|
|
|
|
[Theory]
|
|
[Case(0.0, "0 B/s")]
|
|
[Case(950_000.0, "950 KB/s")]
|
|
[Case(4_240_000.0, "4.2 MB/s")]
|
|
[Case(38_400_000.0, "38 MB/s")]
|
|
[Case(1_260_000_000.0, "1.3 GB/s")]
|
|
public void RatesUseDecimalUnits(double bytesPerSecond, string expected) =>
|
|
Assert.Equal(expected, UploaderText.Rate(bytesPerSecond, En));
|
|
|
|
[Theory]
|
|
[Case(40.0, "40 s")]
|
|
[Case(299.0, "5 min")]
|
|
[Case(3_590.0, "1 h 00 m")]
|
|
[Case(7_500.0, "2 h 05 m")]
|
|
[Case(93_600.0, "1 d 2 h")]
|
|
public void DurationsAreCompact(double seconds, string expected) =>
|
|
Assert.Equal(expected, UploaderText.Duration(TimeSpan.FromSeconds(seconds), En));
|
|
|
|
[Theory]
|
|
[Case(999L, "999 B")]
|
|
[Case(1_536L, "1.5 KB")]
|
|
[Case(96_200_000_000L, "96.2 GB")]
|
|
[Case(1_900_000_000_000L, "1.9 TB")]
|
|
public void SizesUseDecimalUnits(long bytes, string expected) => Assert.Equal(expected, UploaderText.Bytes(bytes, En));
|
|
|
|
[Test]
|
|
public void TimeLeftNeedsAUsableRate()
|
|
{
|
|
Assert.Equal(TimeSpan.FromMinutes(41), RateMeter.TimeLeft(93_480_000_000, 38_000_000));
|
|
Assert.Equal(TimeSpan.Zero, RateMeter.TimeLeft(0, 0));
|
|
Assert.Null(RateMeter.TimeLeft(1_000, 10));
|
|
}
|
|
|
|
[Test]
|
|
public void RateMeterAveragesTheWindowAndDecaysWhenStalled()
|
|
{
|
|
var meter = new RateMeter(TimeSpan.FromSeconds(10));
|
|
Assert.Equal(0.0, meter.BytesPerSecond(TimeSpan.Zero));
|
|
for (var s = 0; s <= 20; s++) meter.Add(4_000_000, TimeSpan.FromSeconds(s));
|
|
Assert.Approximately(4_000_000, meter.BytesPerSecond(TimeSpan.FromSeconds(20)), 1);
|
|
// Nothing sent for 20 s: the window holds no transfer any more.
|
|
Assert.Equal(0.0, meter.BytesPerSecond(TimeSpan.FromSeconds(40)));
|
|
meter.Reset();
|
|
Assert.Equal(0.0, meter.BytesPerSecond(TimeSpan.FromSeconds(40)));
|
|
}
|
|
|
|
[Test]
|
|
public void SummaryCountsStatesAndBytes()
|
|
{
|
|
var queue = new UploadQueue();
|
|
queue.Add(new UploadBatch { Id = Guid.CreateVersion7(), Mode = UploadTargetMode.Sessions },
|
|
Enumerable.Range(0, 5).Select(i => new QueueEntry($"{i}.jpg", 100, DateTime.UtcNow, null, null, null)));
|
|
queue.Items[0].State = UploadItemState.Verified;
|
|
queue.Items[1].State = UploadItemState.Skipped;
|
|
queue.Items[2].State = UploadItemState.Uploading;
|
|
queue.Items[2].BytesSent = 40;
|
|
queue.Items[3].State = UploadItemState.Failed;
|
|
queue.Items[3].Retries = 1;
|
|
|
|
var s = QueueSummary.From(queue.Items);
|
|
Assert.Equal(5, s.Files);
|
|
Assert.Equal(500L, s.Bytes);
|
|
Assert.Equal(2, s.Sent);
|
|
Assert.Equal(2, s.Verified);
|
|
Assert.Equal(1, s.Failed);
|
|
Assert.Equal(1, s.Retries);
|
|
Assert.Equal(240L, s.DoneBytes);
|
|
Assert.Equal(160L, s.RemainingBytes);
|
|
Assert.Equal("2.jpg", s.CurrentFile);
|
|
Assert.Approximately(0.48, s.Progress, 1e-9);
|
|
}
|
|
}
|