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>
61 lines
3.5 KiB
C#
61 lines
3.5 KiB
C#
using System.Net.Http.Json;
|
|
using System.Text.RegularExpressions;
|
|
using Chronos.Core.Model;
|
|
using Chronos.Data.Jobs;
|
|
using Chronos.Protocol;
|
|
using Chronos.Testing;
|
|
|
|
namespace Chronos.Server.Tests.Hosting;
|
|
|
|
/// <summary>
|
|
/// What a job does now in the admin panel (owner review 5, #65; <c>Admin/web/jobs.js</c>): the Jobs page and the dashboard
|
|
/// draw the status line under the target and move it with every progress event, and every step, part and sub-step the
|
|
/// server can send is worded in English and Italian.
|
|
/// </summary>
|
|
[Category("server")]
|
|
public sealed class AdminJobDetailTests(TestContext context)
|
|
{
|
|
private static readonly string[] MaintenanceSteps = ["Leases", "Temp", "Packs", "Duplicates", "Vacuum"];
|
|
|
|
[Test]
|
|
public async Task TheJobsPageAndTheDashboardShowTheStatusLine()
|
|
{
|
|
await using var server = await TestServer.StartAsync(context);
|
|
var jobs = await server.Client.GetStringAsync("/admin/jobs.js");
|
|
foreach (var helper in new[] { "statusText(detail)", "rowStatus(job)", "speedText(kind, rate)", "leftText(seconds)", "targetCell(job)", "statusLine(job)", "updateStatus(row, job)" })
|
|
Assert.Contains($"export function {helper}", jobs);
|
|
// Items are data: they read in their own direction, and the whole line is the tooltip.
|
|
Assert.Contains(@"<span class=""progress-detail"" dir=""auto"" title=""${attr(tip)}"">", jobs);
|
|
foreach (var page in new[] { "/admin/pages/jobs.js", "/admin/pages/dashboard.js" })
|
|
{
|
|
var text = await server.Client.GetStringAsync(page);
|
|
Assert.Contains(@"<span class=""target-cell"" role=""cell"">${targetCell(j)}</span>", text);
|
|
Assert.Contains("if (e.detail) job.detail = e.detail;", text);
|
|
Assert.Contains("updateStatus(row, job);", text);
|
|
Assert.True(!text.Contains(" style=", StringComparison.Ordinal), "inline style");
|
|
}
|
|
Assert.Contains(".progress-detail {", await server.Client.GetStringAsync("/admin/admin.css"));
|
|
}
|
|
|
|
[Test]
|
|
public async Task EveryStepAndPartIsInEnglishAndItalian()
|
|
{
|
|
await using var server = await TestServer.StartAsync(context);
|
|
var jobs = await server.Client.GetStringAsync("/admin/jobs.js");
|
|
var en = Assert.NotNull(await server.Client.GetFromJsonAsync("/api/v1/i18n/en", ProtocolJson.Default.DictionaryStringString));
|
|
var it = Assert.NotNull(await server.Client.GetFromJsonAsync("/api/v1/i18n/it", ProtocolJson.Default.DictionaryStringString));
|
|
var keys = Regex.Matches(jobs, @"""(Admin\.[A-Za-z]+(?:\.[A-Za-z]+)*)""").Select(m => m.Groups[1].Value).ToList();
|
|
Assert.Contains("Admin.Job.Detail.StoppedAt", keys);
|
|
// The keys built from what the server sends.
|
|
keys.AddRange(Enum.GetValues<JobStep>().Where(s => s != JobStep.None).Select(s => $"Admin.Job.Step.{s}"));
|
|
keys.AddRange(Enum.GetValues<JobPartUnit>().Where(u => u != JobPartUnit.None).Select(u => $"Admin.Job.Part.{u}"));
|
|
keys.AddRange(MaintenanceSteps.Select(s => $"Admin.Job.Maintenance.Step.{s}"));
|
|
foreach (var key in keys.Distinct())
|
|
Assert.True(en.ContainsKey(key) && it.ContainsKey(key), key);
|
|
// The step and the unit keys are the wire names in PascalCase, as the panel builds them.
|
|
Assert.Equal("copy-photo", JobWire.Step(JobStep.CopyPhoto));
|
|
Assert.Equal("Copia foto {0} di {1}", it["Admin.Job.Step.CopyPhoto.Count"]);
|
|
Assert.Equal("Verifying photo {0} of {1}", en["Admin.Job.Step.Verify.Count"]);
|
|
}
|
|
}
|