From c9f30fbb2d403bd390d7db7a7d8958057c76ca08 Mon Sep 17 00:00:00 2001 From: "Harry S (Macbook)" Date: Tue, 2 Apr 2024 21:44:41 +0100 Subject: [PATCH] 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() + } + } }