Skip to content

Commit 8b51000

Browse files
authored
Used persisted UI connection state when saving. Fixes #450. (#452)
* Increased emulator version to 35.
1 parent 186d380 commit 8b51000

File tree

18 files changed

+310
-43
lines changed

18 files changed

+310
-43
lines changed

.github/workflows/android.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,7 @@ jobs:
9292
- name: Run connected tests
9393
uses: ReactiveCircus/android-emulator-runner@v2
9494
with:
95-
api-level: 28
95+
api-level: 35
9696
target: google_apis
9797
arch: x86_64
9898
profile: Nexus 6

.github/workflows/script/run_tests.sh

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,10 @@
11
#!/bin/bash
22

33
set +e
4-
./gradlew connectedCheck --no-daemon
4+
./gradlew assembleDebug assembleDebugAndroidTest --no-daemon
5+
adb install app/build/outputs/apk/espresso/app-espresso.apk
6+
adb install app/build/outputs/apk/androidTest/espresso/app-espresso-androidTest.apk
7+
adb shell am instrument -w -m -e debug false \\n -e class 'com.mitteloupe.whoami.suite.SmokeTests' \\ncom.mitteloupe.whoami.test/com.mitteloupe.whoami.di.HiltTestRunner
58
GRADLE_EXIT_CODE=$?
69
set -e
710

app/src/androidTest/java/com/mitteloupe/whoami/launcher/FromScreen.kt

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -14,12 +14,10 @@ fun <ACTIVITY : AppCompatActivity> fromScreen(
1414
) = AppLauncher {
1515
fromComposable(composeContentTestRule) { activity ->
1616
WhoAmITheme {
17-
with(testAppDependenciesEntryPoint(activity).appNavHostDependencies) {
18-
AppNavHost(
19-
supportFragmentManager = activity.supportFragmentManager,
20-
startDestination = startDestination
21-
)
22-
}
17+
testAppDependenciesEntryPoint(activity).appNavHostDependencies.AppNavHost(
18+
supportFragmentManager = activity.supportFragmentManager,
19+
startDestination = startDestination
20+
)
2321
}
2422
}.launch()
2523
}

app/src/androidTest/java/com/mitteloupe/whoami/screen/HistoryScreen.kt

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ package com.mitteloupe.whoami.screen
22

33
import androidx.recyclerview.widget.RecyclerView
44
import androidx.recyclerview.widget.RecyclerView.ViewHolder
5+
import androidx.test.espresso.Espresso
56
import androidx.test.espresso.Espresso.onView
67
import androidx.test.espresso.assertion.ViewAssertions.matches
78
import androidx.test.espresso.contrib.RecyclerViewActions.actionOnItemAtPosition
@@ -72,14 +73,23 @@ class HistoryScreen {
7273
)
7374
}
7475

75-
fun tapDeleteForRecord(position: Int) {
76+
fun seeRecord(position: Int, ipAddress: String, city: String, postCode: String) {
77+
seeIpRecord(ipAddress = ipAddress, position = position)
78+
seeLocation(city = city, postCode = postCode, position = position)
79+
}
80+
81+
fun tapDeleteButtonForRecord(position: Int) {
7682
onView(recordsList)
7783
.perform(scrollToPosition<ViewHolder>(position.zeroBased))
7884
.perform(
7985
actionOnItemAtPosition<ViewHolder>(position.zeroBased, clickChildView(deleteButton))
8086
)
8187
}
8288

89+
fun tapBackButton() {
90+
Espresso.pressBack()
91+
}
92+
8393
private val Int.zeroBased
8494
get() = this - 1
8595
}

