mirror of
https://github.com/vmiklos/plees-tracker.git
synced 2025-08-06 16:40:51 +08:00
ui test: add delete testcase
And remove an unreliable instrumented test which was disabled already.
This commit is contained in:

committed by
Miklos Vajna

parent
329bce2b20
commit
447ede9a1e
@ -86,24 +86,6 @@ class MainActivityInstrumentedTest {
|
||||
assertEquals(1, database.sleepDao().getAll().size)
|
||||
}
|
||||
|
||||
// FIXME started to fail with: androidx.test.espresso.NoMatchingViewException: No views in hierarchy found matching: an instance of android.widget.TextView and view.getText() with or without transformation to match: is "Import File"
|
||||
// @Test
|
||||
fun testDoesNotImportDuplicate() = runBlocking {
|
||||
// Create one sleep.
|
||||
val sleep = Sleep()
|
||||
sleep.start = Calendar.getInstance().timeInMillis
|
||||
sleep.stop = Calendar.getInstance().timeInMillis + Duration.ofHours(1).toMillis()
|
||||
database.sleepDao().insert(sleep)
|
||||
assertEquals(1, database.sleepDao().getAll().size)
|
||||
|
||||
// Export.
|
||||
exportToFile()
|
||||
|
||||
// Import.
|
||||
importFromFile()
|
||||
assertEquals(1, database.sleepDao().getAll().size)
|
||||
}
|
||||
|
||||
private fun exportToFile() {
|
||||
val intent = Intent()
|
||||
intent.data = Uri.fromFile(exportFile)
|
||||
|
@ -10,6 +10,7 @@ import androidx.test.ext.junit.rules.ActivityScenarioRule
|
||||
import androidx.test.ext.junit.runners.AndroidJUnit4
|
||||
import androidx.test.platform.app.InstrumentationRegistry
|
||||
import androidx.test.uiautomator.By
|
||||
import androidx.test.uiautomator.Direction
|
||||
import androidx.test.uiautomator.UiDevice
|
||||
import androidx.test.uiautomator.Until
|
||||
import org.junit.Assert.assertNotNull
|
||||
@ -51,6 +52,34 @@ class MainActivityUITest {
|
||||
)
|
||||
assertNotNull(sleeps)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun testDelete() {
|
||||
// Given a sleep:
|
||||
val instrumentation = InstrumentationRegistry.getInstrumentation()
|
||||
val device = UiDevice.getInstance(instrumentation)
|
||||
val pkg = instrumentation.processName
|
||||
val timeout: Long = 5000
|
||||
device.pressMenu()
|
||||
val deleteAllSleep = device.wait(Until.findObject(By.text("Delete All Sleep")), timeout)
|
||||
deleteAllSleep.click()
|
||||
val yesButton = device.wait(Until.findObject(By.text("YES")), timeout)
|
||||
yesButton.click()
|
||||
val startStop = device.wait(Until.findObject(By.res(pkg, "start_stop")), timeout)
|
||||
startStop.click()
|
||||
startStop.click()
|
||||
|
||||
// When deleting one:
|
||||
val sleepSwipeable = device.wait(Until.findObject(By.res(pkg, "sleep_swipeable")), timeout)
|
||||
sleepSwipeable.swipe(Direction.RIGHT, 1F)
|
||||
|
||||
// Then make sure we have no sleeps:
|
||||
val sleeps = device.wait(
|
||||
Until.findObject(By.res(pkg, "fragment_stats_sleeps").text("0")),
|
||||
timeout
|
||||
)
|
||||
assertNotNull(sleeps)
|
||||
}
|
||||
}
|
||||
|
||||
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|
||||
|
Reference in New Issue
Block a user