-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathEndToEndMainTest.kt
More file actions
126 lines (101 loc) · 3.91 KB
/
Copy pathEndToEndMainTest.kt
File metadata and controls
126 lines (101 loc) · 3.91 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
package de.rki.coronawarnapp.be.unamur.coronalert.uitests
import androidx.test.espresso.Espresso.onView
import androidx.test.espresso.ViewInteraction
import androidx.test.espresso.action.ViewActions.click
import androidx.test.espresso.action.ViewActions.scrollTo
import androidx.test.espresso.assertion.ViewAssertions.matches
import androidx.test.espresso.intent.Intents
import androidx.test.espresso.intent.matcher.IntentMatchers
import androidx.test.espresso.matcher.ViewMatchers.withId
import androidx.test.espresso.matcher.ViewMatchers.withParent
import androidx.test.espresso.matcher.ViewMatchers.withText
import androidx.test.ext.junit.rules.ActivityScenarioRule
import be.sciensano.coronalert.util.DateUtil
import de.rki.coronawarnapp.R
import de.rki.coronawarnapp.ui.main.MainActivity
import de.rki.coronawarnapp.ui.onboarding.OnboardingActivity
import org.hamcrest.Matchers.allOf
import org.joda.time.DateTime
import org.junit.Rule
import org.junit.Test
import java.text.DateFormat
import java.text.SimpleDateFormat
class EndToEndMainTest {
@get: Rule
val activityScenario: ActivityScenarioRule<MainActivity> = ActivityScenarioRule(
MainActivity::class.java
)
private fun handle_popup_tapButton1() {
val btn: ViewInteraction = onView(
allOf(
withId(android.R.id.button1),
withParent(withParent(withId(R.id.buttonPanel)))
)
) // popup
btn.perform(click())
}
private fun handle_popup_tapButton2() {
val btn: ViewInteraction = onView(
allOf(
withId(android.R.id.button2),
withParent(withParent(withId(R.id.buttonPanel)))
)
) // popup
btn.perform(click())
}
private fun handle_popup_tapYes() {
handle_popup_tapButton1()
}
private fun handle_popup_tapNo() {
handle_popup_tapButton2()
}
private fun handle_popup_tapOk() {
handle_popup_tapButton1()
}
private fun handle_popup_tapReset() {
handle_popup_tapButton1()
}
@Test
fun test_generateCode_generatesValidDate() {
// arrange
Thread.sleep(2000)
handle_popup_tapOk(); handle_popup_tapOk()
val receiveTestBtn: ViewInteraction =
onView(withId(R.id.submission_status_card_unregistered_button)) // main page
receiveTestBtn.perform(scrollTo(), click())
val nxtBtn: ViewInteraction =
onView(withId(R.id.submission_intro_button_next)) // receive test page
nxtBtn.perform(click())
val expectedDate: String = DateFormat.getDateInstance(DateFormat.FULL)
.format(DateTime().minusDays(2).toDate())
// act
handle_popup_tapNo() // popup symptoms checking
//assert
onView(withId(R.id.submission_test_request_save_date)).check(matches(withText(expectedDate)))
}
@Test
fun test_reinitialization() {
// arrange
Intents.init()
// act
resetApplicationStateAtMainPage()
// assert
Intents.intended(IntentMatchers.hasComponent(OnboardingActivity::class.java.getName()))
}
private fun resetApplicationStateAtMainPage() {
// handle popup if exposure notifications are not activated
Thread.sleep(2000)
handle_popup_tapOk();handle_popup_tapOk()
val menuBtn = onView(withId(R.id.main_header_options_menu))
menuBtn.perform(scrollTo(), click())
val menuItem = onView(allOf(withId(android.R.id.title), withText(R.string.settings_title)))
menuItem.perform(click())
// handle popup if exposure notifications are not activated
handle_popup_tapOk()
val resetBtn = onView(withId(R.id.settings_reset))
resetBtn.perform(scrollTo(), click())
val resetConfirmBtn = onView(withId(R.id.settings_reset_button_delete))
resetConfirmBtn.perform(click())
handle_popup_tapReset()
}
}