Skip to content

Commit

Permalink
fix tests
Browse files Browse the repository at this point in the history
  • Loading branch information
Razeeman committed Aug 11, 2024
1 parent b7ebb4f commit 4c3648e
Show file tree
Hide file tree
Showing 20 changed files with 97 additions and 31 deletions.
30 changes: 11 additions & 19 deletions .github/workflows/github_actions.yml
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ jobs:
strategy:
fail-fast: false
matrix:
api-level: [21, 28, 29]
api-level: [21, 23, 29, 32, 34]

steps:
- name: Check out code
Expand All @@ -55,28 +55,20 @@ jobs:
sudo udevadm control --reload-rules
sudo udevadm trigger --name-match=kvm
- name: Run tests
uses: reactivecircus/android-emulator-runner@v2
with:
api-level: ${{ matrix.api-level }}
target: google_apis
arch: x86_64
disable-animations: true
script: ./gradlew app:connectedPlayDebugAndroidTest -Pandroid.testInstrumentationRunnerArguments.notAnnotation=com.example.util.simpletimetracker.utils.Widget --stacktrace
- name: Setup Android SDK
uses: android-actions/setup-android@v3

- name: Disable animations
run: |
adb shell settings put global window_animation_scale 0
adb shell settings put global transition_animation_scale 0
adb shell settings put global animator_duration_scale 0
# For some reason widget tests make other tests to fail, so run them separately.
- name: Run widget tests
- name: Run tests
uses: reactivecircus/android-emulator-runner@v2
with:
api-level: ${{ matrix.api-level }}
target: google_apis
arch: x86_64
disable-animations: true
script: ./gradlew app:connectedPlayDebugAndroidTest -Pandroid.testInstrumentationRunnerArguments.annotation=com.example.util.simpletimetracker.utils.Widget --stacktrace

