diff --git a/app/src/main/java/xyz/leomurca/csgomatches/utils/Extensions.kt b/app/src/main/java/xyz/leomurca/csgomatches/utils/Extensions.kt index b337397..ee9b348 100644 --- a/app/src/main/java/xyz/leomurca/csgomatches/utils/Extensions.kt +++ b/app/src/main/java/xyz/leomurca/csgomatches/utils/Extensions.kt @@ -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)}" } diff --git a/app/src/test/java/xyz/leomurca/csgomatches/utils/ExtensionsTest.kt b/app/src/test/java/xyz/leomurca/csgomatches/utils/ExtensionsTest.kt new file mode 100644 index 0000000..2f6555c --- /dev/null +++ b/app/src/test/java/xyz/leomurca/csgomatches/utils/ExtensionsTest.kt @@ -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") + ) + } +} \ No newline at end of file