feat: add schedule and now-playing page

The new Schedule page lets the user choose 1 to 24 hours and create a
plan that starts at the next full hour. The timeline lists start time,
type, title and duration. Each type has a labelled chip: news,
ads and moderator segments get their own border color, songs stay
neutral because the accent color can be the same red as the news.

A now-playing card shows the current item with progress, elapsed and
planned time, Start and Stop buttons and a volume slider. The current
row is selected and scrolled into view. Errors from the generator and
skipped items appear in an InfoBar.

ScheduleController creates the plan from the library and drives the
PlaybackEngine. It lives on App for the whole app run, so a broadcast
keeps playing while the user switches pages, and it stops on exit.

Refs #10

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
fraujulianandClaude Opus 5.5 committed 2026-11-23 11:01:28 +01:00
1 parent 992b74e42d
commit 7f9ed339e7
6 files changed
+533

No files matched your search

@@ -0,0 +1,117 @@
using Microsoft.Data.Sqlite;
using Radiosender.Controllers;
using Radiosender.Models;
using Radiosender.Services;
namespace Radiosender.Tests;
public sealed class ScheduleControllerTests : IDisposable
{
private readonly string _directory = Path.Combine(Path.GetTempPath(), "radiosender-tests", Guid.NewGuid().ToString("N"));
private readonly SongRepository _songs;
private DateTime _now = new(2026, 11, 23, 14, 37, 12);
public ScheduleControllerTests() => _songs = new SongRepository(Path.Combine(_directory, "test.db"));
public void Dispose()
{
SqliteConnection.ClearAllPools();
Directory.Delete(_directory, recursive: true);
}
private sealed class InstantPlayer : IAudioPlayer
{
public event EventHandler? TrackFinished;
public void Play(string filePath) => TrackFinished?.Invoke(this, EventArgs.Empty);
public void Stop() { }
}
private ScheduleController Create(Func<TimeSpan, CancellationToken, Task>? delay = null) =>
new(_songs,
new ScheduleGenerator(new ScheduleOptions(), new Random(7)),
new PlaybackEngine(new InstantPlayer(), delay ?? ((_, _) => Task.CompletedTask)),
() => _now);
private void AddSongs()
{
int[] seconds = [192, 245, 167, 331, 238, 183, 369, 141];
for (var i = 0; i < seconds.Length; i++)
_songs.Add(new Song { Title = $"Song {i}", Artist = "Artist", Duration = TimeSpan.FromSeconds(seconds[i]), FilePath = $"{i}.mp3" });
}
[Fact]
public void CreatePlan_StartsAtNextFullHourAndCoversTheHours()
{
AddSongs();
var controller = Create();
var plan = controller.CreatePlan(2);
Assert.Equal(new DateTime(2026, 11, 23, 15, 0, 0), plan[0].Start);
Assert.Equal(new DateTime(2026, 11, 23, 17, 0, 0), plan[^1].End);
Assert.Same(plan, controller.Plan);
}
[Fact]
public void CreatePlan_ThrowsScheduleExceptionForEmptyLibrary()
{
Assert.Throws<ScheduleException>(() => Create().CreatePlan(1));
}
[Theory]
[InlineData(0)]
[InlineData(25)]
public void CreatePlan_RejectsHoursOutOfRange(int hours)
{
AddSongs();
Assert.Throws<ArgumentOutOfRangeException>(() => Create().CreatePlan(hours));
}
[Fact]
public void Start_WithoutPlanThrows()
{
Assert.Throws<InvalidOperationException>(() => Create().Start());
}
[Fact]
public async Task Start_PlaysThePlanAndRaisesFinished()
{
AddSongs();
var controller = Create();
controller.CreatePlan(1);
var started = 0;
var finished = new TaskCompletionSource(TaskCreationOptions.RunContinuationsAsynchronously);
controller.ItemStarted += (_, _) => Interlocked.Increment(ref started);
controller.Finished += (_, _) => finished.TrySetResult();
controller.Start();
await finished.Task.WaitAsync(TimeSpan.FromSeconds(5));
Assert.Equal(controller.Plan.Count, started);
Assert.Null(controller.CurrentItem);
}
[Fact]
public async Task CurrentItemAndElapsed_FollowThePlayingItem()
{
AddSongs();
var hold = new TaskCompletionSource();
var controller = Create((_, token) => hold.Task.WaitAsync(token));
controller.CreatePlan(1);
var first = new TaskCompletionSource(TaskCreationOptions.RunContinuationsAsynchronously);
controller.ItemStarted += (_, _) => first.TrySetResult();
controller.Start();
await first.Task.WaitAsync(TimeSpan.FromSeconds(5));
_now = _now.AddMinutes(2);
Assert.Equal(ScheduleItemKind.News, controller.CurrentItem!.Kind);
Assert.Equal(TimeSpan.FromMinutes(2), controller.CurrentElapsed);
_now = _now.AddHours(1);
Assert.Equal(controller.CurrentItem.Duration, controller.CurrentElapsed);
controller.Stop();
Assert.False(controller.IsPlaying);
Assert.Null(controller.CurrentItem);
}
}