From de03c7e780b09cc7a4c313de83af6b7c56864a8e Mon Sep 17 00:00:00 2001 From: "Harry S (Macbook)" Date: Tue, 2 Apr 2024 21:44:15 +0100 Subject: [PATCH 1/3] Add big number shortening with unit to price logic --- .../dev/shorthouse/coinwatch/model/Price.kt | 81 +++++++++++++------ 1 file changed, 55 insertions(+), 26 deletions(-) diff --git a/app/src/main/java/dev/shorthouse/coinwatch/model/Price.kt b/app/src/main/java/dev/shorthouse/coinwatch/model/Price.kt index 96e13f87..3c09aaca 100644 --- a/app/src/main/java/dev/shorthouse/coinwatch/model/Price.kt +++ b/app/src/main/java/dev/shorthouse/coinwatch/model/Price.kt @@ -3,45 +3,74 @@ package dev.shorthouse.coinwatch.model import dev.shorthouse.coinwatch.common.toSanitisedBigDecimalOrZero import dev.shorthouse.coinwatch.data.preferences.global.Currency import java.math.BigDecimal +import java.math.MathContext +import java.math.RoundingMode import java.text.DecimalFormat -import java.util.Currency as CurrencyCode import java.util.Locale +import java.util.Currency as CurrencyCode data class Price(val price: String?, val currency: Currency = Currency.USD) : Comparable { - companion object { - private val precisionThreshold = BigDecimal("-1.00")..BigDecimal("1.00") + val amount: BigDecimal = price.toSanitisedBigDecimalOrZero() - private fun createCurrencyFormat(decimalPlaces: Int, currency: Currency): DecimalFormat { - val currencyFormat = DecimalFormat.getCurrencyInstance(Locale.US) as DecimalFormat + private val currencyFormat by lazy { + val currencyFormat = DecimalFormat.getCurrencyInstance(Locale.US) as DecimalFormat - currencyFormat.minimumFractionDigits = decimalPlaces - currencyFormat.maximumFractionDigits = decimalPlaces + val decimalPlaces = if (amount in belowOneThreshold) 6 else 2 + val currencyCode = try { + CurrencyCode.getInstance(currency.name) + } catch (e: IllegalArgumentException) { + CurrencyCode.getInstance(Currency.USD.name) + } - val currencyCode = try { - CurrencyCode.getInstance(currency.name) - } catch (e: IllegalArgumentException) { - CurrencyCode.getInstance(Currency.USD.name) - } - currencyFormat.currency = currencyCode + currencyFormat.minimumFractionDigits = decimalPlaces + currencyFormat.maximumFractionDigits = decimalPlaces + currencyFormat.currency = currencyCode - return currencyFormat - } + currencyFormat } - val amount: BigDecimal = price.toSanitisedBigDecimalOrZero() + val formattedAmount: String = when { + price.isNullOrBlank() -> "${currency.symbol}--" + amount in belowOneThreshold || amount in smallThreshold -> currencyFormat.format(amount) + else -> { + val roundedAmount = amount.round(MathContext(5, RoundingMode.HALF_EVEN)) - private val currencyFormat = if (amount in precisionThreshold) { - createCurrencyFormat(decimalPlaces = 6, currency = currency) - } else { - createCurrencyFormat(decimalPlaces = 2, currency = currency) - } + val divisor = when (roundedAmount) { + in millionThreshold -> million + in billionThreshold -> billion + in trillionThreshold -> trillion + in quadrillionThreshold -> quadrillion + else -> BigDecimal.ONE + } + + val symbol = when (roundedAmount) { + in millionThreshold -> "M" + in billionThreshold -> "B" + in trillionThreshold -> "T" + in quadrillionThreshold -> "Q" + else -> "" + } + + val shortenedAmount = amount.divide(divisor, 2, RoundingMode.HALF_EVEN) - val formattedAmount: String = when (price) { - null -> "${currency.symbol} --" - else -> currencyFormat.format(amount) + currencyFormat.format(shortenedAmount) + symbol + } } - override fun compareTo(other: Price): Int { - return amount.compareTo(other.amount) + override fun compareTo(other: Price) = amount.compareTo(other.amount) + + companion object { + private val million = BigDecimal("1000000") + private val billion = BigDecimal("1000000000") + private val trillion = BigDecimal("1000000000000") + private val quadrillion = BigDecimal("1000000000000000") + private val quintillion = BigDecimal("1000000000000000000") + + private val belowOneThreshold = BigDecimal("-1.00")..BigDecimal("1.00") + private val smallThreshold = BigDecimal("1.00").. Date: Tue, 2 Apr 2024 21:44:28 +0100 Subject: [PATCH 2/3] Add huge number of tests for number shortening logic --- .../shorthouse/coinwatch/model/PriceTest.kt | 434 +++++++++++++++++- 1 file changed, 423 insertions(+), 11 deletions(-) diff --git a/app/src/test/java/dev/shorthouse/coinwatch/model/PriceTest.kt b/app/src/test/java/dev/shorthouse/coinwatch/model/PriceTest.kt index 52a4f59f..a536a901 100644 --- a/app/src/test/java/dev/shorthouse/coinwatch/model/PriceTest.kt +++ b/app/src/test/java/dev/shorthouse/coinwatch/model/PriceTest.kt @@ -2,8 +2,8 @@ package dev.shorthouse.coinwatch.model import com.google.common.truth.Truth.assertThat import dev.shorthouse.coinwatch.data.preferences.global.Currency -import java.math.BigDecimal import org.junit.Test +import java.math.BigDecimal class PriceTest { @@ -17,11 +17,11 @@ class PriceTest { // Assert assertThat(price.amount).isEqualTo(BigDecimal.ZERO) - assertThat(price.formattedAmount).isEqualTo("$ --") + assertThat(price.formattedAmount).isEqualTo("$--") } @Test - fun `When empty input should create zero price`() { + fun `When empty input should create empty price`() { // Arrange val emptyPrice = "" @@ -30,7 +30,7 @@ class PriceTest { // Assert assertThat(price.amount).isEqualTo(BigDecimal.ZERO) - assertThat(price.formattedAmount).isEqualTo("$0.000000") + assertThat(price.formattedAmount).isEqualTo("$--") } @Test @@ -160,7 +160,7 @@ class PriceTest { // Assert assertThat(price.amount).isEqualTo(BigDecimal("123456789.12")) - assertThat(price.formattedAmount).isEqualTo("$123,456,789.12") + assertThat(price.formattedAmount).isEqualTo("$123.46M") } @Test @@ -173,7 +173,7 @@ class PriceTest { // Assert assertThat(price.amount).isEqualTo(BigDecimal("123456789.12")) - assertThat(price.formattedAmount).isEqualTo("$123,456,789.12") + assertThat(price.formattedAmount).isEqualTo("$123.46M") } @Test @@ -186,7 +186,7 @@ class PriceTest { // Assert assertThat(price.amount).isEqualTo(BigDecimal("123456789")) - assertThat(price.formattedAmount).isEqualTo("$123,456,789.00") + assertThat(price.formattedAmount).isEqualTo("$123.46M") } @Test @@ -219,7 +219,7 @@ class PriceTest { // Assert assertThat(price.amount).isEqualTo(BigDecimal("45678901.23")) - assertThat(price.formattedAmount).isEqualTo("$45,678,901.23") + assertThat(price.formattedAmount).isEqualTo("$45.68M") } @Test @@ -247,7 +247,7 @@ class PriceTest { // Assert assertThat(price.amount).isEqualTo(BigDecimal.ZERO) - assertThat(price.formattedAmount).isEqualTo("$ --") + assertThat(price.formattedAmount).isEqualTo("$--") } @Test @@ -275,7 +275,7 @@ class PriceTest { // Assert assertThat(price.amount).isEqualTo(BigDecimal.ZERO) - assertThat(price.formattedAmount).isEqualTo("£ --") + assertThat(price.formattedAmount).isEqualTo("£--") } @Test @@ -303,6 +303,418 @@ class PriceTest { // Assert assertThat(price.amount).isEqualTo(BigDecimal.ZERO) - assertThat(price.formattedAmount).isEqualTo("€ --") + assertThat(price.formattedAmount).isEqualTo("€--") + } + + @Test + fun `When comparing same price different scale should return equal`() { + // Arrange + val price1 = "100" + val price2 = "100.00" + + // Act + val priceNoDecimals = Price(price1) + val priceDecimals = Price(price2) + + // Assert + assertThat(priceNoDecimals.compareTo(priceDecimals)).isEqualTo(0) + } + + @Test + fun `When price just below a million should not perform shortening`() { + val price = "999999.99" + + val normalPrice = Price(price) + + assertThat(normalPrice.amount).isEqualTo(BigDecimal("999999.99")) + assertThat(normalPrice.formattedAmount).isEqualTo("$999,999.99") + } + + @Test + fun `When price just below million no decimal places should not perform shortening`() { + val price = "999999" + + val normalPrice = Price(price) + + assertThat(normalPrice.amount).isEqualTo(BigDecimal("999999")) + assertThat(normalPrice.formattedAmount).isEqualTo("$999,999.00") + } + + @Test + fun `When price is a million should perform shortening`() { + val price = "1000000.00" + + val millionPrice = Price(price) + + assertThat(millionPrice.amount).isEqualTo(BigDecimal("1000000.00")) + assertThat(millionPrice.formattedAmount).isEqualTo("$1.00M") + } + + @Test + fun `When price is a million no decimal places should perform shortening`() { + val price = "1000000" + + val millionPrice = Price(price) + + assertThat(millionPrice.amount).isEqualTo(BigDecimal("1000000")) + assertThat(millionPrice.formattedAmount).isEqualTo("$1.00M") + } + + @Test + fun `When price is random million value should perform shortening`() { + val price = "47234012" + + val millionPrice = Price(price) + + assertThat(millionPrice.amount).isEqualTo(BigDecimal("47234012")) + assertThat(millionPrice.formattedAmount).isEqualTo("$47.23M") + } + + @Test + fun `When price rounds to under a billion should perform million shortening`() { + val price = "999994999.99" + + val millionPrice = Price(price) + + assertThat(millionPrice.amount).isEqualTo(BigDecimal("999994999.99")) + assertThat(millionPrice.formattedAmount).isEqualTo("$999.99M") + } + + @Test + fun `When price rounds to under billion no decimal places should perform million shortening`() { + val price = "999994999" + + val millionPrice = Price(price) + + assertThat(millionPrice.amount).isEqualTo(BigDecimal("999994999")) + assertThat(millionPrice.formattedAmount).isEqualTo("$999.99M") + } + + @Test + fun `When price rounds to a billion should perform billion shortening`() { + val price = "999995000.00" + + val billionPrice = Price(price) + + assertThat(billionPrice.amount).isEqualTo(BigDecimal("999995000.00")) + assertThat(billionPrice.formattedAmount).isEqualTo("$1.00B") + } + + @Test + fun `When price rounds to a billion no decimal places should perform billion shortening`() { + val price = "999995000" + + val billionPrice = Price(price) + + assertThat(billionPrice.amount).isEqualTo(BigDecimal("999995000")) + assertThat(billionPrice.formattedAmount).isEqualTo("$1.00B") + } + + @Test + fun `When price is a billion should perform billion shortening`() { + val price = "1000000000.00" + + val billionPrice = Price(price) + + assertThat(billionPrice.amount).isEqualTo(BigDecimal("1000000000.00")) + assertThat(billionPrice.formattedAmount).isEqualTo("$1.00B") + } + + @Test + fun `When price is a billion no decimal places should perform billion shortening`() { + val price = "1000000000" + + val billionPrice = Price(price) + + assertThat(billionPrice.amount).isEqualTo(BigDecimal("1000000000")) + assertThat(billionPrice.formattedAmount).isEqualTo("$1.00B") + } + + @Test + fun `When price is a random billion should perform billion shortening`() { + val price = "139994238103.23" + + val billionPrice = Price(price) + + assertThat(billionPrice.amount).isEqualTo(BigDecimal("139994238103.23")) + assertThat(billionPrice.formattedAmount).isEqualTo("$139.99B") + } + + @Test + fun `When price is a random billion no decimal places should perform billion shortening`() { + val price = "139994238103" + + val billionPrice = Price(price) + + assertThat(billionPrice.amount).isEqualTo(BigDecimal("139994238103")) + assertThat(billionPrice.formattedAmount).isEqualTo("$139.99B") + } + + @Test + fun `When price rounds to under a trillion should perform billion shortening`() { + val price = "999994999999.99" + + val billionPrice = Price(price) + + assertThat(billionPrice.amount).isEqualTo(BigDecimal("999994999999.99")) + assertThat(billionPrice.formattedAmount).isEqualTo("$999.99B") + } + + @Test + fun `When price rounds to under trillion no decimal places should perform billion shortening`() { + val price = "999994999999" + + val billionPrice = Price(price) + + assertThat(billionPrice.amount).isEqualTo(BigDecimal("999994999999")) + assertThat(billionPrice.formattedAmount).isEqualTo("$999.99B") + } + + @Test + fun `When price rounds to trillion should perform trillion shortening`() { + val price = "999995000000.00" + + val trillionPrice = Price(price) + + assertThat(trillionPrice.amount).isEqualTo(BigDecimal("999995000000.00")) + assertThat(trillionPrice.formattedAmount).isEqualTo("$1.00T") + } + + @Test + fun `When price rounds to trillion no decimal places should perform trillion shortening`() { + val price = "999995000000" + + val trillionPrice = Price(price) + + assertThat(trillionPrice.amount).isEqualTo(BigDecimal("999995000000")) + assertThat(trillionPrice.formattedAmount).isEqualTo("$1.00T") + } + + @Test + fun `When price is a trillion should perform trillion shortening`() { + val price = "1000000000000.00" + + val trillionPrice = Price(price) + + assertThat(trillionPrice.amount).isEqualTo(BigDecimal("1000000000000.00")) + assertThat(trillionPrice.formattedAmount).isEqualTo("$1.00T") + } + + @Test + fun `When price is a trillion no decimal places should perform trillion shortening`() { + val price = "1000000000000" + + val trillionPrice = Price(price) + + assertThat(trillionPrice.amount).isEqualTo(BigDecimal("1000000000000")) + assertThat(trillionPrice.formattedAmount).isEqualTo("$1.00T") + } + + @Test + fun `When price is a random trillion should perform trillion shortening`() { + val price = "12812423810323.23" + + val trillionPrice = Price(price) + + assertThat(trillionPrice.amount).isEqualTo(BigDecimal("12812423810323.23")) + assertThat(trillionPrice.formattedAmount).isEqualTo("$12.81T") + } + + @Test + fun `When price is a random trillion no decimal places should perform trillion shortening`() { + val price = "12812423810323" + + val trillionPrice = Price(price) + + assertThat(trillionPrice.amount).isEqualTo(BigDecimal("12812423810323")) + assertThat(trillionPrice.formattedAmount).isEqualTo("$12.81T") + } + + @Test + fun `When price rounds to under a quadrillion should perform trillion shortening`() { + val price = "999994999999999.99" + + val trillionPrice = Price(price) + + assertThat(trillionPrice.amount).isEqualTo(BigDecimal("999994999999999.99")) + assertThat(trillionPrice.formattedAmount).isEqualTo("$999.99T") + } + + @Test + fun `When price rounds to under quadrillion no decimal places should perform trillion shortening`() { + val price = "999994999999999" + + val trillionPrice = Price(price) + + assertThat(trillionPrice.amount).isEqualTo(BigDecimal("999994999999999")) + assertThat(trillionPrice.formattedAmount).isEqualTo("$999.99T") + } + + @Test + fun `When price rounds to a quadrillion should perform quadrillion shortening`() { + val price = "999995000000000.00" + + val quadrillionPrice = Price(price) + + assertThat(quadrillionPrice.amount).isEqualTo(BigDecimal("999995000000000.00")) + assertThat(quadrillionPrice.formattedAmount).isEqualTo("$1.00Q") + } + + @Test + fun `When price rounds to a quadrillion no decimal places should perform quadrillion shortening`() { + val price = "999995000000000" + + val quadrillionPrice = Price(price) + + assertThat(quadrillionPrice.amount).isEqualTo(BigDecimal("999995000000000")) + assertThat(quadrillionPrice.formattedAmount).isEqualTo("$1.00Q") + } + + @Test + fun `When price is a quadrillion should perform quadrillion shortening`() { + val price = "1000000000000000.00" + + val quadrillionPrice = Price(price) + + assertThat(quadrillionPrice.amount).isEqualTo(BigDecimal("1000000000000000.00")) + assertThat(quadrillionPrice.formattedAmount).isEqualTo("$1.00Q") + } + + @Test + fun `When price is a quadrillion no decimal places should perform quadrillion shortening`() { + val price = "1000000000000000" + + val quadrillionPrice = Price(price) + + assertThat(quadrillionPrice.amount).isEqualTo(BigDecimal("1000000000000000")) + assertThat(quadrillionPrice.formattedAmount).isEqualTo("$1.00Q") + } + + @Test + fun `When price is a random quadrillion should perform quadrillion shortening`() { + val price = "91812812423810323.47" + + val quadrillionPrice = Price(price) + + assertThat(quadrillionPrice.amount).isEqualTo(BigDecimal("91812812423810323.47")) + assertThat(quadrillionPrice.formattedAmount).isEqualTo("$91.81Q") + } + + @Test + fun `When price is a random quadrillion no decimal places should perform quadrillion shortening`() { + val price = "91812812423810323" + + val quadrillionPrice = Price(price) + + assertThat(quadrillionPrice.amount).isEqualTo(BigDecimal("91812812423810323")) + assertThat(quadrillionPrice.formattedAmount).isEqualTo("$91.81Q") + } + + @Test + fun `When price rounds to under a quintillion should perform quadrillion shortening`() { + val price = "999994999999999999.99" + + val quadrillionPrice = Price(price) + + assertThat(quadrillionPrice.amount).isEqualTo(BigDecimal("999994999999999999.99")) + assertThat(quadrillionPrice.formattedAmount).isEqualTo("$999.99Q") + } + + @Test + fun `When price rounds to under quintillion no decimal places should perform quadrillion shortening`() { + val price = "999994999999999999" + + val quadrillionPrice = Price(price) + + assertThat(quadrillionPrice.amount).isEqualTo(BigDecimal("999994999999999999")) + assertThat(quadrillionPrice.formattedAmount).isEqualTo("$999.99Q") + } + + @Test + fun `When price rounds to quintillion should perform no shortening`() { + val price = "999999500000000000.00" + + val noShortenPrice = Price(price) + + assertThat(noShortenPrice.amount).isEqualTo(BigDecimal("999999500000000000.00")) + assertThat(noShortenPrice.formattedAmount).isEqualTo("$999,999,500,000,000,000.00") + } + + @Test + fun `When price rounds to quintillion no decimal places should perform no shortening`() { + val price = "999999500000000000" + + val noShortenPrice = Price(price) + + assertThat(noShortenPrice.amount).isEqualTo(BigDecimal("999999500000000000")) + assertThat(noShortenPrice.formattedAmount).isEqualTo("$999,999,500,000,000,000.00") + } + + @Test + fun `When price is a quintillion should perform no shortening`() { + val price = "1000000000000000000.00" + + val noShortenPrice = Price(price) + + assertThat(noShortenPrice.amount).isEqualTo(BigDecimal("1000000000000000000.00")) + assertThat(noShortenPrice.formattedAmount).isEqualTo("$1,000,000,000,000,000,000.00") + } + + @Test + fun `When price is a quintillion no decimal places should perform no shortening`() { + val price = "1000000000000000000" + + val noShortenPrice = Price(price) + + assertThat(noShortenPrice.amount).isEqualTo(BigDecimal("1000000000000000000")) + assertThat(noShortenPrice.formattedAmount).isEqualTo("$1,000,000,000,000,000,000.00") + } + + @Test + fun `When price is shortened with GBP currency should shorten correctly`() { + val price1 = "231,842.94" + val price2 = "49491394.23440234" + val price3 = " 1009900243 " + val price4 = "3084938574102" + val price5 = "27913084938574102" + val price6 = "149227913084938574102" + + val normalPrice = Price(price1, Currency.GBP) + val millionPrice = Price(price2, Currency.GBP) + val billionPrice = Price(price3, Currency.GBP) + val trillionPrice = Price(price4, Currency.GBP) + val quadrillionPrice = Price(price5, Currency.GBP) + val quintillionPrice = Price(price6, Currency.GBP) + + assertThat(normalPrice.formattedAmount).isEqualTo("£231,842.94") + assertThat(millionPrice.formattedAmount).isEqualTo("£49.49M") + assertThat(billionPrice.formattedAmount).isEqualTo("£1.01B") + assertThat(trillionPrice.formattedAmount).isEqualTo("£3.08T") + assertThat(quadrillionPrice.formattedAmount).isEqualTo("£27.91Q") + assertThat(quintillionPrice.formattedAmount).isEqualTo("£149,227,913,084,938,574,102.00") + } + + @Test + fun `When price is shortened with EUR currency should shorten correctly`() { + val price1 = "231,842.94" + val price2 = "49491394.23440234" + val price3 = " 1009900243 " + val price4 = "3084938574102" + val price5 = "27913084938574102" + val price6 = "149227913084938574102" + + val normalPrice = Price(price1, Currency.EUR) + val millionPrice = Price(price2, Currency.EUR) + val billionPrice = Price(price3, Currency.EUR) + val trillionPrice = Price(price4, Currency.EUR) + val quadrillionPrice = Price(price5, Currency.EUR) + val quintillionPrice = Price(price6, Currency.EUR) + + assertThat(normalPrice.formattedAmount).isEqualTo("€231,842.94") + assertThat(millionPrice.formattedAmount).isEqualTo("€49.49M") + assertThat(billionPrice.formattedAmount).isEqualTo("€1.01B") + assertThat(trillionPrice.formattedAmount).isEqualTo("€3.08T") + assertThat(quadrillionPrice.formattedAmount).isEqualTo("€27.91Q") + assertThat(quintillionPrice.formattedAmount).isEqualTo("€149,227,913,084,938,574,102.00") } } From c9f30fbb2d403bd390d7db7a7d8958057c76ca08 Mon Sep 17 00:00:00 2001 From: "Harry S (Macbook)" Date: Tue, 2 Apr 2024 21:44:41 +0100 Subject: [PATCH 3/3] Update details screen test with number shortening logic --- .../coinwatch/ui/screen/DetailsScreenTest.kt | 97 ++++++++++++++++++- 1 file changed, 93 insertions(+), 4 deletions(-) diff --git a/app/src/androidTest/java/dev/shorthouse/coinwatch/ui/screen/DetailsScreenTest.kt b/app/src/androidTest/java/dev/shorthouse/coinwatch/ui/screen/DetailsScreenTest.kt index b4cb3a0e..9fc61476 100644 --- a/app/src/androidTest/java/dev/shorthouse/coinwatch/ui/screen/DetailsScreenTest.kt +++ b/app/src/androidTest/java/dev/shorthouse/coinwatch/ui/screen/DetailsScreenTest.kt @@ -169,9 +169,9 @@ class DetailsScreenTest { onNodeWithText("Market Cap Rank").assertIsDisplayed() onNodeWithText("2").assertIsDisplayed() onNodeWithText("Market Cap").assertIsDisplayed() - onNodeWithText("$225,722,901,094.00").assertIsDisplayed() + onNodeWithText("$225.72B").assertIsDisplayed() onNodeWithText("Volume (24h)").assertIsDisplayed() - onNodeWithText("$6,627,669,115.00").assertIsDisplayed() + onNodeWithText("$6.63B").assertIsDisplayed() onNodeWithText("Circulating Supply").assertIsDisplayed() onNodeWithText("120,186,525").assertIsDisplayed() onNodeWithText("All Time High").assertIsDisplayed() @@ -518,9 +518,9 @@ class DetailsScreenTest { onNodeWithText("Market Cap Rank").assertIsDisplayed() onNodeWithText("2").assertIsDisplayed() onNodeWithText("Market Cap").assertIsDisplayed() - onNodeWithText("£225,722,901,094.00").assertIsDisplayed() + onNodeWithText("£225.72B").assertIsDisplayed() onNodeWithText("Volume (24h)").assertIsDisplayed() - onNodeWithText("$6,627,669,115.00").assertIsDisplayed() + onNodeWithText("$6.63B").assertIsDisplayed() onNodeWithText("Circulating Supply").assertIsDisplayed() onNodeWithText("120,186,525").assertIsDisplayed() onNodeWithText("All Time High ($)").assertIsDisplayed() @@ -531,4 +531,93 @@ class DetailsScreenTest { onNodeWithText("7 Aug 2015").assertIsDisplayed() } } + + @Test + fun when_pricesAreLarge_should_showShortenedPrices() { + val uiStateSuccess = DetailsUiState.Success( + CoinDetails( + id = "ethereum", + name = "Ethereum", + symbol = "ETH", + imageUrl = "https://cdn.coinranking.com/rk4RKHOuW/eth.svg", + currentPrice = Price("1879.14"), + marketCap = Price("49491394.23440234"), + marketCapRank = "2", + volume24h = Price("1009900243"), + circulatingSupply = "120,186,525", + allTimeHigh = Price("3084938574102"), + allTimeHighDate = "10 Nov 2021", + listedDate = "7 Aug 2015" + ), + CoinChart( + prices = persistentListOf( + BigDecimal("1755.19"), + BigDecimal("1749.71"), + BigDecimal("1750.94"), + BigDecimal("1748.44"), + BigDecimal("1743.98"), + BigDecimal("1740.25") + ), + minPrice = Price("1632.46"), + maxPrice = Price("1922.83"), + periodPriceChangePercentage = Percentage("7.06") + ), + chartPeriod = ChartPeriod.Day, + isCoinFavourite = true + ) + + composeTestRule.setContent { + AppTheme { + DetailsScreen( + uiState = uiStateSuccess, + onNavigateUp = {}, + onClickFavouriteCoin = {}, + onClickChartPeriod = {} + ) + } + } + + composeTestRule.apply { + onNodeWithContentDescription("Back").assertIsDisplayed() + onNodeWithContentDescription("Favourite").assertIsDisplayed() + + onNodeWithText("Ethereum").assertIsDisplayed() + onNodeWithText("ETH").assertIsDisplayed() + onNodeWithText("$1,879.14").assertIsDisplayed() + onNodeWithText("+7.06%").assertIsDisplayed() + onNodeWithText("Past day").assertIsDisplayed() + + onNodeWithText("1H").assertIsDisplayed() + onNodeWithText("1D").assertIsDisplayed() + onNodeWithText("1W").assertIsDisplayed() + onNodeWithText("1M").assertIsDisplayed() + onNodeWithText("3M").assertIsDisplayed() + onNodeWithText("1Y").assertIsDisplayed() + onNodeWithText("5Y").assertIsDisplayed() + + onNodeWithText("Chart Range").assertIsDisplayed() + onNodeWithText("Low").assertIsDisplayed() + onNodeWithText("$1,632.46").assertIsDisplayed() + onNodeWithText("High").assertIsDisplayed() + onNodeWithText("$1,922.83").assertIsDisplayed() + + onNodeWithText("7 Aug 2015").performScrollTo() + + onNodeWithText("Market Stats").assertIsDisplayed() + onNodeWithText("Market Cap Rank").assertIsDisplayed() + onNodeWithText("2").assertIsDisplayed() + onNodeWithText("Market Cap").assertIsDisplayed() + onNodeWithText("$49.49M").assertIsDisplayed() + onNodeWithText("Volume (24h)").assertIsDisplayed() + onNodeWithText("$1.01B").assertIsDisplayed() + onNodeWithText("Circulating Supply").assertIsDisplayed() + onNodeWithText("120,186,525").assertIsDisplayed() + onNodeWithText("All Time High").assertIsDisplayed() + onNodeWithText("$3.08T").assertIsDisplayed() + onNodeWithText("All Time High Date").assertIsDisplayed() + onNodeWithText("10 Nov 2021").assertIsDisplayed() + onNodeWithText("Listed Date").assertIsDisplayed() + onNodeWithText("7 Aug 2015").assertIsDisplayed() + } + } }