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 (Dec 17, 2023, 11:39 AM +0300) 32d2e552 ebb15c10

+595 -5
+41 -3
app/src/androidTest/java/com/example/util/simpletimetracker/AddCategoryTest.kt
··· 6 6 import androidx.test.espresso.assertion.PositionAssertions.isCompletelyAbove 7 7 import androidx.test.espresso.assertion.PositionAssertions.isCompletelyBelow 8 8 import androidx.test.espresso.matcher.ViewMatchers.hasDescendant 9 + import androidx.test.espresso.matcher.ViewMatchers.isDescendantOfA 9 10 import androidx.test.espresso.matcher.ViewMatchers.withId 10 11 import androidx.test.espresso.matcher.ViewMatchers.withParent 11 12 import androidx.test.espresso.matcher.ViewMatchers.withText 12 13 import androidx.test.ext.junit.runners.AndroidJUnit4 13 14 import com.example.util.simpletimetracker.core.mapper.ColorMapper 15 + import com.example.util.simpletimetracker.feature_change_record_type.R 14 16 import com.example.util.simpletimetracker.utils.BaseUiTest 15 17 import com.example.util.simpletimetracker.utils.NavUtils 16 18 import com.example.util.simpletimetracker.utils.checkViewDoesNotExist 17 19 import com.example.util.simpletimetracker.utils.checkViewIsDisplayed 18 20 import com.example.util.simpletimetracker.utils.checkViewIsNotDisplayed 19 21 import com.example.util.simpletimetracker.utils.clickOnRecyclerItem 22 + import com.example.util.simpletimetracker.utils.clickOnView 23 + import com.example.util.simpletimetracker.utils.clickOnViewWithId 20 24 import com.example.util.simpletimetracker.utils.clickOnViewWithText 21 25 import com.example.util.simpletimetracker.utils.longClickOnView 22 26 import com.example.util.simpletimetracker.utils.scrollRecyclerToPosition ··· 31 35 import com.example.util.simpletimetracker.core.R as coreR 32 36 import com.example.util.simpletimetracker.feature_base_adapter.R as baseR 33 37 import com.example.util.simpletimetracker.feature_change_category.R as changeCategoryR 38 + import com.example.util.simpletimetracker.feature_dialogs.R as dialogsR 34 39 35 40 @HiltAndroidTest 36 41 @RunWith(AndroidJUnit4::class) ··· 118 123 onView(withText(typeName2)).check(isCompletelyBelow(withId(changeCategoryR.id.viewDividerItem))) 119 124 120 125 clickOnRecyclerItem(changeCategoryR.id.rvChangeCategoryType, withText(typeName1)) 121 - clickOnViewWithText(coreR.string.change_record_type_save) 126 + clickOnViewWithText(coreR.string.change_category_types_hint) 122 127 123 - // Category type added 128 + // Selecting goal time 129 + clickOnViewWithText(coreR.string.change_record_type_goal_time_hint) 130 + clickOnView( 131 + allOf( 132 + isDescendantOfA(withId(R.id.layoutChangeRecordTypeGoalSession)), 133 + withId(R.id.fieldChangeRecordTypeGoalDuration), 134 + ), 135 + ) 136 + clickOnViewWithId(dialogsR.id.tvNumberKeyboard1) 137 + clickOnViewWithId(dialogsR.id.tvNumberKeyboard0) 138 + clickOnViewWithId(dialogsR.id.tvNumberKeyboard0) 139 + clickOnViewWithId(dialogsR.id.tvNumberKeyboard0) 140 + clickOnViewWithText(coreR.string.duration_dialog_save) 141 + checkViewIsDisplayed(withText("10$minuteString")) 142 + clickOnViewWithText(coreR.string.change_record_type_goal_time_hint) 143 + 144 + // Category added 145 + clickOnViewWithText(coreR.string.change_record_type_save) 124 146 checkViewIsDisplayed(withText(name)) 125 147 checkViewIsDisplayed(withCardColor(lastColor)) 126 148 ··· 131 153 checkViewIsDisplayed(withId(baseR.id.viewDividerItem)) 132 154 onView(withText(typeName1)).check(isCompletelyAbove(withId(baseR.id.viewDividerItem))) 133 155 onView(withText(typeName2)).check(isCompletelyBelow(withId(baseR.id.viewDividerItem))) 156 + 157 + // Check goals saved 158 + clickOnViewWithText(coreR.string.change_category_types_hint) 159 + clickOnViewWithText(coreR.string.change_record_type_goal_time_hint) 160 + checkViewIsDisplayed(withText("10$minuteString")) 134 161 } 135 162 136 163 @Test 137 - fun addCategoryTypesEmpty() { 164 + fun addCategoryEmpty() { 138 165 NavUtils.openSettingsScreen() 139 166 NavUtils.openCategoriesScreen() 140 167 clickOnViewWithText(coreR.string.categories_add_category) 168 + 169 + // Goal time is disabled 170 + clickOnViewWithText(coreR.string.change_record_type_goal_time_hint) 171 + checkViewIsDisplayed( 172 + allOf( 173 + isDescendantOfA(withId(R.id.layoutChangeRecordTypeGoalSession)), 174 + withId(R.id.tvChangeRecordTypeGoalDurationValue), 175 + withText(coreR.string.change_record_type_goal_time_disabled), 176 + ), 177 + ) 178 + clickOnViewWithText(coreR.string.change_record_type_goal_time_hint) 141 179 142 180 // Open activity chooser 143 181 clickOnViewWithText(coreR.string.change_category_types_hint)
+1 -1
app/src/androidTest/java/com/example/util/simpletimetracker/AddRecordTypeTest.kt
··· 172 172 } 173 173 174 174 @Test 175 - fun addRecordTypeCategoriesEmpty() { 175 + fun addRecordTypeEmpty() { 176 176 tryAction { clickOnViewWithText(coreR.string.running_records_add_type) } 177 177 178 178 // Goal time is disabled
+130
app/src/androidTest/java/com/example/util/simpletimetracker/GoalsOnCardsTest.kt
··· 1 + package com.example.util.simpletimetracker 2 + 3 + import android.view.View 4 + import androidx.test.espresso.matcher.ViewMatchers.hasDescendant 5 + import androidx.test.espresso.matcher.ViewMatchers.isCompletelyDisplayed 6 + import androidx.test.espresso.matcher.ViewMatchers.isDescendantOfA 7 + import androidx.test.espresso.matcher.ViewMatchers.withId 8 + import androidx.test.espresso.matcher.ViewMatchers.withText 9 + import androidx.test.ext.junit.runners.AndroidJUnit4 10 + import com.example.util.simpletimetracker.feature_change_record.R 11 + import com.example.util.simpletimetracker.utils.BaseUiTest 12 + import com.example.util.simpletimetracker.utils.NavUtils 13 + import com.example.util.simpletimetracker.utils.checkViewIsDisplayed 14 + import com.example.util.simpletimetracker.utils.checkViewIsNotDisplayed 15 + import dagger.hilt.android.testing.HiltAndroidTest 16 + import org.hamcrest.CoreMatchers.allOf 17 + import org.hamcrest.Matcher 18 + import org.junit.Test 19 + import org.junit.runner.RunWith 20 + import java.util.concurrent.TimeUnit 21 + 22 + @HiltAndroidTest 23 + @RunWith(AndroidJUnit4::class) 24 + class GoalsOnCardsTest : BaseUiTest() { 25 + 26 + @Test 27 + fun noGoals() { 28 + val noGoals = "noGoals" 29 + val otherGoals = "otherGoals" 30 + 31 + // Add data 32 + testUtils.addActivity(noGoals) 33 + testUtils.addActivity( 34 + name = otherGoals, 35 + goals = listOf( 36 + GoalsTestUtils.getSessionDurationGoal(1), 37 + GoalsTestUtils.getWeeklyDurationGoal(1), 38 + GoalsTestUtils.getMonthlyDurationGoal(1), 39 + GoalsTestUtils.getWeeklyCountGoal(1), 40 + GoalsTestUtils.getMonthlyCountGoal(1), 41 + ), 42 + ) 43 + Thread.sleep(1000) 44 + 45 + // Check 46 + checkNoGoal(noGoals) 47 + checkNoGoal(otherGoals) 48 + } 49 + 50 + @Test 51 + fun checkmarks() { 52 + val durationGoal = "durationGoal" 53 + val countGoal = "countGoal" 54 + 55 + // Add data 56 + testUtils.addActivity( 57 + name = durationGoal, 58 + goals = listOf(GoalsTestUtils.getDailyDurationGoal(2)), 59 + ) 60 + testUtils.addActivity( 61 + name = countGoal, 62 + goals = listOf(GoalsTestUtils.getDailyCountGoal(2)), 63 + ) 64 + Thread.sleep(1000) 65 + 66 + // Not reached 67 + checkCheckmark(durationGoal, isVisible = false) 68 + checkCheckmark(countGoal, isVisible = false) 69 + 70 + // Add records 71 + NavUtils.openRecordsScreen() 72 + val current = System.currentTimeMillis() 73 + testUtils.addRecord( 74 + typeName = durationGoal, 75 + timeStarted = current - TimeUnit.SECONDS.toMillis(1), 76 + timeEnded = current, 77 + ) 78 + testUtils.addRecord( 79 + typeName = countGoal, 80 + ) 81 + 82 + // Not reached 83 + NavUtils.openRunningRecordsScreen() 84 + checkCheckmark(durationGoal, isVisible = false) 85 + checkCheckmark(countGoal, isVisible = false) 86 + 87 + // Add more records 88 + NavUtils.openRecordsScreen() 89 + testUtils.addRecord( 90 + typeName = durationGoal, 91 + timeStarted = current - TimeUnit.SECONDS.toMillis(1), 92 + timeEnded = current, 93 + ) 94 + testUtils.addRecord( 95 + typeName = countGoal, 96 + ) 97 + 98 + // Reached 99 + NavUtils.openRunningRecordsScreen() 100 + checkCheckmark(durationGoal, isVisible = true) 101 + checkCheckmark(countGoal, isVisible = true) 102 + } 103 + 104 + private fun checkNoGoal(typeName: String) { 105 + allOf(withId(R.id.viewRecordTypeItem), hasDescendant(withText(typeName)), isCompletelyDisplayed()) 106 + .let(::checkViewIsDisplayed) 107 + allOf(getTypeMatcher(typeName), withId(R.id.ivGoalCheckmarkItemCheckOutline)) 108 + .let(::checkViewIsNotDisplayed) 109 + allOf(getTypeMatcher(typeName), withId(R.id.ivGoalCheckmarkItemCheck)) 110 + .let(::checkViewIsNotDisplayed) 111 + } 112 + 113 + private fun checkCheckmark(typeName: String, isVisible: Boolean) { 114 + allOf(withId(R.id.viewRecordTypeItem), hasDescendant(withText(typeName)), isCompletelyDisplayed()) 115 + .let(::checkViewIsDisplayed) 116 + allOf(getTypeMatcher(typeName), withId(R.id.ivGoalCheckmarkItemCheckOutline)) 117 + .let(::checkViewIsDisplayed) 118 + allOf(getTypeMatcher(typeName), withId(R.id.ivGoalCheckmarkItemCheck)) 119 + .let { if (isVisible) checkViewIsDisplayed(it) else checkViewIsNotDisplayed(it) } 120 + } 121 + 122 + private fun getTypeMatcher(typeName: String): Matcher<View> { 123 + return isDescendantOfA( 124 + allOf( 125 + withId(R.id.viewRecordTypeItem), 126 + hasDescendant(withText(typeName)), 127 + ), 128 + ) 129 + } 130 + }
+380
app/src/androidTest/java/com/example/util/simpletimetracker/GoalsStatisticsTest.kt
··· 1 1 package com.example.util.simpletimetracker 2 2 3 3 import androidx.test.espresso.Espresso.onView 4 + import androidx.test.espresso.Espresso.pressBack 4 5 import androidx.test.espresso.matcher.ViewMatchers.hasDescendant 5 6 import androidx.test.espresso.matcher.ViewMatchers.isCompletelyDisplayed 6 7 import androidx.test.espresso.matcher.ViewMatchers.withId ··· 11 12 import com.example.util.simpletimetracker.utils.BaseUiTest 12 13 import com.example.util.simpletimetracker.utils.NavUtils 13 14 import com.example.util.simpletimetracker.utils.clickOnViewWithId 15 + import com.example.util.simpletimetracker.utils.clickOnViewWithIdOnPager 14 16 import com.example.util.simpletimetracker.utils.clickOnViewWithText 15 17 import com.example.util.simpletimetracker.utils.scrollRecyclerInPagerToView 16 18 import com.example.util.simpletimetracker.utils.scrollToBottom ··· 256 258 GoalsTestUtils.checkNoGoal(otherGoals) 257 259 } 258 260 261 + @Test 262 + fun dailyCategoryGoal() { 263 + val goal = getString(coreR.string.change_record_type_goal_time_hint).lowercase() 264 + 265 + val goalTimeNotFinished = "goalTimeNotFinished" 266 + val goalTimeFinished = "goalTimeFinished" 267 + val goalCountNotFinished = "goalCountNotFinished" 268 + val goalCountFinished = "goalCountFinished" 269 + val otherGoals = "otherDailyGoals" 270 + 271 + // Add data 272 + testUtils.addCategory( 273 + goalTimeNotFinished, 274 + goals = listOf(GoalsTestUtils.getDailyDurationGoalCategory(8 * durationInSeconds)), 275 + ) 276 + testUtils.addActivity( 277 + goalTimeNotFinished.first(), 278 + categories = listOf(goalTimeNotFinished), 279 + ) 280 + testUtils.addActivity( 281 + goalTimeNotFinished.second(), 282 + categories = listOf(goalTimeNotFinished), 283 + ) 284 + addRecords(testUtils, goalTimeNotFinished.first()) 285 + addRecords(testUtils, goalTimeNotFinished.second()) 286 + 287 + testUtils.addCategory( 288 + goalTimeFinished, 289 + goals = listOf(GoalsTestUtils.getDailyDurationGoalCategory(2 * durationInSeconds)), 290 + ) 291 + testUtils.addActivity( 292 + goalTimeFinished.first(), 293 + categories = listOf(goalTimeFinished), 294 + ) 295 + testUtils.addActivity( 296 + goalTimeFinished.second(), 297 + categories = listOf(goalTimeFinished), 298 + ) 299 + addRecords(testUtils, goalTimeFinished.first()) 300 + addRecords(testUtils, goalTimeFinished.second()) 301 + 302 + testUtils.addCategory( 303 + goalCountNotFinished, 304 + goals = listOf(GoalsTestUtils.getDailyCountGoalCategory(8)), 305 + ) 306 + testUtils.addActivity( 307 + goalCountNotFinished.first(), 308 + categories = listOf(goalCountNotFinished), 309 + ) 310 + testUtils.addActivity( 311 + goalCountNotFinished.second(), 312 + categories = listOf(goalCountNotFinished), 313 + ) 314 + addRecords(testUtils, goalCountNotFinished.first()) 315 + addRecords(testUtils, goalCountNotFinished.second()) 316 + 317 + testUtils.addCategory( 318 + goalCountFinished, 319 + goals = listOf(GoalsTestUtils.getDailyCountGoalCategory(3)), 320 + ) 321 + testUtils.addActivity( 322 + goalCountFinished.first(), 323 + categories = listOf(goalCountFinished), 324 + ) 325 + testUtils.addActivity( 326 + goalCountFinished.second(), 327 + categories = listOf(goalCountFinished), 328 + ) 329 + testUtils.addRecord(goalCountFinished.first()) 330 + testUtils.addRecord(goalCountFinished.second()) 331 + addRecords(testUtils, goalCountFinished.first()) 332 + 333 + testUtils.addCategory( 334 + otherGoals, 335 + goals = listOf( 336 + GoalsTestUtils.getWeeklyDurationGoalCategory(durationInSeconds), 337 + GoalsTestUtils.getMonthlyCountGoalCategory(1), 338 + ), 339 + ) 340 + testUtils.addActivity( 341 + otherGoals.first(), 342 + categories = listOf(otherGoals), 343 + ) 344 + testUtils.addActivity( 345 + otherGoals.second(), 346 + categories = listOf(otherGoals), 347 + ) 348 + addRecords(testUtils, otherGoals.first()) 349 + addRecords(testUtils, otherGoals.second()) 350 + 351 + NavUtils.openStatisticsScreen() 352 + clickOnViewWithIdOnPager(statisticsR.id.btnStatisticsChartFilter) 353 + clickOnViewWithText(coreR.string.category_hint) 354 + pressBack() 355 + 356 + // Goal time not finished 357 + scrollTo(goalTimeNotFinished) 358 + GoalsTestUtils.checkGoal(goalTimeNotFinished, "20$minuteString", "$goal - 1$hourString 20$minuteString") 359 + GoalsTestUtils.checkGoalPercent(goalTimeNotFinished, "25%") 360 + GoalsTestUtils.checkGoalMark(goalTimeNotFinished, isVisible = false) 361 + 362 + // Goal time finished 363 + scrollTo(goalTimeFinished) 364 + GoalsTestUtils.checkGoal(goalTimeFinished, "20$minuteString", "$goal - 20$minuteString") 365 + GoalsTestUtils.checkGoalMark(goalTimeFinished, isVisible = true) 366 + 367 + // Goal count not finished 368 + scrollTo(goalCountNotFinished) 369 + GoalsTestUtils.checkGoal(goalCountNotFinished, "2 Records", "$goal - 8 Records") 370 + GoalsTestUtils.checkGoalPercent(goalCountNotFinished, "25%") 371 + GoalsTestUtils.checkGoalMark(goalCountNotFinished, isVisible = false) 372 + 373 + // Goal count finished 374 + scrollTo(goalCountFinished) 375 + GoalsTestUtils.checkGoal(goalCountFinished, "3 Records", "$goal - 3 Records") 376 + GoalsTestUtils.checkGoalMark(goalCountFinished, isVisible = true) 377 + 378 + // Other goals 379 + scrollBottom() 380 + GoalsTestUtils.checkNoGoal(otherGoals) 381 + } 382 + 383 + @Test 384 + fun weeklyCategoryGoal() { 385 + val goal = getString(coreR.string.change_record_type_goal_time_hint).lowercase() 386 + 387 + val goalTimeNotFinished = "goalTimeNotFinished" 388 + val goalTimeFinished = "goalTimeFinished" 389 + val goalCountNotFinished = "goalCountNotFinished" 390 + val goalCountFinished = "goalCountFinished" 391 + val otherGoals = "otherWeeklyGoals" 392 + 393 + // Add data 394 + testUtils.addCategory( 395 + goalTimeNotFinished, 396 + goals = listOf(GoalsTestUtils.getWeeklyDurationGoalCategory(8 * durationInSeconds)), 397 + ) 398 + testUtils.addActivity( 399 + goalTimeNotFinished.first(), 400 + categories = listOf(goalTimeNotFinished), 401 + ) 402 + testUtils.addActivity( 403 + goalTimeNotFinished.second(), 404 + categories = listOf(goalTimeNotFinished), 405 + ) 406 + addRecords(testUtils, goalTimeNotFinished.first()) 407 + addRecords(testUtils, goalTimeNotFinished.second()) 408 + 409 + testUtils.addCategory( 410 + goalTimeFinished, 411 + goals = listOf(GoalsTestUtils.getWeeklyDurationGoalCategory(2 * durationInSeconds)), 412 + ) 413 + testUtils.addActivity( 414 + goalTimeFinished.first(), 415 + categories = listOf(goalTimeFinished), 416 + ) 417 + testUtils.addActivity( 418 + goalTimeFinished.second(), 419 + categories = listOf(goalTimeFinished), 420 + ) 421 + addRecords(testUtils, goalTimeFinished.first()) 422 + addRecords(testUtils, goalTimeFinished.second()) 423 + 424 + testUtils.addCategory( 425 + goalCountNotFinished, 426 + goals = listOf(GoalsTestUtils.getWeeklyCountGoalCategory(8)), 427 + ) 428 + testUtils.addActivity( 429 + goalCountNotFinished.first(), 430 + categories = listOf(goalCountNotFinished), 431 + ) 432 + testUtils.addActivity( 433 + goalCountNotFinished.second(), 434 + categories = listOf(goalCountNotFinished), 435 + ) 436 + addRecords(testUtils, goalCountNotFinished.first()) 437 + addRecords(testUtils, goalCountNotFinished.second()) 438 + 439 + testUtils.addCategory( 440 + goalCountFinished, 441 + goals = listOf(GoalsTestUtils.getWeeklyCountGoalCategory(3)), 442 + ) 443 + testUtils.addActivity( 444 + goalCountFinished.first(), 445 + categories = listOf(goalCountFinished), 446 + ) 447 + testUtils.addActivity( 448 + goalCountFinished.second(), 449 + categories = listOf(goalCountFinished), 450 + ) 451 + testUtils.addRecord(goalCountFinished.first()) 452 + testUtils.addRecord(goalCountFinished.second()) 453 + addRecords(testUtils, goalCountFinished.first()) 454 + 455 + testUtils.addCategory( 456 + otherGoals, 457 + goals = listOf( 458 + GoalsTestUtils.getDailyDurationGoalCategory(durationInSeconds), 459 + GoalsTestUtils.getMonthlyCountGoalCategory(1), 460 + ), 461 + ) 462 + testUtils.addActivity( 463 + otherGoals.first(), 464 + categories = listOf(otherGoals), 465 + ) 466 + testUtils.addActivity( 467 + otherGoals.second(), 468 + categories = listOf(otherGoals), 469 + ) 470 + addRecords(testUtils, otherGoals.first()) 471 + addRecords(testUtils, otherGoals.second()) 472 + 473 + NavUtils.openStatisticsScreen() 474 + clickOnViewWithId(statisticsR.id.btnStatisticsContainerToday) 475 + clickOnViewWithText(coreR.string.range_week) 476 + clickOnViewWithIdOnPager(statisticsR.id.btnStatisticsChartFilter) 477 + clickOnViewWithText(coreR.string.category_hint) 478 + pressBack() 479 + 480 + // Goal time not finished 481 + scrollTo(goalTimeNotFinished) 482 + GoalsTestUtils.checkGoal(goalTimeNotFinished, "40$minuteString", "$goal - 1$hourString 20$minuteString") 483 + GoalsTestUtils.checkGoalPercent(goalTimeNotFinished, "50%") 484 + GoalsTestUtils.checkGoalMark(goalTimeNotFinished, isVisible = false) 485 + 486 + // Goal time finished 487 + scrollTo(goalTimeFinished) 488 + GoalsTestUtils.checkGoal(goalTimeFinished, "40$minuteString", "$goal - 20$minuteString") 489 + GoalsTestUtils.checkGoalMark(goalTimeFinished, isVisible = true) 490 + 491 + // Goal count not finished 492 + scrollTo(goalCountNotFinished) 493 + GoalsTestUtils.checkGoal(goalCountNotFinished, "4 Records", "$goal - 8 Records") 494 + GoalsTestUtils.checkGoalPercent(goalCountNotFinished, "50%") 495 + GoalsTestUtils.checkGoalMark(goalCountNotFinished, isVisible = false) 496 + 497 + // Goal count finished 498 + scrollTo(goalCountFinished) 499 + GoalsTestUtils.checkGoal(goalCountFinished, "4 Records", "$goal - 3 Records") 500 + GoalsTestUtils.checkGoalMark(goalCountFinished, isVisible = true) 501 + 502 + // Other goals 503 + scrollBottom() 504 + GoalsTestUtils.checkNoGoal(otherGoals) 505 + } 506 + 507 + @Test 508 + fun monthlyCategoryGoal() { 509 + val goal = getString(coreR.string.change_record_type_goal_time_hint).lowercase() 510 + 511 + val goalTimeNotFinished = "goalTimeNotFinished" 512 + val goalTimeFinished = "goalTimeFinished" 513 + val goalCountNotFinished = "goalCountNotFinished" 514 + val goalCountFinished = "goalCountFinished" 515 + val otherGoals = "otherMonthlyGoals" 516 + 517 + // Add data 518 + testUtils.addCategory( 519 + goalTimeNotFinished, 520 + goals = listOf(GoalsTestUtils.getMonthlyDurationGoalCategory(8 * durationInSeconds)), 521 + ) 522 + testUtils.addActivity( 523 + goalTimeNotFinished.first(), 524 + categories = listOf(goalTimeNotFinished), 525 + ) 526 + testUtils.addActivity( 527 + goalTimeNotFinished.second(), 528 + categories = listOf(goalTimeNotFinished), 529 + ) 530 + addRecords(testUtils, goalTimeNotFinished.first()) 531 + addRecords(testUtils, goalTimeNotFinished.second()) 532 + 533 + testUtils.addCategory( 534 + goalTimeFinished, 535 + goals = listOf(GoalsTestUtils.getMonthlyDurationGoalCategory(2 * durationInSeconds)), 536 + ) 537 + testUtils.addActivity( 538 + goalTimeFinished.first(), 539 + categories = listOf(goalTimeFinished), 540 + ) 541 + testUtils.addActivity( 542 + goalTimeFinished.second(), 543 + categories = listOf(goalTimeFinished), 544 + ) 545 + addRecords(testUtils, goalTimeFinished.first()) 546 + addRecords(testUtils, goalTimeFinished.second()) 547 + 548 + testUtils.addCategory( 549 + goalCountNotFinished, 550 + goals = listOf(GoalsTestUtils.getMonthlyCountGoalCategory(8)), 551 + ) 552 + testUtils.addActivity( 553 + goalCountNotFinished.first(), 554 + categories = listOf(goalCountNotFinished), 555 + ) 556 + testUtils.addActivity( 557 + goalCountNotFinished.second(), 558 + categories = listOf(goalCountNotFinished), 559 + ) 560 + addRecords(testUtils, goalCountNotFinished.first()) 561 + addRecords(testUtils, goalCountNotFinished.second()) 562 + 563 + testUtils.addCategory( 564 + goalCountFinished, 565 + goals = listOf(GoalsTestUtils.getMonthlyCountGoalCategory(3)), 566 + ) 567 + testUtils.addActivity( 568 + goalCountFinished.first(), 569 + categories = listOf(goalCountFinished), 570 + ) 571 + testUtils.addActivity( 572 + goalCountFinished.second(), 573 + categories = listOf(goalCountFinished), 574 + ) 575 + testUtils.addRecord(goalCountFinished.first()) 576 + testUtils.addRecord(goalCountFinished.second()) 577 + addRecords(testUtils, goalCountFinished.first()) 578 + 579 + testUtils.addCategory( 580 + otherGoals, 581 + goals = listOf( 582 + GoalsTestUtils.getDailyDurationGoalCategory(durationInSeconds), 583 + GoalsTestUtils.getWeeklyCountGoalCategory(1), 584 + ), 585 + ) 586 + testUtils.addActivity( 587 + otherGoals.first(), 588 + categories = listOf(otherGoals), 589 + ) 590 + testUtils.addActivity( 591 + otherGoals.second(), 592 + categories = listOf(otherGoals), 593 + ) 594 + addRecords(testUtils, otherGoals.first()) 595 + addRecords(testUtils, otherGoals.second()) 596 + 597 + NavUtils.openStatisticsScreen() 598 + clickOnViewWithId(statisticsR.id.btnStatisticsContainerToday) 599 + clickOnViewWithText(coreR.string.range_month) 600 + clickOnViewWithIdOnPager(statisticsR.id.btnStatisticsChartFilter) 601 + clickOnViewWithText(coreR.string.category_hint) 602 + pressBack() 603 + 604 + // Goal time not finished 605 + scrollTo(goalTimeNotFinished) 606 + GoalsTestUtils.checkGoal(goalTimeNotFinished, "1$hourString 0$minuteString", "$goal - 1$hourString 20$minuteString") 607 + GoalsTestUtils.checkGoalPercent(goalTimeNotFinished, "75%") 608 + GoalsTestUtils.checkGoalMark(goalTimeNotFinished, isVisible = false) 609 + 610 + // Goal time finished 611 + scrollTo(goalTimeFinished) 612 + GoalsTestUtils.checkGoal(goalTimeFinished, "1$hourString 0$minuteString", "$goal - 20$minuteString") 613 + GoalsTestUtils.checkGoalMark(goalTimeFinished, isVisible = true) 614 + 615 + // Goal count not finished 616 + scrollTo(goalCountNotFinished) 617 + GoalsTestUtils.checkGoal(goalCountNotFinished, "6 Records", "$goal - 8 Records") 618 + GoalsTestUtils.checkGoalPercent(goalCountNotFinished, "75%") 619 + GoalsTestUtils.checkGoalMark(goalCountNotFinished, isVisible = false) 620 + 621 + // Goal count finished 622 + scrollTo(goalCountFinished) 623 + GoalsTestUtils.checkGoal(goalCountFinished, "5 Records", "$goal - 3 Records") 624 + GoalsTestUtils.checkGoalMark(goalCountFinished, isVisible = true) 625 + 626 + // Other goals 627 + scrollBottom() 628 + GoalsTestUtils.checkNoGoal(otherGoals) 629 + } 630 + 259 631 private fun scrollTo(typeName: String) { 260 632 tryAction { 261 633 scrollRecyclerInPagerToView( ··· 267 639 268 640 private fun scrollBottom() { 269 641 onView(allOf(withId(statisticsR.id.rvStatisticsList), isCompletelyDisplayed())).perform(scrollToBottom()) 642 + } 643 + 644 + private fun String.first(): String { 645 + return this + "1" 646 + } 647 + 648 + private fun String.second(): String { 649 + return this + "2" 270 650 } 271 651 }
+37
app/src/androidTest/java/com/example/util/simpletimetracker/GoalsTestUtils.kt
··· 24 24 fun getSessionDurationGoal(duration: Long): RecordTypeGoal = 25 25 getDurationGoal(RecordTypeGoal.Range.Session, duration) 26 26 27 + fun getSessionDurationGoalCategory(duration: Long): RecordTypeGoal = 28 + getDurationGoalCategory(RecordTypeGoal.Range.Session, duration) 29 + 27 30 fun getDailyDurationGoal(duration: Long): RecordTypeGoal = 28 31 getDurationGoal(RecordTypeGoal.Range.Daily, duration) 32 + 33 + fun getDailyDurationGoalCategory(duration: Long): RecordTypeGoal = 34 + getDurationGoalCategory(RecordTypeGoal.Range.Daily, duration) 29 35 30 36 fun getWeeklyDurationGoal(duration: Long): RecordTypeGoal = 31 37 getDurationGoal(RecordTypeGoal.Range.Weekly, duration) 32 38 39 + fun getWeeklyDurationGoalCategory(duration: Long): RecordTypeGoal = 40 + getDurationGoalCategory(RecordTypeGoal.Range.Weekly, duration) 41 + 33 42 fun getMonthlyDurationGoal(duration: Long): RecordTypeGoal = 34 43 getDurationGoal(RecordTypeGoal.Range.Monthly, duration) 44 + 45 + fun getMonthlyDurationGoalCategory(duration: Long): RecordTypeGoal = 46 + getDurationGoalCategory(RecordTypeGoal.Range.Monthly, duration) 35 47 36 48 fun getDailyCountGoal(count: Long): RecordTypeGoal = 37 49 getCountGoal(RecordTypeGoal.Range.Daily, count) 38 50 51 + fun getDailyCountGoalCategory(count: Long): RecordTypeGoal = 52 + getCountGoalCategory(RecordTypeGoal.Range.Daily, count) 53 + 39 54 fun getWeeklyCountGoal(count: Long): RecordTypeGoal = 40 55 getCountGoal(RecordTypeGoal.Range.Weekly, count) 41 56 57 + fun getWeeklyCountGoalCategory(count: Long): RecordTypeGoal = 58 + getCountGoalCategory(RecordTypeGoal.Range.Weekly, count) 59 + 42 60 fun getMonthlyCountGoal(count: Long): RecordTypeGoal = 43 61 getCountGoal(RecordTypeGoal.Range.Monthly, count) 62 + 63 + fun getMonthlyCountGoalCategory(count: Long): RecordTypeGoal = 64 + getCountGoalCategory(RecordTypeGoal.Range.Monthly, count) 44 65 45 66 fun addRecords(testUtils: TestUtils, typeName: String) { 46 67 val currentTime = Calendar.getInstance().apply { ··· 135 156 ) 136 157 } 137 158 159 + private fun getDurationGoalCategory( 160 + range: RecordTypeGoal.Range, 161 + duration: Long, 162 + ): RecordTypeGoal { 163 + return getDurationGoal(range = range, duration = duration) 164 + .copy(idData = RecordTypeGoal.IdData.Category(0)) 165 + } 166 + 138 167 private fun getCountGoal( 139 168 range: RecordTypeGoal.Range, 140 169 count: Long, ··· 144 173 range = range, 145 174 type = RecordTypeGoal.Type.Count(count), 146 175 ) 176 + } 177 + 178 + private fun getCountGoalCategory( 179 + range: RecordTypeGoal.Range, 180 + count: Long, 181 + ): RecordTypeGoal { 182 + return getCountGoal(range = range, count = count) 183 + .copy(idData = RecordTypeGoal.IdData.Category(0)) 147 184 } 148 185 }
+6 -1
core/src/main/java/com/example/util/simpletimetracker/core/utils/TestUtils.kt
··· 147 147 148 148 fun addCategory( 149 149 tagName: String, 150 + goals: List<RecordTypeGoal> = emptyList(), 150 151 ) = runBlocking { 151 152 val data = Category( 152 153 name = tagName, 153 154 color = AppColor(colorId = 0, colorInt = ""), 154 155 ) 155 156 156 - categoryInteractor.add(data) 157 + val categoryId = categoryInteractor.add(data) 158 + 159 + goals.forEach { 160 + recordTypeGoalInteractor.add(it.copy(idData = RecordTypeGoal.IdData.Category(categoryId))) 161 + } 157 162 } 158 163 159 164 fun addRecordTag(