Wetterdienst: Verhersage verlängert, Anzeige im Stundenplan.
This commit is contained in:
@@ -0,0 +1,102 @@
|
||||
using LehrerApp.Core.Models;
|
||||
using LehrerApp.Desktop.ViewModels.Planning;
|
||||
using Xunit;
|
||||
|
||||
namespace LehrerApp.Desktop.Tests;
|
||||
|
||||
public sealed class SchoolDayWeatherSummaryTests
|
||||
{
|
||||
private static readonly DateOnly Day = new(2026, 8, 24);
|
||||
|
||||
[Fact]
|
||||
public void From_GewitterHatVorrangVorSturmUndRegen()
|
||||
{
|
||||
var snapshot = Snapshot(
|
||||
Hour(8, code: 61, rain: 2, gust: 70),
|
||||
Hour(10, code: 95, rain: 1, gust: 80));
|
||||
|
||||
var summary = SchoolDayWeatherSummary.From(snapshot, Day);
|
||||
|
||||
Assert.Equal(SchoolDayWeatherKind.Thunderstorm, summary!.Kind);
|
||||
Assert.Equal("⛈️", summary.Symbol);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void From_BoeAbBeaufortAcht_WirdAlsSturmAngezeigt()
|
||||
{
|
||||
var summary = SchoolDayWeatherSummary.From(Snapshot(Hour(10, gust: 62)), Day);
|
||||
|
||||
Assert.Equal(SchoolDayWeatherKind.Storm, summary!.Kind);
|
||||
Assert.Equal("💨", summary.Symbol);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void From_NaechtlicheBoeBeeinflusstSchultagNicht()
|
||||
{
|
||||
var snapshot = Snapshot(Hour(10, cloud: 10), Hour(23, gust: 90));
|
||||
|
||||
var summary = SchoolDayWeatherSummary.From(snapshot, Day);
|
||||
|
||||
Assert.Equal(20, summary!.MaxWindGustKmh);
|
||||
Assert.Equal(SchoolDayWeatherKind.Sunny, summary!.Kind);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void From_AmtlicheGewitterwarnung_PraegtSymbolUndTooltip()
|
||||
{
|
||||
var snapshot = Snapshot(Hour(10, cloud: 20));
|
||||
snapshot.Warnings.Add(new WeatherWarning
|
||||
{
|
||||
Identifier = "w1", Event = "GEWITTER", Headline = "Amtliche Warnung vor Gewitter",
|
||||
Instruction = "Aufenthalt im Freien vermeiden.", Severity = "Severe",
|
||||
Onset = Day.ToDateTime(new TimeOnly(12, 0)), Expires = Day.ToDateTime(new TimeOnly(16, 0)),
|
||||
});
|
||||
|
||||
var summary = SchoolDayWeatherSummary.From(snapshot, Day);
|
||||
|
||||
Assert.Equal(SchoolDayWeatherKind.Thunderstorm, summary!.Kind);
|
||||
Assert.Contains("Amtliche Warnung", summary.Tooltip);
|
||||
Assert.Contains("Aufenthalt im Freien", summary.Tooltip);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void From_RegenSummiertStundenUndZeigtTemperaturspanne()
|
||||
{
|
||||
var snapshot = Snapshot(
|
||||
Hour(8, temperature: 12, rain: 0.1),
|
||||
Hour(12, temperature: 17, rain: 0.4));
|
||||
|
||||
var summary = SchoolDayWeatherSummary.From(snapshot, Day);
|
||||
|
||||
Assert.Equal(SchoolDayWeatherKind.Rain, summary!.Kind);
|
||||
Assert.Equal(0.5, summary.PrecipitationMm);
|
||||
Assert.Contains("12–17 °C", summary.Tooltip);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void WarningTouchesDate_MehrtaegigeVorwarnung_TrifftAlleUeberlapptenTage()
|
||||
{
|
||||
var warning = new WeatherWarning
|
||||
{
|
||||
Onset = Day.ToDateTime(new TimeOnly(18, 0)),
|
||||
Expires = Day.AddDays(2).ToDateTime(new TimeOnly(8, 0)),
|
||||
};
|
||||
|
||||
Assert.True(SchoolDayWeatherSummary.WarningTouchesDate(warning, Day.AddDays(1)));
|
||||
Assert.False(SchoolDayWeatherSummary.WarningTouchesDate(warning, Day.AddDays(3)));
|
||||
}
|
||||
|
||||
private static WeatherSnapshot Snapshot(params WeatherForecastHour[] hours) => new()
|
||||
{
|
||||
RetrievedAt = DateTime.UtcNow,
|
||||
Forecast = hours.ToList(),
|
||||
};
|
||||
|
||||
private static WeatherForecastHour Hour(int hour, int? code = 0, double? temperature = 20,
|
||||
double? rain = 0, double? gust = 20, double? cloud = 20) => new()
|
||||
{
|
||||
ValidAt = Day.ToDateTime(new TimeOnly(hour, 0)), WeatherCode = code,
|
||||
TemperatureC = temperature, PrecipitationMm = rain, WindGustKmh = gust,
|
||||
CloudCoverPercent = cloud,
|
||||
};
|
||||
}
|
||||
Reference in New Issue
Block a user