|
| 1 | +package com.example.util.simpletimetracker |
| 2 | + |
| 3 | +import androidx.test.core.app.ApplicationProvider |
| 4 | +import androidx.test.espresso.Espresso.pressBack |
| 5 | +import androidx.test.espresso.matcher.ViewMatchers |
| 6 | +import androidx.test.espresso.matcher.ViewMatchers.hasDescendant |
| 7 | +import androidx.test.espresso.matcher.ViewMatchers.isCompletelyDisplayed |
| 8 | +import androidx.test.espresso.matcher.ViewMatchers.isDescendantOfA |
| 9 | +import androidx.test.espresso.matcher.ViewMatchers.withId |
| 10 | +import androidx.test.espresso.matcher.ViewMatchers.withText |
| 11 | +import androidx.test.ext.junit.rules.ActivityScenarioRule |
| 12 | +import androidx.test.ext.junit.runners.AndroidJUnit4 |
| 13 | +import com.example.util.simpletimetracker.core.utils.TestUtils |
| 14 | +import com.example.util.simpletimetracker.di.AppModule |
| 15 | +import com.example.util.simpletimetracker.di.DaggerTestAppComponent |
| 16 | +import com.example.util.simpletimetracker.ui.MainActivity |
| 17 | +import com.example.util.simpletimetracker.utils.NavUtils |
| 18 | +import com.example.util.simpletimetracker.utils.checkViewDoesNotExist |
| 19 | +import com.example.util.simpletimetracker.utils.checkViewIsDisplayed |
| 20 | +import com.example.util.simpletimetracker.utils.clickOnView |
| 21 | +import com.example.util.simpletimetracker.utils.clickOnViewWithId |
| 22 | +import com.example.util.simpletimetracker.utils.clickOnViewWithText |
| 23 | +import com.example.util.simpletimetracker.utils.typeTextIntoView |
| 24 | +import org.hamcrest.CoreMatchers.allOf |
| 25 | +import org.junit.Before |
| 26 | +import org.junit.Rule |
| 27 | +import org.junit.Test |
| 28 | +import org.junit.runner.RunWith |
| 29 | +import javax.inject.Inject |
| 30 | + |
| 31 | +@RunWith(AndroidJUnit4::class) |
| 32 | +class MainScreenEmptyTest { |
| 33 | + |
| 34 | + @Inject |
| 35 | + lateinit var testUtils: TestUtils |
| 36 | + |
| 37 | + @Rule |
| 38 | + @JvmField |
| 39 | + val activityScenarioRule = ActivityScenarioRule(MainActivity::class.java) |
| 40 | + |
| 41 | + @Before |
| 42 | + fun setUp() { |
| 43 | + val app = ApplicationProvider.getApplicationContext() as TimeTrackerApp |
| 44 | + DaggerTestAppComponent.builder() |
| 45 | + .appModule(AppModule(app)) |
| 46 | + .build() |
| 47 | + .inject(this) |
| 48 | + |
| 49 | + testUtils.clearDatabase() |
| 50 | + } |
| 51 | + |
| 52 | + @Test |
| 53 | + fun test() { |
| 54 | + val name = "Test" |
| 55 | + |
| 56 | + // Empty main |
| 57 | + checkViewDoesNotExist(withText(R.string.running_records_empty)) |
| 58 | + |
| 59 | + // Empty records |
| 60 | + NavUtils.openRecordsScreen() |
| 61 | + checkViewIsDisplayed(allOf(withText(R.string.records_empty), isCompletelyDisplayed())) |
| 62 | + clickOnViewWithId(R.id.btnRecordsContainerPrevious) |
| 63 | + checkViewIsDisplayed(allOf(withText(R.string.records_empty), isCompletelyDisplayed())) |
| 64 | + clickOnViewWithId(R.id.btnRecordsContainerNext) |
| 65 | + clickOnViewWithId(R.id.btnRecordsContainerNext) |
| 66 | + checkViewIsDisplayed(allOf(withText(R.string.records_empty), isCompletelyDisplayed())) |
| 67 | + |
| 68 | + // Empty statistics |
| 69 | + NavUtils.openStatisticsScreen() |
| 70 | + checkViewIsDisplayed( |
| 71 | + allOf( |
| 72 | + withId(R.id.layoutStatisticsItem), |
| 73 | + hasDescendant(withText(R.string.untracked_time_name)), |
| 74 | + hasDescendant(ViewMatchers.withSubstring("100%")), |
| 75 | + isCompletelyDisplayed() |
| 76 | + ) |
| 77 | + ) |
| 78 | + clickOnViewWithId(R.id.btnStatisticsContainerNext) |
| 79 | + checkViewIsDisplayed(allOf(withText(R.string.statistics_empty), isCompletelyDisplayed())) |
| 80 | + |
| 81 | + // Week range |
| 82 | + clickOnViewWithId(R.id.btnStatisticsContainerToday) |
| 83 | + clickOnViewWithText(R.string.title_this_week) |
| 84 | + checkViewIsDisplayed( |
| 85 | + allOf( |
| 86 | + withId(R.id.layoutStatisticsItem), |
| 87 | + hasDescendant(withText(R.string.untracked_time_name)), |
| 88 | + hasDescendant(ViewMatchers.withSubstring("100%")), |
| 89 | + isCompletelyDisplayed() |
| 90 | + ) |
| 91 | + ) |
| 92 | + clickOnViewWithId(R.id.btnStatisticsContainerNext) |
| 93 | + checkViewIsDisplayed(allOf(withText(R.string.statistics_empty), isCompletelyDisplayed())) |
| 94 | + |
| 95 | + // Month range |
| 96 | + clickOnViewWithId(R.id.btnStatisticsContainerToday) |
| 97 | + clickOnViewWithText(R.string.title_this_month) |
| 98 | + checkViewIsDisplayed( |
| 99 | + allOf( |
| 100 | + withId(R.id.layoutStatisticsItem), |
| 101 | + hasDescendant(withText(R.string.untracked_time_name)), |
| 102 | + hasDescendant(ViewMatchers.withSubstring("100%")), |
| 103 | + isCompletelyDisplayed() |
| 104 | + ) |
| 105 | + ) |
| 106 | + clickOnViewWithId(R.id.btnStatisticsContainerNext) |
| 107 | + checkViewIsDisplayed(allOf(withText(R.string.statistics_empty), isCompletelyDisplayed())) |
| 108 | + |
| 109 | + // Overall range |
| 110 | + clickOnViewWithId(R.id.btnStatisticsContainerToday) |
| 111 | + clickOnViewWithText(R.string.title_overall) |
| 112 | + checkViewIsDisplayed(allOf(withText(R.string.statistics_empty), isCompletelyDisplayed())) |
| 113 | + |
| 114 | + // Back to day range |
| 115 | + clickOnViewWithId(R.id.btnStatisticsContainerToday) |
| 116 | + clickOnViewWithText(R.string.title_today) |
| 117 | + checkViewIsDisplayed( |
| 118 | + allOf( |
| 119 | + withId(R.id.layoutStatisticsItem), |
| 120 | + hasDescendant(withText(R.string.untracked_time_name)), |
| 121 | + hasDescendant(ViewMatchers.withSubstring("100%")), |
| 122 | + isCompletelyDisplayed() |
| 123 | + ) |
| 124 | + ) |
| 125 | + clickOnViewWithId(R.id.btnStatisticsContainerNext) |
| 126 | + checkViewIsDisplayed(allOf(withText(R.string.statistics_empty), isCompletelyDisplayed())) |
| 127 | + |
| 128 | + // Add activity |
| 129 | + NavUtils.openRunningRecordsScreen() |
| 130 | + clickOnView(withText(R.string.running_records_add_type)) |
| 131 | + typeTextIntoView(R.id.etChangeRecordTypeName, name) |
| 132 | + pressBack() |
| 133 | + clickOnView(withText(R.string.change_record_type_save)) |
| 134 | + checkViewIsDisplayed(withText(R.string.running_records_empty)) |
| 135 | + |
| 136 | + // Start timer |
| 137 | + clickOnViewWithText(name) |
| 138 | + checkViewDoesNotExist(withText(R.string.running_records_empty)) |
| 139 | + clickOnView(allOf(isDescendantOfA(withId(R.id.layoutRunningRecordItem)), withText(name))) |
| 140 | + checkViewIsDisplayed(withText(R.string.running_records_empty)) |
| 141 | + } |
| 142 | +} |
0 commit comments