Skip to content

Commit 6943bea

Browse files
committed
add new tests
1 parent 1f1c12f commit 6943bea

File tree

14 files changed

+276
-26
lines changed

14 files changed

+276
-26
lines changed

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

+1
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,7 @@ class ChangeRecordTest : BaseUiTest() {
5959
testUtils.addActivity(name = newName, color = lastColor, text = lastEmoji)
6060
testUtils.addRecordTag(tag1, name)
6161
testUtils.addRecordTag(tag2, newName)
62+
Thread.sleep(1000)
6263

6364
// Add record
6465
NavUtils.openRecordsScreen()

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

+1
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,7 @@ class ChangeRunningRecordTest : BaseUiTest() {
7676
)
7777
testUtils.addActivity(name = name2, color = lastColor, text = lastEmoji)
7878
testUtils.addRecordTag(tag2, name2)
79+
Thread.sleep(1000)
7980

8081
// Start timer
8182
tryAction { clickOnViewWithText(name1) }
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,249 @@
1+
package com.example.util.simpletimetracker
2+
3+
import androidx.test.espresso.Espresso.pressBack
4+
import androidx.test.espresso.matcher.ViewMatchers.hasDescendant
5+
import androidx.test.espresso.matcher.ViewMatchers.isCompletelyDisplayed
6+
import androidx.test.espresso.matcher.ViewMatchers.withId
7+
import androidx.test.espresso.matcher.ViewMatchers.withText
8+
import androidx.test.ext.junit.runners.AndroidJUnit4
9+
import com.example.util.simpletimetracker.core.extension.setToStartOfDay
10+
import com.example.util.simpletimetracker.utils.BaseUiTest
11+
import com.example.util.simpletimetracker.utils.NavUtils
12+
import com.example.util.simpletimetracker.utils.checkViewDoesNotExist
13+
import com.example.util.simpletimetracker.utils.checkViewIsDisplayed
14+
import com.example.util.simpletimetracker.utils.clickOnViewWithText
15+
import com.example.util.simpletimetracker.utils.longClickOnView
16+
import com.example.util.simpletimetracker.utils.tryAction
17+
import com.example.util.simpletimetracker.utils.withCardColor
18+
import com.example.util.simpletimetracker.utils.withTag
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 java.util.Calendar
24+
import java.util.concurrent.TimeUnit
25+
import com.example.util.simpletimetracker.core.R as coreR
26+
import com.example.util.simpletimetracker.feature_base_adapter.R as baseR
27+
28+
@HiltAndroidTest
29+
@RunWith(AndroidJUnit4::class)
30+
class RecordActionsChangeTagTest : BaseUiTest() {
31+
32+
@Test
33+
fun visibility() {
34+
val recordWithTags = "recordWithTags"
35+
val recordWithNoTags = "recordWithNoTags"
36+
val runningWithTags = "runningWithTags"
37+
val runningWithNoTags = "runningWithNoTags"
38+
val recordTag = "recordTag"
39+
val runningTag = "runningTag"
40+
41+
// Setup
42+
testUtils.addActivity(recordWithTags)
43+
testUtils.addActivity(recordWithNoTags)
44+
testUtils.addActivity(runningWithTags)
45+
testUtils.addActivity(runningWithNoTags)
46+
testUtils.addRecordTag(recordTag, typeName = recordWithTags)
47+
testUtils.addRecordTag(runningTag, typeName = runningWithTags)
48+
testUtils.addRunningRecord(runningWithTags)
49+
testUtils.addRunningRecord(runningWithNoTags)
50+
testUtils.addRecord(recordWithTags)
51+
testUtils.addRecord(recordWithNoTags)
52+
calendar.timeInMillis = System.currentTimeMillis()
53+
testUtils.addRecord(
54+
typeName = recordWithTags,
55+
timeStarted = calendar.timeInMillis - TimeUnit.DAYS.toMillis(1),
56+
timeEnded = calendar.timeInMillis - TimeUnit.DAYS.toMillis(1),
57+
)
58+
Thread.sleep(1000)
59+
60+
// Running record with tags - shown
61+
NavUtils.openRecordsScreen()
62+
longClickOnView(allOf(withText(runningWithTags), isCompletelyDisplayed()))
63+
checkViewIsDisplayed(withText(coreR.string.data_edit_change_tag))
64+
pressBack()
65+
66+
// Running records with no tags - not shown
67+
NavUtils.openRecordsScreen()
68+
longClickOnView(allOf(withText(runningWithNoTags), isCompletelyDisplayed()))
69+
checkViewDoesNotExist(withText(coreR.string.data_edit_change_tag))
70+
pressBack()
71+
72+
// Record with tags - shown
73+
longClickOnView(allOf(withText(recordWithTags), isCompletelyDisplayed()))
74+
checkViewIsDisplayed(withText(coreR.string.data_edit_change_tag))
75+
pressBack()
76+
77+
// Record with no tags - not shown
78+
longClickOnView(allOf(withText(recordWithNoTags), isCompletelyDisplayed()))
79+
checkViewDoesNotExist(withText(coreR.string.data_edit_change_tag))
80+
pressBack()
81+
82+
// Untracked - not shown
83+
longClickOnView(allOf(withText(coreR.string.untracked_time_name), isCompletelyDisplayed()))
84+
checkViewDoesNotExist(withText(coreR.string.data_edit_change_tag))
85+
}
86+
87+
@Test
88+
fun record() {
89+
val name1 = "Name1"
90+
val color1 = firstColor
91+
val icon1 = firstIcon
92+
val comment = "Some_comment"
93+
val tag = "Tag"
94+
val tagGeneral = "TagGeneral"
95+
val fullName1 = "$name1 - $tag, $tagGeneral"
96+
val fullName2 = "$name1 - $tagGeneral"
97+
val calendar = Calendar.getInstance()
98+
99+
// Setup
100+
val current = calendar.timeInMillis
101+
val difference = TimeUnit.MINUTES.toMillis(30)
102+
val timeStartedTimestamp = current - difference
103+
val timeStartedPreview = timeStartedTimestamp.formatTime()
104+
val timeEndedPreview = current.formatTime()
105+
val timeRangePreview = difference.formatInterval()
106+
107+
testUtils.addActivity(name = name1, color = color1, icon = icon1)
108+
testUtils.addRecordTag(tag, typeName = name1)
109+
testUtils.addRecordTag(tagGeneral)
110+
testUtils.addRecord(
111+
typeName = name1,
112+
timeStarted = timeStartedTimestamp,
113+
timeEnded = current,
114+
tagNames = listOf(tag, tagGeneral),
115+
comment = comment,
116+
)
117+
118+
// Check record
119+
NavUtils.openRecordsScreen()
120+
checkRecord(
121+
name = fullName1,
122+
color = color1,
123+
icon = icon1,
124+
timeStartedPreview = timeStartedPreview,
125+
timeEndedPreview = timeEndedPreview,
126+
timeRangePreview = timeRangePreview,
127+
comment = comment,
128+
)
129+
130+
// Change
131+
longClickOnView(allOf(withText(fullName1), isCompletelyDisplayed()))
132+
clickOnViewWithText(R.string.data_edit_change_tag)
133+
clickOnViewWithText(tag)
134+
clickOnViewWithText(R.string.change_record_save)
135+
136+
tryAction {
137+
checkRecord(
138+
name = fullName2,
139+
color = color1,
140+
icon = icon1,
141+
timeStartedPreview = timeStartedPreview,
142+
timeEndedPreview = timeEndedPreview,
143+
timeRangePreview = timeRangePreview,
144+
comment = comment,
145+
)
146+
}
147+
}
148+
149+
@Test
150+
fun runningRecord() {
151+
val name1 = "Name1"
152+
val color1 = firstColor
153+
val icon1 = firstIcon
154+
val comment = "Some_comment"
155+
val tag = "Tag"
156+
val tagGeneral = "TagGeneral"
157+
val fullName1 = "$name1 - $tag, $tagGeneral"
158+
val fullName2 = "$name1 - $tagGeneral"
159+
val calendar = Calendar.getInstance()
160+
161+
// Setup
162+
val current = calendar.timeInMillis
163+
val difference = TimeUnit.MINUTES.toMillis(30)
164+
val timeStartedTimestamp = current - difference
165+
val timeStartedPreview = timeStartedTimestamp.formatTime()
166+
167+
testUtils.addActivity(name = name1, color = color1, icon = icon1)
168+
testUtils.addRecordTag(tag, typeName = name1)
169+
testUtils.addRecordTag(tagGeneral)
170+
testUtils.addRunningRecord(
171+
typeName = name1,
172+
timeStarted = timeStartedTimestamp,
173+
tagNames = listOf(tag, tagGeneral),
174+
comment = comment,
175+
)
176+
177+
// Check record
178+
NavUtils.openRecordsScreen()
179+
checkRunningRecord(
180+
name = fullName1,
181+
color = color1,
182+
icon = icon1,
183+
timeStartedPreview = timeStartedPreview,
184+
comment = comment,
185+
)
186+
187+
// Change
188+
longClickOnView(allOf(withText(fullName1), isCompletelyDisplayed()))
189+
clickOnViewWithText(R.string.data_edit_change_tag)
190+
clickOnViewWithText(tag)
191+
clickOnViewWithText(R.string.change_record_save)
192+
193+
tryAction {
194+
checkRunningRecord(
195+
name = fullName2,
196+
color = color1,
197+
icon = icon1,
198+
timeStartedPreview = timeStartedPreview,
199+
comment = comment,
200+
)
201+
}
202+
}
203+
204+
@Suppress("SameParameterValue")
205+
private fun checkRecord(
206+
name: String,
207+
color: Int,
208+
icon: Int,
209+
timeStartedPreview: String,
210+
timeEndedPreview: String,
211+
timeRangePreview: String,
212+
comment: String,
213+
) {
214+
checkViewIsDisplayed(
215+
allOf(
216+
withId(baseR.id.viewRecordItem),
217+
withCardColor(color),
218+
hasDescendant(withText(name)),
219+
hasDescendant(withTag(icon)),
220+
hasDescendant(withText(timeStartedPreview)),
221+
hasDescendant(withText(timeEndedPreview)),
222+
hasDescendant(withText(timeRangePreview)),
223+
hasDescendant(withText(comment)),
224+
isCompletelyDisplayed(),
225+
),
226+
)
227+
}
228+
229+
@Suppress("SameParameterValue")
230+
private fun checkRunningRecord(
231+
name: String,
232+
color: Int,
233+
icon: Int,
234+
timeStartedPreview: String,
235+
comment: String,
236+
) {
237+
checkViewIsDisplayed(
238+
allOf(
239+
withId(baseR.id.viewRunningRecordItem),
240+
withCardColor(color),
241+
hasDescendant(withText(name)),
242+
hasDescendant(withTag(icon)),
243+
hasDescendant(withText(timeStartedPreview)),
244+
hasDescendant(withText(comment)),
245+
isCompletelyDisplayed(),
246+
),
247+
)
248+
}
249+
}

core/src/main/java/com/example/util/simpletimetracker/core/extension/ViewDataExensions.kt

+2-2
Original file line numberDiff line numberDiff line change
@@ -47,28 +47,28 @@ fun Range.toParams(): RangeParams {
4747
fun ChangeRunningRecordParams.Preview.GoalTimeParams.toViewData(): GoalTimeViewData {
4848
return GoalTimeViewData(
4949
text = this.text,
50-
complete = this.complete,
5150
state = this.state.toViewData(),
5251
)
5352
}
5453

5554
fun GoalTimeViewData.toParams(): ChangeRunningRecordParams.Preview.GoalTimeParams {
5655
return ChangeRunningRecordParams.Preview.GoalTimeParams(
5756
text = this.text,
58-
complete = this.complete,
5957
state = this.state.toParams(),
6058
)
6159
}
6260

6361
fun ChangeRunningRecordParams.Preview.GoalSubtypeParams.toViewData(): GoalTimeViewData.Subtype {
6462
return when (this) {
63+
is ChangeRunningRecordParams.Preview.GoalSubtypeParams.Hidden -> GoalTimeViewData.Subtype.Hidden
6564
is ChangeRunningRecordParams.Preview.GoalSubtypeParams.Goal -> GoalTimeViewData.Subtype.Goal
6665
is ChangeRunningRecordParams.Preview.GoalSubtypeParams.Limit -> GoalTimeViewData.Subtype.Limit
6766
}
6867
}
6968

7069
fun GoalTimeViewData.Subtype.toParams(): ChangeRunningRecordParams.Preview.GoalSubtypeParams {
7170
return when (this) {
71+
is GoalTimeViewData.Subtype.Hidden -> ChangeRunningRecordParams.Preview.GoalSubtypeParams.Hidden
7272
is GoalTimeViewData.Subtype.Goal -> ChangeRunningRecordParams.Preview.GoalSubtypeParams.Goal
7373
is GoalTimeViewData.Subtype.Limit -> ChangeRunningRecordParams.Preview.GoalSubtypeParams.Limit
7474
}

core/src/main/java/com/example/util/simpletimetracker/core/mapper/GoalViewDataMapper.kt

+7-8
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,10 @@ import com.example.util.simpletimetracker.core.viewData.StatisticsDataHolder
77
import com.example.util.simpletimetracker.domain.extension.orFalse
88
import com.example.util.simpletimetracker.domain.extension.orZero
99
import com.example.util.simpletimetracker.domain.recordType.extension.value
10-
import com.example.util.simpletimetracker.domain.statistics.model.ChartFilterType
11-
import com.example.util.simpletimetracker.domain.statistics.model.RangeLength
1210
import com.example.util.simpletimetracker.domain.recordType.model.RecordType
1311
import com.example.util.simpletimetracker.domain.recordType.model.RecordTypeGoal
12+
import com.example.util.simpletimetracker.domain.statistics.model.ChartFilterType
13+
import com.example.util.simpletimetracker.domain.statistics.model.RangeLength
1414
import com.example.util.simpletimetracker.domain.statistics.model.Statistics
1515
import com.example.util.simpletimetracker.feature_base_adapter.runningRecord.GoalTimeViewData
1616
import com.example.util.simpletimetracker.feature_base_adapter.statisticsGoal.StatisticsGoalViewData
@@ -33,8 +33,7 @@ class GoalViewDataMapper @Inject constructor(
3333
): GoalTimeViewData {
3434
val noGoal = GoalTimeViewData(
3535
text = "",
36-
complete = false,
37-
state = GoalTimeViewData.Subtype.Goal,
36+
state = GoalTimeViewData.Subtype.Hidden,
3837
)
3938
if (goal == null || goal.value <= 0L || !goalsVisible) {
4039
return noGoal
@@ -80,14 +79,14 @@ class GoalViewDataMapper @Inject constructor(
8079
"$typeString $formatted"
8180
}
8281

83-
val state = when (goal.subtype) {
84-
is RecordTypeGoal.Subtype.Goal -> GoalTimeViewData.Subtype.Goal
85-
is RecordTypeGoal.Subtype.Limit -> GoalTimeViewData.Subtype.Limit
82+
val state = when {
83+
complete && goal.subtype is RecordTypeGoal.Subtype.Goal -> GoalTimeViewData.Subtype.Goal
84+
complete && goal.subtype is RecordTypeGoal.Subtype.Limit -> GoalTimeViewData.Subtype.Limit
85+
else -> GoalTimeViewData.Subtype.Hidden
8686
}
8787

8888
return GoalTimeViewData(
8989
text = durationLeftString,
90-
complete = complete,
9190
state = state,
9291
)
9392
}

core/src/main/java/com/example/util/simpletimetracker/core/utils/ViewUtis.kt

+1-1
Original file line numberDiff line numberDiff line change
@@ -45,8 +45,8 @@ fun updateRunningRecordPreview(
4545
// Update if goal was shown and need update.
4646
if (it.itemGoalTime.isNotEmpty() && update.goalText.isNotEmpty()) {
4747
it.itemGoalTime = update.goalText
48-
it.itemGoalTimeComplete = update.goalComplete
4948
it.itemGoalTimeCheck = when (update.goalState) {
49+
is GoalState.Hidden -> CheckState.HIDDEN
5050
is GoalState.Goal -> CheckState.GOAL_REACHED
5151
is GoalState.Limit -> CheckState.LIMIT_REACHED
5252
}

domain/src/main/java/com/example/util/simpletimetracker/domain/record/interactor/UpdateRunningRecordFromChangeScreenInteractor.kt

+3-3
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,6 @@ class UpdateRunningRecordFromChangeScreenInteractor @Inject constructor() {
2626
val timer: String,
2727
val timerTotal: String,
2828
val goalText: String,
29-
val goalComplete: Boolean,
3029
val goalState: GoalState,
3130
val additionalData: AdditionalData?,
3231
)
@@ -38,7 +37,8 @@ class UpdateRunningRecordFromChangeScreenInteractor @Inject constructor() {
3837
)
3938

4039
sealed interface GoalState {
41-
object Goal : GoalState
42-
object Limit : GoalState
40+
data object Hidden : GoalState
41+
data object Goal : GoalState
42+
data object Limit : GoalState
4343
}
4444
}

features/feature_base_adapter/src/main/java/com/example/util/simpletimetracker/feature_base_adapter/runningRecord/GoalTimeViewData.kt

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,11 @@ package com.example.util.simpletimetracker.feature_base_adapter.runningRecord
22

33
data class GoalTimeViewData(
44
val text: String,
5-
val complete: Boolean,
65
val state: Subtype,
76
) {
87

98
sealed interface Subtype {
9+
data object Hidden : Subtype
1010
data object Goal : Subtype
1111
data object Limit : Subtype
1212
}

features/feature_base_adapter/src/main/java/com/example/util/simpletimetracker/feature_base_adapter/runningRecord/RunningRecordAdapterDelegate.kt

+2-1
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ package com.example.util.simpletimetracker.feature_base_adapter.runningRecord
22

33
import androidx.core.view.ViewCompat
44
import com.example.util.simpletimetracker.domain.extension.orFalse
5+
import com.example.util.simpletimetracker.domain.record.interactor.UpdateRunningRecordFromChangeScreenInteractor.GoalState
56
import com.example.util.simpletimetracker.feature_base_adapter.createRecyclerBindingAdapterDelegate
67
import com.example.util.simpletimetracker.feature_base_adapter.runningRecord.GoalTimeViewData.Subtype
78
import com.example.util.simpletimetracker.feature_views.GoalCheckmarkView.CheckState
@@ -42,8 +43,8 @@ fun createRunningRecordAdapterDelegate(
4243
}
4344
if (rebind || updates.contains(ViewData.UPDATE_GOAL_TIME).orFalse()) {
4445
itemGoalTime = item.goalTime.text
45-
itemGoalTimeComplete = item.goalTime.complete
4646
itemGoalTimeCheck = when (item.goalTime.state) {
47+
is Subtype.Hidden -> CheckState.HIDDEN
4748
is Subtype.Goal -> CheckState.GOAL_REACHED
4849
is Subtype.Limit -> CheckState.LIMIT_REACHED
4950
}

0 commit comments

Comments
 (0)