Skip to content

Commit

Permalink
add record actions tests
Browse files Browse the repository at this point in the history
  • Loading branch information
Razeeman committed Jul 7, 2024
1 parent 4a6085c commit 92c9e40
Show file tree
Hide file tree
Showing 16 changed files with 537 additions and 53 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ 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.longClickOnView
import com.example.util.simpletimetracker.utils.tryAction
import com.example.util.simpletimetracker.utils.typeTextIntoView
import com.example.util.simpletimetracker.utils.withCardColor
Expand Down Expand Up @@ -112,16 +113,6 @@ class ChangeRecordTest : BaseUiTest() {
checkPreviewUpdated(hasDescendant(withText(timeRangePreview)))
checkPreviewUpdated(hasDescendant(withText(comment)))

// Check statistics navigation
clickOnViewWithId(changeRecordR.id.btnChangeRecordStatistics)
checkViewIsDisplayed(
allOf(
withId(statisticsDetailR.id.viewStatisticsDetailItem),
hasDescendant(withText(name)),
),
)
pressBack()

// Change item
clickOnViewWithText(coreR.string.change_record_type_field)
clickOnRecyclerItem(changeRecordR.id.rvChangeRecordType, withText(newName))
Expand Down Expand Up @@ -289,6 +280,38 @@ class ChangeRecordTest : BaseUiTest() {
}
}

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

// Add activities
testUtils.addActivity(name)
testUtils.addRecord(name)

// Check statistics navigation
NavUtils.openRecordsScreen()
clickOnView(allOf(withText(name), isCompletelyDisplayed()))
clickOnViewWithId(changeRecordR.id.btnChangeRecordStatistics)
checkViewIsDisplayed(
allOf(
withId(statisticsDetailR.id.viewStatisticsDetailItem),
hasDescendant(withText(name)),
),
)
pressBack()
pressBack()

// From quick actions
longClickOnView(allOf(withText(name), isCompletelyDisplayed()))
clickOnViewWithId(dialogsR.id.btnRecordQuickActionsStatistics)
checkViewIsDisplayed(
allOf(
withId(statisticsDetailR.id.viewStatisticsDetailItem),
hasDescendant(withText(name)),
),
)
}

private fun checkPreviewUpdated(matcher: Matcher<View>) =
checkViewIsDisplayed(allOf(withId(changeRecordR.id.previewChangeRecord), matcher))
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import androidx.test.espresso.Espresso.pressBack
import androidx.test.espresso.contrib.PickerActions
import androidx.test.espresso.contrib.PickerActions.setTime
import androidx.test.espresso.matcher.ViewMatchers.hasDescendant
import androidx.test.espresso.matcher.ViewMatchers.isCompletelyDisplayed
import androidx.test.espresso.matcher.ViewMatchers.isDescendantOfA
import androidx.test.espresso.matcher.ViewMatchers.withClassName
import androidx.test.espresso.matcher.ViewMatchers.withId
Expand All @@ -18,6 +19,7 @@ import com.example.util.simpletimetracker.core.extension.setToStartOfDay
import com.example.util.simpletimetracker.domain.model.RecordTypeGoal
import com.example.util.simpletimetracker.feature_dialogs.dateTime.CustomTimePicker
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.checkViewIsNotDisplayed
Expand Down Expand Up @@ -114,16 +116,6 @@ class ChangeRunningRecordTest : BaseUiTest() {
checkPreviewUpdated(hasDescendant(withText(timeStartedPreview)))
checkPreviewUpdated(hasDescendant(withSubstring(goalString)))

// Check statistics navigation
clickOnViewWithId(changeRunningRecordR.id.btnChangeRecordStatistics)
checkViewIsDisplayed(
allOf(
withId(statisticsDetailR.id.viewStatisticsDetailItem),
hasDescendant(withText(name1)),
),
)
pressBack()

// Change item
clickOnViewWithText(coreR.string.change_record_type_field)
clickOnRecyclerItem(changeRecordR.id.rvChangeRecordType, withText(name2))
Expand Down Expand Up @@ -448,6 +440,39 @@ class ChangeRunningRecordTest : BaseUiTest() {
}
}

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

// Add activities
testUtils.addActivity(name)
Thread.sleep(1000)
tryAction { clickOnViewWithText(name) }

// Check statistics navigation
longClickOnView(allOf(isDescendantOfA(withId(changeRecordR.id.viewRunningRecordItem)), withText(name)))
clickOnViewWithId(changeRunningRecordR.id.btnChangeRecordStatistics)
checkViewIsDisplayed(
allOf(
withId(statisticsDetailR.id.viewStatisticsDetailItem),
hasDescendant(withText(name)),
),
)
pressBack()
pressBack()

