test: add unit tests to toFormattedMatchTime
This commit is contained in:
parent
2a9dcbc616
commit
dd2810f516
2 changed files with 72 additions and 1 deletions
|
@ -31,7 +31,7 @@ fun ZonedDateTime?.toFormattedMatchTime(): String {
|
|||
val dayOfWeekFormatter = DateTimeFormatter.ofPattern("EEE", Locale("pt", "BR"))
|
||||
val day = format(dayOfWeekFormatter).replaceFirstChar {
|
||||
it.titlecase(Locale("pt", "BR"))
|
||||
}
|
||||
}.dropLast(1)
|
||||
"$day, ${format(timeFormatter)}"
|
||||
}
|
||||
|
||||
|
|
|
@ -0,0 +1,71 @@
|
|||
package xyz.leomurca.csgomatches.utils
|
||||
|
||||
import java.time.Clock
|
||||
import java.time.DayOfWeek
|
||||
import java.time.ZoneId
|
||||
import java.time.ZonedDateTime
|
||||
import java.time.format.DateTimeFormatter
|
||||
import kotlin.test.Test
|
||||
import kotlin.test.assertEquals
|
||||
|
||||
class ExtensionsTest {
|
||||
|
||||
private fun now(): ZonedDateTime = ZonedDateTime.now(fixedClock)
|
||||
|
||||
@Test
|
||||
fun `toFormattedMatchTime - returns Hoje when date is today`() {
|
||||
// Arrange
|
||||
val date = now().withHour(18).withMinute(30)
|
||||
|
||||
// Act
|
||||
val result = date.toFormattedMatchTime()
|
||||
|
||||
// Assert
|
||||
assertEquals("Hoje, 18:30", result)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `toFormattedMatchTime - returns weekday in Portuguese when date is this week`() {
|
||||
// Arrange
|
||||
val tuesday = now().with(DayOfWeek.TUESDAY).withHour(22).withMinute(0)
|
||||
|
||||
// Act
|
||||
val result = tuesday.toFormattedMatchTime()
|
||||
|
||||
// Assert
|
||||
// "Ter" is the abbreviation for "Terça-feira"
|
||||
assertEquals("Ter, 22:00", result)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `toFormattedMatchTime - returns full date when not this week`() {
|
||||
// Arrange
|
||||
val future = now().plusWeeks(2).withHour(15).withMinute(0)
|
||||
|
||||
// Act
|
||||
val result = future.toFormattedMatchTime()
|
||||
|
||||
// Assert
|
||||
val expected = future.format(DateTimeFormatter.ofPattern("dd.MM HH:mm"))
|
||||
assertEquals(expected, result)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `toFormattedMatchTime - returns A definir when date is null`() {
|
||||
// Arrange
|
||||
val date: ZonedDateTime? = null
|
||||
|
||||
// Act
|
||||
val result = date.toFormattedMatchTime()
|
||||
|
||||
// Assert
|
||||
assertEquals("A definir", result)
|
||||
}
|
||||
|
||||
companion object {
|
||||
private val fixedClock = Clock.fixed(
|
||||
ZonedDateTime.of(2025, 7, 19, 12, 0, 0, 0, ZoneId.of("America/Sao_Paulo")).toInstant(),
|
||||
ZoneId.of("America/Sao_Paulo")
|
||||
)
|
||||
}
|
||||
}
|
Loading…
Add table
Reference in a new issue