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>
70 lines
3.1 KiB
C#
70 lines
3.1 KiB
C#
using Khaemhat.Application.Search;
|
|
using Khaemhat.Application.Security;
|
|
using Khaemhat.Core.Security;
|
|
using Microsoft.Extensions.Logging.Abstractions;
|
|
|
|
namespace Khaemhat.Application.Tests;
|
|
|
|
/// <summary>The global search of SPEC §10.2 (issue #32, mockup 009).</summary>
|
|
[TestClass]
|
|
public sealed class GlobalSearchTests
|
|
{
|
|
private static readonly Actor Root = new("root", UserLevel.SuperUser, 1, null, null);
|
|
|
|
[TestMethod]
|
|
[DataRow(" fattura ", SearchScope.All, "fattura")]
|
|
[DataRow("> tema", SearchScope.Commands, "tema")]
|
|
[DataRow("#FT 12", SearchScope.Documents, "FT 12")]
|
|
[DataRow("@rossi", SearchScope.People, "rossi")]
|
|
[DataRow("", SearchScope.All, "")]
|
|
public void Query_ReadsThePrefix(string input, SearchScope scope, string text)
|
|
{
|
|
var query = SearchQuery.Parse(input);
|
|
Assert.AreEqual(scope, query.Scope);
|
|
Assert.AreEqual(text, query.Text);
|
|
}
|
|
|
|
[TestMethod]
|
|
public void Query_MatchesEveryWord_IgnoringCase()
|
|
{
|
|
var query = SearchQuery.Parse("iva liq");
|
|
Assert.IsTrue(query.Matches("Liquidazione IVA"));
|
|
Assert.IsFalse(query.Matches("Registri IVA"));
|
|
Assert.IsFalse(query.Matches(null));
|
|
Assert.IsTrue(SearchQuery.Parse(" ").Matches("qualsiasi"));
|
|
}
|
|
|
|
[TestMethod]
|
|
public async Task Search_AsksTheProvidersOfTheScope_AndLeavesOutTheOnesThatFail()
|
|
{
|
|
var search = new GlobalSearchService(
|
|
[new Provider([SearchScope.All], "Aiuto"), new Failing(), new Provider([SearchScope.All, SearchScope.Documents], "Documento")],
|
|
NullLogger<GlobalSearchService>.Instance);
|
|
|
|
var all = await search.SearchAsync(Root, SearchQuery.Parse("ab"));
|
|
Assert.HasCount(2 * GlobalSearchService.PerProvider, all);
|
|
CollectionAssert.AreEqual(new[] { "Aiuto ab", "Documento ab" }, all.Select(h => h.Title).Distinct().ToList());
|
|
CollectionAssert.AreEqual(new[] { "Documento ab" }, (await search.SearchAsync(Root, SearchQuery.Parse("#ab"))).Select(h => h.Title).Distinct().ToList());
|
|
Assert.IsEmpty(await search.SearchAsync(Root, SearchQuery.Parse("a")), "Too short.");
|
|
Assert.IsEmpty(await search.SearchAsync(Root, SearchQuery.Parse(">ab")), "Commands are not records.");
|
|
Assert.IsTrue(search.Covers(SearchScope.Documents));
|
|
Assert.IsFalse(search.Covers(SearchScope.People));
|
|
}
|
|
|
|
private sealed class Provider(SearchScope[] scopes, string title) : ISearchProvider
|
|
{
|
|
public IReadOnlyCollection<SearchScope> Scopes => scopes;
|
|
|
|
public Task<IReadOnlyList<SearchHit>> SearchAsync(Actor actor, SearchQuery query, CancellationToken cancellationToken) =>
|
|
Task.FromResult<IReadOnlyList<SearchHit>>([.. Enumerable.Range(0, 20).Select(i => new SearchHit("g", "file", title + " " + query.Text, null, "x"))]);
|
|
}
|
|
|
|
private sealed class Failing : ISearchProvider
|
|
{
|
|
public IReadOnlyCollection<SearchScope> Scopes => [SearchScope.All];
|
|
|
|
public Task<IReadOnlyList<SearchHit>> SearchAsync(Actor actor, SearchQuery query, CancellationToken cancellationToken) =>
|
|
throw new InvalidOperationException("broken");
|
|
}
|
|
}
|