From d5b716ac3ed1fa9a75a9a61f7361cdca7a9cf32c Mon Sep 17 00:00:00 2001 From: Benoit Marty Date: Thu, 12 Dec 2024 00:20:31 +0100 Subject: [PATCH] Add more tests. --- .../impl/DefaultDateFormatterFrTest.kt | 26 +++++++++++++++++++ .../impl/DefaultDateFormatterTest.kt | 26 +++++++++++++++++++ 2 files changed, 52 insertions(+) diff --git a/libraries/dateformatter/impl/src/test/kotlin/io/element/android/libraries/dateformatter/impl/DefaultDateFormatterFrTest.kt b/libraries/dateformatter/impl/src/test/kotlin/io/element/android/libraries/dateformatter/impl/DefaultDateFormatterFrTest.kt index cddfc5b8e0..8dd0c61d9f 100644 --- a/libraries/dateformatter/impl/src/test/kotlin/io/element/android/libraries/dateformatter/impl/DefaultDateFormatterFrTest.kt +++ b/libraries/dateformatter/impl/src/test/kotlin/io/element/android/libraries/dateformatter/impl/DefaultDateFormatterFrTest.kt @@ -180,6 +180,32 @@ class DefaultDateFormatterFrTest { assertThat(formatter.format(ts, DateFormatterMode.TimeOnly, true)).isEqualTo("18:35") } + @Test + fun `test two days before same time`() { + val now = "1980-04-06T18:35:24.00Z" + val dat = "1980-04-04T18:35:24.00Z" + val ts = Instant.parse(dat).toEpochMilliseconds() + val formatter = createFormatter(now) + assertThat(formatter.format(ts, DateFormatterMode.Full)).isEqualTo("4 avril 1980 à 18:35") + assertThat(formatter.format(ts, DateFormatterMode.Month)).isEqualTo("Avril 1980") + assertThat(formatter.format(ts, DateFormatterMode.Day)).isEqualTo("Vendredi 4 avril") + assertThat(formatter.format(ts, DateFormatterMode.TimeOrDate)).isEqualTo("4 avr.") + assertThat(formatter.format(ts, DateFormatterMode.TimeOnly)).isEqualTo("18:35") + } + + @Test + fun `test two days before same time relative`() { + val now = "1980-04-06T18:35:24.00Z" + val dat = "1980-04-04T18:35:24.00Z" + val ts = Instant.parse(dat).toEpochMilliseconds() + val formatter = createFormatter(now) + assertThat(formatter.format(ts, DateFormatterMode.Full, true)).isEqualTo("Vendredi à 18:35") + assertThat(formatter.format(ts, DateFormatterMode.Month, true)).isEqualTo("Ce mois-ci") + assertThat(formatter.format(ts, DateFormatterMode.Day, true)).isEqualTo("Vendredi") + assertThat(formatter.format(ts, DateFormatterMode.TimeOrDate, true)).isEqualTo("4 avr.") + assertThat(formatter.format(ts, DateFormatterMode.TimeOnly, true)).isEqualTo("18:35") + } + @Test fun `test one month before same time`() { val now = "1980-04-06T18:35:24.00Z" diff --git a/libraries/dateformatter/impl/src/test/kotlin/io/element/android/libraries/dateformatter/impl/DefaultDateFormatterTest.kt b/libraries/dateformatter/impl/src/test/kotlin/io/element/android/libraries/dateformatter/impl/DefaultDateFormatterTest.kt index 142af801ea..b7bf9d818e 100644 --- a/libraries/dateformatter/impl/src/test/kotlin/io/element/android/libraries/dateformatter/impl/DefaultDateFormatterTest.kt +++ b/libraries/dateformatter/impl/src/test/kotlin/io/element/android/libraries/dateformatter/impl/DefaultDateFormatterTest.kt @@ -180,6 +180,32 @@ class DefaultDateFormatterTest { assertThat(formatter.format(ts, DateFormatterMode.TimeOnly, true)).isEqualTo("6:35 PM") } + @Test + fun `test two days before same time`() { + val now = "1980-04-06T18:35:24.00Z" + val dat = "1980-04-04T18:35:24.00Z" + val ts = Instant.parse(dat).toEpochMilliseconds() + val formatter = createFormatter(now) + assertThat(formatter.format(ts, DateFormatterMode.Full)).isEqualTo("April 4, 1980 at 6:35 PM") + assertThat(formatter.format(ts, DateFormatterMode.Month)).isEqualTo("April 1980") + assertThat(formatter.format(ts, DateFormatterMode.Day)).isEqualTo("Friday 4 April") + assertThat(formatter.format(ts, DateFormatterMode.TimeOrDate)).isEqualTo("4 Apr") + assertThat(formatter.format(ts, DateFormatterMode.TimeOnly)).isEqualTo("6:35 PM") + } + + @Test + fun `test two days before same time relative`() { + val now = "1980-04-06T18:35:24.00Z" + val dat = "1980-04-04T18:35:24.00Z" + val ts = Instant.parse(dat).toEpochMilliseconds() + val formatter = createFormatter(now) + assertThat(formatter.format(ts, DateFormatterMode.Full, true)).isEqualTo("Friday at 6:35 PM") + assertThat(formatter.format(ts, DateFormatterMode.Month, true)).isEqualTo("This month") + assertThat(formatter.format(ts, DateFormatterMode.Day, true)).isEqualTo("Friday") + assertThat(formatter.format(ts, DateFormatterMode.TimeOrDate, true)).isEqualTo("4 Apr") + assertThat(formatter.format(ts, DateFormatterMode.TimeOnly, true)).isEqualTo("6:35 PM") + } + @Test fun `test one month before same time`() { val now = "1980-04-06T18:35:24.00Z"