|
| 1 | +package com.example.util.simpletimetracker |
| 2 | + |
| 3 | +import androidx.test.espresso.matcher.ViewMatchers.hasDescendant |
| 4 | +import androidx.test.espresso.matcher.ViewMatchers.withId |
| 5 | +import androidx.test.espresso.matcher.ViewMatchers.withText |
| 6 | +import androidx.test.ext.junit.runners.AndroidJUnit4 |
| 7 | +import com.example.util.simpletimetracker.utils.BaseUiTest |
| 8 | +import com.example.util.simpletimetracker.utils.NavUtils |
| 9 | +import com.example.util.simpletimetracker.utils.checkViewDoesNotExist |
| 10 | +import com.example.util.simpletimetracker.utils.checkViewIsDisplayed |
| 11 | +import com.example.util.simpletimetracker.utils.checkViewIsNotDisplayed |
| 12 | +import com.example.util.simpletimetracker.utils.clickOnRecyclerItem |
| 13 | +import com.example.util.simpletimetracker.utils.clickOnView |
| 14 | +import com.example.util.simpletimetracker.utils.clickOnViewWithId |
| 15 | +import com.example.util.simpletimetracker.utils.clickOnViewWithText |
| 16 | +import com.example.util.simpletimetracker.utils.longClickOnView |
| 17 | +import com.example.util.simpletimetracker.utils.scrollRecyclerToView |
| 18 | +import com.example.util.simpletimetracker.utils.tryAction |
| 19 | +import dagger.hilt.android.testing.HiltAndroidTest |
| 20 | +import org.hamcrest.CoreMatchers.allOf |
| 21 | +import org.junit.Test |
| 22 | +import org.junit.runner.RunWith |
| 23 | +import com.example.util.simpletimetracker.core.R as coreR |
| 24 | +import com.example.util.simpletimetracker.feature_base_adapter.R as baseR |
| 25 | +import com.example.util.simpletimetracker.feature_change_shortcut.R as changeShortcutR |
| 26 | + |
| 27 | +@HiltAndroidTest |
| 28 | +@RunWith(AndroidJUnit4::class) |
| 29 | +class ChangeShortcutTest : BaseUiTest() { |
| 30 | + |
| 31 | + @Test |
| 32 | + fun navigationAdd() { |
| 33 | + // Check buttons |
| 34 | + openShortcutsScreen() |
| 35 | + clickOnViewWithText(coreR.string.running_records_add_type) |
| 36 | + checkViewIsDisplayed(withId(changeShortcutR.id.btnChangeShortcutSave)) |
| 37 | + checkViewIsNotDisplayed(withId(changeShortcutR.id.btnChangeShortcutDelete)) |
| 38 | + } |
| 39 | + |
| 40 | + @Test |
| 41 | + fun navigationEdit() { |
| 42 | + val name = "name" |
| 43 | + |
| 44 | + // Add data |
| 45 | + testUtils.addActivity(name) |
| 46 | + testUtils.addShortcut(name) |
| 47 | + |
| 48 | + // Check buttons |
| 49 | + openShortcutsScreen() |
| 50 | + clickShortcut(name) |
| 51 | + checkViewIsDisplayed(withId(changeShortcutR.id.btnChangeShortcutDelete)) |
| 52 | + } |
| 53 | + |
| 54 | + @Test |
| 55 | + fun navigationFromTimers() { |
| 56 | + val name = "name" |
| 57 | + |
| 58 | + // Add data |
| 59 | + testUtils.addActivity(name) |
| 60 | + testUtils.addShortcut(name) |
| 61 | + Thread.sleep(1000) |
| 62 | + |
| 63 | + // Open edit |
| 64 | + NavUtils.openRunningRecordsScreen() |
| 65 | + longClickOnView( |
| 66 | + allOf( |
| 67 | + withId(baseR.id.viewRecordShortcutItem), |
| 68 | + hasDescendant(withText(name)), |
| 69 | + ), |
| 70 | + ) |
| 71 | + checkViewIsDisplayed(withId(changeShortcutR.id.btnChangeShortcutDelete)) |
| 72 | + } |
| 73 | + |
| 74 | + @Test |
| 75 | + fun createRecordShortcut() { |
| 76 | + val name = "name" |
| 77 | + |
| 78 | + // Add data |
| 79 | + testUtils.addActivity(name) |
| 80 | + |
| 81 | + // Check record |
| 82 | + openShortcutsScreen() |
| 83 | + clickOnViewWithText(coreR.string.running_records_add_type) |
| 84 | + selectRecordType(name) |
| 85 | + clickOnViewWithId(changeShortcutR.id.btnChangeShortcutSave) |
| 86 | + |
| 87 | + // Check saved |
| 88 | + tryAction { checkShortcut(name) } |
| 89 | + } |
| 90 | + |
| 91 | + @Test |
| 92 | + fun createSettingShortcut() { |
| 93 | + // Check setting |
| 94 | + openShortcutsScreen() |
| 95 | + clickOnViewWithText(coreR.string.running_records_add_type) |
| 96 | + clickOnViewWithText(coreR.string.shortcut_navigation_settings) |
| 97 | + clickOnViewWithId(changeShortcutR.id.fieldChangeShortcutSettingAction) |
| 98 | + clickOnRecyclerItem( |
| 99 | + changeShortcutR.id.rvChangeShortcutSettingAction, |
| 100 | + withText(coreR.string.settings_allow_multitasking), |
| 101 | + ) |
| 102 | + clickOnViewWithId(changeShortcutR.id.btnChangeShortcutSave) |
| 103 | + |
| 104 | + // Check saved |
| 105 | + tryAction { checkShortcut(getString(coreR.string.settings_allow_multitasking)) } |
| 106 | + } |
| 107 | + |
| 108 | + @Test |
| 109 | + fun edit() { |
| 110 | + val nameBefore = "name1" |
| 111 | + val nameAfter = "name2" |
| 112 | + |
| 113 | + // Add data |
| 114 | + testUtils.addActivity(nameBefore) |
| 115 | + testUtils.addActivity(nameAfter) |
| 116 | + testUtils.addShortcut(nameBefore) |
| 117 | + |
| 118 | + // Update |
| 119 | + openShortcutsScreen() |
| 120 | + clickShortcut(nameBefore) |
| 121 | + selectRecordType(nameAfter) |
| 122 | + clickOnViewWithId(changeShortcutR.id.btnChangeShortcutSave) |
| 123 | + |
| 124 | + // Check updated |
| 125 | + tryAction { checkShortcut(nameAfter) } |
| 126 | + checkViewDoesNotExist( |
| 127 | + allOf( |
| 128 | + withId(baseR.id.viewRecordShortcutItem), |
| 129 | + hasDescendant(withText(nameBefore)), |
| 130 | + ), |
| 131 | + ) |
| 132 | + } |
| 133 | + |
| 134 | + @Test |
| 135 | + fun delete() { |
| 136 | + val name = "name" |
| 137 | + |
| 138 | + // Add data |
| 139 | + testUtils.addActivity(name) |
| 140 | + testUtils.addShortcut(name) |
| 141 | + |
| 142 | + // Delete |
| 143 | + openShortcutsScreen() |
| 144 | + clickShortcut(name) |
| 145 | + clickOnViewWithId(changeShortcutR.id.btnChangeShortcutDelete) |
| 146 | + clickOnViewWithText(R.string.ok) |
| 147 | + |
| 148 | + // Check |
| 149 | + checkViewDoesNotExist( |
| 150 | + allOf( |
| 151 | + withId(baseR.id.viewRecordShortcutItem), |
| 152 | + hasDescendant(withText(name)), |
| 153 | + ), |
| 154 | + ) |
| 155 | + } |
| 156 | + |
| 157 | + private fun openShortcutsScreen() { |
| 158 | + NavUtils.openSettingsScreen() |
| 159 | + NavUtils.openSettingsAdditional() |
| 160 | + NavUtils.openShortcutsScreen() |
| 161 | + } |
| 162 | + |
| 163 | + private fun selectRecordType(name: String) { |
| 164 | + clickOnViewWithId(changeShortcutR.id.fieldChangeShortcutType) |
| 165 | + scrollRecyclerToView( |
| 166 | + changeShortcutR.id.rvChangeShortcutType, |
| 167 | + hasDescendant(withText(name)), |
| 168 | + ) |
| 169 | + clickOnRecyclerItem(changeShortcutR.id.rvChangeShortcutType, withText(name)) |
| 170 | + } |
| 171 | + |
| 172 | + private fun clickShortcut(name: String) { |
| 173 | + clickOnView( |
| 174 | + allOf( |
| 175 | + withId(baseR.id.viewRecordShortcutItem), |
| 176 | + hasDescendant(withText(name)), |
| 177 | + ), |
| 178 | + ) |
| 179 | + } |
| 180 | + |
| 181 | + private fun checkShortcut(name: String) { |
| 182 | + checkViewIsDisplayed( |
| 183 | + allOf( |
| 184 | + withId(baseR.id.viewRecordShortcutItem), |
| 185 | + hasDescendant(withText(name)), |
| 186 | + ), |
| 187 | + ) |
| 188 | + } |
| 189 | +} |
0 commit comments