Skip to content

Commit be2ff55

Browse files
committed
add ui tests for empty screens
1 parent 64b92e9 commit be2ff55

File tree

5 files changed

+173
-58
lines changed

5 files changed

+173
-58
lines changed
Lines changed: 142 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,142 @@
1+
package com.example.util.simpletimetracker
2+
3+
import androidx.test.core.app.ApplicationProvider
4+
import androidx.test.espresso.Espresso.pressBack
5+
import androidx.test.espresso.matcher.ViewMatchers
6+
import androidx.test.espresso.matcher.ViewMatchers.hasDescendant
7+
import androidx.test.espresso.matcher.ViewMatchers.isCompletelyDisplayed
8+
import androidx.test.espresso.matcher.ViewMatchers.isDescendantOfA
9+
import androidx.test.espresso.matcher.ViewMatchers.withId
10+
import androidx.test.espresso.matcher.ViewMatchers.withText
11+
import androidx.test.ext.junit.rules.ActivityScenarioRule
12+
import androidx.test.ext.junit.runners.AndroidJUnit4
13+
import com.example.util.simpletimetracker.core.utils.TestUtils
14+
import com.example.util.simpletimetracker.di.AppModule
15+
import com.example.util.simpletimetracker.di.DaggerTestAppComponent
16+
import com.example.util.simpletimetracker.ui.MainActivity
17+
import com.example.util.simpletimetracker.utils.NavUtils
18+
import com.example.util.simpletimetracker.utils.checkViewDoesNotExist
19+
import com.example.util.simpletimetracker.utils.checkViewIsDisplayed
20+
import com.example.util.simpletimetracker.utils.clickOnView
21+
import com.example.util.simpletimetracker.utils.clickOnViewWithId
22+
import com.example.util.simpletimetracker.utils.clickOnViewWithText
23+
import com.example.util.simpletimetracker.utils.typeTextIntoView
24+
import org.hamcrest.CoreMatchers.allOf
25+
import org.junit.Before
26+
import org.junit.Rule
27+
import org.junit.Test
28+
import org.junit.runner.RunWith
29+
import javax.inject.Inject
30+
31+
@RunWith(AndroidJUnit4::class)
32+
class MainScreenEmptyTest {
33+
34+
@Inject
35+
lateinit var testUtils: TestUtils
36+
37+
@Rule
38+
@JvmField
39+
val activityScenarioRule = ActivityScenarioRule(MainActivity::class.java)
40+
41+
@Before
42+
fun setUp() {
43+
val app = ApplicationProvider.getApplicationContext() as TimeTrackerApp
44+
DaggerTestAppComponent.builder()
45+
.appModule(AppModule(app))
46+
.build()
47+
.inject(this)
48+
49+
testUtils.clearDatabase()
50+
}
51+
52+
@Test
53+
fun test() {
54+
val name = "Test"
55+
56+
// Empty main
57+
checkViewDoesNotExist(withText(R.string.running_records_empty))
58+
59+
// Empty records
60+
NavUtils.openRecordsScreen()
61+
checkViewIsDisplayed(allOf(withText(R.string.records_empty), isCompletelyDisplayed()))
62+
clickOnViewWithId(R.id.btnRecordsContainerPrevious)
63+
checkViewIsDisplayed(allOf(withText(R.string.records_empty), isCompletelyDisplayed()))
64+
clickOnViewWithId(R.id.btnRecordsContainerNext)
65+
clickOnViewWithId(R.id.btnRecordsContainerNext)
66+
checkViewIsDisplayed(allOf(withText(R.string.records_empty), isCompletelyDisplayed()))
67+
68+
// Empty statistics
69+
NavUtils.openStatisticsScreen()
70+
checkViewIsDisplayed(
71+
allOf(
72+
withId(R.id.layoutStatisticsItem),
73+
hasDescendant(withText(R.string.untracked_time_name)),
74+
hasDescendant(ViewMatchers.withSubstring("100%")),
75+
isCompletelyDisplayed()
76+
)
77+
)
78+
clickOnViewWithId(R.id.btnStatisticsContainerNext)
79+
checkViewIsDisplayed(allOf(withText(R.string.statistics_empty), isCompletelyDisplayed()))
80+
81+
// Week range
82+
clickOnViewWithId(R.id.btnStatisticsContainerToday)
83+
clickOnViewWithText(R.string.title_this_week)
84+
checkViewIsDisplayed(
85+
allOf(
86+
withId(R.id.layoutStatisticsItem),
87+
hasDescendant(withText(R.string.untracked_time_name)),
88+
hasDescendant(ViewMatchers.withSubstring("100%")),
89+
isCompletelyDisplayed()
90+
)
91+
)
92+
clickOnViewWithId(R.id.btnStatisticsContainerNext)
93+
checkViewIsDisplayed(allOf(withText(R.string.statistics_empty), isCompletelyDisplayed()))
94+
95+
// Month range
96+
clickOnViewWithId(R.id.btnStatisticsContainerToday)
97+
clickOnViewWithText(R.string.title_this_month)
98+
checkViewIsDisplayed(
99+
allOf(
100+
withId(R.id.layoutStatisticsItem),
101+
hasDescendant(withText(R.string.untracked_time_name)),
102+
hasDescendant(ViewMatchers.withSubstring("100%")),
103+
isCompletelyDisplayed()
104+
)
105+
)
106+
clickOnViewWithId(R.id.btnStatisticsContainerNext)
107+
checkViewIsDisplayed(allOf(withText(R.string.statistics_empty), isCompletelyDisplayed()))
108+
109+
// Overall range
110+
clickOnViewWithId(R.id.btnStatisticsContainerToday)
111+
clickOnViewWithText(R.string.title_overall)
112+
checkViewIsDisplayed(allOf(withText(R.string.statistics_empty), isCompletelyDisplayed()))
113+
114+
// Back to day range
115+
clickOnViewWithId(R.id.btnStatisticsContainerToday)
116+
clickOnViewWithText(R.string.title_today)
117+
checkViewIsDisplayed(
118+
allOf(
119+
withId(R.id.layoutStatisticsItem),
120+
hasDescendant(withText(R.string.untracked_time_name)),
121+
hasDescendant(ViewMatchers.withSubstring("100%")),
122+
isCompletelyDisplayed()
123+
)
124+
)
125+
clickOnViewWithId(R.id.btnStatisticsContainerNext)
126+
checkViewIsDisplayed(allOf(withText(R.string.statistics_empty), isCompletelyDisplayed()))
127+
128+
// Add activity
129+
NavUtils.openRunningRecordsScreen()
130+
clickOnView(withText(R.string.running_records_add_type))
131+
typeTextIntoView(R.id.etChangeRecordTypeName, name)
132+
pressBack()
133+
clickOnView(withText(R.string.change_record_type_save))
134+
checkViewIsDisplayed(withText(R.string.running_records_empty))
135+
136+
// Start timer
137+
clickOnViewWithText(name)
138+
checkViewDoesNotExist(withText(R.string.running_records_empty))
139+
clickOnView(allOf(isDescendantOfA(withId(R.id.layoutRunningRecordItem)), withText(name)))
140+
checkViewIsDisplayed(withText(R.string.running_records_empty))
141+
}
142+
}

