mirror of
https://github.com/hmalik144/Weather-apps.git
synced 2026-03-18 15:36:04 +00:00
Imperial units (#24)
- change location retrieval accuracy - change location retrieval caching from location provider - expand unit test suite - code refactoring - Imperial units added - UI test for unit change
This commit is contained in:
@@ -0,0 +1,48 @@
|
||||
package com.appttude.h_mal.monoWeather.robot
|
||||
|
||||
import androidx.recyclerview.widget.RecyclerView.ViewHolder
|
||||
import androidx.test.espresso.Espresso.onView
|
||||
import androidx.test.espresso.action.ViewActions.click
|
||||
import androidx.test.espresso.assertion.ViewAssertions
|
||||
import androidx.test.espresso.contrib.RecyclerViewActions
|
||||
import androidx.test.espresso.matcher.RootMatchers.isDialog
|
||||
import androidx.test.espresso.matcher.ViewMatchers
|
||||
import androidx.test.espresso.matcher.ViewMatchers.withId
|
||||
import androidx.test.espresso.matcher.ViewMatchers.withText
|
||||
import com.appttude.h_mal.atlas_weather.BaseTestRobot
|
||||
import com.appttude.h_mal.atlas_weather.R
|
||||
import com.appttude.h_mal.atlas_weather.model.types.UnitType
|
||||
|
||||
|
||||
fun settingsScreen(func: SettingsScreen.() -> Unit) = SettingsScreen().apply { func() }
|
||||
class SettingsScreen : BaseTestRobot() {
|
||||
|
||||
fun selectWeatherUnits(unitType: UnitType) {
|
||||
onView(withId(androidx.preference.R.id.recycler_view))
|
||||
.perform(
|
||||
RecyclerViewActions.actionOnItem<ViewHolder>(
|
||||
ViewMatchers.hasDescendant(withText(R.string.weather_units)),
|
||||
click()))
|
||||
val label = when (unitType) {
|
||||
UnitType.METRIC -> "Metric"
|
||||
UnitType.IMPERIAL -> "Imperial"
|
||||
}
|
||||
|
||||
onView(withText(label))
|
||||
.inRoot(isDialog())
|
||||
.check(ViewAssertions.matches(ViewMatchers.isDisplayed()))
|
||||
.perform(click())
|
||||
}
|
||||
|
||||
|
||||
fun verifyCurrentTemperature(temperature: Int) =
|
||||
matchText(R.id.temp_main_4, temperature.toString())
|
||||
|
||||
fun verifyCurrentLocation(location: String) = matchText(R.id.location_main_4, location)
|
||||
fun refresh() = pullToRefresh(R.id.swipe_refresh)
|
||||
|
||||
fun verifyUnableToRetrieve() {
|
||||
matchText(R.id.header_text, R.string.retrieve_warning)
|
||||
matchText(R.id.body_text, R.string.empty_retrieve_warning)
|
||||
}
|
||||
}
|
||||
@@ -2,8 +2,10 @@ package com.appttude.h_mal.monoWeather.tests
|
||||
|
||||
|
||||
import com.appttude.h_mal.atlas_weather.BaseTest
|
||||
import com.appttude.h_mal.atlas_weather.model.types.UnitType
|
||||
import com.appttude.h_mal.atlas_weather.ui.MainActivity
|
||||
import com.appttude.h_mal.atlas_weather.utils.Stubs
|
||||
import com.appttude.h_mal.monoWeather.robot.settingsScreen
|
||||
import com.appttude.h_mal.monoWeather.robot.weatherScreen
|
||||
import org.junit.Test
|
||||
|
||||
@@ -11,6 +13,7 @@ class HomePageUITest : BaseTest<MainActivity>(MainActivity::class.java) {
|
||||
|
||||
override fun beforeLaunch() {
|
||||
stubEndpoint("https://api.openweathermap.org/data/2.5/onecall", Stubs.Metric)
|
||||
clearPrefs()
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -21,4 +24,25 @@ class HomePageUITest : BaseTest<MainActivity>(MainActivity::class.java) {
|
||||
verifyCurrentLocation("Mock Location")
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
fun loadApp_changeToImperial_returnsValidPage() {
|
||||
weatherScreen {
|
||||
isDisplayed()
|
||||
verifyCurrentTemperature(2)
|
||||
verifyCurrentLocation("Mock Location")
|
||||
stubEndpoint("https://api.openweathermap.org/data/2.5/onecall", Stubs.Imperial)
|
||||
openMenuItem()
|
||||
}
|
||||
settingsScreen {
|
||||
selectWeatherUnits(UnitType.IMPERIAL)
|
||||
goBack()
|
||||
}
|
||||
weatherScreen {
|
||||
isDisplayed()
|
||||
refresh()
|
||||
verifyCurrentTemperature(58)
|
||||
verifyCurrentLocation("Mock Location")
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user