This commit is contained in:
ponzischeme89
2026-08-11 23:41:10 +12:00
parent 0e183cf560
commit 5fed3360c2
42 changed files with 1340 additions and 130 deletions
+72
View File
@@ -537,6 +537,78 @@ func TestHeroRotationSlotIsLocal(t *testing.T) {
}
}
func TestPinnedHeroMoviesLeadAndOrganicSelectionFillsTheGrid(t *testing.T) {
pinned := []heroCandidate{
{ID: "custom-2", Item: json.RawMessage(`{"Id":"custom-2"}`)},
{ID: "custom-1", Item: json.RawMessage(`{"Id":"custom-1"}`)},
}
organic := []heroCandidate{
// A pinned title can also qualify organically; it must still appear only once.
{ID: "custom-1", Item: json.RawMessage(`{"Id":"custom-1"}`), Kind: heroSeasonPremiere},
{ID: "release-1", Item: json.RawMessage(`{"Id":"release-1"}`)},
{ID: "release-2", Item: json.RawMessage(`{"Id":"release-2"}`)},
{ID: "library-1", Item: json.RawMessage(`{"Id":"library-1"}`)},
}
got := mergePinnedHeroCandidates(pinned, organic, organic[1:], 4)
want := []string{"custom-2", "custom-1", "release-1", "release-2"}
if strings.Join(heroIDs(got), ",") != strings.Join(want, ",") {
t.Fatalf("pinned hero order = %v, want %v", heroIDs(got), want)
}
if got[1].Kind != heroSeasonPremiere {
t.Fatalf("pin lost its natural premiere evidence: %+v", got[1])
}
}
func TestPinnedHeroMergeHonoursAnEmptyOrShortGrid(t *testing.T) {
candidate := heroCandidate{ID: "custom", Item: json.RawMessage(`{"Id":"custom"}`)}
if got := mergePinnedHeroCandidates([]heroCandidate{candidate}, nil, nil, 0); got != nil {
t.Fatalf("zero-sized grid = %v, want nil", heroIDs(got))
}
if got := heroIDs(mergePinnedHeroCandidates([]heroCandidate{candidate}, nil, nil, 4)); strings.Join(got, ",") != "custom" {
t.Fatalf("short grid = %v, want custom", got)
}
}
func TestPrimeSubtitleChangesOnlyTheLargeFirstCard(t *testing.T) {
candidate := heroCandidate{ReleasedAt: heroDaysAgo(2), Kind: heroMovie}
if got := heroReasonForPosition(candidate, 0, " Family pick tonight ", heroNow, time.UTC); got != "Family pick tonight" {
t.Fatalf("prime subtitle = %q", got)
}
if got := heroReasonForPosition(candidate, 1, "Family pick tonight", heroNow, time.UTC); got == "Family pick tonight" || !strings.Contains(got, "Released") {
t.Fatalf("secondary card lost its natural reason: %q", got)
}
if got := heroReasonForPosition(candidate, 0, "", heroNow, time.UTC); !strings.Contains(got, "Released") {
t.Fatalf("blank override did not fall back to the natural reason: %q", got)
}
}
func TestPinnedSeriesUsesTheSameNaturalPresentationAsOrganicTitles(t *testing.T) {
candidate := heroCandidate{Kind: heroSeries, ReleasedAt: heroDaysAgo(3)}
if got := heroLabel(candidate, heroNow); got != heroLabelNewRelease {
t.Fatalf("recent series label = %q, want %q", got, heroLabelNewRelease)
}
if got := heroReason(candidate, heroNow, time.UTC); !strings.Contains(got, "new series premiered") {
t.Fatalf("recent series reason = %q", got)
}
candidate.ReleasedAt = heroDaysAgo(100)
candidate.Rated, candidate.Rating = true, 0.9
if got := heroLabel(candidate, heroNow); got != heroLabelAcclaimed {
t.Fatalf("older acclaimed series label = %q, want %q", got, heroLabelAcclaimed)
}
}
func TestAdminHeroSearchAcceptsFilmsAndSeriesOnly(t *testing.T) {
for _, itemType := range []string{"Movie", "Series"} {
if item, ok := adminHeroItem(heroItem("id", "Title", itemType)); !ok || item.Type != itemType {
t.Fatalf("%s was not accepted: %+v, %t", itemType, item, ok)
}
}
if _, ok := adminHeroItem(heroItem("episode", "Episode", "Episode")); ok {
t.Fatal("episode was accepted as a pinnable hero title")
}
}
func heroIDs(candidates []heroCandidate) []string {
ids := make([]string, 0, len(candidates))
for _, candidate := range candidates {