A fork of Simple Time Tracker with WearOS support. (Now integrated upstream)
0

Configure Feed

Select the types of activity you want to include in your feed.

add repeat button tests

razeeman (Aug 20, 2023, 10:30 AM +0300) d27a55dd 714e9c3e

+161 -1
+87
app/src/androidTest/java/com/example/util/simpletimetracker/RecordRepeatTest.kt
··· 1 + package com.example.util.simpletimetracker 2 + 3 + import androidx.test.espresso.matcher.ViewMatchers.hasDescendant 4 + import androidx.test.espresso.matcher.ViewMatchers.isCompletelyDisplayed 5 + import androidx.test.espresso.matcher.ViewMatchers.withId 6 + import androidx.test.espresso.matcher.ViewMatchers.withText 7 + import androidx.test.ext.junit.runners.AndroidJUnit4 8 + import com.example.util.simpletimetracker.domain.model.RepeatButtonType 9 + import com.example.util.simpletimetracker.feature_base_adapter.R 10 + import com.example.util.simpletimetracker.utils.BaseUiTest 11 + import com.example.util.simpletimetracker.utils.NavUtils 12 + import com.example.util.simpletimetracker.utils.checkViewDoesNotExist 13 + import com.example.util.simpletimetracker.utils.checkViewIsDisplayed 14 + import com.example.util.simpletimetracker.utils.clickOnViewWithText 15 + import com.example.util.simpletimetracker.utils.tryAction 16 + import dagger.hilt.android.testing.HiltAndroidTest 17 + import kotlinx.coroutines.runBlocking 18 + import org.hamcrest.Matchers.allOf 19 + import org.junit.Test 20 + import org.junit.runner.RunWith 21 + import com.example.util.simpletimetracker.R as coreR 22 + 23 + @HiltAndroidTest 24 + @RunWith(AndroidJUnit4::class) 25 + class RecordRepeatTest : BaseUiTest() { 26 + 27 + @Test 28 + fun visibility() { 29 + val type = "type" 30 + 31 + // Add data 32 + testUtils.addActivity(type) 33 + Thread.sleep(1000) 34 + 35 + // No records - no button 36 + checkViewIsDisplayed(withText(coreR.string.running_records_add_type)) 37 + checkViewDoesNotExist(withText(coreR.string.running_records_repeat)) 38 + 39 + // Add record 40 + testUtils.addRecord(type) 41 + NavUtils.openRecordsScreen() 42 + checkViewIsDisplayed(allOf(withText(type), isCompletelyDisplayed())) 43 + 44 + // Button is shown 45 + NavUtils.openRunningRecordsScreen() 46 + checkViewIsDisplayed(withText(coreR.string.running_records_repeat)) 47 + } 48 + 49 + @Test 50 + fun click() { 51 + val type = "type" 52 + val tag = "tag" 53 + val comment = "comment" 54 + val fullName = "$type - $tag" 55 + 56 + // Add data 57 + testUtils.addActivity(type) 58 + testUtils.addRecordTag(tag) 59 + testUtils.addRecord( 60 + typeName = type, 61 + tagNames = listOf(tag), 62 + comment = comment, 63 + ) 64 + Thread.sleep(1000) 65 + 66 + // Check 67 + clickOnViewWithText(coreR.string.running_records_repeat) 68 + tryAction { 69 + checkViewIsDisplayed( 70 + allOf( 71 + withId(R.id.viewRunningRecordItem), 72 + hasDescendant(withText(fullName)), 73 + hasDescendant(withText(comment)), 74 + ), 75 + ) 76 + } 77 + 78 + // Already started message 79 + clickOnViewWithText(coreR.string.running_records_repeat) 80 + clickOnViewWithText(coreR.string.running_records_repeat_already_tracking) 81 + 82 + // No records message 83 + runBlocking { prefsInteractor.setRepeatButtonType(RepeatButtonType.RepeatBeforeLast) } 84 + clickOnViewWithText(coreR.string.running_records_repeat) 85 + clickOnViewWithText(coreR.string.running_records_repeat_no_prev_record) 86 + } 87 + }
+48
app/src/androidTest/java/com/example/util/simpletimetracker/SettingsTest.kt
··· 22 22 import com.example.util.simpletimetracker.core.extension.setWeekToFirstDay 23 23 import com.example.util.simpletimetracker.domain.model.ActivityFilter 24 24 import com.example.util.simpletimetracker.domain.model.DayOfWeek 25 + import com.example.util.simpletimetracker.feature_base_adapter.R 25 26 import com.example.util.simpletimetracker.feature_dialogs.dateTime.CustomTimePicker 26 27 import com.example.util.simpletimetracker.utils.BaseUiTest 27 28 import com.example.util.simpletimetracker.utils.NavUtils ··· 1830 1831 NavUtils.openRunningRecordsScreen() 1831 1832 checkViewIsDisplayed(withText(coreR.string.running_records_add_filter)) 1832 1833 checkViewIsDisplayed(withText(name)) 1834 + } 1835 + 1836 + @Test 1837 + fun repeatType() { 1838 + val type1 = "type1" 1839 + val type2 = "type2" 1840 + val current = System.currentTimeMillis() 1841 + 1842 + // Add data 1843 + testUtils.addActivity(type1) 1844 + testUtils.addActivity(type2) 1845 + testUtils.addRecord( 1846 + typeName = type1, 1847 + timeStarted = current, 1848 + timeEnded = current, 1849 + ) 1850 + testUtils.addRecord( 1851 + typeName = type2, 1852 + timeStarted = current - TimeUnit.HOURS.toMillis(1), 1853 + timeEnded = current - TimeUnit.HOURS.toMillis(1), 1854 + ) 1855 + 1856 + // Check 1857 + NavUtils.openSettingsScreen() 1858 + NavUtils.openSettingsAdditional() 1859 + onView(withId(settingsR.id.spinnerSettingsRepeatButtonType)).perform(nestedScrollTo()) 1860 + checkViewIsDisplayed( 1861 + allOf( 1862 + withId(settingsR.id.tvSettingsRepeatButtonTypeValue), 1863 + withText(coreR.string.settings_repeat_last_record), 1864 + ), 1865 + ) 1866 + NavUtils.openRunningRecordsScreen() 1867 + clickOnView(allOf(withText(type1), isCompletelyDisplayed())) 1868 + tryAction { 1869 + checkViewIsDisplayed(allOf(withId(R.id.viewRunningRecordItem), hasDescendant(withText(type1)))) 1870 + } 1871 + 1872 + // Change 1873 + NavUtils.openSettingsScreen() 1874 + clickOnSpinnerWithId(settingsR.id.spinnerSettingsRepeatButtonType) 1875 + clickOnViewWithText(coreR.string.settings_repeat_one_before_last) 1876 + NavUtils.openRunningRecordsScreen() 1877 + clickOnView(allOf(withText(type2), isCompletelyDisplayed())) 1878 + tryAction { 1879 + checkViewIsDisplayed(allOf(withId(R.id.viewRunningRecordItem), hasDescendant(withText(type2)))) 1880 + } 1833 1881 } 1834 1882 1835 1883 private fun clearDuration() {
+2
app/src/androidTest/java/com/example/util/simpletimetracker/Widget.kt
··· 15 15 import org.hamcrest.CoreMatchers.allOf 16 16 import org.junit.Test 17 17 import org.junit.runner.RunWith 18 + import com.example.util.simpletimetracker.R as coreR 18 19 import com.example.util.simpletimetracker.feature_base_adapter.R as baseR 19 20 20 21 @HiltAndroidTest ··· 45 46 checkType(firstColor, name1) 46 47 checkType(lastColor, name2) 47 48 checkViewDoesNotExist(withText(name3)) 49 + checkViewIsDisplayed(withText(coreR.string.running_records_repeat)) 48 50 } 49 51 50 52 private fun checkType(color: Int, name: String) {
+24 -1
app/src/androidTest/java/com/example/util/simpletimetracker/WidgetUniversal.kt
··· 16 16 import com.example.util.simpletimetracker.utils.withCardColor 17 17 import dagger.hilt.android.testing.HiltAndroidTest 18 18 import kotlinx.coroutines.runBlocking 19 - import org.hamcrest.CoreMatchers.allOf 19 + import org.hamcrest.Matchers.allOf 20 20 import org.junit.Test 21 21 import org.junit.runner.RunWith 22 22 import com.example.util.simpletimetracker.core.R as coreR ··· 173 173 checkViewIsDisplayed(withText(name1)) 174 174 checkViewIsDisplayed(withText(name2)) 175 175 checkViewIsDisplayed(allOf(withCardColor(viewsR.color.colorFiltered), hasDescendant(withText(filter)))) 176 + } 177 + 178 + @Test 179 + fun repeat() { 180 + val name = "TypeName" 181 + 182 + // Add data 183 + testUtils.addActivity(name) 184 + scenarioRule = ActivityScenario.launch(WidgetUniversalActivity::class.java) 185 + 186 + // No records 187 + clickOnViewWithText(coreR.string.running_records_repeat) 188 + checkViewIsDisplayed( 189 + allOf( 190 + withText(R.string.running_records_repeat_no_prev_record), 191 + withId(com.google.android.material.R.id.snackbar_text) 192 + ) 193 + ) 194 + 195 + // Check 196 + testUtils.addRecord(name) 197 + clickOnViewWithText(coreR.string.running_records_repeat) 198 + checkType(viewsR.color.colorFiltered, name) 176 199 } 177 200 178 201 private fun checkType(color: Int, name: String) {