// From quick actions
NavUtils.openRecordsScreen()
longClickOnView(allOf(withText(name), isCompletelyDisplayed()))
clickOnViewWithId(dialogsR.id.btnRecordQuickActionsStatistics)
checkViewIsDisplayed(
allOf(
withId(statisticsDetailR.id.viewStatisticsDetailItem),
hasDescendant(withText(name)),
),
)
}

private fun checkAfterTimeAdjustment(timeStarted: String) {
checkPreviewUpdated(
hasDescendant(allOf(withId(changeRecordR.id.tvRunningRecordItemTimeStarted), withText(timeStarted))),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ 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.longClickOnView
import com.example.util.simpletimetracker.utils.tryAction
import com.example.util.simpletimetracker.utils.withCardColor
import com.example.util.simpletimetracker.utils.withTag
Expand All @@ -29,6 +30,7 @@ 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_change_record.R as changeRecordR
import com.example.util.simpletimetracker.feature_dialogs.R as dialogsR
import com.example.util.simpletimetracker.feature_statistics_detail.R as statisticsDetailR
import com.example.util.simpletimetracker.feature_views.R as viewsR

Expand Down Expand Up @@ -58,16 +60,6 @@ class ChangeUntrackedTest : BaseUiTest() {
checkViewIsNotDisplayed(withId(changeRecordR.id.rvChangeRecordType))
checkPreviewUpdated(withCardColor(viewsR.color.colorUntracked))

// Check statistics navigation
clickOnViewWithId(changeRecordR.id.btnChangeRecordStatistics)
checkViewIsDisplayed(
allOf(
withId(statisticsDetailR.id.viewStatisticsDetailItem),
hasDescendant(withText(coreR.string.untracked_time_name)),
),
)
pressBack()

// Change item
clickOnViewWithText(coreR.string.change_record_type_field)
clickOnRecyclerItem(changeRecordR.id.rvChangeRecordType, withText(name))
Expand Down Expand Up @@ -101,6 +93,40 @@ class ChangeUntrackedTest : BaseUiTest() {
checkViewIsDisplayed(allOf(withText(coreR.string.untracked_time_name), isCompletelyDisplayed()))
}

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

// Add activities
runBlocking { prefsInteractor.setShowUntrackedInRecords(true) }
testUtils.addActivity(name)
val yesterday = System.currentTimeMillis() - TimeUnit.DAYS.toMillis(1)
testUtils.addRecord(typeName = name, timeStarted = yesterday, timeEnded = yesterday)

// Check statistics navigation
NavUtils.openRecordsScreen()
clickOnView(allOf(withText(coreR.string.untracked_time_name), isCompletelyDisplayed()))
clickOnViewWithId(changeRecordR.id.btnChangeRecordStatistics)
checkViewIsDisplayed(
allOf(
withId(statisticsDetailR.id.viewStatisticsDetailItem),
hasDescendant(withText(coreR.string.untracked_time_name)),
),
)
pressBack()
pressBack()

// From quick actions
longClickOnView(allOf(withText(coreR.string.untracked_time_name), isCompletelyDisplayed()))
clickOnViewWithId(dialogsR.id.btnRecordQuickActionsStatistics)
checkViewIsDisplayed(
allOf(
withId(statisticsDetailR.id.viewStatisticsDetailItem),
hasDescendant(withText(coreR.string.untracked_time_name)),
),
)
}

private fun checkPreviewUpdated(matcher: Matcher<View>) =
checkViewIsDisplayed(allOf(withId(changeRecordR.id.previewChangeRecord), matcher))
}
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import com.example.util.simpletimetracker.utils.checkViewIsDisplayed
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.longClickOnView
import com.example.util.simpletimetracker.utils.withCardColor
import com.example.util.simpletimetracker.utils.withTag
import dagger.hilt.android.testing.HiltAndroidTest
Expand All @@ -22,6 +23,7 @@ import org.junit.runner.RunWith
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_change_record.R as changeRecordR
import com.example.util.simpletimetracker.feature_dialogs.R as dialogsR

@HiltAndroidTest
@RunWith(AndroidJUnit4::class)
Expand Down Expand Up @@ -72,4 +74,48 @@ class DeleteRecordTest : BaseUiTest() {
),
)
}

