0.100.0: v2 interface: one top bar (Home, What's On, TV Guide, Drive-In, Arcade), Home category menu, What's On screen with pop-up and reminders, one-screen Drive-In, restyled TV Guide
pauljd/davidson-ci: Davidson CI / quality (push) Failing after 2m15s
pauljd/davidson-ci: Davidson CI / ai-review (push) Failing after 1m33s

What's On reads confirmed bookings only (WhatsOnPage, 6 tests). Scheduling untouched: booking fingerprints identical to 0.99.17.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
This commit is contained in:
2026-11-04 17:24:37 +00:00
co-authored by Claude Opus 5.5
parent 7bb600fb76
commit 2264361b5c
16 changed files with 599 additions and 280 deletions
@@ -0,0 +1,87 @@
package tv.orbit.classic
import org.junit.Assert.assertEquals
import org.junit.Assert.assertNull
import org.junit.Assert.assertTrue
import org.junit.Test
import java.time.LocalDate
import java.time.ZoneId
/** What's On reads confirmed bookings only, picks by explainable rules, and never lets one channel or franchise take over. */
class WhatsOnPageTest {
private val zone = ZoneId.of("Europe/London")
private val minute = 60_000L
private fun at(date: String, hour: Int, min: Int = 0) = LocalDate.parse(date).atTime(hour, min).atZone(zone).toInstant().toEpochMilli()
private fun entry(title: String, start: Long, minutes: Int, why: String = "block 18-23; weighted", key: String = "", movie: Boolean = false, id: String = title.filter(Char::isLetterOrDigit)) =
ScheduleEntry(id, EpisodeMark(1, 1), ScheduledMedia(SampleItem(title, if (movie) "Movie" else "Episode", minutes.toLong(), "", id, minutes * minute), "src", minutes * minute), start, why, key)
private fun plan(vararg entries: ScheduleEntry) = ChannelPlan(entries.sortedBy { it.startMs }, ScheduleCursor())
private val saturday = "2026-11-21"
private val plans = mapOf(
601 to plan(entry("Dragon Ball Super: Beerus / S1 E1 / The God Who Destroys", at(saturday, 21, 8), 23, "event 21-22; weighted; premiere: first airing on Orbit", "vortex.afterburn.premiere"),
entry("Dragon Ball Super: Beerus / S1 E2 / Planet of the Kai", at(saturday, 21, 31), 23, "event 21-22; weighted; premiere: first airing on Orbit", "vortex.afterburn.premiere"),
entry("Dragon Ball Z: Dead Zone", at(saturday, 20, 27), 41, "event 20-21; weighted", "vortex.movie", movie = true),
entry("Batman Beyond / S1 E1 / Rebirth", at(saturday, 19, 0), 22)),
AFTER_DARK_NUMBER to plan(entry("Joe Bob's Drive-In / S1 E2 / Sleepaway Camp", at(saturday, 21, 3), 120, "event 21-1; weighted", "afterdark.drivein")),
106 to plan(entry("The X-Files / S2 E25 / Anasazi (1)", at(saturday, 22, 0), 45, "block 18-23; weighted; story: part 1 of 2, booked whole")),
303 to plan(entry("Aliens", at(saturday, 20, 0), 137, "block 18-24; next in turn", movie = true)),
401 to plan(entry("WrestleMania III", at("2026-11-22", 19, 8), 184, "event 19-24; next in turn", "ringx.ppv", movie = true)),
101 to plan(entry("Friends / S1 E1 / Pilot", at(saturday, 20, 0), 22)))
@Test fun picksByExplainableRulesFromBookingsOnly() {
val page = whatsOnPage(plans, null, at(saturday, 15), zone)
// The premiere beats every other rule, and its two episodes are one card.
assertEquals("Dragon Ball Super: Beerus", page.pick!!.title)
assertEquals("FIRST ON ORBIT", page.pick!!.tag)
// Tonight, in time order: no ordinary programme (Friends, Batman Beyond), one card per channel, Vortex not repeated.
val tonight = page.tonight.map { it.title }
assertEquals(listOf("Aliens", "Joe Bob's Drive-In", "The X-Files"), tonight)
assertTrue(page.tonight.none { it.channel == 601 })
// Coming Up: the special event after tonight.
assertEquals(listOf("WrestleMania III"), page.comingUp.map { it.title })
}
@Test fun nothingUnbookedEverAppears() {
// Before the premiere is booked, it can't be featured: with no plans there is nothing at all.
val empty = whatsOnPage(emptyMap(), null, at(saturday, 15), zone)
assertNull(empty.pick); assertTrue(empty.tonight.isEmpty() && empty.comingUp.isEmpty())
val withoutBeerus = whatsOnPage(plans - 601, null, at(saturday, 15), zone)
assertTrue((listOfNotNull(withoutBeerus.pick) + withoutBeerus.tonight + withoutBeerus.comingUp).none { "Beerus" in it.title })
}
@Test fun finishedProgrammesDropOutAndTheEditionTurnsAtNoon() {
val late = whatsOnPage(plans, null, at(saturday, 22, 30), zone)
assertTrue((listOfNotNull(late.pick) + late.tonight).none { it.endMs <= at(saturday, 22, 30) })
assertEquals(LocalDate.parse("2026-11-20"), whatsOnEdition(at(saturday, 11, 59), zone))
assertEquals(LocalDate.parse(saturday), whatsOnEdition(at(saturday, 12, 0), zone))
// After midnight it's still Saturday night's edition.
assertEquals(LocalDate.parse(saturday), whatsOnEdition(at("2026-11-22", 0, 30), zone))
}
@Test fun oneFranchiseCantTakeOver() {
assertEquals(whatsOnFranchise("Dragon Ball Z: Dead Zone"), whatsOnFranchise("Dragon Ball Super: Beerus"))
val crowded = mapOf(301 to plan(entry("Dragon Ball: Curse of the Blood Rubies", at(saturday, 20, 0), 50, movie = true)),
302 to plan(entry("Dragon Ball Z: Lord Slug", at(saturday, 20, 0), 52, movie = true)), 303 to plan(entry("Aliens", at(saturday, 20, 0), 137, movie = true)))
val page = whatsOnPage(crowded, null, at(saturday, 15), zone)
assertEquals(1, (listOfNotNull(page.pick) + page.tonight).count { it.title.startsWith("Dragon Ball") })
}
@Test fun driveInBillsComeFromTheDriveInPlan() {
val driveIn = plan(entry("Back to the Future", at(saturday, 19, 0), 116, "", movie = true, id = "bttf1"), entry("Back to the Future Part II", at(saturday, 20, 56), 108, "", movie = true, id = "bttf2"),
entry("Back to the Future Part III", at(saturday, 22, 44), 118, "", movie = true, id = "bttf3"))
val page = whatsOnPage(emptyMap(), driveIn, at(saturday, 15), zone)
assertEquals(DRIVE_IN_NUMBER, page.pick!!.channel)
assertEquals("AT THE DRIVE-IN", page.pick!!.tag)
}
@Test fun remindersComeAtFiveMinutesAndAtTheStartOnce() {
val r = ProgrammeReminder(106, at(saturday, 22, 0), "The X-Files")
assertNull(programmeReminderDue(listOf(r), at(saturday, 21, 50)))
assertEquals(1, programmeReminderDue(listOf(r), at(saturday, 21, 56))!!.stage)
assertNull(programmeReminderDue(listOf(r.copy(stage = 1)), at(saturday, 21, 57)))
assertEquals(2, programmeReminderDue(listOf(r.copy(stage = 1)), at(saturday, 22, 1))!!.stage)
assertNull(programmeReminderDue(listOf(r.copy(stage = 2)), at(saturday, 22, 2)))
assertNull(programmeReminderDue(listOf(r), at(saturday, 22, 20)))
assertEquals(emptyList<ProgrammeReminder>(), liveReminders(listOf(r), at("2026-11-23", 0)))
}
}