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 more tests

razeeman (Jun 12, 2023, 11:54 AM +0300) dac3714b 0238d8f5

+256 -2
+222 -2
app/src/androidTest/java/com/example/util/simpletimetracker/SettingsTest.kt
··· 33 33 import com.example.util.simpletimetracker.utils.clickOnViewWithId 34 34 import com.example.util.simpletimetracker.utils.clickOnViewWithIdOnPager 35 35 import com.example.util.simpletimetracker.utils.clickOnViewWithText 36 + import com.example.util.simpletimetracker.utils.getMillis 36 37 import com.example.util.simpletimetracker.utils.longClickOnViewWithId 37 38 import com.example.util.simpletimetracker.utils.nestedScrollTo 39 + import com.example.util.simpletimetracker.utils.recyclerItemCount 38 40 import com.example.util.simpletimetracker.utils.tryAction 39 41 import com.example.util.simpletimetracker.utils.unconstrainedClickOnView 40 42 import com.example.util.simpletimetracker.utils.withPluralText ··· 109 111 } 110 112 111 113 @Test 114 + fun ignoreShortUntracked() { 115 + fun getTime( 116 + hour: Int, 117 + minutes: Int, 118 + seconds: Int = 0, 119 + ): Long { 120 + return calendar.apply { 121 + timeInMillis = System.currentTimeMillis() 122 + add(Calendar.DATE, -1) 123 + setToStartOfDay() 124 + set(Calendar.HOUR_OF_DAY, hour) 125 + set(Calendar.MINUTE, minutes) 126 + set(Calendar.SECOND, seconds) 127 + }.timeInMillis 128 + } 129 + 130 + fun checkItemCount( 131 + count: Int, 132 + ) { 133 + onView(allOf(withId(recordsR.id.rvRecordsList), isCompletelyDisplayed())) 134 + .check(recyclerItemCount(count)) 135 + } 136 + 137 + fun checkRecordDuration( 138 + interval: Long, 139 + displayed: Boolean, 140 + ) { 141 + val duration = timeMapper.formatInterval( 142 + interval = interval, 143 + forceSeconds = true, 144 + useProportionalMinutes = false 145 + ) 146 + val matcher = allOf( 147 + withId(baseR.id.viewRecordItem), 148 + hasDescendant(withText(coreR.string.untracked_time_name)), 149 + hasDescendant(allOf(withId(changeRecordTypeR.id.tvRecordItemDuration), withText(duration))), 150 + isCompletelyDisplayed() 151 + ) 152 + if (displayed) { 153 + checkViewIsDisplayed(matcher) 154 + } else { 155 + checkViewDoesNotExist(matcher) 156 + } 157 + } 158 + 159 + // Add data 160 + runBlocking { 161 + prefsInteractor.setShowSeconds(true) 162 + prefsInteractor.setShowUntrackedInRecords(true) 163 + } 164 + val name = "name" 165 + testUtils.addActivity(name) 166 + val before = System.currentTimeMillis() - TimeUnit.DAYS.toMillis(10) 167 + testUtils.addRecord(name, timeStarted = before, timeEnded = before) 168 + 169 + // Add records 170 + testUtils.addRecord(name, timeStarted = getTime(0, 0), timeEnded = getTime(1, 0)) 171 + testUtils.addRecord(name, timeStarted = getTime(1, 30), timeEnded = getTime(2, 0)) 172 + testUtils.addRecord(name, timeStarted = getTime(2, 1), timeEnded = getTime(3, 0)) 173 + testUtils.addRecord(name, timeStarted = getTime(3, 0, seconds = 1), timeEnded = getTime(4, 0)) 174 + 175 + // Check disabled 176 + NavUtils.openSettingsScreen() 177 + NavUtils.openSettingsDisplay() 178 + onView(withId(settingsR.id.groupSettingsIgnoreShortUntracked)).perform(nestedScrollTo()) 179 + clickOnViewWithId(settingsR.id.groupSettingsIgnoreShortUntracked) 180 + clickOnViewWithText(coreR.string.duration_dialog_disable) 181 + checkViewIsDisplayed( 182 + allOf( 183 + withId(settingsR.id.tvSettingsIgnoreShortUntrackedTime), 184 + withText(coreR.string.settings_inactivity_reminder_disabled) 185 + ) 186 + ) 187 + 188 + NavUtils.openRecordsScreen() 189 + clickOnViewWithId(recordsR.id.btnRecordsContainerPrevious) 190 + checkItemCount(9) 191 + checkRecordDuration(TimeUnit.HOURS.toMillis(20), displayed = true) 192 + checkRecordDuration(TimeUnit.MINUTES.toMillis(30), displayed = true) 193 + checkRecordDuration(TimeUnit.MINUTES.toMillis(1), displayed = true) 194 + checkRecordDuration(TimeUnit.SECONDS.toMillis(1), displayed = true) 195 + 196 + // Check 30 minutes 197 + NavUtils.openSettingsScreen() 198 + onView(withId(settingsR.id.groupSettingsIgnoreShortUntracked)).perform(nestedScrollTo()) 199 + clickOnViewWithId(settingsR.id.groupSettingsIgnoreShortUntracked) 200 + clickOnViewWithId(dialogsR.id.tvNumberKeyboard3) 201 + clickOnViewWithId(dialogsR.id.tvNumberKeyboard0) 202 + clickOnViewWithId(dialogsR.id.tvNumberKeyboard0) 203 + clickOnViewWithId(dialogsR.id.tvNumberKeyboard1) 204 + clickOnViewWithText(coreR.string.duration_dialog_save) 205 + 206 + NavUtils.openRecordsScreen() 207 + checkItemCount(6) 208 + checkRecordDuration(TimeUnit.HOURS.toMillis(20), displayed = true) 209 + checkRecordDuration(TimeUnit.MINUTES.toMillis(30), displayed = false) 210 + checkRecordDuration(TimeUnit.MINUTES.toMillis(1), displayed = false) 211 + checkRecordDuration(TimeUnit.SECONDS.toMillis(1), displayed = false) 212 + 213 + // Check 1 minutes 214 + NavUtils.openSettingsScreen() 215 + onView(withId(settingsR.id.groupSettingsIgnoreShortUntracked)).perform(nestedScrollTo()) 216 + clickOnViewWithId(settingsR.id.groupSettingsIgnoreShortUntracked) 217 + repeat(4) { clickOnViewWithId(dialogsR.id.ivDurationPickerDelete) } 218 + clickOnViewWithId(dialogsR.id.tvNumberKeyboard1) 219 + clickOnViewWithId(dialogsR.id.tvNumberKeyboard0) 220 + clickOnViewWithId(dialogsR.id.tvNumberKeyboard1) 221 + clickOnViewWithText(coreR.string.duration_dialog_save) 222 + 223 + NavUtils.openRecordsScreen() 224 + checkItemCount(7) 225 + checkRecordDuration(TimeUnit.HOURS.toMillis(20), displayed = true) 226 + checkRecordDuration(TimeUnit.MINUTES.toMillis(30), displayed = true) 227 + checkRecordDuration(TimeUnit.MINUTES.toMillis(1), displayed = false) 228 + checkRecordDuration(TimeUnit.SECONDS.toMillis(1), displayed = false) 229 + } 230 + 231 + @Test 232 + fun untrackedRange() { 233 + val name = "name" 234 + val startOfDay = calendar.apply { setToStartOfDay() }.getMillis(0, 0) 235 + 236 + // Add data 237 + runBlocking { 238 + prefsInteractor.setShowUntrackedInRecords(true) 239 + } 240 + testUtils.addActivity(name) 241 + val before = System.currentTimeMillis() - TimeUnit.DAYS.toMillis(10) 242 + testUtils.addRecord(name, timeStarted = before, timeEnded = before) 243 + 244 + // Check disabled 245 + NavUtils.openRecordsScreen() 246 + clickOnViewWithId(recordsR.id.btnRecordsContainerPrevious) 247 + checkRecord( 248 + nameResId = coreR.string.untracked_time_name, 249 + timeStart = startOfDay.toTimePreview(), 250 + timeEnd = startOfDay.toTimePreview(), 251 + ) 252 + 253 + NavUtils.openSettingsScreen() 254 + NavUtils.openSettingsDisplay() 255 + onView(withId(settingsR.id.checkboxSettingsShowRecordsCalendar)).perform(nestedScrollTo()) 256 + tryAction { onView(withId(settingsR.id.checkboxSettingsUntrackedRange)).check(matches(isNotChecked())) } 257 + checkViewIsNotDisplayed(withId(settingsR.id.tvSettingsUntrackedRangeStart)) 258 + checkViewIsNotDisplayed(withId(settingsR.id.tvSettingsUntrackedRangeEnd)) 259 + unconstrainedClickOnView(withId(settingsR.id.checkboxSettingsUntrackedRange)) 260 + tryAction { onView(withId(settingsR.id.checkboxSettingsUntrackedRange)).check(matches(isChecked())) } 261 + checkViewIsDisplayed(withId(settingsR.id.tvSettingsUntrackedRangeStart)) 262 + checkViewIsDisplayed(withId(settingsR.id.tvSettingsUntrackedRangeEnd)) 263 + 264 + // Check range 265 + var startPreview = (startOfDay + TimeUnit.HOURS.toMillis(8)).toTimePreview() 266 + clickOnViewWithId(settingsR.id.tvSettingsUntrackedRangeStart) 267 + onView(withClassName(equalTo(CustomTimePicker::class.java.name))).perform(setTime(8, 0)) 268 + clickOnViewWithId(dialogsR.id.btnDateTimeDialogPositive) 269 + checkViewIsDisplayed( 270 + allOf( 271 + withId(settingsR.id.tvSettingsUntrackedRangeStart), 272 + withText(startPreview), 273 + ) 274 + ) 275 + var endPreview = (startOfDay + TimeUnit.HOURS.toMillis(17)).toTimePreview() 276 + clickOnViewWithId(settingsR.id.tvSettingsUntrackedRangeEnd) 277 + onView(withClassName(equalTo(CustomTimePicker::class.java.name))).perform(setTime(17, 0)) 278 + clickOnViewWithId(dialogsR.id.btnDateTimeDialogPositive) 279 + checkViewIsDisplayed( 280 + allOf( 281 + withId(settingsR.id.tvSettingsUntrackedRangeEnd), 282 + withText(endPreview), 283 + ) 284 + ) 285 + 286 + NavUtils.openRecordsScreen() 287 + checkRecord( 288 + nameResId = coreR.string.untracked_time_name, 289 + timeStart = startPreview, 290 + timeEnd = endPreview, 291 + ) 292 + 293 + // Check other range 294 + NavUtils.openSettingsScreen() 295 + startPreview = (startOfDay + TimeUnit.HOURS.toMillis(17)).toTimePreview() 296 + clickOnViewWithId(settingsR.id.tvSettingsUntrackedRangeStart) 297 + onView(withClassName(equalTo(CustomTimePicker::class.java.name))).perform(setTime(17, 0)) 298 + clickOnViewWithId(dialogsR.id.btnDateTimeDialogPositive) 299 + checkViewIsDisplayed( 300 + allOf( 301 + withId(settingsR.id.tvSettingsUntrackedRangeStart), 302 + withText(startPreview), 303 + ) 304 + ) 305 + endPreview = (startOfDay + TimeUnit.HOURS.toMillis(8)).toTimePreview() 306 + clickOnViewWithId(settingsR.id.tvSettingsUntrackedRangeEnd) 307 + onView(withClassName(equalTo(CustomTimePicker::class.java.name))).perform(setTime(8, 0)) 308 + clickOnViewWithId(dialogsR.id.btnDateTimeDialogPositive) 309 + checkViewIsDisplayed( 310 + allOf( 311 + withId(settingsR.id.tvSettingsUntrackedRangeEnd), 312 + withText(endPreview), 313 + ) 314 + ) 315 + 316 + NavUtils.openRecordsScreen() 317 + checkRecord( 318 + nameResId = coreR.string.untracked_time_name, 319 + timeStart = startOfDay.toTimePreview(), 320 + timeEnd = endPreview, 321 + ) 322 + checkRecord( 323 + nameResId = coreR.string.untracked_time_name, 324 + timeStart = startPreview, 325 + timeEnd = startOfDay.toTimePreview(), 326 + ) 327 + } 328 + 329 + @Test 112 330 fun allowMultitaskingSetting() { 113 331 val name1 = "Test1" 114 332 val name2 = "Test2" ··· 813 1031 814 1032 @Test 815 1033 fun startOfDay() { 816 - fun Long.toTimePreview() = timeMapper.formatTime(time = this, useMilitaryTime = true, showSeconds = false) 817 - 818 1034 val name = "Test" 819 1035 820 1036 // Add data ··· 1587 1803 isCompletelyDisplayed() 1588 1804 ) 1589 1805 ) 1806 + } 1807 + 1808 + private fun Long.toTimePreview(): String { 1809 + return timeMapper.formatTime(time = this, useMilitaryTime = true, showSeconds = false) 1590 1810 } 1591 1811 }
+34
app/src/androidTest/java/com/example/util/simpletimetracker/StatisticsDetailTest.kt
··· 10 10 import androidx.test.espresso.matcher.ViewMatchers.withId 11 11 import androidx.test.espresso.matcher.ViewMatchers.withText 12 12 import androidx.test.ext.junit.runners.AndroidJUnit4 13 + import com.example.util.simpletimetracker.core.extension.setToStartOfDay 13 14 import com.example.util.simpletimetracker.utils.BaseUiTest 14 15 import com.example.util.simpletimetracker.utils.NavUtils 15 16 import com.example.util.simpletimetracker.utils.checkViewDoesNotExist ··· 1072 1073 isDescendantOfA(withId(statisticsDetailR.id.buttonsStatisticsDetailStreaksType)) 1073 1074 ) 1074 1075 ) 1076 + } 1077 + 1078 + @Test 1079 + fun untracked() { 1080 + val name = "name" 1081 + 1082 + // Add data 1083 + testUtils.addActivity(name) 1084 + val before = Calendar.getInstance().apply { 1085 + setToStartOfDay() 1086 + add(Calendar.DATE, -2) 1087 + set(Calendar.HOUR_OF_DAY, 21) 1088 + }.timeInMillis 1089 + 1090 + testUtils.addRecord( 1091 + typeName = name, 1092 + timeStarted = before - TimeUnit.DAYS.toMillis(1), 1093 + timeEnded = before, 1094 + ) 1095 + 1096 + // Check 1097 + NavUtils.openStatisticsScreen() 1098 + tryAction { clickOnView(allOf(withText(coreR.string.untracked_time_name), isCompletelyDisplayed())) } 1099 + 1100 + clickOnViewWithId(statisticsDetailR.id.btnStatisticsDetailPrevious) 1101 + checkCard(coreR.string.statistics_detail_total_duration, "24$hourString 0$minuteString") 1102 + checkRecordsCard(1) 1103 + checkCard(coreR.string.statistics_detail_average_record, "24$hourString 0$minuteString") 1104 + 1105 + clickOnViewWithId(statisticsDetailR.id.btnStatisticsDetailPrevious) 1106 + checkCard(coreR.string.statistics_detail_total_duration, "3$hourString 0$minuteString") 1107 + checkRecordsCard(1) 1108 + checkCard(coreR.string.statistics_detail_average_record, "3$hourString 0$minuteString") 1075 1109 } 1076 1110 1077 1111 private fun checkPreview(color: Int, icon: Int, name: String) {