Skip to content

Commit

Permalink
add new tests
Browse files Browse the repository at this point in the history
  • Loading branch information
Razeeman committed Nov 16, 2024
1 parent bba3e99 commit adb3043
Show file tree
Hide file tree
Showing 11 changed files with 714 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ import androidx.test.espresso.matcher.ViewMatchers.withId
import androidx.test.espresso.matcher.ViewMatchers.withSubstring
import androidx.test.espresso.matcher.ViewMatchers.withText
import androidx.test.ext.junit.runners.AndroidJUnit4
import com.example.util.simpletimetracker.core.extension.setToStartOfDay
import com.example.util.simpletimetracker.core.extension.setWeekToFirstDay
import com.example.util.simpletimetracker.feature_base_adapter.R
import com.example.util.simpletimetracker.utils.BaseUiTest
import com.example.util.simpletimetracker.utils.NavUtils
Expand All @@ -34,10 +36,13 @@ import dagger.hilt.android.testing.HiltAndroidTest
import org.hamcrest.CoreMatchers.allOf
import org.junit.Test
import org.junit.runner.RunWith
import java.util.Calendar
import java.util.concurrent.TimeUnit
import com.example.util.simpletimetracker.core.R as coreR
import com.example.util.simpletimetracker.feature_base_adapter.R as baseR
import com.example.util.simpletimetracker.feature_data_edit.R as dataEditR
import com.example.util.simpletimetracker.feature_records.R as recordsR
import com.example.util.simpletimetracker.feature_records_filter.R as recordsFilterR

@Suppress("SameParameterValue")
@HiltAndroidTest
Expand Down Expand Up @@ -700,6 +705,90 @@ class DataEditTest : BaseUiTest() {
checkViewIsDisplayed(withText(R.string.no_records_exist))
}

@Test
fun selectByDate() {
NavUtils.openSettingsScreen()
NavUtils.openDataEditScreen()
clickOnViewWithText(coreR.string.data_edit_select_records)
clickOnViewWithText(coreR.string.date_time_dialog_date)

// Check ranges
clickOnViewWithText(R.string.title_today)
var calendar = Calendar.getInstance().apply {
timeInMillis = System.currentTimeMillis()
setToStartOfDay()
}
var timeStarted = calendar.timeInMillis.formatDateTimeYear()
var timeEnded = (calendar.timeInMillis + TimeUnit.DAYS.toMillis(1)).formatDateTimeYear()
checkViewIsDisplayed(allOf(withId(recordsFilterR.id.tvRecordsFilterRangeTimeStarted), withText(timeStarted)))
checkViewIsDisplayed(allOf(withId(recordsFilterR.id.tvRecordsFilterRangeTimeEnded), 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(recordsFilterR.id.tvRecordsFilterRangeTimeStarted), withText(timeStarted)))
checkViewIsDisplayed(allOf(withId(recordsFilterR.id.tvRecordsFilterRangeTimeEnded), 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(recordsFilterR.id.tvRecordsFilterRangeTimeStarted), withText(timeStarted)))
checkViewIsDisplayed(allOf(withId(recordsFilterR.id.tvRecordsFilterRangeTimeEnded), 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(recordsFilterR.id.tvRecordsFilterRangeTimeStarted), withText(timeStarted)))
checkViewIsDisplayed(allOf(withId(recordsFilterR.id.tvRecordsFilterRangeTimeEnded), 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(recordsFilterR.id.tvRecordsFilterRangeTimeStarted), withText(timeStarted)))
checkViewIsDisplayed(allOf(withId(recordsFilterR.id.tvRecordsFilterRangeTimeEnded), 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(recordsFilterR.id.tvRecordsFilterRangeTimeStarted), withText(timeStarted)))
checkViewIsDisplayed(allOf(withId(recordsFilterR.id.tvRecordsFilterRangeTimeEnded), withText(timeEnded)))

clickOnView(allOf(isDescendantOfA(withId(R.id.viewFilterItem)), withText(R.string.range_custom)))
checkViewIsDisplayed(allOf(withId(recordsFilterR.id.tvRecordsFilterRangeTimeStarted), withText(timeStarted)))
checkViewIsDisplayed(allOf(withId(recordsFilterR.id.tvRecordsFilterRangeTimeEnded), withText(timeEnded)))
}

