Skip to content

Commit

Permalink
add new tests
Browse files Browse the repository at this point in the history
  • Loading branch information
Razeeman committed Oct 5, 2024
1 parent cf8a880 commit edd8b2b
Show file tree
Hide file tree
Showing 14 changed files with 881 additions and 528 deletions.
1 change: 1 addition & 0 deletions app/proguard-debug-rules.pro
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
-keepclassmembers class com.example.util.simpletimetracker.feature_statistics.view.StatisticsContainerFragment$Companion { void setViewPagerSmoothScroll(boolean); }
-keepclassmembers class com.example.util.simpletimetracker.feature_views.pieChart.PieChartView$Companion { void setDisableAnimationsForTest(boolean); }
-keepclassmembers class com.example.util.simpletimetracker.navigation.ScreenResolver$Companion { void setDisableAnimationsForTest(boolean); }
-keepclassmembers class com.example.util.simpletimetracker.feature_settings.viewModel.delegate.SettingsFileWorkDelegate$Companion { void setRestartAppIsBlocked(boolean); }
-keepclassmembers class com.example.util.simpletimetracker.core.mapper.ColorMapper$Companion { synthetic java.util.List getAvailableColors$default(com.example.util.simpletimetracker.core.mapper.ColorMapper$Companion,boolean,int,java.lang.Object); }
-keep class com.example.util.simpletimetracker.core.utils.CountingIdlingResourceProvider { *; }
-keep class com.example.util.simpletimetracker.core.utils.TestUtils { *; }
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -333,13 +333,13 @@ class ChangeRunningRecordTest : BaseUiTest() {
// Not visible end
tryAction { clickOnViewWithText(type) }
longClickOnView(allOf(isDescendantOfA(withId(changeRecordR.id.viewRunningRecordItem)), withText(type)))
checkViewIsNotDisplayed(withText(coreR.string.change_record_date_time_end))
checkViewIsNotDisplayed(withId(changeRecordR.id.tvChangeRecordTimeEndedAdjust))

// Check
checkField(isDuration = false)
clickOnViewWithText(coreR.string.change_record_date_time_start)
checkField(isDuration = true)
clickOnViewWithText(coreR.string.change_record_date_time_start)
clickOnViewWithText(coreR.string.change_record_date_time_duration)
checkField(isDuration = false)
}