app/src/androidTest/java/com/mitteloupe/whoami/screen/HomeScreen.kt

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ class HomeScreen {
2020
private val postCodeLabel = hasText("CM14")
2121
private val timeZoneLabel = hasText("Europe/London")
2222
private val internetServiceProviderLabel = hasText("TalkTalk Limited")
23+
private val saveDetailsButton = hasText("Save Details")
2324
private val openSourceNoticesButton = hasText("Open Source Notices")
2425

2526
fun ComposeContentTestRule.seeIpAddressLabel() {
@@ -58,7 +59,11 @@ class HomeScreen {
5859
assertIsDisplayed(internetServiceProviderLabel)
5960
}
6061

61-
fun ComposeContentTestRule.tapOpenSourceNotices() {
62+
fun ComposeContentTestRule.tapSaveDetailsButton() {
63+
onNode(saveDetailsButton).performTouchInput { click() }
64+
}
65+
66+
fun ComposeContentTestRule.tapOpenSourceNoticesButton() {
6267
onNode(openSourceNoticesButton).performTouchInput { click() }
6368
}
6469

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
package com.mitteloupe.whoami.suite
2+
3+
import androidx.compose.ui.test.ExperimentalTestApi
4+
import com.mitteloupe.whoami.test.HistoryHighlightedIpAddressTest
5+
import com.mitteloupe.whoami.test.HistoryTest
6+
import com.mitteloupe.whoami.test.HomeTest
7+
import org.junit.runner.RunWith
8+
import org.junit.runners.Suite
9+
import org.junit.runners.Suite.SuiteClasses
10+
11+
@OptIn(ExperimentalTestApi::class)
12+
@RunWith(Suite::class)
13+
@SuiteClasses(
14+
HistoryTest::class,
15+
HistoryHighlightedIpAddressTest::class,
16+
HomeTest::class
17+
)
18+
class SmokeTests

app/src/androidTest/java/com/mitteloupe/whoami/test/HistoryHighlightedIpAddressTest.kt

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -52,14 +52,4 @@ class HistoryHighlightedIpAddressTest : BaseTest() {
5252
seeNonHighlightedRecord(ipAddress = ipAddress2, position = 2)
5353
}
5454
}
55-
56-
private fun HistoryScreen.seeRecord(
57-
position: Int,
58-
ipAddress: String,
59-
city: String,
60-
postCode: String
61-
) {
62-
seeIpRecord(ipAddress = ipAddress, position = position)
63-
seeLocation(city = city, postCode = postCode, position = position)
64-
}
6555
}

app/src/androidTest/java/com/mitteloupe/whoami/test/HistoryTest.kt

Lines changed: 1 addition & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ class HistoryTest : BaseTest() {
6363
)
6464
}
6565
seeRecord(position = 2, ipAddress = "1.1.1.1", city = "Aberdeen", postCode = "AA11 2BB")
66-
tapDeleteForRecord(position = 1)
66+
tapDeleteButtonForRecord(position = 1)
6767
retry(repeat = 20) {
6868
seeRecord(
6969
position = 1,
@@ -92,14 +92,4 @@ class HistoryTest : BaseTest() {
9292
}
9393
}
9494
}
95-
96-
private fun HistoryScreen.seeRecord(
97-
position: Int,
98-
ipAddress: String,
99-
city: String,
100-
postCode: String
101-
) {
102-
seeIpRecord(ipAddress = ipAddress, position = position)
103-
seeLocation(city = city, postCode = postCode, position = position)
104-
}
10595
}
Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
1+
package com.mitteloupe.whoami.test
2+
3+
import androidx.compose.ui.test.ExperimentalTestApi
4+
import androidx.compose.ui.test.junit4.createAndroidComposeRule
5+
import com.mitteloupe.whoami.di.TestActivity
6+
import com.mitteloupe.whoami.launcher.fromScreen
7+
import com.mitteloupe.whoami.localstore.KEY_VALUE_NO_HISTORY
8+
import com.mitteloupe.whoami.screen.HistoryScreen
9+
import com.mitteloupe.whoami.screen.HomeScreen
10+
import com.mitteloupe.whoami.server.REQUEST_RESPONSE_GET_IP
11+
import com.mitteloupe.whoami.server.REQUEST_RESPONSE_GET_IP_DETAILS
12+
import com.mitteloupe.whoami.test.annotation.LocalStore
13+
import com.mitteloupe.whoami.test.annotation.ServerRequestResponse
14+
import com.mitteloupe.whoami.test.launcher.AppLauncher
15+
import com.mitteloupe.whoami.test.test.BaseTest
16+
import com.mitteloupe.whoami.test.test.retry
17+
import com.mitteloupe.whoami.ui.main.route.Home
18+
import dagger.hilt.android.testing.HiltAndroidTest
19+
import javax.inject.Inject
20+
import org.junit.Test
21+
22+
@HiltAndroidTest
23+
@ExperimentalTestApi
24+
class HomeSaveRecordTest : BaseTest() {
25+
override val composeTestRule = createAndroidComposeRule<TestActivity>()
26+
27+
override val startActivityLauncher: AppLauncher by lazy {
28+
fromScreen(composeTestRule, Home)
29+
}
30+
31+
@Inject
32+
lateinit var homeScreen: HomeScreen
33+
34+
@Inject
35+
lateinit var historyScreen: HistoryScreen
36+
37+
@Test
38+
@ServerRequestResponse([REQUEST_RESPONSE_GET_IP, REQUEST_RESPONSE_GET_IP_DETAILS])
39+
@LocalStore(localStoreDataIds = [KEY_VALUE_NO_HISTORY])
40+
fun givenConnectedWhenNavigatingAwayAndBackThenSavesRecord() {
41+
with(composeTestRule) {
42+
with(homeScreen) {
43+
seeCityLabel()
44+
tapSaveDetailsButton()
45+
}
46+
47+
with(historyScreen) {
48+
retry(repeat = 20) {
49+
seeRecord(
50+
position = 1,
51+
ipAddress = "1.2.3.4",
52+
city = "Brentwood",
53+
postCode = "CM14"
54+
)
55+
}
56+
tapBackButton()
57+
}
58+
59+
with(homeScreen) {
60+
seeCityLabel()
61+
tapSaveDetailsButton()
62+
}
63+
64+
with(historyScreen) {
65+
retry(repeat = 20) {
66+
seeRecord(
67+
position = 1,
68+
ipAddress = "1.2.3.4",
69+
city = "Brentwood",
70+
postCode = "CM14"
71+
)
72+
}
73+
}
74+
}
75+
}
76+
}

app/src/androidTest/java/com/mitteloupe/whoami/test/HomeTest.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ class HomeTest : BaseTest() {
6565
Intents.init()
6666
with(composeTestRule) {
6767
with(homeScreen) {
68-
tapOpenSourceNotices()
68+
tapOpenSourceNoticesButton()
6969
}
7070

7171
with(openSourceNoticesScreen) {

0 commit comments

Comments
 (0)