@Test
fun deleteRecordQuickAction() {
val name = "Name"
val color = firstColor
val icon = firstIcon

// Add activity
testUtils.addActivity(name = name, color = color, icon = icon)
testUtils.addRecord(typeName = name)

// Delete item
NavUtils.openRecordsScreen()
longClickOnView(allOf(withText(name), isCompletelyDisplayed()))
checkViewIsDisplayed(withId(dialogsR.id.btnRecordQuickActionsDelete))
clickOnViewWithId(dialogsR.id.btnRecordQuickActionsDelete)

// Check message
checkViewIsDisplayed(
allOf(
withText(getString(coreR.string.record_removed, name)),
withId(com.google.android.material.R.id.snackbar_text),
),
)

// Record is deleted
checkViewDoesNotExist(allOf(withText(name), isCompletelyDisplayed()))
checkViewDoesNotExist(allOf(withCardColor(color), isCompletelyDisplayed()))
checkViewDoesNotExist(allOf(withTag(icon), isCompletelyDisplayed()))

// Check undo
clickOnViewWithText(coreR.string.record_removed_undo)

// Record is back
checkViewIsDisplayed(
CoreMatchers.allOf(
withId(baseR.id.viewRecordItem),
withCardColor(color),
hasDescendant(withText(name)),
hasDescendant(withTag(icon)),
isCompletelyDisplayed(),
),
)
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,116 @@
package com.example.util.simpletimetracker

import androidx.test.espresso.matcher.ViewMatchers.isCompletelyDisplayed
import androidx.test.espresso.matcher.ViewMatchers.isDescendantOfA
import androidx.test.espresso.matcher.ViewMatchers.withId
import androidx.test.espresso.matcher.ViewMatchers.withText
import androidx.test.ext.junit.runners.AndroidJUnit4
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.clickOnView
import com.example.util.simpletimetracker.utils.clickOnViewWithId
import com.example.util.simpletimetracker.utils.clickOnViewWithText
import com.example.util.simpletimetracker.utils.longClickOnView
import com.example.util.simpletimetracker.utils.tryAction
import dagger.hilt.android.testing.HiltAndroidTest
import org.hamcrest.Matchers.allOf
import org.junit.Test
import org.junit.runner.RunWith
import com.example.util.simpletimetracker.feature_base_adapter.R as baseR
import com.example.util.simpletimetracker.feature_change_record.R as changeRecordR
import com.example.util.simpletimetracker.feature_dialogs.R as dialogsR

@HiltAndroidTest
@RunWith(AndroidJUnit4::class)
class DeleteRunningRecordTest : BaseUiTest() {

@Test
fun deleteRunningRecord() {
val name = "Name"
val color = firstColor
val icon = firstIcon

// Add activity
testUtils.addActivity(name = name, color = color, icon = icon)

// Add record
Thread.sleep(1000)
tryAction { clickOnViewWithText(name) }

// Delete item
longClickOnView(allOf(isDescendantOfA(withId(baseR.id.viewRunningRecordItem)), withText(name)))
checkViewIsDisplayed(withId(changeRecordR.id.btnChangeRecordDelete))
clickOnViewWithId(changeRecordR.id.btnChangeRecordDelete)

// Record is deleted
checkViewDoesNotExist(allOf(isDescendantOfA(withId(baseR.id.viewRunningRecordItem)), withText(name)))
}

@Test
fun deleteRunningRecordFromRecords() {
val name = "Name"
val color = firstColor
val icon = firstIcon

// Add activity
testUtils.addActivity(name = name, color = color, icon = icon)

// Add record
Thread.sleep(1000)
tryAction { clickOnViewWithText(name) }

// Delete item
NavUtils.openRecordsScreen()
clickOnView(
allOf(isDescendantOfA(withId(baseR.id.viewRunningRecordItem)), withText(name), isCompletelyDisplayed()),
)
checkViewIsDisplayed(withId(changeRecordR.id.btnChangeRecordDelete))
clickOnViewWithId(changeRecordR.id.btnChangeRecordDelete)

// Record is deleted
tryAction {
checkViewDoesNotExist(
allOf(
isDescendantOfA(withId(baseR.id.viewRunningRecordItem)),
withText(name),
isCompletelyDisplayed(),
),
)
}
}

@Test
fun deleteRunningRecordQuickAction() {
val name = "Name"
val color = firstColor
val icon = firstIcon

// Add activity
testUtils.addActivity(name = name, color = color, icon = icon)

// Add record
Thread.sleep(1000)
tryAction { clickOnViewWithText(name) }

// Delete item
NavUtils.openRecordsScreen()
longClickOnView(
allOf(isDescendantOfA(withId(baseR.id.viewRunningRecordItem)), withText(name), isCompletelyDisplayed()),
)
checkViewIsDisplayed(withId(dialogsR.id.btnRecordQuickActionsDelete))
clickOnViewWithId(dialogsR.id.btnRecordQuickActionsDelete)

// Record is deleted
tryAction {
checkViewDoesNotExist(
allOf(
isDescendantOfA(withId(baseR.id.viewRunningRecordItem)),
withText(name),
isCompletelyDisplayed(),
),
)
}
}
}
Loading

0 comments on commit 92c9e40

Please sign in to comment.