Files
deepdrft/DeepDrftTests/EmbedSnippetBuilderTests.cs
T
daniel-c-harvey 466084b5a3 feat: Phase 17.3 — Fixed embed queue panel with collapse/expand iframe resize (OQ1 Option A)
Read-only inline queue panel below the release embed's player bar; row-jump reuses PlayRelease. ForRelease mints a taller iframe plus a postMessage resize listener for the collapse toggle; ForTrack unchanged.
2026-06-19 16:21:45 -04:00

104 lines
3.8 KiB
C#

using System.Text.RegularExpressions;
using DeepDrftPublic.Client.Helpers;
namespace DeepDrftTests;
/// <summary>
/// Unit tests for the share-popover embed snippet (<see cref="EmbedSnippetBuilder"/>). The builder is
/// the mode-aware half of SharePopover: track mode targets FramePlayer's TrackEntryKey param, release
/// mode targets its ReleaseEntryKey param. The two snippets share width/border/autoplay chrome but
/// diverge in height by design (Phase 17 §4.1, OQ6): the release embed is taller to show its queue
/// panel; the track embed stays compact. Pure string composition, tested without rendering.
/// </summary>
[TestFixture]
public class EmbedSnippetBuilderTests
{
private const string BaseUri = "https://deepdrft.example/";
[Test]
public void ForTrack_EmitsTrackEntryKeySrc()
{
var snippet = EmbedSnippetBuilder.ForTrack(BaseUri, "abc123");
Assert.That(snippet, Does.Contain(@"src=""https://deepdrft.example/FramePlayer?TrackEntryKey=abc123"""));
Assert.That(snippet, Does.Not.Contain("ReleaseEntryKey"));
}
[Test]
public void ForRelease_EmitsReleaseEntryKeySrc()
{
var snippet = EmbedSnippetBuilder.ForRelease(BaseUri, "rel-xyz");
Assert.That(snippet, Does.Contain(@"src=""https://deepdrft.example/FramePlayer?ReleaseEntryKey=rel-xyz"""));
Assert.That(snippet, Does.Not.Contain("TrackEntryKey"));
}
[Test]
public void BothModes_ShareIdenticalNonHeightChrome()
{
var track = EmbedSnippetBuilder.ForTrack(BaseUri, "k");
var release = EmbedSnippetBuilder.ForRelease(BaseUri, "k");
Assert.Multiple(() =>
{
foreach (var snippet in new[] { track, release })
{
Assert.That(snippet, Does.StartWith("<iframe "));
Assert.That(snippet, Does.Contain(@"width=""656"""));
Assert.That(snippet, Does.Contain(@"frameborder=""0"""));
Assert.That(snippet, Does.Contain(@"style=""border-radius:8px;"""));
Assert.That(snippet, Does.Contain(@"allow=""autoplay"""));
Assert.That(snippet, Does.Contain("</iframe>"));
}
});
}
// T14 (Phase 17 §9): the release embed is taller than the track embed (it shows a queue panel),
// and the track embed's height is unchanged from its historical value (UC6/AC6).
[Test]
public void ForTrack_KeepsHistoricalCompactHeight()
{
var track = EmbedSnippetBuilder.ForTrack(BaseUri, "k");
Assert.That(track, Does.Contain(@"height=""196"""));
}
[Test]
public void ForRelease_IsTallerThanForTrack_ToShowQueuePanel()
{
var trackHeight = HeightOf(EmbedSnippetBuilder.ForTrack(BaseUri, "k"));
var releaseHeight = HeightOf(EmbedSnippetBuilder.ForRelease(BaseUri, "k"));
Assert.That(releaseHeight, Is.GreaterThan(trackHeight));
}
// The release snippet carries the host-side resize listener (OQ1 Option A); the track snippet,
// having no panel to collapse, does not.
[Test]
public void ForRelease_IncludesResizeListenerScript()
{
var release = EmbedSnippetBuilder.ForRelease(BaseUri, "k");
Assert.Multiple(() =>
{
Assert.That(release, Does.Contain("<script>"));
Assert.That(release, Does.Contain("deepdrft-embed-resize"));
});
}
[Test]
public void ForTrack_HasNoResizeListenerScript()
{
var track = EmbedSnippetBuilder.ForTrack(BaseUri, "k");
Assert.That(track, Does.Not.Contain("<script>"));
}
private static int HeightOf(string snippet)
{
var match = Regex.Match(snippet, @"height=""(\d+)""");
Assert.That(match.Success, Is.True, "snippet must declare an iframe height");
return int.Parse(match.Groups[1].Value);
}
}