app/src/androidTest/java/com/example/util/simpletimetracker/MainScreenTest.kt

Lines changed: 27 additions & 57 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,6 @@ package com.example.util.simpletimetracker
22

33
import androidx.test.core.app.ApplicationProvider
44
import androidx.test.espresso.Espresso.pressBack
5-
import androidx.test.espresso.matcher.ViewMatchers
6-
import androidx.test.espresso.matcher.ViewMatchers.hasDescendant
75
import androidx.test.espresso.matcher.ViewMatchers.isCompletelyDisplayed
86
import androidx.test.espresso.matcher.ViewMatchers.isDescendantOfA
97
import androidx.test.espresso.matcher.ViewMatchers.withId
@@ -15,11 +13,12 @@ import com.example.util.simpletimetracker.di.AppModule
1513
import com.example.util.simpletimetracker.di.DaggerTestAppComponent
1614
import com.example.util.simpletimetracker.ui.MainActivity
1715
import com.example.util.simpletimetracker.utils.NavUtils
18-
import com.example.util.simpletimetracker.utils.checkViewDoesNotExist
19-
import com.example.util.simpletimetracker.utils.checkViewIsDisplayed
16+
import com.example.util.simpletimetracker.utils.clickOnRecyclerItem
2017
import com.example.util.simpletimetracker.utils.clickOnView
2118
import com.example.util.simpletimetracker.utils.clickOnViewWithId
2219
import com.example.util.simpletimetracker.utils.clickOnViewWithText
20+
import com.example.util.simpletimetracker.utils.longClickOnView
21+
import com.example.util.simpletimetracker.utils.longClickOnViewWithId
2322
import com.example.util.simpletimetracker.utils.typeTextIntoView
2423
import org.hamcrest.CoreMatchers.allOf
2524
import org.junit.Before
@@ -53,76 +52,47 @@ class MainScreenTest {
5352
fun test() {
5453
val name = "Test"
5554

56-
// Empty main
57-
checkViewDoesNotExist(withText(R.string.running_records_empty))
58-
59-
// Empty records
60-
NavUtils.openRecordsScreen()
61-
checkViewIsDisplayed(allOf(withText(R.string.records_empty), isCompletelyDisplayed()))
62-
clickOnViewWithId(R.id.btnRecordsContainerPrevious)
63-
checkViewIsDisplayed(allOf(withText(R.string.records_empty), isCompletelyDisplayed()))
64-
clickOnViewWithId(R.id.btnRecordsContainerNext)
65-
clickOnViewWithId(R.id.btnRecordsContainerNext)
66-
checkViewIsDisplayed(allOf(withText(R.string.records_empty), isCompletelyDisplayed()))
67-
68-
// Empty statistics
69-
NavUtils.openStatisticsScreen()
70-
checkViewIsDisplayed(
71-
allOf(
72-
withId(R.id.layoutStatisticsItem),
73-
hasDescendant(withText(R.string.untracked_time_name)),
74-
hasDescendant(ViewMatchers.withSubstring("100%")),
75-
isCompletelyDisplayed()
76-
)
77-
)
78-
clickOnView(allOf(withText(R.string.title_today), isCompletelyDisplayed()))
79-
clickOnViewWithText(R.string.title_this_week)
80-
checkViewIsDisplayed(
81-
allOf(
82-
withId(R.id.layoutStatisticsItem),
83-
hasDescendant(withText(R.string.untracked_time_name)),
84-
hasDescendant(ViewMatchers.withSubstring("100%")),
85-
isCompletelyDisplayed()
86-
)
87-
)
88-
clickOnView(allOf(withText(R.string.title_this_week), isCompletelyDisplayed()))
89-
clickOnViewWithText(R.string.title_overall)
90-
checkViewIsDisplayed(allOf(withText(R.string.statistics_empty), isCompletelyDisplayed()))
91-
clickOnView(allOf(withText(R.string.title_overall), isCompletelyDisplayed()))
92-
clickOnViewWithText(R.string.title_today)
93-
clickOnViewWithId(R.id.btnStatisticsContainerPrevious)
94-
checkViewIsDisplayed(
95-
allOf(
96-
withId(R.id.layoutStatisticsItem),
97-
hasDescendant(withText(R.string.untracked_time_name)),
98-
hasDescendant(ViewMatchers.withSubstring("100%")),
99-
isCompletelyDisplayed()
100-
)
101-
)
102-
clickOnViewWithId(R.id.btnStatisticsContainerNext)
103-
clickOnViewWithId(R.id.btnStatisticsContainerNext)
104-
checkViewIsDisplayed(allOf(withText(R.string.statistics_empty), isCompletelyDisplayed()))
105-
10655
// Add activity
107-
NavUtils.openRunningRecordsScreen()
56+
clickOnView(withText(R.string.running_records_add_type))
57+
pressBack()
58+
pressBack()
59+
10860
clickOnView(withText(R.string.running_records_add_type))
10961
typeTextIntoView(R.id.etChangeRecordTypeName, name)
11062
pressBack()
11163
clickOnView(withText(R.string.change_record_type_save))
112-
checkViewIsDisplayed(withText(R.string.running_records_empty))
11364

11465
// Start timer
11566
clickOnViewWithText(name)
116-
checkViewDoesNotExist(withText(R.string.running_records_empty))
67+
68+
// Stop timer
11769
clickOnView(allOf(isDescendantOfA(withId(R.id.layoutRunningRecordItem)), withText(name)))
11870

11971
// Records
12072
NavUtils.openRecordsScreen()
73+
74+
longClickOnView(allOf(withText(name), isCompletelyDisplayed()))
75+
pressBack()
76+
12177
clickOnViewWithId(R.id.btnRecordAdd)
12278
pressBack()
12379

80+
clickOnViewWithId(R.id.btnRecordAdd)
81+
clickOnViewWithText(R.string.change_record_type_field)
82+
clickOnRecyclerItem(R.id.rvChangeRecordType, withText(name))
83+
clickOnViewWithText(R.string.change_record_save)
84+
85+
clickOnViewWithId(R.id.btnRecordsContainerPrevious)
86+
longClickOnViewWithId(R.id.btnRecordsContainerToday)
87+
clickOnViewWithId(R.id.btnRecordsContainerNext)
88+
12489
// Statistics
12590
NavUtils.openStatisticsScreen()
91+
clickOnViewWithId(R.id.btnStatisticsChartFilter)
92+
pressBack()
93+
clickOnViewWithId(R.id.btnStatisticsContainerPrevious)
94+
longClickOnViewWithId(R.id.btnStatisticsContainerToday)
95+
clickOnViewWithId(R.id.btnStatisticsContainerNext)
12696

12797
// Settings
12898
NavUtils.openSettingsScreen()

app/src/androidTest/java/com/example/util/simpletimetracker/di/TestAppComponent.kt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import com.example.util.simpletimetracker.ChangeRecordTest
66
import com.example.util.simpletimetracker.ChangeRecordTypeTest
77
import com.example.util.simpletimetracker.DeleteRecordTest
88
import com.example.util.simpletimetracker.DeleteRecordTypeTest
9+
import com.example.util.simpletimetracker.MainScreenEmptyTest
910
import com.example.util.simpletimetracker.MainScreenTest
1011
import com.example.util.simpletimetracker.RecordsRangesTest
1112
import com.example.util.simpletimetracker.StartRecordTest
@@ -28,6 +29,7 @@ import javax.inject.Singleton
2829
interface TestAppComponent: AppComponent {
2930

3031
fun inject(into: MainScreenTest)
32+
fun inject(into: MainScreenEmptyTest)
3133
fun inject(into: AddRecordTypeTest)
3234
fun inject(into: ChangeRecordTypeTest)
3335
fun inject(into: DeleteRecordTypeTest)

feature_settings/src/main/res/layout/settings_fragment.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@
4949
android:layout_width="0dp"
5050
android:layout_height="wrap_content"
5151
android:layout_marginTop="8dp"
52-
android:text="Sort activities by color"
52+
android:text="@string/settings_sort_by_color"
5353
app:layout_constraintEnd_toStartOf="@id/checkboxSettingsRecordTypeSort"
5454
app:layout_constraintStart_toStartOf="parent"
5555
app:layout_constraintTop_toBottomOf="@id/dividerSettingsRestoreBackup" />

feature_settings/src/main/res/values/strings.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
<resources>
33
<string name="settings_save_backup">Save backup</string>
44
<string name="settings_restore_backup">Restore backup</string>
5+
<string name="settings_sort_by_color">Sort activities by color</string>
56

67
<string name="settings_backup_saved">Backup saved</string>
78
<string name="settings_backup_restored">Backup restored</string>

0 commit comments

Comments
 (0)