Files
Chronos/tests/Chronos.App.Tests/Jobs/ScheduleLanguageTests.cs
T
Alby96 5cb6809fd0 fix(app): keep Jobs › Scheduled true to the scheduler
Owner review 2, phase 2 (R10) review findings on the desktop:

- Showing the Scheduled tab (and coming back to Jobs on it) reads the
  actions' availability again, as does a Run now answered unavailable;
  rows and an open editor follow, so turning proxies on no longer needs a
  restart.
- A delete the index refuses keeps the row: the failed call no longer
  reads as Deleted (the enum's default), so a live schedule never leaves
  the page.
- SchedulerReady completes false when the index (or the engine) does not
  open, so the tab shows that the schedules do not run instead of an
  empty panel.
- A read of a schedule's last job that started before a live change or a
  later read is ignored, so a finished job no longer shows as running.
- The editor's Action, Unit and Priority dropdowns follow a language
  change, keeping what was chosen.
- Weekly days in the table read from the UI language's first day, as the
  editor's toggles do.
- Backup tooltips no longer promise daily copies with three kept (their
  translations are dropped for retranslation); two tooltips now name the
  real Settings rows (Proxy size; Spazio su disco › Limite della cache).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
(cherry picked from commit c137e2c74cddef299b2e4179ef0417fa4977953c)
2026-10-27 09:58:09 +01:00

80 lines
4.3 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.Globalization;
using Chronos.App.Jobs;
using Chronos.Core.Localization;
using Chronos.Core.Model;
using Chronos.Data.Scheduling;
using Chronos.Protocol;
using Chronos.Testing;
namespace Chronos.App.Tests.Jobs;
/// <summary>
/// Jobs › Scheduled in another language (owner review 2, R10). These switch the process-wide UI language, so the class is
/// serial: in parallel it would race with the English assertions of the classes running beside it.
/// </summary>
[Serial]
public sealed class ScheduleLanguageTests(TestContext context)
{
/// <summary>The days of a weekly schedule read in the order of the editor's toggles: from the UI language's first day.</summary>
[Test]
public void WeeklyDaysFollowTheWeekOfTheUiLanguage()
{
var weekend = ScheduleRecurrence.WeeklyAt([DayOfWeek.Saturday, DayOfWeek.Sunday], new TimeOnly(3, 0));
try
{
Loc.SetCulture(CultureInfo.GetCultureInfo("en"));
Assert.Equal(DayOfWeek.Sunday, Loc.Culture.DateTimeFormat.FirstDayOfWeek);
Assert.Equal(Loc.L("Jobs.Schedule.DayList", ScheduleText.DayShort(DayOfWeek.Sunday), ScheduleText.DayShort(DayOfWeek.Saturday)),
ScheduleText.Days(weekend.Days));
Assert.Equal(Loc.L("Jobs.Schedule.When.Weekly", ScheduleText.Days(weekend.Days), ScheduleText.Time(new TimeOnly(3, 0))), ScheduleText.When(weekend));
Loc.SetCulture(CultureInfo.GetCultureInfo("it"));
Assert.Equal(DayOfWeek.Monday, Loc.Culture.DateTimeFormat.FirstDayOfWeek);
Assert.Equal(Loc.L("Jobs.Schedule.DayList", ScheduleText.DayShort(DayOfWeek.Saturday), ScheduleText.DayShort(DayOfWeek.Sunday)),
ScheduleText.Days(weekend.Days));
Assert.Equal(Loc.L("Jobs.Schedule.DayList", ScheduleText.DayShort(DayOfWeek.Monday), ScheduleText.DayShort(DayOfWeek.Thursday)),
ScheduleText.Days([DayOfWeek.Thursday, DayOfWeek.Monday]));
}
finally
{
Loc.SetCulture(CultureInfo.GetCultureInfo("en"));
}
}
/// <summary>The editor's dropdowns say their choices in the new language, and keep what was chosen.</summary>
[Test]
public async Task TheOpenEditorSaysItsChoicesInTheNewLanguage()
{
Loc.SetCulture(CultureInfo.GetCultureInfo("en"));
await using var fx = await ScheduleFixture.CreateAsync(context);
using var vm = await fx.ViewModelAsync();
vm.NewCommand.Execute(null);
var editor = Assert.NotNull(vm.Editor);
editor.SelectedAction = editor.ActionOptions.Single(a => a.Name == ScheduleActions.Verify);
editor.SelectedUnit = editor.Units.Single(u => u.Value == RecurrenceUnit.Minutes);
editor.SelectedPriority = editor.Priorities.Single(p => p.Value == JobPriority.Normal);
Assert.Equal(("minutes", "Normal"), (editor.SelectedUnit.Label, editor.SelectedPriority.Label));
var actions = editor.ActionOptions;
try
{
Loc.SetCulture(CultureInfo.GetCultureInfo("it"));
Assert.SequenceEqual(Enum.GetValues<RecurrenceUnit>().Select(u => Loc.L("Jobs.Editor.Unit." + u)), editor.Units.Select(u => u.Label));
Assert.SequenceEqual(["In background", "Normale", "Alta"], editor.Priorities.Select(p => p.Label));
Assert.Equal((RecurrenceUnit.Minutes, "minuti"), (editor.SelectedUnit.Value, editor.SelectedUnit.Label));
Assert.Equal((JobPriority.Normal, "Normale"), (editor.SelectedPriority.Value, editor.SelectedPriority.Label));
Assert.True(editor.Units.Any(u => ReferenceEquals(u, editor.SelectedUnit)) && editor.Priorities.Any(p => ReferenceEquals(p, editor.SelectedPriority)),
"the choices are among the new options");
// The actions are new options too, so their dropdown reads their names again.
Assert.False(ReferenceEquals(actions, editor.ActionOptions), "the action list was built again");
Assert.Equal(("Scansione archivio", ScheduleActions.Verify), (editor.ActionOptions[0].Label, editor.SelectedAction.Name));
Assert.True(editor.ActionOptions.Any(o => ReferenceEquals(o, editor.SelectedAction)), "the action is among the new options");
}
finally
{
Loc.SetCulture(CultureInfo.GetCultureInfo("en"));
}
}
}