Skip to content

Commit 468c0cf

Browse files
committed
edit shortcut screen
1 parent d3f1d2c commit 468c0cf

File tree

49 files changed

+1996
-121
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

49 files changed

+1996
-121
lines changed

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -116,6 +116,7 @@
116116
│ ├── feature_change_record_tag # Edit tag screen.
117117
│ ├── feature_change_record_type # Edit type screen.
118118
│ ├── feature_change_running_record # Edit timer screen.
119+
│ ├── feature_change_shortcut # Edit shortcut screen.
119120
│ ├── feature_complex_rules # Screen for complex rules list.
120121
│ ├── feature_date_edit # Data edit screen.
121122
│ ├── feature_dialogs # Dialogs.

app/build.gradle.kts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -128,6 +128,7 @@ dependencies {
128128
implementation(project(":feature_complex_rules"))
129129
implementation(project(":feature_suggestions"))
130130
implementation(project(":feature_shortcuts"))
131+
implementation(project(":feature_change_shortcut"))
131132
implementation(project(":feature_change_complex_rule"))
132133
implementation(project(":feature_change_goals"))
133134
implementation(project(":feature_change_goals:api"))
Lines changed: 189 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,189 @@
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+
}

app/src/androidTest/java/com/example/util/simpletimetracker/SettingsTest.kt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1146,7 +1146,7 @@ class SettingsTest : BaseUiTest() {
11461146
hasDescendant(withText(name)),
11471147
),
11481148
)
1149-
clickOnView(withText(R.string.cancel))
1149+
pressBack()
11501150
clickOnView(
11511151
allOf(
11521152
withId(R.id.viewRecordShortcutItem),
@@ -1238,7 +1238,7 @@ class SettingsTest : BaseUiTest() {
12381238
hasDescendant(withText(name)),
12391239
),
12401240
)
1241-
clickOnView(withText(R.string.cancel))
1241+
pressBack()
12421242
longClickOnView(
12431243
allOf(
12441244
withId(R.id.viewRecordShortcutItem),

app/src/androidTest/java/com/example/util/simpletimetracker/RecordShortcutsTest.kt renamed to app/src/androidTest/java/com/example/util/simpletimetracker/ShortcutsTest.kt

Lines changed: 46 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import androidx.test.espresso.matcher.ViewMatchers.isCompletelyDisplayed
77
import androidx.test.espresso.matcher.ViewMatchers.withId
88
import androidx.test.espresso.matcher.ViewMatchers.withText
99
import androidx.test.ext.junit.runners.AndroidJUnit4
10+
import com.example.util.simpletimetracker.domain.recordShortcut.model.RecordShortcut
1011
import com.example.util.simpletimetracker.feature_base_adapter.R
1112
import com.example.util.simpletimetracker.utils.BaseUiTest
1213
import com.example.util.simpletimetracker.utils.NavUtils
@@ -32,7 +33,7 @@ import com.example.util.simpletimetracker.feature_change_record.R as changeRecor
3233

3334
@HiltAndroidTest
3435
@RunWith(AndroidJUnit4::class)
35-
class RecordShortcutsTest : BaseUiTest() {
36+
class ShortcutsTest : BaseUiTest() {
3637

3738
@Test
3839
fun actionVisibility() {
@@ -124,16 +125,17 @@ class RecordShortcutsTest : BaseUiTest() {
124125

125126
// Check shortcut
126127
NavUtils.openRunningRecordsScreen()
127-
checkShortcut(fullShortcutName)
128+
checkRecordShortcut(fullShortcutName)
128129

129130
// Delete
130131
longClickOnView(withText(fullShortcutName))
132+
clickOnViewWithText(R.string.archive_dialog_delete)
131133
clickOnViewWithText(R.string.ok)
132134
checkViewDoesNotExist(withText(fullShortcutName))
133135
}
134136

135137
@Test
136-
fun start() {
138+
fun startRecord() {
137139
val name = "Name"
138140
val color = firstColor
139141
val icon = firstIcon
@@ -148,14 +150,37 @@ class RecordShortcutsTest : BaseUiTest() {
148150
testUtils.addShortcut(typeName = name, tagNames = listOf(tag), comment = comment)
149151
Thread.sleep(1000)
150152

151-
// Start
152-
tryAction { checkShortcut(fullShortcutName) }
153+
// Check
154+
tryAction { checkRecordShortcut(fullShortcutName) }
153155
clickOnViewWithText(fullShortcutName)
154156
checkRunningRecord(fullRecordName, comment)
155157
}
156158

159+
@Test
160+
fun changeSetting() {
161+
val name = "name"
162+
val settingShortcutName = getString(coreR.string.settings_retroactive_tracking_mode)
163+
164+
// Add data
165+
testUtils.addActivity(name)
166+
testUtils.addSettingShortcut(RecordShortcut.SettingAction.RetroactiveMode)
167+
Thread.sleep(1000)
168+
169+
// Check shortcuts
170+
tryAction {
171+
checkSettingShortcut(name = settingShortcutName, isEnabled = false)
172+
}
173+
174+
// Start
175+
clickOnViewWithText(settingShortcutName)
176+
checkSettingShortcut(name = settingShortcutName, isEnabled = true)
177+
tryAction {
178+
checkViewIsDisplayed(withText(R.string.retroactive_tracking_mode_hint))
179+
}
180+
}
181+
157182
@Suppress("SameParameterValue")
158-
private fun checkShortcut(
183+
private fun checkRecordShortcut(
159184
name: String,
160185
) {
161186
checkViewIsDisplayed(
@@ -169,6 +194,21 @@ class RecordShortcutsTest : BaseUiTest() {
169194
)
170195
}
171196

197+
@Suppress("SameParameterValue")
198+
private fun checkSettingShortcut(
199+
name: String,
200+
isEnabled: Boolean,
201+
) {
202+
val color = if (isEnabled) R.color.colorSecondary else R.color.colorInactive
203+
checkViewIsDisplayed(
204+
allOf(
205+
withId(baseR.id.viewRecordShortcutItem),
206+
withCardColor(color),
207+
hasDescendant(withText(name)),
208+
),
209+
)
210+
}
211+
172212
@Suppress("SameParameterValue")
173213
private fun checkRunningRecord(
174214
name: String,

app/src/androidTest/java/com/example/util/simpletimetracker/utils/NavUtils.kt

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -115,6 +115,12 @@ object NavUtils {
115115
Thread.sleep(1000)
116116
}
117117

118+
fun openShortcutsScreen() {
119+
scrollSettingsRecyclerToText(coreR.string.change_record_shortcut)
120+
clickOnSettingsRecyclerText(coreR.string.change_record_shortcut)
121+
Thread.sleep(1000)
122+
}
123+
118124
fun openCardSizeScreen() {
119125
scrollSettingsRecyclerToText(coreR.string.settings_change_card_size)
120126
clickOnSettingsRecyclerText(coreR.string.settings_change_card_size)

app/src/androidTest/java/com/example/util/simpletimetracker/utils/ViewActions.kt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ import androidx.test.espresso.matcher.ViewMatchers.isDescendantOfA
2727
import androidx.test.espresso.matcher.ViewMatchers.isDisplayed
2828
import androidx.test.espresso.matcher.ViewMatchers.isDisplayingAtLeast
2929
import androidx.test.espresso.matcher.ViewMatchers.withEffectiveVisibility
30+
import com.example.util.simpletimetracker.domain.extension.orZero
3031
import com.google.android.material.tabs.TabLayout
3132
import org.hamcrest.Matcher
3233
import org.hamcrest.Matchers.allOf
@@ -236,7 +237,7 @@ fun scrollToBottom(): ViewAction = object : ViewAction {
236237
override fun perform(uiController: UiController?, view: View?) {
237238
val recyclerView = view as RecyclerView
238239
val itemCount = recyclerView.adapter?.itemCount
239-
val position = itemCount?.minus(1) ?: 0
240+
val position = itemCount?.minus(1).orZero()
240241
recyclerView.scrollToPosition(position)
241242
uiController?.loopMainThreadUntilIdle()
242243
}

app/src/main/java/com/example/util/simpletimetracker/di/NavigationScreenMapModule.kt

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import com.example.util.simpletimetracker.feature_change_record.view.ChangeRecor
88
import com.example.util.simpletimetracker.feature_change_record_tag.view.ChangeRecordTagFragment
99
import com.example.util.simpletimetracker.feature_change_record_type.view.ChangeRecordTypeFragment
1010
import com.example.util.simpletimetracker.feature_change_running_record.view.ChangeRunningRecordFragment
11+
import com.example.util.simpletimetracker.feature_change_shortcut.view.ChangeShortcutFragment
1112
import com.example.util.simpletimetracker.feature_records_all.view.RecordsAllFragment
1213
import com.example.util.simpletimetracker.feature_statistics_detail.view.StatisticsDetailFragment
1314
import com.example.util.simpletimetracker.navigation.NavigationData
@@ -29,6 +30,7 @@ import com.example.util.simpletimetracker.navigation.params.screen.ChangeRecordT
2930
import com.example.util.simpletimetracker.navigation.params.screen.ChangeRecordTypeParams
3031
import com.example.util.simpletimetracker.navigation.params.screen.ChangeRunningRecordFromMainParams
3132
import com.example.util.simpletimetracker.navigation.params.screen.ChangeRunningRecordFromRecordsAllParams
33+
import com.example.util.simpletimetracker.navigation.params.screen.ChangeShortcutParams
3234
import com.example.util.simpletimetracker.navigation.params.screen.ComplexRulesParams
3335
import com.example.util.simpletimetracker.navigation.params.screen.DataEditParams
3436
import com.example.util.simpletimetracker.navigation.params.screen.PomodoroParams
@@ -164,6 +166,26 @@ class NavigationScreenMapModule {
164166
)
165167
}
166168

169+
@IntoMap
170+
@Provides
171+
@ScreenKey(ChangeShortcutParams.Change::class)
172+
fun changeShortcutChange(): NavigationData {
173+
return NavigationData(
174+
R.id.action_to_changeShortcutFragment,
175+
bundleCreatorDelegate(ChangeShortcutFragment::createBundle),
176+
)
177+
}
178+
179+
@IntoMap
180+
@Provides
181+
@ScreenKey(ChangeShortcutParams.New::class)
182+
fun changeShortcutNew(): NavigationData {
183+
return NavigationData(
184+
R.id.action_to_changeShortcutFragment,
185+
bundleCreatorDelegate(ChangeShortcutFragment::createBundle),
186+
)
187+
}
188+
167189
@IntoMap
168190
@Provides
169191
@ScreenKey(ActivitySuggestionsParams::class)

0 commit comments

Comments
 (0)