Panoramica now follows mockup 01. Below "Finora" and "Adesso e dopo" it shows: - the two account cards with the invested/cash bar and a 30-day trend; - the four risk limits; - the open positions by value; - the strategies; - the news, learning and system tiles. On the phone it follows mockup 09: Conti as a list, four positions with "Vedi le altre", and two limits. Outside the demo, news and learning say they are not active yet (Phases 7 and 8). The next moves are the scheduler's moves only, no longer every interval job. Diario e sistema follows mockup 08: - the diary grouped by day, with search and filter chips (plain links, no JavaScript) and older days on request; - how each component is doing; - the scheduled jobs; - the host's processor, memory and disk; - the technical logs as a zip, for signed-in users only. In demo mode the screens show the values of appendix F.10. Tests cover the demo figures, the filters and search, and the logs download. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
163 lines
9.0 KiB
C#
163 lines
9.0 KiB
C#
using System.IO.Compression;
|
||
using System.Net;
|
||
using Anubis.Server;
|
||
using Anubis.Trading;
|
||
|
||
namespace Anubis.Tests;
|
||
|
||
/// <summary>The Panoramica and "Diario e sistema" screens (issue #51, mockups 01, 08 and 09).</summary>
|
||
[TestClass]
|
||
public sealed class OverviewScreenTests
|
||
{
|
||
[TestMethod]
|
||
[TestCategory(Category.Integration)]
|
||
public async Task TheDemoPanoramicaShowsAccountsPositionsAndLimits()
|
||
{
|
||
var server = await ServerHarness.StartAsync("docker", ServerHarness.DockerSqlite(), extraArgs: ["--demo"]);
|
||
var demoRoot = server.Host.Config.Data.Root;
|
||
try
|
||
{
|
||
var page = await server.TextAsync("/");
|
||
foreach (var text in new[]
|
||
{
|
||
// Adesso e dopo (F.10).
|
||
"Prossima decisione tra 7 ore e 14 minuti, all'apertura di Wall Street.", "Rimetto gli stop del giorno sulle frazioni di 6 azioni",
|
||
"Alzato lo stop di BTC a 66.180", "Apri il diario completo", "Tutte le mosse e il diario",
|
||
// The two accounts with their last 30 days (F.2).
|
||
"4.231,60", "+231,60", "2.326,50", "1.905,10", "+158,20", "3 posizioni, 3 stop attivi.",
|
||
"6.180,86", "4.344,63", "1.836,23", "+93,50", "sulle frazioni tornano alle 15:35",
|
||
// The four limits (F.10).
|
||
"Tutti i limiti rispettati", "Perdita di oggi", "nessuna", "−2,00%", "Calo dal massimo", "−15,00%", "Capitale investito", "64,1%",
|
||
"Posizione più grande (BTC)", "12,5%", "La tacca segna il calo peggiore finora: −2,82%.", "Vedi tutti i limiti",
|
||
// Positions by value, strategies, news, model, system.
|
||
"BTC/EUR", "1.299,84", "66.180", "(−7,3%)", "Vedi le altre 6",
|
||
"In simulazione, giorno 58 di 60", "In simulazione, 21 operazioni su 30", "1 posizione aperta, 21 operazioni chiuse (10 in guadagno)",
|
||
"Nessuna strategia usa soldi veri.",
|
||
"Rinviato di una settimana l'aggiornamento della rete Solana", "Negativa: per 24 ore non aumento SOL",
|
||
"Il modello osserva e impara, ma non decide ancora.", "domenica 11 ottobre, 03:00",
|
||
"connesso, 84 ms", "PostgreSQL, 1,8 GB", "ultimo messaggio alle 08:00",
|
||
})
|
||
{
|
||
StringAssert.Contains(page, text, $"Missing «{text}» on the Panoramica.");
|
||
}
|
||
|
||
Assert.IsLessThan(page.IndexOf("ETH/EUR", StringComparison.Ordinal), page.IndexOf("BTC/EUR", StringComparison.Ordinal), "Positions in order of value.");
|
||
}
|
||
finally
|
||
{
|
||
await server.DisposeAsync();
|
||
TempFolder.Delete(demoRoot);
|
||
}
|
||
}
|
||
|
||
[TestMethod]
|
||
[TestCategory(Category.Integration)]
|
||
public async Task TheDiaryFiltersAndSearches()
|
||
{
|
||
var server = await ServerHarness.StartAsync("docker", ServerHarness.DockerSqlite(), extraArgs: ["--demo"]);
|
||
var demoRoot = server.Host.Config.Data.Root;
|
||
try
|
||
{
|
||
var all = await server.TextAsync("/diario");
|
||
StringAssert.Contains(all, "Oggi, venerdì 9 ottobre");
|
||
StringAssert.Contains(all, "Ieri, giovedì 8 ottobre");
|
||
StringAssert.Contains(all, "Ho cambiato una regola per 24 ore:");
|
||
StringAssert.Contains(all, "Motivo: l'aggiornamento della rete Solana è stato rinviato di una settimana.");
|
||
StringAssert.Contains(all, "href=\"/operazioni?cerca=MSFT\"");
|
||
StringAssert.Contains(all, "Perché l'ho comprata e venduta");
|
||
Assert.IsFalse(all.Contains("(con il collegamento", StringComparison.Ordinal), "The demo's note on the link is not shown.");
|
||
StringAssert.Contains(all, "Tutto regolare");
|
||
StringAssert.Contains(all, "collegato, mercato chiuso fino alle 15:30");
|
||
StringAssert.Contains(all, "Dom 03:00");
|
||
StringAssert.Contains(all, "Anubis 0.9.2 in Docker, acceso dal 12 agosto: 58 giorni senza interruzioni.");
|
||
|
||
// A kind at a time.
|
||
var orders = await server.TextAsync("/diario?tipo=ordini");
|
||
StringAssert.Contains(orders, "Alzato lo stop di BTC/EUR");
|
||
Assert.IsFalse(orders.Contains("Inviato il riepilogo del mattino", StringComparison.Ordinal));
|
||
Assert.IsFalse(orders.Contains("Controllo del modello: nessuna anomalia.", StringComparison.Ordinal));
|
||
StringAssert.Contains(await server.TextAsync("/diario?tipo=rischio"), "Nessuna voce di questo tipo finora.");
|
||
|
||
// The search ignores case and accents, and keeps the kind chosen.
|
||
var search = await server.TextAsync("/diario?cerca=MARTEDI");
|
||
StringAssert.Contains(search, "Ho messo una restrizione fino a martedì:");
|
||
Assert.IsFalse(search.Contains("Alzato lo stop", StringComparison.Ordinal));
|
||
StringAssert.Contains(search, "Una voce con «MARTEDI»");
|
||
var none = await server.TextAsync("/diario?tipo=ordini&cerca=solana");
|
||
StringAssert.Contains(none, "Nessuna voce con «solana»");
|
||
}
|
||
finally
|
||
{
|
||
await server.DisposeAsync();
|
||
TempFolder.Delete(demoRoot);
|
||
}
|
||
}
|
||
|
||
[TestMethod]
|
||
[TestCategory(Category.Integration)]
|
||
public async Task TheLogsDownloadNeedsASessionAndIsAZip()
|
||
{
|
||
await using var server = await ServerHarness.StartAsync("docker", ServerHarness.DockerSqlite());
|
||
var logs = server.Host.Config.Data.Logs;
|
||
Directory.CreateDirectory(logs);
|
||
await File.WriteAllTextAsync(Path.Combine(logs, "anubis-2099-01-01.log"), "{\"message\":\"una riga\"}\n");
|
||
await File.WriteAllTextAsync(Path.Combine(logs, "altro.txt"), "non è un registro");
|
||
|
||
using (var anonymous = await server.GetAsync("/api/registri.zip"))
|
||
{
|
||
Assert.AreEqual(HttpStatusCode.Unauthorized, anonymous.StatusCode);
|
||
}
|
||
|
||
await server.SignInFirstTimeAsync();
|
||
using (var zip = await server.GetAsync("/api/registri.zip"))
|
||
{
|
||
Assert.AreEqual(HttpStatusCode.OK, zip.StatusCode);
|
||
Assert.AreEqual("application/zip", zip.Content.Headers.ContentType?.MediaType);
|
||
await using var stream = await zip.Content.ReadAsStreamAsync();
|
||
using var archive = new ZipArchive(stream, ZipArchiveMode.Read);
|
||
var names = archive.Entries.Select(e => e.Name).ToList();
|
||
Assert.Contains("anubis-2099-01-01.log", names);
|
||
Assert.DoesNotContain("altro.txt", names);
|
||
using var reader = new StreamReader(archive.GetEntry("anubis-2099-01-01.log")!.Open());
|
||
StringAssert.Contains(await reader.ReadToEndAsync(), "una riga");
|
||
}
|
||
|
||
// A new installation: the screens say what is missing instead of showing numbers.
|
||
var home = await server.TextAsync("/");
|
||
StringAssert.Contains(home, "La lettura delle notizie non è ancora attiva.");
|
||
StringAssert.Contains(home, "L'apprendimento non è ancora attivo.");
|
||
var diary = await server.TextAsync("/diario");
|
||
StringAssert.Contains(diary, "Come sta il sistema");
|
||
StringAssert.Contains(diary, "non configurato");
|
||
StringAssert.Contains(diary, "Il computer che lo ospita");
|
||
}
|
||
|
||
[TestMethod]
|
||
[TestCategory(Category.Unit)]
|
||
public void DiaryEntriesAreSplitAsTheMockupDraws()
|
||
{
|
||
var at = DateTimeOffset.UnixEpoch;
|
||
var rule = DiaryView.Entry(at, DiaryKinds.News, "demo", "Ho cambiato una regola per 24 ore: non aumento la posizione su SOL. Motivo: la rete è ferma.");
|
||
Assert.AreEqual("Ho cambiato una regola per 24 ore:", rule.Lead);
|
||
Assert.AreEqual("Motivo: la rete è ferma.", rule.Rest);
|
||
Assert.IsTrue(rule.Attention);
|
||
|
||
var long1 = DiaryView.Entry(at, DiaryKinds.Orders, "stop_moved", "Alzato lo stop di BTC/EUR da 65.400 € a 66.180 €. Lo stop segue il prezzo quando sale.");
|
||
Assert.AreEqual("Alzato lo stop di BTC/EUR da 65.400 € a 66.180 €.", string.Concat(long1.Main.Select(p => p.Text)));
|
||
Assert.AreEqual("Lo stop segue il prezzo quando sale.", long1.Rest);
|
||
Assert.IsNull(long1.Trade);
|
||
|
||
var shortOne = DiaryView.Entry(at, DiaryKinds.News, "demo", "Voce non confermata su un exchange. Nessuna azione: ricontrollo tra 2 ore.");
|
||
Assert.IsNull(shortOne.Rest, "A short entry stays on one line.");
|
||
|
||
var sale = DiaryView.Entry(at, DiaryKinds.Orders, "fill", "Venduta 1 MSFT a 522,14 $: +9,84 $ in 3 giorni.");
|
||
Assert.AreEqual("MSFT", sale.Trade);
|
||
Assert.AreEqual("gain", sale.Main.Single(p => p.Class is not null).Class);
|
||
Assert.AreEqual("ETH", DiaryView.Entry(at, DiaryKinds.Orders, "fill", "Venduto 0,1 ETH/EUR a 2.500 €: −12,00 € in 4 giorni.").Trade);
|
||
Assert.IsNull(DiaryView.Entry(at, DiaryKinds.Orders, "fill", "Comprate 2 AAPL a 259,80 $.").Trade, "A purchase has no closed trade to explain.");
|
||
|
||
Assert.AreEqual("Oggi, venerdì 9 ottobre", DiaryView.Heading(new DateOnly(2026, 10, 9), new DateOnly(2026, 10, 9)));
|
||
Assert.AreEqual("Mercoledì 7 ottobre", DiaryView.Heading(new DateOnly(2026, 10, 7), new DateOnly(2026, 10, 9)));
|
||
}
|
||
}
|