private fun checkRecord(
indexes: List<Int>,
name: String,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,15 @@ import com.example.util.simpletimetracker.domain.model.IconEmojiType
import com.example.util.simpletimetracker.domain.model.IconImageType
import com.example.util.simpletimetracker.utils.BaseUiTest
import com.example.util.simpletimetracker.utils.NavUtils
import com.example.util.simpletimetracker.utils.checkViewDoesNotExist
import com.example.util.simpletimetracker.utils.checkViewIsDisplayed
import com.example.util.simpletimetracker.utils.clickOnRecyclerItem
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.collapseToolbar
import com.example.util.simpletimetracker.utils.longClickOnView
import com.example.util.simpletimetracker.utils.nthChildOf
import com.example.util.simpletimetracker.utils.recyclerItemCount
import com.example.util.simpletimetracker.utils.scrollRecyclerToView
import com.example.util.simpletimetracker.utils.swipeUp
Expand Down Expand Up @@ -385,4 +387,100 @@ class IconTest : BaseUiTest() {
),
)
}

@Test
fun favouriteIcons() {
tryAction { clickOnViewWithText(coreR.string.running_records_add_type) }

// Check icons
clickOnViewWithText(coreR.string.change_record_type_icon_image_hint)

// Check first category
checkViewIsDisplayed(
allOf(
nthChildOf(withId(R.id.rvIconSelection), 0),
withText(R.string.imageGroupMaps),
),
)

// Add to favourites
val (category, images) = iconImageMapper.getAvailableImages(loadSearchHints = false)
.toList().dropLast(1).last()
clickOnView(withTag(category.categoryIcon))
val firstImage = images.first().iconResId
checkViewIsDisplayed(withText(category.name))
clickOnView(withTag(firstImage))
clickOnViewWithId(R.id.btnIconSelectionFavourite)
clickOnView(withTag(R.drawable.icon_category_image_favourite))
checkViewIsDisplayed(
allOf(
nthChildOf(withId(R.id.rvIconSelection), 0),
withText(R.string.change_record_favourite_comments_hint),
),
)
checkViewIsDisplayed(
allOf(
nthChildOf(withId(R.id.rvIconSelection), 1),
hasDescendant(withTag(firstImage)),
),
)

// Remove from favourites
clickOnViewWithId(R.id.btnIconSelectionFavourite)
checkViewDoesNotExist(withTag(R.drawable.icon_category_image_favourite))
checkViewIsDisplayed(
allOf(
nthChildOf(withId(R.id.rvIconSelection), 0),
withText(R.string.imageGroupMaps),
),
)

// Check emojis
clickOnView(
allOf(
isDescendantOfA(withId(changeRecordTypeR.id.btnIconSelectionSwitch)),
withText(coreR.string.change_record_type_icon_emoji_hint),
),
)

// Check first category
checkViewIsDisplayed(
allOf(
nthChildOf(withId(R.id.rvIconSelection), 0),
withText(R.string.emojiGroupSmileys),
),
)

// Add to favourites
val (emojiCategory, emojis) = iconEmojiMapper.getAvailableEmojis(loadSearchHints = false)
.toList().last()
clickOnView(withTag(emojiCategory.categoryIcon))
val firstEmoji = emojis.first().emojiCode
checkViewIsDisplayed(withText(emojiCategory.name))
clickOnView(withText(firstEmoji))
clickOnViewWithId(R.id.btnIconSelectionFavourite)
clickOnView(withTag(R.drawable.icon_category_image_favourite))
checkViewIsDisplayed(
allOf(
nthChildOf(withId(R.id.rvIconSelection), 0),
withText(R.string.change_record_favourite_comments_hint),
),
)
checkViewIsDisplayed(
allOf(
nthChildOf(withId(R.id.rvIconSelection), 1),
hasDescendant(withText(firstEmoji)),
),
)

// Remove from favourites
clickOnViewWithId(R.id.btnIconSelectionFavourite)
checkViewDoesNotExist(withTag(R.drawable.icon_category_image_favourite))
checkViewIsDisplayed(
allOf(
nthChildOf(withId(R.id.rvIconSelection), 0),
withText(R.string.emojiGroupSmileys),
),
)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -355,12 +355,49 @@ class RecordActionsContinueTest : BaseUiTest() {
clickOnViewWithText(coreR.string.change_record_continue)

// Running record stopped
checkViewIsDisplayed(allOf(withText(name1), isCompletelyDisplayed()))
checkViewIsDisplayed(
allOf(
withId(baseR.id.viewRecordItem),
hasDescendant(withText(name1)),
hasDescendant(withText("0$minuteString")),
isCompletelyDisplayed(),
),
)

// New running record
NavUtils.openRunningRecordsScreen()
checkViewIsDisplayed(
allOf(
withId(baseR.id.viewRunningRecordItem),
hasDescendant(withText(name2)),
isCompletelyDisplayed(),
),
)
}

@Test
fun continueDefaultDuration() {
val name = "name"

// Setup
testUtils.addActivity(
name = name,
defaultDuration = TimeUnit.MINUTES.toMillis(5),
)
Thread.sleep(1000)
tryAction { clickOnViewWithText(name) }

// Continue
NavUtils.openRecordsScreen()
clickOnView(allOf(withText(name), isCompletelyDisplayed()))
clickOnViewWithText(coreR.string.change_record_actions_hint)
scrollRecyclerToView(changeRecordR.id.rvChangeRecordAction, withText(coreR.string.change_record_continue))
clickOnViewWithText(coreR.string.change_record_continue)

// New running record
NavUtils.openRunningRecordsScreen()
checkViewIsDisplayed(
allOf(withId(baseR.id.viewRunningRecordItem), hasDescendant(withText(name2)), isCompletelyDisplayed()),
allOf(withId(baseR.id.viewRunningRecordItem), hasDescendant(withText(name)), isCompletelyDisplayed()),
)
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package com.example.util.simpletimetracker

import androidx.test.espresso.Espresso.onView
import androidx.test.espresso.Espresso.pressBack
import androidx.test.espresso.action.GeneralLocation
import androidx.test.espresso.matcher.ViewMatchers.hasDescendant
import androidx.test.espresso.matcher.ViewMatchers.isCompletelyDisplayed
import androidx.test.espresso.matcher.ViewMatchers.isDescendantOfA
Expand All @@ -13,6 +14,7 @@ import com.example.util.simpletimetracker.utils.BaseUiTest
import com.example.util.simpletimetracker.utils.NavUtils
import com.example.util.simpletimetracker.utils.checkViewDoesNotExist
import com.example.util.simpletimetracker.utils.checkViewIsDisplayed
import com.example.util.simpletimetracker.utils.clickLocation
import com.example.util.simpletimetracker.utils.clickOnRecyclerItem
import com.example.util.simpletimetracker.utils.clickOnView
import com.example.util.simpletimetracker.utils.clickOnViewWithId
Expand Down Expand Up @@ -76,6 +78,17 @@ class RecordActionsSplitTest : BaseUiTest() {
clickOnAdjustment("+5")
timePreview = calendar.apply { add(Calendar.MINUTE, +5) }.timeInMillis.formatDateTime()
checkViewIsDisplayed(allOf(withId(changeRecordR.id.tvChangeRecordTimePreviewItem), withText(timePreview)))

// Check slider
onView(withId(changeRecordR.id.sliderChangeRecordItem)).perform(clickLocation(GeneralLocation.CENTER_LEFT))
timePreview = timeStartedTimestamp.formatDateTime()
checkViewIsDisplayed(allOf(withId(changeRecordR.id.tvChangeRecordTimePreviewItem), withText(timePreview)))
onView(withId(changeRecordR.id.sliderChangeRecordItem)).perform(clickLocation(GeneralLocation.CENTER_RIGHT))
timePreview = timeEndedTimestamp.formatDateTime()
checkViewIsDisplayed(allOf(withId(changeRecordR.id.tvChangeRecordTimePreviewItem), withText(timePreview)))
onView(withId(changeRecordR.id.sliderChangeRecordItem)).perform(clickLocation(GeneralLocation.CENTER))
timePreview = calendar.getMillis(16, 17).formatDateTime()
checkViewIsDisplayed(allOf(withId(changeRecordR.id.tvChangeRecordTimePreviewItem), withText(timePreview)))
}

@Test
Expand Down
Loading

0 comments on commit adb3043

Please sign in to comment.