Part 1 - background box. TextGraphicsElement gains element-level background_color, background_opacity_percent, background_padding, background_corner_radius, border_color and border_width; TextElement draws a rounded rect behind the text block and insets the text into it. Element level rather than per-style because the engine lays the whole element out as one RichTextKit TextBlock and rasterises it into one bitmap, so one box per element is the only shape the renderer can express. width_percent keeps bounding the visible element, so the insets are subtracted from the text's wrap/scale budget. The seeded on-now-next.yml adopts it. The halo drops from 2px to 1px rather than to zero, and the box carries a low-alpha white border: rendered against real frames, a 65% black fill is legible on bright and midtone content but vanishes entirely into dark content, which is why the issue asked for an *outlined* box. The halo still matters because the fill is translucent. Because #74's seeder writes the template only when absent, an already-seeded install would never have seen any of this. GraphicsElementSeeder now keeps every default it has shipped as a verbatim fingerprint and rewrites the file only when it still matches one (line-endings normalised), so an untouched install upgrades and an operator-edited one is left alone. The V1 fingerprint was checked byte-for-byte against the live install before being trusted - a fingerprint that matches nothing in the field is a permanent silent no-op. Part 2 - on by default. New channels get the built-in element from CreateChannelHandler (CreateChannel carries no graphics field and the SPA's channel editor is update-only, so the server is the only place a create-time default can live). Pre-existing channels get a one-time AttachOnNowNextByDefault backfill. The marker is written on the first run even when nothing was attached: the tempting alternative - stay armed until the element row exists - would fire on a later boot and re-attach the overlay to a channel the operator had cleared in between. HLS Direct is excluded at both sites, where the overlay cannot render at all. Resolves the issue's open question: [vge] in a filter graph does not imply a graphics element is bound. Watermarks fall back onto the graphics engine whenever they cannot use ffmpeg's native overlay shortcut, so a watermark alone produces that stage. Tests assert rendered pixels, because every failure mode here is a silent no-op that a model-level test cannot see. 13 clause mutations were executed against them; each reddened only its own clause. Decisions-Edit: yes Refs: #732
93 lines
3.0 KiB
C#
93 lines
3.0 KiB
C#
using ErsatzTV.Application.Channels;
|
|
using ErsatzTV.Core;
|
|
using ErsatzTV.Core.Domain;
|
|
using ErsatzTV.Core.Graphics;
|
|
using ErsatzTV.FFmpeg.State;
|
|
using ErsatzTV.Infrastructure.Data;
|
|
using ErsatzTV.Tests.Support;
|
|
using LanguageExt;
|
|
using Microsoft.EntityFrameworkCore;
|
|
using NUnit.Framework;
|
|
using Shouldly;
|
|
|
|
namespace ErsatzTV.Tests.Application.Channels;
|
|
|
|
/// <summary>
|
|
/// #732: the On Now / Next overlay is a default rather than an opt-in, so a channel created after
|
|
/// that decision gets the built-in element without the operator toggling anything.
|
|
/// </summary>
|
|
[TestFixture]
|
|
public class CreateChannelDefaultGraphicsElementTests : ChannelHandlerTestBase
|
|
{
|
|
private CreateChannelHandler MakeHandler() => new(Worker, Db.Factory, SearchTargets, RemoteLogoCacher);
|
|
|
|
private async Task<int> SeedBuiltInElement()
|
|
{
|
|
await using TvContext context = Db.CreateContext();
|
|
var element = new GraphicsElement
|
|
{
|
|
Path = $"/templates/text/{GraphicsElementDefaults.OnNowNextFileName}",
|
|
Kind = GraphicsElementKind.Text
|
|
};
|
|
|
|
context.GraphicsElements.Add(element);
|
|
await context.SaveChangesAsync();
|
|
return element.Id;
|
|
}
|
|
|
|
private async Task<List<int>> AttachedElementIds(int channelId)
|
|
{
|
|
await using TvContext context = Db.CreateContext();
|
|
Channel reloaded = await context.Channels
|
|
.Include(c => c.ChannelGraphicsElements)
|
|
.SingleAsync(c => c.Id == channelId);
|
|
|
|
return reloaded.ChannelGraphicsElements.Select(x => x.GraphicsElementId).ToList();
|
|
}
|
|
|
|
[Test]
|
|
public async Task Attaches_The_Built_In_Element_To_A_New_Channel()
|
|
{
|
|
await SeedFFmpegProfile();
|
|
int elementId = await SeedBuiltInElement();
|
|
|
|
Either<BaseError, CreateChannelResult> result =
|
|
await MakeHandler().Handle(MakeCreate(), CancellationToken.None);
|
|
|
|
result.IsRight.ShouldBeTrue();
|
|
int channelId = result.RightToSeq().Head().ChannelId;
|
|
|
|
(await AttachedElementIds(channelId)).ShouldBe([elementId]);
|
|
}
|
|
|
|
[Test]
|
|
public async Task Leaves_An_Hls_Direct_Channel_Alone_Because_Nothing_Can_Render_There()
|
|
{
|
|
await SeedFFmpegProfile();
|
|
await SeedBuiltInElement();
|
|
|
|
Either<BaseError, CreateChannelResult> result = await MakeHandler().Handle(
|
|
MakeCreate(streamingMode: StreamingMode.HttpLiveStreamingDirect),
|
|
CancellationToken.None);
|
|
|
|
result.IsRight.ShouldBeTrue();
|
|
int channelId = result.RightToSeq().Head().ChannelId;
|
|
|
|
(await AttachedElementIds(channelId)).ShouldBeEmpty();
|
|
}
|
|
|
|
[Test]
|
|
public async Task Creates_The_Channel_Even_When_The_Built_In_Element_Does_Not_Exist()
|
|
{
|
|
await SeedFFmpegProfile();
|
|
|
|
Either<BaseError, CreateChannelResult> result =
|
|
await MakeHandler().Handle(MakeCreate(), CancellationToken.None);
|
|
|
|
result.IsRight.ShouldBeTrue();
|
|
int channelId = result.RightToSeq().Head().ChannelId;
|
|
|
|
(await AttachedElementIds(channelId)).ShouldBeEmpty();
|
|
}
|
|
}
|