- name: Upload tests results
if: ${{ failure() }}
uses: actions/upload-artifact@v2
with:
name: android_tests_results
path: app/build/reports/androidTests/connected
script: ./gradlew app:connectedPlayDebugAndroidTest --stacktrace
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,7 @@ class AddCategoryTest : BaseUiTest() {

// Check types saved
longClickOnView(withText(name))
Thread.sleep(1000)
clickOnViewWithText(coreR.string.change_category_types_hint)
checkViewIsDisplayed(withText(coreR.string.something_selected))
checkViewIsDisplayed(withId(baseR.id.viewDividerItem))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -176,6 +176,7 @@ class AddRecordTypeTest : BaseUiTest() {
@Test
fun addRecordTypeEmpty() {
tryAction { clickOnViewWithText(coreR.string.running_records_add_type) }
closeSoftKeyboard()

// Goal time is disabled
clickOnViewWithText(coreR.string.change_record_type_goal_time_hint)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package com.example.util.simpletimetracker

import android.view.View
import androidx.test.espresso.Espresso.onView
import androidx.test.espresso.Espresso.pressBack
import androidx.test.espresso.ViewInteraction
import androidx.test.espresso.matcher.ViewMatchers.hasDescendant
Expand All @@ -24,6 +25,7 @@ import com.example.util.simpletimetracker.utils.clickOnView
import com.example.util.simpletimetracker.utils.clickOnViewWithId
import com.example.util.simpletimetracker.utils.clickOnViewWithText
import com.example.util.simpletimetracker.utils.longClickOnView
import com.example.util.simpletimetracker.utils.nestedScrollTo
import com.example.util.simpletimetracker.utils.scrollRecyclerInPagerToView
import com.example.util.simpletimetracker.utils.tryAction
import com.example.util.simpletimetracker.utils.withCardColor
Expand Down Expand Up @@ -68,8 +70,10 @@ class GoalsDaysOfWeek : BaseUiTest() {

// Check
tryAction { longClickOnView(withText(name)) }
onView(withText(R.string.change_record_type_goal_time_hint)).perform(nestedScrollTo())
clickOnViewWithText(R.string.change_record_type_goal_time_hint)

onView(withId(changeRecordTypeR.id.layoutChangeRecordTypeGoalSession)).perform(nestedScrollTo())
checkString(
changeRecordTypeR.id.layoutChangeRecordTypeGoalSession,
withText("1$secondString"),
Expand All @@ -81,6 +85,7 @@ class GoalsDaysOfWeek : BaseUiTest() {
::checkViewDoesNotExist,
)

onView(withId(changeRecordTypeR.id.layoutChangeRecordTypeGoalDaily)).perform(nestedScrollTo())
checkString(
changeRecordTypeR.id.layoutChangeRecordTypeGoalDaily,
withText("1$secondString"),
Expand All @@ -92,6 +97,7 @@ class GoalsDaysOfWeek : BaseUiTest() {
::checkViewIsDisplayed,
)

onView(withId(changeRecordTypeR.id.layoutChangeRecordTypeGoalWeekly)).perform(nestedScrollTo())
checkString(
changeRecordTypeR.id.layoutChangeRecordTypeGoalWeekly,
withText("1$secondString"),
Expand All @@ -103,6 +109,7 @@ class GoalsDaysOfWeek : BaseUiTest() {
::checkViewDoesNotExist,
)

onView(withId(changeRecordTypeR.id.layoutChangeRecordTypeGoalMonthly)).perform(nestedScrollTo())
checkString(
changeRecordTypeR.id.layoutChangeRecordTypeGoalMonthly,
withText("1$secondString"),
Expand All @@ -125,6 +132,7 @@ class GoalsDaysOfWeek : BaseUiTest() {
tryAction { longClickOnView(withText(name)) }

// No days by default
onView(withText(R.string.change_record_type_goal_time_hint)).perform(nestedScrollTo())
clickOnViewWithText(R.string.change_record_type_goal_time_hint)
checkViewDoesNotExist(withText(R.string.day_of_week_sunday))

Expand Down Expand Up @@ -198,6 +206,7 @@ class GoalsDaysOfWeek : BaseUiTest() {

// Change days
tryAction { longClickOnView(withText(name1)) }
onView(withText(R.string.change_record_type_goal_time_hint)).perform(nestedScrollTo())
clickOnViewWithText(R.string.change_record_type_goal_time_hint)
clickOnView(withText(R.string.day_of_week_monday))
clickOnView(withText(R.string.day_of_week_wednesday))
Expand All @@ -206,6 +215,7 @@ class GoalsDaysOfWeek : BaseUiTest() {

// Days are saved
tryAction { longClickOnView(withText(name1)) }
onView(withText(R.string.change_record_type_goal_time_hint)).perform(nestedScrollTo())
clickOnViewWithText(R.string.change_record_type_goal_time_hint)
checkTypeDay(stringResId = R.string.day_of_week_sunday, colorResId = R.color.colorActive)
checkTypeDay(stringResId = R.string.day_of_week_monday, colorResId = R.color.colorInactive)
Expand All @@ -218,6 +228,7 @@ class GoalsDaysOfWeek : BaseUiTest() {
pressBack()

tryAction { longClickOnView(withText(name2)) }
onView(withText(R.string.change_record_type_goal_time_hint)).perform(nestedScrollTo())
clickOnViewWithText(R.string.change_record_type_goal_time_hint)
daysResIdList.forEach { checkTypeDay(stringResId = it, colorResId = R.color.colorActive) }
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ import com.example.util.simpletimetracker.utils.checkViewIsDisplayed
import com.example.util.simpletimetracker.utils.clickOnView
import com.example.util.simpletimetracker.utils.clickOnViewWithText
import com.example.util.simpletimetracker.utils.longClickOnView
import com.example.util.simpletimetracker.utils.nestedScrollTo
import com.example.util.simpletimetracker.utils.scrollRecyclerToView
import com.example.util.simpletimetracker.utils.selectTabAtPosition
import com.example.util.simpletimetracker.utils.tryAction
Expand Down Expand Up @@ -91,6 +92,7 @@ class GoalsTabTest : BaseUiTest() {
is RecordTypeGoal.Type.Count -> goal.value.toString()
}

onView(withId(layout)).perform(nestedScrollTo())
checkViewIsDisplayed(
allOf(
isDescendantOfA(withId(layout)),
Expand All @@ -107,6 +109,7 @@ class GoalsTabTest : BaseUiTest() {
goals.forEach { goalsToAdd ->
// Add goals
tryAction { longClickOnView(withText(type)) }
onView(withText(coreR.string.change_record_type_goal_time_hint)).perform(nestedScrollTo())
clickOnViewWithText(coreR.string.change_record_type_goal_time_hint)
goalsToAdd.forEach { goal ->
NavUtils.addGoalToActivity(goal)
Expand All @@ -116,6 +119,7 @@ class GoalsTabTest : BaseUiTest() {

// Check goals saved
longClickOnView(withText(type))
onView(withText(coreR.string.change_record_type_goal_time_hint)).perform(nestedScrollTo())
clickOnViewWithText(coreR.string.change_record_type_goal_time_hint)
goalsToAdd.forEach { goal ->
checkGoal(goal)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ import com.example.util.simpletimetracker.utils.clickOnView
import com.example.util.simpletimetracker.utils.clickOnViewWithText
import com.example.util.simpletimetracker.utils.getMillis
import com.example.util.simpletimetracker.utils.longClickOnView
import com.example.util.simpletimetracker.utils.nestedScrollTo
import com.example.util.simpletimetracker.utils.scrollRecyclerToView
import dagger.hilt.android.testing.HiltAndroidTest
import kotlinx.coroutines.runBlocking
Expand Down Expand Up @@ -91,6 +92,7 @@ class RecordActionsAdjustTest : BaseUiTest() {
adjust(isStart = true, buttonText = "-30")
adjust(isStart = false, buttonText = "+30")
adjust(isStart = false, buttonText = "+30")
onView(withText(coreR.string.change_record_actions_hint)).perform(nestedScrollTo())
clickOnViewWithText(coreR.string.change_record_actions_hint)
scrollRecyclerToView(changeRecordR.id.rvChangeRecordAction, withText(coreR.string.change_record_adjust))
clickOnViewWithText(coreR.string.change_record_adjust)
Expand Down Expand Up @@ -176,6 +178,7 @@ class RecordActionsAdjustTest : BaseUiTest() {
adjust(isStart = false, buttonText = "+1")
clickOnViewWithText(coreR.string.change_record_type_field)
clickOnRecyclerItem(changeRecordR.id.rvChangeRecordType, withText(name2))
onView(withText(coreR.string.change_record_actions_hint)).perform(nestedScrollTo())
clickOnViewWithText(coreR.string.change_record_actions_hint)
scrollRecyclerToView(changeRecordR.id.rvChangeRecordAction, withText(coreR.string.change_record_adjust))
clickOnViewWithText(coreR.string.change_record_adjust)
Expand Down Expand Up @@ -240,6 +243,7 @@ class RecordActionsAdjustTest : BaseUiTest() {
allOf(isDescendantOfA(withId(baseR.id.viewRunningRecordItem)), withText(name2), isCompletelyDisplayed()),
)
clickOnViewWithText("-5")
onView(withText(coreR.string.change_record_actions_hint)).perform(nestedScrollTo())
clickOnViewWithText(coreR.string.change_record_actions_hint)
scrollRecyclerToView(changeRecordR.id.rvChangeRecordAction, withText(coreR.string.change_record_adjust))
clickOnViewWithText(coreR.string.change_record_adjust)
Expand Down Expand Up @@ -292,6 +296,7 @@ class RecordActionsAdjustTest : BaseUiTest() {
adjust(isStart = true, buttonText = "-30")
adjust(isStart = false, buttonText = "+30")
adjust(isStart = false, buttonText = "+30")
onView(withText(coreR.string.change_record_actions_hint)).perform(nestedScrollTo())
clickOnViewWithText(coreR.string.change_record_actions_hint)
scrollRecyclerToView(changeRecordR.id.rvChangeRecordAction, withText(coreR.string.change_record_adjust))
clickOnViewWithText(coreR.string.change_record_adjust)
Expand Down Expand Up @@ -391,6 +396,7 @@ class RecordActionsAdjustTest : BaseUiTest() {
}

// Deselect
onView(withText(coreR.string.change_record_actions_hint)).perform(nestedScrollTo())
clickOnViewWithText(coreR.string.change_record_actions_hint)

scrollToView(name5)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import com.example.util.simpletimetracker.utils.clickOnView
import com.example.util.simpletimetracker.utils.clickOnViewWithId
import com.example.util.simpletimetracker.utils.clickOnViewWithText
import com.example.util.simpletimetracker.utils.longClickOnView
import com.example.util.simpletimetracker.utils.nestedScrollTo
import com.example.util.simpletimetracker.utils.recyclerItemCount
import com.example.util.simpletimetracker.utils.scrollRecyclerToView
import com.example.util.simpletimetracker.utils.tryAction
Expand Down Expand Up @@ -72,6 +73,7 @@ class RecordActionsContinueTest : BaseUiTest() {

// Continue
clickOnViewWithText(fullName)
onView(withText(coreR.string.change_record_actions_hint)).perform(nestedScrollTo())
clickOnViewWithText(coreR.string.change_record_actions_hint)
scrollRecyclerToView(changeRecordR.id.rvChangeRecordAction, withText(coreR.string.change_record_continue))
clickOnViewWithText(coreR.string.change_record_continue)
Expand Down Expand Up @@ -120,17 +122,20 @@ class RecordActionsContinueTest : BaseUiTest() {
clickOnViewWithText(coreR.string.untracked_time_name)

// Continue untracked doesn't work
onView(withText(coreR.string.change_record_actions_hint)).perform(nestedScrollTo())
clickOnViewWithText(coreR.string.change_record_actions_hint)
scrollRecyclerToView(changeRecordR.id.rvChangeRecordAction, withText(coreR.string.change_record_continue))
clickOnViewWithText(coreR.string.change_record_continue)
clickOnViewWithId(com.google.android.material.R.id.snackbar_text)
onView(withText(coreR.string.change_record_actions_hint)).perform(nestedScrollTo())
clickOnViewWithText(coreR.string.change_record_actions_hint)

// Select activity
clickOnViewWithText(coreR.string.change_record_type_field)
clickOnRecyclerItem(changeRecordR.id.rvChangeRecordType, withText(name))

// Continue
onView(withText(coreR.string.change_record_actions_hint)).perform(nestedScrollTo())
clickOnViewWithText(coreR.string.change_record_actions_hint)
scrollRecyclerToView(changeRecordR.id.rvChangeRecordAction, withText(coreR.string.change_record_continue))
clickOnViewWithText(coreR.string.change_record_continue)
Expand Down Expand Up @@ -178,17 +183,20 @@ class RecordActionsContinueTest : BaseUiTest() {
clickOnViewWithId(recordsR.id.btnRecordAdd)

// Continue untracked doesn't work
onView(withText(coreR.string.change_record_actions_hint)).perform(nestedScrollTo())
clickOnViewWithText(coreR.string.change_record_actions_hint)
scrollRecyclerToView(changeRecordR.id.rvChangeRecordAction, withText(coreR.string.change_record_continue))
clickOnViewWithText(coreR.string.change_record_continue)
clickOnViewWithId(com.google.android.material.R.id.snackbar_text)
onView(withText(coreR.string.change_record_actions_hint)).perform(nestedScrollTo())
clickOnViewWithText(coreR.string.change_record_actions_hint)

// Select activity
clickOnViewWithText(coreR.string.change_record_type_field)
clickOnRecyclerItem(changeRecordR.id.rvChangeRecordType, withText(name))

// Continue
onView(withText(coreR.string.change_record_actions_hint)).perform(nestedScrollTo())
clickOnViewWithText(coreR.string.change_record_actions_hint)
scrollRecyclerToView(changeRecordR.id.rvChangeRecordAction, withText(coreR.string.change_record_continue))
clickOnViewWithText(coreR.string.change_record_continue)
Expand Down Expand Up @@ -241,6 +249,7 @@ class RecordActionsContinueTest : BaseUiTest() {
// Try continue record
NavUtils.openRecordsScreen()
clickOnView(allOf(withText(name), isCompletelyDisplayed()))
onView(withText(coreR.string.change_record_actions_hint)).perform(nestedScrollTo())
clickOnViewWithText(coreR.string.change_record_actions_hint)
scrollRecyclerToView(changeRecordR.id.rvChangeRecordAction, withText(coreR.string.change_record_continue))
clickOnViewWithText(coreR.string.change_record_continue)
Expand All @@ -261,6 +270,7 @@ class RecordActionsContinueTest : BaseUiTest() {
adjust("+30")
adjust("+30")
adjust("+5")
onView(withText(coreR.string.change_record_actions_hint)).perform(nestedScrollTo())
clickOnViewWithText(coreR.string.change_record_actions_hint)
scrollRecyclerToView(changeRecordR.id.rvChangeRecordAction, withText(coreR.string.change_record_continue))
clickOnViewWithText(coreR.string.change_record_continue)
Expand Down Expand Up @@ -288,6 +298,7 @@ class RecordActionsContinueTest : BaseUiTest() {
}

// Try continue record
onView(withText(coreR.string.change_record_actions_hint)).perform(nestedScrollTo())
clickOnViewWithText(coreR.string.change_record_actions_hint)
checkViewDoesNotExist(withText(coreR.string.change_record_continue))
}
Expand All @@ -305,6 +316,7 @@ class RecordActionsContinueTest : BaseUiTest() {
clickOnViewWithId(recordsR.id.btnRecordAdd)
clickOnViewWithText(coreR.string.change_record_type_field)
clickOnRecyclerItem(changeRecordR.id.rvChangeRecordType, withText(name))
onView(withText(coreR.string.change_record_actions_hint)).perform(nestedScrollTo())
clickOnViewWithText(coreR.string.change_record_actions_hint)
scrollRecyclerToView(changeRecordR.id.rvChangeRecordAction, withText(coreR.string.change_record_continue))
clickOnViewWithText(coreR.string.change_record_continue)
Expand Down Expand Up @@ -337,6 +349,7 @@ class RecordActionsContinueTest : BaseUiTest() {
clickOnViewWithId(recordsR.id.btnRecordAdd)
clickOnViewWithText(coreR.string.change_record_type_field)
clickOnRecyclerItem(changeRecordR.id.rvChangeRecordType, withText(name2))
onView(withText(coreR.string.change_record_actions_hint)).perform(nestedScrollTo())
clickOnViewWithText(coreR.string.change_record_actions_hint)
scrollRecyclerToView(changeRecordR.id.rvChangeRecordAction, withText(coreR.string.change_record_continue))
clickOnViewWithText(coreR.string.change_record_continue)
Expand Down
Loading

0 comments on commit 4c3648e

Please sign in to comment.