|
1 | 1 | package dev.johnoreilly.climatetrace.screen |
2 | 2 |
|
3 | | -import androidx.compose.material3.Text |
4 | 3 | import androidx.compose.ui.test.ExperimentalTestApi |
5 | 4 | import androidx.compose.ui.test.onNodeWithText |
6 | 5 | import androidx.compose.ui.test.runComposeUiTest |
7 | 6 | import dev.johnoreilly.climatetrace.remote.Country |
| 7 | +import dev.johnoreilly.climatetrace.remote.CountryEmissionsInfo |
| 8 | +import dev.johnoreilly.climatetrace.remote.EmissionInfo |
| 9 | +import dev.johnoreilly.climatetrace.ui.CountryInfoDetailedView |
8 | 10 | import dev.johnoreilly.climatetrace.ui.CountryListView |
| 11 | +import dev.johnoreilly.climatetrace.ui.toPercent |
| 12 | +import dev.johnoreilly.climatetrace.viewmodel.CountryDetailsUIState |
9 | 13 | import kotlin.test.Test |
10 | 14 |
|
11 | 15 | @OptIn(ExperimentalTestApi::class) |
12 | 16 | class ClimateTraceScreenTest { |
13 | | - private val countryList = listOf<Country>(Country("IRL", "IE", "Ireland", "Europe")) |
| 17 | + private val country = Country("IRL", "IE", "Ireland", "Europe") |
| 18 | + private val countryList = listOf<Country>(country) |
| 19 | + private val countryEmissions = EmissionInfo(53_000_000.0f, 75_000_000.0f, 100_000_000.0f) |
| 20 | + private val worldEmissions = EmissionInfo(53_000_000_000.0f, 75_000_000_000.0f, 100_000_000_000.0f) |
| 21 | + private val countryEmissionsInfo = CountryEmissionsInfo(country = country.alpha3, |
| 22 | + rank = 73, emissions = countryEmissions, worldEmissions = worldEmissions) |
| 23 | + private val year = "2022" |
14 | 24 |
|
15 | 25 | @Test |
16 | | - fun testCountryListScreen() = runComposeUiTest { |
| 26 | + fun testCountryListView() = runComposeUiTest { |
17 | 27 | setContent { |
18 | 28 | CountryListView(countryList, null, {}) |
19 | 29 | } |
20 | 30 |
|
21 | | - onNodeWithText("Ireland").assertExists() |
| 31 | + onNodeWithText(country.name).assertExists() |
22 | 32 | } |
| 33 | + |
| 34 | + |
| 35 | + @Test |
| 36 | + fun testCountryInfoDetailsView() = runComposeUiTest { |
| 37 | + val state = CountryDetailsUIState.Success(country, |
| 38 | + year, countryEmissionsInfo, emptyList() |
| 39 | + ) |
| 40 | + setContent { |
| 41 | + CountryInfoDetailedView(state, {}) |
| 42 | + } |
| 43 | + |
| 44 | + onNodeWithText(country.name).assertExists() |
| 45 | + val millionTonnes = (countryEmissions.co2 / 1_000_000).toInt() |
| 46 | + val percentage = (countryEmissions.co2 / worldEmissions.co2).toPercent(2) |
| 47 | + onNodeWithText("co2 = $millionTonnes Million Tonnes ($year)").assertExists() |
| 48 | + onNodeWithText("rank = ${countryEmissionsInfo.rank} ($percentage)").assertExists() |
| 49 | + } |
| 50 | + |
23 | 51 | } |
24 | 52 |
|
0 commit comments