Skip to content

Commit

Permalink
Add temperature estimation tests
Browse files Browse the repository at this point in the history
  • Loading branch information
kylecorry31 committed Aug 13, 2024
1 parent d241e0d commit b3ff987
Show file tree
Hide file tree
Showing 2 changed files with 69 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -220,6 +220,8 @@ object TestUtils {
prefs.putBoolean(context.getString(R.string.pref_main_disclaimer_shown_key), true)
prefs.putBoolean(context.getString(R.string.pref_require_satellites), false)
prefs.putBoolean(context.getString(R.string.pref_cliff_height_enabled), true)
prefs.putString(context.getString(R.string.pref_altimeter_calibration_mode), "gps")
prefs.putInt(context.getString(R.string.pref_altimeter_accuracy), 1)

val userPrefs = UserPreferences(context)
// The settings tool is the fastest to get to idle, which allows the tests to run faster
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
package com.kylecorry.trail_sense.tools.temperature_estimation

import androidx.arch.core.executor.testing.InstantTaskExecutorRule
import com.kylecorry.luna.text.toFloatCompat
import com.kylecorry.trail_sense.R
import com.kylecorry.trail_sense.test_utils.TestUtils
import com.kylecorry.trail_sense.test_utils.TestUtils.waitFor
import com.kylecorry.trail_sense.test_utils.views.click
import com.kylecorry.trail_sense.test_utils.views.hasText
import com.kylecorry.trail_sense.test_utils.views.input
import com.kylecorry.trail_sense.test_utils.views.view
import com.kylecorry.trail_sense.tools.tools.infrastructure.Tools
import dagger.hilt.android.testing.HiltAndroidRule
import dagger.hilt.android.testing.HiltAndroidTest
import org.junit.Before
import org.junit.Rule
import org.junit.Test

@HiltAndroidTest
class ToolTemperatureEstimationTest {

@get:Rule
var hiltRule = HiltAndroidRule(this)

@get:Rule
val grantPermissionRule = TestUtils.mainPermissionsGranted()

@get:Rule
val instantExec = InstantTaskExecutorRule()

@Before
fun setUp() {
hiltRule.inject()
TestUtils.setWaitForIdleTimeout(100)
TestUtils.setupApplication()
TestUtils.startWithTool(Tools.TEMPERATURE_ESTIMATION)
}

@Test
fun verifyBasicFunctionality() {
waitFor {
view(R.id.temperature_title)
}

view(R.id.temp_est_base_elevation, R.id.amount).input("100")
view(R.id.temp_est_dest_elevation, R.id.amount).input("1000")
view(R.id.temp_est_base_temperature, R.id.amount).input("15")

view(R.id.temperature_title).hasText("12 °F")

// Clear all views
view(R.id.temp_est_base_elevation, R.id.amount).input("")
view(R.id.temp_est_base_temperature, R.id.amount).input("")

// Autofill
view(R.id.temp_est_autofill).click()

waitFor(12000) {
view(R.id.temp_est_base_elevation, R.id.amount).hasText {
it.split(",").first().toFloatCompat() != null
}
view(R.id.temp_est_base_temperature, R.id.amount).hasText {
it.split(",").first().toFloatCompat() != null
}
}
}
}

0 comments on commit b3ff987

Please sign in to comment.