Promos between programmes (from 0.108.37)
pauljd/davidson-ci: Davidson CI / quality (push) Failing after 2m8s
pauljd/davidson-ci: Davidson CI / ai-review (push) Failing after 1m22s

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
This commit is contained in:
2026-11-06 00:56:44 +00:00
co-authored by Claude Opus 5.5
parent a7f31b07bf
commit 7ce0e62cc7
4 changed files with 159 additions and 1 deletions
@@ -0,0 +1,39 @@
package tv.orbit.classic
import org.junit.Assert.*
import org.junit.Test
import java.time.ZoneId
import java.time.ZonedDateTime
class PromosTest {
private val london = ZoneId.of("Europe/London")
private val minute = 60_000L
private fun at(d: Int, h: Int, m: Int = 0) = ZonedDateTime.of(2026, 11, d, h, m, 0, 0, london).toInstant().toEpochMilli()
private fun item(channel: Int, start: Long, title: String = "Film") =
WhatsOnItem(channel, ScheduleEntry("s$start", EpisodeMark(1, 1), ScheduledMedia(SampleItem(title, "Movie", 90, "", "i$start", 90 * minute), "src", 90 * minute), start), "TONIGHT'S PICK", "", 90)
// A changeover on a minute divisible by three, so it's one of the "now and then".
private val changeover = at(6, 18, 0).let { it - Math.floorMod(it / minute, 3L) * minute }
@Test fun nowAndThenAtMostHourlyAndForSomethingAhead() {
val items = listOf(item(302, changeover + 2 * 60 * minute), item(DRIVE_IN_NUMBER, changeover + 60 * minute))
assertNotNull(promoFor(106, changeover, items, null) { false })
// Not twice within the hour, and not on the other changeovers.
assertNull(promoFor(106, changeover + 30 * minute, items, changeover) { false })
assertNull(promoFor(106, changeover + minute, items, null) { false })
// Never on Tots or the Drive-In itself, never for something starting within ten minutes or already gone.
assertNull(promoFor(TOTS_NUMBER, changeover, items, null) { false })
assertNull(promoFor(DRIVE_IN_NUMBER, changeover, items, null) { false })
assertNull(promoFor(106, changeover, listOf(item(302, changeover + 5 * minute)), null) { false })
// Nothing the profile watching can't see.
assertNull(promoFor(106, changeover, items, null) { true })
}
@Test fun theHeadlineSaysWhenAndWhere() {
val now = at(6, 18)
assertEquals("TONIGHT AT THE DRIVE-IN", promoHeadline(item(DRIVE_IN_NUMBER, at(6, 20)), now, london))
assertEquals("TONIGHT ON ACTION", promoHeadline(item(302, at(6, 21)), now, london))
assertEquals("TONIGHT ON ACTION", promoHeadline(item(302, at(7, 1)), now, london))
assertEquals("TOMORROW ON ACTION", promoHeadline(item(302, at(7, 20)), now, london))
assertEquals("LATER ON ACTION", promoHeadline(item(302, at(6, 15)), at(6, 12), london))
}
}