Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ sealed interface SeparatorConfig {
}

data class Continuous(
val gap: Duration = 3.hours,
val gap: Duration = 1.hours,
) : SeparatorConfig {
override val groupingWindow: Duration = Duration.INFINITE
override fun shouldSeparate(before: Instant, after: Instant): Boolean =
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
package com.flipcash.shared.chat.models

import kotlinx.datetime.LocalDate
import kotlinx.datetime.TimeZone
import kotlinx.datetime.atTime
import kotlinx.datetime.toInstant
import org.junit.Test
import kotlin.test.assertEquals
import kotlin.test.assertFalse
import kotlin.test.assertTrue
import kotlin.time.Duration.Companion.hours
import kotlin.time.Duration.Companion.minutes

/** The transcript opens a date separator after a one-hour pause, or at a change of day. */
class SeparatorConfigTest {

// Local noon keeps the offsets below on the same calendar day in any time zone.
private val noon = LocalDate(2024, 1, 10)
.atTime(12, 0)
.toInstant(TimeZone.currentSystemDefault())

private val config = SeparatorConfig.Continuous()

@Test
fun `default gap is one hour`() {
assertEquals(1.hours, config.gap)
}

@Test
fun `separates after a 90 minute pause on the same day`() {
assertTrue(config.shouldSeparate(noon, noon + 90.minutes))
}

@Test
fun `separates regardless of argument order`() {
assertTrue(config.shouldSeparate(noon + 90.minutes, noon))
}

@Test
fun `does not separate after a 30 minute pause on the same day`() {
assertFalse(config.shouldSeparate(noon, noon + 30.minutes))
}

@Test
fun `does not separate at exactly one hour`() {
assertFalse(config.shouldSeparate(noon, noon + 1.hours))
}
}
Loading