F1 and "?" now open the wiki page of the screen inside the application (/aiuto, mockup 011) from a copy of the wiki shipped next to the program, so help works offline and always matches the installed version. Markdown is converted in-house and fully encoded; images of the repository are served from the copy. KHAEMHAT_HELP_URL sets the online wiki behind "Apri nel wiki"; "Segnala un problema" opens a new issue of that repo. A test checks that every page and menu entry has an existing wiki page. The bell opens a notifications panel (mockup 010) with all/unread filters and mark read. Broadcast notifications are now read per user through sys_notification_reads / notification_reads instead of one shared read_at. The global search asks ISearchProvider implementations through GlobalSearchService after a short pause; the first provider finds help pages and sections, # and @ say which modules will fill them. Escape also closes a side panel when the focus fell out of it. Decisions in ADR 0023. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
71 lines
4.1 KiB
C#
71 lines
4.1 KiB
C#
using Khaemhat.Application.Modules;
|
|
using Khaemhat.Application.Notifications;
|
|
using Khaemhat.Application.Security;
|
|
using Khaemhat.Core.Instance;
|
|
using Khaemhat.Core.Security;
|
|
using Khaemhat.Web.Tests.Hosting;
|
|
using Microsoft.Extensions.DependencyInjection;
|
|
|
|
namespace Khaemhat.Web.Tests.Shell;
|
|
|
|
/// <summary>The notification panel of mockup 010 (issue #32): what each user reads is kept per user.</summary>
|
|
[TestClass]
|
|
public sealed class NotificationInboxTests
|
|
{
|
|
private const string Category = "test";
|
|
|
|
[TestMethod]
|
|
public async Task ANotificationForEveryone_IsReadByEachUserSeparately()
|
|
{
|
|
var (app, _, company) = await TestInstance.StartAsync(CancellationToken.None);
|
|
await using (app)
|
|
{
|
|
var notifications = app.Services.GetRequiredService<NotificationDispatcher>();
|
|
var users = app.Services.GetRequiredService<UserService>();
|
|
var root = new Actor(TestInstance.SuperUser, UserLevel.SuperUser, 1, null, null);
|
|
var (anna, _) = await users.CreateAsync(root, company, new NewCompanyUser("anna", "Anna Verdi", null, UserKind.Human, [PredefinedRoles.ReadOnly], new UserFlags(false, false, false, false)));
|
|
var (luca, _) = await users.CreateAsync(root, company, new NewCompanyUser("luca", "Luca Neri", null, UserKind.Human, [PredefinedRoles.ReadOnly], new UserFlags(false, false, false, false)));
|
|
var annaActor = new Actor("anna", UserLevel.Standard, null, anna.Id, company);
|
|
var lucaActor = new Actor("luca", UserLevel.Standard, null, luca.Id, company);
|
|
|
|
await notifications.NotifyCompanyAsync(company, new NotificationMessage(Category, NotificationSeverity.Info, "Per tutti"));
|
|
await notifications.NotifyCompanyAsync(company, new NotificationMessage(Category, NotificationSeverity.Warning, "Solo per Anna", "Dettaglio", "/profilo"), anna.Id);
|
|
|
|
var annaInbox = await Inbox(annaActor);
|
|
CollectionAssert.AreEqual(new[] { "Solo per Anna", "Per tutti" }, annaInbox.Select(n => n.Title).ToList(), "Newest first.");
|
|
Assert.IsTrue(annaInbox[0].Personal);
|
|
Assert.AreEqual("/profilo", annaInbox[0].Link);
|
|
Assert.IsTrue(annaInbox.All(n => !n.Read));
|
|
CollectionAssert.AreEqual(new[] { "Per tutti" }, (await Inbox(lucaActor)).Select(n => n.Title).ToList(), "Personal notifications stay personal.");
|
|
|
|
// Anna reads the one for everyone: it stays unread for Luca; reading it again changes nothing.
|
|
var everyone = annaInbox[1].Id;
|
|
await notifications.MarkReadAsync(annaActor, everyone);
|
|
await notifications.MarkReadAsync(annaActor, everyone);
|
|
Assert.IsTrue((await Inbox(annaActor)).Single(n => n.Id == everyone).Read);
|
|
Assert.IsFalse((await Inbox(lucaActor)).Single(n => n.Id == everyone).Read);
|
|
|
|
// Nobody marks someone else's notification.
|
|
await notifications.MarkReadAsync(lucaActor, annaInbox[0].Id);
|
|
Assert.IsFalse((await Inbox(annaActor)).Single(n => n.Id == annaInbox[0].Id).Read);
|
|
|
|
// "Segna tutte come lette" is for the user only.
|
|
await notifications.MarkAllReadAsync(annaActor);
|
|
Assert.IsEmpty(await Inbox(annaActor, unreadOnly: true));
|
|
Assert.HasCount(1, await Inbox(lucaActor, unreadOnly: true));
|
|
|
|
// Instance accounts read the notifications of the system.
|
|
await notifications.NotifyInstanceAsync(new NotificationMessage(Category, NotificationSeverity.Error, "Backup non riuscito"));
|
|
var system = await Inbox(root, unreadOnly: true);
|
|
Assert.AreEqual("Backup non riuscito", system.Single().Title);
|
|
Assert.IsFalse((await Inbox(annaActor)).Any(n => n.Title == "Backup non riuscito"));
|
|
await notifications.MarkAllReadAsync(root);
|
|
Assert.IsEmpty(await Inbox(root, unreadOnly: true));
|
|
await app.StopAsync();
|
|
|
|
async Task<List<InboxItem>> Inbox(Actor actor, bool unreadOnly = false) =>
|
|
[.. (await notifications.InboxAsync(actor, unreadOnly)).Where(n => n.Category == Category)];
|
|
}
|
|
}
|
|
}
|