|
| 1 | +package com.example.util.simpletimetracker |
| 2 | + |
| 3 | +import androidx.test.espresso.Espresso.pressBack |
| 4 | +import androidx.test.espresso.matcher.ViewMatchers.isCompletelyDisplayed |
| 5 | +import androidx.test.espresso.matcher.ViewMatchers.isDescendantOfA |
| 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.utils.BaseUiTest |
| 10 | +import com.example.util.simpletimetracker.utils.NavUtils |
| 11 | +import com.example.util.simpletimetracker.utils.checkViewDoesNotExist |
| 12 | +import com.example.util.simpletimetracker.utils.checkViewIsDisplayed |
| 13 | +import com.example.util.simpletimetracker.utils.checkViewIsNotDisplayed |
| 14 | +import com.example.util.simpletimetracker.utils.clickOnView |
| 15 | +import com.example.util.simpletimetracker.utils.clickOnViewWithId |
| 16 | +import com.example.util.simpletimetracker.utils.clickOnViewWithText |
| 17 | +import com.example.util.simpletimetracker.utils.tryAction |
| 18 | +import dagger.hilt.android.testing.HiltAndroidTest |
| 19 | +import kotlinx.coroutines.runBlocking |
| 20 | +import org.hamcrest.CoreMatchers.allOf |
| 21 | +import org.junit.Test |
| 22 | +import org.junit.runner.RunWith |
| 23 | +import java.util.concurrent.TimeUnit |
| 24 | +import com.example.util.simpletimetracker.core.R as coreR |
| 25 | +import com.example.util.simpletimetracker.feature_base_adapter.R as baseR |
| 26 | +import com.example.util.simpletimetracker.feature_records.R as recordsR |
| 27 | + |
| 28 | +@HiltAndroidTest |
| 29 | +@RunWith(AndroidJUnit4::class) |
| 30 | +class RecordsOptionsTest : BaseUiTest() { |
| 31 | + |
| 32 | + @Test |
| 33 | + fun buttonsVisibility() { |
| 34 | + NavUtils.openRecordsScreen() |
| 35 | + |
| 36 | + // Check not visible |
| 37 | + checkViewIsDisplayed(withId(recordsR.id.btnRecordsContainerOptions)) |
| 38 | + checkViewIsNotDisplayed(withId(recordsR.id.btnRecordsContainerFilter)) |
| 39 | + checkViewIsNotDisplayed(withId(recordsR.id.btnRecordsContainerShare)) |
| 40 | + checkViewIsNotDisplayed(withId(recordsR.id.btnRecordsContainerCalendarSwitch)) |
| 41 | + |
| 42 | + // Show options |
| 43 | + clickOnViewWithId(recordsR.id.btnRecordsContainerOptions) |
| 44 | + checkViewIsDisplayed(withId(recordsR.id.btnRecordsContainerOptions)) |
| 45 | + checkViewIsDisplayed(withId(recordsR.id.btnRecordsContainerFilter)) |
| 46 | + checkViewIsDisplayed(withId(recordsR.id.btnRecordsContainerShare)) |
| 47 | + checkViewIsNotDisplayed(withId(recordsR.id.btnRecordsContainerCalendarSwitch)) |
| 48 | + |
| 49 | + // Switch tabs |
| 50 | + NavUtils.openRunningRecordsScreen() |
| 51 | + NavUtils.openRecordsScreen() |
| 52 | + |
| 53 | + // Still shown |
| 54 | + checkViewIsDisplayed(withId(recordsR.id.btnRecordsContainerOptions)) |
| 55 | + checkViewIsDisplayed(withId(recordsR.id.btnRecordsContainerFilter)) |
| 56 | + checkViewIsDisplayed(withId(recordsR.id.btnRecordsContainerShare)) |
| 57 | + checkViewIsNotDisplayed(withId(recordsR.id.btnRecordsContainerCalendarSwitch)) |
| 58 | + |
| 59 | + // Hide options |
| 60 | + clickOnViewWithId(recordsR.id.btnRecordsContainerOptions) |
| 61 | + checkViewIsDisplayed(withId(recordsR.id.btnRecordsContainerOptions)) |
| 62 | + checkViewIsNotDisplayed(withId(recordsR.id.btnRecordsContainerFilter)) |
| 63 | + checkViewIsNotDisplayed(withId(recordsR.id.btnRecordsContainerShare)) |
| 64 | + checkViewIsNotDisplayed(withId(recordsR.id.btnRecordsContainerCalendarSwitch)) |
| 65 | + } |
| 66 | + |
| 67 | + @Test |
| 68 | + fun filterType() { |
| 69 | + val name1 = "TypeName1" |
| 70 | + val name2 = "TypeName2" |
| 71 | + |
| 72 | + // Add data |
| 73 | + testUtils.addActivity(name1) |
| 74 | + testUtils.addActivity(name2) |
| 75 | + |
| 76 | + // Add records |
| 77 | + testUtils.addRecord(name1) |
| 78 | + testUtils.addRecord(name2) |
| 79 | + val before = System.currentTimeMillis() - TimeUnit.DAYS.toMillis(1) |
| 80 | + testUtils.addRecord(name1, timeStarted = before, timeEnded = before) |
| 81 | + testUtils.addRecord(name2, timeStarted = before, timeEnded = before) |
| 82 | + |
| 83 | + // All records displayed |
| 84 | + NavUtils.openRecordsScreen() |
| 85 | + checkViewIsDisplayed(allOf(withText(coreR.string.untracked_time_name), isCompletelyDisplayed())) |
| 86 | + checkViewIsDisplayed(allOf(withText(name1), isCompletelyDisplayed())) |
| 87 | + checkViewIsDisplayed(allOf(withText(name2), isCompletelyDisplayed())) |
| 88 | + |
| 89 | + // Filter untracked |
| 90 | + clickOnViewWithId(recordsR.id.btnRecordsContainerOptions) |
| 91 | + clickOnViewWithId(recordsR.id.btnRecordsContainerFilter) |
| 92 | + clickOnView( |
| 93 | + allOf(isDescendantOfA(withId(baseR.id.viewRecordTypeItem)), withText(coreR.string.untracked_time_name)), |
| 94 | + ) |
| 95 | + pressBack() |
| 96 | + tryAction { checkViewDoesNotExist(allOf(withText(coreR.string.untracked_time_name), isCompletelyDisplayed())) } |
| 97 | + checkViewIsDisplayed(allOf(withText(name1), isCompletelyDisplayed())) |
| 98 | + checkViewIsDisplayed(allOf(withText(name2), isCompletelyDisplayed())) |
| 99 | + |
| 100 | + // Filter activity |
| 101 | + clickOnViewWithId(recordsR.id.btnRecordsContainerFilter) |
| 102 | + clickOnView(allOf(isDescendantOfA(withId(baseR.id.viewRecordTypeItem)), withText(name1))) |
| 103 | + pressBack() |
| 104 | + tryAction { checkViewDoesNotExist(allOf(withText(coreR.string.untracked_time_name), isCompletelyDisplayed())) } |
| 105 | + checkViewDoesNotExist(allOf(withText(name1), isCompletelyDisplayed())) |
| 106 | + checkViewIsDisplayed(allOf(withText(name2), isCompletelyDisplayed())) |
| 107 | + |
| 108 | + // Filter all |
| 109 | + clickOnViewWithId(recordsR.id.btnRecordsContainerFilter) |
| 110 | + clickOnView(allOf(isDescendantOfA(withId(baseR.id.viewRecordTypeItem)), withText(name2))) |
| 111 | + pressBack() |
| 112 | + tryAction { checkViewDoesNotExist(allOf(withText(coreR.string.untracked_time_name), isCompletelyDisplayed())) } |
| 113 | + checkViewDoesNotExist(allOf(withText(name1), isCompletelyDisplayed())) |
| 114 | + checkViewDoesNotExist(allOf(withText(name2), isCompletelyDisplayed())) |
| 115 | + checkViewIsDisplayed(allOf(withText(coreR.string.no_data), isCompletelyDisplayed())) |
| 116 | + |
| 117 | + // Show all |
| 118 | + clickOnViewWithId(recordsR.id.btnRecordsContainerFilter) |
| 119 | + clickOnViewWithText(coreR.string.types_filter_show_all) |
| 120 | + pressBack() |
| 121 | + tryAction { checkViewIsDisplayed(allOf(withText(coreR.string.untracked_time_name), isCompletelyDisplayed())) } |
| 122 | + checkViewIsDisplayed(allOf(withText(name1), isCompletelyDisplayed())) |
| 123 | + checkViewIsDisplayed(allOf(withText(name2), isCompletelyDisplayed())) |
| 124 | + |
| 125 | + // Hide all |
| 126 | + clickOnViewWithId(recordsR.id.btnRecordsContainerFilter) |
| 127 | + clickOnViewWithText(coreR.string.types_filter_hide_all) |
| 128 | + pressBack() |
| 129 | + tryAction { checkViewDoesNotExist(allOf(withText(coreR.string.untracked_time_name), isCompletelyDisplayed())) } |
| 130 | + checkViewDoesNotExist(allOf(withText(name1), isCompletelyDisplayed())) |
| 131 | + checkViewDoesNotExist(allOf(withText(name2), isCompletelyDisplayed())) |
| 132 | + checkViewIsDisplayed(allOf(withText(coreR.string.no_data), isCompletelyDisplayed())) |
| 133 | + } |
| 134 | + |
| 135 | + @Test |
| 136 | + fun showRecordsCalendar() { |
| 137 | + val name = "Test" |
| 138 | + |
| 139 | + // Add data |
| 140 | + runBlocking { prefsInteractor.setShowCalendarButtonOnRecordsTab(true) } |
| 141 | + testUtils.addActivity(name = name) |
| 142 | + testUtils.addRecord(name) |
| 143 | + |
| 144 | + // Record is shown |
| 145 | + NavUtils.openRecordsScreen() |
| 146 | + checkViewDoesNotExist(allOf(withId(recordsR.id.viewRecordsCalendar), isCompletelyDisplayed())) |
| 147 | + checkViewDoesNotExist(allOf(withId(recordsR.id.tvRecordsCalendarHint), isCompletelyDisplayed())) |
| 148 | + checkViewIsDisplayed(allOf(withId(recordsR.id.rvRecordsList), isCompletelyDisplayed())) |
| 149 | + checkViewIsDisplayed(allOf(withText(name), isCompletelyDisplayed())) |
| 150 | + |
| 151 | + // Change setting |
| 152 | + clickOnViewWithId(recordsR.id.btnRecordsContainerOptions) |
| 153 | + clickOnViewWithId(recordsR.id.btnRecordsContainerCalendarSwitch) |
| 154 | + |
| 155 | + // Record is not shown |
| 156 | + checkViewIsDisplayed(allOf(withId(recordsR.id.viewRecordsCalendar), isCompletelyDisplayed())) |
| 157 | + checkViewIsDisplayed(allOf(withId(recordsR.id.tvRecordsCalendarHint), isCompletelyDisplayed())) |
| 158 | + checkViewDoesNotExist(allOf(withId(recordsR.id.rvRecordsList), isCompletelyDisplayed())) |
| 159 | + checkViewDoesNotExist(allOf(withText(name), isCompletelyDisplayed())) |
| 160 | + |
| 161 | + // Change setting |
| 162 | + clickOnViewWithId(recordsR.id.btnRecordsContainerCalendarSwitch) |
| 163 | + |
| 164 | + // Record is shown |
| 165 | + checkViewDoesNotExist(allOf(withId(recordsR.id.viewRecordsCalendar), isCompletelyDisplayed())) |
| 166 | + checkViewDoesNotExist(allOf(withId(recordsR.id.tvRecordsCalendarHint), isCompletelyDisplayed())) |
| 167 | + checkViewIsDisplayed(allOf(withId(recordsR.id.rvRecordsList), isCompletelyDisplayed())) |
| 168 | + checkViewIsDisplayed(allOf(withText(name), isCompletelyDisplayed())) |
| 169 | + } |
| 170 | +} |
0 commit comments