Expand Down

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -1589,17 +1589,22 @@ class SettingsTest : BaseUiTest() {
clickOnSettingsRecyclerText(coreR.string.settings_export_csv)

// View is set up
val currentTime = System.currentTimeMillis()
var timeStarted = timeMapper.formatDateTime(
time = currentTime - TimeUnit.DAYS.toMillis(7), useMilitaryTime = true, showSeconds = false,
)
var timeEnded = timeMapper.formatDateTime(
time = currentTime, useMilitaryTime = true, showSeconds = false,
checkViewIsDisplayed(
allOf(
withId(dialogsR.id.etCsvExportSettingsFileName),
withText("stt_records_{date}.csv"),
),
)
val currentTime = Calendar.getInstance().apply {
timeInMillis = System.currentTimeMillis()
setToStartOfDay()
}.timeInMillis
var timeStarted = currentTime.formatDateTimeYear()
var timeEnded = (currentTime + TimeUnit.DAYS.toMillis(1)).formatDateTimeYear()
checkViewIsDisplayed(allOf(withId(dialogsR.id.tvCsvExportSettingsTimeStarted), withText(timeStarted)))
checkViewIsDisplayed(allOf(withId(dialogsR.id.tvCsvExportSettingsTimeEnded), withText(timeEnded)))

val calendar = Calendar.getInstance().apply {
var calendar = Calendar.getInstance().apply {
add(Calendar.DATE, -1)
}
val hourStarted = 15
Expand Down Expand Up @@ -1632,8 +1637,7 @@ class SettingsTest : BaseUiTest() {
set(Calendar.MINUTE, minutesStarted)
timeInMillis
}
timeStarted = timeStartedTimestamp
.let { timeMapper.formatDateTime(time = it, useMilitaryTime = true, showSeconds = false) }
timeStarted = timeStartedTimestamp.formatDateTimeYear()

checkViewIsDisplayed(allOf(withId(dialogsR.id.tvCsvExportSettingsTimeStarted), withText(timeStarted)))

Expand All @@ -1659,9 +1663,80 @@ class SettingsTest : BaseUiTest() {
set(Calendar.MINUTE, minutesEnded)
timeInMillis
}
timeEnded = timeEndedTimestamp
.let { timeMapper.formatDateTime(time = it, useMilitaryTime = true, showSeconds = false) }
timeEnded = timeEndedTimestamp.formatDateTimeYear()

checkViewIsDisplayed(allOf(withId(dialogsR.id.tvCsvExportSettingsTimeEnded), withText(timeEnded)))

// Check ranges
clickOnViewWithText(R.string.title_today)
calendar = Calendar.getInstance().apply {
timeInMillis = System.currentTimeMillis()
setToStartOfDay()
}
timeStarted = calendar.timeInMillis.formatDateTimeYear()
timeEnded = (calendar.timeInMillis + TimeUnit.DAYS.toMillis(1)).formatDateTimeYear()
checkViewIsDisplayed(allOf(withId(dialogsR.id.tvCsvExportSettingsTimeStarted), withText(timeStarted)))
checkViewIsDisplayed(allOf(withId(dialogsR.id.tvCsvExportSettingsTimeEnded), withText(timeEnded)))

clickOnViewWithText(R.string.title_this_week)
calendar = Calendar.getInstance().apply {
timeInMillis = System.currentTimeMillis()
setToStartOfDay()
setWeekToFirstDay()
}
timeStarted = calendar.timeInMillis.formatDateTimeYear()
timeEnded = (calendar.timeInMillis + TimeUnit.DAYS.toMillis(7)).formatDateTimeYear()
checkViewIsDisplayed(allOf(withId(dialogsR.id.tvCsvExportSettingsTimeStarted), withText(timeStarted)))
checkViewIsDisplayed(allOf(withId(dialogsR.id.tvCsvExportSettingsTimeEnded), withText(timeEnded)))

clickOnViewWithText(R.string.title_this_month)
calendar = Calendar.getInstance().apply {
timeInMillis = System.currentTimeMillis()
setToStartOfDay()
set(Calendar.DAY_OF_MONTH, 1)
}
timeStarted = calendar.timeInMillis.formatDateTimeYear()
calendar.apply {
add(Calendar.MONTH, 1)
}
timeEnded = calendar.timeInMillis.formatDateTimeYear()
checkViewIsDisplayed(allOf(withId(dialogsR.id.tvCsvExportSettingsTimeStarted), withText(timeStarted)))
checkViewIsDisplayed(allOf(withId(dialogsR.id.tvCsvExportSettingsTimeEnded), withText(timeEnded)))

clickOnViewWithText(R.string.title_this_year)
calendar = Calendar.getInstance().apply {
timeInMillis = System.currentTimeMillis()
setToStartOfDay()
set(Calendar.DAY_OF_YEAR, 1)
}
timeStarted = calendar.timeInMillis.formatDateTimeYear()
calendar.apply {
add(Calendar.YEAR, 1)
}
timeEnded = calendar.timeInMillis.formatDateTimeYear()
checkViewIsDisplayed(allOf(withId(dialogsR.id.tvCsvExportSettingsTimeStarted), withText(timeStarted)))
checkViewIsDisplayed(allOf(withId(dialogsR.id.tvCsvExportSettingsTimeEnded), withText(timeEnded)))

clickOnViewWithText(R.string.range_overall)
calendar = Calendar.getInstance().apply {
timeInMillis = 0
}
timeStarted = calendar.timeInMillis.formatDateTimeYear()
calendar.apply {
timeInMillis = System.currentTimeMillis()
}
timeEnded = calendar.timeInMillis.formatDateTimeYear()
checkViewIsDisplayed(allOf(withId(dialogsR.id.tvCsvExportSettingsTimeStarted), withText(timeStarted)))
checkViewIsDisplayed(allOf(withId(dialogsR.id.tvCsvExportSettingsTimeEnded), withText(timeEnded)))

clickOnViewWithText(getQuantityString(R.plurals.range_last, 7, 7))
calendar = Calendar.getInstance().apply {
timeInMillis = System.currentTimeMillis()
setToStartOfDay()
}
timeStarted = (calendar.timeInMillis - TimeUnit.DAYS.toMillis(6)).formatDateTimeYear()
timeEnded = (calendar.timeInMillis + TimeUnit.DAYS.toMillis(1)).formatDateTimeYear()
checkViewIsDisplayed(allOf(withId(dialogsR.id.tvCsvExportSettingsTimeStarted), withText(timeStarted)))
checkViewIsDisplayed(allOf(withId(dialogsR.id.tvCsvExportSettingsTimeEnded), withText(timeEnded)))
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -661,8 +661,13 @@ class StatisticsRangesTest : BaseUiTest() {
clickOnViewWithId(statisticsR.id.btnStatisticsContainerToday)
clickOnViewWithText(coreR.string.range_custom)
clickOnViewWithId(dialogsR.id.btnCustomRangeSelection)
val rangeTitle = calendar.apply {
timeInMillis = System.currentTimeMillis()
}.timeInMillis.formatDate().let {
"$it - $it"
}
checkViewIsDisplayed(
allOf(withId(statisticsR.id.btnStatisticsContainerToday), withText(coreR.string.range_custom)),
allOf(withId(statisticsR.id.btnStatisticsContainerToday), withText(rangeTitle)),
)
checkViewDoesNotExist(allOf(withText(name1), isCompletelyDisplayed()))
checkViewDoesNotExist(allOf(withText(name2), isCompletelyDisplayed()))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import com.example.util.simpletimetracker.domain.interactor.PrefsInteractor
import com.example.util.simpletimetracker.domain.repo.ComplexRuleRepo
import com.example.util.simpletimetracker.domain.resolver.BackupRepo
import com.example.util.simpletimetracker.feature_records.view.RecordsContainerFragment
import com.example.util.simpletimetracker.feature_settings.viewModel.delegate.SettingsFileWorkDelegate
import com.example.util.simpletimetracker.feature_statistics.view.StatisticsContainerFragment
import com.example.util.simpletimetracker.feature_views.pieChart.PieChartView
import com.example.util.simpletimetracker.navigation.ScreenResolver
Expand Down Expand Up @@ -131,6 +132,11 @@ open class BaseUiTest {
.getString(id, *args)
}

internal fun getQuantityString(id: Int, quantity: Int, vararg args: Any): String {
return InstrumentationRegistry.getInstrumentation().targetContext.resources
.getQuantityString(id, quantity, *args)
}

@ColorInt
internal fun getColor(id: Int): Int {
return InstrumentationRegistry.getInstrumentation().targetContext.resources
Expand All @@ -141,10 +147,18 @@ open class BaseUiTest {
return timeMapper.formatTime(time = this, useMilitaryTime = true, showSeconds = false)
}

internal fun Long.formatDate(): String {
return timeMapper.formatDate(time = this)
}

internal fun Long.formatDateTime(): String {
return timeMapper.formatDateTime(time = this, useMilitaryTime = true, showSeconds = false)
}

internal fun Long.formatDateTimeYear(): String {
return timeMapper.formatDateTimeYear(time = this, useMilitaryTime = true)
}

internal fun Long.formatInterval(): String {
return timeMapper.formatInterval(interval = this, forceSeconds = false, useProportionalMinutes = false)
}
Expand All @@ -159,13 +173,15 @@ open class BaseUiTest {
StatisticsContainerFragment.viewPagerSmoothScroll = false
PieChartView.disableAnimationsForTest = true
ScreenResolver.disableAnimationsForTest = true
SettingsFileWorkDelegate.restartAppIsBlocked = true
}

private fun enableAnimations() {
RecordsContainerFragment.viewPagerSmoothScroll = true
StatisticsContainerFragment.viewPagerSmoothScroll = true
PieChartView.disableAnimationsForTest = false
ScreenResolver.disableAnimationsForTest = false
SettingsFileWorkDelegate.restartAppIsBlocked = false
}

private fun registerIdlingResource() {
Expand Down
3 changes: 2 additions & 1 deletion app/src/androidTest/res/raw/db_version_22
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,8 @@ typeToDefaultTag 2 3
typeToDefaultTag 3 3
activityFilter 1 1,2 0 filter1 0 0
activityFilter 2 1,2 1 filter2 0 -13347208 1
favouriteComment 1 comment favourite
favouriteComment 1 comment favourite 1
favouriteComment 2 comment favourite 2
favouriteIcon 1 🍉
favouriteIcon 2 ic_accessibility_24px
recordTypeGoal 1 3 0 0 60 0 0000000
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ class CsvExportSettingsDialogFragment :
}

override fun initUx(): Unit = with(binding) {
etChangeRecordTypeName.doAfterTextChanged { viewModel.onNameChange(it.toString()) }
etCsvExportSettingsFileName.doAfterTextChanged { viewModel.onNameChange(it.toString()) }
fieldCsvExportSettingsTimeStarted.setOnClick(viewModel::onRangeStartClick)
fieldCsvExportSettingsTimeEnded.setOnClick(viewModel::onRangeEndClick)
btnCsvExportSettingsRange.setOnClick(viewModel::onExportClick)
Expand All @@ -91,11 +91,11 @@ class CsvExportSettingsDialogFragment :
private fun updateViewDataState(
viewData: CsvExportSettingsViewData,
) = with(binding) {
if (etChangeRecordTypeName.text.toString() != viewData.fileName) {
etChangeRecordTypeName.setText(viewData.fileName)
if (etCsvExportSettingsFileName.text.toString() != viewData.fileName) {
etCsvExportSettingsFileName.setText(viewData.fileName)
}
inputCsvExportSettingsFileName.hint = viewData.fileNameHint
etChangeRecordTypeName.setTextColor(viewData.fileNameTextColor)
etCsvExportSettingsFileName.setTextColor(viewData.fileNameTextColor)
filterSelectionAdapter.replace(viewData.filters)
tvCsvExportSettingsTimeStarted.text = viewData.rangeStartString
tvCsvExportSettingsTimeStarted.setTextColor(viewData.textColor)
Expand All @@ -104,7 +104,7 @@ class CsvExportSettingsDialogFragment :
}

private fun onResult(
params: DataExportSettingsResult
params: DataExportSettingsResult,
) {
dialogListener?.onDataExportSettingsSelected(params)
dismiss()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@
app:layout_constraintTop_toBottomOf="@id/tvCsvExportSettingsFileNameHint">

<com.google.android.material.textfield.TextInputEditText
android:id="@+id/etChangeRecordTypeName"
android:id="@+id/etCsvExportSettingsFileName"
style="@style/ChangeItemNameEditText"
android:layout_width="match_parent"
android:layout_height="wrap_content"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package com.example.util.simpletimetracker.feature_records_filter.adapter

import android.view.Gravity
import androidx.core.view.isVisible
import com.example.util.simpletimetracker.feature_base_adapter.createRecyclerBindingAdapterDelegate
import com.example.util.simpletimetracker.feature_views.extension.setOnClick
import com.example.util.simpletimetracker.feature_records_filter.adapter.RecordsFilterRangeViewData as ViewData
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,10 @@
package com.example.util.simpletimetracker.feature_settings.viewModel.delegate

import com.example.util.simpletimetracker.core.base.ViewModelDelegate
import com.example.util.simpletimetracker.core.extension.toModel
import com.example.util.simpletimetracker.core.mapper.TimeMapper
import com.example.util.simpletimetracker.domain.extension.flip
import com.example.util.simpletimetracker.domain.interactor.PrefsInteractor
import com.example.util.simpletimetracker.domain.model.BackupOptionsData
import com.example.util.simpletimetracker.domain.model.RangeLength
import com.example.util.simpletimetracker.feature_base_adapter.ViewHolderType
import com.example.util.simpletimetracker.feature_settings.api.SettingsBlock
import com.example.util.simpletimetracker.feature_settings.interactor.SettingsBackupViewDataInteractor
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.example.util.simpletimetracker.feature_settings.viewModel.delegate

import androidx.annotation.VisibleForTesting
import androidx.core.text.HtmlCompat
import com.example.util.simpletimetracker.core.R
import com.example.util.simpletimetracker.core.base.ViewModelDelegate
Expand Down Expand Up @@ -529,12 +530,16 @@ class SettingsFileWorkDelegate @Inject constructor(
}

private suspend fun restartApp() {
if (restartAppIsBlocked) return
// Delay for message to show.
delay(1000)
router.restartApp()
}

companion object {
@VisibleForTesting
var restartAppIsBlocked: Boolean = false

private const val FILE_EXPORT_DATE_TAG = "date"
private const val CSV_EXPORT_DEFAULT_FILE_NAME = "stt_records_{$FILE_EXPORT_DATE_TAG}.csv"
private const val ICS_EXPORT_DEFAULT_FILE_NAME = "stt_events_{$FILE_EXPORT_DATE_TAG}.ics"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,7 @@ import com.example.util.simpletimetracker.core.extension.toModel
import com.example.util.simpletimetracker.core.extension.toParams
import com.example.util.simpletimetracker.core.interactor.RecordFilterInteractor
import com.example.util.simpletimetracker.core.repo.ResourceRepo
import com.example.util.simpletimetracker.domain.extension.hasDateFilter
import com.example.util.simpletimetracker.domain.interactor.PrefsInteractor
import com.example.util.simpletimetracker.domain.model.RangeLength
import com.example.util.simpletimetracker.domain.model.RecordBase
import com.example.util.simpletimetracker.domain.model.RecordsFilter
import com.example.util.simpletimetracker.feature_statistics_detail.R
Expand Down

0 comments on commit edd8b2b

Please sign in to comment.